[Libreoffice-commits] core.git: 6 commits - dbaccess/CppunitTest_dbaccess_embeddeddb_performancetest.mk dbaccess/CppunitTest_dbaccess_firebird_test.mk dbaccess/CppunitTest_dbaccess_hsqldb_test.mk dbaccess/Module_dbaccess.mk dbaccess/qa

Andrzej J.R. Hunt andrzej at ahunt.org
Fri Sep 27 10:09:51 PDT 2013


 dbaccess/CppunitTest_dbaccess_embeddeddb_performancetest.mk |   81 ++
 dbaccess/CppunitTest_dbaccess_firebird_test.mk              |    2 
 dbaccess/CppunitTest_dbaccess_hsqldb_test.mk                |   79 ++
 dbaccess/Module_dbaccess.mk                                 |   15 
 dbaccess/qa/unit/data/hsqldb_empty.odb                      |binary
 dbaccess/qa/unit/dbtest_base.cxx                            |    6 
 dbaccess/qa/unit/embeddeddb_performancetest.cxx             |  371 ++++++++++++
 dbaccess/qa/unit/hsqldb.cxx                                 |   52 +
 8 files changed, 603 insertions(+), 3 deletions(-)

New commits:
commit 981b73c98576ea297cf8244c1cbe1ece783e5ca9
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Wed Sep 18 13:51:55 2013 +0100

    Add normal (non PreparedStatement) insert test.
    
    Change-Id: I0f6220917d8a9e8ecce30acbabf8386e73372ed3

diff --git a/dbaccess/qa/unit/embeddeddb_performancetest.cxx b/dbaccess/qa/unit/embeddeddb_performancetest.cxx
index 7832cfc..0ba4ac4 100644
--- a/dbaccess/qa/unit/embeddeddb_performancetest.cxx
+++ b/dbaccess/qa/unit/embeddeddb_performancetest.cxx
@@ -15,7 +15,11 @@
 #include <osl/time.h>
 #include <rtl/ustrbuf.hxx>
 #include <tools/stream.hxx>
+#include <unotools/tempfile.hxx>
 
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
+#include <com/sun/star/lang/XComponent.hpp>
 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
 #include <com/sun/star/sdbc/XColumnLocate.hpp>
 #include <com/sun/star/sdbc/XConnection.hpp>
@@ -24,8 +28,12 @@
 #include <com/sun/star/sdbc/XResultSet.hpp>
 #include <com/sun/star/sdbc/XRow.hpp>
 #include <com/sun/star/sdbc/XStatement.hpp>
+#include <com/sun/star/util/XCloseable.hpp>
 
 using namespace ::com::sun::star;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::lang;
 using namespace ::com::sun::star::sdb;
 using namespace ::com::sun::star::sdbc;
 using namespace ::com::sun::star::uno;
@@ -61,8 +69,11 @@ OUString getPrintableTimeValue(const TimeValue* pTimeValue)
  * 'SAL_LOG="" DBA_PERFTEST=YES make CppunitTest_dbaccess_embeddeddb_performancetest'
  * This blocks the unnecessary exception output and show only the performance data.
  *
- * You also need to create the file dbacess/qa/unit/data/wordlist, one easy way
- * of generating a list is using 'aspell dump master > dbacess/qa/unit/data/wordlist'
+ * You also need to create the file dbacess/qa/unit/data/wordlist, this list cannot
+ * contain any unescaped apostrophes (since the words are used directly to assemble
+ * sql statement), apostrophes are escaped using a double apostrophe, i.e. ''.
+ * one easy way of generating a list is using:
+ * 'for WORD in $(aspell dump master); do echo ${WORD//\'/\'\'}; done > dbaccess/qa/unit/data/wordlist'
  *
  * Note that wordlist cannot have more than 220580 lines, this is due to a hard
  * limit in our hsqldb version.
@@ -83,7 +94,9 @@ private:
 
     void printTimes(const TimeValue* pTime1, const TimeValue* pTime2, const TimeValue* pTime3);
 
-    void doPerformanceTestOnODB(const OUString& rFileName, const OUString& rDBName);
+    void doPerformanceTestOnODB(const OUString& rDriverURL,
+                                const OUString& rDBName,
+                                const bool bUsePreparedStatement);
 
     void setupTestTable(uno::Reference< XConnection >& xConnection);
 
@@ -91,6 +104,9 @@ private:
     void performPreparedStatementInsertTest(
         uno::Reference< XConnection >& xConnection,
         const OUString& rDBName);
+    void performStatementInsertTest(
+        uno::Reference< XConnection >& xConnection,
+        const OUString& rDBName);
     void performReadTest(
         uno::Reference< XConnection >& xConnection,
         const OUString& rDBName);
