diff options
author | Tamas Bunth <tamas.bunth@collabora.co.uk> | 2018-03-24 18:56:11 +0100 |
---|---|---|
committer | Tamás Bunth <btomi96@gmail.com> | 2018-03-29 11:07:51 +0200 |
commit | 606cf347404f86ba3d6c94058eb4c470e9e4b596 (patch) | |
tree | 4d645e4981b361f277136dcb9fb85e5cfb00b39b /dbaccess/qa | |
parent | b15f56816515f63b89eea254a590effba47fd56f (diff) |
dbahsql: Unit test for binary import
Also fix bugs shown by the unit test
Use boost date/time instead of std, because std::tm cannot handle dates
before 1970.
Change-Id: I7f5dbb3d828a591a4b51c7204dc3bd39fefc42ff
Reviewed-on: https://gerrit.libreoffice.org/51804
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tamás Bunth <btomi96@gmail.com>
Diffstat (limited to 'dbaccess/qa')
-rw-r--r-- | dbaccess/qa/unit/data/hsqldb_migration_test.odb | bin | 0 -> 3949 bytes | |||
-rw-r--r-- | dbaccess/qa/unit/hsql_binary_import.cxx | 94 |
2 files changed, 94 insertions, 0 deletions
diff --git a/dbaccess/qa/unit/data/hsqldb_migration_test.odb b/dbaccess/qa/unit/data/hsqldb_migration_test.odb Binary files differnew file mode 100644 index 000000000000..99b6b5d9a69d --- /dev/null +++ b/dbaccess/qa/unit/data/hsqldb_migration_test.odb diff --git a/dbaccess/qa/unit/hsql_binary_import.cxx b/dbaccess/qa/unit/hsql_binary_import.cxx new file mode 100644 index 000000000000..3afe7bd55396 --- /dev/null +++ b/dbaccess/qa/unit/hsql_binary_import.cxx @@ -0,0 +1,94 @@ +/* -*- 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 <hsqlimport.hxx> + +#include <osl/process.h> +#include <cppunit/plugin/TestPlugIn.h> +#include <com/sun/star/sdbc/DataType.hpp> +#include <com/sun/star/sdbc/XRow.hpp> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <test/unoapi_test.hxx> +#include <svtools/miscopt.hxx> + +using namespace dbahsql; + +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(); + SvtMiscOptions aMiscOptions; + aMiscOptions.SetExperimentalMode(true); + osl_setEnvironment(OUString{ "DBACCESS_HSQL_MIGRATION" }.pData, OUString{ "1" }.pData); +} + +void HsqlBinaryImportTest::testBinaryImport() +{ + uno::Reference<XOfficeDatabaseDocument> xDocument + = getDocumentForFileName("hsqldb_migration_test.odb"); + + uno::Reference<XConnection> xConnection = getConnectionForDocument(xDocument); + // at this point migration is already done + + uno::Reference<XStatement> statement = xConnection->createStatement(); + OUString sql{ "SELECT \"ID\", \"Power_value\", \"Power_name\", \"Retired\", " + "\"Birth_date\" FROM \"TestTable\" ORDER BY \"ID\"" }; + + uno::Reference<XResultSet> xRes = statement->executeQuery(sql); + uno::Reference<XRow> xRow(xRes, UNO_QUERY_THROW); + + // assert first row + 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 + 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)); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(HsqlBinaryImportTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); |