dbaccess: port test from java to c++

I would like to turn this into an easyhack but first I want
to revert
commit 42190cd153
Author: Noel Grandin <noel.grandin@collabora.co.uk>
Date:   Mon Mar 31 12:38:35 2025 +0200

    Revert "Move SingleSelectQueryComposer.java tests to C++"

    This reverts commit d1ec7e9077.

    To avoid deadlocks on jenkins.

and see where CI deadlocks

Change-Id: I99a4b0ac035421cd255c51f69946b52d6ae6635f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/211888
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
This commit is contained in:
Xisco Fauli
2026-10-06 21:18:49 +02:00
parent a36c7459d1
commit 4b870e7fcf
6 changed files with 245 additions and 147 deletions
@@ -0,0 +1,58 @@
# -*- 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_rowset_test))
$(eval $(call gb_CppunitTest_use_externals,dbaccess_rowset_test, \
boost_headers \
libxml2 \
))
$(eval $(call gb_CppunitTest_add_exception_objects,dbaccess_rowset_test, \
dbaccess/qa/unit/rowset_test \
))
$(eval $(call gb_CppunitTest_use_libraries,dbaccess_rowset_test, \
comphelper \
cppu \
cppuhelper \
dbaxml \
dbtools \
sal \
subsequenttest \
utl \
test \
tk \
tl \
unotest \
xo \
))
$(eval $(call gb_CppunitTest_use_api,dbaccess_rowset_test,\
offapi \
oovbaapi \
udkapi \
))
$(eval $(call gb_CppunitTest_use_ure,dbaccess_rowset_test))
$(eval $(call gb_CppunitTest_use_vcl,dbaccess_rowset_test))
$(eval $(call gb_CppunitTest_use_rdb,dbaccess_rowset_test,services))
$(eval $(call gb_CppunitTest_use_configuration,dbaccess_rowset_test))
$(eval $(call gb_CppunitTest_use_uiconfigs,dbaccess_rowset_test, \
dbaccess \
))
$(eval $(call gb_CppunitTest_use_jars,dbaccess_rowset_test, \
sdbc_hsqldb \
))
# vim: set noet sw=4 ts=4:
+1
View File
@@ -63,6 +63,7 @@ $(eval $(call gb_Module_add_check_targets,dbaccess,\
CppunitTest_dbaccess_hsqldb_test \
CppunitTest_dbaccess_RowSetClones \
CppunitTest_dbaccess_CRMDatabase_test \
CppunitTest_dbaccess_rowset_test \
))
endif
-126
View File
@@ -812,131 +812,5 @@ public class RowSet extends TestCase
testPosition(clone, cloneRow, 1, "mixed clone/rowset move/insertion: clone check");
testPosition(m_resultSet, m_row, 100, "mixed clone/rowset move/insertion: rowset check");
}
private void testTableParameters() throws com.sun.star.uno.Exception
{
// for a row set simply based on a table, there should be not parameters at all
createRowSet("products", CommandType.TABLE, false);
verifyParameters(new String[]
{
}, "testTableParameters");
}
private void testParametersAfterNormalExecute() throws com.sun.star.uno.Exception
{
createRowSet("SELECT * FROM \"customers\"", CommandType.COMMAND, true);
m_rowSetProperties.setPropertyValue("Command", "SELECT * FROM \"customers\" WHERE \"City\" = :city");
final XParameters rowsetParams = UnoRuntime.queryInterface( XParameters.class, m_rowSet );
rowsetParams.setString(1, "London");
m_rowSet.execute();
}
private void verifyParameters(String[] _paramNames, String _context) throws com.sun.star.uno.Exception
{
final XIndexAccess params = m_paramsSupplier.getParameters();
final int expected = _paramNames.length;
final int found = params != null ? params.getCount() : 0;
assertTrue("wrong number of parameters (expected: " + expected + ", found: " + found + ") in " + _context,
found == expected);
if (found == 0)
{
return;
}
for (int i = 0; i < expected; ++i)
{
final XPropertySet parameter = UnoRuntime.queryInterface( XPropertySet.class, params.getByIndex( i ) );
final String expectedName = _paramNames[i];
final String foundName = (String) parameter.getPropertyValue("Name");
assertTrue("wrong parameter name (expected: " + expectedName + ", found: " + foundName + ") in" + _context,
expectedName.equals(foundName));
}
}
private void testParametrizedQuery() throws com.sun.star.uno.Exception
{
// for a row set based on a parametrized query, those parameters should be properly
// recognized
m_dataSource.createQuery("products like", "SELECT * FROM \"products\" WHERE \"Name\" LIKE :product_name");
createRowSet("products like", CommandType.QUERY, false);
verifyParameters(new String[]
{
"product_name"
}, "testParametrizedQuery");
}
private void testParametersInteraction() throws com.sun.star.uno.Exception
{
createRowSet("products like", CommandType.QUERY, false);
// let's fill in a parameter value via XParameters, and see whether it is respected by the parameters container
final XParameters rowsetParams = UnoRuntime.queryInterface(XParameters.class, m_rowSet);
rowsetParams.setString(1, "Apples");
XIndexAccess params = m_paramsSupplier.getParameters();
XPropertySet firstParam = UnoRuntime.queryInterface( XPropertySet.class, params.getByIndex( 0 ) );
Object firstParamValue = firstParam.getPropertyValue("Value");
assertTrue("XParameters and the parameters container do not properly interact",
"Apples".equals(firstParamValue));
// let's see whether this also survives an execute of the row set
rowsetParams.setString(1, "Oranges");
m_rowSet.execute();
{
// TODO: the following would not be necessary if the parameters container would *survive*
// the execution of the row set. It currently doesn't (though the values it represents do).
// It would be nice, but not strictly necessary, if it would.
params = m_paramsSupplier.getParameters();
firstParam = UnoRuntime.queryInterface( XPropertySet.class, params.getByIndex( 0 ) );
}
firstParamValue = firstParam.getPropertyValue("Value");
assertTrue("XParameters and the parameters container do not properly interact, after the row set has been executed",
"Oranges".equals(firstParamValue));
}
private void testParametersInFilter() throws com.sun.star.uno.Exception
{
createRowSet("SELECT * FROM \"customers\"", CommandType.COMMAND, false);
m_rowSetProperties.setPropertyValue("Filter", "\"City\" = :city");
m_rowSetProperties.setPropertyValue("ApplyFilter", Boolean.TRUE);
verifyParameters(new String[]
{
"city"
}, "testParametersInFilter");
m_rowSetProperties.setPropertyValue("ApplyFilter", Boolean.FALSE);
verifyParameters(new String[]
{
}, "testParametersInFilter");
}
/** checks the XParametersSupplier functionality of a RowSet
*/
@Test
public void testParameters() throws Exception
{
createTestCase(false);
// use an own RowSet instance, not the one which is also used for the other cases
testTableParameters();
testParametrizedQuery();
testParametersInFilter();
testParametersAfterNormalExecute();
testParametersInteraction();
}
}
-19
View File
@@ -30,7 +30,6 @@ class CRMDBTest : public DBTestBase
public:
void testCRMDatabase();
void testRegistrationName();
uno::Reference<XConnection> setUpDBConnection();
void testQueryColumns();
void testODBCEscapeQuery();
@@ -42,24 +41,9 @@ public:
CPPUNIT_TEST_SUITE_END();
};
uno::Reference<XConnection> CRMDBTest::setUpDBConnection()
{
createDBDocument(u"sdbc:embedded:hsqldb"_ustr);
uno::Reference<sdb::XOfficeDatabaseDocument> xDocument(mxComponent, UNO_QUERY_THROW);
uno::Reference<XDataSource> xDataSource = xDocument->getDataSource();
CPPUNIT_ASSERT(xDataSource.is());
// create queries before establishing connection to database
createQueries(xDataSource);
uno::Reference<XConnection> xConnection = getConnectionForDocument(xDocument);
return xConnection;
}
void CRMDBTest::testCRMDatabase()
{
uno::Reference<XConnection> xConnection = setUpDBConnection();
createTables(xConnection);
// test selection
Reference<XStatement> xStatement = xConnection->createStatement();
@@ -110,7 +94,6 @@ void CRMDBTest::testRegistrationName()
// 2. register a newly created data source, and verify it has the proper name
// Setup the CRMDatabase
uno::Reference<XConnection> xConnection = setUpDBConnection();
createTables(xConnection);
uno::Reference<sdb::XOfficeDatabaseDocument> xDocument(mxComponent, UNO_QUERY_THROW);
uno::Reference<XDataSource> xDataSource = xDocument->getDataSource();
@@ -142,7 +125,6 @@ void CRMDBTest::testQueryColumns()
// Test prepared queries return the expected column names
uno::Reference<XConnection> xConnection = setUpDBConnection();
createTables(xConnection);
uno::Reference<XQueriesSupplier> xQuerySupplier(xConnection, UNO_QUERY_THROW);
uno::Reference<container::XNameAccess> xQueryAccess = xQuerySupplier->getQueries();
@@ -175,7 +157,6 @@ void CRMDBTest::testQueryColumns()
void CRMDBTest::testODBCEscapeQuery()
{
uno::Reference<XConnection> xConnection = setUpDBConnection();
createTables(xConnection);
uno::Reference<lang::XMultiServiceFactory> xFactory(xConnection, UNO_QUERY);
CPPUNIT_ASSERT(xFactory.is());
+19 -2
View File
@@ -9,8 +9,6 @@
#include <sal/config.h>
#include <string_view>
#include <test/unoapi_test.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
@@ -47,6 +45,8 @@ public:
void createQuery(const OUString& sQuery, bool bEscapeProcessing,
const OUString& sQueryName, const Reference<XDataSource> & xDataSource);
uno::Reference<XConnection> setUpDBConnection();
virtual void tearDown() override;
};
@@ -182,6 +182,23 @@ void DBTestBase::createQuery(const OUString& sQuery, bool bEscapeProcessing, con
xNameContainer->insertByName(sQueryName, Any(xQueryProp));
}
uno::Reference<XConnection> DBTestBase::setUpDBConnection()
{
createDBDocument(u"sdbc:embedded:hsqldb"_ustr);
uno::Reference<sdb::XOfficeDatabaseDocument> xDocument(mxComponent, UNO_QUERY_THROW);
uno::Reference<XDataSource> xDataSource = xDocument->getDataSource();
CPPUNIT_ASSERT(xDataSource.is());
// create queries before establishing connection to database
createQueries(xDataSource);
uno::Reference<XConnection> xConnection = getConnectionForDocument(xDocument);
createTables(xConnection);
return xConnection;
}
void DBTestBase::tearDown()
{
if (mxComponent)
+167
View File
@@ -0,0 +1,167 @@
/* -*- 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 "dbtest_base.cxx"
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/sdb/CommandType.hpp>
#include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
#include <com/sun/star/sdb/XParametersSupplier.hpp>
#include <com/sun/star/sdbc/XParameters.hpp>
#include <com/sun/star/sdbc/XRowSet.hpp>
#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
#include <com/sun/star/util/XRefreshable.hpp>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
class RowSetTest : public DBTestBase
{
};
CPPUNIT_TEST_FIXTURE(RowSetTest, testParameters)
{
uno::Reference<XConnection> xConnection = setUpDBConnection();
Reference<XStatement> xStatement = xConnection->createStatement();
CPPUNIT_ASSERT(xStatement.is());
xStatement->execute(u"DROP TABLE \"TEST1\" IF EXISTS"_ustr);
xStatement->execute(
u"CREATE TABLE \"TEST1\" (\"ID\" INTEGER NOT NULL PRIMARY KEY, \"col2\" VARCHAR(50))"_ustr);
xConnection->prepareStatement(u"INSERT INTO \"TEST1\" VALUES (?,?)"_ustr);
Reference<XPreparedStatement> xPrepared
= xConnection->prepareStatement(u"INSERT INTO \"TEST1\" VALUES (?,?)"_ustr);
Reference<XParameters> xParams(xPrepared, UNO_QUERY);
constexpr int MAX_TABLE_ROWS = 100;
for (int i = 0; i < MAX_TABLE_ROWS; ++i)
{
xParams->setInt(1, i);
xParams->setString(2, u"Test"_ustr + OUString::number(i));
xPrepared->executeUpdate();
}
uno::Reference<sdbcx::XTablesSupplier> xTablesSupplier(xConnection, UNO_QUERY_THROW);
uno::Reference<util::XRefreshable> xTablesRefresh(xTablesSupplier->getTables(),
UNO_QUERY_THROW);
xTablesRefresh->refresh();
uno::Reference<XRowSet> xRowSet(
getMultiServiceFactory()->createInstance(u"com.sun.star.sdb.RowSet"_ustr), UNO_QUERY);
CPPUNIT_ASSERT(xRowSet.is());
uno::Reference<XPropertySet> xRowSetProperties(xRowSet, UNO_QUERY);
CPPUNIT_ASSERT(xRowSetProperties.is());
// testTableParameters
// for a row set simply based on a table, there should be not parameters at all
xRowSetProperties->setPropertyValue(u"Command"_ustr, Any(u"PRODUCTS"_ustr));
xRowSetProperties->setPropertyValue(u"CommandType"_ustr, Any(CommandType::TABLE));
xRowSetProperties->setPropertyValue(u"ActiveConnection"_ustr, Any(xConnection));
uno::Reference<XParametersSupplier> xParametersSupplier(xRowSet, UNO_QUERY);
uno::Reference<container::XIndexAccess> xIndex = xParametersSupplier->getParameters();
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndex->getCount());
// testParametrizedQuery
// for a row set based on a parametrized query, those parameters should be properly recognized
uno::Reference<sdb::XOfficeDatabaseDocument> xDocument(mxComponent, UNO_QUERY_THROW);
createQuery(u"SELECT * FROM \"PRODUCTS\" WHERE \"NAME\" LIKE :product_name"_ustr, true,
u"products like"_ustr, xDocument->getDataSource());
xRowSetProperties->setPropertyValue(u"Command"_ustr, Any(u"products like"_ustr));
xRowSetProperties->setPropertyValue(u"CommandType"_ustr, Any(CommandType::QUERY));
xRowSetProperties->setPropertyValue(u"ActiveConnection"_ustr, Any(xConnection));
xIndex.set(xParametersSupplier->getParameters());
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndex->getCount());
uno::Reference<beans::XPropertySet> xPropertySet(xIndex->getByIndex(0), UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(u"product_name"_ustr,
xPropertySet->getPropertyValue(u"Name"_ustr).get<OUString>());
// testParametersInFilter
xRowSetProperties->setPropertyValue(u"Command"_ustr, Any(u"SELECT * FROM \"CUSTOMERS\""_ustr));
xRowSetProperties->setPropertyValue(u"CommandType"_ustr, Any(CommandType::COMMAND));
xRowSetProperties->setPropertyValue(u"ActiveConnection"_ustr, Any(xConnection));
xRowSetProperties->setPropertyValue(u"Filter"_ustr, Any(u"\"CITY\" = :city"_ustr));
xRowSetProperties->setPropertyValue(u"ApplyFilter"_ustr, Any(true));
xIndex.set(xParametersSupplier->getParameters());
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndex->getCount());
xPropertySet.set(xIndex->getByIndex(0), UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(u"city"_ustr,
xPropertySet->getPropertyValue(u"Name"_ustr).get<OUString>());
xRowSetProperties->setPropertyValue(u"ApplyFilter"_ustr, Any(false));
xIndex.set(xParametersSupplier->getParameters());
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndex->getCount());
// testParametersAfterNormalExecute
xRowSetProperties->setPropertyValue(u"Command"_ustr, Any(u"SELECT * FROM \"CUSTOMERS\""_ustr));
xRowSetProperties->setPropertyValue(u"CommandType"_ustr, Any(CommandType::COMMAND));
xRowSetProperties->setPropertyValue(u"ActiveConnection"_ustr, Any(xConnection));
xRowSet->execute();
xIndex.set(xParametersSupplier->getParameters());
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndex->getCount());
xRowSetProperties->setPropertyValue(
u"Command"_ustr, Any(u"SELECT * FROM \"CUSTOMERS\" WHERE \"CITY\" = :city"_ustr));
xParams.set(xRowSet, UNO_QUERY);
xParams->setString(1, u"London"_ustr);
xRowSet->execute();
xIndex.set(xParametersSupplier->getParameters());
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndex->getCount());
xPropertySet.set(xIndex->getByIndex(0), UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(u"city"_ustr,
xPropertySet->getPropertyValue(u"Name"_ustr).get<OUString>());
CPPUNIT_ASSERT_EQUAL(u"London"_ustr,
xPropertySet->getPropertyValue(u"Value"_ustr).get<OUString>());
//testParametersInteraction
xRowSetProperties->setPropertyValue(u"Command"_ustr, Any(u"products like"_ustr));
xRowSetProperties->setPropertyValue(u"CommandType"_ustr, Any(CommandType::QUERY));
xRowSetProperties->setPropertyValue(u"ActiveConnection"_ustr, Any(xConnection));
// let's fill in a parameter value via XParameters, and see whether it is respected by the parameters container
xParams->setString(1, u"Apples"_ustr);
xIndex.set(xParametersSupplier->getParameters());
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndex->getCount());
xPropertySet.set(xIndex->getByIndex(0), UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(u"product_name"_ustr,
xPropertySet->getPropertyValue(u"Name"_ustr).get<OUString>());
CPPUNIT_ASSERT_EQUAL(u"Apples"_ustr,
xPropertySet->getPropertyValue(u"Value"_ustr).get<OUString>());
// let's fill in a parameter value via XParameters, and see whether it is respected by the parameters container
xParams->setString(1, u"Oranges"_ustr);
xRowSet->execute();
CPPUNIT_ASSERT_EQUAL(u"product_name"_ustr,
xPropertySet->getPropertyValue(u"Name"_ustr).get<OUString>());
CPPUNIT_ASSERT_EQUAL(u"Oranges"_ustr,
xPropertySet->getPropertyValue(u"Value"_ustr).get<OUString>());
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */