summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/sql/kernel/qsqlquery/main.cpp
diff options
context:
space:
mode:
authorChristian Ehrlicher <[email protected]>2023-02-28 21:33:46 +0100
committerChristian Ehrlicher <[email protected]>2023-03-12 17:21:17 +0100
commit18bd15a9eac88adb1de1f877b112e255b19353b6 (patch)
treef85cd9bd37e8cdebc23511e813df16b727d5e8fd /tests/benchmarks/sql/kernel/qsqlquery/main.cpp
parentf19320748d282b1e68fc2e3de2b0cf9ec44b49ef (diff)
SQL/Tests: remove safeDropTable() / add helper class
Add a helper class which makes sure that the used table does not exist before usage (e.g. due to leftovers from previous tests) and is properly cleaned up on exit. This also allows to remove all usages of safeDropTable(). Change-Id: Iefeffbd10e2f2f67985183ea822d7b6dd2b80be7 Reviewed-by: Volker Hilsheimer <[email protected]>
Diffstat (limited to 'tests/benchmarks/sql/kernel/qsqlquery/main.cpp')
-rw-r--r--tests/benchmarks/sql/kernel/qsqlquery/main.cpp51
1 files changed, 17 insertions, 34 deletions
diff --git a/tests/benchmarks/sql/kernel/qsqlquery/main.cpp b/tests/benchmarks/sql/kernel/qsqlquery/main.cpp
index 3c7c802c563..56e11df8c3d 100644
--- a/tests/benchmarks/sql/kernel/qsqlquery/main.cpp
+++ b/tests/benchmarks/sql/kernel/qsqlquery/main.cpp
@@ -13,8 +13,7 @@ class tst_QSqlQuery : public QObject
Q_OBJECT
public:
- tst_QSqlQuery();
- virtual ~tst_QSqlQuery();
+ using QObject::QObject;
public slots:
void initTestCase();
@@ -40,20 +39,12 @@ private:
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 ) );
+ for (const auto &dbName : std::as_const(dbs.dbNames)) {
+ QSqlDatabase db = QSqlDatabase::database(dbName);
CHECK_DATABASE( db );
dropTestTables( db ); //in case of leftovers
createTestTables( db );
@@ -63,8 +54,8 @@ void tst_QSqlQuery::initTestCase()
void tst_QSqlQuery::cleanupTestCase()
{
- for ( QStringList::ConstIterator it = dbs.dbNames.begin(); it != dbs.dbNames.end(); ++it ) {
- QSqlDatabase db = QSqlDatabase::database(( *it ) );
+ for (const auto &dbName : std::as_const(dbs.dbNames)) {
+ QSqlDatabase db = QSqlDatabase::database(dbName);
CHECK_DATABASE( db );
dropTestTables( db );
}
@@ -153,18 +144,17 @@ void tst_QSqlQuery::dropTestTables( QSqlDatabase db )
if (dbType == QSqlDriver::MSSqlServer || dbType == QSqlDriver::Oracle)
tablenames << qTableName("qtest_longstr", __FILE__, db);
+ QSqlQuery q(db);
if (dbType == QSqlDriver::MSSqlServer)
- db.exec("DROP PROCEDURE " + qTableName("test141895_proc", __FILE__, db));
+ q.exec("DROP PROCEDURE " + qTableName("test141895_proc", __FILE__, db));
if (dbType == QSqlDriver::MySqlServer)
- db.exec("DROP PROCEDURE IF EXISTS "+qTableName("bug6852_proc", __FILE__, db));
+ q.exec("DROP PROCEDURE IF EXISTS "+qTableName("bug6852_proc", __FILE__, db));
tst_Databases::safeDropTables( db, tablenames );
- if (dbType == QSqlDriver::Oracle) {
- QSqlQuery q( db );
+ if (dbType == QSqlDriver::Oracle)
q.exec("DROP PACKAGE " + qTableName("pkg", __FILE__, db));
- }
}
void tst_QSqlQuery::createTestTables( QSqlDatabase db )
@@ -214,11 +204,9 @@ void tst_QSqlQuery::benchmark()
QSqlDatabase db = QSqlDatabase::database( dbName );
CHECK_DATABASE( db );
QSqlQuery q(db);
- const QString tableName(qTableName("benchmark", __FILE__, db));
-
- tst_Databases::safeDropTable( db, tableName );
+ TableScope ts(db, "benchmark", __FILE__);
- QVERIFY_SQL(q, exec("CREATE TABLE "+tableName+"(\n"
+ QVERIFY_SQL(q, exec("CREATE TABLE " + ts.tableName() + "(\n"
"MainKey INT NOT NULL,\n"
"OtherTextCol VARCHAR(45) NOT NULL,\n"
"PRIMARY KEY(`MainKey`))"));
@@ -226,11 +214,10 @@ void tst_QSqlQuery::benchmark()
int i=1;
QBENCHMARK {
- QVERIFY_SQL(q, exec("INSERT INTO "+tableName+" VALUES("+QString::number(i)+", \"Value"+QString::number(i)+"\")"));
+ const QString num = QString::number(i);
+ QVERIFY_SQL(q, exec("INSERT INTO " + ts.tableName() + " VALUES(" + num + ", \"Value" + num + "\")"));
i++;
}
-
- tst_Databases::safeDropTable( db, tableName );
}
void tst_QSqlQuery::benchmarkSelectPrepared()
@@ -239,22 +226,20 @@ void tst_QSqlQuery::benchmarkSelectPrepared()
QSqlDatabase db = QSqlDatabase::database(dbName);
CHECK_DATABASE(db);
QSqlQuery q(db);
- const QString tableName(qTableName("benchmark", __FILE__, db));
-
- tst_Databases::safeDropTable(db, tableName);
+ TableScope ts(db, "benchmark", __FILE__);
- QVERIFY_SQL(q, exec("CREATE TABLE " + tableName + "(id INT NOT NULL)"));
+ QVERIFY_SQL(q, exec("CREATE TABLE " + ts.tableName() + "(id INT NOT NULL)"));
const int NUM_ROWS = 1000;
int expectedSum = 0;
- QString fillQuery = "INSERT INTO " + tableName + " VALUES (0)";
+ QString fillQuery = "INSERT INTO " + ts.tableName() + " VALUES (0)";
for (int i = 1; i < NUM_ROWS; ++i) {
fillQuery += ", (" + QString::number(i) + QLatin1Char(')');
expectedSum += i;
}
QVERIFY_SQL(q, exec(fillQuery));
- QVERIFY_SQL(q, prepare("SELECT id FROM "+tableName));
+ QVERIFY_SQL(q, prepare("SELECT id FROM " + ts.tableName()));
QBENCHMARK {
QVERIFY_SQL(q, exec());
int sum = 0;
@@ -264,8 +249,6 @@ void tst_QSqlQuery::benchmarkSelectPrepared()
QCOMPARE(sum, expectedSum);
}
-
- tst_Databases::safeDropTable(db, tableName);
}
#include "main.moc"