tests/auto/qscriptstring/tst_qscriptstring.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
child 7 f7bc934e204c
child 18 2f34d5167611
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    57     virtual ~tst_QScriptString();
    57     virtual ~tst_QScriptString();
    58 
    58 
    59 private slots:
    59 private slots:
    60     void test();
    60     void test();
    61     void hash();
    61     void hash();
       
    62     void toArrayIndex_data();
       
    63     void toArrayIndex();
    62 };
    64 };
    63 
    65 
    64 tst_QScriptString::tst_QScriptString()
    66 tst_QScriptString::tst_QScriptString()
    65 {
    67 {
    66 }
    68 }
   153     stringToInt.insert(bar, 456);
   155     stringToInt.insert(bar, 456);
   154     QCOMPARE(stringToInt.value(bar), 456);
   156     QCOMPARE(stringToInt.value(bar), 456);
   155     QCOMPARE(stringToInt.value(foo), 123);
   157     QCOMPARE(stringToInt.value(foo), 123);
   156 }
   158 }
   157 
   159 
       
   160 void tst_QScriptString::toArrayIndex_data()
       
   161 {
       
   162     QTest::addColumn<QString>("input");
       
   163     QTest::addColumn<bool>("expectSuccess");
       
   164     QTest::addColumn<quint32>("expectedIndex");
       
   165     QTest::newRow("foo") << QString::fromLatin1("foo") << false << quint32(0xffffffff);
       
   166     QTest::newRow("empty") << QString::fromLatin1("") << false << quint32(0xffffffff);
       
   167     QTest::newRow("0") << QString::fromLatin1("0") << true << quint32(0);
       
   168     QTest::newRow("00") << QString::fromLatin1("00") << false << quint32(0xffffffff);
       
   169     QTest::newRow("1") << QString::fromLatin1("1") << true << quint32(1);
       
   170     QTest::newRow("123") << QString::fromLatin1("123") << true << quint32(123);
       
   171     QTest::newRow("-1") << QString::fromLatin1("-1") << false << quint32(0xffffffff);
       
   172     QTest::newRow("0a") << QString::fromLatin1("0a") << false << quint32(0xffffffff);
       
   173     QTest::newRow("0x1") << QString::fromLatin1("0x1") << false << quint32(0xffffffff);
       
   174     QTest::newRow("01") << QString::fromLatin1("01") << false << quint32(0xffffffff);
       
   175     QTest::newRow("4294967294") << QString::fromLatin1("4294967294") << true << quint32(0xfffffffe);
       
   176     QTest::newRow("4294967295") << QString::fromLatin1("4294967295") << false << quint32(0xffffffff);
       
   177 }
       
   178 
       
   179 void tst_QScriptString::toArrayIndex()
       
   180 {
       
   181     QFETCH(QString, input);
       
   182     QFETCH(bool, expectSuccess);
       
   183     QFETCH(quint32, expectedIndex);
       
   184     QScriptEngine engine;
       
   185     for (int x = 0; x < 2; ++x) {
       
   186         bool isArrayIndex;
       
   187         bool *ptr = (x == 0) ? &isArrayIndex : (bool*)0;
       
   188         quint32 result = engine.toStringHandle(input).toArrayIndex(ptr);
       
   189         if (x == 0)
       
   190             QCOMPARE(isArrayIndex, expectSuccess);
       
   191         QCOMPARE(result, expectedIndex);
       
   192     }
       
   193 }
       
   194 
   158 QTEST_MAIN(tst_QScriptString)
   195 QTEST_MAIN(tst_QScriptString)
   159 #include "tst_qscriptstring.moc"
   196 #include "tst_qscriptstring.moc"