Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / dbaccess / qa / unit / tdf126268.cxx
blob9d41b95809aa0599df1b20c4615bd7e2e49dae2d
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 <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 Tdf126268Test : public DBTestBase
27 public:
28 void testNumbers();
30 virtual void setUp() override;
32 CPPUNIT_TEST_SUITE(Tdf126268Test);
34 CPPUNIT_TEST(testNumbers);
36 CPPUNIT_TEST_SUITE_END();
39 void Tdf126268Test::setUp()
41 DBTestBase::setUp();
42 SvtMiscOptions aMiscOptions;
43 osl_setEnvironment(OUString{ "DBACCESS_HSQL_MIGRATION" }.pData, OUString{ "1" }.pData);
46 struct expect_t
48 sal_Int16 id;
49 OUString number;
52 static const expect_t expect[] = {
53 { 1, "0.00" }, { 2, "25.00" }, { 3, "26.00" }, { 4, "30.4" }, { 5, "45.8" },
54 { 6, "-25.00" }, { 7, "-26.00" }, { 8, "-30.4" }, { 9, "-45.8" },
57 void Tdf126268Test::testNumbers()
59 SvtMiscOptions aMiscOptions;
60 bool oldValue = aMiscOptions.IsExperimentalMode();
62 aMiscOptions.SetExperimentalMode(true);
64 // the migration requires the file to be writable
65 utl::TempFile const temp(createTempCopy("tdf126268.odb"));
66 uno::Reference<XOfficeDatabaseDocument> const xDocument = getDocumentForUrl(temp.GetURL());
68 uno::Reference<XConnection> xConnection = getConnectionForDocument(xDocument);
70 // select basically everything from the .odb
71 uno::Reference<XStatement> statement = xConnection->createStatement();
72 const OUString sql{ "SELECT ID, Column1, Column2 FROM tableTest ORDER BY ID" };
74 uno::Reference<XResultSet> xRes = statement->executeQuery(sql);
75 uno::Reference<XRow> xRow(xRes, UNO_QUERY_THROW);
77 // check result
78 for (auto& e : expect)
80 CPPUNIT_ASSERT(xRes->next());
81 CPPUNIT_ASSERT_EQUAL(e.id, xRow->getShort(1));
82 CPPUNIT_ASSERT_EQUAL(e.number, xRow->getString(2)); //decimal
83 CPPUNIT_ASSERT_EQUAL(e.number, xRow->getString(3)); //numeric
85 CPPUNIT_ASSERT(!xRes->next());
87 closeDocument(uno::Reference<lang::XComponent>(xDocument, uno::UNO_QUERY));
88 if (!oldValue)
89 aMiscOptions.SetExperimentalMode(false);
92 CPPUNIT_TEST_SUITE_REGISTRATION(Tdf126268Test);
94 CPPUNIT_PLUGIN_IMPLEMENT();