diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /dbaccess/qa/unit/tdf126268.cxx | |
parent | Initial commit. (diff) | |
download | libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | dbaccess/qa/unit/tdf126268.cxx | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/dbaccess/qa/unit/tdf126268.cxx b/dbaccess/qa/unit/tdf126268.cxx new file mode 100644 index 000000000..b0719936f --- /dev/null +++ b/dbaccess/qa/unit/tdf126268.cxx @@ -0,0 +1,89 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "dbtest_base.cxx" + +#include <osl/process.h> +#include <cppunit/plugin/TestPlugIn.h> +#include <com/sun/star/sdbc/XRow.hpp> +#include <cppunit/extensions/HelperMacros.h> +#include <svtools/miscopt.hxx> + +class Tdf126268Test : public DBTestBase +{ +public: + void testNumbers(); + + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(Tdf126268Test); + + CPPUNIT_TEST(testNumbers); + + CPPUNIT_TEST_SUITE_END(); +}; + +void Tdf126268Test::setUp() +{ + DBTestBase::setUp(); + osl_setEnvironment(OUString{ "DBACCESS_HSQL_MIGRATION" }.pData, OUString{ "1" }.pData); +} + +namespace +{ +struct expect_t +{ + sal_Int16 id; + OUString number; +}; +} + +static const expect_t expect[] = { + { 1, "0.00" }, { 2, "25.00" }, { 3, "26.00" }, { 4, "30.4" }, { 5, "45.8" }, + { 6, "-25.00" }, { 7, "-26.00" }, { 8, "-30.4" }, { 9, "-45.8" }, +}; + +void Tdf126268Test::testNumbers() +{ + SvtMiscOptions aMiscOptions; + bool oldValue = aMiscOptions.IsExperimentalMode(); + + aMiscOptions.SetExperimentalMode(true); + + // the migration requires the file to be writable + utl::TempFile const temp(createTempCopy("tdf126268.odb")); + uno::Reference<XOfficeDatabaseDocument> const xDocument = getDocumentForUrl(temp.GetURL()); + + uno::Reference<XConnection> xConnection = getConnectionForDocument(xDocument); + + // select basically everything from the .odb + uno::Reference<XStatement> statement = xConnection->createStatement(); + const OUString sql{ "SELECT ID, Column1, Column2 FROM tableTest ORDER BY ID" }; + + uno::Reference<XResultSet> xRes = statement->executeQuery(sql); + uno::Reference<XRow> xRow(xRes, UNO_QUERY_THROW); + + // check result + for (auto& e : expect) + { + CPPUNIT_ASSERT(xRes->next()); + CPPUNIT_ASSERT_EQUAL(e.id, xRow->getShort(1)); + CPPUNIT_ASSERT_EQUAL(e.number, xRow->getString(2)); //decimal + CPPUNIT_ASSERT_EQUAL(e.number, xRow->getString(3)); //numeric + } + CPPUNIT_ASSERT(!xRes->next()); + + closeDocument(uno::Reference<lang::XComponent>(xDocument, uno::UNO_QUERY)); + if (!oldValue) + aMiscOptions.SetExperimentalMode(false); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Tdf126268Test); + +CPPUNIT_PLUGIN_IMPLEMENT(); |