dbaccess/JunitTest_dbaccess_complex.mk  |    1 
 dbaccess/qa/complex/dbaccess/Query.java |  107 --------------------------------
 dbaccess/qa/unit/CRMDatabase_test.cxx   |   46 +++++++++++++
 3 files changed, 46 insertions(+), 108 deletions(-)

New commits:
commit dd386eddfdfe77c0b14cf2ed84243f066aadefb0
Author:     Adam Seskunas <adamsesku...@gmail.com>
AuthorDate: Sat Oct 12 02:19:29 2024 -0700
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Jan 14 09:22:55 2025 +0100

    Port Query.java test to CppUnit
    
    dbaccess/qa/unit/CRMDatabase_test.cxx add test
    dbaccess/qa/complex/dbaccess remove Query.java
    dbaccess/JunitTest_dbaccess_complex.mk remove test call
    
    Change-Id: If21863de1fa4db738e3d51f93a3c7ca19130bb1e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177278
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Tested-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/dbaccess/JunitTest_dbaccess_complex.mk 
b/dbaccess/JunitTest_dbaccess_complex.mk
index 99a3cd9f5cbc..04609c4413f0 100644
--- a/dbaccess/JunitTest_dbaccess_complex.mk
+++ b/dbaccess/JunitTest_dbaccess_complex.mk
@@ -38,7 +38,6 @@ $(eval $(call gb_JunitTest_add_sourcefiles,dbaccess_complex,\
     dbaccess/qa/complex/dbaccess/FileHelper \
     dbaccess/qa/complex/dbaccess/Parser \
     dbaccess/qa/complex/dbaccess/PropertyBag \
-    dbaccess/qa/complex/dbaccess/Query \
     dbaccess/qa/complex/dbaccess/QueryInQuery \
     dbaccess/qa/complex/dbaccess/RowSet \
     dbaccess/qa/complex/dbaccess/RowSetEventListener \
diff --git a/dbaccess/qa/complex/dbaccess/Query.java 
b/dbaccess/qa/complex/dbaccess/Query.java
deleted file mode 100644
index 8881bb3edecb..000000000000
--- a/dbaccess/qa/complex/dbaccess/Query.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-package complex.dbaccess;
-
-import com.sun.star.beans.XPropertySet;
-import com.sun.star.container.XIndexAccess;
-import com.sun.star.container.XNameAccess;
-import com.sun.star.container.XNamed;
-import com.sun.star.sdb.XQueriesSupplier;
-import com.sun.star.sdbcx.XColumnsSupplier;
-import com.sun.star.uno.UnoRuntime;
-import connectivity.tools.CRMDatabase;
-
-// ---------- junit imports -----------------
-import org.junit.Test;
-import static org.junit.Assert.*;
-
-
-public class Query extends TestCase
-{
-
-    connectivity.tools.HsqlDatabase m_database;
-
-
-    private void createTestCase()
-    {
-        try
-        {
-            if (m_database == null)
-            {
-                final CRMDatabase database = new CRMDatabase(getMSF(), false);
-                m_database = database.getDatabase();
-            }
-        }
-        catch (Exception e)
-        {
-            System.out.println("could not create the test case, error message:
" + e.getMessage());
-            e.printStackTrace(System.err);
-            fail("failed to created the test case");
-        }
-    }
-
-
-    @Test
-    public void testQueryColumns()
-    {
-        createTestCase();
-
-        try
-        {
-            final XQueriesSupplier suppQueries = UnoRuntime.queryInterface(
-                XQueriesSupplier.class, 
m_database.defaultConnection().getXConnection() );
-            final XNameAccess queries = suppQueries.getQueries();
-
-            final String[] queryNames = new String[] { "parseable", "parseable 
native", "unparseable" };
-            final String[][] expectedColumnNames = new String[][] {
-                new String[] { "ID", "Name", "Address", "City", 
"Postal","Comment" },
-                new String[] { "TABLE_CATALOG", "TABLE_SCHEMA", "TABLE_NAME", 
"VIEW_DEFINITION", "CHECK_OPTION", "IS_UPDATABLE", "VALID" },
-                new String[] { "ID_VARCHAR" }
-            };
-
-            for ( int i = 0; i < queryNames.length; ++i )
-            {
-                if (queries.hasByName(queryNames[i]))
-                {
-                    final XPropertySet query = UnoRuntime.queryInterface(
-                        XPropertySet.class, queries.getByName( queryNames[i] ) 
);
-
-                    final XColumnsSupplier suppCols = 
UnoRuntime.queryInterface(
-                        XColumnsSupplier.class, query);
-                    final XIndexAccess columns = UnoRuntime.queryInterface(
-                                XIndexAccess.class, suppCols.getColumns());
-
-                    // check whether the columns supplied by the query match 
what we expected
-                    assertTrue( "invalid column count (found " + 
columns.getCount() + ", expected: " + expectedColumnNames[i].length + ") for 
query \"" + queryNames[i] + "\"",
-                        columns.getCount() == expectedColumnNames[i].length );
-                    for ( int col = 0; col < columns.getCount(); ++col )
-                    {
-                        final XNamed columnName = UnoRuntime.queryInterface(
-                            XNamed.class, columns.getByIndex(col) );
-                        assertTrue( "column no. " + col + " of query \"" + 
queryNames[i] + "\" not matching",
-                            columnName.getName().equals( 
expectedColumnNames[i][col] ) );
-                    }
-                }
-            }
-        }
-        catch ( Exception e )
-        {
-            fail( "caught an unexpected exception: " + e.getMessage() );
-        }
-    }
-}
diff --git a/dbaccess/qa/unit/CRMDatabase_test.cxx 
b/dbaccess/qa/unit/CRMDatabase_test.cxx
index 9b61b85f8a12..adb9a9af479b 100644
--- a/dbaccess/qa/unit/CRMDatabase_test.cxx
+++ b/dbaccess/qa/unit/CRMDatabase_test.cxx
@@ -32,10 +32,12 @@ public:
     void testCRMDatabase();
     void testRegistrationName();
     uno::Reference<XConnection> setUpDBConnection();
+    void testQueryColumns();
 
     CPPUNIT_TEST_SUITE(CRMDBTest);
     CPPUNIT_TEST(testCRMDatabase);
     CPPUNIT_TEST(testRegistrationName);
+    CPPUNIT_TEST(testQueryColumns);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -134,6 +136,50 @@ void CRMDBTest::testRegistrationName()
         container::ElementExistException);
 }
 
+void CRMDBTest::testQueryColumns()
+{
+    // Ported from dbaccess/Query.java
+    // Test prepared queries return the expected column names
+
+    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);
+
+    uno::Reference<XQueriesSupplier> xQuerySupplier(xConnection, 
UNO_QUERY_THROW);
+    uno::Reference<container::XNameAccess> xQueryAccess = 
xQuerySupplier->getQueries();
+    CPPUNIT_ASSERT(xQueryAccess->hasElements());
+
+    Sequence<OUString> queryNames{ u"parseable"_ustr, u"parseable native"_ustr 
};
+
+    Sequence<Sequence<OUString>> expectedColumnNames{
+        { u"ID"_ustr, u"NAME"_ustr, u"ADDRESS"_ustr, u"CITY"_ustr, 
u"POSTAL"_ustr,
+          u"COMMENT"_ustr },
+        { u"TABLE_CATALOG"_ustr, u"TABLE_SCHEMA"_ustr, u"TABLE_NAME"_ustr, 
u"VIEW_DEFINITION"_ustr,
+          u"CHECK_OPTION"_ustr, u"IS_UPDATABLE"_ustr, u"VALID"_ustr }
+    };
+
+    for (sal_uInt32 i = 0; i < queryNames.size(); ++i)
+    {
+        uno::Reference<sdbcx::XColumnsSupplier> 
xColumns(xQueryAccess->getByName(queryNames[i]),
+                                                         UNO_QUERY);
+        uno::Reference<container::XNameAccess> 
xColumnAccess(xColumns->getColumns());
+        CPPUNIT_ASSERT(xColumnAccess->hasElements());
+        Sequence<OUString> ColumnNames = xColumnAccess->getElementNames();
+
+        for (sal_uInt32 j = 0; j < expectedColumnNames[i].size(); ++j)
+        {
+            CPPUNIT_ASSERT_EQUAL(expectedColumnNames[i][j], ColumnNames[j]);
+        }
+    }
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(CRMDBTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();

Reply via email to