From 4204fdcc04e20eabd19704f2235ba06afa84605e Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 29 Oct 2009 17:32:57 +0100 Subject: Avoid infinite loop when laying out text with unconvertible chars When the stringToCMap() fails, it can be because it did not have enough space in the layout, or it can because of other errors. In order to implement "try-again" processing in a simple way, we had an infinite loop which assumed that stringToCMap() would always succeed in the second run (which would be the case if the only possible error was "not enough space".) Since there are other possible failures not related to the number of glyphs, you could easily get into an infinite loop here, e.g. when laying out text that contains the Byte Order Mark. The fix changes the implementation to explictly try stringToCMap() twice at max, and is also how it's implemented in the default qtextengine.cpp. Task-number: QTBUG-4680 Reviewed-by: Trond Conflicts: src/gui/text/qtextengine_mac.cpp tests/auto/qtextlayout/tst_qtextlayout.cpp --- tests/auto/qtextlayout/tst_qtextlayout.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests') diff --git a/tests/auto/qtextlayout/tst_qtextlayout.cpp b/tests/auto/qtextlayout/tst_qtextlayout.cpp index a5fed4e27f..b02a70455c 100644 --- a/tests/auto/qtextlayout/tst_qtextlayout.cpp +++ b/tests/auto/qtextlayout/tst_qtextlayout.cpp @@ -119,6 +119,7 @@ private slots: void smallTextLengthWordWrap(); void smallTextLengthWrapAtWordBoundaryOrAnywhere(); void testLineBreakingAllSpaces(); + void lineWidthFromBOM(); private: @@ -1277,5 +1278,18 @@ void tst_QTextLayout::widthOfTabs() QCOMPARE(qRound(engine.width(0, 5)), qRound(engine.boundingBox(0, 5).width)); } +void tst_QTextLayout::lineWidthFromBOM() +{ + const QString string(QChar(0xfeff)); // BYTE ORDER MARK + QTextLayout layout(string); + layout.beginLayout(); + QTextLine line = layout.createLine(); + line.setLineWidth(INT_MAX / 256); + layout.endLayout(); + + // Don't spin into an infinite loop + } + + QTEST_MAIN(tst_QTextLayout) #include "tst_qtextlayout.moc" -- cgit v1.2.3 From 91c09562ed9c6eb1bd3a4dbd84a8cc64647751ee Mon Sep 17 00:00:00 2001 From: Derick Hawcroft Date: Thu, 5 Nov 2009 10:35:48 +1000 Subject: Fix retrieval of SQL type "TIME" information for PostgreSQL PostgreSQL can store/retieve the millisecond part of type "TIME" , so allow it in the API level. Task-number: QTBUG-5251 Reviewed-by: Bill King --- tests/auto/qsqlquery/tst_qsqlquery.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests') diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp index 3463153214..87774a3250 100644 --- a/tests/auto/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp @@ -194,6 +194,8 @@ private slots: void sqlServerReturn0_data() { generic_data(); } void sqlServerReturn0(); + void QTBUG_5251_data() { generic_data("QPSQL"); } + void QTBUG_5251(); private: // returns all database connections @@ -2880,5 +2882,35 @@ void tst_QSqlQuery::sqlServerReturn0() QVERIFY_SQL(q, next()); } +void tst_QSqlQuery::QTBUG_5251() +{ + QFETCH( QString, dbName ); + QSqlDatabase db = QSqlDatabase::database( dbName ); + CHECK_DATABASE( db ); + + if (!db.driverName().startsWith( "QPSQL" )) return; + + QSqlQuery q(db); + q.exec("DROP TABLE " + qTableName("timetest")); + QVERIFY_SQL(q, exec("CREATE TABLE " + qTableName("timetest") + " (t TIME)")); + QVERIFY_SQL(q, exec("INSERT INTO " + qTableName("timetest") + " VALUES ('1:2:3.666')")); + + QSqlTableModel timetestModel(0,db); + timetestModel.setEditStrategy(QSqlTableModel::OnManualSubmit); + timetestModel.setTable(qTableName("timetest")); + QVERIFY_SQL(timetestModel, select()); + + QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("01:02:03.666")); + QVERIFY_SQL(timetestModel,setData(timetestModel.index(0, 0), QTime(0,12,34,500))); + QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("00:12:34.500")); + QVERIFY_SQL(timetestModel, submitAll()); + QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("00:12:34.500")); + + QVERIFY_SQL(q, exec("UPDATE " + qTableName("timetest") + " SET t = '0:11:22.33'")); + QVERIFY_SQL(timetestModel, select()); + QCOMPARE(timetestModel.record(0).field(0).value().toTime().toString("HH:mm:ss.zzz"), QString("00:11:22.330")); + +} + QTEST_MAIN( tst_QSqlQuery ) #include "tst_qsqlquery.moc" -- cgit v1.2.3 From c416d0d026377a5c8659abbd12cb4a8eab7c7264 Mon Sep 17 00:00:00 2001 From: Bill King Date: Thu, 5 Nov 2009 12:13:59 +1000 Subject: Add new cross schema relation autotest Autotest for http://bugreports.qt.nokia.com/browse/QTBUG-5373 --- .../tst_qsqlrelationaltablemodel.cpp | 36 +++++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp b/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp index cb24a9f36a..e045c1021f 100644 --- a/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp +++ b/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp @@ -86,6 +86,7 @@ private slots: void escapedRelations(); void escapedTableName(); void whiteSpaceInIdentifiers(); + void psqlSchemaTest(); private: void dropTestTables( QSqlDatabase db ); @@ -150,10 +151,11 @@ void tst_QSqlRelationalTableModel::initTestCase() if (db.driverName().startsWith("QIBASE")) db.exec("SET DIALECT 3"); else if (tst_Databases::isSqlServer(db)) { - QSqlQuery q(db); - QVERIFY_SQL(q, exec("SET ANSI_DEFAULTS ON")); - QVERIFY_SQL(q, exec("SET IMPLICIT_TRANSACTIONS OFF")); + db.exec("SET ANSI_DEFAULTS ON"); + db.exec("SET IMPLICIT_TRANSACTIONS OFF"); } + else if(tst_Databases::isPostgreSQL(db)) + db.exec("set client_min_messages='warning'"); recreateTestTables(db); } } @@ -181,6 +183,9 @@ void tst_QSqlRelationalTableModel::dropTestTables( QSqlDatabase db ) << qTableName("CASETEST1" ) << qTableName("casetest1" ); tst_Databases::safeDropTables( db, tableNames ); + + db.exec("DROP SCHEMA "+qTableName("QTBUG_5373")); + db.exec("DROP SCHEMA "+qTableName("QTBUG_5373_s2")); } void tst_QSqlRelationalTableModel::init() @@ -1118,8 +1123,8 @@ void tst_QSqlRelationalTableModel::escapedTableName() } } -void tst_QSqlRelationalTableModel::whiteSpaceInIdentifiers() { - +void tst_QSqlRelationalTableModel::whiteSpaceInIdentifiers() +{ QFETCH_GLOBAL(QString, dbName); QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); @@ -1193,5 +1198,26 @@ void tst_QSqlRelationalTableModel::whiteSpaceInIdentifiers() { QCOMPARE(model.data(model.index(0, 2)).toInt(), 6); } +void tst_QSqlRelationalTableModel::psqlSchemaTest() +{ + QFETCH_GLOBAL(QString, dbName); + QSqlDatabase db = QSqlDatabase::database(dbName); + CHECK_DATABASE(db); + + if(!tst_Databases::isPostgreSQL(db)) { + QSKIP("Postgresql specific test", SkipSingle); + return; + } + QSqlRelationalTableModel model(0, db); + QSqlQuery q(db); + QVERIFY_SQL(q, exec("create schema "+qTableName("QTBUG_5373"))); + QVERIFY_SQL(q, exec("create schema "+qTableName("QTBUG_5373_s2"))); + QVERIFY_SQL(q, exec("create table "+qTableName("QTBUG_5373")+"."+qTableName("user")+"(userid int primary key, relatingid int)")); + QVERIFY_SQL(q, exec("create table "+qTableName("QTBUG_5373_s2")+"."+qTableName("user2")+"(userid2 int primary key, username2 char(40))")); + model.setTable(qTableName("QTBUG_5373")+"."+qTableName("user")); + model.setRelation(1, QSqlRelation(qTableName("QTBUG_5373_s2")+"."+qTableName("user2"), "userid2", "username2")); + QVERIFY_SQL(model, select()); +} + QTEST_MAIN(tst_QSqlRelationalTableModel) #include "tst_qsqlrelationaltablemodel.moc" -- cgit v1.2.3 From aa58293b57a05cd52b36ba14a05958dceb65c603 Mon Sep 17 00:00:00 2001 From: Bill King Date: Thu, 5 Nov 2009 14:21:36 +1000 Subject: Cascade delete to cleanup autotest properly. Task-number: QTBUG-5373 --- tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp b/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp index e045c1021f..8c840cd1d5 100644 --- a/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp +++ b/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp @@ -184,8 +184,8 @@ void tst_QSqlRelationalTableModel::dropTestTables( QSqlDatabase db ) << qTableName("casetest1" ); tst_Databases::safeDropTables( db, tableNames ); - db.exec("DROP SCHEMA "+qTableName("QTBUG_5373")); - db.exec("DROP SCHEMA "+qTableName("QTBUG_5373_s2")); + db.exec("DROP SCHEMA "+qTableName("QTBUG_5373")+" CASCADE"); + db.exec("DROP SCHEMA "+qTableName("QTBUG_5373_s2")+" CASCADE"); } void tst_QSqlRelationalTableModel::init() -- cgit v1.2.3