From 15d134b4f57e66faa8bcf538a08db98dc9204c54 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Fri, 15 Dec 2017 15:26:27 +0100 Subject: Make temp copy of dbaccess/qa/unit/data/firebird_empty.odb for testing ...in CppunitTest_dbaccess_firebird_test. Otherwise, the test would fail with > Test name: FirebirdTest::testEmptyDBConnection > An uncaught exception of type com.sun.star.sdbc.SQLException > - The connection can not be established. No storage or URL was given. if dbaccess/qa/unit/data/firebird_empty.odb is read-only, as DocumentStorageAccess::impl_openSubStorage_nothrow (dbaccess/source/core/dataaccess/ModelImpl.cxx) takes m_pModelImplementation->m_bDocumentReadOnly into account and returns a null xStorage. Adds a move ctor to utl::TempFile (thus causing copy ctor and copy assignment op to be implicitly deleted), but leaves any move assignment op undeclared for now, as none happens to be needed (yet). Change-Id: I6f9eff07eb54f1364a0560ffa4cf1f676a319d16 Reviewed-on: https://gerrit.libreoffice.org/46561 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- dbaccess/qa/unit/dbtest_base.cxx | 29 +++++++++++++++++++++++++++-- dbaccess/qa/unit/firebird.cxx | 3 ++- 2 files changed, 29 insertions(+), 3 deletions(-) (limited to 'dbaccess/qa') diff --git a/dbaccess/qa/unit/dbtest_base.cxx b/dbaccess/qa/unit/dbtest_base.cxx index 86914faee5c2..3541715f6b49 100644 --- a/dbaccess/qa/unit/dbtest_base.cxx +++ b/dbaccess/qa/unit/dbtest_base.cxx @@ -7,9 +7,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include + +#include + #include #include - +#include #include #include #include @@ -25,20 +29,41 @@ class DBTestBase public: DBTestBase() : UnoApiTest("dbaccess/qa/unit/data") {}; + utl::TempFile createTempCopy(OUString const & pathname); + uno::Reference< XOfficeDatabaseDocument > getDocumentForFileName(const OUString &sFileName); + uno::Reference getDocumentForUrl(OUString const & url); + uno::Reference< XConnection > getConnectionForDocument( uno::Reference< XOfficeDatabaseDocument > const & xDocument); }; +utl::TempFile DBTestBase::createTempCopy(OUString const & pathname) { + OUString url; + createFileURL(pathname, url); + utl::TempFile tmp; + tmp.EnableKillingFile(); + auto const e = osl::File::copy(url, tmp.GetURL()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + (OUStringToOString("<" + url + "> -> <" + tmp.GetURL() + ">", RTL_TEXTENCODING_UTF8) + .getStr()), + osl::FileBase::E_None, e); + return tmp; +} + uno::Reference< XOfficeDatabaseDocument > DBTestBase::getDocumentForFileName(const OUString &sFileName) { OUString sFilePath; createFileURL(sFileName, sFilePath); - uno::Reference< lang::XComponent > xComponent (loadFromDesktop(sFilePath)); + return getDocumentForUrl(sFilePath); +} + +uno::Reference DBTestBase::getDocumentForUrl(OUString const & url) { + uno::Reference< lang::XComponent > xComponent (loadFromDesktop(url)); CPPUNIT_ASSERT(xComponent.is()); uno::Reference< XOfficeDatabaseDocument > xDocument(xComponent, UNO_QUERY); diff --git a/dbaccess/qa/unit/firebird.cxx b/dbaccess/qa/unit/firebird.cxx index 16a4fb60e800..f7361ac76548 100644 --- a/dbaccess/qa/unit/firebird.cxx +++ b/dbaccess/qa/unit/firebird.cxx @@ -51,8 +51,9 @@ void FirebirdTest::setUp() */ void FirebirdTest::testEmptyDBConnection() { + auto const tmp = createTempCopy("firebird_empty.odb"); uno::Reference< XOfficeDatabaseDocument > xDocument = - getDocumentForFileName("firebird_empty.odb"); + getDocumentForUrl(tmp.GetURL()); getConnectionForDocument(xDocument); -- cgit