summaryrefslogtreecommitdiffstats
path: root/tests/auto/qscriptstring/tst_qscriptstring.cpp
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar@trolltech.com>2009-11-03 11:52:16 (GMT)
committerGunnar Sletta <gunnar@trolltech.com>2009-11-03 11:52:16 (GMT)
commit2e02518498379fc691a27ec96ae182aff436a38d (patch)
tree1ed6ce158c8de6507b36ae2b70133edbc6beca5d /tests/auto/qscriptstring/tst_qscriptstring.cpp
parentfc4a3206fd89d28c0b0c6c36fa0c136a65e2e057 (diff)
parent9fab0ede200960f0dbec1457757a6ba3214c3ce6 (diff)
downloadQt-2e02518498379fc691a27ec96ae182aff436a38d.zip
Qt-2e02518498379fc691a27ec96ae182aff436a38d.tar.gz
Qt-2e02518498379fc691a27ec96ae182aff436a38d.tar.bz2
Merge branch '4.6' of git@scm.dev.nokia.troll.no:qt/qt into 4.6
Diffstat (limited to 'tests/auto/qscriptstring/tst_qscriptstring.cpp')
-rw-r--r--tests/auto/qscriptstring/tst_qscriptstring.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/qscriptstring/tst_qscriptstring.cpp b/tests/auto/qscriptstring/tst_qscriptstring.cpp
index e1a4bc1..1229f4a 100644
--- a/tests/auto/qscriptstring/tst_qscriptstring.cpp
+++ b/tests/auto/qscriptstring/tst_qscriptstring.cpp
@@ -59,6 +59,8 @@ public:
private slots:
void test();
void hash();
+ void toArrayIndex_data();
+ void toArrayIndex();
};
tst_QScriptString::tst_QScriptString()
@@ -155,5 +157,40 @@ void tst_QScriptString::hash()
QCOMPARE(stringToInt.value(foo), 123);
}
+void tst_QScriptString::toArrayIndex_data()
+{
+ QTest::addColumn<QString>("input");
+ QTest::addColumn<bool>("expectSuccess");
+ QTest::addColumn<quint32>("expectedIndex");
+ QTest::newRow("foo") << QString::fromLatin1("foo") << false << quint32(0xffffffff);
+ QTest::newRow("empty") << QString::fromLatin1("") << false << quint32(0xffffffff);
+ QTest::newRow("0") << QString::fromLatin1("0") << true << quint32(0);
+ QTest::newRow("00") << QString::fromLatin1("00") << false << quint32(0xffffffff);
+ QTest::newRow("1") << QString::fromLatin1("1") << true << quint32(1);
+ QTest::newRow("123") << QString::fromLatin1("123") << true << quint32(123);
+ QTest::newRow("-1") << QString::fromLatin1("-1") << false << quint32(0xffffffff);
+ QTest::newRow("0a") << QString::fromLatin1("0a") << false << quint32(0xffffffff);
+ QTest::newRow("0x1") << QString::fromLatin1("0x1") << false << quint32(0xffffffff);
+ QTest::newRow("01") << QString::fromLatin1("01") << false << quint32(0xffffffff);
+ QTest::newRow("4294967294") << QString::fromLatin1("4294967294") << true << quint32(0xfffffffe);
+ QTest::newRow("4294967295") << QString::fromLatin1("4294967295") << false << quint32(0xffffffff);
+}
+
+void tst_QScriptString::toArrayIndex()
+{
+ QFETCH(QString, input);
+ QFETCH(bool, expectSuccess);
+ QFETCH(quint32, expectedIndex);
+ QScriptEngine engine;
+ for (int x = 0; x < 2; ++x) {
+ bool isArrayIndex;
+ bool *ptr = (x == 0) ? &isArrayIndex : (bool*)0;
+ quint32 result = engine.toStringHandle(input).toArrayIndex(ptr);
+ if (x == 0)
+ QCOMPARE(isArrayIndex, expectSuccess);
+ QCOMPARE(result, expectedIndex);
+ }
+}
+
QTEST_MAIN(tst_QScriptString)
#include "tst_qscriptstring.moc"