bump product version to 6.3.0.0.beta1
[LibreOffice.git] / dbaccess / qa / unit / dbtest_base.cxx
blob72f4e9b685f1a3dc7c9bcd54acd9bf1252a8e785
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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;
25 class DBTestBase
26 : public UnoApiTest
28 public:
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) {
44 OUString url;
45 createFileURL(pathname, url);
46 utl::TempFile tmp;
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)
51 .getStr()),
52 osl::FileBase::E_None, e);
53 return tmp;
56 uno::Reference< XOfficeDatabaseDocument >
57 DBTestBase::getDocumentForFileName(const OUString &sFileName)
59 OUString sFilePath;
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());
71 return xDocument;
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());
83 return xConnection;
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */