diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /dbaccess/qa/unit/hsql_binary_import.cxx | |
parent | Initial commit. (diff) | |
download | libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | dbaccess/qa/unit/hsql_binary_import.cxx | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/dbaccess/qa/unit/hsql_binary_import.cxx b/dbaccess/qa/unit/hsql_binary_import.cxx new file mode 100644 index 000000000..4eac0cdc4 --- /dev/null +++ b/dbaccess/qa/unit/hsql_binary_import.cxx @@ -0,0 +1,101 @@ +/* -*- 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 <officecfg/Office/Common.hxx> + +class HsqlBinaryImportTest : public DBTestBase +{ +public: + void testBinaryImport(); + + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(HsqlBinaryImportTest); + + CPPUNIT_TEST(testBinaryImport); + + CPPUNIT_TEST_SUITE_END(); +}; + +void HsqlBinaryImportTest::setUp() +{ + DBTestBase::setUp(); + osl_setEnvironment(OUString{ "DBACCESS_HSQL_MIGRATION" }.pData, OUString{ "1" }.pData); +} + +void HsqlBinaryImportTest::testBinaryImport() +{ + bool oldValue = officecfg::Office::Common::Misc::ExperimentalMode::get(); + { + std::shared_ptr<comphelper::ConfigurationChanges> xChanges( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Misc::ExperimentalMode::set(true, xChanges); + xChanges->commit(); + } + + // the migration requires the file to be writable + utl::TempFile const temp(createTempCopy(u"hsqldb_migration_test.odb")); + uno::Reference<XOfficeDatabaseDocument> const xDocument = getDocumentForUrl(temp.GetURL()); + + uno::Reference<XConnection> xConnection = getConnectionForDocument(xDocument); + // at this point migration is already done + + uno::Reference<XStatement> statement = xConnection->createStatement(); + + uno::Reference<XResultSet> xRes + = statement->executeQuery("SELECT \"ID\", \"Power_value\", \"Power_name\", \"Retired\", " + "\"Birth_date\" FROM \"TestTable\" ORDER BY \"ID\""); + uno::Reference<XRow> xRow(xRes, UNO_QUERY_THROW); + + // assert first row + CPPUNIT_ASSERT(xRes->next()); + constexpr sal_Int16 idExpected = 1; + CPPUNIT_ASSERT_EQUAL(idExpected, xRow->getShort(1)); + CPPUNIT_ASSERT_EQUAL(OUString{ "45.32" }, xRow->getString(2)); // numeric + CPPUNIT_ASSERT_EQUAL(OUString{ "laser eye" }, xRow->getString(3)); // varchar + CPPUNIT_ASSERT(xRow->getBoolean(4)); // boolean + + css::util::Date date = xRow->getDate(5); + + CPPUNIT_ASSERT_EQUAL(sal_uInt16{ 15 }, date.Day); + CPPUNIT_ASSERT_EQUAL(sal_uInt16{ 1 }, date.Month); + CPPUNIT_ASSERT_EQUAL(sal_Int16{ 1996 }, date.Year); + + // assert second row + CPPUNIT_ASSERT(xRes->next()); + constexpr sal_Int16 secondIdExpected = 2; + CPPUNIT_ASSERT_EQUAL(secondIdExpected, xRow->getShort(1)); // ID + CPPUNIT_ASSERT_EQUAL(OUString{ "54.12" }, xRow->getString(2)); // numeric + CPPUNIT_ASSERT_EQUAL(OUString{ "telekinesis" }, xRow->getString(3)); // varchar + CPPUNIT_ASSERT(!xRow->getBoolean(4)); // boolean + + date = xRow->getDate(5); + CPPUNIT_ASSERT_EQUAL(sal_uInt16{ 26 }, date.Day); + CPPUNIT_ASSERT_EQUAL(sal_uInt16{ 2 }, date.Month); + CPPUNIT_ASSERT_EQUAL(sal_Int16{ 1998 }, date.Year); + + closeDocument(uno::Reference<lang::XComponent>(xDocument, uno::UNO_QUERY)); + if (!oldValue) + { + std::shared_ptr<comphelper::ConfigurationChanges> xChanges( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Misc::ExperimentalMode::set(false, xChanges); + xChanges->commit(); + } +} + +CPPUNIT_TEST_SUITE_REGISTRATION(HsqlBinaryImportTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); |