From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- dbaccess/qa/unit/firebird.cxx | 125 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 dbaccess/qa/unit/firebird.cxx (limited to 'dbaccess/qa/unit/firebird.cxx') diff --git a/dbaccess/qa/unit/firebird.cxx b/dbaccess/qa/unit/firebird.cxx new file mode 100644 index 000000000..7a8143810 --- /dev/null +++ b/dbaccess/qa/unit/firebird.cxx @@ -0,0 +1,125 @@ +/* -*- 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(); + void testTdf132924(); + + CPPUNIT_TEST_SUITE(FirebirdTest); + CPPUNIT_TEST(testEmptyDBConnection); + CPPUNIT_TEST(testIntegerDatabase); + CPPUNIT_TEST(testTdf132924); + 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(u"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(u"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)); +} + +void FirebirdTest::testTdf132924() +{ + uno::Reference xDocument = getDocumentForFileName(u"tdf132924.odb"); + uno::Reference xConnection = getConnectionForDocument(xDocument); + + uno::Reference xStatement = xConnection->createStatement(); + CPPUNIT_ASSERT(xStatement.is()); + + uno::Reference xResultSet = xStatement->executeQuery("SELECT * FROM AliasTest"); + CPPUNIT_ASSERT(xResultSet.is()); + CPPUNIT_ASSERT(xResultSet->next()); + + uno::Reference xRow(xResultSet, UNO_QUERY); + CPPUNIT_ASSERT(xRow.is()); + uno::Reference xColumnLocate(xRow, UNO_QUERY); + CPPUNIT_ASSERT(xColumnLocate.is()); + + // Without the fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : The column name 'TestId' is not valid + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), xRow->getShort(xColumnLocate->findColumn("TestId"))); + CPPUNIT_ASSERT_EQUAL(OUString("TestName"), xRow->getString(xColumnLocate->findColumn("TestName"))); + + closeDocument(uno::Reference(xDocument, uno::UNO_QUERY)); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(FirebirdTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3