fdo#88475 add UnitTest
Change-Id: Icc2b80cfdcb3ff6a8a4fa8d1fb30a8ce9c865c95
This commit is contained in:
parent
34f8864c9a
commit
5d47b83cef
4 changed files with 271 additions and 0 deletions
122
dbaccess/CppunitTest_dbaccess_RowSetClones.mk
Normal file
122
dbaccess/CppunitTest_dbaccess_RowSetClones.mk
Normal file
|
@ -0,0 +1,122 @@
|
|||
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
|
||||
#
|
||||
# This file is part of the LibreOffice project.
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
|
||||
$(eval $(call gb_CppunitTest_CppunitTest,dbaccess_RowSetClones))
|
||||
|
||||
$(eval $(call gb_CppunitTest_add_exception_objects,dbaccess_RowSetClones, \
|
||||
dbaccess/qa/extras/rowsetclones \
|
||||
))
|
||||
|
||||
$(eval $(call gb_CppunitTest_use_externals,dbaccess_RowSetClones,\
|
||||
boost_headers \
|
||||
))
|
||||
|
||||
$(eval $(call gb_CppunitTest_use_libraries,dbaccess_RowSetClones, \
|
||||
basegfx \
|
||||
comphelper \
|
||||
cppu \
|
||||
cppuhelper \
|
||||
dba \
|
||||
dbu \
|
||||
sdbt \
|
||||
drawinglayer \
|
||||
editeng \
|
||||
for \
|
||||
forui \
|
||||
i18nlangtag \
|
||||
msfilter \
|
||||
oox \
|
||||
sal \
|
||||
salhelper \
|
||||
sax \
|
||||
sb \
|
||||
sfx \
|
||||
sot \
|
||||
svl \
|
||||
svt \
|
||||
svx \
|
||||
svxcore \
|
||||
test \
|
||||
subsequenttest \
|
||||
tl \
|
||||
tk \
|
||||
ucbhelper \
|
||||
unotest \
|
||||
utl \
|
||||
vbahelper \
|
||||
vcl \
|
||||
xo \
|
||||
$(gb_UWINAPI) \
|
||||
))
|
||||
|
||||
$(eval $(call gb_CppunitTest_set_include,dbaccess_RowSetClones,\
|
||||
$$(INCLUDE) \
|
||||
))
|
||||
|
||||
$(eval $(call gb_CppunitTest_use_api,dbaccess_RowSetClones,\
|
||||
offapi \
|
||||
oovbaapi \
|
||||
udkapi \
|
||||
))
|
||||
|
||||
$(eval $(call gb_CppunitTest_use_ure,dbaccess_RowSetClones))
|
||||
$(eval $(call gb_CppunitTest_use_vcl,dbaccess_RowSetClones))
|
||||
|
||||
$(eval $(call gb_CppunitTest_use_components,dbaccess_RowSetClones,\
|
||||
basic/util/sb \
|
||||
comphelper/util/comphelp \
|
||||
configmgr/source/configmgr \
|
||||
connectivity/source/drivers/hsqldb/hsqldb \
|
||||
connectivity/source/drivers/jdbc/jdbc \
|
||||
connectivity/source/manager/sdbc2 \
|
||||
dbaccess/util/dba \
|
||||
dbaccess/util/dbu \
|
||||
dbaccess/util/sdbt \
|
||||
dbaccess/source/filter/xml/dbaxml \
|
||||
filter/source/config/cache/filterconfig1 \
|
||||
forms/util/frm \
|
||||
framework/util/fwk \
|
||||
i18npool/util/i18npool \
|
||||
linguistic/source/lng \
|
||||
oox/util/oox \
|
||||
package/source/xstor/xstor \
|
||||
package/util/package2 \
|
||||
sax/source/expatwrap/expwrap \
|
||||
scripting/source/basprov/basprov \
|
||||
scripting/util/scriptframe \
|
||||
sfx2/util/sfx \
|
||||
sot/util/sot \
|
||||
svl/source/fsstor/fsstorage \
|
||||
svl/util/svl \
|
||||
toolkit/util/tk \
|
||||
ucb/source/core/ucb1 \
|
||||
ucb/source/ucp/file/ucpfile1 \
|
||||
ucb/source/ucp/tdoc/ucptdoc1 \
|
||||
unotools/util/utl \
|
||||
unoxml/source/rdf/unordf \
|
||||
unoxml/source/service/unoxml \
|
||||
xmloff/util/xo \
|
||||
))
|
||||
|
||||
$(eval $(call gb_CppunitTest_use_configuration,dbaccess_RowSetClones))
|
||||
|
||||
$(eval $(call gb_CppunitTest_use_filter_configuration,dbaccess_RowSetClones))
|
||||
|
||||
$(eval $(call gb_CppunitTest_use_unittest_configuration,dbaccess_RowSetClones))
|
||||
|
||||
$(call gb_CppunitTest_get_target,dbaccess_RowSetClones) : $(WORKDIR)/CppunitTest/RowSetClones.odb
|
||||
$(WORKDIR)/CppunitTest/RowSetClones.odb : $(SRCDIR)/dbaccess/qa/extras/testdocuments/RowSetClones.odb
|
||||
mkdir -p $(dir $@)
|
||||
cp -P -f "$<" "$@"
|
||||
.PHONY: $(WORKDIR)/CppunitTest/RowSetClones.odb
|
||||
|
||||
$(call gb_CppunitTest_get_target,dbaccess_RowSetClones): \
|
||||
$(call gb_AllLangResTarget_get_target,ofa)
|
||||
|
||||
# vim: set noet sw=4 ts=4:
|
|
@ -45,6 +45,7 @@ $(eval $(call gb_Module_add_check_targets,dbaccess,\
|
|||
CppunitTest_dbaccess_empty_stdlib_save \
|
||||
CppunitTest_dbaccess_nolib_save \
|
||||
CppunitTest_dbaccess_macros_test \
|
||||
CppunitTest_dbaccess_RowSetClones \
|
||||
))
|
||||
|
||||
ifeq ($(ENABLE_JAVA),TRUE)
|
||||
|
|
148
dbaccess/qa/extras/rowsetclones.cxx
Normal file
148
dbaccess/qa/extras/rowsetclones.cxx
Normal file
|
@ -0,0 +1,148 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* This file is part of the LibreOffice project.
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <sal/config.h>
|
||||
#include <test/bootstrapfixture.hxx>
|
||||
#include <test/unoapi_test.hxx>
|
||||
#include <rtl/strbuf.hxx>
|
||||
#include <osl/file.hxx>
|
||||
#include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
|
||||
#include <com/sun/star/frame/Desktop.hpp>
|
||||
#include <com/sun/star/lang/XComponent.hpp>
|
||||
#include <com/sun/star/sdb/CommandType.hpp>
|
||||
#include <com/sun/star/sdbc/XConnection.hpp>
|
||||
#include <com/sun/star/sdbc/XResultSet.hpp>
|
||||
#include <com/sun/star/sdbc/XRow.hpp>
|
||||
#include <com/sun/star/sdbcx/XRowLocate.hpp>
|
||||
#include <com/sun/star/sdbc/XRowSet.hpp>
|
||||
#include <com/sun/star/sdb/XResultSetAccess.hpp>
|
||||
#include <com/sun/star/beans/XPropertySet.hpp>
|
||||
|
||||
#include <sfx2/app.hxx>
|
||||
#include <sfx2/docfilt.hxx>
|
||||
#include <sfx2/docfile.hxx>
|
||||
#include <sfx2/objsh.hxx>
|
||||
#include <sfx2/sfxmodelfactory.hxx>
|
||||
#include <svl/intitem.hxx>
|
||||
#include <comphelper/processfactory.hxx>
|
||||
|
||||
using namespace ::com::sun::star;
|
||||
using namespace ::com::sun::star::uno;
|
||||
using namespace ::com::sun::star::beans;
|
||||
using namespace ::com::sun::star::sdb;
|
||||
using namespace ::com::sun::star::sdbc;
|
||||
using namespace ::com::sun::star::sdbcx;
|
||||
|
||||
class RowSetClones : public UnoApiTest
|
||||
{
|
||||
public:
|
||||
RowSetClones();
|
||||
|
||||
void test();
|
||||
|
||||
CPPUNIT_TEST_SUITE(RowSetClones);
|
||||
CPPUNIT_TEST(test);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
};
|
||||
|
||||
|
||||
RowSetClones::RowSetClones()
|
||||
: UnoApiTest("")
|
||||
{
|
||||
}
|
||||
|
||||
void RowSetClones::test()
|
||||
{
|
||||
const OUString sFilePath(getURLFromWorkdir("CppunitTest/RowSetClones.odb"));
|
||||
|
||||
uno::Reference< lang::XComponent > xComponent (loadFromDesktop(sFilePath));
|
||||
CPPUNIT_ASSERT(xComponent.is());
|
||||
|
||||
uno::Reference< XOfficeDatabaseDocument > xDocument(xComponent, UNO_QUERY);
|
||||
CPPUNIT_ASSERT(xDocument.is());
|
||||
|
||||
uno::Reference< XDataSource > xDataSource = xDocument->getDataSource();
|
||||
CPPUNIT_ASSERT(xDataSource.is());
|
||||
|
||||
uno::Reference< XConnection > xConnection = xDataSource->getConnection("","");
|
||||
CPPUNIT_ASSERT(xConnection.is());
|
||||
|
||||
uno::Reference< XRowSet > xRowSet (getMultiServiceFactory()->createInstance("com.sun.star.sdb.RowSet" ), UNO_QUERY);
|
||||
CPPUNIT_ASSERT(xRowSet.is());
|
||||
uno::Reference< XPropertySet > rowSetProperties ( xRowSet, UNO_QUERY );
|
||||
CPPUNIT_ASSERT(rowSetProperties.is());
|
||||
rowSetProperties->setPropertyValue("Command", Any(OUString("SELECT * FROM Assets ORDER BY AssetID")));
|
||||
rowSetProperties->setPropertyValue("CommandType", Any(CommandType::COMMAND));
|
||||
rowSetProperties->setPropertyValue("ActiveConnection", Any(xConnection));
|
||||
|
||||
xRowSet->execute();
|
||||
uno::Reference< XResultSet > xResultSet(xRowSet, UNO_QUERY);
|
||||
CPPUNIT_ASSERT(xResultSet.is());
|
||||
// always starts at BeforeFirst position
|
||||
CPPUNIT_ASSERT(xResultSet->isBeforeFirst());
|
||||
CPPUNIT_ASSERT(xResultSet->next());
|
||||
CPPUNIT_ASSERT(xResultSet->isFirst());
|
||||
CPPUNIT_ASSERT(xResultSet->getRow() == 1);
|
||||
|
||||
uno::Reference< XRow > xRow(xResultSet, UNO_QUERY);
|
||||
CPPUNIT_ASSERT(xRow.is());
|
||||
CPPUNIT_ASSERT(xRow->getInt(1) == 1);
|
||||
|
||||
uno::Reference< XResultSetAccess > xResultSetAccess(xResultSet, UNO_QUERY);
|
||||
CPPUNIT_ASSERT(xResultSetAccess.is());
|
||||
uno::Reference< XResultSet > xResultSetClone = xResultSetAccess->createResultSet();
|
||||
CPPUNIT_ASSERT(xResultSetClone.is());
|
||||
|
||||
uno::Reference< XRow > xRowClone(xResultSetClone, UNO_QUERY);
|
||||
CPPUNIT_ASSERT(xRowClone.is());
|
||||
|
||||
// the clone starts at same position as what it is cloned from,
|
||||
// and does not move its source.
|
||||
CPPUNIT_ASSERT(xResultSetClone->isFirst());
|
||||
CPPUNIT_ASSERT(xResultSet->isFirst());
|
||||
CPPUNIT_ASSERT(xResultSet->getRow() == 1);
|
||||
CPPUNIT_ASSERT(xResultSetClone->getRow() == 1);
|
||||
CPPUNIT_ASSERT(xRow->getInt(1) == 1);
|
||||
CPPUNIT_ASSERT(xRowClone->getInt(1) == 1);
|
||||
|
||||
// if we move the source, the clone does not move
|
||||
CPPUNIT_ASSERT(xResultSet->next());
|
||||
CPPUNIT_ASSERT(xResultSetClone->isFirst());
|
||||
CPPUNIT_ASSERT(xResultSet->getRow() == 2);
|
||||
CPPUNIT_ASSERT(xResultSetClone->getRow() == 1);
|
||||
CPPUNIT_ASSERT(xRow->getInt(1) == 2);
|
||||
CPPUNIT_ASSERT(xRowClone->getInt(1) == 1);
|
||||
|
||||
CPPUNIT_ASSERT(xResultSet->last());
|
||||
CPPUNIT_ASSERT(xResultSet->isLast());
|
||||
CPPUNIT_ASSERT(xResultSetClone->isFirst());
|
||||
CPPUNIT_ASSERT(xRowClone->getInt(1) == 1);
|
||||
|
||||
// and the other way round
|
||||
CPPUNIT_ASSERT(xResultSet->first());
|
||||
CPPUNIT_ASSERT(xResultSetClone->next());
|
||||
CPPUNIT_ASSERT(xResultSet->isFirst());
|
||||
CPPUNIT_ASSERT(xResultSetClone->getRow() == 2);
|
||||
CPPUNIT_ASSERT(xRowClone->getInt(1) == 2);
|
||||
CPPUNIT_ASSERT(xRow->getInt(1) == 1);
|
||||
|
||||
CPPUNIT_ASSERT(xResultSetClone->last());
|
||||
CPPUNIT_ASSERT(xResultSetClone->isLast());
|
||||
CPPUNIT_ASSERT(xResultSet->isFirst());
|
||||
CPPUNIT_ASSERT(xRow->getInt(1) == 1);
|
||||
|
||||
closeDocument(uno::Reference<lang::XComponent>(xDocument, uno::UNO_QUERY));
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(RowSetClones);
|
||||
|
||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
BIN
dbaccess/qa/extras/testdocuments/RowSetClones.odb
Normal file
BIN
dbaccess/qa/extras/testdocuments/RowSetClones.odb
Normal file
Binary file not shown.
Loading…
Reference in a new issue