From c833ed5711b40465a77a2d43b79e041092e638cc Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 28 Mar 2025 20:50:17 +0100 Subject: [PATCH] Tests/QSqlDriver: move cleanup tables into own function Move the cleanup of the temporary tables into an own function and call them during init and cleanup. this makes sure the tables are - deleted on clean exit - not there during init when cleanup was not run (e.g. due to debugging or a crash). Pick-to: 6.9 6.8 Change-Id: I9013a26b0166d0756a37f0a5d50ed825adf63868 Reviewed-by: Thiago Macieira --- .../sql/kernel/qsqldriver/tst_qsqldriver.cpp | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/auto/sql/kernel/qsqldriver/tst_qsqldriver.cpp b/tests/auto/sql/kernel/qsqldriver/tst_qsqldriver.cpp index fb8d804843e..8448dc4e474 100644 --- a/tests/auto/sql/kernel/qsqldriver/tst_qsqldriver.cpp +++ b/tests/auto/sql/kernel/qsqldriver/tst_qsqldriver.cpp @@ -13,6 +13,7 @@ class tst_QSqlDriver : public QObject public: void recreateTestTables(QSqlDatabase); + void dropTables(); tst_Databases dbs; @@ -54,8 +55,6 @@ void tst_QSqlDriver::recreateTestTables(QSqlDatabase db) { QSqlQuery q(db); const QString tableName(qTableName("relTEST1", __FILE__, db)); - tst_Databases::safeDropTables(db, {tableName}); - QSqlDriver::DbmsType dbType = tst_Databases::getDatabaseType(db); if (dbType == QSqlDriver::PostgreSQL) QVERIFY_SQL( q, exec("set client_min_messages='warning'")); @@ -80,13 +79,7 @@ void tst_QSqlDriver::recreateTestTables(QSqlDatabase db) QVERIFY_SQL( q, exec("insert into " + tableName + " values(4, 'boris', 2, 2, 2.345678)")); } -void tst_QSqlDriver::initTestCase() -{ - for (const QString &dbname : std::as_const(dbs.dbNames)) - recreateTestTables(QSqlDatabase::database(dbname)); -} - -void tst_QSqlDriver::cleanupTestCase() +void tst_QSqlDriver::dropTables() { for (const QString &dbName : std::as_const(dbs.dbNames)) { QSqlDatabase db = QSqlDatabase::database(dbName); @@ -96,6 +89,18 @@ void tst_QSqlDriver::cleanupTestCase() tables.push_back(qTableName("clobTable", __FILE__, db)); tst_Databases::safeDropTables(db, tables); } +} + +void tst_QSqlDriver::initTestCase() +{ + dropTables(); + for (const QString &dbname : std::as_const(dbs.dbNames)) + recreateTestTables(QSqlDatabase::database(dbname)); +} + +void tst_QSqlDriver::cleanupTestCase() +{ + dropTables(); dbs.close(); }