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 <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>
23 using namespace dbahsql
;
25 class HsqlBinaryImportTest
: public DBTestBase
28 void testBinaryImport();
30 virtual void setUp() override
;
32 CPPUNIT_TEST_SUITE(HsqlBinaryImportTest
);
34 CPPUNIT_TEST(testBinaryImport
);
36 CPPUNIT_TEST_SUITE_END();
39 void HsqlBinaryImportTest::setUp()
42 SvtMiscOptions aMiscOptions
;
43 osl_setEnvironment(OUString
{ "DBACCESS_HSQL_MIGRATION" }.pData
, OUString
{ "1" }.pData
);
46 void HsqlBinaryImportTest::testBinaryImport()
48 SvtMiscOptions aMiscOptions
;
49 bool oldValue
= aMiscOptions
.IsExperimentalMode();
51 aMiscOptions
.SetExperimentalMode(true);
52 // the migration requires the file to be writable
53 utl::TempFile
const temp(createTempCopy("hsqldb_migration_test.odb"));
54 uno::Reference
<XOfficeDatabaseDocument
> const xDocument
= getDocumentForUrl(temp
.GetURL());
56 uno::Reference
<XConnection
> xConnection
= getConnectionForDocument(xDocument
);
57 // at this point migration is already done
59 uno::Reference
<XStatement
> statement
= xConnection
->createStatement();
60 OUString sql
{ "SELECT \"ID\", \"Power_value\", \"Power_name\", \"Retired\", "
61 "\"Birth_date\" FROM \"TestTable\" ORDER BY \"ID\"" };
63 uno::Reference
<XResultSet
> xRes
= statement
->executeQuery(sql
);
64 uno::Reference
<XRow
> xRow(xRes
, UNO_QUERY_THROW
);
67 CPPUNIT_ASSERT(xRes
->next());
68 constexpr sal_Int16 idExpected
= 1;
69 CPPUNIT_ASSERT_EQUAL(idExpected
, xRow
->getShort(1));
70 CPPUNIT_ASSERT_EQUAL(OUString
{ "45.32" }, xRow
->getString(2)); // numeric
71 CPPUNIT_ASSERT_EQUAL(OUString
{ "laser eye" }, xRow
->getString(3)); // varchar
72 CPPUNIT_ASSERT(xRow
->getBoolean(4)); // boolean
74 css::util::Date date
= xRow
->getDate(5);
76 CPPUNIT_ASSERT_EQUAL(sal_uInt16
{ 15 }, date
.Day
);
77 CPPUNIT_ASSERT_EQUAL(sal_uInt16
{ 1 }, date
.Month
);
78 CPPUNIT_ASSERT_EQUAL(sal_Int16
{ 1996 }, date
.Year
);
81 CPPUNIT_ASSERT(xRes
->next());
82 constexpr sal_Int16 secondIdExpected
= 2;
83 CPPUNIT_ASSERT_EQUAL(secondIdExpected
, xRow
->getShort(1)); // ID
84 CPPUNIT_ASSERT_EQUAL(OUString
{ "54.12" }, xRow
->getString(2)); // numeric
85 CPPUNIT_ASSERT_EQUAL(OUString
{ "telekinesis" }, xRow
->getString(3)); // varchar
86 CPPUNIT_ASSERT(!xRow
->getBoolean(4)); // boolean
88 date
= xRow
->getDate(5);
89 CPPUNIT_ASSERT_EQUAL(sal_uInt16
{ 26 }, date
.Day
);
90 CPPUNIT_ASSERT_EQUAL(sal_uInt16
{ 2 }, date
.Month
);
91 CPPUNIT_ASSERT_EQUAL(sal_Int16
{ 1998 }, date
.Year
);
93 closeDocument(uno::Reference
<lang::XComponent
>(xDocument
, uno::UNO_QUERY
));
95 aMiscOptions
.SetExperimentalMode(false);
98 CPPUNIT_TEST_SUITE_REGISTRATION(HsqlBinaryImportTest
);
100 CPPUNIT_PLUGIN_IMPLEMENT();