1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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
24 virtual void setUp() override
;
26 CPPUNIT_TEST_SUITE(Tdf119625Test
);
28 CPPUNIT_TEST(testTime
);
30 CPPUNIT_TEST_SUITE_END();
33 void Tdf119625Test::setUp()
36 osl_setEnvironment(OUString
{ "DBACCESS_HSQL_MIGRATION" }.pData
, OUString
{ "1" }.pData
);
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
);
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
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 "
96 uno::Reference
<XRow
> xRow(xRes
, UNO_QUERY_THROW
);
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());
112 std::shared_ptr
<comphelper::ConfigurationChanges
> xChanges(
113 comphelper::ConfigurationChanges::create());
114 officecfg::Office::Common::Misc::ExperimentalMode::set(false, xChanges
);
119 CPPUNIT_TEST_SUITE_REGISTRATION(Tdf119625Test
);
121 CPPUNIT_PLUGIN_IMPLEMENT();