diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2010-03-29 08:45:22 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2010-03-29 08:45:22 (GMT) |
commit | de306893b464ed0fa00f98488912fd6269713519 (patch) | |
tree | b1ef87ee3e5afa0722c9da87a45e11ff3f620fdc /tests/auto | |
parent | 4fb6cae4dd0c6a90008780df606abb8a9e73cb2c (diff) | |
parent | 473da75ed84651c70ae0d10e23f09e1a0e4ae799 (diff) | |
download | Qt-de306893b464ed0fa00f98488912fd6269713519.zip Qt-de306893b464ed0fa00f98488912fd6269713519.tar.gz Qt-de306893b464ed0fa00f98488912fd6269713519.tar.bz2 |
Merge remote branch 'origin/4.6' into qt-4.7-from-4.6
Conflicts:
mkspecs/common/symbian/symbian.conf
qmake/generators/symbian/symmake.cpp
src/3rdparty/webkit/WebCore/WebCore.pro
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp | 178 | ||||
-rw-r--r-- | tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp | 44 | ||||
-rw-r--r-- | tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 125 | ||||
-rw-r--r-- | tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp | 28 | ||||
-rw-r--r-- | tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 13 | ||||
-rw-r--r-- | tests/auto/qsqlquery/tst_qsqlquery.cpp | 9 | ||||
-rw-r--r-- | tests/auto/qstatemachine/tst_qstatemachine.cpp | 59 |
7 files changed, 356 insertions, 100 deletions
diff --git a/tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp b/tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp index f837564..f3c2c09 100644 --- a/tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp +++ b/tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp @@ -44,7 +44,7 @@ #include <q3sqlcursor.h> #include <qsqlfield.h> #include <qsqldriver.h> - +#include <QSet> #include "../qsqldatabase/tst_databases.h" @@ -122,7 +122,7 @@ void tst_Q3SqlCursor::generic_data(const QString &engine) { if ( dbs.fillTestTable(engine) == 0 ) { if(engine.isEmpty()) - QSKIP( "No database drivers are available in this Qt configuration", SkipAll ); + QSKIP( "No database drivers are available in this Qt configuration", SkipAll ); else QSKIP( (QString("No database drivers of type %1 are available in this Qt configuration").arg(engine)).toLocal8Bit(), SkipAll ); } @@ -131,7 +131,7 @@ void tst_Q3SqlCursor::generic_data(const QString &engine) void tst_Q3SqlCursor::createTestTables( QSqlDatabase db ) { if ( !db.isValid() ) - return; + return; QSqlQuery q( db ); if (tst_Databases::isSqlServer(db)) { @@ -143,20 +143,20 @@ void tst_Q3SqlCursor::createTestTables( QSqlDatabase db ) // please never ever change this table; otherwise fix all tests ;) if ( tst_Databases::isMSAccess( db ) ) { - QVERIFY_SQL(q, exec( "create table " + qtest + " ( id int not null, t_varchar varchar(40) not null," - "t_char char(40), t_numeric number, primary key (id, t_varchar) )" )); + QVERIFY_SQL(q, exec( "create table " + qtest + " ( id int not null, t_varchar varchar(40) not null," + "t_char char(40), t_numeric number, primary key (id, t_varchar) )" )); } else { - QVERIFY_SQL(q, exec( "create table " + qtest + " ( id int not null, t_varchar varchar(40) not null," - "t_char char(40), t_numeric numeric(6, 3), primary key (id, t_varchar) )" )); + QVERIFY_SQL(q, exec( "create table " + qtest + " ( id int not null, t_varchar varchar(40) not null," + "t_char char(40), t_numeric numeric(6, 3), primary key (id, t_varchar) )" )); } if ( tst_Databases::isSqlServer( db ) ) { - //workaround for SQL SERVER since he can store unicode only in nvarchar fields - QVERIFY_SQL(q, exec("create table " + qTableName("qtest_unicode", __FILE__) + " (id int not null, " - "t_varchar nvarchar(80) not null, t_char nchar(80) )" )); + //workaround for SQL SERVER since he can store unicode only in nvarchar fields + QVERIFY_SQL(q, exec("create table " + qTableName("qtest_unicode", __FILE__) + " (id int not null, " + "t_varchar nvarchar(80) not null, t_char nchar(80) )" )); } else { - QVERIFY_SQL(q, exec("create table " + qTableName("qtest_unicode", __FILE__) + " (id int not null, " - "t_varchar varchar(100) not null," "t_char char(100))" )); + QVERIFY_SQL(q, exec("create table " + qTableName("qtest_unicode", __FILE__) + " (id int not null, " + "t_varchar varchar(100) not null," "t_char char(100))" )); } if (tst_Databases::isMSAccess(db)) { @@ -169,7 +169,7 @@ void tst_Q3SqlCursor::createTestTables( QSqlDatabase db ) void tst_Q3SqlCursor::dropTestTables( QSqlDatabase db ) { if ( !db.isValid() ) - return; + return; QStringList tableNames; tableNames << qtest << qTableName( "qtest_unicode", __FILE__ ) @@ -183,7 +183,7 @@ void tst_Q3SqlCursor::dropTestTables( QSqlDatabase db ) void tst_Q3SqlCursor::populateTestTables( QSqlDatabase db ) { if (!db.isValid()) - return; + return; QSqlQuery q( db ); q.exec( "delete from " + qtest ); //not fatal @@ -200,21 +200,21 @@ void tst_Q3SqlCursor::initTestCase() dbs.open(); for ( QStringList::ConstIterator it = dbs.dbNames.begin(); it != dbs.dbNames.end(); ++it ) { - QSqlDatabase db = QSqlDatabase::database( (*it) ); - CHECK_DATABASE( db ); + QSqlDatabase db = QSqlDatabase::database( (*it) ); + CHECK_DATABASE( db ); - dropTestTables( db ); //in case of leftovers - createTestTables( db ); - populateTestTables( db ); + dropTestTables( db ); //in case of leftovers + createTestTables( db ); + populateTestTables( db ); } } void tst_Q3SqlCursor::cleanupTestCase() { for ( QStringList::ConstIterator it = dbs.dbNames.begin(); it != dbs.dbNames.end(); ++it ) { - QSqlDatabase db = QSqlDatabase::database( (*it) ); - CHECK_DATABASE( db ); - dropTestTables( db ); + QSqlDatabase db = QSqlDatabase::database( (*it) ); + CHECK_DATABASE( db ); + dropTestTables( db ); } dbs.close(); @@ -230,9 +230,9 @@ void tst_Q3SqlCursor::cleanup() QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); if ( QTest::currentTestFailed() ) { - //since Oracle ODBC totally craps out on error, we init again - db.close(); - db.open(); + //since Oracle ODBC totally craps out on error, we init again + db.close(); + db.open(); } } @@ -244,10 +244,10 @@ void tst_Q3SqlCursor::copyConstructor() Q3SqlCursor cur2; { - Q3SqlCursor cur( qtest, true, db ); - QVERIFY_SQL(cur, select( cur.index( QString("id") ) )); - cur2 = Q3SqlCursor( cur ); - // let "cur" run out of scope... + Q3SqlCursor cur( qtest, true, db ); + QVERIFY_SQL(cur, select( cur.index( QString("id") ) )); + cur2 = Q3SqlCursor( cur ); + // let "cur" run out of scope... } QSqlRecord* rec = cur2.primeUpdate(); @@ -256,8 +256,8 @@ void tst_Q3SqlCursor::copyConstructor() int i = 0; while ( cur2.next() ) { - QVERIFY( cur2.value("id").toInt() == i ); - i++; + QVERIFY( cur2.value("id").toInt() == i ); + i++; } } @@ -271,8 +271,8 @@ void tst_Q3SqlCursor::value() QVERIFY_SQL(cur, select( cur.index( QString("id") ) )); int i = 0; while ( cur.next() ) { - QCOMPARE(cur.value("id").toInt(), i); - i++; + QCOMPARE(cur.value("id").toInt(), i); + i++; } } @@ -285,11 +285,11 @@ void tst_Q3SqlCursor::primaryIndex() Q3SqlCursor cur( qtest, true, db ); QSqlIndex index = cur.primaryIndex(); if ( tst_Databases::isMSAccess( db ) ) { - QCOMPARE( index.fieldName(1).upper(), QString( "ID" ) ); - QCOMPARE( index.fieldName(0).upper(), QString( "T_VARCHAR" ) ); + QCOMPARE( index.fieldName(1).upper(), QString( "ID" ) ); + QCOMPARE( index.fieldName(0).upper(), QString( "T_VARCHAR" ) ); } else { - QCOMPARE( index.fieldName(0).upper(), QString( "ID" ) ); - QCOMPARE( index.fieldName(1).upper(), QString( "T_VARCHAR" ) ); + QCOMPARE( index.fieldName(0).upper(), QString( "ID" ) ); + QCOMPARE( index.fieldName(1).upper(), QString( "T_VARCHAR" ) ); } QVERIFY(!index.isDescending(0)); QVERIFY(!index.isDescending(1)); @@ -308,10 +308,10 @@ 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() ) ) ); + QFAIL( QString( "Wrong datatype %1 for field 'ID'" + " (expected Int or String)" ).arg( QVariant::typeToName( irec->field( 0 ).type() ) ) ); } QCOMPARE( QVariant::typeToName( irec->field( 1 ).type() ), QVariant::typeToName( QVariant::String ) ); QCOMPARE( QVariant::typeToName( irec->field( 2 ).type() ), QVariant::typeToName( QVariant::String ) ); @@ -327,7 +327,9 @@ void tst_Q3SqlCursor::insert() irec->setValue( "t_char", "SomeChar" ); irec->setValue( "t_numeric", 400.400 ); - QCOMPARE( cur.insert(), 1 ); + QSet<int> validReturns(QSet<int>() << -1 << 1); + + QVERIFY( validReturns.contains(cur.insert()) ); // restore old test-tables populateTestTables( db ); @@ -338,6 +340,7 @@ void tst_Q3SqlCursor::insertSpecial() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); + QSet<int> validReturns(QSet<int>() << -1 << 1); Q3SqlCursor cur( qtest, true, db ); QSqlRecord* irec = cur.primeInsert(); @@ -355,25 +358,25 @@ void tst_Q3SqlCursor::insertSpecial() // INSERT the strings QStringList::Iterator it; for ( it = strings.begin(); it != strings.end(); ++it ) { - QSqlRecord* irec = cur.primeInsert(); - QVERIFY( irec != 0 ); - irec->setValue( "id", i ); - irec->setValue( "t_varchar", (*it) ); - irec->setValue( "t_char", (*it) ); - irec->setValue( "t_numeric", (double)i ); - ++i; - QCOMPARE( cur.insert(), 1 ); + QSqlRecord* irec = cur.primeInsert(); + QVERIFY( irec != 0 ); + irec->setValue( "id", i ); + irec->setValue( "t_varchar", (*it) ); + irec->setValue( "t_char", (*it) ); + irec->setValue( "t_numeric", (double)i ); + ++i; + QVERIFY( validReturns.contains(cur.insert()) ); } QVERIFY( cur.select( "id >= 800 and id < 900" ) ); int i2 = 800; while( cur.next() ) { - QCOMPARE( cur.value( "id" ).toInt(), i2 ); - QCOMPARE( cur.value( "t_varchar" ).toString().stripWhiteSpace(), strings.at( i2 - 800 ) ); - QCOMPARE( cur.value( "t_char" ).toString().stripWhiteSpace(), strings.at( i2 - 800 ) ); - QCOMPARE( cur.value( "t_numeric" ).toDouble(), (double)i2 ); - ++i2; + QCOMPARE( cur.value( "id" ).toInt(), i2 ); + QCOMPARE( cur.value( "t_varchar" ).toString().stripWhiteSpace(), strings.at( i2 - 800 ) ); + QCOMPARE( cur.value( "t_char" ).toString().stripWhiteSpace(), strings.at( i2 - 800 ) ); + QCOMPARE( cur.value( "t_numeric" ).toDouble(), (double)i2 ); + ++i2; } QCOMPARE( i, i2 ); @@ -385,6 +388,7 @@ void tst_Q3SqlCursor::batchInsert() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); + QSet<int> validReturns(QSet<int>() << -1 << 1); QSqlQuery q( db ); q.exec( "delete from " + qtest ); @@ -393,16 +397,16 @@ void tst_Q3SqlCursor::batchInsert() int i = 0; for ( ; i < 100; ++i ) { - QSqlRecord* irec = cur.primeInsert(); - Q_ASSERT( irec ); - irec->setValue( "id", i ); - irec->setValue( "t_varchar", "blah" ); - irec->setValue( "t_char", "blah" ); - irec->setValue( "t_numeric", 1.1 ); - if ( db.driverName().startsWith( "QSQLITE" ) ) { - QVERIFY( cur.insert( true ) ); - } else { - QCOMPARE( cur.insert( true ), 1 ); + QSqlRecord* irec = cur.primeInsert(); + Q_ASSERT( irec ); + irec->setValue( "id", i ); + irec->setValue( "t_varchar", "blah" ); + irec->setValue( "t_char", "blah" ); + irec->setValue( "t_numeric", 1.1 ); + if ( db.driverName().startsWith( "QSQLITE" ) ) { + QVERIFY( cur.insert( true ) ); + } else { + QVERIFY( validReturns.contains(cur.insert( true )) ); } } @@ -413,18 +417,18 @@ void tst_Q3SqlCursor::batchInsert() irec->setValue( "t_varchar", "blah" ); irec->setValue( "t_char", "blah" ); irec->setValue( "t_numeric", 1.1 ); - if ( db.driverName().startsWith( "QSQLITE" ) ) { - QVERIFY( cur.insert( false ) ); - } else { - QCOMPARE( cur.insert( false ), 1 ); + if ( db.driverName().startsWith( "QSQLITE" ) ) { + QVERIFY( cur.insert( false ) ); + } else { + QVERIFY( validReturns.contains(cur.insert( false )) ); } } i = 0; QVERIFY_SQL(q, exec( "select * from " + qtest + " order by id" )); while ( q.next() ) { - QCOMPARE( q.value( 0 ).toInt(), i ); - i++; + QCOMPARE( q.value( 0 ).toInt(), i ); + i++; } QCOMPARE( i, 200 ); @@ -436,7 +440,7 @@ static QString dumpUtf8( const QString& str ) { QString res; for ( int i = 0; i < (int)str.length(); ++i ) { - res += "0x" + QString::number( str[ i ].unicode(), 16 ) + ' '; + res += "0x" + QString::number( str[ i ].unicode(), 16 ) + ' '; } return res; } @@ -448,7 +452,7 @@ void tst_Q3SqlCursor::insertORA() CHECK_DATABASE( db ); if (tst_Databases::getOraVersion(db) < 9) - QSKIP("Need Oracle >= 9", SkipSingle); + QSKIP("Need Oracle >= 9", SkipSingle); /****** CHARSET TEST ******/ @@ -466,8 +470,8 @@ void tst_Q3SqlCursor::insertORA() QVERIFY_SQL(cur, select()); QVERIFY( cur.next() ); if ( cur.value( "t_char" ).toString() != val1 ) - qDebug( QString( "Wrong value for t_char: expected '%1', got '%2'" ).arg( val1 ).arg( - cur.value( "t_char" ).toString() ) ); + qDebug( QString( "Wrong value for t_char: expected '%1', got '%2'" ).arg( val1 ).arg( + cur.value( "t_char" ).toString() ) ); static const unsigned short utf8arr[] = { 0xd792,0xd79c,0xd792,0xd79c,0xd799,0x00 }; static const QString utf8str = QString::fromUcs2( utf8arr ); @@ -524,7 +528,7 @@ void tst_Q3SqlCursor::unicode() static const QString utf8str = QString::fromUtf8( "ὕαλον ϕαγεῖν δύναμαι· τοῦτο οὔ με βλάπτει." ); if ( !db.driver()->hasFeature( QSqlDriver::Unicode ) ) { - QSKIP( "DBMS not Unicode capable", SkipSingle ); + QSKIP( "DBMS not Unicode capable", SkipSingle ); } // ascii in the data storage, can't transliterate properly. invalid test. if(db.driverName().startsWith("QIBASE") && (db.databaseName() == "silence.nokia.troll.no:c:\\ibase\\testdb_ascii" || db.databaseName() == "/opt/interbase/qttest.gdb")) @@ -640,11 +644,11 @@ void tst_Q3SqlCursor::select() QSqlIndex idx = cur4.primaryIndex( false ); QCOMPARE( (int)idx.count(), 2 ); if ( tst_Databases::isMSAccess( db ) ) { - QCOMPARE( idx.field( 1 ).name().upper(), QString("ID") ); - QCOMPARE( idx.field( 0 ).name().upper(), QString("T_VARCHAR") ); + QCOMPARE( idx.field( 1 ).name().upper(), QString("ID") ); + QCOMPARE( idx.field( 0 ).name().upper(), QString("T_VARCHAR") ); } else { - QCOMPARE( idx.field( 0 ).name().upper(), QString("ID") ); - QCOMPARE( idx.field( 1 ).name().upper(), QString("T_VARCHAR") ); + QCOMPARE( idx.field( 0 ).name().upper(), QString("ID") ); + QCOMPARE( idx.field( 1 ).name().upper(), QString("T_VARCHAR") ); } #ifdef QT_DEBUG @@ -688,17 +692,18 @@ void tst_Q3SqlCursor::updateNoPK() QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); - + QSet<int> validReturns(QSet<int>() << -1 << 1); + QSqlQuery q(db); QVERIFY_SQL(q, exec("create table " + qTableName( "qtestPK", __FILE__ ) + " (id int, name varchar(20), num numeric)")); - + Q3SqlCursor cur(qTableName("qtestPK", __FILE__), true, db); QSqlRecord* rec = cur.primeInsert(); Q_ASSERT(rec); rec->setNull(0); rec->setNull(1); rec->setNull(2); - QVERIFY_SQL(cur, insert() == 1); + QVERIFY(validReturns.contains(cur.insert())); if (!db.driver()->hasFeature(QSqlDriver::PreparedQueries)) { // Only QPSQL, QMYSQL, QODBC and QOCI drivers currently use escape identifiers for column names @@ -713,8 +718,8 @@ void tst_Q3SqlCursor::updateNoPK() + " values (NULL,NULL,NULL)"); QCOMPARE(cur.lastQuery(), query); } else { - QCOMPARE(cur.lastQuery(), QString::fromLatin1("insert into " + qTableName("qtestPK", __FILE__) + - " (\"id\",\"name\",\"num\") values (NULL,NULL,NULL)")); + QCOMPARE(cur.lastQuery(), QString::fromLatin1("insert into " + qTableName("qtestPK", __FILE__) + + " (\"id\",\"name\",\"num\") values (NULL,NULL,NULL)")); } } @@ -733,7 +738,7 @@ void tst_Q3SqlCursor::updateNoPK() qTableName("qtestPK", __FILE__) + ".num IS NULL"; if (!db.driver()->hasFeature(QSqlDriver::PreparedQueries)) { if (!db.driverName().startsWith("QSQLITE")) { - QCOMPARE(cur.lastQuery(), expect); + QCOMPARE(cur.lastQuery(), expect); } } QVERIFY(cur.select(cur.index(QString("id")))); @@ -750,6 +755,7 @@ void tst_Q3SqlCursor::insertFieldNameContainsWS() { QFETCH( QString, dbName ); QSqlDatabase db = QSqlDatabase::database( dbName ); CHECK_DATABASE( db ); + QSet<int> validReturns(QSet<int>() << -1 << 1); // The bugfix (and this test) depends on QSqlDriver::escapeIdentifier(...) // to be implemented, which is currently only the case for the @@ -778,7 +784,7 @@ void tst_Q3SqlCursor::insertFieldNameContainsWS() { r->setValue("firsT NaMe", "Kong"); r->setValue("lastNaMe", "Harald"); - QVERIFY(cur.insert() == 1); + QVERIFY(validReturns.contains(cur.insert())); cur.select(); cur.next(); diff --git a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp index 1007d61..49b840f 100644 --- a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp +++ b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp @@ -46,6 +46,7 @@ #include <QtGui/qgraphicsview.h> #include <QtGui/qgraphicsscene.h> #include <QtGui/qgraphicsitem.h> +#include <QtGui/qgraphicswidget.h> #include <QtGui/qstyleoption.h> #include "../../shared/util.h" @@ -73,6 +74,7 @@ private slots: void deviceCoordinateTranslateCaching(); void inheritOpacity(); void dropShadowClipping(); + void childrenVisibilityShouldInvalidateCache(); }; void tst_QGraphicsEffect::initTestCase() @@ -510,6 +512,7 @@ void tst_QGraphicsEffect::drawPixmapItem() QGraphicsView view(&scene); view.show(); QTest::qWaitForWindowShown(&view); + QTRY_VERIFY(effect->repaints >= 1); item->rotate(180); QTest::qWait(50); @@ -613,6 +616,47 @@ void tst_QGraphicsEffect::dropShadowClipping() QCOMPARE(img.pixel(x, y), img.pixel(x, y-1)); } +class MyGraphicsItem : public QGraphicsWidget +{ +public: + MyGraphicsItem(QGraphicsItem *parent = 0) : + QGraphicsWidget(parent), nbPaint(0) + {} + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + { + nbPaint++; + QGraphicsWidget::paint(painter, option, widget); + } + int nbPaint; +}; + +void tst_QGraphicsEffect::childrenVisibilityShouldInvalidateCache() +{ + QGraphicsScene scene; + MyGraphicsItem parent; + parent.resize(200, 200); + QGraphicsWidget child(&parent); + child.resize(200, 200); + child.setVisible(false); + scene.addItem(&parent); + QGraphicsView view(&scene); + view.show(); + QApplication::setActiveWindow(&view); + QTest::qWaitForWindowShown(&view); + QTRY_COMPARE(parent.nbPaint, 1); + //we set an effect on the parent + parent.setGraphicsEffect(new QGraphicsDropShadowEffect(&parent)); + //flush the events + QApplication::processEvents(); + //new effect applied->repaint + QCOMPARE(parent.nbPaint, 2); + child.setVisible(true); + //flush the events + QApplication::processEvents(); + //a new child appears we need to redraw the effect. + QCOMPARE(parent.nbPaint, 3); +} + QTEST_MAIN(tst_QGraphicsEffect) #include "tst_qgraphicseffect.moc" diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 92a7f2e..01ef9a2 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -384,6 +384,7 @@ private slots: void tabChangesFocus(); void tabChangesFocus_data(); void cacheMode(); + void cacheMode2(); void updateCachedItemAfterMove(); void deviceTransform_data(); void deviceTransform(); @@ -439,6 +440,7 @@ private slots: void QTBUG_7714_fullUpdateDiscardingOpacityUpdate2(); void QT_2653_fullUpdateDiscardingOpacityUpdate(); void QT_2649_focusScope(); + void sortItemsWhileAdding(); private: QList<QGraphicsItem *> paintedItems; @@ -6823,6 +6825,9 @@ void tst_QGraphicsItem::cacheMode() QTRY_COMPARE(tester->repaints, 4); QCOMPARE(testerChild->repaints, 4); QCOMPARE(testerChild2->repaints, 3); + tester->resetTransform(); + testerChild->resetTransform(); + testerChild2->resetTransform(); // Explicit update causes a repaint. tester->update(0, 0, 5, 5); @@ -6896,23 +6901,24 @@ void tst_QGraphicsItem::cacheMode() // because the parent is rotated with a perspective. testerChild->setPos(1, 1); QTest::qWait(25); - QTRY_COMPARE(tester->repaints, 10); + QTRY_COMPARE(tester->repaints, 11); QCOMPARE(testerChild->repaints, 10); QCOMPARE(testerChild2->repaints, 5); + tester->resetTransform(); // Make a huge item tester->setGeometry(QRectF(-4000, -4000, 8000, 8000)); QTest::qWait(25); - QTRY_COMPARE(tester->repaints, 11); - QCOMPARE(testerChild->repaints, 10); + QTRY_COMPARE(tester->repaints, 12); + QCOMPARE(testerChild->repaints, 11); QCOMPARE(testerChild2->repaints, 5); // Move the large item - will cause a repaint as the // cache is clipped. tester->setPos(5, 0); QTest::qWait(25); - QTRY_COMPARE(tester->repaints, 12); - QCOMPARE(testerChild->repaints, 10); + QTRY_COMPARE(tester->repaints, 13); + QCOMPARE(testerChild->repaints, 11); QCOMPARE(testerChild2->repaints, 5); // Hiding and showing should invalidate the cache @@ -6920,11 +6926,83 @@ void tst_QGraphicsItem::cacheMode() QTest::qWait(25); tester->show(); QTest::qWait(25); - QTRY_COMPARE(tester->repaints, 13); - QCOMPARE(testerChild->repaints, 11); + QTRY_COMPARE(tester->repaints, 14); + QCOMPARE(testerChild->repaints, 12); QCOMPARE(testerChild2->repaints, 6); } +void tst_QGraphicsItem::cacheMode2() +{ + QGraphicsScene scene(0, 0, 100, 100); + QGraphicsView view(&scene); + view.resize(150, 150); + view.show(); + QApplication::setActiveWindow(&view); + QTest::qWaitForWindowShown(&view); + + // Increase the probability of window activation + // not causing another repaint of test items. + QTest::qWait(50); + + EventTester *tester = new EventTester; + scene.addItem(tester); + QTest::qWait(10); + QTRY_COMPARE(tester->repaints, 1); + + // Switching from NoCache to NoCache (no repaint) + tester->setCacheMode(QGraphicsItem::NoCache); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 1); + + // Switching from NoCache to DeviceCoordinateCache (no repaint) + tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 1); + + // Switching from DeviceCoordinateCache to DeviceCoordinateCache (no repaint) + tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 1); + + // Switching from DeviceCoordinateCache to NoCache (no repaint) + tester->setCacheMode(QGraphicsItem::NoCache); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 1); + + // Switching from NoCache to ItemCoordinateCache (repaint) + tester->setCacheMode(QGraphicsItem::ItemCoordinateCache); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 2); + + // Switching from ItemCoordinateCache to ItemCoordinateCache (no repaint) + tester->setCacheMode(QGraphicsItem::ItemCoordinateCache); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 2); + + // Switching from ItemCoordinateCache to ItemCoordinateCache with different size (repaint) + tester->setCacheMode(QGraphicsItem::ItemCoordinateCache, QSize(100, 100)); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 3); + + // Switching from ItemCoordinateCache to NoCache (repaint) + tester->setCacheMode(QGraphicsItem::NoCache); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 4); + + // Switching from DeviceCoordinateCache to ItemCoordinateCache (repaint) + tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 4); + tester->setCacheMode(QGraphicsItem::ItemCoordinateCache); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 5); + + // Switching from ItemCoordinateCache to DeviceCoordinateCache (repaint) + tester->setCacheMode(QGraphicsItem::DeviceCoordinateCache); + QTest::qWait(50); + QTRY_COMPARE(tester->repaints, 6); +} + void tst_QGraphicsItem::updateCachedItemAfterMove() { // A simple item that uses ItemCoordinateCache @@ -10083,5 +10161,38 @@ void tst_QGraphicsItem::QT_2649_focusScope() delete scene; } +class MyGraphicsItemWithItemChange : public QGraphicsWidget +{ +public: + MyGraphicsItemWithItemChange(QGraphicsItem *parent = 0) : QGraphicsWidget(parent) + {} + + QVariant itemChange(GraphicsItemChange change, const QVariant &value) + { + if (change == QGraphicsItem::ItemSceneHasChanged) { + foreach (QGraphicsView *view, scene()->views()) { + //We trigger a sort of unindexed items in the BSP + view->sceneRect(); + } + } + return QGraphicsWidget::itemChange(change, value); + } +}; + +void tst_QGraphicsItem::sortItemsWhileAdding() +{ + QGraphicsScene scene; + QGraphicsView view(&scene); + QGraphicsWidget grandGrandParent; + grandGrandParent.resize(200, 200); + scene.addItem(&grandGrandParent); + QGraphicsWidget grandParent; + grandParent.resize(200, 200); + QGraphicsWidget parent(&grandParent); + parent.resize(200, 200); + MyGraphicsItemWithItemChange item(&parent); + grandParent.setParentItem(&grandGrandParent); +} + QTEST_MAIN(tst_QGraphicsItem) #include "tst_qgraphicsitem.moc" diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index 587b7d5..4c0bc78 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -111,6 +111,8 @@ private slots: void fontPropagationSceneChange(); void geometry_data(); void geometry(); + void width(); + void height(); void getContentsMargins_data(); void getContentsMargins(); void initStyleOption_data(); @@ -776,6 +778,32 @@ void tst_QGraphicsWidget::geometry() QCOMPARE(widget.geometry(), QRectF(pos, size)); } +void tst_QGraphicsWidget::width() +{ + QGraphicsWidget w; + QCOMPARE(w.property("width").toReal(), qreal(0)); + QSignalSpy spy(&w, SIGNAL(widthChanged())); + w.setProperty("width", qreal(50)); + QCOMPARE(w.property("width").toReal(), qreal(50)); + QCOMPARE(spy.count(), 1); + //calling old school setGeometry should work too + w.setGeometry(0, 0, 200, 200); + QCOMPARE(spy.count(), 2); +} + +void tst_QGraphicsWidget::height() +{ + QGraphicsWidget w; + QCOMPARE(w.property("height").toReal(), qreal(0)); + QSignalSpy spy(&w, SIGNAL(heightChanged())); + w.setProperty("height", qreal(50)); + QCOMPARE(w.property("height").toReal(), qreal(50)); + QCOMPARE(spy.count(), 1); + //calling old school setGeometry should work too + w.setGeometry(0, 0, 200, 200); + QCOMPARE(spy.count(), 2); +} + void tst_QGraphicsWidget::getContentsMargins_data() { QTest::addColumn<qreal>("left"); diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index 4922a89..e269092 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -283,6 +283,9 @@ private Q_SLOTS: void ignoreSslErrorsListWithSlot_data(); void ignoreSslErrorsListWithSlot(); #endif + + // NOTE: This test must be last! + void parentingRepliesToTheApp(); }; QT_BEGIN_NAMESPACE @@ -3931,7 +3934,7 @@ void tst_QNetworkReply::httpConnectionCount() for (int i = 0; i < 10; i++) { QNetworkRequest request (QUrl("http://127.0.0.1:" + QString::number(server.serverPort()) + "/" + QString::number(i))); QNetworkReply* reply = manager.get(request); - reply->setParent(this); + reply->setParent(&server); } int pendingConnectionCount = 0; @@ -4205,5 +4208,13 @@ void tst_QNetworkReply::ignoreSslErrorsListWithSlot() #endif // QT_NO_OPENSSL +// NOTE: This test must be last testcase in tst_qnetworkreply! +void tst_QNetworkReply::parentingRepliesToTheApp() +{ + QNetworkRequest request (QUrl("http://" + QtNetworkSettings::serverName())); + manager.get(request)->setParent(this); // parent to this object + manager.get(request)->setParent(qApp); // parent to the app +} + QTEST_MAIN(tst_QNetworkReply) #include "tst_qnetworkreply.moc" diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp index b9ab73f..db3a929 100644 --- a/tests/auto/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp @@ -1137,17 +1137,14 @@ void tst_QSqlQuery::last() QVERIFY( q.last() ); - if ( !tst_Databases::isMSAccess( db ) ) - // Access doesn't return the correct position - QCOMPARE( q.at(), ( i-1 ) ); + QSet<int> validReturns(QSet<int>() << -1 << i-1); + QVERIFY( validReturns.contains(q.at()) ); QSqlQuery q2( "select * from " + qtest, db ); QVERIFY( q2.last() ); - if ( !tst_Databases::isMSAccess( db ) ) - // Access doesn't return the correct position - QCOMPARE( q.at(), ( i-1 ) ); + QVERIFY( validReturns.contains(q.at()) ); } void tst_QSqlQuery::seek() diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 90b5a22..2bf76e7 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -155,6 +155,7 @@ private slots: void clearError(); void historyStateHasNowhereToGo(); void historyStateAsInitialState(); + void historyStateAfterRestart(); void brokenStateIsNeverEntered(); void customErrorStateNotInGraph(); void transitionToStateNotInGraph(); @@ -906,6 +907,64 @@ void tst_QStateMachine::historyStateHasNowhereToGo() QCOMPARE(machine.errorString(), QString::fromLatin1("Missing default state in history state 'historyState'")); } +void tst_QStateMachine::historyStateAfterRestart() +{ + // QTBUG-8842 + QStateMachine machine; + + QState *s1 = new QState(&machine); + machine.setInitialState(s1); + QState *s2 = new QState(&machine); + QState *s21 = new QState(s2); + QState *s22 = new QState(s2); + QHistoryState *s2h = new QHistoryState(s2); + s2h->setDefaultState(s21); + s1->addTransition(new EventTransition(QEvent::User, s2h)); + s21->addTransition(new EventTransition(QEvent::User, s22)); + s2->addTransition(new EventTransition(QEvent::User, s1)); + + for (int x = 0; x < 2; ++x) { + QSignalSpy startedSpy(&machine, SIGNAL(started())); + machine.start(); + QTRY_COMPARE(startedSpy.count(), 1); + QCOMPARE(machine.configuration().count(), 1); + QVERIFY(machine.configuration().contains(s1)); + + // s1 -> s2h -> s21 (default state) + machine.postEvent(new QEvent(QEvent::User)); + QCoreApplication::processEvents(); + QCOMPARE(machine.configuration().count(), 2); + QVERIFY(machine.configuration().contains(s2)); + // This used to fail on the 2nd run because the + // history had not been cleared. + QVERIFY(machine.configuration().contains(s21)); + + // s21 -> s22 + machine.postEvent(new QEvent(QEvent::User)); + QCoreApplication::processEvents(); + QCOMPARE(machine.configuration().count(), 2); + QVERIFY(machine.configuration().contains(s2)); + QVERIFY(machine.configuration().contains(s22)); + + // s2 -> s1 (s22 saved in s2h) + machine.postEvent(new QEvent(QEvent::User)); + QCoreApplication::processEvents(); + QCOMPARE(machine.configuration().count(), 1); + QVERIFY(machine.configuration().contains(s1)); + + // s1 -> s2h -> s22 (saved state) + machine.postEvent(new QEvent(QEvent::User)); + QCoreApplication::processEvents(); + QCOMPARE(machine.configuration().count(), 2); + QVERIFY(machine.configuration().contains(s2)); + QVERIFY(machine.configuration().contains(s22)); + + QSignalSpy stoppedSpy(&machine, SIGNAL(stopped())); + machine.stop(); + QTRY_COMPARE(stoppedSpy.count(), 1); + } +} + void tst_QStateMachine::brokenStateIsNeverEntered() { QStateMachine machine; |