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 Tdf126268Test
: public DBTestBase
23 virtual void setUp() override
;
25 CPPUNIT_TEST_SUITE(Tdf126268Test
);
27 CPPUNIT_TEST(testNumbers
);
29 CPPUNIT_TEST_SUITE_END();
32 void Tdf126268Test::setUp()
35 osl_setEnvironment(OUString
{ "DBACCESS_HSQL_MIGRATION" }.pData
, OUString
{ "1" }.pData
);
47 const expect_t expect
[] = {
48 { 1, "0.00" }, { 2, "25.00" }, { 3, "26.00" }, { 4, "30.4" }, { 5, "45.8" },
49 { 6, "-25.00" }, { 7, "-26.00" }, { 8, "-30.4" }, { 9, "-45.8" },
52 void Tdf126268Test::testNumbers()
54 bool oldValue
= officecfg::Office::Common::Misc::ExperimentalMode::get();
56 std::shared_ptr
<comphelper::ConfigurationChanges
> xChanges(
57 comphelper::ConfigurationChanges::create());
58 officecfg::Office::Common::Misc::ExperimentalMode::set(true, xChanges
);
62 // the migration requires the file to be writable
63 utl::TempFile
const temp(createTempCopy(u
"tdf126268.odb"));
64 uno::Reference
<XOfficeDatabaseDocument
> const xDocument
= getDocumentForUrl(temp
.GetURL());
66 uno::Reference
<XConnection
> xConnection
= getConnectionForDocument(xDocument
);
68 // select basically everything from the .odb
69 uno::Reference
<XStatement
> statement
= xConnection
->createStatement();
71 uno::Reference
<XResultSet
> xRes
72 = statement
->executeQuery("SELECT ID, Column1, Column2 FROM tableTest ORDER BY ID");
73 uno::Reference
<XRow
> xRow(xRes
, UNO_QUERY_THROW
);
76 for (auto& e
: expect
)
78 CPPUNIT_ASSERT(xRes
->next());
79 CPPUNIT_ASSERT_EQUAL(e
.id
, xRow
->getShort(1));
80 CPPUNIT_ASSERT_EQUAL(e
.number
, xRow
->getString(2)); //decimal
81 CPPUNIT_ASSERT_EQUAL(e
.number
, xRow
->getString(3)); //numeric
83 CPPUNIT_ASSERT(!xRes
->next());
85 closeDocument(uno::Reference
<lang::XComponent
>(xDocument
, uno::UNO_QUERY
));
88 std::shared_ptr
<comphelper::ConfigurationChanges
> xChanges(
89 comphelper::ConfigurationChanges::create());
90 officecfg::Office::Common::Misc::ExperimentalMode::set(false, xChanges
);
95 CPPUNIT_TEST_SUITE_REGISTRATION(Tdf126268Test
);
97 CPPUNIT_PLUGIN_IMPLEMENT();