diff options
author | Sergio Ahumada <sergio.ahumada@nokia.com> | 2012-01-09 18:49:04 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-03 06:47:05 (GMT) |
commit | 687344ec72d2c36786a031f9c44da6df3f8f2110 (patch) | |
tree | eb9385407399b7e70faf56f7c8eef5fdd9fe1f48 /tests | |
parent | bf4ff951186bf717e911e759a9c6972d24c8fa59 (diff) | |
download | Qt-687344ec72d2c36786a031f9c44da6df3f8f2110.zip Qt-687344ec72d2c36786a031f9c44da6df3f8f2110.tar.gz Qt-687344ec72d2c36786a031f9c44da6df3f8f2110.tar.bz2 |
test: Split `qsqlquery' unit and benchmark test
Moving benchmark test from 'tests/auto' to 'tests/benchmarks'.
Also removing 'qttest_p4' usage while we are at it.
- void benchmark();
was moved to 'tests/benchmarks/sql/kernel/qsqlquery'
Change-Id: Icbe88fecdfe24a7754079451f635f9c19b3d6683
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qsqlquery/qsqlquery.pro | 7 | ||||
-rw-r--r-- | tests/auto/qsqlquery/tst_qsqlquery.cpp | 35 | ||||
-rw-r--r-- | tests/benchmarks/benchmarks.pro | 1 | ||||
-rw-r--r-- | tests/benchmarks/sql/kernel/kernel.pro | 3 | ||||
-rw-r--r-- | tests/benchmarks/sql/kernel/qsqlquery/main.cpp | 273 | ||||
-rw-r--r-- | tests/benchmarks/sql/kernel/qsqlquery/qsqlquery.pro | 6 | ||||
-rw-r--r-- | tests/benchmarks/sql/sql.pro | 3 |
7 files changed, 290 insertions, 38 deletions
diff --git a/tests/auto/qsqlquery/qsqlquery.pro b/tests/auto/qsqlquery/qsqlquery.pro index fbcc998..7acc040 100644 --- a/tests/auto/qsqlquery/qsqlquery.pro +++ b/tests/auto/qsqlquery/qsqlquery.pro @@ -1,7 +1,8 @@ -load(qttest_p4) -SOURCES += tst_qsqlquery.cpp +CONFIG += testcase -QT = core sql +TARGET = tst_qsqlquery +QT = core sql testlib +SOURCES += tst_qsqlquery.cpp !wince*:win32:LIBS += -lws2_32 diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp index 482b70f..7d2c547 100644 --- a/tests/auto/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp @@ -219,11 +219,6 @@ private slots: void sqlite_constraint_data() { generic_data("QSQLITE"); } void sqlite_constraint(); -#if 0 - void benchmark_data() { generic_data(); } - void benchmark(); -#endif - void sqlite_real_data() { generic_data("QSQLITE"); } void sqlite_real(); @@ -3283,36 +3278,6 @@ void tst_QSqlQuery::sqlite_constraint() QCOMPARE(q.lastError().databaseText(), QLatin1String("Raised Abort successfully")); } -#if 0 -void tst_QSqlQuery::benchmark() -{ - QFETCH( QString, dbName ); - QSqlDatabase db = QSqlDatabase::database( dbName ); - CHECK_DATABASE( db ); - if ( tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 0 ).toInt()<5 ) - QSKIP( "Test requires MySQL >= 5.0", SkipSingle ); - - QSqlQuery q(db); - const QString tableName(qTableName("benchmark", __FILE__)); - - tst_Databases::safeDropTable( db, tableName ); - - QVERIFY_SQL(q, exec("CREATE TABLE "+tableName+"(\n" - "MainKey INT NOT NULL,\n" - "OtherTextCol VARCHAR(45) NOT NULL,\n" - "PRIMARY KEY(`MainKey`))")); - - int i=1; - - QBENCHMARK { - QVERIFY_SQL(q, exec("INSERT INTO "+tableName+" VALUES("+QString::number(i)+", \"Value"+QString::number(i)+"\")")); - i++; - } - - tst_Databases::safeDropTable( db, tableName ); -} -#endif - void tst_QSqlQuery::sqlite_real() { QFETCH(QString, dbName); diff --git a/tests/benchmarks/benchmarks.pro b/tests/benchmarks/benchmarks.pro index b5e3a4b..4196dc0 100644 --- a/tests/benchmarks/benchmarks.pro +++ b/tests/benchmarks/benchmarks.pro @@ -4,6 +4,7 @@ SUBDIRS = \ gui \ network \ script \ + sql \ svg contains(QT_CONFIG, opengl): SUBDIRS += opengl contains(QT_CONFIG, declarative): SUBDIRS += declarative diff --git a/tests/benchmarks/sql/kernel/kernel.pro b/tests/benchmarks/sql/kernel/kernel.pro new file mode 100644 index 0000000..f907fee --- /dev/null +++ b/tests/benchmarks/sql/kernel/kernel.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs +SUBDIRS = \ + qsqlquery \ diff --git a/tests/benchmarks/sql/kernel/qsqlquery/main.cpp b/tests/benchmarks/sql/kernel/qsqlquery/main.cpp new file mode 100644 index 0000000..48c9a10 --- /dev/null +++ b/tests/benchmarks/sql/kernel/qsqlquery/main.cpp @@ -0,0 +1,273 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <QtSql/QtSql> + +#include "../../../../auto/qsqldatabase/tst_databases.h" + +const QString qtest(qTableName( "qtest", __FILE__ )); + +class tst_QSqlQuery : public QObject +{ + Q_OBJECT + +public: + tst_QSqlQuery(); + virtual ~tst_QSqlQuery(); + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void benchmark_data() { generic_data(); } + void benchmark(); + +private: + // returns all database connections + void generic_data(const QString &engine=QString()); + void dropTestTables( QSqlDatabase db ); + void createTestTables( QSqlDatabase db ); + void populateTestTables( QSqlDatabase db ); + + tst_Databases dbs; +}; + +QTEST_MAIN(tst_QSqlQuery) + +tst_QSqlQuery::tst_QSqlQuery() +{ +} + +tst_QSqlQuery::~tst_QSqlQuery() +{ +} + +void tst_QSqlQuery::initTestCase() +{ + dbs.open(); + + for ( QStringList::ConstIterator it = dbs.dbNames.begin(); it != dbs.dbNames.end(); ++it ) { + QSqlDatabase db = QSqlDatabase::database(( *it ) ); + CHECK_DATABASE( db ); + dropTestTables( db ); //in case of leftovers + createTestTables( db ); + populateTestTables( db ); + } +} + +void tst_QSqlQuery::cleanupTestCase() +{ + for ( QStringList::ConstIterator it = dbs.dbNames.begin(); it != dbs.dbNames.end(); ++it ) { + QSqlDatabase db = QSqlDatabase::database(( *it ) ); + CHECK_DATABASE( db ); + dropTestTables( db ); + } + + dbs.close(); +} + +void tst_QSqlQuery::init() +{ +} + +void tst_QSqlQuery::cleanup() +{ + QFETCH( QString, dbName ); + QSqlDatabase db = QSqlDatabase::database( dbName ); + CHECK_DATABASE( db ); + + if ( QTest::currentTestFunction() == QLatin1String( "numRowsAffected" ) + || QTest::currentTestFunction() == QLatin1String( "transactions" ) + || QTest::currentTestFunction() == QLatin1String( "size" ) + || QTest::currentTestFunction() == QLatin1String( "isActive" ) + || QTest::currentTestFunction() == QLatin1String( "lastInsertId" ) ) { + populateTestTables( db ); + } + + if ( QTest::currentTestFailed() && ( db.driverName().startsWith( "QOCI" ) + || db.driverName().startsWith( "QODBC" ) ) ) { + //since Oracle ODBC totally craps out on error, we init again + db.close(); + db.open(); + } +} + +void tst_QSqlQuery::generic_data(const QString& engine) +{ + if ( dbs.fillTestTable(engine) == 0 ) { + if (engine.isEmpty()) + QSKIP( "No database drivers are available in this Qt configuration", SkipAll ); + else + QSKIP( (QString("No database drivers of type %1 are available in this Qt configuration").arg(engine)).toLocal8Bit(), SkipAll ); + } +} + +void tst_QSqlQuery::dropTestTables( QSqlDatabase db ) +{ + QStringList tablenames; + // drop all the table in case a testcase failed + tablenames << qtest + << qTableName( "qtest_null", __FILE__ ) + << qTableName( "qtest_blob", __FILE__ ) + << qTableName( "qtest_bittest", __FILE__ ) + << qTableName( "qtest_nullblob", __FILE__ ) + << qTableName( "qtest_rawtest", __FILE__ ) + << qTableName( "qtest_precision", __FILE__ ) + << qTableName( "qtest_prepare", __FILE__ ) + << qTableName( "qtestj1", __FILE__ ) + << qTableName( "qtestj2", __FILE__ ) + << qTableName( "char1Select", __FILE__ ) + << qTableName( "char1SU", __FILE__ ) + << qTableName( "qxmltest", __FILE__ ) + << qTableName( "qtest_exerr", __FILE__ ) + << qTableName( "qtest_empty", __FILE__ ) + << qTableName( "clobby", __FILE__ ) + << qTableName( "bindtest", __FILE__ ) + << qTableName( "more_results", __FILE__ ) + << qTableName( "blobstest", __FILE__ ) + << qTableName( "oraRowId", __FILE__ ) + << qTableName( "qtest_batch", __FILE__ ) + << qTableName("bug6421", __FILE__).toUpper() + << qTableName("bug5765", __FILE__) + << qTableName("bug6852", __FILE__) + << qTableName( "qtest_lockedtable", __FILE__ ) + << qTableName( "Planet", __FILE__ ) + << qTableName( "task_250026", __FILE__ ) + << qTableName( "task_234422", __FILE__ ) + << qTableName("test141895", __FILE__) + << qTableName("qtest_oraOCINumber", __FILE__); + + if ( db.driverName().startsWith("QPSQL") ) + tablenames << qTableName("task_233829", __FILE__); + + if ( db.driverName().startsWith("QSQLITE") ) + tablenames << qTableName( "record_sqlite", __FILE__ ); + + if ( tst_Databases::isSqlServer( db ) || db.driverName().startsWith( "QOCI" ) ) + tablenames << qTableName( "qtest_longstr", __FILE__ ); + + if (tst_Databases::isSqlServer( db )) + db.exec("DROP PROCEDURE " + qTableName("test141895_proc", __FILE__)); + + if (tst_Databases::isMySQL( db )) + db.exec("DROP PROCEDURE IF EXISTS "+qTableName("bug6852_proc", __FILE__)); + + tst_Databases::safeDropTables( db, tablenames ); + + if ( db.driverName().startsWith( "QOCI" ) ) { + QSqlQuery q( db ); + q.exec( "DROP PACKAGE " + qTableName("pkg", __FILE__) ); + } +} + +void tst_QSqlQuery::createTestTables( QSqlDatabase db ) +{ + QSqlQuery q( db ); + + if ( db.driverName().startsWith( "QMYSQL" ) ) + // ### stupid workaround until we find a way to hardcode this + // in the MySQL server startup script + q.exec( "set table_type=innodb" ); + else if (tst_Databases::isPostgreSQL(db)) + QVERIFY_SQL( q, exec("set client_min_messages='warning'")); + + if (tst_Databases::isPostgreSQL(db)) + QVERIFY_SQL( q, exec( "create table " + qtest + " (id serial NOT NULL, t_varchar varchar(20), t_char char(20), primary key(id)) WITH OIDS" ) ); + else + QVERIFY_SQL( q, exec( "create table " + qtest + " (id int "+tst_Databases::autoFieldName(db) +" NOT NULL, t_varchar varchar(20), t_char char(20), primary key(id))" ) ); + + if ( tst_Databases::isSqlServer( db ) || db.driverName().startsWith( "QTDS" ) ) + QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_null", __FILE__ ) + " (id int null, t_varchar varchar(20) null)" ) ); + else + QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_null", __FILE__ ) + " (id int, t_varchar varchar(20))" ) ); +} + +void tst_QSqlQuery::populateTestTables( QSqlDatabase db ) +{ + QSqlQuery q( db ); + const QString qtest_null(qTableName( "qtest_null", __FILE__ )); + q.exec( "delete from " + qtest ); + QVERIFY_SQL( q, exec( "insert into " + qtest + " values (1, 'VarChar1', 'Char1')" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest + " values (2, 'VarChar2', 'Char2')" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest + " values (3, 'VarChar3', 'Char3')" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest + " values (4, 'VarChar4', 'Char4')" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest + " values (5, 'VarChar5', 'Char5')" ) ); + + q.exec( "delete from " + qtest_null ); + QVERIFY_SQL( q, exec( "insert into " + qtest_null + " values (0, NULL)" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest_null + " values (1, 'n')" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest_null + " values (2, 'i')" ) ); + QVERIFY_SQL( q, exec( "insert into " + qtest_null + " values (3, NULL)" ) ); +} + +void tst_QSqlQuery::benchmark() +{ + QFETCH( QString, dbName ); + QSqlDatabase db = QSqlDatabase::database( dbName ); + CHECK_DATABASE( db ); + if ( tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 0 ).toInt()<5 ) + QSKIP( "Test requires MySQL >= 5.0", SkipSingle ); + + QSqlQuery q(db); + const QString tableName(qTableName("benchmark", __FILE__)); + + tst_Databases::safeDropTable( db, tableName ); + + QVERIFY_SQL(q, exec("CREATE TABLE "+tableName+"(\n" + "MainKey INT NOT NULL,\n" + "OtherTextCol VARCHAR(45) NOT NULL,\n" + "PRIMARY KEY(`MainKey`))")); + + int i=1; + + QBENCHMARK { + QVERIFY_SQL(q, exec("INSERT INTO "+tableName+" VALUES("+QString::number(i)+", \"Value"+QString::number(i)+"\")")); + i++; + } + + tst_Databases::safeDropTable( db, tableName ); +} + +#include "main.moc" diff --git a/tests/benchmarks/sql/kernel/qsqlquery/qsqlquery.pro b/tests/benchmarks/sql/kernel/qsqlquery/qsqlquery.pro new file mode 100644 index 0000000..e38fd99 --- /dev/null +++ b/tests/benchmarks/sql/kernel/qsqlquery/qsqlquery.pro @@ -0,0 +1,6 @@ +TARGET = tst_bench_qsqlquery + +QT = core sql testlib +SOURCES += main.cpp + +win32: LIBS += -lWs2_32 diff --git a/tests/benchmarks/sql/sql.pro b/tests/benchmarks/sql/sql.pro new file mode 100644 index 0000000..a9d7fc7 --- /dev/null +++ b/tests/benchmarks/sql/sql.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs +SUBDIRS = \ + kernel \ |