Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / dbaccess / qa / unit / tdf119625.cxx
blobba0c7b2ce34511e258620bb6451bef307b0b3313
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 <osl/process.h>
13 #include <cppunit/plugin/TestPlugIn.h>
14 #include <com/sun/star/sdbc/XRow.hpp>
15 #include <cppunit/extensions/HelperMacros.h>
16 #include <com/sun/star/util/Time.hpp>
17 #include <officecfg/Office/Common.hxx>
19 class Tdf119625Test : public DBTestBase
21 public:
22 void testTime();
24 virtual void setUp() override;
26 CPPUNIT_TEST_SUITE(Tdf119625Test);
28 CPPUNIT_TEST(testTime);
30 CPPUNIT_TEST_SUITE_END();
33 void Tdf119625Test::setUp()
35 DBTestBase::setUp();
36 osl_setEnvironment(OUString{ "DBACCESS_HSQL_MIGRATION" }.pData, OUString{ "1" }.pData);
39 namespace
41 struct expect_t
43 sal_Int16 id;
44 sal_Int16 h, m, s;
48 /* The values here assume that our results are in UTC. However,
49 tdf#119675 "Firebird: Migration: User dialog to set treatment of
50 datetime and time values during migration" is going to change the
51 final result of migration. If that change is implemented below
52 the level we are testing, this test will have to allow for or set
53 the destination timezone.
55 const expect_t expect[] = { { 0, 15, 10, 10 }, { 1, 23, 30, 30 }, { 2, 5, 0, 0 }, { 3, 4, 30, 0 },
56 { 4, 3, 15, 10 }, { 5, 5, 0, 0 }, { 6, 3, 22, 22 } };
58 void Tdf119625Test::testTime()
60 bool oldValue = officecfg::Office::Common::Misc::ExperimentalMode::get();
62 std::shared_ptr<comphelper::ConfigurationChanges> xChanges(
63 comphelper::ConfigurationChanges::create());
64 officecfg::Office::Common::Misc::ExperimentalMode::set(true, xChanges);
65 xChanges->commit();
68 // the migration requires the file to be writable
69 createTempCopy(u"tdf119625.odb");
70 uno::Reference<XOfficeDatabaseDocument> const xDocument
71 = getDocumentForUrl(maTempFile.GetURL());
73 uno::Reference<XConnection> xConnection = getConnectionForDocument(xDocument);
74 // at this point migration is already done
75 /* In the presence of tdf#119625, terminal already has messages
77 *value exceeds the range for a valid time
78 caused by
79 'isc_dsql_execute'
81 warn:dbaccess:22435:22435:dbaccess/source/filter/hsqldb/hsqlimport.cxx:373: Error during migration
83 In this case, we do not expect anything good from the following
84 code, but I (tje, 2018-09-04) do not know how to detect this
85 situation. In particular, the migration has been observed to
86 create the destination table (but truncated after the first
87 row), and xConnection.is() returns true.
90 // select basically everything from the .odb
91 uno::Reference<XStatement> statement = xConnection->createStatement();
93 uno::Reference<XResultSet> xRes = statement->executeQuery(" SELECT id, tst_dt, tst_d, tst_t "
94 " FROM tst_data "
95 "ORDER BY id");
96 uno::Reference<XRow> xRow(xRes, UNO_QUERY_THROW);
98 // check result
99 for (auto& e : expect)
101 CPPUNIT_ASSERT(xRes->next());
102 CPPUNIT_ASSERT_EQUAL(xRow->getShort(1), e.id);
103 auto time_got = xRow->getTime(4);
104 auto time_expected = com::sun::star::util::Time(0, e.s, e.m, e.h, false);
105 auto equal_times = time_got == time_expected;
106 CPPUNIT_ASSERT(equal_times);
108 CPPUNIT_ASSERT(!xRes->next());
110 if (!oldValue)
112 std::shared_ptr<comphelper::ConfigurationChanges> xChanges(
113 comphelper::ConfigurationChanges::create());
114 officecfg::Office::Common::Misc::ExperimentalMode::set(false, xChanges);
115 xChanges->commit();
119 CPPUNIT_TEST_SUITE_REGISTRATION(Tdf119625Test);
121 CPPUNIT_PLUGIN_IMPLEMENT();