1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #include <sal/config.h>
12 #include <cppunit/TestAssert.h>
14 #include <test/unoapi_test.hxx>
15 #include <unotools/tempfile.hxx>
16 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
17 #include <com/sun/star/sdbc/XConnection.hpp>
18 #include <com/sun/star/sdbc/XDataSource.hpp>
20 using namespace ::com::sun::star
;
21 using namespace ::com::sun::star::sdb
;
22 using namespace ::com::sun::star::sdbc
;
23 using namespace ::com::sun::star::uno
;
29 DBTestBase() : UnoApiTest("dbaccess/qa/unit/data") {};
31 utl::TempFile
createTempCopy(OUString
const & pathname
);
33 uno::Reference
< XOfficeDatabaseDocument
>
34 getDocumentForFileName(const OUString
&sFileName
);
36 uno::Reference
<XOfficeDatabaseDocument
> getDocumentForUrl(OUString
const & url
);
38 uno::Reference
< XConnection
>
39 getConnectionForDocument(
40 uno::Reference
< XOfficeDatabaseDocument
> const & xDocument
);
43 utl::TempFile
DBTestBase::createTempCopy(OUString
const & pathname
) {
45 createFileURL(pathname
, url
);
47 tmp
.EnableKillingFile();
48 auto const e
= osl::File::copy(url
, tmp
.GetURL());
49 CPPUNIT_ASSERT_EQUAL_MESSAGE(
50 (OUStringToOString("<" + url
+ "> -> <" + tmp
.GetURL() + ">", RTL_TEXTENCODING_UTF8
)
52 osl::FileBase::E_None
, e
);
56 uno::Reference
< XOfficeDatabaseDocument
>
57 DBTestBase::getDocumentForFileName(const OUString
&sFileName
)
60 createFileURL(sFileName
, sFilePath
);
61 return getDocumentForUrl(sFilePath
);
64 uno::Reference
<XOfficeDatabaseDocument
> DBTestBase::getDocumentForUrl(OUString
const & url
) {
65 uno::Reference
< lang::XComponent
> xComponent (loadFromDesktop(url
));
66 CPPUNIT_ASSERT(xComponent
.is());
68 uno::Reference
< XOfficeDatabaseDocument
> xDocument(xComponent
, UNO_QUERY
);
69 CPPUNIT_ASSERT(xDocument
.is());
74 uno::Reference
< XConnection
> DBTestBase::getConnectionForDocument(
75 uno::Reference
< XOfficeDatabaseDocument
> const & xDocument
)
77 uno::Reference
< XDataSource
> xDataSource
= xDocument
->getDataSource();
78 CPPUNIT_ASSERT(xDataSource
.is());
80 uno::Reference
< XConnection
> xConnection
= xDataSource
->getConnection("","");
81 CPPUNIT_ASSERT(xConnection
.is());
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */