summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2009-06-23 05:53:53 (GMT)
committerBradley T. Hughes <bradley.hughes@nokia.com>2009-06-23 05:53:53 (GMT)
commitfbe44b843194f3892e163ecec1be52fb498e2ddd (patch)
tree857c749710a71e2d485bd134d6542c62ac51c4e5 /tests/auto
parent6fc3873707ae9e8c002b14800bac9fd64faca42b (diff)
parent3647de5291db9e359e7844f80202251f47e83a97 (diff)
downloadQt-fbe44b843194f3892e163ecec1be52fb498e2ddd.zip
Qt-fbe44b843194f3892e163ecec1be52fb498e2ddd.tar.gz
Qt-fbe44b843194f3892e163ecec1be52fb498e2ddd.tar.bz2
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp37
-rw-r--r--tests/auto/q3sqlselectcursor/tst_q3sqlselectcursor.cpp2
-rw-r--r--tests/auto/qitemmodel/qitemmodel.pro3
-rw-r--r--tests/auto/qsqldatabase/tst_databases.h14
-rw-r--r--tests/auto/qsqldatabase/tst_qsqldatabase.cpp8
-rw-r--r--tests/auto/qsqldriver/tst_qsqldriver.cpp8
-rw-r--r--tests/auto/qsqlquery/tst_qsqlquery.cpp65
-rw-r--r--tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp48
-rw-r--r--tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp2
-rw-r--r--tests/auto/qstatemachine/tst_qstatemachine.cpp49
-rw-r--r--tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp272
11 files changed, 387 insertions, 121 deletions
diff --git a/tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp b/tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp
index 74126f8..2d89639 100644
--- a/tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp
+++ b/tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp
@@ -132,6 +132,11 @@ void tst_Q3SqlCursor::createTestTables( QSqlDatabase db )
if ( !db.isValid() )
return;
QSqlQuery q( db );
+
+ if (tst_Databases::isSqlServer(db)) {
+ QVERIFY_SQL(q, exec("SET ANSI_DEFAULTS ON"));
+ }
+
// please never ever change this table; otherwise fix all tests ;)
if ( tst_Databases::isMSAccess( db ) ) {
QVERIFY_SQL(q, exec( "create table " + qTableName( "qtest" ) + " ( id int not null, t_varchar varchar(40) not null,"
@@ -301,7 +306,8 @@ void tst_Q3SqlCursor::insert()
// check that primeInsert returns a valid QSqlRecord
QCOMPARE( (int)irec->count(), 4 );
if ( ( irec->field( 0 ).type() != QVariant::Int ) &&
- ( irec->field( 0 ).type() != QVariant::String ) ) {
+ ( irec->field( 0 ).type() != QVariant::String ) &&
+ ( irec->field( 0 ).type() != QVariant::Double ) ) {
QFAIL( QString( "Wrong datatype %1 for field 'ID'"
" (expected Int or String)" ).arg( QVariant::typeToName( irec->field( 0 ).type() ) ) );
}
@@ -533,13 +539,18 @@ void tst_Q3SqlCursor::unicode()
cur.del();
if ( res != utf8str ) {
- int i;
- for ( i = 0; i < (int)res.length(); ++i ) {
- if ( res[ i ] != utf8str[ i ] )
- break;
- }
- QFAIL( QString( "Strings differ at position %1: orig: %2, db: %3" ).arg( i ).arg( utf8str[ i ].unicode(), 0, 16 ).arg( res[ i ].unicode(), 0, 16 ) );
+ int i;
+ for ( i = 0; i < (int)res.length(); ++i ) {
+ if ( res[ i ] != utf8str[ i ] )
+ break;
+ }
+ if(db.driverName().startsWith("QMYSQL") || db.driverName().startsWith("QDB2"))
+ qWarning() << "Needs someone with more Unicode knowledge than I have to fix:" << QString( "Strings differ at position %1: orig: %2, db: %3" ).arg( i ).arg( utf8str[ i ].unicode(), 0, 16 ).arg( res[ i ].unicode(), 0, 16 );
+ else
+ QFAIL( QString( "Strings differ at position %1: orig: %2, db: %3" ).arg( i ).arg( utf8str[ i ].unicode(), 0, 16 ).arg( res[ i ].unicode(), 0, 16 ) );
}
+ if(db.driverName().startsWith("QMYSQL") || db.driverName().startsWith("QDB2"))
+ QEXPECT_FAIL("", "See above message", Continue);
QVERIFY( res == utf8str );
}
@@ -747,12 +758,12 @@ void tst_Q3SqlCursor::insertFieldNameContainsWS() {
QString tableName = qTableName("qtestws");
QSqlQuery q(db);
- q.exec(QString("DROP TABLE %1").arg(tableName));
+ tst_Databases::safeDropTable(db, tableName);
QString query = QString("CREATE TABLE %1 (id int, \"first Name\" varchar(20), "
- "lastName varchar(20))");
- QVERIFY_SQL(q, exec(query.arg(tableName)));
+ "lastName varchar(20))").arg(tableName);
+ QVERIFY_SQL(q, exec(query));
- Q3SqlCursor cur(QString("%1").arg(tableName), true, db);
+ Q3SqlCursor cur(tableName, true, db);
cur.select();
QSqlRecord *r = cur.primeInsert();
@@ -768,8 +779,8 @@ void tst_Q3SqlCursor::insertFieldNameContainsWS() {
QVERIFY(cur.value(0) == 1);
QCOMPARE(cur.value(1).toString(), QString("Kong"));
QCOMPARE(cur.value(2).toString(), QString("Harald"));
-
- q.exec(QString("DROP TABLE %1").arg(tableName));
+
+ tst_Databases::safeDropTable(db, tableName);
}
diff --git a/tests/auto/q3sqlselectcursor/tst_q3sqlselectcursor.cpp b/tests/auto/q3sqlselectcursor/tst_q3sqlselectcursor.cpp
index d026cbf..ec1f805 100644
--- a/tests/auto/q3sqlselectcursor/tst_q3sqlselectcursor.cpp
+++ b/tests/auto/q3sqlselectcursor/tst_q3sqlselectcursor.cpp
@@ -114,7 +114,7 @@ void tst_Q3SqlSelectCursor::createTestTables( QSqlDatabase db )
void tst_Q3SqlSelectCursor::dropTestTables( QSqlDatabase db )
{
- tst_Databases::safeDropTables( db, QStringList() << qTableName( "qtest" ) );
+ tst_Databases::safeDropTable( db, qTableName( "qtest" ) );
}
void tst_Q3SqlSelectCursor::populateTestTables( QSqlDatabase db )
diff --git a/tests/auto/qitemmodel/qitemmodel.pro b/tests/auto/qitemmodel/qitemmodel.pro
index c51f4c7..38c615b 100644
--- a/tests/auto/qitemmodel/qitemmodel.pro
+++ b/tests/auto/qitemmodel/qitemmodel.pro
@@ -1,6 +1,5 @@
-CONFIG += qtestlib
+load(qttest_p4)
SOURCES += tst_qitemmodel.cpp
-TARGET = tst_qitemmodel
QT += sql
diff --git a/tests/auto/qsqldatabase/tst_databases.h b/tests/auto/qsqldatabase/tst_databases.h
index a490a2f..b81182a 100644
--- a/tests/auto/qsqldatabase/tst_databases.h
+++ b/tests/auto/qsqldatabase/tst_databases.h
@@ -238,8 +238,8 @@ public:
// addDb( "QIBASE", "/opt/firebird/databases/testdb.fdb", "testuser", "Ee4Gabf6_", "firebird2-nokia.trolltech.com.au" ); // Firebird 2.1.1
// use in-memory database to prevent local files
- addDb("QSQLITE", ":memory:");
-// addDb( "QSQLITE", QDir::toNativeSeparators(QDir::tempPath()+"/foo.db") );
+// addDb("QSQLITE", ":memory:");
+ addDb( "QSQLITE", QDir::toNativeSeparators(QDir::tempPath()+"/foo.db") );
// 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", "" );
@@ -333,6 +333,11 @@ public:
}
}
+ static void safeDropTable( QSqlDatabase db, const QString& tableName )
+ {
+ safeDropTables(db, QStringList() << tableName);
+ }
+
static void safeDropViews( QSqlDatabase db, const QStringList &viewNames )
{
if ( isMSAccess( db ) ) // Access is sooo stupid.
@@ -354,6 +359,11 @@ public:
}
}
+ static void safeDropView( QSqlDatabase db, const QString& tableName )
+ {
+ safeDropViews(db, QStringList() << tableName);
+ }
+
// returns the type name of the blob datatype for the database db.
// blobSize is only used if the db doesn't have a generic blob type
static QString blobTypeName( QSqlDatabase db, int blobSize = 10000 )
diff --git a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp
index cce4602..f697488 100644
--- a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp
+++ b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp
@@ -249,7 +249,7 @@ struct FieldDef {
// excluding the primary key field
static int createFieldTable(const FieldDef fieldDefs[], QSqlDatabase db)
{
- tst_Databases::safeDropTables(db, QStringList() << qTableName("qtestfields"));
+ tst_Databases::safeDropTable(db, qTableName("qtestfields"));
QSqlQuery q(db);
// construct a create table statement consisting of all fieldtypes
QString qs = "create table " + qTableName("qtestfields");
@@ -357,6 +357,7 @@ void tst_QSqlDatabase::dropTestTables(QSqlDatabase db)
tableNames << (qTableName("qtest") + " test");
tst_Databases::safeDropTables(db, tableNames);
+ tst_Databases::safeDropView(db, qTableName("qtest_view"));
}
void tst_QSqlDatabase::populateTestTables(QSqlDatabase db)
@@ -540,11 +541,6 @@ void tst_QSqlDatabase::tables()
QVERIFY(tables.contains(qTableName("temp_tab"), Qt::CaseInsensitive));
QVERIFY(tables.contains(qTableName("qtest"), Qt::CaseInsensitive));
- if (tst_Databases::isMSAccess(db))
- QSqlQuery("drop table " + qTableName("qtest_view"), db);
- else
- QSqlQuery("drop view " + qTableName("qtest_view"), db);
-
if (db.driverName().startsWith("QPSQL")) {
QVERIFY(tables.contains(qTableName("qtest") + " test"));
}
diff --git a/tests/auto/qsqldriver/tst_qsqldriver.cpp b/tests/auto/qsqldriver/tst_qsqldriver.cpp
index bbd7483..d8f7747 100644
--- a/tests/auto/qsqldriver/tst_qsqldriver.cpp
+++ b/tests/auto/qsqldriver/tst_qsqldriver.cpp
@@ -85,9 +85,7 @@ void tst_QSqlDriver::recreateTestTables(QSqlDatabase db)
{
QSqlQuery q(db);
- QStringList tableNames;
- tableNames << qTableName( "relTEST1" );
- tst_Databases::safeDropTables( db, tableNames );
+ tst_Databases::safeDropTable( db, qTableName( "relTEST1" ) );
QVERIFY_SQL( q, exec("create table " + qTableName("relTEST1") +
" (id int not null primary key, name varchar(20), title_key int, another_title_key int)"));
@@ -105,11 +103,9 @@ void tst_QSqlDriver::initTestCase()
void tst_QSqlDriver::cleanupTestCase()
{
- QStringList tableNames;
- tableNames << qTableName( "relTEST1" );
foreach (const QString &dbName, dbs.dbNames) {
QSqlDatabase db = QSqlDatabase::database(dbName);
- tst_Databases::safeDropTables( db, tableNames );
+ tst_Databases::safeDropTable( db, qTableName( "relTEST1" ) );
}
dbs.close();
}
diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp
index 825db6c..9604fa8 100644
--- a/tests/auto/qsqlquery/tst_qsqlquery.cpp
+++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp
@@ -289,7 +289,8 @@ void tst_QSqlQuery::dropTestTables( QSqlDatabase db )
<< qTableName( "bindtest" )
<< qTableName( "more_results" )
<< qTableName( "blobstest" )
- << qTableName( "oraRowId" );
+ << qTableName( "oraRowId" )
+ << qTableName( "qtest_batch" );
if ( db.driverName().startsWith("QSQLITE") )
tablenames << qTableName( "record_sqlite" );
@@ -303,6 +304,7 @@ void tst_QSqlQuery::dropTestTables( QSqlDatabase db )
tablenames << qTableName( "Planet" );
#endif
tablenames << qTableName( "task_250026" );
+ tablenames << qTableName( "task_234422" );
tst_Databases::safeDropTables( db, tablenames );
}
@@ -1902,71 +1904,48 @@ void tst_QSqlQuery::batchExec()
QSKIP( "Database can't do BatchOperations", SkipSingle );
QSqlQuery q( db );
+ QString tableName = qTableName( "qtest_batch" );
- q.exec( "drop table " + qTableName( "qtest_batch" ) );
-
- QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest_batch" ) + " (id int, name varchar(20), dt date, num numeric(8, 4))" ) );
-
- QVERIFY_SQL( q, prepare( "insert into " + qTableName( "qtest_batch" ) + " (id, name, dt, num) values (?, ?, ?, ?)" ) );
+ QVERIFY_SQL( q, exec( "create table " + tableName + " (id int, name varchar(20), dt date, num numeric(8, 4))" ) );
+ QVERIFY_SQL( q, prepare( "insert into " + tableName + " (id, name, dt, num) values (?, ?, ?, ?)" ) );
QVariantList intCol;
-
intCol << 1 << 2 << QVariant( QVariant::Int );
QVariantList charCol;
-
charCol << QLatin1String( "harald" ) << QLatin1String( "boris" ) << QVariant( QVariant::String );
QVariantList dateCol;
-
QDateTime dt = QDateTime( QDate::currentDate(), QTime( 1, 2, 3 ) );
-
dateCol << dt << dt.addDays( -1 ) << QVariant( QVariant::DateTime );
QVariantList numCol;
-
numCol << 2.3 << 3.4 << QVariant( QVariant::Double );
q.addBindValue( intCol );
-
q.addBindValue( charCol );
-
q.addBindValue( dateCol );
-
q.addBindValue( numCol );
QVERIFY_SQL( q, execBatch() );
-
- QVERIFY_SQL( q, exec( "select id, name, dt, num from " + qTableName( "qtest_batch" ) + " order by id" ) );
+ QVERIFY_SQL( q, exec( "select id, name, dt, num from " + tableName + " order by id" ) );
QVERIFY( q.next() );
-
QCOMPARE( q.value( 0 ).toInt(), 1 );
-
QCOMPARE( q.value( 1 ).toString(), QString( "harald" ) );
-
QCOMPARE( q.value( 2 ).toDateTime(), dt );
-
QCOMPARE( q.value( 3 ).toDouble(), 2.3 );
QVERIFY( q.next() );
-
QCOMPARE( q.value( 0 ).toInt(), 2 );
-
QCOMPARE( q.value( 1 ).toString(), QString( "boris" ) );
-
QCOMPARE( q.value( 2 ).toDateTime(), dt.addDays( -1 ) );
-
QCOMPARE( q.value( 3 ).toDouble(), 3.4 );
QVERIFY( q.next() );
-
QVERIFY( q.value( 0 ).isNull() );
-
QVERIFY( q.value( 1 ).isNull() );
-
QVERIFY( q.value( 2 ).isNull() );
-
QVERIFY( q.value( 3 ).isNull() );
}
@@ -2344,6 +2323,8 @@ void tst_QSqlQuery::sqlite_finish()
QString tableName = qTableName( "qtest_lockedtable" );
QSqlQuery q( db );
+
+ tst_Databases::safeDropTable( db2, tableName );
q.exec( "CREATE TABLE " + tableName + " (pk_id INTEGER PRIMARY KEY, whatever TEXT)" );
q.exec( "INSERT INTO " + tableName + " values(1, 'whatever')" );
q.exec( "INSERT INTO " + tableName + " values(2, 'whatever more')" );
@@ -2361,7 +2342,8 @@ void tst_QSqlQuery::sqlite_finish()
q.finish();
QVERIFY_SQL( q2, exec( "DELETE FROM " + tableName + " WHERE pk_id=2" ) );
QCOMPARE( q2.numRowsAffected(), 1 );
- q.exec( "DROP TABLE " + tableName );
+
+ tst_Databases::safeDropTable( db2, tableName );
}
QSqlDatabase::removeDatabase( "sqlite_finish_sqlite" );
@@ -2574,71 +2556,47 @@ void tst_QSqlQuery::blobsPreparedQuery()
QString tableName = qTableName( "blobstest" );
QSqlQuery q( db );
-
q.setForwardOnly( true ); // This is needed to make the test work with DB2.
-
QString shortBLOB( "abc" );
-
QString longerBLOB( "abcdefghijklmnopqrstuvxyz¿äëïöü¡ " );
// In PostgreSQL a BLOB is not called a BLOB, but a BYTEA! :-)
// ... and in SQL Server it can be called a lot, but IMAGE will do.
QString typeName( "BLOB" );
-
if ( db.driverName().startsWith( "QPSQL" ) )
typeName = "BYTEA";
else if ( db.driverName().startsWith( "QODBC" ) )
typeName = "IMAGE";
QVERIFY_SQL( q, exec( QString( "CREATE TABLE %1(id INTEGER, data %2)" ).arg( tableName ).arg( typeName ) ) );
-
q.prepare( QString( "INSERT INTO %1(id, data) VALUES(:id, :data)" ).arg( tableName ) );
-
q.bindValue( ":id", 1 );
-
q.bindValue( ":data", shortBLOB.toAscii() );
-
QVERIFY_SQL( q, exec() );
q.bindValue( ":id", 2 );
-
q.bindValue( ":data", longerBLOB.toAscii() );
-
QVERIFY_SQL( q, exec() );
// Two executions and result sets
q.prepare( QString( "SELECT data FROM %1 WHERE id = ?" ).arg( tableName ) );
-
q.bindValue( 0, QVariant( 1 ) );
-
QVERIFY_SQL( q, exec() );
-
QVERIFY_SQL( q, next() );
-
QCOMPARE( q.value( 0 ).toString(), shortBLOB );
q.bindValue( 0, QVariant( 2 ) );
-
QVERIFY_SQL( q, exec() );
-
QVERIFY_SQL( q, next() );
-
QCOMPARE( q.value( 0 ).toString(), longerBLOB );
// Only one execution and result set
q.prepare( QString( "SELECT id, data FROM %1 ORDER BY id" ).arg( tableName ) );
-
QVERIFY_SQL( q, exec() );
-
QVERIFY_SQL( q, next() );
-
QCOMPARE( q.value( 1 ).toString(), shortBLOB );
-
QVERIFY_SQL( q, next() );
-
QCOMPARE( q.value( 1 ).toString(), longerBLOB );
-
- q.exec( QString( "DROP TABLE %1" ).arg( tableName ) );
}
// There were problems with navigating past the end of a table returning an error on mysql
@@ -2792,7 +2750,6 @@ void tst_QSqlQuery::task_234422()
QString tableName = qTableName( "task_234422" );
- query.exec("DROP TABLE " + tableName);
QVERIFY_SQL(query,exec("CREATE TABLE " + tableName + " (id int primary key, "
"name varchar(20), homecountry varchar(2))"));
for (int i = 0; i < m_airlines.count(); ++i) {
diff --git a/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp b/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp
index 4588af8..e2dace8 100644
--- a/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp
+++ b/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp
@@ -86,6 +86,9 @@ private slots:
void escapedRelations();
void escapedTableName();
void whiteSpaceInIdentifiers();
+
+private:
+ void dropTestTables( QSqlDatabase db );
};
@@ -100,18 +103,9 @@ void tst_QSqlRelationalTableModel::initTestCase_data()
void tst_QSqlRelationalTableModel::recreateTestTables(QSqlDatabase db)
{
- QSqlQuery q(db);
-
- QStringList tableNames;
- tableNames << qTableName( "reltest1" )
- << qTableName( "reltest2" )
- << qTableName( "reltest3" )
- << qTableName( "reltest4" )
- << qTableName( "reltest5" )
- << db.driver()->escapeIdentifier(qTableName( "rel test6" ), QSqlDriver::TableName)
- << db.driver()->escapeIdentifier(qTableName( "rel test7" ), QSqlDriver::TableName);
- tst_Databases::safeDropTables( db, tableNames );
+ dropTestTables(db);
+ QSqlQuery q(db);
QVERIFY_SQL( q, exec("create table " + qTableName("reltest1") +
" (id int not null primary key, name varchar(20), title_key int, another_title_key int)"));
QVERIFY_SQL( q, exec("insert into " + qTableName("reltest1") + " values(1, 'harry', 1, 2)"));
@@ -157,20 +151,27 @@ void tst_QSqlRelationalTableModel::initTestCase()
void tst_QSqlRelationalTableModel::cleanupTestCase()
{
+ foreach (const QString &dbName, dbs.dbNames) {
+ QSqlDatabase db = QSqlDatabase::database(dbName);
+ CHECK_DATABASE( db );
+ dropTestTables( QSqlDatabase::database(dbName) );
+ }
+ dbs.close();
+}
+
+void tst_QSqlRelationalTableModel::dropTestTables( QSqlDatabase db )
+{
QStringList tableNames;
tableNames << qTableName( "reltest1" )
<< qTableName( "reltest2" )
<< qTableName( "reltest3" )
<< qTableName( "reltest4" )
- << qTableName( "reltest5" );
- foreach (const QString &dbName, dbs.dbNames) {
- QSqlDatabase db = QSqlDatabase::database(dbName);
- QStringList tables = tableNames;
- tables << db.driver()->escapeIdentifier(qTableName( "rel test6" ), QSqlDriver::TableName)
- << db.driver()->escapeIdentifier(qTableName( "rel test7" ), QSqlDriver::TableName);
- tst_Databases::safeDropTables( db, tables );
- }
- dbs.close();
+ << qTableName( "reltest5" )
+ << qTableName( "rel test6", db.driver() )
+ << qTableName( "rel test7", db.driver() )
+ << qTableName("CASETEST1", db.driver() )
+ << qTableName("casetest1", db.driver() );
+ tst_Databases::safeDropTables( db, tableNames );
}
void tst_QSqlRelationalTableModel::init()
@@ -916,11 +917,6 @@ void tst_QSqlRelationalTableModel::casing()
if (db.driverName().startsWith("QSQLITE"))
QSKIP("The casing test for SQLITE is irrelevant since SQLITE is case insensitive", SkipAll);
- QStringList tableNames;
- tableNames << qTableName("CASETEST1", db.driver()).toUpper();
- tableNames << qTableName("casetest1", db.driver());
- tst_Databases::safeDropTables(db, tableNames);
-
QSqlQuery q(db);
QVERIFY_SQL( q, exec("create table " + qTableName("CASETEST1", db.driver()).toUpper() +
" (id int not null primary key, name varchar(20), title_key int, another_title_key int)"));
@@ -974,8 +970,6 @@ void tst_QSqlRelationalTableModel::casing()
QCOMPARE(model.data(model.index(0, 0)).toInt(), 1);
QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry"));
QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr"));
-
- tst_Databases::safeDropTables(db, tableNames);
}
void tst_QSqlRelationalTableModel::escapedRelations()
diff --git a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp
index aa882be..1445f34 100644
--- a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp
+++ b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp
@@ -899,7 +899,7 @@ void tst_QSqlTableModel::sqlite_attachedDatabase()
QVERIFY_SQL( q, exec("INSERT INTO atest2 VALUES(2, 'attached-atest2')"));
QSqlQuery q2(db);
- tst_Databases::safeDropTables(db, QStringList() << "atest");
+ tst_Databases::safeDropTable(db, "atest");
QVERIFY_SQL(q2, exec("CREATE TABLE atest(id int, text varchar(20))"));
QVERIFY_SQL(q2, exec("INSERT INTO atest VALUES(3, 'main')"));
QVERIFY_SQL(q2, exec("ATTACH DATABASE \""+attachedDb.databaseName()+"\" as adb"));
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
index b39f0a1..553833c 100644
--- a/tests/auto/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -118,6 +118,7 @@ private slots:
void postEvent();
void stateFinished();
void parallelStates();
+ void parallelRootState();
void allSourceToTargetConfigurations();
void signalTransitions();
void eventTransitions();
@@ -1633,6 +1634,29 @@ void tst_QStateMachine::parallelStates()
QVERIFY(machine.configuration().contains(s2));
}
+void tst_QStateMachine::parallelRootState()
+{
+ QStateMachine machine;
+ QState *root = machine.rootState();
+ QCOMPARE(root->childMode(), QState::ExclusiveStates);
+ root->setChildMode(QState::ParallelStates);
+ QCOMPARE(root->childMode(), QState::ParallelStates);
+
+ QState *s1 = new QState(root);
+ QFinalState *s1_f = new QFinalState(s1);
+ s1->setInitialState(s1_f);
+ QState *s2 = new QState(root);
+ QFinalState *s2_f = new QFinalState(s2);
+ s2->setInitialState(s2_f);
+
+ QSignalSpy startedSpy(&machine, SIGNAL(started()));
+ QTest::ignoreMessage(QtWarningMsg, "QStateMachine::start: No initial state set for machine. Refusing to start.");
+ machine.start();
+ QCoreApplication::processEvents();
+ QEXPECT_FAIL("", "parallel root state is not supported (task 256587)", Continue);
+ QCOMPARE(startedSpy.count(), 1);
+}
+
void tst_QStateMachine::allSourceToTargetConfigurations()
{
QStateMachine machine;
@@ -1957,6 +1981,31 @@ void tst_QStateMachine::signalTransitions()
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s3));
}
+ // signature normalization
+ {
+ QStateMachine machine;
+ SignalEmitter emitter;
+ QState *s0 = new QState(machine.rootState());
+ QFinalState *s1 = new QFinalState(machine.rootState());
+ QSignalTransition *t0 = s0->addTransition(&emitter, SIGNAL( signalWithNoArg( ) ), s1);
+ QVERIFY(t0 != 0);
+ QCOMPARE(t0->signal(), QByteArray(SIGNAL( signalWithNoArg( ) )));
+
+ QSignalTransition *t1 = s0->addTransition(&emitter, SIGNAL( signalWithStringArg( const QString & ) ), s1);
+ QVERIFY(t1 != 0);
+ QCOMPARE(t1->signal(), QByteArray(SIGNAL( signalWithStringArg( const QString & ) )));
+
+ QSignalSpy startedSpy(&machine, SIGNAL(started()));
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.setInitialState(s0);
+ machine.start();
+ QTRY_COMPARE(startedSpy.count(), 1);
+ QCOMPARE(finishedSpy.count(), 0);
+
+ emitter.emitSignalWithNoArg();
+
+ QTRY_COMPARE(finishedSpy.count(), 1);
+ }
}
void tst_QStateMachine::eventTransitions()
diff --git a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
index e8cb089..f11aff9 100644
--- a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
+++ b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
@@ -75,7 +75,11 @@ private slots:
void stylePropagation() const;
void matrixForElement() const;
void gradientStops() const;
+ void gradientRefs();
void fillRule();
+ void opacity();
+ void paths();
+ void displayMode();
#ifndef QT_NO_COMPRESS
void testGzLoading();
@@ -331,7 +335,7 @@ void tst_QSvgRenderer::nestedQXmlStreamReader() const
QCOMPARE(reader.readNext(), QXmlStreamReader::StartDocument);
QCOMPARE(reader.readNext(), QXmlStreamReader::StartElement);
QCOMPARE(reader.name().toString(), QLatin1String("bar"));
-
+
QPicture picture;
QPainter painter(&picture);
QSvgRenderer renderer(&reader);
@@ -533,7 +537,10 @@ void tst_QSvgRenderer::gradientStops() const
QCOMPARE(image, refImage);
}
+}
+void tst_QSvgRenderer::gradientRefs()
+{
const char *svgs[] = {
"<svg>"
"<defs>"
@@ -565,6 +572,17 @@ void tst_QSvgRenderer::gradientStops() const
"</linearGradient>"
"</defs>"
"<rect fill=\"url(#gradient)\" height=\"8\" width=\"256\" x=\"0\" y=\"0\"/>"
+ "</svg>",
+ "<svg>"
+ "<rect fill=\"url(#gradient)\" height=\"8\" width=\"256\" x=\"0\" y=\"0\"/>"
+ "<defs>"
+ "<linearGradient id=\"gradient0\">"
+ "<stop offset=\"0\" stop-color=\"red\" stop-opacity=\"0\"/>"
+ "<stop offset=\"1\" stop-color=\"blue\"/>"
+ "</linearGradient>"
+ "<linearGradient id=\"gradient\" xlink:href=\"#gradient0\">"
+ "</linearGradient>"
+ "</defs>"
"</svg>"
};
for (int i = 0 ; i < sizeof(svgs) / sizeof(svgs[0]) ; ++i)
@@ -589,6 +607,7 @@ void tst_QSvgRenderer::gradientStops() const
}
}
+
#ifndef QT_NO_COMPRESS
void tst_QSvgRenderer::testGzLoading()
{
@@ -653,22 +672,257 @@ void tst_QSvgRenderer::testGzHelper()
void tst_QSvgRenderer::fillRule()
{
- QByteArray data(
+ static const char *svgs[] = {
+ // Paths
+ // Default fill-rule (nonzero)
"<svg>"
- "<rect x=\"0\" y=\"0\" height=\"300\" width=\"400\" fill=\"blue\" />"
- "<path d=\"M100 200 L300 200 L300 100 L100 100 M100 200 L300 200 L300 100 L100 100 Z\" fill=\"red\" stroke=\"black\" />"
- "</svg>");
+ " <rect x=\"0\" y=\"0\" height=\"30\" width=\"30\" fill=\"blue\" />"
+ " <path d=\"M10 0 L30 0 L30 30 L0 30 L0 10 L20 10 L20 20 L10 20 Z\" fill=\"red\" />"
+ "</svg>",
+ // nonzero
+ "<svg>"
+ " <rect x=\"0\" y=\"0\" height=\"30\" width=\"30\" fill=\"blue\" />"
+ " <path d=\"M10 0 L30 0 L30 30 L0 30 L0 10 L20 10 L20 20 L10 20 Z\" fill=\"red\" fill-rule=\"nonzero\" />"
+ "</svg>",
+ // evenodd
+ "<svg>"
+ " <rect x=\"0\" y=\"0\" height=\"30\" width=\"30\" fill=\"blue\" />"
+ " <path d=\"M10 0 L30 0 L30 30 L0 30 L0 10 L20 10 L20 20 L10 20 Z\" fill=\"red\" fill-rule=\"evenodd\" />"
+ "</svg>",
- QSvgRenderer renderer(data);
+ // Polygons
+ // Default fill-rule (nonzero)
+ "<svg>"
+ " <rect x=\"0\" y=\"0\" height=\"30\" width=\"30\" fill=\"blue\" />"
+ " <polygon points=\"10 0 30 0 30 30 0 30 0 10 20 10 20 20 10 20\" fill=\"red\" />"
+ "</svg>",
+ // nonzero
+ "<svg>"
+ " <rect x=\"0\" y=\"0\" height=\"30\" width=\"30\" fill=\"blue\" />"
+ " <polygon points=\"10 0 30 0 30 30 0 30 0 10 20 10 20 20 10 20\" fill=\"red\" fill-rule=\"nonzero\" />"
+ "</svg>",
+ // evenodd
+ "<svg>"
+ " <rect x=\"0\" y=\"0\" height=\"30\" width=\"30\" fill=\"blue\" />"
+ " <polygon points=\"10 0 30 0 30 30 0 30 0 10 20 10 20 20 10 20\" fill=\"red\" fill-rule=\"evenodd\" />"
+ "</svg>"
+ };
- QImage image(128, 128, QImage::Format_ARGB32_Premultiplied);
- image.fill(0);
+ const int COUNT = sizeof(svgs) / sizeof(svgs[0]);
+ QImage refImageNonZero(30, 30, QImage::Format_ARGB32_Premultiplied);
+ QImage refImageEvenOdd(30, 30, QImage::Format_ARGB32_Premultiplied);
+ refImageNonZero.fill(0xffff0000);
+ refImageEvenOdd.fill(0xffff0000);
+ QPainter p;
+ p.begin(&refImageNonZero);
+ p.fillRect(QRectF(0, 0, 10, 10), Qt::blue);
+ p.end();
+ p.begin(&refImageEvenOdd);
+ p.fillRect(QRectF(0, 0, 10, 10), Qt::blue);
+ p.fillRect(QRectF(10, 10, 10, 10), Qt::blue);
+ p.end();
+
+ for (int i = 0; i < COUNT; ++i) {
+ QByteArray data(svgs[i]);
+ QSvgRenderer renderer(data);
+ QImage image(30, 30, QImage::Format_ARGB32_Premultiplied);
+ image.fill(0);
+ p.begin(&image);
+ renderer.render(&p);
+ p.end();
+ QCOMPARE(image, i % 3 == 2 ? refImageEvenOdd : refImageNonZero);
+ }
+}
+static void opacity_drawSvgAndVerify(const QByteArray &data)
+{
+ QSvgRenderer renderer(data);
+ QVERIFY(renderer.isValid());
+ QImage image(10, 10, QImage::Format_ARGB32_Premultiplied);
+ image.fill(0xffff00ff);
QPainter painter(&image);
renderer.render(&painter);
painter.end();
+ QCOMPARE(image.pixel(5, 5), 0xff7f7f7f);
+}
+
+void tst_QSvgRenderer::opacity()
+{
+ static const char *opacities[] = {"-1,4641", "0", "0.5", "1", "1.337"};
+ static const char *firstColors[] = {"#7f7f7f", "#7f7f7f", "#402051", "blue", "#123456"};
+ static const char *secondColors[] = {"red", "#bad", "#bedead", "#7f7f7f", "#7f7f7f"};
+
+ // Fill-opacity
+ for (int i = 0; i < 5; ++i) {
+ QByteArray data("<svg><rect x=\"0\" y=\"0\" height=\"10\" width=\"10\" fill=\"");
+ data.append(firstColors[i]);
+ data.append("\"/><rect x=\"0\" y=\"0\" height=\"10\" width=\"10\" fill=\"");
+ data.append(secondColors[i]);
+ data.append("\" fill-opacity=\"");
+ data.append(opacities[i]);
+ data.append("\"/></svg>");
+ opacity_drawSvgAndVerify(data);
+ }
+ // Stroke-opacity
+ for (int i = 0; i < 5; ++i) {
+ QByteArray data("<svg viewBox=\"0 0 10 10\"><polyline points=\"0 5 10 5\" fill=\"none\" stroke=\"");
+ data.append(firstColors[i]);
+ data.append("\" stroke-width=\"10\"/><line x1=\"5\" y1=\"0\" x2=\"5\" y2=\"10\" fill=\"none\" stroke=\"");
+ data.append(secondColors[i]);
+ data.append("\" stroke-width=\"10\" stroke-opacity=\"");
+ data.append(opacities[i]);
+ data.append("\"/></svg>");
+ opacity_drawSvgAndVerify(data);
+ }
+ // As gradients:
+ // Fill-opacity
+ for (int i = 0; i < 5; ++i) {
+ QByteArray data("<svg><defs><linearGradient id=\"gradient\"><stop offset=\"0\" stop-color=\"");
+ data.append(secondColors[i]);
+ data.append("\"/><stop offset=\"1\" stop-color=\"");
+ data.append(secondColors[i]);
+ data.append("\"/></linearGradient></defs><rect x=\"0\" y=\"0\" height=\"10\" width=\"10\" fill=\"");
+ data.append(firstColors[i]);
+ data.append("\"/><rect x=\"0\" y=\"0\" height=\"10\" width=\"10\" fill=\"url(#gradient)\" fill-opacity=\"");
+ data.append(opacities[i]);
+ data.append("\"/></svg>");
+ opacity_drawSvgAndVerify(data);
+ }
+ // When support for gradients on strokes has been implemented, add the code below.
+ /*
+ // Stroke-opacity
+ for (int i = 0; i < 5; ++i) {
+ QByteArray data("<svg viewBox=\"0 0 10 10\"><defs><linearGradient id=\"grad\"><stop offset=\"0\" stop-color=\"");
+ data.append(secondColors[i]);
+ data.append("\"/><stop offset=\"1\" stop-color=\"");
+ data.append(secondColors[i]);
+ data.append("\"/></linearGradient></defs><polyline points=\"0 5 10 5\" fill=\"none\" stroke=\"");
+ data.append(firstColors[i]);
+ data.append("\" stroke-width=\"10\" /><line x1=\"5\" y1=\"0\" x2=\"5\" y2=\"10\" fill=\"none\" stroke=\"url(#grad)\" stroke-width=\"10\" stroke-opacity=\"");
+ data.append(opacities[i]);
+ data.append("\" /></svg>");
+ opacity_drawSvgAndVerify(data);
+ }
+ */
+}
+
+void tst_QSvgRenderer::paths()
+{
+ static const char *svgs[] = {
+ // Absolute coordinates, explicit commands.
+ "<svg>"
+ " <rect x=\"0\" y=\"0\" height=\"50\" width=\"50\" fill=\"blue\" />"
+ " <path d=\"M50 0 V50 H0 Q0 25 25 25 T50 0 C25 0 50 50 25 50 S25 0 0 0 Z\" fill=\"red\" fill-rule=\"evenodd\"/>"
+ "</svg>",
+ // Absolute coordinates, implicit commands.
+ "<svg>"
+ " <rect x=\"0\" y=\"0\" height=\"50\" width=\"50\" fill=\"blue\" />"
+ " <path d=\"M50 0 50 50 0 50 Q0 25 25 25 Q50 25 50 0 C25 0 50 50 25 50 C0 50 25 0 0 0 Z\" fill=\"red\" fill-rule=\"evenodd\" />"
+ "</svg>",
+ // Relative coordinates, explicit commands.
+ "<svg>"
+ " <rect x=\"0\" y=\"0\" height=\"50\" width=\"50\" fill=\"blue\" />"
+ " <path d=\"m50 0 v50 h-50 q0 -25 25 -25 t25 -25 c-25 0 0 50 -25 50 s0 -50 -25 -50 z\" fill=\"red\" fill-rule=\"evenodd\" />"
+ "</svg>",
+ // Relative coordinates, implicit commands.
+ "<svg>"
+ " <rect x=\"0\" y=\"0\" height=\"50\" width=\"50\" fill=\"blue\" />"
+ " <path d=\"m50 0 0 50 -50 0 q0 -25 25 -25 25 0 25 -25 c-25 0 0 50 -25 50 -25 0 0 -50 -25 -50 z\" fill=\"red\" fill-rule=\"evenodd\" />"
+ "</svg>",
+ // Absolute coordinates, explicit commands, minimal whitespace.
+ "<svg>"
+ " <rect x=\"0\" y=\"0\" height=\"50\" width=\"50\" fill=\"blue\" />"
+ " <path d=\"m50 0v50h-50q0-25 25-25t25-25c-25 0 0 50-25 50s0-50-25-50z\" fill=\"red\" fill-rule=\"evenodd\" />"
+ "</svg>",
+ // Absolute coordinates, explicit commands, extra whitespace.
+ "<svg>"
+ " <rect x=\"0\" y=\"0\" height=\"50\" width=\"50\" fill=\"blue\" />"
+ " <path d=\" M 50 0 V 50 H 0 Q 0 25 25 25 T 50 0 C 25 0 50 50 25 50 S 25 0 0 0 Z \" fill=\"red\" fill-rule=\"evenodd\" />"
+ "</svg>"
+ };
+
+ const int COUNT = sizeof(svgs) / sizeof(svgs[0]);
+ QImage images[COUNT];
+ QPainter p;
+
+ for (int i = 0; i < COUNT; ++i) {
+ QByteArray data(svgs[i]);
+ QSvgRenderer renderer(data);
+ QVERIFY(renderer.isValid());
+ images[i] = QImage(50, 50, QImage::Format_ARGB32_Premultiplied);
+ images[i].fill(0);
+ p.begin(&images[i]);
+ renderer.render(&p);
+ p.end();
+ if (i != 0) {
+ QCOMPARE(images[i], images[0]);
+ }
+ }
+}
+
+void tst_QSvgRenderer::displayMode()
+{
+ static const char *svgs[] = {
+ // All visible.
+ "<svg>"
+ " <g>"
+ " <rect x=\"0\" y=\"0\" height=\"10\" width=\"10\" fill=\"red\" />"
+ " <rect x=\"0\" y=\"0\" height=\"10\" width=\"10\" fill=\"blue\" />"
+ " </g>"
+ "</svg>",
+ // Don't display svg element.
+ "<svg display=\"none\">"
+ " <g>"
+ " <rect x=\"0\" y=\"0\" height=\"10\" width=\"10\" fill=\"red\" />"
+ " <rect x=\"0\" y=\"0\" height=\"10\" width=\"10\" fill=\"blue\" />"
+ " </g>"
+ "</svg>",
+ // Don't display g element.
+ "<svg>"
+ " <g display=\"none\">"
+ " <rect x=\"0\" y=\"0\" height=\"10\" width=\"10\" fill=\"red\" />"
+ " <rect x=\"0\" y=\"0\" height=\"10\" width=\"10\" fill=\"blue\" />"
+ " </g>"
+ "</svg>",
+ // Don't display first rect element.
+ "<svg>"
+ " <g>"
+ " <rect x=\"0\" y=\"0\" height=\"10\" width=\"10\" fill=\"red\" display=\"none\" />"
+ " <rect x=\"0\" y=\"0\" height=\"10\" width=\"10\" fill=\"blue\" />"
+ " </g>"
+ "</svg>",
+ // Don't display second rect element.
+ "<svg>"
+ " <g>"
+ " <rect x=\"0\" y=\"0\" height=\"10\" width=\"10\" fill=\"red\" />"
+ " <rect x=\"0\" y=\"0\" height=\"10\" width=\"10\" fill=\"blue\" display=\"none\" />"
+ " </g>"
+ "</svg>",
+ // Don't display svg element, but set display mode to "inline" for other elements.
+ "<svg display=\"none\">"
+ " <g display=\"inline\">"
+ " <rect x=\"0\" y=\"0\" height=\"10\" width=\"10\" fill=\"red\" display=\"inline\" />"
+ " <rect x=\"0\" y=\"0\" height=\"10\" width=\"10\" fill=\"blue\" display=\"inline\" />"
+ " </g>"
+ "</svg>"
+ };
+
+ QRgb expectedColors[] = {0xff0000ff, 0xff00ff00, 0xff00ff00, 0xff0000ff, 0xffff0000, 0xff00ff00};
+
+ const int COUNT = sizeof(svgs) / sizeof(svgs[0]);
+ QPainter p;
- QCOMPARE(image.pixel(64, 64), QColor(Qt::red).rgba());
+ for (int i = 0; i < COUNT; ++i) {
+ QByteArray data(svgs[i]);
+ QSvgRenderer renderer(data);
+ QVERIFY(renderer.isValid());
+ QImage image(10, 10, QImage::Format_ARGB32_Premultiplied);
+ image.fill(0xff00ff00);
+ p.begin(&image);
+ renderer.render(&p);
+ p.end();
+ QCOMPARE(image.pixel(5, 5), expectedColors[i]);
+ }
}
QTEST_MAIN(tst_QSvgRenderer)