summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
authorSergio Ahumada <sergio.ahumada@digia.com>2013-03-20 23:30:31 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-20 23:30:31 +0100
commite5a11fbb3251a98fafd6bebf0b6fc366acb19088 (patch)
tree8e1bd6704205307e0a23484221ea1bb67a9f411e /tests/auto/corelib/tools
parent0646d1131b4bc65cdd9af29f4ce00fdd2398a3df (diff)
parent76c0be34cd4ff4564693162fa7528463e23ce9d8 (diff)
Merge "Merge branch 'dev' into stable" into refs/staging/stable
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/qchar/tst_qchar.cpp68
-rw-r--r--tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp73
-rw-r--r--tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp48
-rw-r--r--tests/auto/corelib/tools/qhash/tst_qhash.cpp34
-rw-r--r--tests/auto/corelib/tools/qlocale/tst_qlocale.cpp30
-rw-r--r--tests/auto/corelib/tools/qmap/tst_qmap.cpp161
-rw-r--r--tests/auto/corelib/tools/qmargins/tst_qmargins.cpp46
-rw-r--r--tests/auto/corelib/tools/qmessageauthenticationcode/.gitignore1
-rw-r--r--tests/auto/corelib/tools/qmessageauthenticationcode/qmessageauthenticationcode.pro7
-rw-r--r--tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp151
-rw-r--r--tests/auto/corelib/tools/qpoint/tst_qpoint.cpp25
-rw-r--r--tests/auto/corelib/tools/qpointf/tst_qpointf.cpp26
-rw-r--r--tests/auto/corelib/tools/qqueue/tst_qqueue.cpp18
-rw-r--r--tests/auto/corelib/tools/qrect/tst_qrect.cpp21
-rw-r--r--tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp217
-rw-r--r--tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h5
-rw-r--r--tests/auto/corelib/tools/qset/tst_qset.cpp22
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/externaltests.pri2
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp122
-rw-r--r--tests/auto/corelib/tools/qstring/tst_qstring.cpp107
-rw-r--r--tests/auto/corelib/tools/qstringref/tst_qstringref.cpp954
-rw-r--r--tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp23
-rw-r--r--tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp24
-rw-r--r--tests/auto/corelib/tools/qvector/tst_qvector.cpp98
-rw-r--r--tests/auto/corelib/tools/tools.pro1
25 files changed, 2212 insertions, 72 deletions
diff --git a/tests/auto/corelib/tools/qchar/tst_qchar.cpp b/tests/auto/corelib/tools/qchar/tst_qchar.cpp
index 478747bf15..c89d553112 100644
--- a/tests/auto/corelib/tools/qchar/tst_qchar.cpp
+++ b/tests/auto/corelib/tools/qchar/tst_qchar.cpp
@@ -709,40 +709,40 @@ void tst_QChar::lineBreakClass()
void tst_QChar::script()
{
- QVERIFY(QUnicodeTables::script(0x0020u) == QUnicodeTables::Common);
- QVERIFY(QUnicodeTables::script(0x0041u) == QUnicodeTables::Common); // ### Latin
- QVERIFY(QUnicodeTables::script(0x0375u) == QUnicodeTables::Greek);
- QVERIFY(QUnicodeTables::script(0x0400u) == QUnicodeTables::Cyrillic);
- QVERIFY(QUnicodeTables::script(0x0531u) == QUnicodeTables::Armenian);
- QVERIFY(QUnicodeTables::script(0x0591u) == QUnicodeTables::Hebrew);
- QVERIFY(QUnicodeTables::script(0x0600u) == QUnicodeTables::Arabic);
- QVERIFY(QUnicodeTables::script(0x0700u) == QUnicodeTables::Syriac);
- QVERIFY(QUnicodeTables::script(0x0780u) == QUnicodeTables::Thaana);
- QVERIFY(QUnicodeTables::script(0x07c0u) == QUnicodeTables::Nko);
- QVERIFY(QUnicodeTables::script(0x0900u) == QUnicodeTables::Devanagari);
- QVERIFY(QUnicodeTables::script(0x0981u) == QUnicodeTables::Bengali);
- QVERIFY(QUnicodeTables::script(0x0a01u) == QUnicodeTables::Gurmukhi);
- QVERIFY(QUnicodeTables::script(0x0a81u) == QUnicodeTables::Gujarati);
- QVERIFY(QUnicodeTables::script(0x0b01u) == QUnicodeTables::Oriya);
- QVERIFY(QUnicodeTables::script(0x0b82u) == QUnicodeTables::Tamil);
- QVERIFY(QUnicodeTables::script(0x0c01u) == QUnicodeTables::Telugu);
- QVERIFY(QUnicodeTables::script(0x0c82u) == QUnicodeTables::Kannada);
- QVERIFY(QUnicodeTables::script(0x0d02u) == QUnicodeTables::Malayalam);
- QVERIFY(QUnicodeTables::script(0x0d82u) == QUnicodeTables::Sinhala);
- QVERIFY(QUnicodeTables::script(0x0e01u) == QUnicodeTables::Thai);
- QVERIFY(QUnicodeTables::script(0x0e81u) == QUnicodeTables::Lao);
- QVERIFY(QUnicodeTables::script(0x0f00u) == QUnicodeTables::Tibetan);
- QVERIFY(QUnicodeTables::script(0x1000u) == QUnicodeTables::Myanmar);
- QVERIFY(QUnicodeTables::script(0x10a0u) == QUnicodeTables::Georgian);
- QVERIFY(QUnicodeTables::script(0x1100u) == QUnicodeTables::Hangul);
- QVERIFY(QUnicodeTables::script(0x1680u) == QUnicodeTables::Ogham);
- QVERIFY(QUnicodeTables::script(0x16a0u) == QUnicodeTables::Runic);
- QVERIFY(QUnicodeTables::script(0x1780u) == QUnicodeTables::Khmer);
- QVERIFY(QUnicodeTables::script(0x200cu) == QUnicodeTables::Inherited);
- QVERIFY(QUnicodeTables::script(0x200du) == QUnicodeTables::Inherited);
- QVERIFY(QUnicodeTables::script(0x1018au) == QUnicodeTables::Greek);
- QVERIFY(QUnicodeTables::script(0x1f130u) == QUnicodeTables::Common);
- QVERIFY(QUnicodeTables::script(0xe0100u) == QUnicodeTables::Inherited);
+ QVERIFY(QChar::script(0x0020u) == QChar::Script_Common);
+ QVERIFY(QChar::script(0x0041u) == QChar::Script_Latin);
+ QVERIFY(QChar::script(0x0375u) == QChar::Script_Greek);
+ QVERIFY(QChar::script(0x0400u) == QChar::Script_Cyrillic);
+ QVERIFY(QChar::script(0x0531u) == QChar::Script_Armenian);
+ QVERIFY(QChar::script(0x0591u) == QChar::Script_Hebrew);
+ QVERIFY(QChar::script(0x0600u) == QChar::Script_Arabic);
+ QVERIFY(QChar::script(0x0700u) == QChar::Script_Syriac);
+ QVERIFY(QChar::script(0x0780u) == QChar::Script_Thaana);
+ QVERIFY(QChar::script(0x07c0u) == QChar::Script_Nko);
+ QVERIFY(QChar::script(0x0900u) == QChar::Script_Devanagari);
+ QVERIFY(QChar::script(0x0981u) == QChar::Script_Bengali);
+ QVERIFY(QChar::script(0x0a01u) == QChar::Script_Gurmukhi);
+ QVERIFY(QChar::script(0x0a81u) == QChar::Script_Gujarati);
+ QVERIFY(QChar::script(0x0b01u) == QChar::Script_Oriya);
+ QVERIFY(QChar::script(0x0b82u) == QChar::Script_Tamil);
+ QVERIFY(QChar::script(0x0c01u) == QChar::Script_Telugu);
+ QVERIFY(QChar::script(0x0c82u) == QChar::Script_Kannada);
+ QVERIFY(QChar::script(0x0d02u) == QChar::Script_Malayalam);
+ QVERIFY(QChar::script(0x0d82u) == QChar::Script_Sinhala);
+ QVERIFY(QChar::script(0x0e01u) == QChar::Script_Thai);
+ QVERIFY(QChar::script(0x0e81u) == QChar::Script_Lao);
+ QVERIFY(QChar::script(0x0f00u) == QChar::Script_Tibetan);
+ QVERIFY(QChar::script(0x1000u) == QChar::Script_Myanmar);
+ QVERIFY(QChar::script(0x10a0u) == QChar::Script_Georgian);
+ QVERIFY(QChar::script(0x1100u) == QChar::Script_Hangul);
+ QVERIFY(QChar::script(0x1680u) == QChar::Script_Ogham);
+ QVERIFY(QChar::script(0x16a0u) == QChar::Script_Runic);
+ QVERIFY(QChar::script(0x1780u) == QChar::Script_Khmer);
+ QVERIFY(QChar::script(0x200cu) == QChar::Script_Inherited);
+ QVERIFY(QChar::script(0x200du) == QChar::Script_Inherited);
+ QVERIFY(QChar::script(0x1018au) == QChar::Script_Greek);
+ QVERIFY(QChar::script(0x1f130u) == QChar::Script_Common);
+ QVERIFY(QChar::script(0xe0100u) == QChar::Script_Inherited);
}
void tst_QChar::normalization_data()
diff --git a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp
index 5ba2f2920a..de252a5d5e 100644
--- a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp
+++ b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp
@@ -52,6 +52,7 @@ private slots:
void intermediary_result_data();
void intermediary_result();
void sha1();
+ void sha3();
void files_data();
void files();
};
@@ -118,6 +119,23 @@ void tst_QCryptographicHash::intermediary_result_data()
<< QByteArray("abc") << QByteArray("abc")
<< QByteArray::fromHex("DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA20A9EEEE64B55D39A2192992A274FC1A836BA3C23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F")
<< QByteArray::fromHex("F3C41E7B63EE869596FC28BAD64120612C520F65928AB4D126C72C6998B551B8FF1CEDDFED4373E6717554DC89D1EEE6F0AB22FD3675E561ABA9AE26A3EEC53B");
+
+ QTest::newRow("sha3_224") << int(QCryptographicHash::Sha3_224)
+ << QByteArray("abc") << QByteArray("abc")
+ << QByteArray::fromHex("C30411768506EBE1C2871B1EE2E87D38DF342317300A9B97A95EC6A8")
+ << QByteArray::fromHex("048330E7C7C8B4A41AB713B3A6F958D77B8CF3EE969930F1584DD550");
+ QTest::newRow("sha3_256") << int(QCryptographicHash::Sha3_256)
+ << QByteArray("abc") << QByteArray("abc")
+ << QByteArray::fromHex("4E03657AEA45A94FC7D47BA826C8D667C0D1E6E33A64A036EC44F58FA12D6C45")
+ << QByteArray::fromHex("9F0ADAD0A59B05D2E04A1373342B10B9EB16C57C164C8A3BFCBF46DCCEE39A21");
+ QTest::newRow("sha3_384") << int(QCryptographicHash::Sha3_384)
+ << QByteArray("abc") << QByteArray("abc")
+ << QByteArray::fromHex("F7DF1165F033337BE098E7D288AD6A2F74409D7A60B49C36642218DE161B1F99F8C681E4AFAF31A34DB29FB763E3C28E")
+ << QByteArray::fromHex("D733B87D392D270889D3DA23AE113F349E25574B445F319CDE4CD3F877C753E9E3C65980421339B3A131457FF393939F");
+ QTest::newRow("sha3_512") << int(QCryptographicHash::Sha3_512)
+ << QByteArray("abc") << QByteArray("abc")
+ << QByteArray::fromHex("18587DC2EA106B9A1563E32B3312421CA164C7F1F07BC922A9C83D77CEA3A1E5D0C69910739025372DC14AC9642629379540C17E2A65B19D77AA511A9D00BB96")
+ << QByteArray::fromHex("A7C392D2A42155761CA76BDDDE1C47D55486B007EDF465397BFB9DFA74D11C8F0D7C86CD29415283F1B5E7F655CEC25B869C9E9C33A8986F0B38542FB12BFB93");
}
void tst_QCryptographicHash::intermediary_result()
@@ -151,22 +169,71 @@ void tst_QCryptographicHash::sha1()
// A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
QCOMPARE(QCryptographicHash::hash("abc", QCryptographicHash::Sha1).toHex().toUpper(),
QByteArray("A9993E364706816ABA3E25717850C26C9CD0D89D"));
-
+
// SHA1("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") =
// 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
QCOMPARE(QCryptographicHash::hash("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
QCryptographicHash::Sha1).toHex().toUpper(),
QByteArray("84983E441C3BD26EBAAE4AA1F95129E5E54670F1"));
-
+
// SHA1(A million repetitions of "a") =
// 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
QByteArray as;
for (int i = 0; i < 1000000; ++i)
as += 'a';
- QCOMPARE(QCryptographicHash::hash(as, QCryptographicHash::Sha1).toHex().toUpper(),
+ QCOMPARE(QCryptographicHash::hash(as, QCryptographicHash::Sha1).toHex().toUpper(),
QByteArray("34AA973CD4C4DAA4F61EEB2BDBAD27316534016F"));
}
+void tst_QCryptographicHash::sha3()
+{
+ // SHA3-224("The quick brown fox jumps over the lazy dog")
+ // 10aee6b30c47350576ac2873fa89fd190cdc488442f3ef654cf23fe
+ QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog",
+ QCryptographicHash::Sha3_224).toHex(),
+ QByteArray("310aee6b30c47350576ac2873fa89fd190cdc488442f3ef654cf23fe"));
+ // SHA3-224("The quick brown fox jumps over the lazy dog.")
+ // c59d4eaeac728671c635ff645014e2afa935bebffdb5fbd207ffdeab
+ QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog.",
+ QCryptographicHash::Sha3_224).toHex(),
+ QByteArray("c59d4eaeac728671c635ff645014e2afa935bebffdb5fbd207ffdeab"));
+
+ // SHA3-256("The quick brown fox jumps over the lazy dog")
+ // 4d741b6f1eb29cb2a9b9911c82f56fa8d73b04959d3d9d222895df6c0b28aa15
+ QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog",
+ QCryptographicHash::Sha3_256).toHex(),
+ QByteArray("4d741b6f1eb29cb2a9b9911c82f56fa8d73b04959d3d9d222895df6c0b28aa15"));
+
+ // SHA3-256("The quick brown fox jumps over the lazy dog.")
+ // 578951e24efd62a3d63a86f7cd19aaa53c898fe287d2552133220370240b572d
+ QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog.",
+ QCryptographicHash::Sha3_256).toHex(),
+ QByteArray("578951e24efd62a3d63a86f7cd19aaa53c898fe287d2552133220370240b572d"));
+
+ // SHA3-384("The quick brown fox jumps over the lazy dog")
+ // 283990fa9d5fb731d786c5bbee94ea4db4910f18c62c03d173fc0a5e494422e8a0b3da7574dae7fa0baf005e504063b3
+ QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog",
+ QCryptographicHash::Sha3_384).toHex(),
+ QByteArray("283990fa9d5fb731d786c5bbee94ea4db4910f18c62c03d173fc0a5e494422e8a0b3da7574dae7fa0baf005e504063b3"));
+
+ // SHA3-384("The quick brown fox jumps over the lazy dog.")
+ // 9ad8e17325408eddb6edee6147f13856ad819bb7532668b605a24a2d958f88bd5c169e56dc4b2f89ffd325f6006d820b
+ QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog.",
+ QCryptographicHash::Sha3_384).toHex(),
+ QByteArray("9ad8e17325408eddb6edee6147f13856ad819bb7532668b605a24a2d958f88bd5c169e56dc4b2f89ffd325f6006d820b"));
+
+ // SHA3-512("The quick brown fox jumps over the lazy dog")
+ // d135bb84d0439dbac432247ee573a23ea7d3c9deb2a968eb31d47c4fb45f1ef4422d6c531b5b9bd6f449ebcc449ea94d0a8f05f62130fda612da53c79659f609
+ QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog",
+ QCryptographicHash::Sha3_512).toHex(),
+ QByteArray("d135bb84d0439dbac432247ee573a23ea7d3c9deb2a968eb31d47c4fb45f1ef4422d6c531b5b9bd6f449ebcc449ea94d0a8f05f62130fda612da53c79659f609"));
+
+ // SHA3-512("The quick brown fox jumps over the lazy dog.")
+ // ab7192d2b11f51c7dd744e7b3441febf397ca07bf812cceae122ca4ded6387889064f8db9230f173f6d1ab6e24b6e50f065b039f799f5592360a6558eb52d760
+ QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog.",
+ QCryptographicHash::Sha3_512).toHex(),
+ QByteArray("ab7192d2b11f51c7dd744e7b3441febf397ca07bf812cceae122ca4ded6387889064f8db9230f173f6d1ab6e24b6e50f065b039f799f5592360a6558eb52d760"));
+}
Q_DECLARE_METATYPE(QCryptographicHash::Algorithm);
diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
index 05a6c6b252..4e5b0a3555 100644
--- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
@@ -145,6 +145,8 @@ private:
QDateTime invalidDateTime() const { return QDateTime(invalidDate(), invalidTime()); }
QDate invalidDate() const { return QDate(); }
QTime invalidTime() const { return QTime(-1, -1, -1); }
+ qint64 minJd() const { return QDateTimePrivate::minJd(); }
+ qint64 maxJd() const { return QDateTimePrivate::maxJd(); }
};
Q_DECLARE_METATYPE(Qt::TimeSpec)
@@ -462,14 +464,25 @@ void tst_QDateTime::setMSecsSinceEpoch_data()
<< (Q_INT64_C(123456) << 32)
<< QDateTime(QDate(18772, 8, 15), QTime(1, 8, 14, 976), Qt::UTC)
<< QDateTime(QDate(18772, 8, 15), QTime(3, 8, 14, 976));
- QTest::newRow("min_date") // julian day 0 is an invalid date for QDate
+ QTest::newRow("old min (Tue Nov 25 00:00:00 -4714)")
<< Q_INT64_C(-210866716800000)
<< QDateTime(QDate::fromJulianDay(1), QTime(), Qt::UTC)
<< QDateTime(QDate::fromJulianDay(1), QTime(1, 0));
- QTest::newRow("max_date") // technically jd is unsigned, but fromJulianDay takes int
+ QTest::newRow("old max (Tue Jun 3 21:59:59 5874898)")
<< Q_INT64_C(185331720376799999)
<< QDateTime(QDate::fromJulianDay(0x7fffffff), QTime(21, 59, 59, 999), Qt::UTC)
<< QDateTime(QDate::fromJulianDay(0x7fffffff), QTime(23, 59, 59, 999));
+ QTest::newRow("min")
+ // + 1 because, in the reference check below, calling addMSecs(qint64min)
+ // will internally apply unary minus to -qint64min, resulting in a
+ // positive value 1 too big for qint64max, causing an overflow.
+ << std::numeric_limits<qint64>::min() + 1
+ << QDateTime(QDate(-292275056, 5, 16), QTime(16, 47, 4, 193), Qt::UTC)
+ << QDateTime(QDate(-292275056, 5, 16), QTime(17, 47, 4, 193), Qt::LocalTime);
+ QTest::newRow("max")
+ << std::numeric_limits<qint64>::max()
+ << QDateTime(QDate(292278994, 8, 17), QTime(7, 12, 55, 807), Qt::UTC)
+ << QDateTime(QDate(292278994, 8, 17), QTime(9, 12, 55, 807), Qt::LocalTime);
}
void tst_QDateTime::setMSecsSinceEpoch()
@@ -821,6 +834,29 @@ void tst_QDateTime::toTimeSpec_data()
QTest::newRow("winter4") << QDateTime(QDate(6000, 2, 29), utcTime, Qt::UTC)
<< QDateTime(QDate(6000, 2, 29), localStandardTime, Qt::LocalTime);
+ // Test mktime boundaries (1970 - 2038) and adjustDate().
+ QTest::newRow("1969/12/31 23:00 UTC")
+ << QDateTime(QDate(1969, 12, 31), QTime(23, 0, 0), Qt::UTC)
+ << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 0), Qt::LocalTime);
+ QTest::newRow("2037/12/31 23:00 UTC")
+ << QDateTime(QDate(2037, 12, 31), QTime(23, 0, 0), Qt::UTC)
+ << QDateTime(QDate(2038, 1, 1), QTime(0, 0, 0), Qt::LocalTime);
+
+ QTest::newRow("-271821/4/20 00:00 UTC (JavaScript min date, start of day)")
+ << QDateTime(QDate(-271821, 4, 20), QTime(0, 0, 0), Qt::UTC)
+ << QDateTime(QDate(-271821, 4, 20), QTime(1, 0, 0), Qt::LocalTime);
+ QTest::newRow("-271821/4/20 23:00 UTC (JavaScript min date, end of day)")
+ << QDateTime(QDate(-271821, 4, 20), QTime(23, 0, 0), Qt::UTC)
+ << QDateTime(QDate(-271821, 4, 21), QTime(0, 0, 0), Qt::LocalTime);
+
+ QTest::newRow("QDate min")
+ << QDateTime(QDate::fromJulianDay(minJd()), QTime(0, 0, 0), Qt::UTC)
+ << QDateTime(QDate::fromJulianDay(minJd()), QTime(1, 0, 0), Qt::LocalTime);
+
+ QTest::newRow("QDate max")
+ << QDateTime(QDate::fromJulianDay(maxJd()), QTime(22, 59, 59), Qt::UTC)
+ << QDateTime(QDate::fromJulianDay(maxJd()), QTime(23, 59, 59), Qt::LocalTime);
+
if (europeanTimeZone) {
QTest::newRow("summer1") << QDateTime(QDate(2004, 6, 30), utcTime, Qt::UTC)
<< QDateTime(QDate(2004, 6, 30), localDaylightTime, Qt::LocalTime);
@@ -835,6 +871,14 @@ void tst_QDateTime::toTimeSpec_data()
#endif
QTest::newRow("summer3") << QDateTime(QDate(4000, 6, 30), utcTime, Qt::UTC)
<< QDateTime(QDate(4000, 6, 30), localDaylightTime, Qt::LocalTime);
+
+ QTest::newRow("275760/9/23 00:00 UTC (JavaScript max date, start of day)")
+ << QDateTime(QDate(275760, 9, 23), QTime(0, 0, 0), Qt::UTC)
+ << QDateTime(QDate(275760, 9, 23), QTime(2, 0, 0), Qt::LocalTime);
+
+ QTest::newRow("275760/9/23 22:00 UTC (JavaScript max date, end of day)")
+ << QDateTime(QDate(275760, 9, 23), QTime(22, 0, 0), Qt::UTC)
+ << QDateTime(QDate(275760, 9, 24), QTime(0, 0, 0), Qt::LocalTime);
}
QTest::newRow("msec") << QDateTime(QDate(4000, 6, 30), utcTime.addMSecs(1), Qt::UTC)
diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
index 6df84e6363..1cbf181286 100644
--- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp
+++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
@@ -74,6 +74,7 @@ private slots:
void const_shared_null();
void twoArguments_qHash();
+ void initializerList();
};
struct Foo {
@@ -844,7 +845,7 @@ void tst_QHash::iterators()
//STL-Style iterators
QHash<int, QString>::iterator stlIt = hash.begin();
- for(stlIt = hash.begin(), i = 1; stlIt != hash.end(), i < 100; ++stlIt, ++i) {
+ for (stlIt = hash.begin(), i = 1; stlIt != hash.end() && i < 100; ++stlIt, ++i) {
testMap.insert(i,stlIt.value());
//QVERIFY(stlIt.value() == hash.value(
}
@@ -869,7 +870,7 @@ void tst_QHash::iterators()
//STL-Style const-iterators
QHash<int, QString>::const_iterator cstlIt = hash.constBegin();
- for(cstlIt = hash.constBegin(), i = 1; cstlIt != hash.constEnd(), i < 100; ++cstlIt, ++i) {
+ for (cstlIt = hash.constBegin(), i = 1; cstlIt != hash.constEnd() && i < 100; ++cstlIt, ++i) {
testMap.insert(i,cstlIt.value());
//QVERIFY(stlIt.value() == hash.value(
}
@@ -1300,5 +1301,34 @@ void tst_QHash::twoArguments_qHash()
QCOMPARE(wrongqHashOverload, 0);
}
+void tst_QHash::initializerList()
+{
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+ QHash<int, QString> hash{{1, "hello"}, {2, "initializer_list"}};
+ QCOMPARE(hash.count(), 2);
+ QVERIFY(hash[1] == "hello");
+ QVERIFY(hash[2] == "initializer_list");
+
+ QMultiHash<QString, int> multiHash{{"il", 1}, {"il", 2}, {"il", 3}};
+ QCOMPARE(multiHash.count(), 3);
+ QList<int> values = multiHash.values("il");
+ QCOMPARE(values.count(), 3);
+
+ QHash<int, int> emptyHash{};
+ QVERIFY(emptyHash.isEmpty());
+
+ QHash<int, char> emptyPairs{{}, {}};
+ QVERIFY(!emptyPairs.isEmpty());
+
+ QMultiHash<QString, double> emptyMultiHash{};
+ QVERIFY(emptyMultiHash.isEmpty());
+
+ QMultiHash<int, float> emptyPairs2{{}, {}};
+ QVERIFY(!emptyPairs2.isEmpty());
+#else
+ QSKIP("Compiler doesn't support initializer lists");
+#endif
+}
+
QTEST_APPLESS_MAIN(tst_QHash)
#include "tst_qhash.moc"
diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
index d58d207546..ed74c939f7 100644
--- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
@@ -42,7 +42,7 @@
#include <QtTest/QtTest>
#include <math.h>
-#include <qglobal.h>
+#include <qdebug.h>
#include <qdir.h>
#include <qfileinfo.h>
#include <QScopedArrayPointer>
@@ -712,6 +712,7 @@ void tst_QLocale::double_conversion()
QFETCH(QString, num_str);
QFETCH(bool, good);
QFETCH(double, num);
+ QStringRef num_strRef = num_str.leftRef(-1);
QLocale locale(locale_name);
QCOMPARE(locale.name(), locale_name);
@@ -726,6 +727,16 @@ void tst_QLocale::double_conversion()
diff = -diff;
QVERIFY(diff <= MY_DOUBLE_EPSILON);
}
+
+ d = locale.toDouble(num_strRef, &ok);
+ QCOMPARE(ok, good);
+
+ if (ok) {
+ double diff = d - num;
+ if (diff < 0)
+ diff = -diff;
+ QVERIFY(diff <= MY_DOUBLE_EPSILON);
+ }
}
void tst_QLocale::long_long_conversion_data()
@@ -787,6 +798,7 @@ void tst_QLocale::long_long_conversion()
QFETCH(QString, num_str);
QFETCH(bool, good);
QFETCH(qlonglong, num);
+ QStringRef num_strRef = num_str.leftRef(-1);
QLocale locale(locale_name);
QCOMPARE(locale.name(), locale_name);
@@ -795,9 +807,14 @@ void tst_QLocale::long_long_conversion()
qlonglong l = locale.toLongLong(num_str, &ok);
QCOMPARE(ok, good);
- if (ok) {
+ if (ok)
+ QCOMPARE(l, num);
+
+ l = locale.toLongLong(num_strRef, &ok);
+ QCOMPARE(ok, good);
+
+ if (ok)
QCOMPARE(l, num);
- }
}
void tst_QLocale::long_long_conversion_extra()
@@ -1281,7 +1298,7 @@ static QString getWinLocaleInfo(LCTYPE type)
int cnt = GetLocaleInfo(id, type, 0, 0) * 2;
if (cnt == 0) {
- qWarning("QLocale: empty windows locale info (%d)", type);
+ qWarning().nospace() << "QLocale: empty windows locale info (" << type << ')';
return QString();
}
cnt /= sizeof(wchar_t);
@@ -1289,7 +1306,7 @@ static QString getWinLocaleInfo(LCTYPE type)
cnt = GetLocaleInfo(id, type, buf.data(), cnt);
if (cnt == 0) {
- qWarning("QLocale: empty windows locale info (%d)", type);
+ qWarning().nospace() << "QLocale: empty windows locale info (" << type << ')';
return QString();
}
return QString::fromWCharArray(buf.data());
@@ -1680,6 +1697,9 @@ void tst_QLocale::dateFormat()
const QLocale ja("ja_JP");
QCOMPARE(ja.dateFormat(QLocale::ShortFormat), QLatin1String("yyyy/MM/dd"));
+
+ const QLocale ir("ga_IE");
+ QCOMPARE(ir.dateFormat(QLocale::ShortFormat), QLatin1String("dd/MM/yyyy"));
}
void tst_QLocale::timeFormat()
diff --git a/tests/auto/corelib/tools/qmap/tst_qmap.cpp b/tests/auto/corelib/tools/qmap/tst_qmap.cpp
index 5069b805bf..0742f19a5e 100644
--- a/tests/auto/corelib/tools/qmap/tst_qmap.cpp
+++ b/tests/auto/corelib/tools/qmap/tst_qmap.cpp
@@ -84,6 +84,9 @@ private slots:
void insert();
void checkMostLeftNode();
+ void initializerList();
+ void testInsertWithHint();
+ void testInsertMultiWithHint();
};
typedef QMap<QString, QString> StringMap;
@@ -937,6 +940,18 @@ void tst_QMap::qmultimap_specific()
QVERIFY(map2.remove(42,5));
QVERIFY(map1 == map2);
}
+
+ map1.insert(map1.constBegin(), -1, -1);
+ QCOMPARE(map1.size(), 45);
+ map1.insert(map1.constBegin(), -1, -1);
+ QCOMPARE(map1.size(), 46);
+ map1.insert(map1.constBegin(), -2, -2);
+ QCOMPARE(map1.size(), 47);
+ map1.insert(map1.constBegin(), 5, 5); // Invald hint
+ QCOMPARE(map1.size(), 48);
+ map1.insert(map1.constBegin(), 5, 5); // Invald hint
+ QCOMPARE(map1.size(), 49);
+ sanityCheckTree(map1, __LINE__);
}
void tst_QMap::const_shared_null()
@@ -1129,5 +1144,151 @@ void tst_QMap::checkMostLeftNode()
sanityCheckTree(map, __LINE__);
}
+void tst_QMap::initializerList()
+{
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+ QMap<int, QString> map{{1, "hello"}, {2, "initializer_list"}};
+ QCOMPARE(map.count(), 2);
+ QVERIFY(map[1] == "hello");
+ QVERIFY(map[2] == "initializer_list");
+
+ QMultiMap<QString, int> multiMap{{"il", 1}, {"il", 2}, {"il", 3}};
+ QCOMPARE(multiMap.count(), 3);
+ QList<int> values = multiMap.values("il");
+ QCOMPARE(values.count(), 3);
+
+ QMap<int, int> emptyMap{};
+ QVERIFY(emptyMap.isEmpty());
+
+ QMap<char, char> emptyPairs{{}, {}};
+ QVERIFY(!emptyPairs.isEmpty());
+
+ QMultiMap<double, double> emptyMultiMap{};
+ QVERIFY(emptyMultiMap.isEmpty());
+
+ QMultiMap<float, float> emptyPairs2{{}, {}};
+ QVERIFY(!emptyPairs2.isEmpty());
+#else
+ QSKIP("Compiler doesn't support initializer lists");
+#endif
+}
+
+void tst_QMap::testInsertWithHint()
+{
+ QMap<int, int> map;
+ map.setSharable(false);
+
+ // Check with end hint();
+ map.insert(map.constEnd(), 3, 1); // size == 1
+ sanityCheckTree(map, __LINE__);
+ map.insert(map.constEnd(), 5, 1); // size = 2
+ sanityCheckTree(map, __LINE__);
+ map.insert(map.constEnd(), 50, 1); // size = 3
+ sanityCheckTree(map, __LINE__);
+ QMap<int, int>::const_iterator key75(map.insert(map.constEnd(), 75, 1)); // size = 4
+ sanityCheckTree(map, __LINE__);
+ map.insert(map.constEnd(), 100, 1); // size = 5
+ sanityCheckTree(map, __LINE__);
+ map.insert(map.constEnd(), 105, 1); // size = 6
+ sanityCheckTree(map, __LINE__);
+ map.insert(map.constEnd(), 10, 5); // invalid hint and size = 7
+ sanityCheckTree(map, __LINE__);
+ QMap<int, int>::iterator lastkey = map.insert(map.constEnd(), 105, 12); // overwrite
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(lastkey.value(), 12);
+ QCOMPARE(lastkey.key(), 105);
+ QCOMPARE(map.size(), 7);
+
+ // With regular hint
+ map.insert(key75, 75, 100); // overwrite current key
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 7);
+ QCOMPARE(key75.key(), 75);
+ QCOMPARE(key75.value(), 100);
+
+ map.insert(key75, 50, 101); // overwrite previous value
+ QMap<int, int>::const_iterator key50(key75);
+ --key50;
+ QCOMPARE(map.size(), 7);
+ QCOMPARE(key50.key(), 50);
+ QCOMPARE(key50.value(), 101);
+
+ map.insert(key75, 17, 125); // invalid hint - size 8
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 8);
+
+ // begin
+ map.insert(map.constBegin(), 1, 1); // size 9
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 9);
+
+ map.insert(map.constBegin(), 1, 10); // overwrite existing (leftmost) value
+ QCOMPARE(map.constBegin().value(), 10);
+
+ map.insert(map.constBegin(), 47, 47); // wrong hint - size 10
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 10);
+
+ // insert with right == 0
+ QMap<int, int>::const_iterator i1 (map.insert(key75, 70, 12)); // overwrite
+ map.insert(i1, 69, 12); // size 12
+
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 12);
+}
+
+void tst_QMap::testInsertMultiWithHint()
+{
+ QMap<int, int> map;
+ map.setSharable(false);
+
+ typedef QMap<int, int>::const_iterator cite; // Hack since we define QT_STRICT_ITERATORS
+ map.insertMulti(cite(map.end()), 64, 65);
+ map[128] = 129;
+ map[256] = 257;
+ sanityCheckTree(map, __LINE__);
+
+ map.insertMulti(cite(map.end()), 512, 513);
+ map.insertMulti(cite(map.end()), 512, 513 * 2);
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 5);
+ map.insertMulti(cite(map.end()), 256, 258); // wrong hint
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 6);
+
+ QMap<int, int>::iterator i = map.insertMulti(map.constBegin(), 256, 259); // wrong hint
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 7);
+
+ QMap<int, int>::iterator j = map.insertMulti(map.constBegin(), 69, 66);
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 8);
+
+ j = map.insertMulti(cite(j), 68, 259);
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 9);
+
+ j = map.insertMulti(cite(j), 67, 67);
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 10);
+
+ i = map.insertMulti(cite(i), 256, 259);
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 11);
+
+ i = map.insertMulti(cite(i), 256, 260);
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 12);
+
+ map.insertMulti(cite(i), 64, 67);
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 13);
+
+ map.insertMulti(map.constBegin(), 20, 20);
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 14);
+}
+
+
QTEST_APPLESS_MAIN(tst_QMap)
#include "tst_qmap.moc"
diff --git a/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp b/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp
index 9700f91128..d22e771b79 100644
--- a/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp
+++ b/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp
@@ -50,6 +50,7 @@ class tst_QMargins : public QObject
private slots:
void getSetCheck();
void dataStreamCheck();
+ void operators();
};
// Testing get/set functions
@@ -73,7 +74,50 @@ void tst_QMargins::getSetCheck()
margins.setRight(5);
QVERIFY(!margins.isNull());
QCOMPARE(margins, QMargins(5, 0, 5, 0));
-}
+}
+
+void tst_QMargins::operators()
+{
+ const QMargins m1(12, 14, 16, 18);
+ const QMargins m2(2, 3, 4, 5);
+
+ const QMargins added = m1 + m2;
+ QCOMPARE(added, QMargins(14, 17, 20, 23));
+ QMargins a = m1;
+ a += m2;
+ QCOMPARE(a, added);
+
+ const QMargins subtracted = m1 - m2;
+ QCOMPARE(subtracted, QMargins(10, 11, 12, 13));
+ a = m1;
+ a -= m2;
+ QCOMPARE(a, subtracted);
+
+ const QMargins doubled = m1 * 2;
+ QCOMPARE(doubled, QMargins(24, 28, 32, 36));
+ QCOMPARE(2 * m1, doubled);
+ QCOMPARE(qreal(2) * m1, doubled);
+ QCOMPARE(m1 * qreal(2), doubled);
+
+ a = m1;
+ a *= 2;
+ QCOMPARE(a, doubled);
+ a = m1;
+ a *= qreal(2);
+ QCOMPARE(a, doubled);
+
+ const QMargins halved = m1 / 2;
+ QCOMPARE(halved, QMargins(6, 7, 8, 9));
+
+ a = m1;
+ a /= 2;
+ QCOMPARE(a, halved);
+ a = m1;
+ a /= qreal(2);
+ QCOMPARE(a, halved);
+
+ QCOMPARE(m1 + (-m1), QMargins());
+}
// Testing QDataStream operators
void tst_QMargins::dataStreamCheck()
diff --git a/tests/auto/corelib/tools/qmessageauthenticationcode/.gitignore b/tests/auto/corelib/tools/qmessageauthenticationcode/.gitignore
new file mode 100644
index 0000000000..bfd53f437b
--- /dev/null
+++ b/tests/auto/corelib/tools/qmessageauthenticationcode/.gitignore
@@ -0,0 +1 @@
+tst_qmessageauthenticationcode
diff --git a/tests/auto/corelib/tools/qmessageauthenticationcode/qmessageauthenticationcode.pro b/tests/auto/corelib/tools/qmessageauthenticationcode/qmessageauthenticationcode.pro
new file mode 100644
index 0000000000..1ea23915b7
--- /dev/null
+++ b/tests/auto/corelib/tools/qmessageauthenticationcode/qmessageauthenticationcode.pro
@@ -0,0 +1,7 @@
+CONFIG += testcase parallel_test
+TARGET = tst_qmessageauthenticationcode
+QT = core testlib
+SOURCES = tst_qmessageauthenticationcode.cpp
+
+TESTDATA += data/*
+DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
diff --git a/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp b/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp
new file mode 100644
index 0000000000..0e243988e2
--- /dev/null
+++ b/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp
@@ -0,0 +1,151 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Ruslan Nigmatullin <euroelessar@yandex.ru>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtCore/QCoreApplication>
+#include <QtTest/QtTest>
+
+class tst_QMessageAuthenticationCode : public QObject
+{
+ Q_OBJECT
+private slots:
+ void result_data();
+ void result();
+ void result_incremental_data();
+ void result_incremental();
+};
+
+Q_DECLARE_METATYPE(QCryptographicHash::Algorithm)
+
+void tst_QMessageAuthenticationCode::result_data()
+{
+ QTest::addColumn<QCryptographicHash::Algorithm>("algo");
+ QTest::addColumn<QByteArray>("key");
+ QTest::addColumn<QByteArray>("message");
+ QTest::addColumn<QByteArray>("code");
+
+ // Empty values
+ QTest::newRow("md5-empty") << QCryptographicHash::Md5
+ << QByteArray()
+ << QByteArray()
+ << QByteArray::fromHex("74e6f7298a9c2d168935f58c001bad88");
+ QTest::newRow("sha1-empty") << QCryptographicHash::Sha1
+ << QByteArray()
+ << QByteArray()
+ << QByteArray::fromHex("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d");
+ QTest::newRow("sha256-empty") << QCryptographicHash::Sha256
+ << QByteArray()
+ << QByteArray()
+ << QByteArray::fromHex("b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad");
+
+ // Some not-empty
+ QTest::newRow("md5") << QCryptographicHash::Md5
+ << QByteArray("key")
+ << QByteArray("The quick brown fox jumps over the lazy dog")
+ << QByteArray::fromHex("80070713463e7749b90c2dc24911e275");
+ QTest::newRow("sha1") << QCryptographicHash::Sha1
+ << QByteArray("key")
+ << QByteArray("The quick brown fox jumps over the lazy dog")
+ << QByteArray::fromHex("de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9");
+ QTest::newRow("sha256") << QCryptographicHash::Sha256
+ << QByteArray("key")
+ << QByteArray("The quick brown fox jumps over the lazy dog")
+ << QByteArray::fromHex("f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8");
+
+ // Some from rfc-2104
+ QTest::newRow("rfc-md5-1") << QCryptographicHash::Md5
+ << QByteArray::fromHex("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b")
+ << QByteArray("Hi There")
+ << QByteArray::fromHex("9294727a3638bb1c13f48ef8158bfc9d");
+ QTest::newRow("rfc-md5-2") << QCryptographicHash::Md5
+ << QByteArray("Jefe")
+ << QByteArray("what do ya want for nothing?")
+ << QByteArray::fromHex("750c783e6ab0b503eaa86e310a5db738");
+ QTest::newRow("rfc-md5-3") << QCryptographicHash::Md5
+ << QByteArray::fromHex("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
+ << QByteArray(50, 0xdd)
+ << QByteArray::fromHex("56be34521d144c88dbb8c733f0e8b3f6");
+}
+
+void tst_QMessageAuthenticationCode::result()
+{
+ QFETCH(QCryptographicHash::Algorithm, algo);
+ QFETCH(QByteArray, key);
+ QFETCH(QByteArray, message);
+ QFETCH(QByteArray, code);
+
+ QMessageAuthenticationCode mac(algo);
+ mac.setKey(key);
+ mac.addData(message);
+ QByteArray result = mac.result();
+
+ QCOMPARE(result, code);
+}
+
+void tst_QMessageAuthenticationCode::result_incremental_data()
+{
+ result_data();
+}
+
+void tst_QMessageAuthenticationCode::result_incremental()
+{
+ QFETCH(QCryptographicHash::Algorithm, algo);
+ QFETCH(QByteArray, key);
+ QFETCH(QByteArray, message);
+ QFETCH(QByteArray, code);
+
+ int index = message.length() / 2;
+ QByteArray leftPart(message.mid(0, index));
+ QByteArray rightPart(message.mid(index));
+
+ QCOMPARE(leftPart + rightPart, message);
+
+ QMessageAuthenticationCode mac(algo);
+ mac.setKey(key);
+ mac.addData(leftPart);
+ mac.addData(rightPart);
+ QByteArray result = mac.result();
+
+ QCOMPARE(result, code);
+}
+
+QTEST_MAIN(tst_QMessageAuthenticationCode)
+#include "tst_qmessageauthenticationcode.moc"
diff --git a/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp b/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp
index 924cac292e..3231469261 100644
--- a/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp
+++ b/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp
@@ -70,6 +70,9 @@ private slots:
void operator_divide_data();
void operator_divide();
+ void dotProduct_data();
+ void dotProduct();
+
void operator_unary_plus_data();
void operator_unary_plus();
@@ -271,6 +274,28 @@ void tst_QPoint::operator_divide()
QCOMPARE(point, expected);
}
+void tst_QPoint::dotProduct_data()
+{
+ QTest::addColumn<QPoint>("point1");
+ QTest::addColumn<QPoint>("point2");
+ QTest::addColumn<int>("expected");
+
+ QTest::newRow("(0, 0) dot (0, 0)") << QPoint(0, 0) << QPoint(0, 0)<< 0;
+ QTest::newRow("(10, 0) dot (0, 10)") << QPoint(10, 0) << QPoint(0, 10) << 0;
+ QTest::newRow("(0, 10) dot (10, 0)") << QPoint(0, 10) << QPoint(10, 0) << 0;
+ QTest::newRow("(10, 20) dot (-10, -20)") << QPoint(10, 20) << QPoint(-10, -20) << -500;
+ QTest::newRow("(-10, -20) dot (10, 20)") << QPoint(-10, -20) << QPoint(10, 20) << -500;
+}
+
+void tst_QPoint::dotProduct()
+{
+ QFETCH(QPoint, point1);
+ QFETCH(QPoint, point2);
+ QFETCH(int, expected);
+
+ QCOMPARE(QPoint::dotProduct(point1, point2), expected);
+}
+
void tst_QPoint::operator_unary_plus_data()
{
operator_unary_minus_data();
diff --git a/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp b/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp
index 0f2e74e68e..fc79b40a18 100644
--- a/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp
+++ b/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp
@@ -75,6 +75,9 @@ private slots:
void operator_divide();
void division();
+ void dotProduct_data();
+ void dotProduct();
+
void operator_unary_plus_data();
void operator_unary_plus();
@@ -290,6 +293,29 @@ void tst_QPointF::division()
}
}
+void tst_QPointF::dotProduct_data()
+{
+ QTest::addColumn<QPointF>("point1");
+ QTest::addColumn<QPointF>("point2");
+ QTest::addColumn<qreal>("expected");
+
+ QTest::newRow("(0, 0) dot (0, 0)") << QPointF(0, 0) << QPointF(0, 0) << qreal(0);
+ QTest::newRow("(10, 0) dot (0, 10)") << QPointF(10, 0) << QPointF(0, 10)<< qreal(0);
+ QTest::newRow("(0, 10) dot (10, 0)") << QPointF(0, 10) << QPointF(10, 0) << qreal(0);
+ QTest::newRow("(10, 20) dot (-10, -20)") << QPointF(10, 20) << QPointF(-10, -20) << qreal(-500);
+ QTest::newRow("(10.1, 20.2) dot (-10.1, -20.2)") << QPointF(10.1, 20.2) << QPointF(-10.1, -20.2) << qreal(-510.05);
+ QTest::newRow("(-10.1, -20.2) dot (10.1, 20.2)") << QPointF(-10.1, -20.2) << QPointF(10.1, 20.2) << qreal(-510.05);
+}
+
+void tst_QPointF::dotProduct()
+{
+ QFETCH(QPointF, point1);
+ QFETCH(QPointF, point2);
+ QFETCH(qreal, expected);
+
+ QCOMPARE(QPointF::dotProduct(point1, point2), expected);
+}
+
void tst_QPointF::operator_unary_plus_data()
{
operator_unary_minus_data();
diff --git a/tests/auto/corelib/tools/qqueue/tst_qqueue.cpp b/tests/auto/corelib/tools/qqueue/tst_qqueue.cpp
index 88de03e4bf..2fdde3c613 100644
--- a/tests/auto/corelib/tools/qqueue/tst_qqueue.cpp
+++ b/tests/auto/corelib/tools/qqueue/tst_qqueue.cpp
@@ -63,15 +63,15 @@ void tst_QQueue::enqueue_dequeue_data()
void tst_QQueue::enqueue_dequeue()
{
- QFETCH(int, num_items);
-
- int *values = new int[num_items];
- QQueue<int> queue_v;
- QQueue<int*> queue_p;
+ QFETCH(int, num_items);
+
+ int *values = new int[num_items];
+ QQueue<int> queue_v;
+ QQueue<int*> queue_p;
QVERIFY(queue_v.empty());
QVERIFY(queue_p.empty());
-
+
for (int i = 0; i < num_items; i++ ) {
values[i] = i;
queue_p.enqueue(values + i);
@@ -84,11 +84,11 @@ void tst_QQueue::enqueue_dequeue()
v = queue_v.head();
p = queue_p.head();
QCOMPARE(*p, v);
- QCOMPARE(v, i);
+ QCOMPARE(v, i);
v = queue_v.dequeue();
p = queue_p.dequeue();
- QCOMPARE(*p, v);
- QCOMPARE(v, values[i]);
+ QCOMPARE(*p, v);
+ QCOMPARE(v, values[i]);
}
QVERIFY(queue_v.empty());
QVERIFY(queue_p.empty());
diff --git a/tests/auto/corelib/tools/qrect/tst_qrect.cpp b/tests/auto/corelib/tools/qrect/tst_qrect.cpp
index b3fc8b0759..1b11673bd1 100644
--- a/tests/auto/corelib/tools/qrect/tst_qrect.cpp
+++ b/tests/auto/corelib/tools/qrect/tst_qrect.cpp
@@ -41,6 +41,7 @@
#include <QtTest/QtTest>
#include <qrect.h>
+#include <qmargins.h>
#include <limits.h>
#include <qdebug.h>
@@ -133,6 +134,7 @@ private slots:
void newMoveTopLeft();
void newMoveBottomRight_data();
void newMoveBottomRight();
+ void margins();
void translate_data();
void translate();
@@ -3484,6 +3486,25 @@ void tst_QRect::newMoveBottomRight()
QCOMPARE(r,nr);
}
+void tst_QRect::margins()
+{
+ const QRect rectangle = QRect(QPoint(10, 10), QSize(50 ,50));
+ const QMargins margins = QMargins(2, 3, 4, 5);
+
+ const QRect added = rectangle + margins;
+ QCOMPARE(added, QRect(QPoint(8, 7), QSize(56, 58)));
+ QCOMPARE(added, margins + rectangle);
+ QCOMPARE(added, rectangle.marginsAdded(margins));
+
+ QRect a = rectangle;
+ a += margins;
+ QCOMPARE(added, a);
+
+ a = rectangle;
+ a -= margins;
+ QCOMPARE(a, QRect(QPoint(12, 13), QSize(44, 42)));
+ QCOMPARE(a, rectangle.marginsRemoved(margins));
+}
void tst_QRect::translate_data()
{
diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
index 7073805db4..909725f4b8 100644
--- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
+++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>.
+** Copyright (C) 2013 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
@@ -126,8 +127,6 @@ bool operator!=(const Match &m, const QRegularExpressionMatch &rem)
bool operator==(const QRegularExpressionMatchIterator &iterator, const QList<Match> &expectedMatchList)
{
QRegularExpressionMatchIterator i = iterator;
- if (i.isValid() != (!expectedMatchList.isEmpty()))
- return false;
foreach (const Match &expectedMatch, expectedMatchList)
{
@@ -293,6 +292,31 @@ void tst_QRegularExpression::provideRegularExpressions()
| QRegularExpression::InvertedGreedinessOption);
}
+void tst_QRegularExpression::defaultConstructors()
+{
+ QRegularExpression re;
+ QCOMPARE(re.pattern(), QString());
+ QCOMPARE(re.patternOptions(), QRegularExpression::NoPatternOption);
+
+ QRegularExpressionMatch match;
+ QCOMPARE(match.regularExpression(), QRegularExpression());
+ QCOMPARE(match.regularExpression(), re);
+ QCOMPARE(match.matchType(), QRegularExpression::NoMatch);
+ QCOMPARE(match.matchOptions(), QRegularExpression::NoMatchOption);
+ QCOMPARE(match.hasMatch(), false);
+ QCOMPARE(match.hasPartialMatch(), false);
+ QCOMPARE(match.isValid(), true);
+ QCOMPARE(match.lastCapturedIndex(), -1);
+
+ QRegularExpressionMatchIterator iterator;
+ QCOMPARE(iterator.regularExpression(), QRegularExpression());
+ QCOMPARE(iterator.regularExpression(), re);
+ QCOMPARE(iterator.matchType(), QRegularExpression::NoMatch);
+ QCOMPARE(iterator.matchOptions(), QRegularExpression::NoMatchOption);
+ QCOMPARE(iterator.isValid(), true);
+ QCOMPARE(iterator.hasNext(), false);
+}
+
void tst_QRegularExpression::gettersSetters_data()
{
provideRegularExpressions();
@@ -693,12 +717,31 @@ void tst_QRegularExpression::normalMatch()
QFETCH(QRegularExpression::MatchOptions, matchOptions);
QFETCH(Match, match);
- QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NormalMatch, matchOptions);
- consistencyCheck(m);
- QVERIFY(m == match);
+ {
+ QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NormalMatch, matchOptions);
+ consistencyCheck(m);
+ QVERIFY(m == match);
+ QCOMPARE(m.regularExpression(), regexp);
+ QCOMPARE(m.matchType(), QRegularExpression::NormalMatch);
+ QCOMPARE(m.matchOptions(), matchOptions);
+ }
+ {
+ // ignore the expected results provided by the match object --
+ // we'll never get any result when testing the NoMatch type.
+ // Just check the validity of the match here.
+ Match realMatch;
+ realMatch.clear();
+ realMatch.isValid = match.isValid;
+
+ QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NoMatch, matchOptions);
+ consistencyCheck(m);
+ QVERIFY(m == realMatch);
+ QCOMPARE(m.regularExpression(), regexp);
+ QCOMPARE(m.matchType(), QRegularExpression::NoMatch);
+ QCOMPARE(m.matchOptions(), matchOptions);
+ }
}
-
void tst_QRegularExpression::partialMatch_data()
{
QTest::addColumn<QRegularExpression>("regexp");
@@ -952,9 +995,29 @@ void tst_QRegularExpression::partialMatch()
QFETCH(QRegularExpression::MatchOptions, matchOptions);
QFETCH(Match, match);
- QRegularExpressionMatch m = regexp.match(subject, offset, matchType, matchOptions);
- consistencyCheck(m);
- QVERIFY(m == match);
+ {
+ QRegularExpressionMatch m = regexp.match(subject, offset, matchType, matchOptions);
+ consistencyCheck(m);
+ QVERIFY(m == match);
+ QCOMPARE(m.regularExpression(), regexp);
+ QCOMPARE(m.matchType(), matchType);
+ QCOMPARE(m.matchOptions(), matchOptions);
+ }
+ {
+ // ignore the expected results provided by the match object --
+ // we'll never get any result when testing the NoMatch type.
+ // Just check the validity of the match here.
+ Match realMatch;
+ realMatch.clear();
+ realMatch.isValid = match.isValid;
+
+ QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NoMatch, matchOptions);
+ consistencyCheck(m);
+ QVERIFY(m == realMatch);
+ QCOMPARE(m.regularExpression(), regexp);
+ QCOMPARE(m.matchType(), QRegularExpression::NoMatch);
+ QCOMPARE(m.matchOptions(), matchOptions);
+ }
}
void tst_QRegularExpression::globalMatch_data()
@@ -1223,10 +1286,28 @@ void tst_QRegularExpression::globalMatch()
QFETCH(QRegularExpression::MatchType, matchType);
QFETCH(QRegularExpression::MatchOptions, matchOptions);
QFETCH(QList<Match>, matchList);
+ {
+ QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, matchType, matchOptions);
+ consistencyCheck(iterator);
+ QVERIFY(iterator == matchList);
+ QCOMPARE(iterator.regularExpression(), regexp);
+ QCOMPARE(iterator.matchType(), matchType);
+ QCOMPARE(iterator.matchOptions(), matchOptions);
+ }
+ {
+ // ignore the expected results provided by the match object --
+ // we'll never get any result when testing the NoMatch type.
+ // Just check the validity of the match here.
+ QList<Match> realMatchList;
+
+ QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, QRegularExpression::NoMatch, matchOptions);
+ consistencyCheck(iterator);
+ QVERIFY(iterator == realMatchList);
+ QCOMPARE(iterator.regularExpression(), regexp);
+ QCOMPARE(iterator.matchType(), QRegularExpression::NoMatch);
+ QCOMPARE(iterator.matchOptions(), matchOptions);
+ }
- QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, matchType, matchOptions);
- consistencyCheck(iterator);
- QVERIFY(iterator == matchList);
}
void tst_QRegularExpression::serialize_data()
@@ -1338,6 +1419,86 @@ void tst_QRegularExpression::captureCount()
QCOMPARE(re.captureCount(), -1);
}
+// the comma in the template breaks QFETCH...
+typedef QMultiHash<QString, int> StringToIntMap;
+Q_DECLARE_METATYPE(StringToIntMap)
+
+void tst_QRegularExpression::captureNames_data()
+{
+ QTest::addColumn<QString>("pattern");
+ QTest::addColumn<StringToIntMap>("namedCapturesIndexMap");
+ StringToIntMap map;
+
+ QTest::newRow("captureNames01") << "a pattern" << map;
+ QTest::newRow("captureNames02") << "a.*pattern" << map;
+ QTest::newRow("captureNames03") << "(a) pattern" << map;
+ QTest::newRow("captureNames04") << "(a).*(pattern)" << map;
+
+ map.clear();
+ map.replace("named", 1);
+ QTest::newRow("captureNames05") << "a.*(?<named>pattern)" << map;
+
+ map.clear();
+ map.replace("named", 2);
+ QTest::newRow("captureNames06") << "(a).*(?<named>pattern)" << map;
+
+ map.clear();
+ map.replace("name1", 1);
+ map.replace("name2", 2);
+ QTest::newRow("captureNames07") << "(?<name1>a).*(?<name2>pattern)" << map;
+
+ map.clear();
+ map.replace("name1", 2);
+ map.replace("name2", 1);
+ QTest::newRow("captureNames08") << "(?<name2>a).*(?<name1>pattern)" << map;
+
+ map.clear();
+ map.replace("date", 1);
+ map.replace("month", 2);
+ map.replace("year", 3);
+ QTest::newRow("captureNames09") << "^(?<date>\\d\\d)/(?<month>\\d\\d)/(?<year>\\d\\d\\d\\d)$" << map;
+
+ map.clear();
+ map.replace("date", 2);
+ map.replace("month", 1);
+ map.replace("year", 3);
+ QTest::newRow("captureNames10") << "^(?<month>\\d\\d)/(?<date>\\d\\d)/(?<year>\\d\\d\\d\\d)$" << map;
+
+ map.clear();
+ map.replace("noun", 2);
+ QTest::newRow("captureNames11") << "(a)(?|(?<noun>b)|(?<noun>c))(d)" << map;
+
+ map.clear();
+ QTest::newRow("captureNames_invalid01") << "(.*" << map;
+ QTest::newRow("captureNames_invalid02") << "\\" << map;
+ QTest::newRow("captureNames_invalid03") << "(?<noun)" << map;
+ QTest::newRow("captureNames_invalid04") << "(?|(?<noun1>a)|(?<noun2>b))" << map;
+}
+
+void tst_QRegularExpression::captureNames()
+{
+ QFETCH(QString, pattern);
+ QFETCH(StringToIntMap, namedCapturesIndexMap);
+
+ const QRegularExpression re(pattern);
+ QStringList namedCaptureGroups = re.namedCaptureGroups();
+ int namedCaptureGroupsCount = namedCaptureGroups.size();
+
+ QCOMPARE(namedCaptureGroupsCount, re.captureCount() + 1);
+
+ for (int i = 0; i < namedCaptureGroupsCount; ++i) {
+ const QString &name = namedCaptureGroups.at(i);
+
+ if (name.isEmpty()) {
+ QVERIFY(!namedCapturesIndexMap.contains(name));
+ } else {
+ QVERIFY(namedCapturesIndexMap.contains(name));
+ QCOMPARE(i, namedCapturesIndexMap.value(name));
+ }
+ }
+
+}
+
void tst_QRegularExpression::pcreJitStackUsage_data()
{
QTest::addColumn<QString>("pattern");
@@ -1389,3 +1550,35 @@ void tst_QRegularExpression::regularExpressionMatch()
QTest::ignoreMessage(QtWarningMsg, "QRegularExpressionMatch::captured: empty capturing group name passed");
QCOMPARE(match.captured(QString()).isNull(), true);
}
+
+void tst_QRegularExpression::JOptionUsage_data()
+{
+ QTest::addColumn<QString>("pattern");
+ QTest::addColumn<bool>("isValid");
+ QTest::addColumn<bool>("JOptionUsed");
+
+ QTest::newRow("joption-notused-01") << "a.*b" << true << false;
+ QTest::newRow("joption-notused-02") << "^a(b)(c)$" << true << false;
+ QTest::newRow("joption-notused-03") << "a(b)(?<c>d)|e" << true << false;
+ QTest::newRow("joption-notused-04") << "(?<a>.)(?<a>.)" << false << false;
+
+ QTest::newRow("joption-used-01") << "(?J)a.*b" << true << true;
+ QTest::newRow("joption-used-02") << "(?-J)a.*b" << true << true;
+ QTest::newRow("joption-used-03") << "(?J)(?<a>.)(?<a>.)" << true << true;
+ QTest::newRow("joption-used-04") << "(?-J)(?<a>.)(?<a>.)" << false << true;
+
+}
+
+void tst_QRegularExpression::JOptionUsage()
+{
+ QFETCH(QString, pattern);
+ QFETCH(bool, isValid);
+ QFETCH(bool, JOptionUsed);
+
+ const QString warningMessage = QStringLiteral("QRegularExpressionPrivate::getPatternInfo(): the pattern '%1'\n is using the (?J) option; duplicate capturing group names are not supported by Qt");
+
+ QRegularExpression re(pattern);
+ if (isValid && JOptionUsed)
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warningMessage.arg(pattern)));
+ QCOMPARE(re.isValid(), isValid);
+}
diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h
index d6f9312411..0f62570114 100644
--- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h
+++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h
@@ -51,6 +51,7 @@ class tst_QRegularExpression : public QObject
Q_OBJECT
private slots:
+ void defaultConstructors();
void gettersSetters_data();
void gettersSetters();
void escape_data();
@@ -71,10 +72,14 @@ private slots:
void operatoreq();
void captureCount_data();
void captureCount();
+ void captureNames_data();
+ void captureNames();
void pcreJitStackUsage_data();
void pcreJitStackUsage();
void regularExpressionMatch_data();
void regularExpressionMatch();
+ void JOptionUsage_data();
+ void JOptionUsage();
private:
void provideRegularExpressions();
diff --git a/tests/auto/corelib/tools/qset/tst_qset.cpp b/tests/auto/corelib/tools/qset/tst_qset.cpp
index a3232d05c3..eaa1c018ba 100644
--- a/tests/auto/corelib/tools/qset/tst_qset.cpp
+++ b/tests/auto/corelib/tools/qset/tst_qset.cpp
@@ -79,6 +79,7 @@ private slots:
void javaIterator();
void javaMutableIterator();
void makeSureTheComfortFunctionsCompile();
+ void initializerList();
};
void tst_QSet::operator_eq()
@@ -918,6 +919,27 @@ void tst_QSet::makeSureTheComfortFunctionsCompile()
set1 = set2 - set3;
}
+void tst_QSet::initializerList()
+{
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+ QSet<int> set{1, 2, 3, 4, 5};
+ QCOMPARE(set.count(), 5);
+ QVERIFY(set.contains(1));
+ QVERIFY(set.contains(2));
+ QVERIFY(set.contains(3));
+ QVERIFY(set.contains(4));
+ QVERIFY(set.contains(5));
+
+ QSet<int> emptySet{};
+ QVERIFY(emptySet.isEmpty());
+
+ QSet<int> set3{{}, {}, {}};
+ QVERIFY(!set3.isEmpty());
+#else
+ QSKIP("Compiler doesn't support initializer lists");
+#endif
+}
+
QTEST_APPLESS_MAIN(tst_QSet)
#include "tst_qset.moc"
diff --git a/tests/auto/corelib/tools/qsharedpointer/externaltests.pri b/tests/auto/corelib/tools/qsharedpointer/externaltests.pri
index 10d30e3c76..b3a01f7990 100644
--- a/tests/auto/corelib/tools/qsharedpointer/externaltests.pri
+++ b/tests/auto/corelib/tools/qsharedpointer/externaltests.pri
@@ -4,4 +4,4 @@ cleanedQMAKESPEC = $$replace(QMAKESPEC, \\\\, /)
DEFINES += DEFAULT_MAKESPEC=\\\"$$cleanedQMAKESPEC\\\"
cross_compile:DEFINES += QTEST_NO_RTTI QTEST_CROSS_COMPILED
-wince*:DEFINES += QTEST_CROSS_COMPILED QTEST_NO_RTTI
+wince*:DEFINES += QTEST_CROSS_COMPILED QTEST_NO_RTTI
diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
index 8e10b757c8..5b1a2cf076 100644
--- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
@@ -97,6 +97,7 @@ private slots:
void lambdaCustomDeleter();
#endif
void creating();
+ void creatingVariadic();
void creatingQObject();
void mixTrackingPointerCode();
void reentrancyWhileDestructing();
@@ -176,6 +177,49 @@ public:
int Data::generationCounter = 0;
int Data::destructorCounter = 0;
+struct NoDefaultConstructor1
+{
+ int i;
+ NoDefaultConstructor1(int i) : i(i) {}
+ NoDefaultConstructor1(uint j) : i(j + 42) {}
+};
+
+struct NoDefaultConstructorRef1
+{
+ int &i;
+ NoDefaultConstructorRef1(int &i) : i(i) {}
+};
+
+struct NoDefaultConstructor2
+{
+ void *ptr;
+ int i;
+ NoDefaultConstructor2(void *ptr, int i) : ptr(ptr), i(i) {}
+};
+
+struct NoDefaultConstructorRef2
+{
+ QString str;
+ int i;
+ NoDefaultConstructorRef2(QString &str, int i) : str(str), i(i) {}
+};
+
+struct NoDefaultConstructorConstRef2
+{
+ QString str;
+ int i;
+ NoDefaultConstructorConstRef2(const QString &str, int i) : str(str), i(i) {}
+ NoDefaultConstructorConstRef2(const QByteArray &ba, int i = 42) : str(QString::fromLatin1(ba)), i(i) {}
+};
+
+#ifdef Q_COMPILER_RVALUE_REFS
+struct NoDefaultConstructorRRef1
+{
+ int &i;
+ NoDefaultConstructorRRef1(int &&i) : i(i) {}
+};
+#endif
+
void tst_QSharedPointer::basics_data()
{
QTest::addColumn<bool>("isNull");
@@ -1436,6 +1480,82 @@ void tst_QSharedPointer::creating()
safetyCheck();
}
+void tst_QSharedPointer::creatingVariadic()
+{
+#if !defined(Q_COMPILER_RVALUE_REFS) || !defined(Q_COMPILER_VARIADIC_TEMPLATES)
+ QSKIP("This compiler is not in C++11 mode or it doesn't support rvalue refs and variadic templates");
+#else
+ int i = 42;
+
+ {
+ NoDefaultConstructor1(1); // control check
+ QSharedPointer<NoDefaultConstructor1> ptr = QSharedPointer<NoDefaultConstructor1>::create(1);
+ QCOMPARE(ptr->i, 1);
+
+ NoDefaultConstructor1(0u); // control check
+ ptr = QSharedPointer<NoDefaultConstructor1>::create(0u);
+ QCOMPARE(ptr->i, 42);
+
+ NoDefaultConstructor1 x(i); // control check
+ ptr = QSharedPointer<NoDefaultConstructor1>::create(i);
+ QCOMPARE(ptr->i, i);
+ }
+ {
+ NoDefaultConstructor2((void*)0, 1); // control check
+ QSharedPointer<NoDefaultConstructor2> ptr = QSharedPointer<NoDefaultConstructor2>::create((void*)0, 1);
+ QCOMPARE(ptr->i, 1);
+ QCOMPARE(ptr->ptr, (void*)0);
+
+ int *null = 0;
+ NoDefaultConstructor2(null, 2); // control check
+ ptr = QSharedPointer<NoDefaultConstructor2>::create(null, 2);
+ QCOMPARE(ptr->i, 2);
+ QCOMPARE(ptr->ptr, (void*)0);
+
+#ifdef Q_COMPILER_NULLPTR
+ NoDefaultConstructor2(nullptr, 3); // control check
+ ptr = QSharedPointer<NoDefaultConstructor2>::create(nullptr, 3);
+ QCOMPARE(ptr->i, 3);
+ QCOMPARE(ptr->ptr, (void*)nullptr);
+#endif
+ }
+ {
+ NoDefaultConstructorRef1 x(i); // control check
+ QSharedPointer<NoDefaultConstructorRef1> ptr = QSharedPointer<NoDefaultConstructorRef1>::create(i);
+ QCOMPARE(ptr->i, i);
+ QCOMPARE(&ptr->i, &i);
+ }
+ {
+ NoDefaultConstructorRRef1(1); // control check
+ QSharedPointer<NoDefaultConstructorRRef1> ptr = QSharedPointer<NoDefaultConstructorRRef1>::create(1);
+ QCOMPARE(ptr->i, 1);
+
+ NoDefaultConstructorRRef1(std::move(i)); // control check
+ ptr = QSharedPointer<NoDefaultConstructorRRef1>::create(std::move(i));
+ QCOMPARE(ptr->i, i);
+ }
+ {
+ QString text("Hello, World");
+ NoDefaultConstructorRef2(text, 1); // control check
+ QSharedPointer<NoDefaultConstructorRef2> ptr = QSharedPointer<NoDefaultConstructorRef2>::create(text, 1);
+ QCOMPARE(ptr->str, text);
+ QCOMPARE(ptr->i, 1);
+ }
+ {
+ QSharedPointer<NoDefaultConstructorConstRef2> ptr;
+ NoDefaultConstructorConstRef2(QLatin1String("string"), 1); // control check
+ ptr = QSharedPointer<NoDefaultConstructorConstRef2>::create(QLatin1String("string"), 1);
+ QCOMPARE(ptr->str, QString("string"));
+ QCOMPARE(ptr->i, 1);
+
+ NoDefaultConstructorConstRef2(QByteArray("bytearray")); // control check
+ ptr = QSharedPointer<NoDefaultConstructorConstRef2>::create(QByteArray("bytearray"));
+ QCOMPARE(ptr->str, QString("bytearray"));
+ QCOMPARE(ptr->i, 42);
+ }
+#endif
+}
+
void tst_QSharedPointer::creatingQObject()
{
{
@@ -1876,7 +1996,7 @@ void tst_QSharedPointer::invalidConstructs()
QByteArray body = code.toLatin1();
bool result = (test.*testFunction)(body);
- if (qgetenv("QTEST_EXTERNAL_DEBUG").toInt() > 0) {
+ if (!result || qgetenv("QTEST_EXTERNAL_DEBUG").toInt() > 0) {
qDebug("External test output:");
#ifdef Q_CC_MSVC
// MSVC prints errors to stdout
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
index 8e30a66d6f..aa61885a47 100644
--- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
@@ -195,6 +195,8 @@ private slots:
void stringRef_local8Bit();
void fromLatin1();
void fromAscii();
+ void fromUcs4();
+ void toUcs4();
void arg();
void number();
void arg_fillChar_data();
@@ -238,7 +240,7 @@ private slots:
#ifdef QT_USE_ICU
void toUpperLower_icu();
#endif
-#if defined(QT_UNICODE_LITERAL) && (defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU))
+#if !defined(QT_NO_UNICODE_LITERAL) && defined(Q_COMPILER_LAMBDA)
void literals();
#endif
void eightBitLiterals_data();
@@ -1003,10 +1005,12 @@ void tst_QString::sprintf()
a.sprintf("%s%n%s", "hello", &n1, "goodbye");
QCOMPARE(n1, 5);
QCOMPARE(a, QString("hellogoodbye"));
+#ifndef Q_CC_MINGW // does not know %ll
qlonglong n2;
a.sprintf("%s%s%lln%s", "foo", "bar", &n2, "whiz");
QCOMPARE((int)n2, 6);
QCOMPARE(a, QString("foobarwhiz"));
+#endif
}
/*
@@ -1425,6 +1429,55 @@ void tst_QString::contains()
QVERIFY(a.contains(QRegularExpression("[FG][HI]")));
QVERIFY(a.contains(QRegularExpression("[G][HE]")));
+ {
+ QRegularExpressionMatch match;
+ QVERIFY(!match.hasMatch());
+
+ QVERIFY(a.contains(QRegularExpression("[FG][HI]"), &match));
+ QVERIFY(match.hasMatch());
+ QCOMPARE(match.capturedStart(), 6);
+ QCOMPARE(match.capturedEnd(), 8);
+ QCOMPARE(match.captured(), QStringLiteral("GH"));
+
+ QVERIFY(a.contains(QRegularExpression("[G][HE]"), &match));
+ QVERIFY(match.hasMatch());
+ QCOMPARE(match.capturedStart(), 6);
+ QCOMPARE(match.capturedEnd(), 8);
+ QCOMPARE(match.captured(), QStringLiteral("GH"));
+
+ QVERIFY(a.contains(QRegularExpression("[f](.*)[FG]"), &match));
+ QVERIFY(match.hasMatch());
+ QCOMPARE(match.capturedStart(), 10);
+ QCOMPARE(match.capturedEnd(), 15);
+ QCOMPARE(match.captured(), QString("fGEFG"));
+ QCOMPARE(match.capturedStart(1), 11);
+ QCOMPARE(match.capturedEnd(1), 14);
+ QCOMPARE(match.captured(1), QStringLiteral("GEF"));
+
+ QVERIFY(a.contains(QRegularExpression("[f](.*)[F]"), &match));
+ QVERIFY(match.hasMatch());
+ QCOMPARE(match.capturedStart(), 10);
+ QCOMPARE(match.capturedEnd(), 14);
+ QCOMPARE(match.captured(), QString("fGEF"));
+ QCOMPARE(match.capturedStart(1), 11);
+ QCOMPARE(match.capturedEnd(1), 13);
+ QCOMPARE(match.captured(1), QStringLiteral("GE"));
+
+ QVERIFY(!a.contains(QRegularExpression("ZZZ"), &match));
+ // doesn't match, but ensure match didn't change
+ QVERIFY(match.hasMatch());
+ QCOMPARE(match.capturedStart(), 10);
+ QCOMPARE(match.capturedEnd(), 14);
+ QCOMPARE(match.captured(), QStringLiteral("fGEF"));
+ QCOMPARE(match.capturedStart(1), 11);
+ QCOMPARE(match.capturedEnd(1), 13);
+ QCOMPARE(match.captured(1), QStringLiteral("GE"));
+
+ // don't crash with a null pointer
+ QVERIFY(a.contains(QRegularExpression("[FG][HI]"), 0));
+ QVERIFY(!a.contains(QRegularExpression("ZZZ"), 0));
+ }
+
CREATE_REF(QLatin1String("FG"));
QVERIFY(a.contains(ref));
QVERIFY(a.contains(ref, Qt::CaseInsensitive));
@@ -3880,6 +3933,52 @@ void tst_QString::fromAscii()
QVERIFY(a.size() == 5);
}
+void tst_QString::fromUcs4()
+{
+ QString s;
+ s = QString::fromUcs4( 0 );
+ QVERIFY( s.isNull() );
+ QCOMPARE( s.size(), 0 );
+ s = QString::fromUcs4( 0, 0 );
+ QVERIFY( s.isNull() );
+ QCOMPARE( s.size(), 0 );
+ s = QString::fromUcs4( 0, 5 );
+ QVERIFY( s.isNull() );
+ QCOMPARE( s.size(), 0 );
+
+ uint nil = '\0';
+ s = QString::fromUcs4( &nil );
+ QVERIFY( !s.isNull() );
+ QCOMPARE( s.size(), 0 );
+ s = QString::fromUcs4( &nil, 0 );
+ QVERIFY( !s.isNull() );
+ QCOMPARE( s.size(), 0 );
+
+ uint bmp = 'a';
+ s = QString::fromUcs4( &bmp, 1 );
+ QVERIFY( !s.isNull() );
+ QCOMPARE( s.size(), 1 );
+
+ uint smp = 0x10000;
+ s = QString::fromUcs4( &smp, 1 );
+ QVERIFY( !s.isNull() );
+ QCOMPARE( s.size(), 2 );
+}
+
+void tst_QString::toUcs4()
+{
+ QString s;
+ QCOMPARE( s.toUcs4().size(), 0 );
+
+ QChar bmp = QLatin1Char('a');
+ s = QString(&bmp, 1);
+ QCOMPARE( s.toUcs4().size(), 1 );
+
+ QChar smp[] = { QChar::highSurrogate(0x10000), QChar::lowSurrogate(0x10000) };
+ s = QString(smp, 2);
+ QCOMPARE( s.toUcs4().size(), 1 );
+}
+
void tst_QString::arg()
{
/*
@@ -5187,6 +5286,9 @@ void tst_QString::QCharRefDetaching() const
void tst_QString::sprintfZU() const
{
+#ifdef Q_CC_MINGW
+ QSKIP("MinGW does not support '%zu'.");
+#else
{
QString string;
size_t s = 6;
@@ -5215,6 +5317,7 @@ void tst_QString::sprintfZU() const
string.sprintf("%zu %s\n", s, "foo");
QCOMPARE(string, QString::fromLatin1("6 foo\n"));
}
+#endif // !Q_CC_MINGW
}
void tst_QString::repeatedSignature() const
@@ -5382,7 +5485,7 @@ void tst_QString::toUpperLower_icu()
}
#endif
-#if defined(QT_UNICODE_LITERAL) && (defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU))
+#if !defined(QT_NO_UNICODE_LITERAL) && defined(Q_COMPILER_LAMBDA)
// Only tested on c++0x compliant compiler or gcc
void tst_QString::literals()
{
diff --git a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp
index 66f40e05cb..1045d5929f 100644
--- a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp
+++ b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp
@@ -69,6 +69,25 @@ private slots:
void compare_data();
void compare();
void operator_eqeq_nullstring();
+ void toNum();
+ void toDouble_data();
+ void toDouble();
+ void toFloat();
+ void toLong_data();
+ void toLong();
+ void toULong_data();
+ void toULong();
+ void toLongLong();
+ void toULongLong();
+ void toUInt();
+ void toInt();
+ void toShort();
+ void toUShort();
+ void double_conversion_data();
+ void double_conversion();
+ void integer_conversion_data();
+ void integer_conversion();
+ void trimmed();
};
static QStringRef emptyRef()
@@ -840,6 +859,941 @@ void tst_QStringRef::compare()
}
}
+void tst_QStringRef::toNum()
+{
+#define TEST_TO_INT(num, func, type) \
+ a = #num; \
+ b = a.leftRef(-1); \
+ QCOMPARE(b.func(&ok), type(Q_INT64_C(num))); \
+ QVERIFY2(ok, "Failed: num=" #num);
+
+ QString a;
+ QStringRef b;
+ bool ok = false;
+
+ TEST_TO_INT(0, toInt, int)
+ TEST_TO_INT(-1, toInt, int)
+ TEST_TO_INT(1, toInt, int)
+ TEST_TO_INT(2147483647, toInt, int)
+ TEST_TO_INT(-2147483648, toInt, int)
+
+ TEST_TO_INT(0, toShort, short)
+ TEST_TO_INT(-1, toShort, short)
+ TEST_TO_INT(1, toShort, short)
+ TEST_TO_INT(32767, toShort, short)
+ TEST_TO_INT(-32768, toShort, short)
+
+ TEST_TO_INT(0, toLong, long)
+ TEST_TO_INT(-1, toLong, long)
+ TEST_TO_INT(1, toLong, long)
+ TEST_TO_INT(2147483647, toLong, long)
+ TEST_TO_INT(-2147483648, toLong, long)
+ TEST_TO_INT(0, toLongLong, (long long))
+ TEST_TO_INT(-1, toLongLong, (long long))
+ TEST_TO_INT(1, toLongLong, (long long))
+ TEST_TO_INT(9223372036854775807, toLongLong, (long long))
+ TEST_TO_INT(-9223372036854775807, toLongLong, (long long))
+
+#undef TEST_TO_INT
+
+#define TEST_TO_UINT(num, func, type) \
+ a = #num; \
+ b = a.leftRef(-1); \
+ QCOMPARE(b.func(&ok), type(Q_UINT64_C(num))); \
+ QVERIFY2(ok, "Failed: num=" #num);
+
+ TEST_TO_UINT(0, toUInt, (unsigned int))
+ TEST_TO_UINT(1, toUInt, (unsigned int))
+ TEST_TO_UINT(4294967295, toUInt, (unsigned int))
+
+ TEST_TO_UINT(0, toUShort, (unsigned short))
+ TEST_TO_UINT(1, toUShort, (unsigned short))
+ TEST_TO_UINT(65535, toUShort, (unsigned short))
+
+ TEST_TO_UINT(0, toULong, (unsigned long))
+ TEST_TO_UINT(1, toULong, (unsigned long))
+ TEST_TO_UINT(4294967295, toULong, (unsigned long))
+
+ TEST_TO_UINT(0, toULongLong, (unsigned long long))
+ TEST_TO_UINT(1, toULongLong, (unsigned long long))
+ TEST_TO_UINT(18446744073709551615, toULongLong, (unsigned long long))
+
+#undef TEST_TO_UINT
+
+#define TEST_BASE(str, base, num) \
+ a = str; \
+ b = a.leftRef(-1); \
+ QCOMPARE(b.toInt(&ok,base), int(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toInt"); \
+ QCOMPARE(b.toUInt(&ok, base), (unsigned int)(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toUInt"); \
+ QCOMPARE(b.toShort(&ok, base), short(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toShort"); \
+ QCOMPARE(b.toUShort(&ok, base), (unsigned short)(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toUShort"); \
+ QCOMPARE(b.toLong(&ok, base), long(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toLong"); \
+ QCOMPARE(b.toULong(&ok, base), (unsigned long)(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toULong"); \
+ QCOMPARE(b.toLongLong(&ok, base), (long long)(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toLongLong"); \
+ QCOMPARE(b.toULongLong(&ok, base), (unsigned long long)(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toULongLong");
+
+ TEST_BASE("FF", 16, 255)
+ TEST_BASE("0xFF", 16, 255)
+ TEST_BASE("77", 8, 63)
+ TEST_BASE("077", 8, 63)
+
+ TEST_BASE("0xFF", 0, 255)
+ TEST_BASE("077", 0, 63)
+ TEST_BASE("255", 0, 255)
+
+ TEST_BASE(" FF", 16, 255)
+ TEST_BASE(" 0xFF", 16, 255)
+ TEST_BASE(" 77", 8, 63)
+ TEST_BASE(" 077", 8, 63)
+
+ TEST_BASE(" 0xFF", 0, 255)
+ TEST_BASE(" 077", 0, 63)
+ TEST_BASE(" 255", 0, 255)
+
+ TEST_BASE("\tFF\t", 16, 255)
+ TEST_BASE("\t0xFF ", 16, 255)
+ TEST_BASE(" 77 ", 8, 63)
+ TEST_BASE("77 ", 8, 63)
+
+#undef TEST_BASE
+
+#define TEST_NEG_BASE(str, base, num) \
+ a = str; \
+ b = a.leftRef(-1); \
+ QCOMPARE(b.toInt(&ok, base), int(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toInt"); \
+ QCOMPARE(b.toShort(&ok,base), short(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toShort"); \
+ QCOMPARE(b.toLong(&ok, base), long(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toLong"); \
+ QCOMPARE(b.toLongLong(&ok, base), (long long)(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toLongLong");
+
+ TEST_NEG_BASE("-FE", 16, -254)
+ TEST_NEG_BASE("-0xFE", 16, -254)
+ TEST_NEG_BASE("-77", 8, -63)
+ TEST_NEG_BASE("-077", 8, -63)
+
+ TEST_NEG_BASE("-0xFE", 0, -254)
+ TEST_NEG_BASE("-077", 0, -63)
+ TEST_NEG_BASE("-254", 0, -254)
+
+#undef TEST_NEG_BASE
+
+#define TEST_DOUBLE(num, str) \
+ a = str; \
+ b = a.leftRef(-1); \
+ QCOMPARE(b.toDouble(&ok), num); \
+ QVERIFY(ok);
+
+ TEST_DOUBLE(1.2345, "1.2345")
+ TEST_DOUBLE(12.345, "1.2345e+01")
+ TEST_DOUBLE(12.345, "1.2345E+01")
+ TEST_DOUBLE(12345.6, "12345.6")
+
+#undef TEST_DOUBLE
+
+#define TEST_BAD(str, func) \
+ a = str; \
+ b = a.leftRef(-1); \
+ b.func(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str " func=" #func);
+
+ TEST_BAD("32768", toShort)
+ TEST_BAD("-32769", toShort)
+ TEST_BAD("65536", toUShort)
+ TEST_BAD("2147483648", toInt)
+ TEST_BAD("-2147483649", toInt)
+ TEST_BAD("4294967296", toUInt)
+ if (sizeof(long) == 4) {
+ TEST_BAD("2147483648", toLong)
+ TEST_BAD("-2147483649", toLong)
+ TEST_BAD("4294967296", toULong)
+ }
+ TEST_BAD("9223372036854775808", toLongLong)
+ TEST_BAD("-9223372036854775809", toLongLong)
+ TEST_BAD("18446744073709551616", toULongLong)
+ TEST_BAD("-1", toUShort)
+ TEST_BAD("-1", toUInt)
+ TEST_BAD("-1", toULong)
+ TEST_BAD("-1", toULongLong)
+
+#undef TEST_BAD
+
+#define TEST_BAD_ALL(str) \
+ a = str; \
+ b = a.leftRef(-1); \
+ b.toShort(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str); \
+ b.toUShort(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str); \
+ b.toInt(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str); \
+ b.toUInt(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str); \
+ b.toLong(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str); \
+ b.toULong(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str); \
+ b.toLongLong(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str); \
+ b.toULongLong(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str); \
+ b.toFloat(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str); \
+ b.toDouble(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str);
+
+ TEST_BAD_ALL((const char*)0);
+ TEST_BAD_ALL("");
+ TEST_BAD_ALL(" ");
+ TEST_BAD_ALL(".");
+ TEST_BAD_ALL("-");
+ TEST_BAD_ALL("hello");
+ TEST_BAD_ALL("1.2.3");
+ TEST_BAD_ALL("0x0x0x");
+ TEST_BAD_ALL("123-^~<");
+ TEST_BAD_ALL("123ThisIsNotANumber");
+
+#undef TEST_BAD_ALL
+
+ a = "FF";
+ b = a.leftRef(-1);
+ b.toULongLong(&ok, 10);
+ QVERIFY(!ok);
+
+ a = "FF";
+ b = a.leftRef(-1);
+ b.toULongLong(&ok, 0);
+ QVERIFY(!ok);
+
+#ifdef QT_NO_FPU
+ double d = 3.40282346638528e+38; // slightly off FLT_MAX when using hardfloats
+#else
+ double d = 3.4028234663852886e+38; // FLT_MAX
+#endif
+ QString::number(d, 'e', 17).leftRef(-1).toFloat(&ok);
+ QVERIFY(ok);
+ QString::number(d + 1e32, 'e', 17).leftRef(-1).toFloat(&ok);
+ QVERIFY(!ok);
+ a = QString::number(-d, 'e', 17).leftRef(-1).toFloat(&ok);
+ QVERIFY(ok);
+ QString::number(-d - 1e32, 'e', 17).leftRef(-1).toFloat(&ok);
+ QVERIFY(!ok);
+ QString::number(d + 1e32, 'e', 17).leftRef(-1).toDouble(&ok);
+ QVERIFY(ok);
+ QString::number(-d - 1e32, 'e', 17).leftRef(-1).toDouble(&ok);
+ QVERIFY(ok);
+}
+
+void tst_QStringRef::toUShort()
+{
+ QString a;
+ QStringRef b;
+ bool ok;
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+
+ a = "";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+
+ a = "COMPARE";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+
+ a = "123";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(123));
+ QCOMPARE(b.toUShort(&ok), ushort(123));
+ QVERIFY(ok);
+
+ a = "123A";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+
+ a = "1234567";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+
+ a = "aaa123aaa";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+
+ a = "aaa123";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+
+ a = "123aaa";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+
+ a = "32767";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(32767));
+ QCOMPARE(b.toUShort(&ok), ushort(32767));
+ QVERIFY(ok);
+
+ a = "-32767";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+
+ a = "65535";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(65535));
+ QCOMPARE(b.toUShort(&ok), ushort(65535));
+ QVERIFY(ok);
+
+ if (sizeof(short) == 2) {
+ a = "65536";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+
+ a = "123456";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+ }
+}
+
+void tst_QStringRef::toShort()
+{
+ QString a;
+ QStringRef b;
+ bool ok;
+ QCOMPARE(b.toShort(), short(0));
+ QCOMPARE(b.toShort(&ok), short(0));
+ QVERIFY(!ok);
+
+ a = "";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(0));
+ QCOMPARE(b.toShort(&ok), short(0));
+ QVERIFY(!ok);
+
+ a = "COMPARE";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(0));
+ QCOMPARE(b.toShort(&ok), short(0));
+ QVERIFY(!ok);
+
+ a = "123";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(123));
+ QCOMPARE(b.toShort(&ok), short(123));
+ QVERIFY(ok);
+
+ a = "123A";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(0));
+ QCOMPARE(b.toShort(&ok), short(0));
+ QVERIFY(!ok);
+
+ a = "1234567";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(0));
+ QCOMPARE(b.toShort(&ok), short(0));
+ QVERIFY(!ok);
+
+ a = "aaa123aaa";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(0));
+ QCOMPARE(b.toShort(&ok), short(0));
+ QVERIFY(!ok);
+
+ a = "aaa123";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(0));
+ QCOMPARE(b.toShort(&ok), short(0));
+ QVERIFY(!ok);
+
+ a = "123aaa";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(0));
+ QCOMPARE(b.toShort(&ok), short(0));
+ QVERIFY(!ok);
+
+ a = "32767";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(32767));
+ QCOMPARE(b.toShort(&ok), short(32767));
+ QVERIFY(ok);
+
+ a = "-32767";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(-32767));
+ QCOMPARE(b.toShort(&ok), short(-32767));
+ QVERIFY(ok);
+
+ a = "-32768";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(-32768));
+ QCOMPARE(b.toShort(&ok), short(-32768));
+ QVERIFY(ok);
+
+ if (sizeof(short) == 2) {
+ a = "32768";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(0));
+ QCOMPARE(b.toShort(&ok), short(0));
+ QVERIFY(!ok);
+
+ a = "-32769";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(0));
+ QCOMPARE(b.toShort(&ok), short(0));
+ QVERIFY(!ok);
+ }
+}
+
+void tst_QStringRef::toInt()
+{
+ QString a;
+ QStringRef b;
+ bool ok;
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+
+ a = "";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+
+ a = "COMPARE";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+
+ a = "123";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 123);
+ QCOMPARE(b.toInt(&ok), 123);
+ QVERIFY(ok);
+
+ a = "123A";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+
+ a = "1234567";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 1234567);
+ QCOMPARE(b.toInt(&ok), 1234567);
+ QVERIFY(ok);
+
+ a = "12345678901234";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+
+ a = "3234567890";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+
+ a = "aaa12345aaa";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+
+ a = "aaa12345";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+
+ a = "12345aaa";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+
+ a = "2147483647"; // 2**31 - 1
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 2147483647);
+ QCOMPARE(b.toInt(&ok), 2147483647);
+ QVERIFY(ok);
+
+ if (sizeof(int) == 4) {
+ a = "-2147483647"; // -(2**31 - 1)
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), -2147483647);
+ QCOMPARE(b.toInt(&ok), -2147483647);
+ QVERIFY(ok);
+
+ a = "2147483648"; // 2**31
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+
+ a = "-2147483648"; // -2**31
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), -2147483647 - 1);
+ QCOMPARE(b.toInt(&ok), -2147483647 - 1);
+ QVERIFY(ok);
+
+ a = "2147483649"; // 2**31 + 1
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+ }
+}
+
+void tst_QStringRef::toUInt()
+{
+ bool ok;
+ QString a;
+ QStringRef b;
+ a = "3234567890";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUInt(&ok), 3234567890u);
+ QVERIFY(ok);
+
+ a = "-50";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUInt(), 0u);
+ QCOMPARE(b.toUInt(&ok), 0u);
+ QVERIFY(!ok);
+
+ a = "4294967295"; // 2**32 - 1
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUInt(), 4294967295u);
+ QCOMPARE(b.toUInt(&ok), 4294967295u);
+ QVERIFY(ok);
+
+ if (sizeof(int) == 4) {
+ a = "4294967296"; // 2**32
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUInt(), 0u);
+ QCOMPARE(b.toUInt(&ok), 0u);
+ QVERIFY(!ok);
+ }
+}
+
+///////////////////////////// to*Long //////////////////////////////////////
+
+void tst_QStringRef::toULong_data()
+{
+ QTest::addColumn<QString>("str");
+ QTest::addColumn<int>("base");
+ QTest::addColumn<ulong>("result");
+ QTest::addColumn<bool>("ok");
+
+ QTest::newRow("default") << QString() << 10 << 0UL << false;
+ QTest::newRow("empty") << QString("") << 10 << 0UL << false;
+ QTest::newRow("ulong1") << QString("3234567890") << 10 << 3234567890UL << true;
+ QTest::newRow("ulong2") << QString("fFFfFfFf") << 16 << 0xFFFFFFFFUL << true;
+}
+
+void tst_QStringRef::toULong()
+{
+ QFETCH(QString, str);
+ QFETCH(int, base);
+ QFETCH(ulong, result);
+ QFETCH(bool, ok);
+ QStringRef strRef = str.leftRef(-1);
+
+ bool b;
+ QCOMPARE(strRef.toULong(0, base), result);
+ QCOMPARE(strRef.toULong(&b, base), result);
+ QCOMPARE(b, ok);
+}
+
+void tst_QStringRef::toLong_data()
+{
+ QTest::addColumn<QString>("str");
+ QTest::addColumn<int>("base");
+ QTest::addColumn<long>("result");
+ QTest::addColumn<bool>("ok");
+
+ QTest::newRow("default") << QString() << 10 << 0L << false;
+ QTest::newRow("empty") << QString("") << 10 << 0L << false;
+ QTest::newRow("normal") << QString("7fFFfFFf") << 16 << 0x7fFFfFFfL << true;
+ QTest::newRow("long_max") << QString("2147483647") << 10 << 2147483647L << true;
+ if (sizeof(long) == 4) {
+ QTest::newRow("long_max+1") << QString("2147483648") << 10 << 0L << false;
+ QTest::newRow("long_min-1") << QString("-80000001") << 16 << 0L << false;
+ }
+ QTest::newRow("negative") << QString("-7fffffff") << 16 << -0x7fffffffL << true;
+// QTest::newRow("long_min") << QString("-80000000") << 16 << 0x80000000uL << true;
+}
+
+void tst_QStringRef::toLong()
+{
+ QFETCH(QString, str);
+ QFETCH(int, base);
+ QFETCH(long, result);
+ QFETCH(bool, ok);
+ QStringRef strRef = str.leftRef(-1);
+
+ bool b;
+ QCOMPARE(strRef.toLong(0, base), result);
+ QCOMPARE(strRef.toLong(&b, base), result);
+ QCOMPARE(b, ok);
+}
+
+
+////////////////////////// to*LongLong //////////////////////////////////////
+
+void tst_QStringRef::toULongLong()
+{
+ QString str;
+ QStringRef strRef;
+ bool ok;
+ str = "18446744073709551615"; // ULLONG_MAX
+ strRef = str.leftRef(-1);
+ QCOMPARE(strRef.toULongLong(0), Q_UINT64_C(18446744073709551615));
+ QCOMPARE(strRef.toULongLong(&ok), Q_UINT64_C(18446744073709551615));
+ QVERIFY(ok);
+
+ str = "18446744073709551616"; // ULLONG_MAX + 1
+ strRef = str.leftRef(-1);
+ QCOMPARE(strRef.toULongLong(0), Q_UINT64_C(0));
+ QCOMPARE(strRef.toULongLong(&ok), Q_UINT64_C(0));
+ QVERIFY(!ok);
+
+ str = "-150";
+ strRef = str.leftRef(-1);
+ QCOMPARE(strRef.toULongLong(0), Q_UINT64_C(0));
+ QCOMPARE(strRef.toULongLong(&ok), Q_UINT64_C(0));
+ QVERIFY(!ok);
+}
+
+void tst_QStringRef::toLongLong()
+{
+ QString str;
+ QStringRef strRef;
+ bool ok;
+
+ str = "9223372036854775807"; // LLONG_MAX
+ strRef = str.leftRef(-1);
+ QCOMPARE(strRef.toLongLong(0), Q_INT64_C(9223372036854775807));
+ QCOMPARE(strRef.toLongLong(&ok), Q_INT64_C(9223372036854775807));
+ QVERIFY(ok);
+
+ str = "-9223372036854775808"; // LLONG_MIN
+ strRef = str.leftRef(-1);
+ QCOMPARE(strRef.toLongLong(0),
+ -Q_INT64_C(9223372036854775807) - Q_INT64_C(1));
+ QCOMPARE(strRef.toLongLong(&ok),
+ -Q_INT64_C(9223372036854775807) - Q_INT64_C(1));
+ QVERIFY(ok);
+
+ str = "aaaa9223372036854775807aaaa";
+ strRef = str.leftRef(-1);
+ QCOMPARE(strRef.toLongLong(0), Q_INT64_C(0));
+ QCOMPARE(strRef.toLongLong(&ok), Q_INT64_C(0));
+ QVERIFY(!ok);
+
+ str = "9223372036854775807aaaa";
+ strRef = str.leftRef(-1);
+ QCOMPARE(strRef.toLongLong(0), Q_INT64_C(0));
+ QCOMPARE(strRef.toLongLong(&ok), Q_INT64_C(0));
+ QVERIFY(!ok);
+
+ str = "aaaa9223372036854775807";
+ strRef = str.leftRef(-1);
+ QCOMPARE(strRef.toLongLong(0), Q_INT64_C(0));
+ QCOMPARE(strRef.toLongLong(&ok), Q_INT64_C(0));
+ QVERIFY(!ok);
+
+ static char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+ for (int i = 0; i < 36; ++i) {
+ for (int j = 0; j < 36; ++j) {
+ for (int k = 0; k < 36; ++k) {
+ QString str;
+ str += QChar(digits[i]);
+ str += QChar(digits[j]);
+ str += QChar(digits[k]);
+ strRef = str.leftRef(-1);
+ qlonglong value = (((i * 36) + j) * 36) + k;
+ QVERIFY(strRef.toLongLong(0, 36) == value);
+ }
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////
+
+void tst_QStringRef::toFloat()
+{
+ QString a;
+ QStringRef b;
+ bool ok;
+ a = "0.000000000931322574615478515625";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toFloat(&ok), float(0.000000000931322574615478515625));
+ QVERIFY(ok);
+}
+
+void tst_QStringRef::toDouble_data()
+{
+ QTest::addColumn<QString>("str");
+ QTest::addColumn<double>("result");
+ QTest::addColumn<bool>("result_ok");
+
+ QTest::newRow("ok00") << QString("0.000000000931322574615478515625") << 0.000000000931322574615478515625 << true;
+ QTest::newRow("ok01") << QString(" 123.45") << 123.45 << true;
+
+ QTest::newRow("ok02") << QString("0.1e10") << 0.1e10 << true;
+ QTest::newRow("ok03") << QString("0.1e-10") << 0.1e-10 << true;
+
+ QTest::newRow("ok04") << QString("1e10") << 1.0e10 << true;
+ QTest::newRow("ok05") << QString("1e+10") << 1.0e10 << true;
+ QTest::newRow("ok06") << QString("1e-10") << 1.0e-10 << true;
+
+ QTest::newRow("ok07") << QString(" 1e10") << 1.0e10 << true;
+ QTest::newRow("ok08") << QString(" 1e+10") << 1.0e10 << true;
+ QTest::newRow("ok09") << QString(" 1e-10") << 1.0e-10 << true;
+
+ QTest::newRow("ok10") << QString("1.") << 1.0 << true;
+ QTest::newRow("ok11") << QString(".1") << 0.1 << true;
+
+ QTest::newRow("wrong00") << QString("123.45 ") << 123.45 << true;
+ QTest::newRow("wrong01") << QString(" 123.45 ") << 123.45 << true;
+
+ QTest::newRow("wrong02") << QString("aa123.45aa") << 0.0 << false;
+ QTest::newRow("wrong03") << QString("123.45aa") << 0.0 << false;
+ QTest::newRow("wrong04") << QString("123erf") << 0.0 << false;
+
+ QTest::newRow("wrong05") << QString("abc") << 0.0 << false;
+ QTest::newRow("wrong06") << QString() << 0.0 << false;
+ QTest::newRow("wrong07") << QString("") << 0.0 << false;
+}
+
+void tst_QStringRef::toDouble()
+{
+ QFETCH(QString, str);
+ QFETCH(bool, result_ok);
+ QStringRef strRef = str.leftRef(-1);
+ bool ok;
+ double d = strRef.toDouble(&ok);
+ if (result_ok) {
+ QTEST(d, "result");
+ QVERIFY(ok);
+ } else {
+ QVERIFY(!ok);
+ }
+}
+
+void tst_QStringRef::integer_conversion_data()
+{
+ QTest::addColumn<QString>("num_str");
+ QTest::addColumn<int>("base");
+ QTest::addColumn<bool>("good");
+ QTest::addColumn<qlonglong>("num");
+
+ QTest::newRow("C empty 0") << QString("") << 0 << false << (qlonglong)0;
+ QTest::newRow("C empty 8") << QString("") << 8 << false << (qlonglong)0;
+ QTest::newRow("C empty 10") << QString("") << 10 << false << (qlonglong)0;
+ QTest::newRow("C empty 16") << QString("") << 16 << false << (qlonglong)0;
+
+ QTest::newRow("C null 0") << QString() << 0 << false << (qlonglong)0;
+ QTest::newRow("C null 8") << QString() << 8 << false << (qlonglong)0;
+ QTest::newRow("C null 10") << QString() << 10 << false << (qlonglong)0;
+ QTest::newRow("C null 16") << QString() << 16 << false << (qlonglong)0;
+
+ QTest::newRow("C -0xf 0") << QString(" -0xf") << 0 << true << (qlonglong)-15;
+ QTest::newRow("C -0xf 0") << QString("-0xf ") << 0 << true << (qlonglong)-15;
+ QTest::newRow("C \t0xf\t 0") << QString("\t0xf\t") << 0 << true << (qlonglong)15;
+ QTest::newRow("C -010 0") << QString(" -010") << 0 << true << (qlonglong)-8;
+ QTest::newRow("C 010 0") << QString("010 ") << 0 << true << (qlonglong)8;
+ QTest::newRow("C \t-010\t 0") << QString("\t-010\t") << 0 << true << (qlonglong)-8;
+ QTest::newRow("C 123 10") << QString(" 123") << 10 << true << (qlonglong)123;
+ QTest::newRow("C 123 10") << QString("123 ") << 10 << true << (qlonglong)123;
+ QTest::newRow("C \t123\t 10") << QString("\t123\t") << 10 << true << (qlonglong)123;
+ QTest::newRow("C -0xf 16") << QString(" -0xf") << 16 << true << (qlonglong)-15;
+ QTest::newRow("C -0xf 16") << QString("-0xf ") << 16 << true << (qlonglong)-15;
+ QTest::newRow("C \t0xf\t 16") << QString("\t0xf\t") << 16 << true << (qlonglong)15;
+
+ QTest::newRow("C -0 0") << QString("-0") << 0 << true << (qlonglong)0;
+ QTest::newRow("C -0 8") << QString("-0") << 8 << true << (qlonglong)0;
+ QTest::newRow("C -0 10") << QString("-0") << 10 << true << (qlonglong)0;
+ QTest::newRow("C -0 16") << QString("-0") << 16 << true << (qlonglong)0;
+
+ QTest::newRow("C 1.234 10") << QString("1.234") << 10 << false << (qlonglong)0;
+ QTest::newRow("C 1,234 10") << QString("1,234") << 10 << false << (qlonglong)0;
+
+ QTest::newRow("C 0x 0") << QString("0x") << 0 << false << (qlonglong)0;
+ QTest::newRow("C 0x 16") << QString("0x") << 16 << false << (qlonglong)0;
+
+ QTest::newRow("C 10 0") << QString("10") << 0 << true << (qlonglong)10;
+ QTest::newRow("C 010 0") << QString("010") << 0 << true << (qlonglong)8;
+ QTest::newRow("C 0x10 0") << QString("0x10") << 0 << true << (qlonglong)16;
+ QTest::newRow("C 10 8") << QString("10") << 8 << true << (qlonglong)8;
+ QTest::newRow("C 010 8") << QString("010") << 8 << true << (qlonglong)8;
+ QTest::newRow("C 0x10 8") << QString("0x10") << 8 << false << (qlonglong)0;
+ QTest::newRow("C 10 10") << QString("10") << 10 << true << (qlonglong)10;
+ QTest::newRow("C 010 10") << QString("010") << 10 << true << (qlonglong)10;
+ QTest::newRow("C 0x10 10") << QString("0x10") << 10 << false << (qlonglong)0;
+ QTest::newRow("C 10 16") << QString("10") << 16 << true << (qlonglong)16;
+ QTest::newRow("C 010 16") << QString("010") << 16 << true << (qlonglong)16;
+ QTest::newRow("C 0x10 16") << QString("0x10") << 16 << true << (qlonglong)16;
+
+ QTest::newRow("C -10 0") << QString("-10") << 0 << true << (qlonglong)-10;
+ QTest::newRow("C -010 0") << QString("-010") << 0 << true << (qlonglong)-8;
+ QTest::newRow("C -0x10 0") << QString("-0x10") << 0 << true << (qlonglong)-16;
+ QTest::newRow("C -10 8") << QString("-10") << 8 << true << (qlonglong)-8;
+ QTest::newRow("C -010 8") << QString("-010") << 8 << true << (qlonglong)-8;
+ QTest::newRow("C -0x10 8") << QString("-0x10") << 8 << false << (qlonglong)0;
+ QTest::newRow("C -10 10") << QString("-10") << 10 << true << (qlonglong)-10;
+ QTest::newRow("C -010 10") << QString("-010") << 10 << true << (qlonglong)-10;
+ QTest::newRow("C -0x10 10") << QString("-0x10") << 10 << false << (qlonglong)0;
+ QTest::newRow("C -10 16") << QString("-10") << 16 << true << (qlonglong)-16;
+ QTest::newRow("C -010 16") << QString("-010") << 16 << true << (qlonglong)-16;
+ QTest::newRow("C -0x10 16") << QString("-0x10") << 16 << true << (qlonglong)-16;
+
+ // Let's try some Arabic
+ const quint16 arabic_str[] = { 0x0661, 0x0662, 0x0663, 0x0664, 0x0000 }; // "1234"
+ QTest::newRow("ar_SA 1234 0") << QString::fromUtf16(arabic_str) << 0 << false << (qlonglong)0;
+}
+
+void tst_QStringRef::integer_conversion()
+{
+ QFETCH(QString, num_str);
+ QFETCH(int, base);
+ QFETCH(bool, good);
+ QFETCH(qlonglong, num);
+ QStringRef num_strRef = num_str.leftRef(-1);
+
+ bool ok;
+ qlonglong d = num_strRef.toLongLong(&ok, base);
+ QCOMPARE(ok, good);
+
+ if (ok) {
+ QCOMPARE(d, num);
+ }
+}
+
+void tst_QStringRef::double_conversion_data()
+{
+ QTest::addColumn<QString>("num_str");
+ QTest::addColumn<bool>("good");
+ QTest::addColumn<double>("num");
+
+ // The good...
+
+ QTest::newRow("C 1") << QString("1") << true << 1.0;
+ QTest::newRow("C 1.0") << QString("1.0") << true << 1.0;
+ QTest::newRow("C 1.234") << QString("1.234") << true << 1.234;
+ QTest::newRow("C 1.234e-10") << QString("1.234e-10") << true << 1.234e-10;
+ QTest::newRow("C 1.234E10") << QString("1.234E10") << true << 1.234e10;
+ QTest::newRow("C 1e10") << QString("1e10") << true << 1.0e10;
+
+ // The bad...
+
+ QTest::newRow("C empty") << QString("") << false << 0.0;
+ QTest::newRow("C null") << QString() << false << 0.0;
+ QTest::newRow("C .") << QString(".") << false << 0.0;
+ QTest::newRow("C 1e") << QString("1e") << false << 0.0;
+ QTest::newRow("C 1,") << QString("1,") << false << 0.0;
+ QTest::newRow("C 1,0") << QString("1,0") << false << 0.0;
+ QTest::newRow("C 1,000") << QString("1,000") << false << 0.0;
+ QTest::newRow("C 1e1.0") << QString("1e1.0") << false << 0.0;
+ QTest::newRow("C 1e+") << QString("1e+") << false << 0.0;
+ QTest::newRow("C 1e-") << QString("1e-") << false << 0.0;
+ QTest::newRow("de_DE 1,0") << QString("1,0") << false << 0.0;
+ QTest::newRow("de_DE 1,234") << QString("1,234") << false << 0.0;
+ QTest::newRow("de_DE 1,234e-10") << QString("1,234e-10") << false << 0.0;
+ QTest::newRow("de_DE 1,234E10") << QString("1,234E10") << false << 0.0;
+
+ // And the ugly...
+
+ QTest::newRow("C .1") << QString(".1") << true << 0.1;
+ QTest::newRow("C -.1") << QString("-.1") << true << -0.1;
+ QTest::newRow("C 1.") << QString("1.") << true << 1.0;
+ QTest::newRow("C 1.E10") << QString("1.E10") << true << 1.0e10;
+ QTest::newRow("C 1e+10") << QString("1e+10") << true << 1.0e+10;
+ QTest::newRow("C 1") << QString(" 1") << true << 1.0;
+ QTest::newRow("C 1 ") << QString("1 ") << true << 1.0;
+
+ // Let's try some Arabic
+ const quint16 arabic_str[] = { 0x0660, 0x066B, 0x0661, 0x0662,
+ 0x0663, 0x0664, 0x0065, 0x0662,
+ 0x0000 }; // "0.1234e2"
+ QTest::newRow("ar_SA") << QString::fromUtf16(arabic_str) << false << 0.0;
+}
+
+void tst_QStringRef::double_conversion()
+{
+#define MY_DOUBLE_EPSILON (2.22045e-16)
+
+ QFETCH(QString, num_str);
+ QFETCH(bool, good);
+ QFETCH(double, num);
+ QStringRef num_strRef = num_str.leftRef(-1);
+
+ bool ok;
+ double d = num_strRef.toDouble(&ok);
+ QCOMPARE(ok, good);
+
+ if (ok) {
+ double diff = d - num;
+ if (diff < 0)
+ diff = -diff;
+ QVERIFY(diff <= MY_DOUBLE_EPSILON);
+ }
+}
+
+void tst_QStringRef::trimmed()
+{
+ QString a;
+ QStringRef b;
+ a = "Text";
+ b = a.leftRef(-1);
+ QCOMPARE(b.compare(QStringLiteral("Text")), 0);
+ QCOMPARE(b.trimmed().compare(QStringLiteral("Text")), 0);
+ a = " ";
+ b = a.leftRef(-1);
+ QCOMPARE(b.compare(QStringLiteral(" ")), 0);
+ QCOMPARE(b.trimmed().compare(QStringLiteral("")), 0);
+ a = " a ";
+ b = a.leftRef(-1);
+ QCOMPARE(b.trimmed().compare(QStringLiteral("a")), 0);
+ a = "Text a ";
+ b = a.midRef(4);
+ QCOMPARE(b.compare(QStringLiteral(" a ")), 0);
+ QCOMPARE(b.trimmed().compare(QStringLiteral("a")), 0);
+}
+
QTEST_APPLESS_MAIN(tst_QStringRef)
#include "tst_qstringref.moc"
diff --git a/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp b/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp
index 4d05f45252..e6629301f9 100644
--- a/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp
+++ b/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp
@@ -69,6 +69,7 @@ private slots:
void stateInFinishedSignal();
void resume();
void restart();
+ void setPaused();
protected slots:
void finishedSlot();
@@ -681,6 +682,28 @@ void tst_QTimeLine::restart()
QCOMPARE(timeLine.currentTime(), 0);
}
+void tst_QTimeLine::setPaused()
+{
+ QTimeLine timeLine(1000);
+ {
+ QCOMPARE(timeLine.currentTime(), 0);
+ timeLine.start();
+ QTest::qWait(250);
+ timeLine.setPaused(true);
+ int oldCurrentTime = timeLine.currentTime();
+ QVERIFY(oldCurrentTime > 0);
+ QVERIFY(oldCurrentTime < 1000);
+ QTest::qWait(1000);
+ timeLine.setPaused(false);
+ QTest::qWait(250);
+ int currentTime = timeLine.currentTime();
+ QVERIFY(currentTime > 0);
+ QVERIFY(currentTime > oldCurrentTime);
+ QVERIFY(currentTime < 1000);
+ timeLine.stop();
+ }
+}
+
QTEST_MAIN(tst_QTimeLine)
#include "tst_qtimeline.moc"
diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
index bda3a2596f..c19080e345 100644
--- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
+++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
@@ -58,6 +58,7 @@ private slots:
void count();
void first();
void last();
+ void squeeze();
};
int fooCtor = 0;
@@ -653,5 +654,28 @@ void tst_QVarLengthArray::last()
QCOMPARE(list.length(), 1);
}
+void tst_QVarLengthArray::squeeze()
+{
+ QVarLengthArray<int> list;
+ int sizeOnStack = list.capacity();
+ int sizeOnHeap = sizeOnStack * 2;
+ list.resize(0);
+ QCOMPARE(list.capacity(), sizeOnStack);
+ list.resize(sizeOnHeap);
+ QCOMPARE(list.capacity(), sizeOnHeap);
+ list.resize(sizeOnStack);
+ QCOMPARE(list.capacity(), sizeOnHeap);
+ list.resize(0);
+ QCOMPARE(list.capacity(), sizeOnHeap);
+ list.squeeze();
+ QCOMPARE(list.capacity(), sizeOnStack);
+ list.resize(sizeOnStack);
+ list.squeeze();
+ QCOMPARE(list.capacity(), sizeOnStack);
+ list.resize(sizeOnHeap);
+ list.squeeze();
+ QCOMPARE(list.capacity(), sizeOnHeap);
+}
+
QTEST_APPLESS_MAIN(tst_QVarLengthArray)
#include "tst_qvarlengtharray.moc"
diff --git a/tests/auto/corelib/tools/qvector/tst_qvector.cpp b/tests/auto/corelib/tools/qvector/tst_qvector.cpp
index 7738a2c797..53caec4a64 100644
--- a/tests/auto/corelib/tools/qvector/tst_qvector.cpp
+++ b/tests/auto/corelib/tools/qvector/tst_qvector.cpp
@@ -236,6 +236,7 @@ private slots:
void removeInt() const;
void removeMovable() const;
void removeCustom() const;
+ void removeFirstLast() const;
void resizePOD_data() const;
void resizePOD() const;
void resizeComplexMovable_data() const;
@@ -1393,6 +1394,103 @@ void tst_QVector::removeCustom() const
QCOMPARE(instancesCount, Custom::counter.loadAcquire());
}
+struct RemoveLastTestClass
+{
+ RemoveLastTestClass() { other = 0; deleted = false; }
+ RemoveLastTestClass *other;
+ bool deleted;
+ ~RemoveLastTestClass()
+ {
+ deleted = true;
+ if (other)
+ other->other = 0;
+ }
+};
+
+void tst_QVector::removeFirstLast() const
+{
+ // pop_pack - pop_front
+ QVector<int> t, t2;
+ t.append(1);
+ t.append(2);
+ t.append(3);
+ t.append(4);
+ t2 = t;
+ t.pop_front();
+ QCOMPARE(t.size(), 3);
+ QCOMPARE(t.at(0), 2);
+ t.pop_back();
+ QCOMPARE(t.size(), 2);
+ QCOMPARE(t.at(0), 2);
+ QCOMPARE(t.at(1), 3);
+
+ // takefirst - takeLast
+ int n1 = t2.takeLast();
+ QCOMPARE(t2.size(), 3);
+ QCOMPARE(n1, 4);
+ QCOMPARE(t2.at(0), 1);
+ QCOMPARE(t2.at(2), 3);
+ n1 = t2.takeFirst();
+ QCOMPARE(t2.size(), 2);
+ QCOMPARE(n1, 1);
+ QCOMPARE(t2.at(0), 2);
+ QCOMPARE(t2.at(1), 3);
+
+ // remove first
+ QVector<int> x, y;
+ x.append(1);
+ x.append(2);
+ y = x;
+ x.removeFirst();
+ QCOMPARE(x.size(), 1);
+ QCOMPARE(y.size(), 2);
+ QCOMPARE(x.at(0), 2);
+
+ // remove Last
+ QVector<RemoveLastTestClass> v;
+ v.resize(2);
+ v[0].other = &(v[1]);
+ v[1].other = &(v[0]);
+ // Check dtor - complex type
+ QVERIFY(v.at(0).other != 0);
+ v.removeLast();
+ QVERIFY(v.at(0).other == 0);
+ QCOMPARE(v.at(0).deleted, false);
+ // check iterator
+ int count = 0;
+ for (QVector<RemoveLastTestClass>::const_iterator i = v.constBegin(); i != v.constEnd(); ++i) {
+ ++count;
+ QVERIFY(i->other == 0);
+ QCOMPARE(i->deleted, false);
+ }
+ // Check size
+ QCOMPARE(count, 1);
+ QCOMPARE(v.size(), 1);
+ v.removeLast();
+ QCOMPARE(v.size(), 0);
+ // Check if we do correct realloc
+ QVector<int> v2, v3;
+ v2.append(1);
+ v2.append(2);
+ v3 = v2; // shared
+ v2.removeLast();
+ QCOMPARE(v2.size(), 1);
+ QCOMPARE(v3.size(), 2);
+ QCOMPARE(v2.at(0), 1);
+ QCOMPARE(v3.at(0), 1);
+ QCOMPARE(v3.at(1), 2);
+
+ // Remove last with shared
+ QVector<int> z1, z2;
+ z1.append(9);
+ z2 = z1;
+ z1.removeLast();
+ QCOMPARE(z1.size(), 0);
+ QCOMPARE(z2.size(), 1);
+ QCOMPARE(z2.at(0), 9);
+}
+
+
void tst_QVector::resizePOD_data() const
{
QTest::addColumn<QVector<int> >("vector");
diff --git a/tests/auto/corelib/tools/tools.pro b/tests/auto/corelib/tools/tools.pro
index 100409e58b..f8b2437d35 100644
--- a/tests/auto/corelib/tools/tools.pro
+++ b/tests/auto/corelib/tools/tools.pro
@@ -22,6 +22,7 @@ SUBDIRS=\
qlocale \
qmap \
qmargins \
+ qmessageauthenticationcode \
qpair \
qpoint \
qpointf \