Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : */
9 :
10 : #include <comphelper/processfactory.hxx>
11 : #include <test/unoapi_test.hxx>
12 :
13 : #include <com/sun/star/frame/XModel.hpp>
14 : #include <com/sun/star/frame/Desktop.hpp>
15 : #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
16 : #include <com/sun/star/sdbc/XConnection.hpp>
17 : #include <com/sun/star/sdbc/XDataSource.hpp>
18 :
19 : using namespace ::com::sun::star;
20 : using namespace ::com::sun::star::frame;
21 : using namespace ::com::sun::star::sdb;
22 : using namespace ::com::sun::star::sdbc;
23 : using namespace ::com::sun::star::uno;
24 :
25 8 : class DBTestBase
26 : : public UnoApiTest
27 : {
28 : protected:
29 : static const OUString our_sFilePath;
30 : public:
31 8 : DBTestBase() : UnoApiTest("dbaccess/qa/unit/data") {};
32 :
33 : uno::Reference< XOfficeDatabaseDocument >
34 : getDocumentForFileName(const OUString &sFileName);
35 :
36 : uno::Reference< XConnection >
37 : getConnectionForDocument(
38 : uno::Reference< XOfficeDatabaseDocument >& xDocument);
39 : };
40 :
41 : uno::Reference< XOfficeDatabaseDocument >
42 6 : DBTestBase::getDocumentForFileName(const OUString &sFileName)
43 : {
44 6 : OUString sFilePath;
45 6 : createFileURL(sFileName, sFilePath);
46 12 : uno::Reference< lang::XComponent > xComponent (loadFromDesktop(sFilePath));
47 6 : CPPUNIT_ASSERT(xComponent.is());
48 :
49 6 : uno::Reference< XOfficeDatabaseDocument > xDocument(xComponent, UNO_QUERY);
50 6 : CPPUNIT_ASSERT(xDocument.is());
51 :
52 12 : return xDocument;
53 : }
54 :
55 6 : uno::Reference< XConnection > DBTestBase::getConnectionForDocument(
56 : uno::Reference< XOfficeDatabaseDocument >& xDocument)
57 : {
58 6 : uno::Reference< XDataSource > xDataSource = xDocument->getDataSource();
59 6 : CPPUNIT_ASSERT(xDataSource.is());
60 :
61 6 : uno::Reference< XConnection > xConnection = xDataSource->getConnection("","");
62 6 : CPPUNIT_ASSERT(xConnection.is());
63 :
64 6 : return xConnection;
65 : }
66 :
67 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|