From 940b4d1848e8c70ab7642901a68594e8016caffc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:51:28 +0200 Subject: Adding upstream version 1:7.0.4. Signed-off-by: Daniel Baumann --- dbaccess/qa/unit/data/dbaccess-dialogs-test.txt | 111 +++++++ dbaccess/qa/unit/data/firebird_empty.odb | Bin 0 -> 2148 bytes dbaccess/qa/unit/data/firebird_empty_le.odb | Bin 0 -> 1733 bytes dbaccess/qa/unit/data/firebird_integer_le.odb | Bin 0 -> 43990 bytes .../qa/unit/data/firebird_integer_le_ods12.odb | Bin 0 -> 75701 bytes dbaccess/qa/unit/data/firebird_integer_ods12.odb | Bin 0 -> 77617 bytes dbaccess/qa/unit/data/hsqldb_empty.odb | Bin 0 -> 2345 bytes dbaccess/qa/unit/data/hsqldb_migration_test.odb | Bin 0 -> 3949 bytes dbaccess/qa/unit/data/tdf119625.odb | Bin 0 -> 6350 bytes dbaccess/qa/unit/data/tdf126268.odb | Bin 0 -> 5015 bytes dbaccess/qa/unit/dbaccess-dialogs-test.cxx | 61 ++++ dbaccess/qa/unit/dbtest_base.cxx | 86 +++++ dbaccess/qa/unit/embeddeddb_performancetest.cxx | 359 +++++++++++++++++++++ dbaccess/qa/unit/firebird-regression.cxx | 106 ++++++ dbaccess/qa/unit/firebird.cxx | 97 ++++++ dbaccess/qa/unit/hsql_binary_import.cxx | 92 ++++++ dbaccess/qa/unit/hsqldb.cxx | 49 +++ dbaccess/qa/unit/tdf119625.cxx | 115 +++++++ dbaccess/qa/unit/tdf126268.cxx | 89 +++++ 19 files changed, 1165 insertions(+) create mode 100644 dbaccess/qa/unit/data/dbaccess-dialogs-test.txt create mode 100644 dbaccess/qa/unit/data/firebird_empty.odb create mode 100644 dbaccess/qa/unit/data/firebird_empty_le.odb create mode 100644 dbaccess/qa/unit/data/firebird_integer_le.odb create mode 100644 dbaccess/qa/unit/data/firebird_integer_le_ods12.odb create mode 100644 dbaccess/qa/unit/data/firebird_integer_ods12.odb create mode 100644 dbaccess/qa/unit/data/hsqldb_empty.odb create mode 100644 dbaccess/qa/unit/data/hsqldb_migration_test.odb create mode 100644 dbaccess/qa/unit/data/tdf119625.odb create mode 100644 dbaccess/qa/unit/data/tdf126268.odb create mode 100644 dbaccess/qa/unit/dbaccess-dialogs-test.cxx create mode 100644 dbaccess/qa/unit/dbtest_base.cxx create mode 100644 dbaccess/qa/unit/embeddeddb_performancetest.cxx create mode 100644 dbaccess/qa/unit/firebird-regression.cxx create mode 100644 dbaccess/qa/unit/firebird.cxx create mode 100644 dbaccess/qa/unit/hsql_binary_import.cxx create mode 100644 dbaccess/qa/unit/hsqldb.cxx create mode 100644 dbaccess/qa/unit/tdf119625.cxx create mode 100644 dbaccess/qa/unit/tdf126268.cxx (limited to 'dbaccess/qa/unit') diff --git a/dbaccess/qa/unit/data/dbaccess-dialogs-test.txt b/dbaccess/qa/unit/data/dbaccess-dialogs-test.txt new file mode 100644 index 000000000..d30f9f70e --- /dev/null +++ b/dbaccess/qa/unit/data/dbaccess-dialogs-test.txt @@ -0,0 +1,111 @@ +# -*- 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/. +# + +# This file contains all dialogs that the unit tests in the module +# will work on if it is in script mode. It will read one-by-one, +# try to open it and create a screenshot that will be saved in +# workdir/screenshots using the pattern of the ui-file name. +# +# Syntax: +# - empty lines are allowed +# - lines starting with '#' are treated as comment +# - all other lines should contain a *.ui filename in the same +# notation as in the dialog constructors (see code) + +# +# The 'known' dialogs which have a hard-coded representation +# in registerKnownDialogsByID/createDialogByID +# + +# No known dialogs in dbaccess for now + +# +# Dialogs without a hard-coded representation. These will +# be visualized using a fallback based on VclBuilder +# + +# currently deactivated, leads to problems and the test to not work +# This is typically a hint that these should be hard-coded in the +# test case since they need some document and model data to work +# dbaccess/ui/joindialog.ui <- not calling ORelationControl::lateInit for +# DlgQryJoin::m_xTableControl member OTableListBoxControl::m_pRC_Tables leaves its +# BrowseBox::mvCols empty, causing "implicit conversion from type 'int' of value -1 (32-bit, +# signed) to type 'sal_uInt16' (aka 'unsigned short') changed the value to 65535 (16-bit, +# unsigned)" when calling +# GetColumnId( static_cast(mvCols.size()) - 1 ); +# in BrowseBox::AutoSizeLastColumn (svtools/source/brwbox/brwbox1.cxx) with Clang +# -fsanitize=implicit-signed-integer-truncation +# dbaccess/ui/relationdialog.ui <- not calling ORelationControl::lateInit for +# ORelationDialog::m_xTableControl member OTableListBoxControl::m_pRC_Tables leaves its +# BrowseBox::mvCols empty, causing "implicit conversion from type 'int' of value -1 (32-bit, +# signed) to type 'sal_uInt16' (aka 'unsigned short') changed the value to 65535 (16-bit, +# unsigned)" when calling +# GetColumnId( static_cast(mvCols.size()) - 1 ); +# in BrowseBox::AutoSizeLastColumn (svtools/source/brwbox/brwbox1.cxx) with Clang +# -fsanitize=implicit-signed-integer-truncation + +dbaccess/ui/advancedsettingsdialog.ui +dbaccess/ui/admindialog.ui +dbaccess/ui/fielddialog.ui +dbaccess/ui/useradmindialog.ui +dbaccess/ui/mysqlnativesettings.ui +dbaccess/ui/textpage.ui +dbaccess/ui/applycolpage.ui +dbaccess/ui/copytablepage.ui +dbaccess/ui/namematchingpage.ui +dbaccess/ui/typeselectpage.ui +dbaccess/ui/specialsettingspage.ui +dbaccess/ui/generatedvaluespage.ui +dbaccess/ui/ldapconnectionpage.ui +dbaccess/ui/dbwizmysqlintropage.ui +dbaccess/ui/dbwizmysqlnativepage.ui +dbaccess/ui/specialjdbcconnectionpage.ui +dbaccess/ui/authentificationpage.ui +dbaccess/ui/finalpagewizard.ui +dbaccess/ui/tablesfilterpage.ui +dbaccess/ui/useradminpage.ui +dbaccess/ui/connectionpage.ui +dbaccess/ui/dbwizconnectionpage.ui +dbaccess/ui/dbwiztextpage.ui +dbaccess/ui/jdbcconnectionpage.ui +dbaccess/ui/dbwizspreadsheetpage.ui +dbaccess/ui/dbasepage.ui +dbaccess/ui/autocharsetpage.ui +dbaccess/ui/odbcpage.ui +dbaccess/ui/userdetailspage.ui +dbaccess/ui/autocharsetpage.ui +dbaccess/ui/generalspecialjdbcdetailspage.ui +dbaccess/ui/mysqlnativepage.ui +dbaccess/ui/ldappage.ui +dbaccess/ui/emptypage.ui +dbaccess/ui/generalpagedialog.ui +dbaccess/ui/generalpagewizard.ui +dbaccess/ui/collectionviewdialog.ui +dbaccess/ui/dbaseindexdialog.ui +dbaccess/ui/directsqldialog.ui +dbaccess/ui/savedialog.ui +dbaccess/ui/savedialog.ui +dbaccess/ui/rowheightdialog.ui +dbaccess/ui/colwidthdialog.ui +dbaccess/ui/choosedatasourcedialog.ui +dbaccess/ui/indexdesigndialog.ui +dbaccess/ui/parametersdialog.ui +dbaccess/ui/queryfilterdialog.ui +dbaccess/ui/sortdialog.ui +dbaccess/ui/querypropertiesdialog.ui +dbaccess/ui/sqlexception.ui +dbaccess/ui/textconnectionsettings.ui +dbaccess/ui/password.ui +dbaccess/ui/tablesfilterdialog.ui +dbaccess/ui/tablesjoindialog.ui +dbaccess/ui/savemodifieddialog.ui +dbaccess/ui/saveindexdialog.ui +dbaccess/ui/designsavemodifieddialog.ui +dbaccess/ui/tabledesignsavemodifieddialog.ui +dbaccess/ui/deleteallrowsdialog.ui diff --git a/dbaccess/qa/unit/data/firebird_empty.odb b/dbaccess/qa/unit/data/firebird_empty.odb new file mode 100644 index 000000000..9aabfd47b Binary files /dev/null and b/dbaccess/qa/unit/data/firebird_empty.odb differ diff --git a/dbaccess/qa/unit/data/firebird_empty_le.odb b/dbaccess/qa/unit/data/firebird_empty_le.odb new file mode 100644 index 000000000..766c17db2 Binary files /dev/null and b/dbaccess/qa/unit/data/firebird_empty_le.odb differ diff --git a/dbaccess/qa/unit/data/firebird_integer_le.odb b/dbaccess/qa/unit/data/firebird_integer_le.odb new file mode 100644 index 000000000..da2ec1499 Binary files /dev/null and b/dbaccess/qa/unit/data/firebird_integer_le.odb differ diff --git a/dbaccess/qa/unit/data/firebird_integer_le_ods12.odb b/dbaccess/qa/unit/data/firebird_integer_le_ods12.odb new file mode 100644 index 000000000..95691ed20 Binary files /dev/null and b/dbaccess/qa/unit/data/firebird_integer_le_ods12.odb differ diff --git a/dbaccess/qa/unit/data/firebird_integer_ods12.odb b/dbaccess/qa/unit/data/firebird_integer_ods12.odb new file mode 100644 index 000000000..642b038dd Binary files /dev/null and b/dbaccess/qa/unit/data/firebird_integer_ods12.odb differ diff --git a/dbaccess/qa/unit/data/hsqldb_empty.odb b/dbaccess/qa/unit/data/hsqldb_empty.odb new file mode 100644 index 000000000..087c26113 Binary files /dev/null and b/dbaccess/qa/unit/data/hsqldb_empty.odb differ diff --git a/dbaccess/qa/unit/data/hsqldb_migration_test.odb b/dbaccess/qa/unit/data/hsqldb_migration_test.odb new file mode 100644 index 000000000..99b6b5d9a Binary files /dev/null and b/dbaccess/qa/unit/data/hsqldb_migration_test.odb differ diff --git a/dbaccess/qa/unit/data/tdf119625.odb b/dbaccess/qa/unit/data/tdf119625.odb new file mode 100644 index 000000000..e7bd69d60 Binary files /dev/null and b/dbaccess/qa/unit/data/tdf119625.odb differ diff --git a/dbaccess/qa/unit/data/tdf126268.odb b/dbaccess/qa/unit/data/tdf126268.odb new file mode 100644 index 000000000..434a4238b Binary files /dev/null and b/dbaccess/qa/unit/data/tdf126268.odb differ diff --git a/dbaccess/qa/unit/dbaccess-dialogs-test.cxx b/dbaccess/qa/unit/dbaccess-dialogs-test.cxx new file mode 100644 index 000000000..49eff86ec --- /dev/null +++ b/dbaccess/qa/unit/dbaccess-dialogs-test.cxx @@ -0,0 +1,61 @@ +/* -*- 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 +#include +#include + +using namespace ::com::sun::star; + +/// Test opening a dialog in dbaccess +class DbaccessDialogsTest : public ScreenshotTest +{ +private: + /// helper method to populate KnownDialogs, called in setUp(). Needs to be + /// written and has to add entries to KnownDialogs + virtual void registerKnownDialogsByID(mapType& rKnownDialogs) override; + + /// dialog creation for known dialogs by ID. Has to be implemented for + /// each registered known dialog + virtual VclPtr createDialogByID(sal_uInt32 nID) override; + +public: + DbaccessDialogsTest(); + + // try to open a dialog + void openAnyDialog(); + + CPPUNIT_TEST_SUITE(DbaccessDialogsTest); + CPPUNIT_TEST(openAnyDialog); + CPPUNIT_TEST_SUITE_END(); +}; + +DbaccessDialogsTest::DbaccessDialogsTest() {} + +void DbaccessDialogsTest::registerKnownDialogsByID(mapType& /*rKnownDialogs*/) +{ + // fill map of known dialogs +} + +VclPtr DbaccessDialogsTest::createDialogByID(sal_uInt32 /*nID*/) +{ + return nullptr; +} + +void DbaccessDialogsTest::openAnyDialog() +{ + /// process input file containing the UXMLDescriptions of the dialogs to dump + processDialogBatchFile("dbaccess/qa/unit/data/dbaccess-dialogs-test.txt"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(DbaccessDialogsTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/qa/unit/dbtest_base.cxx b/dbaccess/qa/unit/dbtest_base.cxx new file mode 100644 index 000000000..72f4e9b68 --- /dev/null +++ b/dbaccess/qa/unit/dbtest_base.cxx @@ -0,0 +1,86 @@ +/* -*- 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 + +#include + +#include +#include +#include +#include +#include + +using namespace ::com::sun::star; +using namespace ::com::sun::star::sdb; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::uno; + +class DBTestBase + : public UnoApiTest +{ +public: + DBTestBase() : UnoApiTest("dbaccess/qa/unit/data") {}; + + utl::TempFile createTempCopy(OUString const & pathname); + + uno::Reference< XOfficeDatabaseDocument > + getDocumentForFileName(const OUString &sFileName); + + uno::Reference getDocumentForUrl(OUString const & url); + + uno::Reference< XConnection > + getConnectionForDocument( + uno::Reference< XOfficeDatabaseDocument > const & xDocument); +}; + +utl::TempFile DBTestBase::createTempCopy(OUString const & pathname) { + OUString url; + createFileURL(pathname, url); + utl::TempFile tmp; + tmp.EnableKillingFile(); + auto const e = osl::File::copy(url, tmp.GetURL()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + (OUStringToOString("<" + url + "> -> <" + tmp.GetURL() + ">", RTL_TEXTENCODING_UTF8) + .getStr()), + osl::FileBase::E_None, e); + return tmp; +} + +uno::Reference< XOfficeDatabaseDocument > + DBTestBase::getDocumentForFileName(const OUString &sFileName) +{ + OUString sFilePath; + createFileURL(sFileName, sFilePath); + return getDocumentForUrl(sFilePath); +} + +uno::Reference DBTestBase::getDocumentForUrl(OUString const & url) { + uno::Reference< lang::XComponent > xComponent (loadFromDesktop(url)); + CPPUNIT_ASSERT(xComponent.is()); + + uno::Reference< XOfficeDatabaseDocument > xDocument(xComponent, UNO_QUERY); + CPPUNIT_ASSERT(xDocument.is()); + + return xDocument; +} + +uno::Reference< XConnection > DBTestBase::getConnectionForDocument( + uno::Reference< XOfficeDatabaseDocument > const & xDocument) +{ + uno::Reference< XDataSource > xDataSource = xDocument->getDataSource(); + CPPUNIT_ASSERT(xDataSource.is()); + + uno::Reference< XConnection > xConnection = xDataSource->getConnection("",""); + CPPUNIT_ASSERT(xConnection.is()); + + return xConnection; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/qa/unit/embeddeddb_performancetest.cxx b/dbaccess/qa/unit/embeddeddb_performancetest.cxx new file mode 100644 index 000000000..0517a9fd1 --- /dev/null +++ b/dbaccess/qa/unit/embeddeddb_performancetest.cxx @@ -0,0 +1,359 @@ +/* -*- 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 +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace ::com::sun::star; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::frame; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::sdb; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::uno; + +static void normaliseTimeValue(TimeValue* pVal) +{ + pVal->Seconds += pVal->Nanosec / 1000000000; + pVal->Nanosec %= 1000000000; +} + +static void getTimeDifference(const TimeValue* pTimeStart, + const TimeValue* pTimeEnd, + TimeValue* pTimeDifference) +{ + // We add 1 second to the nanoseconds to ensure that we get a positive number + // We have to normalise anyway so this doesn't cause any harm. + // (Seconds/Nanosec are both unsigned) + pTimeDifference->Seconds = pTimeEnd->Seconds - pTimeStart->Seconds - 1; + pTimeDifference->Nanosec = 1000000000 + pTimeEnd->Nanosec - pTimeStart->Nanosec; + normaliseTimeValue(pTimeDifference); +} + +static OUString getPrintableTimeValue(const TimeValue* pTimeValue) +{ + return OUString::number( + (sal_uInt64(pTimeValue->Seconds) * SAL_CONST_UINT64(1000000000) + + sal_uInt64(pTimeValue->Nanosec))/ 1000000 + ); +} + +/* + * The recommended way to run this test is: + * 'SAL_LOG="" DBA_PERFTEST=YES make CppunitTest_dbaccess_embeddeddb_performancetest' + * This blocks the unnecessary exception output and show only the performance data. + * + * You also need to create the file dbaccess/qa/unit/data/wordlist, this list cannot + * contain any unescaped apostrophes (since the words are used directly to assemble + * sql statement), apostrophes are escaped using a double apostrophe, i.e. ''. + * one easy way of generating a list is using: + * 'for WORD in $(aspell dump master); do echo ${WORD//\'/\'\'}; done > dbaccess/qa/unit/data/wordlist' + * + * Note that wordlist cannot have more than 220580 lines, this is due to a hard + * limit in our hsqldb version. + * + * Also note that this unit test "fails" when doing performance testing, this is + * since by default unit test output is hidden, and thus there is no way of + * reading the results. + */ +class EmbeddedDBPerformanceTest + : public DBTestBase +{ +private: + static const char our_sEnableTestEnvVar[]; + + // We store the results and print them at the end due to the amount of warning + // noise present which otherwise obscures the results. + OUStringBuffer m_aOutputBuffer; + + void printTimes(const TimeValue* pTime1, const TimeValue* pTime2, const TimeValue* pTime3); + + void doPerformanceTestOnODB(const OUString& rDriverURL, + const OUString& rDBName, + const bool bUsePreparedStatement); + + void setupTestTable(uno::Reference< XConnection > const & xConnection); + + SvFileStream *getWordListStream(); + + // Individual Tests + void performPreparedStatementInsertTest( + uno::Reference< XConnection > const & xConnection, + const OUString& rDBName); + void performStatementInsertTest( + uno::Reference< XConnection > const & xConnection, + const OUString& rDBName); + void performReadTest( + uno::Reference< XConnection > const & xConnection, + const OUString& rDBName); + + // Perform all tests on a given DB. + void testFirebird(); + void testHSQLDB(); + +public: + void testPerformance(); + + CPPUNIT_TEST_SUITE(EmbeddedDBPerformanceTest); + CPPUNIT_TEST(testPerformance); + CPPUNIT_TEST_SUITE_END(); +}; + +SvFileStream* EmbeddedDBPerformanceTest::getWordListStream() +{ + OUString wlPath; + createFileURL("wordlist", wlPath); + return new SvFileStream(wlPath, StreamMode::READ); +} + +void EmbeddedDBPerformanceTest::printTimes( + const TimeValue* pTime1, + const TimeValue* pTime2, + const TimeValue* pTime3) +{ + m_aOutputBuffer + .append(getPrintableTimeValue(pTime1)).append("\t") + .append(getPrintableTimeValue(pTime2)).append("\t") + .append(getPrintableTimeValue(pTime3)).append("\t") + .append("\n"); +} + +const char EmbeddedDBPerformanceTest::our_sEnableTestEnvVar[] = "DBA_PERFTEST"; + +// TODO: we probably should create a document from scratch instead? + +void EmbeddedDBPerformanceTest::testPerformance() +{ + OUString sEnabled; + osl_getEnvironment(OUString(our_sEnableTestEnvVar).pData, &sEnabled.pData); + + if (sEnabled.isEmpty()) + return; + + m_aOutputBuffer.append("---------------------\n"); + testFirebird(); + m_aOutputBuffer.append("---------------------\n"); + testHSQLDB(); + m_aOutputBuffer.append("---------------------\n"); + + fprintf(stdout, "Performance Test Results:\n"); + fprintf(stdout, "%s", + OUStringToOString(m_aOutputBuffer.makeStringAndClear(), + RTL_TEXTENCODING_UTF8) + .getStr() + ); + + // We want the results printed, but unit test output is only printed on failure + // Hence we deliberately fail the test. + CPPUNIT_ASSERT(false); +} + +void EmbeddedDBPerformanceTest::testFirebird() +{ + + m_aOutputBuffer.append("Standard Insert\n"); + doPerformanceTestOnODB("sdbc:embedded:firebird", "Firebird", false); + m_aOutputBuffer.append("PreparedStatement Insert\n"); + doPerformanceTestOnODB("sdbc:embedded:firebird", "Firebird", true); +} + +void EmbeddedDBPerformanceTest::testHSQLDB() +{ + m_aOutputBuffer.append("Standard Insert\n"); + doPerformanceTestOnODB("sdbc:embedded:hsqldb", "HSQLDB", false); + m_aOutputBuffer.append("PreparedStatement Insert\n"); + doPerformanceTestOnODB("sdbc:embedded:hsqldb", "HSQLDB", true); +} + +/** + * Use an existing .odb to do performance tests on. The database cannot have + * a table of the name PFTESTTABLE. + */ +void EmbeddedDBPerformanceTest::doPerformanceTestOnODB( + const OUString& rDriverURL, + const OUString& rDBName, + const bool bUsePreparedStatement) +{ + ::utl::TempFile aFile; + aFile.EnableKillingFile(); + + { + uno::Reference< XOfficeDatabaseDocument > xDocument( + m_xSFactory->createInstance("com.sun.star.sdb.OfficeDatabaseDocument"), + UNO_QUERY_THROW); + uno::Reference< XStorable > xStorable(xDocument, UNO_QUERY_THROW); + + uno::Reference< XDataSource > xDataSource = xDocument->getDataSource(); + uno::Reference< XPropertySet > xPropertySet(xDataSource, UNO_QUERY_THROW); + xPropertySet->setPropertyValue("URL", Any(rDriverURL)); + + xStorable->storeAsURL(aFile.GetURL(), uno::Sequence< beans::PropertyValue >()); + } + + uno::Reference< XOfficeDatabaseDocument > xDocument( + loadFromDesktop(aFile.GetURL()), UNO_QUERY_THROW); + + uno::Reference< XConnection > xConnection = + getConnectionForDocument(xDocument); + + setupTestTable(xConnection); + + if (bUsePreparedStatement) + performPreparedStatementInsertTest(xConnection, rDBName); + else + performStatementInsertTest(xConnection, rDBName); + + performReadTest(xConnection, rDBName); +} + +void EmbeddedDBPerformanceTest::setupTestTable( + uno::Reference< XConnection > const & xConnection) +{ + uno::Reference< XStatement > xStatement = xConnection->createStatement(); + + // Although not strictly necessary we use quoted identifiers to reflect + // the fact that Base always uses quoted identifiers. + xStatement->execute( + "CREATE TABLE \"PFTESTTABLE\" ( \"ID\" INTEGER NOT NULL PRIMARY KEY " + ", \"STRINGCOLUMNA\" VARCHAR (50) " + ")"); + + xConnection->commit(); +} + +void EmbeddedDBPerformanceTest::performPreparedStatementInsertTest( + uno::Reference< XConnection > const & xConnection, + const OUString& rDBName) +{ + uno::Reference< XPreparedStatement > xPreparedStatement = + xConnection->prepareStatement( + "INSERT INTO \"PFTESTTABLE\" ( \"ID\", " + "\"STRINGCOLUMNA\" " + ") VALUES ( ?, ? )" + ); + + uno::Reference< XParameters > xParameters(xPreparedStatement, UNO_QUERY_THROW); + + std::unique_ptr< SvFileStream > pFile(getWordListStream()); + + OUString aWord; + sal_Int32 aID = 0; + + TimeValue aStart, aMiddle, aEnd; + osl_getSystemTime(&aStart); + + while (pFile->ReadByteStringLine(aWord, RTL_TEXTENCODING_UTF8)) + { + xParameters->setInt(1, aID++); + xParameters->setString(2, aWord); + xPreparedStatement->execute(); + } + osl_getSystemTime(&aMiddle); + xConnection->commit(); + osl_getSystemTime(&aEnd); + + + TimeValue aTimeInsert, aTimeCommit, aTimeTotal; + getTimeDifference(&aStart, &aMiddle, &aTimeInsert); + getTimeDifference(&aMiddle, &aEnd, &aTimeCommit); + getTimeDifference(&aStart, &aEnd, &aTimeTotal); + m_aOutputBuffer.append("Insert: ").append(rDBName).append("\n"); + printTimes(&aTimeInsert, &aTimeCommit, &aTimeTotal); + + pFile->Close(); +} + +void EmbeddedDBPerformanceTest::performStatementInsertTest( + uno::Reference< XConnection > const & xConnection, + const OUString& rDBName) +{ + uno::Reference< XStatement > xStatement = + xConnection->createStatement(); + + std::unique_ptr< SvFileStream > pFile(getWordListStream()); + + OUString aWord; + sal_Int32 aID = 0; + + TimeValue aStart, aMiddle, aEnd; + osl_getSystemTime(&aStart); + + while (pFile->ReadByteStringLine(aWord, RTL_TEXTENCODING_UTF8)) + { + xStatement->execute( + "INSERT INTO \"PFTESTTABLE\" ( \"ID\", " + "\"STRINGCOLUMNA\" " + ") VALUES ( " + + OUString::number(aID++) + ", '" + aWord + "' )" + ); + } + osl_getSystemTime(&aMiddle); + xConnection->commit(); + osl_getSystemTime(&aEnd); + + TimeValue aTimeInsert, aTimeCommit, aTimeTotal; + getTimeDifference(&aStart, &aMiddle, &aTimeInsert); + getTimeDifference(&aMiddle, &aEnd, &aTimeCommit); + getTimeDifference(&aStart, &aEnd, &aTimeTotal); + m_aOutputBuffer.append("Insert: ").append(rDBName).append("\n"); + printTimes(&aTimeInsert, &aTimeCommit, &aTimeTotal); + + pFile->Close(); +} + +void EmbeddedDBPerformanceTest::performReadTest( + uno::Reference< XConnection > const & xConnection, + const OUString& rDBName) +{ + uno::Reference< XStatement > xStatement = xConnection->createStatement(); + + TimeValue aStart, aMiddle, aEnd; + osl_getSystemTime(&aStart); + + uno::Reference< XResultSet > xResults = xStatement->executeQuery("SELECT * FROM PFTESTTABLE"); + + osl_getSystemTime(&aMiddle); + + uno::Reference< XRow > xRow(xResults, UNO_QUERY_THROW); + + while (xResults->next()) + { + xRow->getString(2); + } + osl_getSystemTime(&aEnd); + + TimeValue aTimeSelect, aTimeIterate, aTimeTotal; + getTimeDifference(&aStart, &aMiddle, &aTimeSelect); + getTimeDifference(&aMiddle, &aEnd, &aTimeIterate); + getTimeDifference(&aStart, &aEnd, &aTimeTotal); + m_aOutputBuffer.append("Read from: ").append(rDBName).append("\n"); + printTimes(&aTimeSelect, &aTimeIterate, &aTimeTotal); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(EmbeddedDBPerformanceTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/qa/unit/firebird-regression.cxx b/dbaccess/qa/unit/firebird-regression.cxx new file mode 100644 index 000000000..faf0a834b --- /dev/null +++ b/dbaccess/qa/unit/firebird-regression.cxx @@ -0,0 +1,106 @@ +/* -*- 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 +#include +#include +#include +#include +#include + +using namespace ::com::sun::star; +using namespace ::com::sun::star::sdb; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::uno; + +class FirebirdTest + : public DBTestBase +{ +public: + void testEmptyDBConnection(); + void testIntegerDatabase(); + + CPPUNIT_TEST_SUITE(FirebirdTest); + CPPUNIT_TEST(testEmptyDBConnection); + CPPUNIT_TEST(testIntegerDatabase); + CPPUNIT_TEST_SUITE_END(); +}; + +/** + * Test the loading of an "empty" file, i.e. the embedded database has not yet + * been initialised (as occurs when a new .odb is created and opened by base). + */ +void FirebirdTest::testEmptyDBConnection() +{ +#ifdef OSL_BIGENDIAN + auto const tmp = createTempCopy("firebird_empty_be.odb"); +#else + auto const tmp = createTempCopy("firebird_empty_le.odb"); +#endif + uno::Reference< XOfficeDatabaseDocument > xDocument = + getDocumentForUrl(tmp.GetURL()); + + getConnectionForDocument(xDocument); + + closeDocument(uno::Reference(xDocument, uno::UNO_QUERY)); +} + +/** + * Test reading of integers from a known .odb to verify that the data + * can still be read on all systems. + */ +void FirebirdTest::testIntegerDatabase() +{ +#ifdef OSL_BIGENDIAN + uno::Reference< XOfficeDatabaseDocument > xDocument = + getDocumentForFileName("firebird_integer_be_ods12.odb"); +#else + uno::Reference< XOfficeDatabaseDocument > xDocument = + getDocumentForFileName("firebird_integer_le_ods12.odb"); +#endif + + uno::Reference< XConnection > xConnection = + getConnectionForDocument(xDocument); + + uno::Reference< XStatement > xStatement = xConnection->createStatement(); + CPPUNIT_ASSERT(xStatement.is()); + + uno::Reference< XResultSet > xResultSet = xStatement->executeQuery( + "SELECT * FROM TESTTABLE"); + CPPUNIT_ASSERT(xResultSet.is()); + CPPUNIT_ASSERT(xResultSet->next()); + + uno::Reference< XRow > xRow(xResultSet, UNO_QUERY); + CPPUNIT_ASSERT(xRow.is()); + uno::Reference< XColumnLocate > xColumnLocate(xRow, UNO_QUERY); + CPPUNIT_ASSERT(xColumnLocate.is()); + + CPPUNIT_ASSERT_EQUAL(sal_Int16(-30000), + xRow->getShort(xColumnLocate->findColumn("_SMALLINT"))); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-2100000000), + xRow->getInt(xColumnLocate->findColumn("_INT"))); + CPPUNIT_ASSERT_EQUAL(SAL_CONST_INT64(-9000000000000000000), + xRow->getLong(xColumnLocate->findColumn("_BIGINT"))); + CPPUNIT_ASSERT_EQUAL(OUString("5"), + xRow->getString(xColumnLocate->findColumn("_CHAR"))); + CPPUNIT_ASSERT_EQUAL(OUString("5"), + xRow->getString(xColumnLocate->findColumn("_VARCHAR"))); + + CPPUNIT_ASSERT(!xResultSet->next()); // Should only be one row + + closeDocument(uno::Reference(xDocument, uno::UNO_QUERY)); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(FirebirdTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/qa/unit/firebird.cxx b/dbaccess/qa/unit/firebird.cxx new file mode 100644 index 000000000..955813324 --- /dev/null +++ b/dbaccess/qa/unit/firebird.cxx @@ -0,0 +1,97 @@ +/* -*- 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 +#include +#include +#include +#include +#include + +using namespace ::com::sun::star; +using namespace ::com::sun::star::sdb; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::uno; + +class FirebirdTest + : public DBTestBase +{ +public: + void testEmptyDBConnection(); + void testIntegerDatabase(); + + CPPUNIT_TEST_SUITE(FirebirdTest); + CPPUNIT_TEST(testEmptyDBConnection); + CPPUNIT_TEST(testIntegerDatabase); + CPPUNIT_TEST_SUITE_END(); +}; + +/** + * Test the loading of an "empty" file, i.e. the embedded database has not yet + * been initialised (as occurs when a new .odb is created and opened by base). + */ +void FirebirdTest::testEmptyDBConnection() +{ + auto const tmp = createTempCopy("firebird_empty.odb"); + uno::Reference< XOfficeDatabaseDocument > xDocument = + getDocumentForUrl(tmp.GetURL()); + + getConnectionForDocument(xDocument); + + closeDocument(uno::Reference(xDocument, uno::UNO_QUERY)); +} + +/** + * Test reading of integers from a known .odb to verify that the data + * can still be read on all systems. + */ +void FirebirdTest::testIntegerDatabase() +{ + uno::Reference< XOfficeDatabaseDocument > xDocument = + getDocumentForFileName("firebird_integer_ods12.odb"); + + uno::Reference< XConnection > xConnection = + getConnectionForDocument(xDocument); + + uno::Reference< XStatement > xStatement = xConnection->createStatement(); + CPPUNIT_ASSERT(xStatement.is()); + + uno::Reference< XResultSet > xResultSet = xStatement->executeQuery( + "SELECT * FROM TESTTABLE"); + CPPUNIT_ASSERT(xResultSet.is()); + CPPUNIT_ASSERT(xResultSet->next()); + + uno::Reference< XRow > xRow(xResultSet, UNO_QUERY); + CPPUNIT_ASSERT(xRow.is()); + uno::Reference< XColumnLocate > xColumnLocate(xRow, UNO_QUERY); + CPPUNIT_ASSERT(xColumnLocate.is()); + + CPPUNIT_ASSERT_EQUAL(sal_Int16(-30000), + xRow->getShort(xColumnLocate->findColumn("_SMALLINT"))); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-2100000000), + xRow->getInt(xColumnLocate->findColumn("_INT"))); + CPPUNIT_ASSERT_EQUAL(SAL_CONST_INT64(-9000000000000000000), + xRow->getLong(xColumnLocate->findColumn("_BIGINT"))); + CPPUNIT_ASSERT_EQUAL(OUString("5"), + xRow->getString(xColumnLocate->findColumn("_CHAR"))); + CPPUNIT_ASSERT_EQUAL(OUString("5"), + xRow->getString(xColumnLocate->findColumn("_VARCHAR"))); + + CPPUNIT_ASSERT(!xResultSet->next()); // Should only be one row + + closeDocument(uno::Reference(xDocument, uno::UNO_QUERY)); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(FirebirdTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/qa/unit/hsql_binary_import.cxx b/dbaccess/qa/unit/hsql_binary_import.cxx new file mode 100644 index 000000000..fbf12f929 --- /dev/null +++ b/dbaccess/qa/unit/hsql_binary_import.cxx @@ -0,0 +1,92 @@ +/* -*- 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 +#include +#include +#include +#include + +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() +{ + SvtMiscOptions aMiscOptions; + bool oldValue = aMiscOptions.IsExperimentalMode(); + + aMiscOptions.SetExperimentalMode(true); + // the migration requires the file to be writable + utl::TempFile const temp(createTempCopy("hsqldb_migration_test.odb")); + uno::Reference const xDocument = getDocumentForUrl(temp.GetURL()); + + uno::Reference xConnection = getConnectionForDocument(xDocument); + // at this point migration is already done + + uno::Reference statement = xConnection->createStatement(); + OUString sql{ "SELECT \"ID\", \"Power_value\", \"Power_name\", \"Retired\", " + "\"Birth_date\" FROM \"TestTable\" ORDER BY \"ID\"" }; + + uno::Reference xRes = statement->executeQuery(sql); + uno::Reference 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(xDocument, uno::UNO_QUERY)); + if (!oldValue) + aMiscOptions.SetExperimentalMode(false); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(HsqlBinaryImportTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/dbaccess/qa/unit/hsqldb.cxx b/dbaccess/qa/unit/hsqldb.cxx new file mode 100644 index 000000000..5af5dff89 --- /dev/null +++ b/dbaccess/qa/unit/hsqldb.cxx @@ -0,0 +1,49 @@ +/* -*- 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 + +using namespace ::com::sun::star; +using namespace ::com::sun::star::sdb; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::uno; + +class HSQLDBTest + : public DBTestBase +{ +public: + void testEmptyDBConnection(); + + CPPUNIT_TEST_SUITE(HSQLDBTest); + CPPUNIT_TEST(testEmptyDBConnection); + CPPUNIT_TEST_SUITE_END(); +}; + +/** + * Test the loading of an "empty" file, i.e. the embedded database has not yet + * been initialised (as occurs when a new .odb is created and opened by base). + */ +void HSQLDBTest::testEmptyDBConnection() +{ + uno::Reference< XOfficeDatabaseDocument > xDocument = + getDocumentForFileName("hsqldb_empty.odb"); + + getConnectionForDocument(xDocument); + + css::uno::Reference( + xDocument, css::uno::UNO_QUERY_THROW)->dispose(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(HSQLDBTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/qa/unit/tdf119625.cxx b/dbaccess/qa/unit/tdf119625.cxx new file mode 100644 index 000000000..8431c5426 --- /dev/null +++ b/dbaccess/qa/unit/tdf119625.cxx @@ -0,0 +1,115 @@ +/* -*- 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 +#include +#include +#include +#include +#include + +class Tdf119625Test : public DBTestBase +{ +public: + void testTime(); + + virtual void setUp() override; + + CPPUNIT_TEST_SUITE(Tdf119625Test); + + CPPUNIT_TEST(testTime); + + CPPUNIT_TEST_SUITE_END(); +}; + +void Tdf119625Test::setUp() +{ + DBTestBase::setUp(); + osl_setEnvironment(OUString{ "DBACCESS_HSQL_MIGRATION" }.pData, OUString{ "1" }.pData); +} + +namespace +{ +struct expect_t +{ + sal_Int16 id; + sal_Int16 h, m, s; +}; +} + +/* The values here assume that our results are in UTC. However, + tdf#119675 "Firebird: Migration: User dialog to set treatment of + datetime and time values during migration" is going to change the + final result of migration. If that change is implemented below + the level we are testing, this test will have to allow for or set + the destination timezone. + */ +static const expect_t expect[] + = { { 0, 15, 10, 10 }, { 1, 23, 30, 30 }, { 2, 5, 0, 0 }, { 3, 4, 30, 0 }, + { 4, 3, 15, 10 }, { 5, 5, 0, 0 }, { 6, 3, 22, 22 } }; + +void Tdf119625Test::testTime() +{ + SvtMiscOptions aMiscOptions; + bool oldValue = aMiscOptions.IsExperimentalMode(); + + aMiscOptions.SetExperimentalMode(true); + + // the migration requires the file to be writable + utl::TempFile const temp(createTempCopy("tdf119625.odb")); + uno::Reference const xDocument = getDocumentForUrl(temp.GetURL()); + + uno::Reference xConnection = getConnectionForDocument(xDocument); + // at this point migration is already done + /* In the presence of tdf#119625, terminal already has messages + + *value exceeds the range for a valid time + caused by + 'isc_dsql_execute' + + warn:dbaccess:22435:22435:dbaccess/source/filter/hsqldb/hsqlimport.cxx:373: Error during migration + + In this case, we do not expect anything good from the following + code, but I (tje, 2018-09-04) do not know how to detect this + situation. In particular, the migration has been observed to + create the destination table (but truncated after the first + row), and xConnection.is() returns true. + */ + + // select basically everything from the .odb + uno::Reference statement = xConnection->createStatement(); + const OUString sql{ " SELECT id, tst_dt, tst_d, tst_t " + " FROM tst_data " + "ORDER BY id" }; + + uno::Reference xRes = statement->executeQuery(sql); + uno::Reference xRow(xRes, UNO_QUERY_THROW); + + // check result + for (auto& e : expect) + { + CPPUNIT_ASSERT(xRes->next()); + CPPUNIT_ASSERT_EQUAL(xRow->getShort(1), e.id); + auto time_got = xRow->getTime(4); + auto time_expected = com::sun::star::util::Time(0, e.s, e.m, e.h, false); + auto equal_times = time_got == time_expected; + CPPUNIT_ASSERT(equal_times); + } + CPPUNIT_ASSERT(!xRes->next()); + + closeDocument(uno::Reference(xDocument, uno::UNO_QUERY)); + if (!oldValue) + aMiscOptions.SetExperimentalMode(false); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Tdf119625Test); + +CPPUNIT_PLUGIN_IMPLEMENT(); 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 +#include +#include +#include +#include + +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 const xDocument = getDocumentForUrl(temp.GetURL()); + + uno::Reference xConnection = getConnectionForDocument(xDocument); + + // select basically everything from the .odb + uno::Reference statement = xConnection->createStatement(); + const OUString sql{ "SELECT ID, Column1, Column2 FROM tableTest ORDER BY ID" }; + + uno::Reference xRes = statement->executeQuery(sql); + uno::Reference 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(xDocument, uno::UNO_QUERY)); + if (!oldValue) + aMiscOptions.SetExperimentalMode(false); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Tdf126268Test); + +CPPUNIT_PLUGIN_IMPLEMENT(); -- cgit v1.2.3