LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / dbaccess / qa / unit / dbtest_base.cxx
blobc7992288cdbd840fbeffc86e5abae9c23edba781
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 <string_view>
14 #include <cppunit/TestAssert.h>
16 #include <test/unoapi_test.hxx>
17 #include <unotools/tempfile.hxx>
18 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
19 #include <com/sun/star/sdbc/XConnection.hpp>
20 #include <com/sun/star/sdbc/XDataSource.hpp>
22 using namespace ::com::sun::star;
23 using namespace ::com::sun::star::sdb;
24 using namespace ::com::sun::star::sdbc;
25 using namespace ::com::sun::star::uno;
27 class DBTestBase
28 : public UnoApiTest
30 public:
31 DBTestBase() : UnoApiTest("dbaccess/qa/unit/data") {};
33 utl::TempFile createTempCopy(std::u16string_view pathname);
35 uno::Reference< XOfficeDatabaseDocument >
36 getDocumentForFileName(std::u16string_view sFileName);
38 uno::Reference<XOfficeDatabaseDocument> getDocumentForUrl(OUString const & url);
40 uno::Reference< XConnection >
41 getConnectionForDocument(
42 uno::Reference< XOfficeDatabaseDocument > const & xDocument);
45 utl::TempFile DBTestBase::createTempCopy(std::u16string_view pathname) {
46 OUString url;
47 createFileURL(pathname, url);
48 utl::TempFile tmp;
49 tmp.EnableKillingFile();
50 auto const e = osl::File::copy(url, tmp.GetURL());
51 CPPUNIT_ASSERT_EQUAL_MESSAGE(
52 (OString(
53 "<" + OUStringToOString(url, RTL_TEXTENCODING_UTF8) + "> -> <"
54 + OUStringToOString(tmp.GetURL(), RTL_TEXTENCODING_UTF8) + ">")
55 .getStr()),
56 osl::FileBase::E_None, e);
57 return tmp;
60 uno::Reference< XOfficeDatabaseDocument >
61 DBTestBase::getDocumentForFileName(std::u16string_view sFileName)
63 OUString sFilePath;
64 createFileURL(sFileName, sFilePath);
65 return getDocumentForUrl(sFilePath);
68 uno::Reference<XOfficeDatabaseDocument> DBTestBase::getDocumentForUrl(OUString const & url) {
69 uno::Reference< lang::XComponent > xComponent (loadFromDesktop(url));
70 uno::Reference< XOfficeDatabaseDocument > xDocument(xComponent, UNO_QUERY);
71 CPPUNIT_ASSERT(xDocument.is());
73 return xDocument;
76 uno::Reference< XConnection > DBTestBase::getConnectionForDocument(
77 uno::Reference< XOfficeDatabaseDocument > const & xDocument)
79 uno::Reference< XDataSource > xDataSource = xDocument->getDataSource();
80 CPPUNIT_ASSERT(xDataSource.is());
82 uno::Reference< XConnection > xConnection = xDataSource->getConnection("","");
83 CPPUNIT_ASSERT(xConnection.is());
85 return xConnection;
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */