summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/auto/qsql/tst_qsql.cpp1
-rw-r--r--tests/auto/qsqldatabase/tst_databases.h27
-rw-r--r--tests/auto/qsqldatabase/tst_qsqldatabase.cpp1
-rw-r--r--tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp3
4 files changed, 29 insertions, 3 deletions
diff --git a/tests/auto/qsql/tst_qsql.cpp b/tests/auto/qsql/tst_qsql.cpp
index 906d8b7..916d124 100644
--- a/tests/auto/qsql/tst_qsql.cpp
+++ b/tests/auto/qsql/tst_qsql.cpp
@@ -254,6 +254,7 @@ void tst_QSql::concurrentAccess()
QVERIFY_SQL( ndb, open() );
QCOMPARE( db.tables(), ndb.tables() );
+ ndb.close();
}
// no database servers installed - don't fail
QVERIFY(1);
diff --git a/tests/auto/qsqldatabase/tst_databases.h b/tests/auto/qsqldatabase/tst_databases.h
index a688f9e..64dcb80 100644
--- a/tests/auto/qsqldatabase/tst_databases.h
+++ b/tests/auto/qsqldatabase/tst_databases.h
@@ -136,13 +136,24 @@ class tst_Databases
{
public:
- tst_Databases(): counter( 0 )
+ tst_Databases(): counter( 0 ), m_sqLitePrefix(QDir::tempPath())
{
+ if (!m_sqLitePrefix.endsWith(QLatin1Char('/')))
+ m_sqLitePrefix += QLatin1Char('/');
+ m_sqLitePrefix += QLatin1String("foo");
+ m_sqLitePrefix += QString::number(QDateTime::currentDateTime().toMSecsSinceEpoch() % quint64(1000));
}
~tst_Databases()
{
close();
+ for (int i = m_sqLiteFiles.size() - 1; i >= 0; --i) {
+ QFile sqLiteFile(m_sqLiteFiles.at(i));
+ if (sqLiteFile.exists() && !sqLiteFile.remove()) {
+ qWarning() << "Cannot remove " << QDir::toNativeSeparators(sqLiteFile.fileName())
+ << ':' << sqLiteFile.errorString();
+ }
+ }
}
// returns a testtable consisting of the names of all database connections if
@@ -279,7 +290,7 @@ public:
// use in-memory database to prevent local files
// addDb("QSQLITE", ":memory:");
- addDb( "QSQLITE", QDir::toNativeSeparators(QDir::tempPath()+"/foo.db") );
+ addDb( "QSQLITE", QDir::toNativeSeparators(sqLiteFileName()));
// addDb( "QSQLITE2", QDir::toNativeSeparators(QDir::tempPath()+"/foo2.db") );
// addDb( "QODBC3", "DRIVER={SQL SERVER};SERVER=iceblink.nokia.troll.no\\ICEBLINK", "troll", "trond", "" );
// addDb( "QODBC3", "DRIVER={SQL Native Client};SERVER=silence.nokia.troll.no\\SQLEXPRESS", "troll", "trond", "" );
@@ -569,8 +580,20 @@ public:
return QString();
}
+ QString sqLiteFileName() // Return a temporary file name for SQLite DB
+ {
+ const QString newFileName = m_sqLitePrefix + QLatin1Char('_')
+ + QString::number(m_sqLiteFiles.size()) + QLatin1String(".db");
+ m_sqLiteFiles.append(newFileName);
+ return newFileName;
+ }
+
QStringList dbNames;
int counter;
+
+private:
+ QString m_sqLitePrefix;
+ QStringList m_sqLiteFiles;
};
#endif
diff --git a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp
index bc0eb32..9bdd011 100644
--- a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp
+++ b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp
@@ -2538,6 +2538,7 @@ void tst_QSqlDatabase::sqlite_enable_cache_mode()
QSqlQuery q(db), q2(db2);
QVERIFY_SQL(q, exec("select * from "+qTableName("qtest", __FILE__)));
QVERIFY_SQL(q2, exec("select * from "+qTableName("qtest", __FILE__)));
+ db2.close();
}
QTEST_MAIN(tst_QSqlDatabase)
diff --git a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp
index e9bcdaa..078e109 100644
--- a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp
+++ b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp
@@ -1261,7 +1261,7 @@ void tst_QSqlTableModel::sqlite_attachedDatabase()
QSKIP(":memory: database, skipping test", SkipSingle);
QSqlDatabase attachedDb = QSqlDatabase::cloneDatabase(db, db.driverName() + QLatin1String("attached"));
- attachedDb.setDatabaseName(db.databaseName()+QLatin1String("attached.dat"));
+ attachedDb.setDatabaseName(dbs.sqLiteFileName());
QVERIFY_SQL(attachedDb, open());
QSqlQuery q(attachedDb);
tst_Databases::safeDropTables(attachedDb, QStringList() << "atest" << "atest2");
@@ -1297,6 +1297,7 @@ void tst_QSqlTableModel::sqlite_attachedDatabase()
QCOMPARE(model.rowCount(), 1);
QCOMPARE(model.data(model.index(0, 0), Qt::DisplayRole).toInt(), 3);
QCOMPARE(model.data(model.index(0, 1), Qt::DisplayRole).toString(), QLatin1String("main"));
+ attachedDb.close();
}