Split reusable parts of Firebird unit test into DBTestBase.

Change-Id: I6b2d131e0e4b53bb6b4cec69c5b0e99b8b9e74a7
This commit is contained in:
Andrzej J.R. Hunt
2013-09-10 10:19:26 +01:00
parent f44f94b95b
commit f7383e8b58
2 changed files with 95 additions and 54 deletions

View File

@@ -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: */

View File

@@ -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< XOfficeDatabaseDocument > xDocument =
getDocumentForFileName("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< 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< XOfficeDatabaseDocument > xDocument =
getDocumentForFileName("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< 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();