diff options
author | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2013-09-10 10:19:26 +0100 |
---|---|---|
committer | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2013-09-10 11:28:33 +0100 |
commit | f7383e8b58903410210ff72348636976f9229be2 (patch) | |
tree | 103dd067cff23cd342ede155680511e0c19554a7 /dbaccess | |
parent | f44f94b95b435ee0ec71c73133daeb88cd2539b1 (diff) |
Split reusable parts of Firebird unit test into DBTestBase.
Change-Id: I6b2d131e0e4b53bb6b4cec69c5b0e99b8b9e74a7
Diffstat (limited to 'dbaccess')
-rw-r--r-- | dbaccess/qa/unit/dbtest_base.cxx | 86 | ||||
-rw-r--r-- | dbaccess/qa/unit/firebird.cxx | 63 |
2 files changed, 95 insertions, 54 deletions
diff --git a/dbaccess/qa/unit/dbtest_base.cxx b/dbaccess/qa/unit/dbtest_base.cxx new file mode 100644 index 000000000000..4b4e3a32e9f2 --- /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 <comphelper/processfactory.hxx> +#include <test/bootstrapfixture.hxx> +#include <unotest/macros_test.hxx> + +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp> +#include <com/sun/star/sdbc/XConnection.hpp> +#include <com/sun/star/sdbc/XDataSource.hpp> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::frame; +using namespace ::com::sun::star::sdb; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::uno; + +class DBTestBase + : public ::test::BootstrapFixture + , public ::unotest::MacrosTest +{ +private: + static OUString our_sFilePath; +public: + virtual void setUp(); + virtual void tearDown(); + + uno::Reference< XOfficeDatabaseDocument > + getDocumentForFileName(OUString sFileName); + + uno::Reference< XConnection > + getConnectionForDocument( + uno::Reference< XOfficeDatabaseDocument >& xDocument); +}; + +OUString DBTestBase::our_sFilePath("/dbaccess/qa/unit/data/"); + +uno::Reference< XOfficeDatabaseDocument > + DBTestBase::getDocumentForFileName(OUString sFileName) +{ + uno::Reference< lang::XComponent > xComponent = + loadFromDesktop(getSrcRootURL() + our_sFilePath + sFileName); + 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 >& xDocument) +{ + uno::Reference< XDataSource > xDataSource = xDocument->getDataSource(); + CPPUNIT_ASSERT(xDataSource.is()); + + uno::Reference< XConnection > xConnection = xDataSource->getConnection("",""); + CPPUNIT_ASSERT(xConnection.is()); + + return xConnection; +} + + +void DBTestBase::setUp() +{ + ::test::BootstrapFixture::setUp(); + + mxDesktop = ::com::sun::star::frame::Desktop::create( + ::comphelper::getProcessComponentContext()); + CPPUNIT_ASSERT(mxDesktop.is()); +} + +void DBTestBase::tearDown() +{ + test::BootstrapFixture::tearDown(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/qa/unit/firebird.cxx b/dbaccess/qa/unit/firebird.cxx index fb8234dc52c9..183d83dfbcd1 100644 --- a/dbaccess/qa/unit/firebird.cxx +++ b/dbaccess/qa/unit/firebird.cxx @@ -7,34 +7,24 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <comphelper/processfactory.hxx> -#include <test/bootstrapfixture.hxx> -#include <unotest/macros_test.hxx> +#include "dbtest_base.cxx" -#include <com/sun/star/frame/XModel.hpp> -#include <com/sun/star/frame/Desktop.hpp> #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp> #include <com/sun/star/sdbc/XColumnLocate.hpp> #include <com/sun/star/sdbc/XConnection.hpp> -#include <com/sun/star/sdbc/XDataSource.hpp> #include <com/sun/star/sdbc/XResultSet.hpp> #include <com/sun/star/sdbc/XRow.hpp> #include <com/sun/star/sdbc/XStatement.hpp> using namespace ::com::sun::star; -using namespace ::com::sun::star::frame; using namespace ::com::sun::star::sdb; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::uno; class FirebirdTest - : public ::test::BootstrapFixture - , public ::unotest::MacrosTest + : public DBTestBase { public: - virtual void setUp(); - virtual void tearDown(); - void testEmptyDBConnection(); void testIntegerDatabase(); @@ -44,28 +34,16 @@ public: CPPUNIT_TEST_SUITE_END(); }; -// TODO: refactor the load file -> get Connection stuff into a separate class - /** * 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() { - const OUString sFileName("/dbaccess/qa/unit/data/firebird_empty.odb"); - - uno::Reference< lang::XComponent > xComponent = loadFromDesktop( - getSrcRootURL() + sFileName); - CPPUNIT_ASSERT(xComponent.is()); - - uno::Reference< XOfficeDatabaseDocument > xDocument(xComponent, UNO_QUERY); - CPPUNIT_ASSERT(xDocument.is()); + uno::Reference< XOfficeDatabaseDocument > xDocument = + getDocumentForFileName("firebird_empty.odb"); - uno::Reference< XDataSource > xDataSource = xDocument->getDataSource(); - CPPUNIT_ASSERT(xDataSource.is()); - - uno::Reference< XConnection > xConnection = xDataSource->getConnection("",""); - CPPUNIT_ASSERT(xConnection.is()); + getConnectionForDocument(xDocument); } /** @@ -74,20 +52,11 @@ void FirebirdTest::testEmptyDBConnection() */ void FirebirdTest::testIntegerDatabase() { - const OUString sFileName("/dbaccess/qa/unit/data/firebird_integer_x64le.odb"); - - uno::Reference< lang::XComponent > xComponent = loadFromDesktop( - getSrcRootURL() + sFileName); - CPPUNIT_ASSERT(xComponent.is()); - - uno::Reference< XOfficeDatabaseDocument > xDocument(xComponent, UNO_QUERY); - CPPUNIT_ASSERT(xDocument.is()); - - uno::Reference< XDataSource > xDataSource = xDocument->getDataSource(); - CPPUNIT_ASSERT(xDataSource.is()); + uno::Reference< XOfficeDatabaseDocument > xDocument = + getDocumentForFileName("firebird_integer_x64le.odb"); - uno::Reference< XConnection > xConnection = xDataSource->getConnection("",""); - CPPUNIT_ASSERT(xConnection.is()); + uno::Reference< XConnection > xConnection = + getConnectionForDocument(xDocument); uno::Reference< XStatement > xStatement = xConnection->createStatement(); CPPUNIT_ASSERT(xStatement.is()); @@ -116,20 +85,6 @@ void FirebirdTest::testIntegerDatabase() CPPUNIT_ASSERT(!xResultSet->next()); // Should only be one row } -void FirebirdTest::setUp() -{ - ::test::BootstrapFixture::setUp(); - - mxDesktop = ::com::sun::star::frame::Desktop::create( - ::comphelper::getProcessComponentContext()); - CPPUNIT_ASSERT(mxDesktop.is()); -} - -void FirebirdTest::tearDown() -{ - test::BootstrapFixture::tearDown(); -} - CPPUNIT_TEST_SUITE_REGISTRATION(FirebirdTest); CPPUNIT_PLUGIN_IMPLEMENT(); |