diff --git a/dbaccess/CppunitTest_dbaccess_firebird_test.mk b/dbaccess/CppunitTest_dbaccess_firebird_test.mk index 5652e6622d76..5065520993e2 100644 --- a/dbaccess/CppunitTest_dbaccess_firebird_test.mk +++ b/dbaccess/CppunitTest_dbaccess_firebird_test.mk @@ -25,6 +25,7 @@ $(eval $(call gb_CppunitTest_use_libraries,dbaccess_firebird_test, \ svt \ test \ unotest \ + utl \ xo \ )) 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); diff --git a/include/unotools/tempfile.hxx b/include/unotools/tempfile.hxx index 9f5ac4c45dab..791b51573f29 100644 --- a/include/unotools/tempfile.hxx +++ b/include/unotools/tempfile.hxx @@ -49,9 +49,6 @@ class UNOTOOLS_DLLPUBLIC TempFile bool bIsDirectory; bool bKillingFileEnabled; - TempFile( const TempFile& ) = delete; - TempFile& operator=(const TempFile&) = delete; - public: /** Create a temporary file or directory, in the default tempfile folder or if possible in a given folder. @@ -72,6 +69,8 @@ public: TempFile( const OUString& rLeadingChars, bool _bStartWithZero=true, const OUString* pExtension=nullptr, const OUString* pParent=nullptr, bool bCreateParentDirs=false ); + TempFile(TempFile && other); + /** TempFile will be removed from disk in dtor if EnableKillingFile(true) was called before. Temporary directories will be removed recursively in that case. diff --git a/unotools/source/ucbhelper/tempfile.cxx b/unotools/source/ucbhelper/tempfile.cxx index 4df84af0cb6a..eb099a43dca9 100644 --- a/unotools/source/ucbhelper/tempfile.cxx +++ b/unotools/source/ucbhelper/tempfile.cxx @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -366,6 +367,14 @@ TempFile::TempFile( const OUString& rLeadingChars, bool _bStartWithZero, true, true, bCreateParentDirs ); } +TempFile::TempFile(TempFile && other): + aName(std::move(other.aName)), pStream(other.pStream), bIsDirectory(other.bIsDirectory), + bKillingFileEnabled(other.bKillingFileEnabled) +{ + other.pStream = nullptr; + other.bKillingFileEnabled = false; +} + TempFile::~TempFile() { delete pStream;