Improve handling of temporary directories in SQL tests.
Initialize directory delayed in shared code and add checks to verify that it is valid. Close attached / cloned databases to prevent locks on files and leaking temporary directories caused by SQLite: QTemporaryDir: Unable to remove "...\Temp\tst_qsqldatabase-P1XkOA" most likely due to the presence of read-only files. QTemporaryDir: Unable to remove "...\Temp\tst_qsqltablemodel-P1XkOA" most likely due to the presence of read-only files. QWARN : tst_QSql::concurrentAccess() QTemporaryDir: Unable to remove "...\Temp\tst_qsql-l0VAKJ" most likely due to the presence of read-only files. Change-Id: If85bbaed04bb1a32e427d642be332996d967f796 Reviewed-by: Andy Shaw <andy.shaw@digia.com> Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
This commit is contained in:
parent
19ff7d038f
commit
9a4beb4d36
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
** Contact: http://www.qt-project.org/legal
|
** Contact: http://www.qt-project.org/legal
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** This file is part of the test suite of the Qt Toolkit.
|
||||||
@ -117,7 +117,7 @@ void tst_QSql::basicDriverTest()
|
|||||||
char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
|
char *argv[] = { const_cast<char*>(QTest::currentAppName()) };
|
||||||
QCoreApplication app(argc, argv, false);
|
QCoreApplication app(argc, argv, false);
|
||||||
tst_Databases dbs;
|
tst_Databases dbs;
|
||||||
dbs.open();
|
QVERIFY(dbs.open());
|
||||||
|
|
||||||
foreach (const QString& dbName, dbs.dbNames) {
|
foreach (const QString& dbName, dbs.dbNames) {
|
||||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||||
@ -161,7 +161,7 @@ void tst_QSql::open()
|
|||||||
QCoreApplication app(argc, argv, false);
|
QCoreApplication app(argc, argv, false);
|
||||||
tst_Databases dbs;
|
tst_Databases dbs;
|
||||||
|
|
||||||
dbs.open();
|
QVERIFY(dbs.open());
|
||||||
if (count == -1)
|
if (count == -1)
|
||||||
// first iteration: see how many dbs are open
|
// first iteration: see how many dbs are open
|
||||||
count = (int) dbs.dbNames.count();
|
count = (int) dbs.dbNames.count();
|
||||||
@ -188,7 +188,7 @@ void tst_QSql::concurrentAccess()
|
|||||||
QCoreApplication app(argc, argv, false);
|
QCoreApplication app(argc, argv, false);
|
||||||
tst_Databases dbs;
|
tst_Databases dbs;
|
||||||
|
|
||||||
dbs.open();
|
QVERIFY(dbs.open());
|
||||||
foreach (const QString& dbName, dbs.dbNames) {
|
foreach (const QString& dbName, dbs.dbNames) {
|
||||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||||
QVERIFY(db.isValid());
|
QVERIFY(db.isValid());
|
||||||
@ -204,6 +204,7 @@ void tst_QSql::concurrentAccess()
|
|||||||
QVERIFY_SQL(ndb, open());
|
QVERIFY_SQL(ndb, open());
|
||||||
|
|
||||||
QCOMPARE(db.tables(), ndb.tables());
|
QCOMPARE(db.tables(), ndb.tables());
|
||||||
|
ndb.close();
|
||||||
}
|
}
|
||||||
// no database servers installed - don't fail
|
// no database servers installed - don't fail
|
||||||
QVERIFY(1);
|
QVERIFY(1);
|
||||||
@ -217,7 +218,7 @@ void tst_QSql::openErrorRecovery()
|
|||||||
QCoreApplication app(argc, argv, false);
|
QCoreApplication app(argc, argv, false);
|
||||||
tst_Databases dbs;
|
tst_Databases dbs;
|
||||||
|
|
||||||
dbs.addDbs();
|
QVERIFY(dbs.addDbs());
|
||||||
if (dbs.dbNames.isEmpty())
|
if (dbs.dbNames.isEmpty())
|
||||||
QSKIP("No database drivers installed");
|
QSKIP("No database drivers installed");
|
||||||
foreach (const QString& dbName, dbs.dbNames) {
|
foreach (const QString& dbName, dbs.dbNames) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
** Contact: http://www.qt-project.org/legal
|
** Contact: http://www.qt-project.org/legal
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** This file is part of the test suite of the Qt Toolkit.
|
||||||
@ -49,6 +49,7 @@
|
|||||||
#include <QSqlQuery>
|
#include <QSqlQuery>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QScopedPointer>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QSqlTableModel>
|
#include <QSqlTableModel>
|
||||||
@ -248,7 +249,7 @@ public:
|
|||||||
dbNames.append( cName );
|
dbNames.append( cName );
|
||||||
}
|
}
|
||||||
|
|
||||||
void addDbs()
|
bool addDbs()
|
||||||
{
|
{
|
||||||
//addDb("QOCI", "localhost", "system", "penandy");
|
//addDb("QOCI", "localhost", "system", "penandy");
|
||||||
// addDb( "QOCI8", "//horsehead.qt-project.org:1521/pony.troll.no", "scott", "tiger" ); // Oracle 9i on horsehead
|
// addDb( "QOCI8", "//horsehead.qt-project.org:1521/pony.troll.no", "scott", "tiger" ); // Oracle 9i on horsehead
|
||||||
@ -302,7 +303,10 @@ public:
|
|||||||
|
|
||||||
// use in-memory database to prevent local files
|
// use in-memory database to prevent local files
|
||||||
// addDb("QSQLITE", ":memory:");
|
// addDb("QSQLITE", ":memory:");
|
||||||
addDb( "QSQLITE", QDir::toNativeSeparators(dbDir.path() + "/foo.db") );
|
QTemporaryDir *sqLiteDir = dbDir();
|
||||||
|
if (!sqLiteDir)
|
||||||
|
return false;
|
||||||
|
addDb( QStringLiteral("QSQLITE"), QDir::toNativeSeparators(sqLiteDir->path() + QStringLiteral("/foo.db")) );
|
||||||
// addDb( "QSQLITE2", QDir::toNativeSeparators(dbDir.path() + "/foo2.db") );
|
// addDb( "QSQLITE2", QDir::toNativeSeparators(dbDir.path() + "/foo2.db") );
|
||||||
// addDb( "QODBC3", "DRIVER={SQL SERVER};SERVER=iceblink.qt-project.org\\ICEBLINK", "troll", "trond", "" );
|
// addDb( "QODBC3", "DRIVER={SQL SERVER};SERVER=iceblink.qt-project.org\\ICEBLINK", "troll", "trond", "" );
|
||||||
// addDb( "QODBC3", "DRIVER={SQL Native Client};SERVER=silence.qt-project.org\\SQLEXPRESS", "troll", "trond", "" );
|
// addDb( "QODBC3", "DRIVER={SQL Native Client};SERVER=silence.qt-project.org\\SQLEXPRESS", "troll", "trond", "" );
|
||||||
@ -319,11 +323,14 @@ public:
|
|||||||
// addDb( "QODBC3", "DRIVER={SQL SERVER};SERVER=bq-winserv2008-x86-01.qt-project.org;DATABASE=testdb;PORT=1433", "testuser", "Ee4Gabf6_", "" );
|
// addDb( "QODBC3", "DRIVER={SQL SERVER};SERVER=bq-winserv2008-x86-01.qt-project.org;DATABASE=testdb;PORT=1433", "testuser", "Ee4Gabf6_", "" );
|
||||||
// addDb( "QODBC", "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\\dbs\\access\\testdb.mdb", "", "", "" );
|
// addDb( "QODBC", "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\\dbs\\access\\testdb.mdb", "", "", "" );
|
||||||
// addDb( "QODBC", "DRIVER={Postgresql};SERVER=bq-pgsql84.qt-project.org;DATABASE=testdb", "testuser", "Ee4Gabf6_", "" );
|
// addDb( "QODBC", "DRIVER={Postgresql};SERVER=bq-pgsql84.qt-project.org;DATABASE=testdb", "testuser", "Ee4Gabf6_", "" );
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void open()
|
// 'false' return indicates a system error, for example failure to create a temporary directory.
|
||||||
|
bool open()
|
||||||
{
|
{
|
||||||
addDbs();
|
if (!addDbs())
|
||||||
|
return false;
|
||||||
|
|
||||||
QStringList::Iterator it = dbNames.begin();
|
QStringList::Iterator it = dbNames.begin();
|
||||||
|
|
||||||
@ -341,6 +348,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void close()
|
void close()
|
||||||
@ -589,7 +597,21 @@ public:
|
|||||||
|
|
||||||
QStringList dbNames;
|
QStringList dbNames;
|
||||||
int counter;
|
int counter;
|
||||||
QTemporaryDir dbDir;
|
|
||||||
|
private:
|
||||||
|
QTemporaryDir *dbDir()
|
||||||
|
{
|
||||||
|
if (m_dbDir.isNull()) {
|
||||||
|
m_dbDir.reset(new QTemporaryDir);
|
||||||
|
if (!m_dbDir->isValid()) {
|
||||||
|
qWarning() << Q_FUNC_INFO << "Unable to create a temporary directory: " << QDir::toNativeSeparators(m_dbDir->path());
|
||||||
|
m_dbDir.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m_dbDir.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
QScopedPointer<QTemporaryDir> m_dbDir;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
** Contact: http://www.qt-project.org/legal
|
** Contact: http://www.qt-project.org/legal
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** This file is part of the test suite of the Qt Toolkit.
|
||||||
@ -394,7 +394,7 @@ void tst_QSqlDatabase::populateTestTables(QSqlDatabase db)
|
|||||||
void tst_QSqlDatabase::initTestCase()
|
void tst_QSqlDatabase::initTestCase()
|
||||||
{
|
{
|
||||||
qRegisterMetaType<QSqlDriver::NotificationSource>("QSqlDriver::NotificationSource");
|
qRegisterMetaType<QSqlDriver::NotificationSource>("QSqlDriver::NotificationSource");
|
||||||
dbs.open();
|
QVERIFY(dbs.open());
|
||||||
|
|
||||||
for (QStringList::ConstIterator it = dbs.dbNames.begin(); it != dbs.dbNames.end(); ++it) {
|
for (QStringList::ConstIterator it = dbs.dbNames.begin(); it != dbs.dbNames.end(); ++it) {
|
||||||
QSqlDatabase db = QSqlDatabase::database((*it));
|
QSqlDatabase db = QSqlDatabase::database((*it));
|
||||||
@ -2229,6 +2229,7 @@ void tst_QSqlDatabase::sqlite_enable_cache_mode()
|
|||||||
QSqlQuery q(db), q2(db2);
|
QSqlQuery q(db), q2(db2);
|
||||||
QVERIFY_SQL(q, exec("select * from " + qTableName("qtest", __FILE__, db)));
|
QVERIFY_SQL(q, exec("select * from " + qTableName("qtest", __FILE__, db)));
|
||||||
QVERIFY_SQL(q2, exec("select * from " + qTableName("qtest", __FILE__, db)));
|
QVERIFY_SQL(q2, exec("select * from " + qTableName("qtest", __FILE__, db)));
|
||||||
|
db2.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QSqlDatabase)
|
QTEST_MAIN(tst_QSqlDatabase)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
** Contact: http://www.qt-project.org/legal
|
** Contact: http://www.qt-project.org/legal
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** This file is part of the test suite of the Qt Toolkit.
|
||||||
@ -69,7 +69,7 @@ private slots:
|
|||||||
|
|
||||||
void tst_QSqlDriver::initTestCase_data()
|
void tst_QSqlDriver::initTestCase_data()
|
||||||
{
|
{
|
||||||
dbs.open();
|
QVERIFY(dbs.open());
|
||||||
if (dbs.fillTestTable() == 0)
|
if (dbs.fillTestTable() == 0)
|
||||||
QSKIP("No database drivers are available in this Qt configuration");
|
QSKIP("No database drivers are available in this Qt configuration");
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
** Contact: http://www.qt-project.org/legal
|
** Contact: http://www.qt-project.org/legal
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** This file is part of the test suite of the Qt Toolkit.
|
||||||
@ -257,7 +257,7 @@ tst_QSqlQuery::~tst_QSqlQuery()
|
|||||||
|
|
||||||
void tst_QSqlQuery::initTestCase()
|
void tst_QSqlQuery::initTestCase()
|
||||||
{
|
{
|
||||||
dbs.open();
|
QVERIFY(dbs.open());
|
||||||
|
|
||||||
for ( QStringList::ConstIterator it = dbs.dbNames.begin(); it != dbs.dbNames.end(); ++it ) {
|
for ( QStringList::ConstIterator it = dbs.dbNames.begin(); it != dbs.dbNames.end(); ++it ) {
|
||||||
QSqlDatabase db = QSqlDatabase::database(( *it ) );
|
QSqlDatabase db = QSqlDatabase::database(( *it ) );
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
** Contact: http://www.qt-project.org/legal
|
** Contact: http://www.qt-project.org/legal
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** This file is part of the test suite of the Qt Toolkit.
|
||||||
@ -350,7 +350,7 @@ void tst_QSqlThread::recreateTestTables()
|
|||||||
|
|
||||||
void tst_QSqlThread::initTestCase()
|
void tst_QSqlThread::initTestCase()
|
||||||
{
|
{
|
||||||
dbs.open();
|
QVERIFY(dbs.open());
|
||||||
recreateTestTables();
|
recreateTestTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
** Contact: http://www.qt-project.org/legal
|
** Contact: http://www.qt-project.org/legal
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** This file is part of the test suite of the Qt Toolkit.
|
||||||
@ -124,7 +124,7 @@ tst_QSqlQueryModel::~tst_QSqlQueryModel()
|
|||||||
|
|
||||||
void tst_QSqlQueryModel::initTestCase()
|
void tst_QSqlQueryModel::initTestCase()
|
||||||
{
|
{
|
||||||
dbs.open();
|
QVERIFY(dbs.open());
|
||||||
for (QStringList::ConstIterator it = dbs.dbNames.begin(); it != dbs.dbNames.end(); ++it) {
|
for (QStringList::ConstIterator it = dbs.dbNames.begin(); it != dbs.dbNames.end(); ++it) {
|
||||||
QSqlDatabase db = QSqlDatabase::database((*it));
|
QSqlDatabase db = QSqlDatabase::database((*it));
|
||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
** Contact: http://www.qt-project.org/legal
|
** Contact: http://www.qt-project.org/legal
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** This file is part of the test suite of the Qt Toolkit.
|
||||||
@ -98,7 +98,7 @@ private:
|
|||||||
|
|
||||||
void tst_QSqlRelationalTableModel::initTestCase_data()
|
void tst_QSqlRelationalTableModel::initTestCase_data()
|
||||||
{
|
{
|
||||||
dbs.open();
|
QVERIFY(dbs.open());
|
||||||
if (dbs.fillTestTable() == 0)
|
if (dbs.fillTestTable() == 0)
|
||||||
QSKIP("No database drivers are available in this Qt configuration");
|
QSKIP("No database drivers are available in this Qt configuration");
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
||||||
** Contact: http://www.qt-project.org/legal
|
** Contact: http://www.qt-project.org/legal
|
||||||
**
|
**
|
||||||
** This file is part of the test suite of the Qt Toolkit.
|
** This file is part of the test suite of the Qt Toolkit.
|
||||||
@ -157,7 +157,7 @@ private:
|
|||||||
|
|
||||||
tst_QSqlTableModel::tst_QSqlTableModel()
|
tst_QSqlTableModel::tst_QSqlTableModel()
|
||||||
{
|
{
|
||||||
dbs.open();
|
QVERIFY(dbs.open());
|
||||||
}
|
}
|
||||||
|
|
||||||
tst_QSqlTableModel::~tst_QSqlTableModel()
|
tst_QSqlTableModel::~tst_QSqlTableModel()
|
||||||
@ -1968,6 +1968,7 @@ void tst_QSqlTableModel::sqlite_attachedDatabase()
|
|||||||
QCOMPARE(model.rowCount(), 1);
|
QCOMPARE(model.rowCount(), 1);
|
||||||
QCOMPARE(model.data(model.index(0, 0), Qt::DisplayRole).toInt(), 3);
|
QCOMPARE(model.data(model.index(0, 0), Qt::DisplayRole).toInt(), 3);
|
||||||
QCOMPARE(model.data(model.index(0, 1), Qt::DisplayRole).toString(), QLatin1String("main"));
|
QCOMPARE(model.data(model.index(0, 1), Qt::DisplayRole).toString(), QLatin1String("main"));
|
||||||
|
attachedDb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user