diff options
Diffstat (limited to 'dbaccess/qa/extras')
-rw-r--r-- | dbaccess/qa/extras/dialog-save.cxx | 102 | ||||
-rw-r--r-- | dbaccess/qa/extras/empty-stdlib-save.cxx | 114 | ||||
-rw-r--r-- | dbaccess/qa/extras/hsql_schema_import.cxx | 210 | ||||
-rw-r--r-- | dbaccess/qa/extras/macros-test.cxx | 51 | ||||
-rw-r--r-- | dbaccess/qa/extras/nolib-save.cxx | 104 | ||||
-rw-r--r-- | dbaccess/qa/extras/rowsetclones.cxx | 133 | ||||
-rw-r--r-- | dbaccess/qa/extras/testdocuments/RowSetClones.odb | bin | 0 -> 33734 bytes | |||
-rw-r--r-- | dbaccess/qa/extras/testdocuments/fdo84315.odb | bin | 0 -> 3592 bytes | |||
-rw-r--r-- | dbaccess/qa/extras/testdocuments/testDialogSave.odb | bin | 0 -> 34059 bytes | |||
-rw-r--r-- | dbaccess/qa/extras/testdocuments/testdb.odb | bin | 0 -> 3700 bytes |
10 files changed, 714 insertions, 0 deletions
diff --git a/dbaccess/qa/extras/dialog-save.cxx b/dbaccess/qa/extras/dialog-save.cxx new file mode 100644 index 000000000..212127d48 --- /dev/null +++ b/dbaccess/qa/extras/dialog-save.cxx @@ -0,0 +1,102 @@ +/* -*- 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 <sal/config.h> +#include <test/unoapi_test.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/document/XEmbeddedScripts.hpp> +#include <com/sun/star/script/XStorageBasedLibraryContainer.hpp> +#include <com/sun/star/script/XLibraryContainer.hpp> +#include <com/sun/star/util/XModifiable.hpp> +#include <com/sun/star/util/XCloseable.hpp> +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> + +#include <vcl/svapp.hxx> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + + +class DialogSaveTest : public UnoApiTest +{ +public: + DialogSaveTest(); + + void test(); + + CPPUNIT_TEST_SUITE(DialogSaveTest); +// Should we disable this test on MOX and WNT? +// #if !defined(MACOSX) && !defined(_WIN32) + CPPUNIT_TEST(test); +// #endif + CPPUNIT_TEST_SUITE_END(); + +}; + + +DialogSaveTest::DialogSaveTest() + : UnoApiTest("/dbaccess/qa/extras/testdocuments") +{ +} + +void DialogSaveTest::test() +{ + const OUString aFileName(m_directories.getURLFromWorkdir(u"CppunitTest/testDialogSave.odb")); + { + uno::Reference< lang::XComponent > xComponent = loadFromDesktop(aFileName); + uno::Reference< frame::XStorable > xDocStorable(xComponent, UNO_QUERY_THROW); + uno::Reference< document::XEmbeddedScripts > xDocScr(xComponent, UNO_QUERY_THROW); + uno::Reference< script::XStorageBasedLibraryContainer > xStorBasLib(xDocScr->getBasicLibraries()); + CPPUNIT_ASSERT(xStorBasLib.is()); + uno::Reference< script::XLibraryContainer > xBasLib(xStorBasLib, UNO_QUERY_THROW); + uno::Reference< script::XStorageBasedLibraryContainer > xStorDlgLib(xDocScr->getDialogLibraries()); + CPPUNIT_ASSERT(xStorDlgLib.is()); + uno::Reference< script::XLibraryContainer > xDlgLib(xStorDlgLib, UNO_QUERY_THROW); + static const OUStringLiteral sStandard(u"Standard"); + xBasLib->loadLibrary(sStandard); + CPPUNIT_ASSERT(xBasLib->isLibraryLoaded(sStandard)); + // the whole point of this test is to test the "save" operation + // when the Basic library is loaded, but not the Dialog library + CPPUNIT_ASSERT(!xDlgLib->isLibraryLoaded(sStandard)); + + // make some change to enable a save + // uno::Reference< document::XDocumentPropertiesSupplier > xDocPropSuppl(xComponent, UNO_QUERY_THROW); + // uno::Reference< document::XDocumentPropertiesSupplier > xDocProps(xDocPropSuppl->getDocumentProperties()); + // CPPUNIT_ASSERT(xDocProps.is()); + // xDocProps.setTitle(xDocProps.getTitle() + " suffix"); + uno::Reference< util::XModifiable > xDocMod(xComponent, UNO_QUERY_THROW); + xDocMod->setModified(true); + + // now save; the code path to exercise in this test is the "store to same location" + // do *not* change to store(As|To|URL)! + xDocStorable->store(); + + // close + uno::Reference< util::XCloseable > xDocCloseable(xComponent, UNO_QUERY_THROW); + xDocCloseable->close(false); + + // All our uno::References are (should?) be invalid now -> let them go out of scope + } + { + uno::Sequence<uno::Any> args{ uno::Any(aFileName) }; + Reference<container::XHierarchicalNameAccess> xHNA(getMultiServiceFactory()->createInstanceWithArguments("com.sun.star.packages.Package", args), UNO_QUERY_THROW); + Reference< beans::XPropertySet > xPS(xHNA->getByHierarchicalName("Dialogs/Standard/Dialog1.xml"), UNO_QUERY_THROW); + sal_Int64 nSize = 0; + CPPUNIT_ASSERT(xPS->getPropertyValue("Size") >>= nSize); + CPPUNIT_ASSERT(nSize != 0); + } +} + +CPPUNIT_TEST_SUITE_REGISTRATION(DialogSaveTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/qa/extras/empty-stdlib-save.cxx b/dbaccess/qa/extras/empty-stdlib-save.cxx new file mode 100644 index 000000000..440fc19d4 --- /dev/null +++ b/dbaccess/qa/extras/empty-stdlib-save.cxx @@ -0,0 +1,114 @@ +/* -*- 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 <sal/config.h> +#include <test/unoapi_test.hxx> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/document/XEmbeddedScripts.hpp> +#include <com/sun/star/script/XStorageBasedLibraryContainer.hpp> +#include <com/sun/star/script/XLibraryContainer.hpp> +#include <com/sun/star/util/XCloseable.hpp> +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> + +#include <vcl/svapp.hxx> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + + +class DialogSaveTest : public UnoApiTest +{ +public: + DialogSaveTest(); + + void test(); + + CPPUNIT_TEST_SUITE(DialogSaveTest); +// Should we disable this test on MOX and WNT? +// #if !defined(MACOSX) && !defined(_WIN32) + CPPUNIT_TEST(test); +// #endif + CPPUNIT_TEST_SUITE_END(); + +}; + + +DialogSaveTest::DialogSaveTest() + : UnoApiTest("/dbaccess/qa/extras/testdocuments") +{ +} + +void DialogSaveTest::test() +{ + const OUString aFileName(m_directories.getURLFromWorkdir(u"CppunitTest/testEmptyStdlibSave.odb")); + { + uno::Reference< lang::XComponent > xComponent = loadFromDesktop(aFileName); + uno::Reference< frame::XStorable > xDocStorable(xComponent, UNO_QUERY_THROW); + uno::Reference< document::XEmbeddedScripts > xDocScr(xComponent, UNO_QUERY_THROW); + uno::Reference< script::XStorageBasedLibraryContainer > xStorBasLib(xDocScr->getBasicLibraries()); + CPPUNIT_ASSERT(xStorBasLib.is()); + uno::Reference< script::XLibraryContainer > xBasLib(xStorBasLib, UNO_QUERY_THROW); + uno::Reference< script::XStorageBasedLibraryContainer > xStorDlgLib(xDocScr->getDialogLibraries()); + CPPUNIT_ASSERT(xStorDlgLib.is()); + uno::Reference< script::XLibraryContainer > xDlgLib(xStorDlgLib, UNO_QUERY_THROW); + static const OUStringLiteral sStandard(u"Standard"); + xBasLib->loadLibrary(sStandard); + xDlgLib->loadLibrary(sStandard); + CPPUNIT_ASSERT(xBasLib->isLibraryLoaded(sStandard)); + CPPUNIT_ASSERT(xDlgLib->isLibraryLoaded(sStandard)); + + Any a; + uno::Reference< container::XNameContainer > xI; + + a = xBasLib->getByName(sStandard); + a >>= xI; + CPPUNIT_ASSERT(xI.is()); + xI->removeByName("Raralix"); + + a = xDlgLib->getByName(sStandard); + a >>= xI; + CPPUNIT_ASSERT(xI.is()); + xI->removeByName("Dialog1"); + + // uno::Reference< util::XModifiable > xDlgMod(xDlgLib, UNO_QUERY_THROW); + // xDlgMod->setModified(sal_True); + + // uno::Reference< util::XModifiable > xScrMod(xDocScr, UNO_QUERY_THROW); + // xScrMod->setModified(sal_True); + + // uno::Reference< util::XModifiable > xDocMod(xComponent, UNO_QUERY_THROW); + // std::cerr << "** Modified: " << static_cast<bool>(xDocMod->isModified()) << std::endl; + // xDocMod->setModified(sal_True); + // std::cerr << "** Modified: " << static_cast<bool>(xDocMod->isModified()) << std::endl; + // CPPUNIT_ASSERT(xDocMod->isModified()); + + // now save; the code path to exercise in this test is the "store to same location" + // do *not* change to store(As|To|URL)! + xDocStorable->store(); + + // close + uno::Reference< util::XCloseable > xDocCloseable(xComponent, UNO_QUERY_THROW); + xDocCloseable->close(false); + + // All our uno::References are (should?) be invalid now -> let them go out of scope + } + { + uno::Sequence<uno::Any> args{ uno::Any(aFileName) }; + Reference<container::XHierarchicalNameAccess> xHNA(getMultiServiceFactory()->createInstanceWithArguments("com.sun.star.packages.Package", args), UNO_QUERY_THROW); + CPPUNIT_ASSERT(!xHNA->hasByHierarchicalName("Basic/Standard")); + CPPUNIT_ASSERT(!xHNA->hasByHierarchicalName("Dialogs/Standard")); + } +} + +CPPUNIT_TEST_SUITE_REGISTRATION(DialogSaveTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/qa/extras/hsql_schema_import.cxx b/dbaccess/qa/extras/hsql_schema_import.cxx new file mode 100644 index 000000000..f5f34d38b --- /dev/null +++ b/dbaccess/qa/extras/hsql_schema_import.cxx @@ -0,0 +1,210 @@ +/* -*- 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 <fbcreateparser.hxx> +#include <columndef.hxx> +#include <cppunit/plugin/TestPlugIn.h> +#include <com/sun/star/sdbc/DataType.hpp> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> + +using namespace dbahsql; + +namespace +{ +constexpr std::size_t operator"" _z(unsigned long long n) { return n; } + +const ColumnDefinition* lcl_findByType(const std::vector<ColumnDefinition>& columns, + sal_Int32 nType) +{ + for (const auto& column : columns) + { + if (column.getDataType() == nType) + return &column; + } + return nullptr; +} +} + +class HsqlSchemaImportTest : public CppUnit::TestFixture +{ +public: + void testIntegerPrimaryKeyNotNull(); + void testVarcharWithParam(); + void testVarcharWithoutParam(); + void testNumericWithTwoParam(); + void testIntegerAutoincremental(); + void testTimestampWithParam(); + void testDefaultValueNow(); + void testEvilNullColumnName(); + // TODO testForeign, testDecomposer + + CPPUNIT_TEST_SUITE(HsqlSchemaImportTest); + + CPPUNIT_TEST(testIntegerPrimaryKeyNotNull); + CPPUNIT_TEST(testVarcharWithParam); + CPPUNIT_TEST(testVarcharWithoutParam); + CPPUNIT_TEST(testNumericWithTwoParam); + CPPUNIT_TEST(testIntegerAutoincremental); + CPPUNIT_TEST(testTimestampWithParam); + CPPUNIT_TEST(testDefaultValueNow); + CPPUNIT_TEST(testEvilNullColumnName); + + CPPUNIT_TEST_SUITE_END(); +}; + +void HsqlSchemaImportTest::testIntegerPrimaryKeyNotNull() +{ + FbCreateStmtParser aCreateParser; + aCreateParser.parse(u"CREATE CACHED TABLE \"myTable\"(\"id\" INTEGER NOT NULL PRIMARY KEY)"); + + CPPUNIT_ASSERT_EQUAL(OUString{ "\"myTable\"" }, aCreateParser.getTableName()); + const auto& columns = aCreateParser.getColumnDef(); + CPPUNIT_ASSERT_EQUAL(1_z, columns.size()); + const auto& column = columns.at(0); + CPPUNIT_ASSERT_EQUAL(OUString{ "\"id\"" }, column.getName()); + CPPUNIT_ASSERT_EQUAL(css::sdbc::DataType::INTEGER, column.getDataType()); + CPPUNIT_ASSERT(column.isPrimaryKey()); + CPPUNIT_ASSERT(!column.isNullable()); + CPPUNIT_ASSERT(!column.isAutoIncremental()); +} + +void HsqlSchemaImportTest::testVarcharWithParam() +{ + FbCreateStmtParser aCreateParser; + aCreateParser.parse( + u"CREATE CACHED TABLE \"myTable\"(\"id\" INTEGER NOT NULL PRIMARY KEY, \"myText\" " + "VARCHAR(50))"); + + const auto& columns = aCreateParser.getColumnDef(); + CPPUNIT_ASSERT_EQUAL(2_z, columns.size()); + const ColumnDefinition* colVarchar = lcl_findByType(columns, css::sdbc::DataType::VARCHAR); + CPPUNIT_ASSERT(colVarchar != nullptr); + const auto& params = colVarchar->getParams(); + CPPUNIT_ASSERT_EQUAL(1_z, params.size()); + constexpr sal_Int32 nParamExpected = 50; + CPPUNIT_ASSERT_EQUAL(nParamExpected, params.at(0)); // VARCHAR(50) +} + +/** + * Special case: + * HSQLDB might define a column VARCHAR without parameter. With Firebird + * dialect, this is forbidden, so a default parameter has to be appended: + **/ +void HsqlSchemaImportTest::testVarcharWithoutParam() +{ + FbCreateStmtParser aCreateParser; + aCreateParser.parse( + u"CREATE CACHED TABLE \"myTable\"(\"id\" INTEGER NOT NULL PRIMARY KEY, \"myText\" " + "VARCHAR)"); + + const auto& columns = aCreateParser.getColumnDef(); + CPPUNIT_ASSERT_EQUAL(2_z, columns.size()); + const ColumnDefinition* colVarchar = lcl_findByType(columns, css::sdbc::DataType::VARCHAR); + CPPUNIT_ASSERT(colVarchar != nullptr); + const auto& params = colVarchar->getParams(); + CPPUNIT_ASSERT_EQUAL(1_z, params.size()); // parameter generated +} + +void HsqlSchemaImportTest::testNumericWithTwoParam() +{ + FbCreateStmtParser aCreateParser; + aCreateParser.parse( + u"CREATE CACHED TABLE \"myTable\"(\"id\" INTEGER NOT NULL PRIMARY KEY, \"Betrag\" " + "NUMERIC(8,2))"); + + const auto& columns = aCreateParser.getColumnDef(); + CPPUNIT_ASSERT_EQUAL(2_z, columns.size()); + + const ColumnDefinition* colNumeric = lcl_findByType(columns, css::sdbc::DataType::NUMERIC); + CPPUNIT_ASSERT(colNumeric != nullptr); + const auto& params = colNumeric->getParams(); + CPPUNIT_ASSERT_EQUAL(2_z, params.size()); + + constexpr sal_Int32 nPrecision = 8; + constexpr sal_Int32 nScale = 2; + CPPUNIT_ASSERT_EQUAL(nPrecision, params.at(0)); + CPPUNIT_ASSERT_EQUAL(nScale, params.at(1)); +} + +void HsqlSchemaImportTest::testIntegerAutoincremental() +{ + FbCreateStmtParser aCreateParser; + aCreateParser.parse( + u"CREATE CACHED TABLE \"myTable\"(\"id\" INTEGER NOT NULL PRIMARY KEY GENERATED " + "BY DEFAULT AS IDENTITY(START WITH 0), \"myText\" VARCHAR(50))"); + + const auto& columns = aCreateParser.getColumnDef(); + const auto column = columns.at(0); + CPPUNIT_ASSERT_EQUAL(css::sdbc::DataType::INTEGER, column.getDataType()); + CPPUNIT_ASSERT(column.isAutoIncremental()); + CPPUNIT_ASSERT(column.isPrimaryKey()); + CPPUNIT_ASSERT(!column.isNullable()); +} + +/** + * Special case: + * Hsqldb might use one parameter for defining column with type TIMESTAMP. + * With Firebird this is illegal. + */ +void HsqlSchemaImportTest::testTimestampWithParam() +{ + FbCreateStmtParser aCreateParser; + aCreateParser.parse( + u"CREATE CACHED TABLE \"myTable\"(\"id\" INTEGER NOT NULL PRIMARY KEY, \"myText\" " + "TIMESTAMP(0))"); + + const auto& columns = aCreateParser.getColumnDef(); + const ColumnDefinition* colTimeStamp = lcl_findByType(columns, css::sdbc::DataType::TIMESTAMP); + + CPPUNIT_ASSERT(colTimeStamp != nullptr); + + // instead of asserting parameter size, look at the deparsed string, + // because it's Firebird specific + OUString fbSql = aCreateParser.compose(); + CPPUNIT_ASSERT(fbSql.indexOf("0") < 0); //does not contain +} + +/** + * Special case: + * HSQLDB uses keyword NOW without quotes. Firebird uses single quotes 'NOW' + */ +void HsqlSchemaImportTest::testDefaultValueNow() +{ + FbCreateStmtParser aCreateParser; + aCreateParser.parse( + u"CREATE CACHED TABLE \"myTable\"(\"id\" INTEGER NOT NULL PRIMARY KEY, \"myDate\" " + "TIMESTAMP DEFAULT NOW)"); + + const auto& columns = aCreateParser.getColumnDef(); + const ColumnDefinition* colTimeStamp = lcl_findByType(columns, css::sdbc::DataType::TIMESTAMP); + + CPPUNIT_ASSERT(colTimeStamp != nullptr); + CPPUNIT_ASSERT_EQUAL(OUString{ "NOW" }, colTimeStamp->getDefault()); // parsed NOW + OUString fbSql = aCreateParser.compose(); + CPPUNIT_ASSERT(fbSql.indexOf("\'NOW\'") > 0); // composed 'NOW' +} + +void HsqlSchemaImportTest::testEvilNullColumnName() +{ + FbCreateStmtParser aCreateParser; + aCreateParser.parse(u"CREATE CACHED TABLE \"myTable\"(\"id\" INTEGER NOT NULL PRIMARY KEY, " + "\"myEvilNOT NULLName\" " + "VARCHAR(20))"); + + const auto& columns = aCreateParser.getColumnDef(); + CPPUNIT_ASSERT_EQUAL(2_z, columns.size()); + const ColumnDefinition* colVarchar = lcl_findByType(columns, css::sdbc::DataType::VARCHAR); + CPPUNIT_ASSERT(colVarchar != nullptr); + CPPUNIT_ASSERT(colVarchar->isNullable()); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(HsqlSchemaImportTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/dbaccess/qa/extras/macros-test.cxx b/dbaccess/qa/extras/macros-test.cxx new file mode 100644 index 000000000..dee5919c3 --- /dev/null +++ b/dbaccess/qa/extras/macros-test.cxx @@ -0,0 +1,51 @@ +/* -*- 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 <sal/config.h> +#include <test/unoapi_test.hxx> +#include <com/sun/star/util/XCloseable.hpp> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +#if !defined(MACOSX) && !defined(_WIN32) + +class DBAccessTest : public UnoApiTest +{ +public: + DBAccessTest(); + + void test(); + + CPPUNIT_TEST_SUITE(DBAccessTest); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); +}; + +DBAccessTest::DBAccessTest() + : UnoApiTest("/dbaccess/qa/extras/testdocuments") +{ +} + +void DBAccessTest::test() +{ + OUString aFileName; + createFileURL(u"testdb.odb", aFileName); + uno::Reference<lang::XComponent> xComponent = loadFromDesktop(aFileName); + uno::Reference<util::XCloseable> xDocCloseable(xComponent, UNO_QUERY_THROW); + xDocCloseable->close(false); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(DBAccessTest); + +#endif + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/qa/extras/nolib-save.cxx b/dbaccess/qa/extras/nolib-save.cxx new file mode 100644 index 000000000..59fee844f --- /dev/null +++ b/dbaccess/qa/extras/nolib-save.cxx @@ -0,0 +1,104 @@ +/* -*- 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 <sal/config.h> +#include <test/unoapi_test.hxx> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/document/XEmbeddedScripts.hpp> +#include <com/sun/star/script/XStorageBasedLibraryContainer.hpp> +#include <com/sun/star/script/XLibraryContainer.hpp> +#include <com/sun/star/util/XCloseable.hpp> +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> + +#include <vcl/svapp.hxx> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + + +class DialogSaveTest : public UnoApiTest +{ +public: + DialogSaveTest(); + + void test(); + + CPPUNIT_TEST_SUITE(DialogSaveTest); +// Should we disable this test on MOX and WNT? +// #if !defined(MACOSX) && !defined(_WIN32) + CPPUNIT_TEST(test); +// #endif + CPPUNIT_TEST_SUITE_END(); + +}; + + +DialogSaveTest::DialogSaveTest() + : UnoApiTest("/dbaccess/qa/extras/testdocuments") +{ +} + +void DialogSaveTest::test() +{ + const OUString aFileName(m_directories.getURLFromWorkdir(u"CppunitTest/testNolibSave.odb")); + { + uno::Reference< lang::XComponent > xComponent = loadFromDesktop(aFileName); + uno::Reference< frame::XStorable > xDocStorable(xComponent, UNO_QUERY_THROW); + uno::Reference< document::XEmbeddedScripts > xDocScr(xComponent, UNO_QUERY_THROW); + uno::Reference< script::XStorageBasedLibraryContainer > xStorBasLib(xDocScr->getBasicLibraries()); + CPPUNIT_ASSERT(xStorBasLib.is()); + uno::Reference< script::XLibraryContainer > xBasLib(xStorBasLib, UNO_QUERY_THROW); + uno::Reference< script::XStorageBasedLibraryContainer > xStorDlgLib(xDocScr->getDialogLibraries()); + CPPUNIT_ASSERT(xStorDlgLib.is()); + uno::Reference< script::XLibraryContainer > xDlgLib(xStorDlgLib, UNO_QUERY_THROW); + static const OUStringLiteral sStandard(u"Standard"); + xBasLib->loadLibrary(sStandard); + xDlgLib->loadLibrary(sStandard); + CPPUNIT_ASSERT(xBasLib->isLibraryLoaded(sStandard)); + CPPUNIT_ASSERT(xDlgLib->isLibraryLoaded(sStandard)); + + xBasLib->removeLibrary(sStandard); + xDlgLib->removeLibrary(sStandard); + + // uno::Reference< util::XModifiable > xDlgMod(xDlgLib, UNO_QUERY_THROW); + // xDlgMod->setModified(sal_True); + + // uno::Reference< util::XModifiable > xScrMod(xDocScr, UNO_QUERY_THROW); + // xScrMod->setModified(sal_True); + + // uno::Reference< util::XModifiable > xDocMod(xComponent, UNO_QUERY_THROW); + // std::cerr << "** Modified: " << static_cast<bool>(xDocMod->isModified()) << std::endl; + // xDocMod->setModified(sal_True); + // std::cerr << "** Modified: " << static_cast<bool>(xDocMod->isModified()) << std::endl; + // CPPUNIT_ASSERT(xDocMod->isModified()); + + // now save; the code path to exercise in this test is the "store to same location" + // do *not* change to store(As|To|URL)! + xDocStorable->store(); + + // close + uno::Reference< util::XCloseable > xDocCloseable(xComponent, UNO_QUERY_THROW); + xDocCloseable->close(false); + + // All our uno::References are (should?) be invalid now -> let them go out of scope + } + { + uno::Sequence<uno::Any> args{ uno::Any(aFileName) }; + Reference<container::XHierarchicalNameAccess> xHNA(getMultiServiceFactory()->createInstanceWithArguments("com.sun.star.packages.Package", args), UNO_QUERY_THROW); + CPPUNIT_ASSERT(!xHNA->hasByHierarchicalName("Basic/Standard")); + CPPUNIT_ASSERT(!xHNA->hasByHierarchicalName("Dialogs/Standard")); + } +} + +CPPUNIT_TEST_SUITE_REGISTRATION(DialogSaveTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/qa/extras/rowsetclones.cxx b/dbaccess/qa/extras/rowsetclones.cxx new file mode 100644 index 000000000..d83d160ca --- /dev/null +++ b/dbaccess/qa/extras/rowsetclones.cxx @@ -0,0 +1,133 @@ +/* -*- 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 <sal/config.h> +#include <test/unoapi_test.hxx> +#include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/sdb/CommandType.hpp> +#include <com/sun/star/sdbc/XConnection.hpp> +#include <com/sun/star/sdbc/XResultSet.hpp> +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbcx/XRowLocate.hpp> +#include <com/sun/star/sdbc/XRowSet.hpp> +#include <com/sun/star/sdb/XResultSetAccess.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::sdb; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::sdbcx; + +class RowSetClones : public UnoApiTest +{ +public: + RowSetClones(); + + void test(); + + CPPUNIT_TEST_SUITE(RowSetClones); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); + +}; + + +RowSetClones::RowSetClones() + : UnoApiTest("") +{ +} + +void RowSetClones::test() +{ + const OUString sFilePath(m_directories.getURLFromWorkdir(u"CppunitTest/RowSetClones.odb")); + + uno::Reference< lang::XComponent > xComponent (loadFromDesktop(sFilePath)); + uno::Reference< XOfficeDatabaseDocument > xDocument(xComponent, UNO_QUERY_THROW); + + uno::Reference< XDataSource > xDataSource = xDocument->getDataSource(); + CPPUNIT_ASSERT(xDataSource.is()); + + uno::Reference< XConnection > xConnection = xDataSource->getConnection("",""); + CPPUNIT_ASSERT(xConnection.is()); + + uno::Reference< XRowSet > xRowSet (getMultiServiceFactory()->createInstance("com.sun.star.sdb.RowSet" ), UNO_QUERY); + CPPUNIT_ASSERT(xRowSet.is()); + uno::Reference< XPropertySet > rowSetProperties ( xRowSet, UNO_QUERY ); + CPPUNIT_ASSERT(rowSetProperties.is()); + rowSetProperties->setPropertyValue("Command", Any(OUString("SELECT * FROM Assets ORDER BY AssetID"))); + rowSetProperties->setPropertyValue("CommandType", Any(CommandType::COMMAND)); + rowSetProperties->setPropertyValue("ActiveConnection", Any(xConnection)); + + xRowSet->execute(); + uno::Reference< XResultSet > xResultSet = xRowSet; + CPPUNIT_ASSERT(xResultSet.is()); + // always starts at BeforeFirst position + CPPUNIT_ASSERT(xResultSet->isBeforeFirst()); + CPPUNIT_ASSERT(xResultSet->next()); + CPPUNIT_ASSERT(xResultSet->isFirst()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xResultSet->getRow()); + + uno::Reference< XRow > xRow(xResultSet, UNO_QUERY); + CPPUNIT_ASSERT(xRow.is()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xRow->getInt(1)); + + uno::Reference< XResultSetAccess > xResultSetAccess(xResultSet, UNO_QUERY); + CPPUNIT_ASSERT(xResultSetAccess.is()); + uno::Reference< XResultSet > xResultSetClone = xResultSetAccess->createResultSet(); + CPPUNIT_ASSERT(xResultSetClone.is()); + + uno::Reference< XRow > xRowClone(xResultSetClone, UNO_QUERY); + CPPUNIT_ASSERT(xRowClone.is()); + + // the clone starts at same position as what it is cloned from, + // and does not move its source. + CPPUNIT_ASSERT(xResultSetClone->isFirst()); + CPPUNIT_ASSERT(xResultSet->isFirst()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xResultSet->getRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xResultSetClone->getRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xRow->getInt(1)); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xRowClone->getInt(1)); + + // if we move the source, the clone does not move + CPPUNIT_ASSERT(xResultSet->next()); + CPPUNIT_ASSERT(xResultSetClone->isFirst()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xResultSet->getRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xResultSetClone->getRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xRow->getInt(1)); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xRowClone->getInt(1)); + + CPPUNIT_ASSERT(xResultSet->last()); + CPPUNIT_ASSERT(xResultSet->isLast()); + CPPUNIT_ASSERT(xResultSetClone->isFirst()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xRowClone->getInt(1)); + + // and the other way round + CPPUNIT_ASSERT(xResultSet->first()); + CPPUNIT_ASSERT(xResultSetClone->next()); + CPPUNIT_ASSERT(xResultSet->isFirst()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xResultSetClone->getRow()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xRowClone->getInt(1)); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xRow->getInt(1)); + + CPPUNIT_ASSERT(xResultSetClone->last()); + CPPUNIT_ASSERT(xResultSetClone->isLast()); + CPPUNIT_ASSERT(xResultSet->isFirst()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xRow->getInt(1)); + + closeDocument(uno::Reference<lang::XComponent>(xDocument, uno::UNO_QUERY)); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(RowSetClones); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/qa/extras/testdocuments/RowSetClones.odb b/dbaccess/qa/extras/testdocuments/RowSetClones.odb Binary files differnew file mode 100644 index 000000000..91ed328ac --- /dev/null +++ b/dbaccess/qa/extras/testdocuments/RowSetClones.odb diff --git a/dbaccess/qa/extras/testdocuments/fdo84315.odb b/dbaccess/qa/extras/testdocuments/fdo84315.odb Binary files differnew file mode 100644 index 000000000..0513ff587 --- /dev/null +++ b/dbaccess/qa/extras/testdocuments/fdo84315.odb diff --git a/dbaccess/qa/extras/testdocuments/testDialogSave.odb b/dbaccess/qa/extras/testdocuments/testDialogSave.odb Binary files differnew file mode 100644 index 000000000..d72531253 --- /dev/null +++ b/dbaccess/qa/extras/testdocuments/testDialogSave.odb diff --git a/dbaccess/qa/extras/testdocuments/testdb.odb b/dbaccess/qa/extras/testdocuments/testdb.odb Binary files differnew file mode 100644 index 000000000..038e998e6 --- /dev/null +++ b/dbaccess/qa/extras/testdocuments/testdb.odb |