bump product version to 6.3.0.0.beta1
[LibreOffice.git] / dbaccess / qa / unit / tdf119625.cxx
blobd38e85bb75a397bb56f9ca28f45a9f2b8ebabc7c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include "dbtest_base.cxx"
12 #include <hsqlimport.hxx>
14 #include <osl/process.h>
15 #include <cppunit/plugin/TestPlugIn.h>
16 #include <com/sun/star/sdbc/DataType.hpp>
17 #include <com/sun/star/sdbc/XRow.hpp>
18 #include <cppunit/TestFixture.h>
19 #include <cppunit/extensions/HelperMacros.h>
20 #include <test/unoapi_test.hxx>
21 #include <svtools/miscopt.hxx>
22 #include <com/sun/star/util/Time.hpp>
24 using namespace dbahsql;
26 class Tdf119625Test : public DBTestBase
28 public:
29 void testTime();
31 virtual void setUp() override;
33 CPPUNIT_TEST_SUITE(Tdf119625Test);
35 CPPUNIT_TEST(testTime);
37 CPPUNIT_TEST_SUITE_END();
40 void Tdf119625Test::setUp()
42 DBTestBase::setUp();
43 SvtMiscOptions aMiscOptions;
44 osl_setEnvironment(OUString{ "DBACCESS_HSQL_MIGRATION" }.pData, OUString{ "1" }.pData);
47 struct expect_t
49 sal_Int16 id;
50 sal_Int16 h, m, s;
53 /* The values here assume that our results are in UTC. However,
54 tdf#119675 "Firebird: Migration: User dialog to set treatment of
55 datetime and time values during migration" is going to change the
56 final result of migration. If that change is implemented below
57 the level we are testing, this test will have to allow for or set
58 the destination timezone.
60 static const expect_t expect[]
61 = { { 0, 15, 10, 10 }, { 1, 23, 30, 30 }, { 2, 5, 0, 0 }, { 3, 4, 30, 0 },
62 { 4, 3, 15, 10 }, { 5, 5, 0, 0 }, { 6, 3, 22, 22 } };
64 void Tdf119625Test::testTime()
66 // the migration requires the file to be writable
67 utl::TempFile const temp(createTempCopy("tdf119625.odb"));
68 uno::Reference<XOfficeDatabaseDocument> const xDocument = getDocumentForUrl(temp.GetURL());
70 uno::Reference<XConnection> xConnection = getConnectionForDocument(xDocument);
71 // at this point migration is already done
72 /* In the presence of tdf#119625, terminal already has messages
74 *value exceeds the range for a valid time
75 caused by
76 'isc_dsql_execute'
78 warn:dbaccess:22435:22435:dbaccess/source/filter/hsqldb/hsqlimport.cxx:373: Error during migration
80 In this case, we do not expect anything good from the following
81 code, but I (tje, 2018-09-04) do not know how to detect this
82 situation. In particular, the migration has been observed to
83 create the destination table (but truncated after the first
84 row), and xConnection.is() returns true.
87 // select basically everything from the .odb
88 uno::Reference<XStatement> statement = xConnection->createStatement();
89 const OUString sql{ " SELECT id, tst_dt, tst_d, tst_t "
90 " FROM tst_data "
91 "ORDER BY id" };
93 uno::Reference<XResultSet> xRes = statement->executeQuery(sql);
94 uno::Reference<XRow> xRow(xRes, UNO_QUERY_THROW);
96 // check result
97 for (auto& e : expect)
99 CPPUNIT_ASSERT(xRes->next());
100 CPPUNIT_ASSERT_EQUAL(xRow->getShort(1), e.id);
101 auto time_got = xRow->getTime(4);
102 auto time_expected = com::sun::star::util::Time(0, e.s, e.m, e.h, false);
103 auto equal_times = time_got == time_expected;
104 CPPUNIT_ASSERT(equal_times);
106 CPPUNIT_ASSERT(!xRes->next());
108 closeDocument(uno::Reference<lang::XComponent>(xDocument, uno::UNO_QUERY));
111 CPPUNIT_TEST_SUITE_REGISTRATION(Tdf119625Test);
113 CPPUNIT_PLUGIN_IMPLEMENT();