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 <officecfg/Office/Common.hxx>
18 class HsqlBinaryImportTest
: public DBTestBase
21 void testBinaryImport();
23 virtual void setUp() override
;
25 CPPUNIT_TEST_SUITE(HsqlBinaryImportTest
);
27 CPPUNIT_TEST(testBinaryImport
);
29 CPPUNIT_TEST_SUITE_END();
32 void HsqlBinaryImportTest::setUp()
35 osl_setEnvironment(OUString
{ "DBACCESS_HSQL_MIGRATION" }.pData
, OUString
{ "1" }.pData
);
38 void HsqlBinaryImportTest::testBinaryImport()
40 bool oldValue
= officecfg::Office::Common::Misc::ExperimentalMode::get();
42 std::shared_ptr
<comphelper::ConfigurationChanges
> xChanges(
43 comphelper::ConfigurationChanges::create());
44 officecfg::Office::Common::Misc::ExperimentalMode::set(true, xChanges
);
48 // the migration requires the file to be writable
49 createTempCopy(u
"hsqldb_migration_test.odb");
50 uno::Reference
<XOfficeDatabaseDocument
> const xDocument
51 = getDocumentForUrl(maTempFile
.GetURL());
53 uno::Reference
<XConnection
> xConnection
= getConnectionForDocument(xDocument
);
54 // at this point migration is already done
56 uno::Reference
<XStatement
> statement
= xConnection
->createStatement();
58 uno::Reference
<XResultSet
> xRes
59 = statement
->executeQuery("SELECT \"ID\", \"Power_value\", \"Power_name\", \"Retired\", "
60 "\"Birth_date\" FROM \"TestTable\" ORDER BY \"ID\"");
61 uno::Reference
<XRow
> xRow(xRes
, UNO_QUERY_THROW
);
64 CPPUNIT_ASSERT(xRes
->next());
65 constexpr sal_Int16 idExpected
= 1;
66 CPPUNIT_ASSERT_EQUAL(idExpected
, xRow
->getShort(1));
67 CPPUNIT_ASSERT_EQUAL(OUString
{ "45.32" }, xRow
->getString(2)); // numeric
68 CPPUNIT_ASSERT_EQUAL(OUString
{ "laser eye" }, xRow
->getString(3)); // varchar
69 CPPUNIT_ASSERT(xRow
->getBoolean(4)); // boolean
71 css::util::Date date
= xRow
->getDate(5);
73 CPPUNIT_ASSERT_EQUAL(sal_uInt16
{ 15 }, date
.Day
);
74 CPPUNIT_ASSERT_EQUAL(sal_uInt16
{ 1 }, date
.Month
);
75 CPPUNIT_ASSERT_EQUAL(sal_Int16
{ 1996 }, date
.Year
);
78 CPPUNIT_ASSERT(xRes
->next());
79 constexpr sal_Int16 secondIdExpected
= 2;
80 CPPUNIT_ASSERT_EQUAL(secondIdExpected
, xRow
->getShort(1)); // ID
81 CPPUNIT_ASSERT_EQUAL(OUString
{ "54.12" }, xRow
->getString(2)); // numeric
82 CPPUNIT_ASSERT_EQUAL(OUString
{ "telekinesis" }, xRow
->getString(3)); // varchar
83 CPPUNIT_ASSERT(!xRow
->getBoolean(4)); // boolean
85 date
= xRow
->getDate(5);
86 CPPUNIT_ASSERT_EQUAL(sal_uInt16
{ 26 }, date
.Day
);
87 CPPUNIT_ASSERT_EQUAL(sal_uInt16
{ 2 }, date
.Month
);
88 CPPUNIT_ASSERT_EQUAL(sal_Int16
{ 1998 }, date
.Year
);
92 std::shared_ptr
<comphelper::ConfigurationChanges
> xChanges(
93 comphelper::ConfigurationChanges::create());
94 officecfg::Office::Common::Misc::ExperimentalMode::set(false, xChanges
);
99 CPPUNIT_TEST_SUITE_REGISTRATION(HsqlBinaryImportTest
);
101 CPPUNIT_PLUGIN_IMPLEMENT();