@@ -152,13 +168,19 @@ void EmbeddedDBPerformanceTest::testPerformance()
 
 void EmbeddedDBPerformanceTest::testFirebird()
 {
-    doPerformanceTestOnODB("firebird_empty.odb", "Firebird");
 
+    m_aOutputBuffer.append("Standard Insert\n");
+    doPerformanceTestOnODB("sdbc:embedded:firebird", "Firebird", false);
+    m_aOutputBuffer.append("PreparedStatement Insert\n");
+    doPerformanceTestOnODB("sdbc:embedded:firebird", "Firebird", true);
 }
 
 void EmbeddedDBPerformanceTest::testHSQLDB()
 {
-      doPerformanceTestOnODB("hsqldb_empty.odb", "HSQLDB");
+    m_aOutputBuffer.append("Standard Insert\n");
+    doPerformanceTestOnODB("sdbc:embedded:hsqldb", "HSQLDB", false);
+    m_aOutputBuffer.append("PreparedStatement Insert\n");
+    doPerformanceTestOnODB("sdbc:embedded:hsqldb", "HSQLDB", true);
 }
 
 /**
@@ -166,22 +188,40 @@ void EmbeddedDBPerformanceTest::testHSQLDB()
  * a table of the name PFTESTTABLE.
  */
 void EmbeddedDBPerformanceTest::doPerformanceTestOnODB(
-    const OUString& rFileName,
-    const OUString& rDBName)
+    const OUString& rDriverURL,
+    const OUString& rDBName,
+    const bool bUsePreparedStatement)
 {
-    uno::Reference< XOfficeDatabaseDocument > xDocument =
-        getDocumentForFileName(rFileName);
+    ::utl::TempFile aFile;
+    aFile.EnableKillingFile();
+
+    {
+        uno::Reference< XOfficeDatabaseDocument > xDocument(
+            m_xSFactory->createInstance("com.sun.star.sdb.OfficeDatabaseDocument"),
+            UNO_QUERY_THROW);
+        uno::Reference< XStorable > xStorable(xDocument, UNO_QUERY_THROW);
+
+        uno::Reference< XDataSource > xDataSource = xDocument->getDataSource();
+        uno::Reference< XPropertySet > xPropertySet(xDataSource, UNO_QUERY_THROW);
+        xPropertySet->setPropertyValue("URL", Any(rDriverURL));
+
+        xStorable->storeAsURL(aFile.GetURL(), uno::Sequence< beans::PropertyValue >());
+    }
+
+    uno::Reference< XOfficeDatabaseDocument > xDocument(
+        loadFromDesktop(aFile.GetURL()), UNO_QUERY_THROW);
 
     uno::Reference< XConnection > xConnection =
         getConnectionForDocument(xDocument);
 
     setupTestTable(xConnection);
 
-    performPreparedStatementInsertTest(xConnection, rDBName);
-    performReadTest(xConnection, rDBName);
-
-//     xConnection.dispose();
+    if (bUsePreparedStatement)
+        performPreparedStatementInsertTest(xConnection, rDBName);
+    else
+        performStatementInsertTest(xConnection, rDBName);
 
+    performReadTest(xConnection, rDBName);
 }
 
 void EmbeddedDBPerformanceTest::setupTestTable(
@@ -243,7 +283,53 @@ void EmbeddedDBPerformanceTest::performPreparedStatementInsertTest(
     getTimeDifference(&aStart, &aMiddle, &aTimeInsert);
     getTimeDifference(&aMiddle, &aEnd, &aTimeCommit);
     getTimeDifference(&aStart, &aEnd, &aTimeTotal);
-    m_aOutputBuffer.append("PreparedStatement Insert: " + rDBName + "\n");
+    m_aOutputBuffer.append("Insert: " + rDBName + "\n");
+    printTimes(&aTimeInsert, &aTimeCommit, &aTimeTotal);
+
+    pFile->Close();
+}
+
+void EmbeddedDBPerformanceTest::performStatementInsertTest(
+    uno::Reference< XConnection >& xConnection,
+    const OUString& rDBName)
+{
+    uno::Reference< XStatement > xStatement =
+        xConnection->createStatement();
+
+    ::boost::scoped_ptr< SvFileStream > pFile(new SvFileStream(
+            getSrcRootURL() + our_sFilePath + "wordlist",
+            STREAM_READ));
+
+    if (!pFile)
+    {
+        fprintf(stderr, "Please ensure the wordlist is present\n");
+        CPPUNIT_ASSERT(false);
+    }
+
+    OUString aWord;
+    sal_Int32 aID = 0;
+
+    TimeValue aStart, aMiddle, aEnd;
+    osl_getSystemTime(&aStart);
+
+    while (pFile->ReadByteStringLine(aWord, RTL_TEXTENCODING_UTF8))
+    {
+        xStatement->execute(
+            "INSERT INTO \"PFTESTTABLE\" ( \"ID\", "
+            "\"STRINGCOLUMNA\" "
+            ") VALUES ( "
+            + OUString::number(aID++) + ", '" + aWord + "' )"
+                    );
+    }
+    osl_getSystemTime(&aMiddle);
+    xConnection->commit();
+    osl_getSystemTime(&aEnd);
+
+    TimeValue aTimeInsert, aTimeCommit, aTimeTotal;
+    getTimeDifference(&aStart, &aMiddle, &aTimeInsert);
+    getTimeDifference(&aMiddle, &aEnd, &aTimeCommit);
+    getTimeDifference(&aStart, &aEnd, &aTimeTotal);
+    m_aOutputBuffer.append("Insert: " + rDBName + "\n");
     printTimes(&aTimeInsert, &aTimeCommit, &aTimeTotal);
 
     pFile->Close();
commit c058510595812af9254c7e95ca97e3a84c8d354d
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Wed Sep 18 09:42:16 2013 +0100

    Refactor performance test.
    
    This is to allow for comparing the use of Prepared/Normal statements.
    
    Change-Id: I6e120892f1c66f8b1c59bda309e88b2b7f39d230

diff --git a/dbaccess/qa/unit/embeddeddb_performancetest.cxx b/dbaccess/qa/unit/embeddeddb_performancetest.cxx
index 7d51102..7832cfc 100644
--- a/dbaccess/qa/unit/embeddeddb_performancetest.cxx
+++ b/dbaccess/qa/unit/embeddeddb_performancetest.cxx
@@ -85,6 +85,17 @@ private:
 
     void doPerformanceTestOnODB(const OUString& rFileName, const OUString& rDBName);
 
+    void setupTestTable(uno::Reference< XConnection >& xConnection);
+
+    // Individual Tests
+    void performPreparedStatementInsertTest(
+        uno::Reference< XConnection >& xConnection,
+        const OUString& rDBName);
+    void performReadTest(
+        uno::Reference< XConnection >& xConnection,
+        const OUString& rDBName);
+
+    // Perform all tests on a given DB.
     void testFirebird();
     void testHSQLDB();
 
@@ -164,107 +175,107 @@ void EmbeddedDBPerformanceTest::doPerformanceTestOnODB(
     uno::Reference< XConnection > xConnection =
         getConnectionForDocument(xDocument);
 
-    // Create Table
+    setupTestTable(xConnection);
+
+    performPreparedStatementInsertTest(xConnection, rDBName);
+    performReadTest(xConnection, rDBName);
+
+//     xConnection.dispose();
+
+}
+
+void EmbeddedDBPerformanceTest::setupTestTable(
+    uno::Reference< XConnection >& xConnection)
+{
+    uno::Reference< XStatement > xStatement = xConnection->createStatement();
+
+    // Although not strictly necessary we use quoted identifiers to reflect
+    // the fact that Base always uses quoted identifiers.
+    xStatement->execute(
+        "CREATE TABLE \"PFTESTTABLE\" ( \"ID\" INTEGER NOT NULL PRIMARY KEY "
+        ", \"STRINGCOLUMNA\" VARCHAR (50) "
+    ")");
+
+    xConnection->commit();
+}
+
+void EmbeddedDBPerformanceTest::performPreparedStatementInsertTest(
+    uno::Reference< XConnection >& xConnection,
+    const OUString& rDBName)
+{
+    uno::Reference< XPreparedStatement > xPreparedStatement =
+        xConnection->prepareStatement(
+            "INSERT INTO \"PFTESTTABLE\" ( \"ID\", "
+            "\"STRINGCOLUMNA\" "
+            ") VALUES ( ?, ? )"
+        );
+
+    uno::Reference< XParameters > xParameters(xPreparedStatement, UNO_QUERY_THROW);
+
+    ::boost::scoped_ptr< SvFileStream > pFile(new SvFileStream(
+            getSrcRootURL() + our_sFilePath + "wordlist",
+            STREAM_READ));
+
+    if (!pFile)
     {
-        uno::Reference< XStatement > xStatement = xConnection->createStatement();
-        CPPUNIT_ASSERT(xStatement.is());
-
-        // Although not strictly necessary we use quoted identifiers to reflect
-        // the fact that Base always uses quoted identifiers.
-        xStatement->execute(
-            "CREATE TABLE \"PFTESTTABLE\" ( \"ID\" INTEGER NOT NULL PRIMARY KEY "
-            ", \"STRINGCOLUMNA\" VARCHAR (50) "
-//             ", \"STRINGCOLUMNB\" VARCHAR (50) "
-//             ", \"STRINGCOLUMNC\" VARCHAR (50) "
-//             ", \"STRINGCOLUMND\" VARCHAR (50) "
-        ")");
-        xConnection->commit();
+        fprintf(stderr, "Please ensure the wordlist is present\n");
+        CPPUNIT_ASSERT(false);
     }
 
-    // Writing test
+    OUString aWord;
+    sal_Int32 aID = 0;
+
+    TimeValue aStart, aMiddle, aEnd;
+    osl_getSystemTime(&aStart);
+
+    while (pFile->ReadByteStringLine(aWord, RTL_TEXTENCODING_UTF8))
     {
-        uno::Reference< XPreparedStatement > xPreparedStatement =
-            xConnection->prepareStatement(
-                "INSERT INTO \"PFTESTTABLE\" ( \"ID\", "
-                "\"STRINGCOLUMNA\" "
-//                 ", \"STRINGCOLUMNB\" "
-//                 ", \"STRINGCOLUMNC\" "
-//                 ", \"STRINGCOLUMND\" "
-                ") VALUES ( ?, ?"
-//                 ", ?, ?, ? "
-                ")");
-
-        uno::Reference< XParameters > xParameters(xPreparedStatement, UNO_QUERY_THROW);
-
-        ::boost::scoped_ptr< SvFileStream > pFile(new SvFileStream(
-                getSrcRootURL() + our_sFilePath + "wordlist",
-                STREAM_READ));
-
-        if (!pFile)
-        {
-            fprintf(stderr, "Please ensure the wordlist is present\n");
-            CPPUNIT_ASSERT(false);
-        }
-
-        OUString aWord;
-        sal_Int32 aID = 0;
-
-        TimeValue aStart, aMiddle, aEnd;
-        osl_getSystemTime(&aStart);
-
-        while (pFile->ReadByteStringLine(aWord, RTL_TEXTENCODING_UTF8))
-        {
-            xParameters->setInt(1, aID++);
-            xParameters->setString(2, aWord);
-//             xParameters->setString(3, aWord);
-//             xParameters->setString(4, aWord);
-//             xParameters->setString(5, aWord);
-            xPreparedStatement->execute();
-        }
-        osl_getSystemTime(&aMiddle);
-        xConnection->commit();
-        osl_getSystemTime(&aEnd);
-
-
-        TimeValue aTimeInsert, aTimeCommit, aTimeTotal;
-        getTimeDifference(&aStart, &aMiddle, &aTimeInsert);
-        getTimeDifference(&aMiddle, &aEnd, &aTimeCommit);
-        getTimeDifference(&aStart, &aEnd, &aTimeTotal);
-        m_aOutputBuffer.append("Write to: " + rDBName + "\n");
-        printTimes(&aTimeInsert, &aTimeCommit, &aTimeTotal);
-
-        pFile->Close();
+        xParameters->setInt(1, aID++);
+        xParameters->setString(2, aWord);
+        xPreparedStatement->execute();
     }
+    osl_getSystemTime(&aMiddle);
+    xConnection->commit();
+    osl_getSystemTime(&aEnd);
 
-    // Read test
-    {
-        uno::Reference< XStatement > xStatement = xConnection->createStatement();
 
-        TimeValue aStart, aMiddle, aEnd;
-        osl_getSystemTime(&aStart);
+    TimeValue aTimeInsert, aTimeCommit, aTimeTotal;
+    getTimeDifference(&aStart, &aMiddle, &aTimeInsert);
+    getTimeDifference(&aMiddle, &aEnd, &aTimeCommit);
+    getTimeDifference(&aStart, &aEnd, &aTimeTotal);
+    m_aOutputBuffer.append("PreparedStatement Insert: " + rDBName + "\n");
+    printTimes(&aTimeInsert, &aTimeCommit, &aTimeTotal);
 
-        uno::Reference< XResultSet > xResults = xStatement->executeQuery("SELECT * FROM PFTESTTABLE");
+    pFile->Close();
+}
+
+void EmbeddedDBPerformanceTest::performReadTest(
+    uno::Reference< XConnection >& xConnection,
+    const OUString& rDBName)
+{
+    uno::Reference< XStatement > xStatement = xConnection->createStatement();
+
+    TimeValue aStart, aMiddle, aEnd;
+    osl_getSystemTime(&aStart);
 
-        osl_getSystemTime(&aMiddle);
+    uno::Reference< XResultSet > xResults = xStatement->executeQuery("SELECT * FROM PFTESTTABLE");
 
-        uno::Reference< XRow > xRow(xResults, UNO_QUERY_THROW);
+    osl_getSystemTime(&aMiddle);
 
-        while (xResults->next())
-        {
-            xRow->getString(2);
-//             xRow->getString(3);
-//             xRow->getString(4);
-//             xRow->getString(5);
-        }
-        osl_getSystemTime(&aEnd);
+    uno::Reference< XRow > xRow(xResults, UNO_QUERY_THROW);
 
-        TimeValue aTimeSelect, aTimeIterate, aTimeTotal;
-        getTimeDifference(&aStart, &aMiddle, &aTimeSelect);
-        getTimeDifference(&aMiddle, &aEnd, &aTimeIterate);
-        getTimeDifference(&aStart, &aEnd, &aTimeTotal);
-        m_aOutputBuffer.append("Read from: " + rDBName + "\n");
-        printTimes(&aTimeSelect, &aTimeIterate, &aTimeTotal);
+    while (xResults->next())
+    {
+        xRow->getString(2);
     }
+    osl_getSystemTime(&aEnd);
+
+    TimeValue aTimeSelect, aTimeIterate, aTimeTotal;
+    getTimeDifference(&aStart, &aMiddle, &aTimeSelect);
+    getTimeDifference(&aMiddle, &aEnd, &aTimeIterate);
+    getTimeDifference(&aStart, &aEnd, &aTimeTotal);
+    m_aOutputBuffer.append("Read from: " + rDBName + "\n");
+    printTimes(&aTimeSelect, &aTimeIterate, &aTimeTotal);
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(EmbeddedDBPerformanceTest);
commit 7c87a5383ae03df0f9ad0e39cfbd6f83645a659a
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Tue Sep 17 15:34:36 2013 +0100

    Implement firebird/hsqldb performance comparison test.
    
    Change-Id: Iaf28b0fcb04ee713ccae6a593e56653eac6e2eba

diff --git a/dbaccess/CppunitTest_dbaccess_embeddeddb_performancetest.mk b/dbaccess/CppunitTest_dbaccess_embeddeddb_performancetest.mk
new file mode 100644
index 0000000..a20712b
--- /dev/null
+++ b/dbaccess/CppunitTest_dbaccess_embeddeddb_performancetest.mk
@@ -0,0 +1,81 @@
+# -*- 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_embeddeddb_performancetest))
+
+$(eval $(call gb_CppunitTest_use_external,dbaccess_embeddeddb_performancetest,boost_headers))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,dbaccess_embeddeddb_performancetest, \
+    dbaccess/qa/unit/embeddeddb_performancetest \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,dbaccess_embeddeddb_performancetest, \
+    comphelper \
+    cppu \
+    cppuhelper \
+    dbaxml \
+    dbtools \
+    firebird_sdbc \
+    jvmfwk \
+    sal \
+    subsequenttest \
+    utl \
+    test \
+    tk \
+    tl \
+    unotest \
+    xo \
+    $(gb_UWINAPI) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,dbaccess_embeddeddb_performancetest,\
+    offapi \
+    oovbaapi \
+    udkapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,dbaccess_embeddeddb_performancetest))
+
+$(eval $(call gb_CppunitTest_use_components,dbaccess_embeddeddb_performancetest,\
+    basic/util/sb \
+    comphelper/util/comphelp \
+    configmgr/source/configmgr \
+    connectivity/source/cpool/dbpool2 \
+    connectivity/source/drivers/firebird/firebird_sdbc \
+    connectivity/source/drivers/hsqldb/hsqldb \
+    connectivity/source/drivers/jdbc/jdbc \
+    connectivity/source/manager/sdbc2 \
+    dbaccess/util/dba \
+    dbaccess/source/filter/xml/dbaxml \
+    dbaccess/util/dbu \
+    fileaccess/source/fileacc \
+    filter/source/config/cache/filterconfig1 \
+    framework/util/fwk \
+    i18npool/util/i18npool \
+    linguistic/source/lng \
+    package/source/xstor/xstor \
+    package/util/package2 \
+    sax/source/expatwrap/expwrap \
+    sfx2/util/sfx \
+    svl/source/fsstor/fsstorage \
+    svl/util/svl \
+    toolkit/util/tk \
+    ucb/source/core/ucb1 \
+    ucb/source/ucp/file/ucpfile1 \
+    unotools/util/utl \
+    xmloff/util/xo \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,dbaccess_embeddeddb_performancetest))
+
+$(eval $(call gb_CppunitTest_use_filter_configuration,dbaccess_embeddeddb_performancetest))
+
+$(eval $(call gb_CppunitTest_use_unittest_configuration,dbaccess_embeddeddb_performancetest))
+
+# vim: set noet sw=4 ts=4:
diff --git a/dbaccess/Module_dbaccess.mk b/dbaccess/Module_dbaccess.mk
index ce439c0..e9eb146 100644
--- a/dbaccess/Module_dbaccess.mk
+++ b/dbaccess/Module_dbaccess.mk
@@ -47,6 +47,16 @@ $(eval $(call gb_Module_add_check_targets,dbaccess,\
 ))
 endif
 
+# This runs a suite of peformance tests on embedded firebird and HSQLDB.
+# Instructions on running the test can be found in qa/unit/embeddedb_performancetest
+ifeq ($(ENABLE_FIREBIRD_SDBC),TRUE)
+ifeq ($(ENABLE_JAVA),TRUE)
+$(eval $(call gb_Module_add_check_targets,dbaccess,\
+    CppunitTest_dbaccess_embeddeddb_performancetest \
+))
+endif
+endif
+
 # disable test because it still fails in some situations
 #    CppunitTest_dbaccess_macros_test \
 #
diff --git a/dbaccess/qa/unit/embeddeddb_performancetest.cxx b/dbaccess/qa/unit/embeddeddb_performancetest.cxx
new file mode 100644
index 0000000..7d51102
--- /dev/null
+++ b/dbaccess/qa/unit/embeddeddb_performancetest.cxx
@@ -0,0 +1,274 @@
+/* -*- 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 <boost/scoped_ptr.hpp>
+#include <osl/file.hxx>
+#include <osl/process.h>
+#include <osl/time.h>
+#include <rtl/ustrbuf.hxx>
+#include <tools/stream.hxx>
+
+#include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
+#include <com/sun/star/sdbc/XColumnLocate.hpp>
+#include <com/sun/star/sdbc/XConnection.hpp>
+#include <com/sun/star/sdbc/XParameters.hpp>
+#include <com/sun/star/sdbc/XPreparedStatement.hpp>
+#include <com/sun/star/sdbc/XResultSet.hpp>
+#include <com/sun/star/sdbc/XRow.hpp>
+#include <com/sun/star/sdbc/XStatement.hpp>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::sdb;
+using namespace ::com::sun::star::sdbc;
+using namespace ::com::sun::star::uno;
+
+void normaliseTimeValue(TimeValue* pVal)
+{
+    pVal->Seconds += pVal->Nanosec / 1000000000;
+    pVal->Nanosec %= 1000000000;
+}
+
+void getTimeDifference(const TimeValue* pTimeStart,
+                       const TimeValue* pTimeEnd,
+                       TimeValue* pTimeDifference)
+{
+    // We add 1 second to the nanoseconds to ensure that we get a positive number
+    // We have to normalise anyway so this doesn't cause any harm.
+    // (Seconds/Nanosec are both unsigned)
+    pTimeDifference->Seconds = pTimeEnd->Seconds - pTimeStart->Seconds - 1;
+    pTimeDifference->Nanosec = 1000000000 + pTimeEnd->Nanosec - pTimeStart->Nanosec;
+    normaliseTimeValue(pTimeDifference);
+}
+
+OUString getPrintableTimeValue(const TimeValue* pTimeValue)
+{
+    return OUString::number(
+        (sal_uInt64(pTimeValue->Seconds) * SAL_CONST_UINT64(1000000000)
+        + sal_uInt64(pTimeValue->Nanosec))/ 1000000
+    );
+}
+
+/*
+ * The reccomended way to run this test is:
+ * 'SAL_LOG="" DBA_PERFTEST=YES make CppunitTest_dbaccess_embeddeddb_performancetest'
+ * This blocks the unnecessary exception output and show only the performance data.
+ *
+ * You also need to create the file dbacess/qa/unit/data/wordlist, one easy way
+ * of generating a list is using 'aspell dump master > dbacess/qa/unit/data/wordlist'
+ *
+ * Note that wordlist cannot have more than 220580 lines, this is due to a hard
+ * limit in our hsqldb version.
+ *
+ * Also note that this unit test "fails" when doing performance testing, this is
+ * since by default unit test output is hidden, and thus there is no way of
+ * reading the results.
+ */
+class EmbeddedDBPerformanceTest
+    : public DBTestBase
+{
+private:
+    const static OUString our_sEnableTestEnvVar;
+
+    // We store the results and print them at the end due to the amount of warning
+    // noise present which otherwise obscures the results.
+    OUStringBuffer m_aOutputBuffer;
+
+    void printTimes(const TimeValue* pTime1, const TimeValue* pTime2, const TimeValue* pTime3);
+
+    void doPerformanceTestOnODB(const OUString& rFileName, const OUString& rDBName);
+
+    void testFirebird();
+    void testHSQLDB();
+
+public:
+    void testPerformance();
+
+    CPPUNIT_TEST_SUITE(EmbeddedDBPerformanceTest);
+    CPPUNIT_TEST(testPerformance);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+void EmbeddedDBPerformanceTest::printTimes(
+    const TimeValue* pTime1,
+    const TimeValue* pTime2,
+    const TimeValue* pTime3)
+{
+    m_aOutputBuffer.append(
+        getPrintableTimeValue(pTime1) + "\t" +
+        getPrintableTimeValue(pTime2) + "\t" +
+        getPrintableTimeValue(pTime3) + "\t"
+        "\n"
+   );
+}
+
+const OUString EmbeddedDBPerformanceTest::our_sEnableTestEnvVar("DBA_PERFTEST");
+
+// TODO: we probably should create a document from scratch instead?
+
+void EmbeddedDBPerformanceTest::testPerformance()
+{
+    OUString sEnabled;
+    osl_getEnvironment(our_sEnableTestEnvVar.pData, &sEnabled.pData);
+
+    if (sEnabled.isEmpty())
+        return;
+
+    m_aOutputBuffer.append("---------------------\n");
+    testFirebird();
+    m_aOutputBuffer.append("---------------------\n");
+    testHSQLDB();
+    m_aOutputBuffer.append("---------------------\n");
+
+    fprintf(stdout, "Performance Test Results:\n");
+    fprintf(stdout, "%s",
+            OUStringToOString(m_aOutputBuffer.makeStringAndClear(),
+                              RTL_TEXTENCODING_UTF8)
+                .getStr()
+    );
+
+    // We want the results printed, but unit test output is only printed on failure
+    // Hence we deliberately fail the test.
+    CPPUNIT_ASSERT(false);
+}
+
+void EmbeddedDBPerformanceTest::testFirebird()
+{
+    doPerformanceTestOnODB("firebird_empty.odb", "Firebird");
+
+}
+
+void EmbeddedDBPerformanceTest::testHSQLDB()
+{
+      doPerformanceTestOnODB("hsqldb_empty.odb", "HSQLDB");
+}
+
+/**
+ * Use an existing .odb to do performance tests on. The database cannot have
+ * a table of the name PFTESTTABLE.
+ */
+void EmbeddedDBPerformanceTest::doPerformanceTestOnODB(
+    const OUString& rFileName,
+    const OUString& rDBName)
+{
+    uno::Reference< XOfficeDatabaseDocument > xDocument =
+        getDocumentForFileName(rFileName);
+
+    uno::Reference< XConnection > xConnection =
+        getConnectionForDocument(xDocument);
+
+    // Create Table
+    {
+        uno::Reference< XStatement > xStatement = xConnection->createStatement();
+        CPPUNIT_ASSERT(xStatement.is());
+
+        // Although not strictly necessary we use quoted identifiers to reflect
+        // the fact that Base always uses quoted identifiers.
+        xStatement->execute(
+            "CREATE TABLE \"PFTESTTABLE\" ( \"ID\" INTEGER NOT NULL PRIMARY KEY "
+            ", \"STRINGCOLUMNA\" VARCHAR (50) "
+//             ", \"STRINGCOLUMNB\" VARCHAR (50) "
+//             ", \"STRINGCOLUMNC\" VARCHAR (50) "
+//             ", \"STRINGCOLUMND\" VARCHAR (50) "
+        ")");
+        xConnection->commit();
+    }
+
+    // Writing test
+    {
+        uno::Reference< XPreparedStatement > xPreparedStatement =
+            xConnection->prepareStatement(
+                "INSERT INTO \"PFTESTTABLE\" ( \"ID\", "
+                "\"STRINGCOLUMNA\" "
+//                 ", \"STRINGCOLUMNB\" "
+//                 ", \"STRINGCOLUMNC\" "
+//                 ", \"STRINGCOLUMND\" "
+                ") VALUES ( ?, ?"
+//                 ", ?, ?, ? "
+                ")");
+
+        uno::Reference< XParameters > xParameters(xPreparedStatement, UNO_QUERY_THROW);
+
+        ::boost::scoped_ptr< SvFileStream > pFile(new SvFileStream(
+                getSrcRootURL() + our_sFilePath + "wordlist",
+                STREAM_READ));
+
+        if (!pFile)
+        {
+            fprintf(stderr, "Please ensure the wordlist is present\n");
+            CPPUNIT_ASSERT(false);
+        }
+
+        OUString aWord;
+        sal_Int32 aID = 0;
+
+        TimeValue aStart, aMiddle, aEnd;
+        osl_getSystemTime(&aStart);
+
+        while (pFile->ReadByteStringLine(aWord, RTL_TEXTENCODING_UTF8))
+        {
+            xParameters->setInt(1, aID++);
+            xParameters->setString(2, aWord);
+//             xParameters->setString(3, aWord);
+//             xParameters->setString(4, aWord);
+//             xParameters->setString(5, aWord);
+            xPreparedStatement->execute();
+        }
+        osl_getSystemTime(&aMiddle);
+        xConnection->commit();
+        osl_getSystemTime(&aEnd);
+
+
+        TimeValue aTimeInsert, aTimeCommit, aTimeTotal;
+        getTimeDifference(&aStart, &aMiddle, &aTimeInsert);
+        getTimeDifference(&aMiddle, &aEnd, &aTimeCommit);
+        getTimeDifference(&aStart, &aEnd, &aTimeTotal);
+        m_aOutputBuffer.append("Write to: " + rDBName + "\n");
+        printTimes(&aTimeInsert, &aTimeCommit, &aTimeTotal);
+
+        pFile->Close();
+    }
+
+    // Read test
+    {
+        uno::Reference< XStatement > xStatement = xConnection->createStatement();
+
+        TimeValue aStart, aMiddle, aEnd;
+        osl_getSystemTime(&aStart);
+
+        uno::Reference< XResultSet > xResults = xStatement->executeQuery("SELECT * FROM PFTESTTABLE");
+
+        osl_getSystemTime(&aMiddle);
+
+        uno::Reference< XRow > xRow(xResults, UNO_QUERY_THROW);
+
+        while (xResults->next())
+        {
+            xRow->getString(2);
+//             xRow->getString(3);
+//             xRow->getString(4);
+//             xRow->getString(5);
+        }
+        osl_getSystemTime(&aEnd);
+
+        TimeValue aTimeSelect, aTimeIterate, aTimeTotal;
+        getTimeDifference(&aStart, &aMiddle, &aTimeSelect);
+        getTimeDifference(&aMiddle, &aEnd, &aTimeIterate);
+        getTimeDifference(&aStart, &aEnd, &aTimeTotal);
+        m_aOutputBuffer.append("Read from: " + rDBName + "\n");
+        printTimes(&aTimeSelect, &aTimeIterate, &aTimeTotal);
+    }
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(EmbeddedDBPerformanceTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 2fe4dd1e8b5dbcab7e313ad007ea35bf7ff01724
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Mon Sep 16 11:15:45 2013 +0100

    Make our_sFilePath protected to allow reuse.
    
    Change-Id: Id760cfd196bb25aa1d982efa0b2b47211680c77e

diff --git a/dbaccess/qa/unit/dbtest_base.cxx b/dbaccess/qa/unit/dbtest_base.cxx
index 4b4e3a3..633a144 100644
--- a/dbaccess/qa/unit/dbtest_base.cxx
+++ b/dbaccess/qa/unit/dbtest_base.cxx
@@ -27,8 +27,8 @@ class DBTestBase
     : public ::test::BootstrapFixture
     , public ::unotest::MacrosTest
 {
-private:
-    static OUString our_sFilePath;
+protected:
+    static const OUString our_sFilePath;
 public:
     virtual void setUp();
     virtual void tearDown();
@@ -41,7 +41,7 @@ public:
             uno::Reference< XOfficeDatabaseDocument >& xDocument);
 };
 
-OUString DBTestBase::our_sFilePath("/dbaccess/qa/unit/data/");
+const OUString DBTestBase::our_sFilePath("/dbaccess/qa/unit/data/");
 
 uno::Reference< XOfficeDatabaseDocument >
     DBTestBase::getDocumentForFileName(OUString sFileName)
commit 24320dca8565a1b801dd6cc578e9592dff4d972d
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Fri Sep 13 14:00:09 2013 +0100

    Implement hsqldb loading test.
    
    Change-Id: I7dc6390b1061585054d1fa435414cae245122a1c

diff --git a/dbaccess/CppunitTest_dbaccess_hsqldb_test.mk b/dbaccess/CppunitTest_dbaccess_hsqldb_test.mk
new file mode 100644
index 0000000..66b4401
--- /dev/null
+++ b/dbaccess/CppunitTest_dbaccess_hsqldb_test.mk
@@ -0,0 +1,79 @@
+# -*- 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_hsqldb_test))
+
+$(eval $(call gb_CppunitTest_use_external,dbaccess_hsqldb_test,boost_headers))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,dbaccess_hsqldb_test, \
+    dbaccess/qa/unit/hsqldb \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,dbaccess_hsqldb_test, \
+    comphelper \
+    cppu \
+    cppuhelper \
+    dbaxml \
+    dbtools \
+    firebird_sdbc \
+    jvmfwk \
+    sal \
+    subsequenttest \
+    utl \
+    test \
+    tk \
+    unotest \
+    xo \
+    $(gb_UWINAPI) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,dbaccess_hsqldb_test,\
+    offapi \
+    oovbaapi \
+    udkapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,dbaccess_hsqldb_test))
+
+$(eval $(call gb_CppunitTest_use_components,dbaccess_hsqldb_test,\
+    basic/util/sb \
+    comphelper/util/comphelp \
+    configmgr/source/configmgr \
+    connectivity/source/cpool/dbpool2 \
+    connectivity/source/drivers/hsqldb/hsqldb \
+    connectivity/source/drivers/jdbc/jdbc \
+    connectivity/source/manager/sdbc2 \
+    dbaccess/util/dba \
+    dbaccess/source/filter/xml/dbaxml \
+    dbaccess/util/dbu \
+    fileaccess/source/fileacc \
+    filter/source/config/cache/filterconfig1 \
+    framework/util/fwk \
+    i18npool/util/i18npool \
+    linguistic/source/lng \
+    package/source/xstor/xstor \
+    package/util/package2 \
+    sax/source/expatwrap/expwrap \
+    sfx2/util/sfx \
+    svl/source/fsstor/fsstorage \
+    svl/util/svl \
+    toolkit/util/tk \
+    ucb/source/core/ucb1 \
+    ucb/source/ucp/file/ucpfile1 \
+    unotools/util/utl \
+    xmloff/util/xo \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,dbaccess_hsqldb_test))
+
+$(eval $(call gb_CppunitTest_use_filter_configuration,dbaccess_hsqldb_test))
+
+$(eval $(call gb_CppunitTest_use_unittest_configuration,dbaccess_hsqldb_test))
+
+# vim: set noet sw=4 ts=4:
diff --git a/dbaccess/Module_dbaccess.mk b/dbaccess/Module_dbaccess.mk
index eb1dbbc..ce439c0 100644
--- a/dbaccess/Module_dbaccess.mk
+++ b/dbaccess/Module_dbaccess.mk
@@ -41,6 +41,11 @@ $(eval $(call gb_Module_add_check_targets,dbaccess,\
 	CppunitTest_dbaccess_dialog_save \
 ))
 
+ifeq ($(ENABLE_JAVA),TRUE)
+$(eval $(call gb_Module_add_check_targets,dbaccess,\
+    CppunitTest_dbaccess_hsqldb_test \
+))
+endif
 
 # disable test because it still fails in some situations
 #    CppunitTest_dbaccess_macros_test \
diff --git a/dbaccess/qa/unit/data/hsqldb_empty.odb b/dbaccess/qa/unit/data/hsqldb_empty.odb
new file mode 100644
index 0000000..087c261
Binary files /dev/null and b/dbaccess/qa/unit/data/hsqldb_empty.odb differ
diff --git a/dbaccess/qa/unit/hsqldb.cxx b/dbaccess/qa/unit/hsqldb.cxx
new file mode 100644
index 0000000..5ac7b45
--- /dev/null
+++ b/dbaccess/qa/unit/hsqldb.cxx
@@ -0,0 +1,52 @@
+/* -*- 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/sdb/XOfficeDatabaseDocument.hpp>
+#include <com/sun/star/sdbc/XColumnLocate.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/sdbc/XStatement.hpp>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::sdb;
+using namespace ::com::sun::star::sdbc;
+using namespace ::com::sun::star::uno;
+
+class HSQLDBTest
+    : public DBTestBase
+{
+public:
+    void testEmptyDBConnection();
+    void testIntegerDatabase();
+
+    CPPUNIT_TEST_SUITE(HSQLDBTest);
+    CPPUNIT_TEST(testEmptyDBConnection);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+/**
+ * Test the loading of an "empty" file, i.e. the embedded database has not yet
+ * been initialised (as occurs when a new .odb is created and opened by base).
+ */
+void HSQLDBTest::testEmptyDBConnection()
+{
+    uno::Reference< XOfficeDatabaseDocument > xDocument =
+        getDocumentForFileName("hsqldb_empty.odb");
+
+    getConnectionForDocument(xDocument);
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(HSQLDBTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 1301f29e108fa5ba1e59c7c1fedf907a75756d15
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Fri Sep 13 09:47:55 2013 +0100

    Silence some (irrelevant) exceptions in firebird unit test.
    
    Change-Id: I0639b2c69f5f111e37e5566bf4cbea6719de8789

diff --git a/dbaccess/CppunitTest_dbaccess_firebird_test.mk b/dbaccess/CppunitTest_dbaccess_firebird_test.mk
index 4237e0d..9d4173c 100644
--- a/dbaccess/CppunitTest_dbaccess_firebird_test.mk
+++ b/dbaccess/CppunitTest_dbaccess_firebird_test.mk
@@ -37,6 +37,7 @@ $(eval $(call gb_CppunitTest_use_api,dbaccess_firebird_test,\
 $(eval $(call gb_CppunitTest_use_ure,dbaccess_firebird_test))
 
 $(eval $(call gb_CppunitTest_use_components,dbaccess_firebird_test,\
+    basic/util/sb \
     comphelper/util/comphelp \
     configmgr/source/configmgr \
     connectivity/source/drivers/firebird/firebird_sdbc \
@@ -58,6 +59,7 @@ $(eval $(call gb_CppunitTest_use_components,dbaccess_firebird_test,\
     toolkit/util/tk \
     ucb/source/core/ucb1 \
     ucb/source/ucp/file/ucpfile1 \
+    unotools/util/utl \
     xmloff/util/xo \
 ))
 


More information about the Libreoffice-commits mailing list