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 <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
@@ -25,6 +25,7 @@ $(eval $(call gb_CppunitTest_use_libraries,dbaccess_firebird_test, \
|
|||||||
svt \
|
svt \
|
||||||
test \
|
test \
|
||||||
unotest \
|
unotest \
|
||||||
|
utl \
|
||||||
xo \
|
xo \
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@@ -7,9 +7,13 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sal/config.h>
|
||||||
|
|
||||||
|
#include <cppunit/TestAssert.h>
|
||||||
|
|
||||||
#include <comphelper/processfactory.hxx>
|
#include <comphelper/processfactory.hxx>
|
||||||
#include <test/unoapi_test.hxx>
|
#include <test/unoapi_test.hxx>
|
||||||
|
#include <unotools/tempfile.hxx>
|
||||||
#include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
|
#include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
|
||||||
#include <com/sun/star/sdbc/XConnection.hpp>
|
#include <com/sun/star/sdbc/XConnection.hpp>
|
||||||
#include <com/sun/star/sdbc/XDataSource.hpp>
|
#include <com/sun/star/sdbc/XDataSource.hpp>
|
||||||
@@ -25,20 +29,41 @@ class DBTestBase
|
|||||||
public:
|
public:
|
||||||
DBTestBase() : UnoApiTest("dbaccess/qa/unit/data") {};
|
DBTestBase() : UnoApiTest("dbaccess/qa/unit/data") {};
|
||||||
|
|
||||||
|
utl::TempFile createTempCopy(OUString const & pathname);
|
||||||
|
|
||||||
uno::Reference< XOfficeDatabaseDocument >
|
uno::Reference< XOfficeDatabaseDocument >
|
||||||
getDocumentForFileName(const OUString &sFileName);
|
getDocumentForFileName(const OUString &sFileName);
|
||||||
|
|
||||||
|
uno::Reference<XOfficeDatabaseDocument> getDocumentForUrl(OUString const & url);
|
||||||
|
|
||||||
uno::Reference< XConnection >
|
uno::Reference< XConnection >
|
||||||
getConnectionForDocument(
|
getConnectionForDocument(
|
||||||
uno::Reference< XOfficeDatabaseDocument > const & xDocument);
|
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 >
|
uno::Reference< XOfficeDatabaseDocument >
|
||||||
DBTestBase::getDocumentForFileName(const OUString &sFileName)
|
DBTestBase::getDocumentForFileName(const OUString &sFileName)
|
||||||
{
|
{
|
||||||
OUString sFilePath;
|
OUString sFilePath;
|
||||||
createFileURL(sFileName, sFilePath);
|
createFileURL(sFileName, sFilePath);
|
||||||
uno::Reference< lang::XComponent > xComponent (loadFromDesktop(sFilePath));
|
return getDocumentForUrl(sFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
uno::Reference<XOfficeDatabaseDocument> DBTestBase::getDocumentForUrl(OUString const & url) {
|
||||||
|
uno::Reference< lang::XComponent > xComponent (loadFromDesktop(url));
|
||||||
CPPUNIT_ASSERT(xComponent.is());
|
CPPUNIT_ASSERT(xComponent.is());
|
||||||
|
|
||||||
uno::Reference< XOfficeDatabaseDocument > xDocument(xComponent, UNO_QUERY);
|
uno::Reference< XOfficeDatabaseDocument > xDocument(xComponent, UNO_QUERY);
|
||||||
|
@@ -51,8 +51,9 @@ void FirebirdTest::setUp()
|
|||||||
*/
|
*/
|
||||||
void FirebirdTest::testEmptyDBConnection()
|
void FirebirdTest::testEmptyDBConnection()
|
||||||
{
|
{
|
||||||
|
auto const tmp = createTempCopy("firebird_empty.odb");
|
||||||
uno::Reference< XOfficeDatabaseDocument > xDocument =
|
uno::Reference< XOfficeDatabaseDocument > xDocument =
|
||||||
getDocumentForFileName("firebird_empty.odb");
|
getDocumentForUrl(tmp.GetURL());
|
||||||
|
|
||||||
getConnectionForDocument(xDocument);
|
getConnectionForDocument(xDocument);
|
||||||
|
|
||||||
|
@@ -49,9 +49,6 @@ class UNOTOOLS_DLLPUBLIC TempFile
|
|||||||
bool bIsDirectory;
|
bool bIsDirectory;
|
||||||
bool bKillingFileEnabled;
|
bool bKillingFileEnabled;
|
||||||
|
|
||||||
TempFile( const TempFile& ) = delete;
|
|
||||||
TempFile& operator=(const TempFile&) = delete;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
Create a temporary file or directory, in the default tempfile folder or if possible in a given folder.
|
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,
|
TempFile( const OUString& rLeadingChars, bool _bStartWithZero=true, const OUString* pExtension=nullptr,
|
||||||
const OUString* pParent=nullptr, bool bCreateParentDirs=false );
|
const OUString* pParent=nullptr, bool bCreateParentDirs=false );
|
||||||
|
|
||||||
|
TempFile(TempFile && other);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
TempFile will be removed from disk in dtor if EnableKillingFile(true) was called before.
|
TempFile will be removed from disk in dtor if EnableKillingFile(true) was called before.
|
||||||
Temporary directories will be removed recursively in that case.
|
Temporary directories will be removed recursively in that case.
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
#include <sal/config.h>
|
#include <sal/config.h>
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include <com/sun/star/ucb/UniversalContentBroker.hpp>
|
#include <com/sun/star/ucb/UniversalContentBroker.hpp>
|
||||||
#include <comphelper/processfactory.hxx>
|
#include <comphelper/processfactory.hxx>
|
||||||
@@ -366,6 +367,14 @@ TempFile::TempFile( const OUString& rLeadingChars, bool _bStartWithZero,
|
|||||||
true, true, bCreateParentDirs );
|
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()
|
TempFile::~TempFile()
|
||||||
{
|
{
|
||||||
delete pStream;
|
delete pStream;
|
||||||
|
Reference in New Issue
Block a user