diff options
author | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2012-05-10 11:26:05 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-10 12:34:42 +0200 |
commit | 58f53b807fafcadf76282f0c8c7f20451c7a97a5 (patch) | |
tree | 01522c659562d19a0232b977f955ead7d6c057cb /tests | |
parent | 406402dc639db7f5d785961717326467026fb6f1 (diff) | |
download | qtscript-58f53b807fafcadf76282f0c8c7f20451c7a97a5.tar.gz |
Remove large, static QString[] arrays from test qscriptvaluegenerated.
They seems to trigger a compiler error for linux-arm-gnueabi-g++
(32bit).
Use const char *-arrays and introduce utility functions
to populate the static hashes, sets. Fix some string and iterator
usage errors.
Change-Id: I4e32c6ffa004e141bc04c3a2971c379f71072b38
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
Diffstat (limited to 'tests')
5 files changed, 173 insertions, 263 deletions
diff --git a/tests/auto/qscriptvaluegenerated/tst_qscriptvalue.h b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue.h index 182e836..301d51a 100644 --- a/tests/auto/qscriptvaluegenerated/tst_qscriptvalue.h +++ b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue.h @@ -363,6 +363,34 @@ private: QString m_currentExpression; }; +static inline QSet<QString> charArrayToQStringSet(const char **array, int size) +{ + QSet<QString> result; + result.reserve(size); + for (int i = 0; i < size; ++i) + result.insert(QLatin1String(array[i])); + return result; +} + +static inline QHash<QString, QString> charArraysToStringHash(const char **keys, const char **values, int size) +{ + QHash<QString, QString > result; + result.reserve(size); + for (int i = 0; i < size; ++i) + result.insert(QLatin1String(keys[i]), QLatin1String(values[i])); + return result; +} + +template <class Value> +QHash<QString, Value> charValueArraysToHash(const char **keys, const Value *values, int size) +{ + QHash<QString, Value> result; + result.reserve(size); + for (int i = 0; i < size; ++i) + result.insert(QLatin1String(keys[i]), values[i]); + return result; +} + #define DEFINE_TEST_FUNCTION(name) \ void tst_QScriptValueGenerated::name##_data() { dataHelper(&tst_QScriptValueGenerated::name##_initData, &tst_QScriptValueGenerated::name##_makeData); } \ void tst_QScriptValueGenerated::name() { testHelper(&tst_QScriptValueGenerated::name##_test); } diff --git a/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_cast.cpp b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_cast.cpp index f64b8cc..47eab4b 100644 --- a/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_cast.cpp +++ b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_cast.cpp @@ -53,7 +53,7 @@ void tst_QScriptValueGenerated::qscriptvalue_castQString_initData() initScriptValues(); } -static QString qscriptvalue_castQString_tagArray[] = { +static const char *qscriptvalue_castQString_tagArray[] = { "QScriptValue()", "QScriptValue(QScriptValue::UndefinedValue)", "QScriptValue(QScriptValue::NullValue)", @@ -202,7 +202,7 @@ static QString qscriptvalue_castQString_tagArray[] = { "engine->newVariant(QVariant(false))", "engine->newQObject(0)", "engine->newQObject(engine)"}; -static QString qscriptvalue_castQString_valueArray[] = { +static const char *qscriptvalue_castQString_valueArray[] = { "", "", "", "true", "false", "122", @@ -279,13 +279,10 @@ static QString qscriptvalue_castQString_valueArray[] = { "", "QScriptEngine(name = \"\")"}; void tst_QScriptValueGenerated::qscriptvalue_castQString_makeData(const char* expr) { - static QHash<QString, QString> value; - if (value.isEmpty()) { - value.reserve(148); - for (unsigned i = 0; i < 148; ++i) - value.insert(qscriptvalue_castQString_tagArray[i], qscriptvalue_castQString_valueArray[i]); - } - newRow(expr) << value.value(expr); + static const QHash<QString, QString> valueMap = + charArraysToStringHash(qscriptvalue_castQString_tagArray, qscriptvalue_castQString_valueArray, + int(sizeof(qscriptvalue_castQString_tagArray) / sizeof(const char *))); + newRow(expr) << valueMap.value(expr); } void tst_QScriptValueGenerated::qscriptvalue_castQString_test(const char*, const QScriptValue& value) @@ -304,7 +301,7 @@ void tst_QScriptValueGenerated::qscriptvalue_castqsreal_initData() initScriptValues(); } -static QString qscriptvalue_castqsreal_tagArray[] = { +static const char *qscriptvalue_castqsreal_tagArray[] = { "QScriptValue()", "QScriptValue(QScriptValue::UndefinedValue)", "QScriptValue(QScriptValue::NullValue)", @@ -471,12 +468,9 @@ static qsreal qscriptvalue_castqsreal_valueArray[] = { qQNaN(), qQNaN(), qQNaN(), qQNaN(), 123, 0, 0, qQNaN()}; void tst_QScriptValueGenerated::qscriptvalue_castqsreal_makeData(const char* expr) { - static QHash<QString, qsreal> value; - if (value.isEmpty()) { - value.reserve(148); - for (unsigned i = 0; i < 148; ++i) - value.insert(qscriptvalue_castqsreal_tagArray[i], qscriptvalue_castqsreal_valueArray[i]); - } + static const QHash<QString, qsreal> value = + charValueArraysToHash(qscriptvalue_castqsreal_tagArray, qscriptvalue_castqsreal_valueArray, + int(sizeof(qscriptvalue_castqsreal_tagArray) / sizeof(const char *))); newRow(expr) << value.value(expr); } @@ -506,7 +500,7 @@ void tst_QScriptValueGenerated::qscriptvalue_castbool_initData() initScriptValues(); } -static QString qscriptvalue_castbool_tagArray[] = { +static const char *qscriptvalue_castbool_tagArray[] = { "QScriptValue()", "QScriptValue(QScriptValue::UndefinedValue)", "QScriptValue(QScriptValue::NullValue)", @@ -732,12 +726,9 @@ static bool qscriptvalue_castbool_valueArray[] = { false, true}; void tst_QScriptValueGenerated::qscriptvalue_castbool_makeData(const char* expr) { - static QHash<QString, bool> value; - if (value.isEmpty()) { - value.reserve(148); - for (unsigned i = 0; i < 148; ++i) - value.insert(qscriptvalue_castbool_tagArray[i], qscriptvalue_castbool_valueArray[i]); - } + static const QHash<QString, bool> value = + charValueArraysToHash(qscriptvalue_castbool_tagArray, qscriptvalue_castbool_valueArray, + int(sizeof(qscriptvalue_castqsreal_tagArray) / sizeof(const char *))); newRow(expr) << value.value(expr); } @@ -757,7 +748,7 @@ void tst_QScriptValueGenerated::qscriptvalue_castqint32_initData() initScriptValues(); } -static QString qscriptvalue_castqint32_tagArray[] = { +static const char *qscriptvalue_castqint32_tagArray[] = { "QScriptValue()", "QScriptValue(QScriptValue::UndefinedValue)", "QScriptValue(QScriptValue::NullValue)", @@ -983,12 +974,9 @@ static qint32 qscriptvalue_castqint32_valueArray[] = { 0, 0}; void tst_QScriptValueGenerated::qscriptvalue_castqint32_makeData(const char* expr) { - static QHash<QString, qint32> value; - if (value.isEmpty()) { - value.reserve(148); - for (unsigned i = 0; i < 148; ++i) - value.insert(qscriptvalue_castqint32_tagArray[i], qscriptvalue_castqint32_valueArray[i]); - } + static const QHash<QString, qint32> value = + charValueArraysToHash(qscriptvalue_castqint32_tagArray, qscriptvalue_castqint32_valueArray, + int(sizeof(qscriptvalue_castqint32_tagArray) / sizeof(const char *))); newRow(expr) << value.value(expr); } @@ -1008,7 +996,7 @@ void tst_QScriptValueGenerated::qscriptvalue_castquint32_initData() initScriptValues(); } -static QString qscriptvalue_castquint32_tagArray[] = { +static const char *qscriptvalue_castquint32_tagArray[] = { "QScriptValue()", "QScriptValue(QScriptValue::UndefinedValue)", "QScriptValue(QScriptValue::NullValue)", @@ -1234,12 +1222,9 @@ static quint32 qscriptvalue_castquint32_valueArray[] = { 0, 0}; void tst_QScriptValueGenerated::qscriptvalue_castquint32_makeData(const char* expr) { - static QHash<QString, quint32> value; - if (value.isEmpty()) { - value.reserve(148); - for (unsigned i = 0; i < 148; ++i) - value.insert(qscriptvalue_castquint32_tagArray[i], qscriptvalue_castquint32_valueArray[i]); - } + static const QHash<QString, quint32> value = + charValueArraysToHash(qscriptvalue_castquint32_tagArray, qscriptvalue_castquint32_valueArray, + int(sizeof(qscriptvalue_castquint32_tagArray) / sizeof(const char *))); newRow(expr) << value.value(expr); } @@ -1259,7 +1244,7 @@ void tst_QScriptValueGenerated::qscriptvalue_castquint16_initData() initScriptValues(); } -static QString qscriptvalue_castquint16_tagArray[] = { +static const char *qscriptvalue_castquint16_tagArray[] = { "QScriptValue()", "QScriptValue(QScriptValue::UndefinedValue)", "QScriptValue(QScriptValue::NullValue)", @@ -1485,12 +1470,9 @@ static quint16 qscriptvalue_castquint16_valueArray[] = { 0, 0}; void tst_QScriptValueGenerated::qscriptvalue_castquint16_makeData(const char* expr) { - static QHash<QString, quint16> value; - if (value.isEmpty()) { - value.reserve(148); - for (unsigned i = 0; i < 148; ++i) - value.insert(qscriptvalue_castquint16_tagArray[i], qscriptvalue_castquint16_valueArray[i]); - } + static const QHash<QString, quint16> value = + charValueArraysToHash(qscriptvalue_castquint16_tagArray, qscriptvalue_castquint16_valueArray, + int(sizeof(qscriptvalue_castquint16_tagArray) / sizeof(const char *))); newRow(expr) << value.value(expr); } diff --git a/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_comparison.cpp b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_comparison.cpp index d426886..d983d0d 100644 --- a/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_comparison.cpp +++ b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_comparison.cpp @@ -54,7 +54,7 @@ void tst_QScriptValueGenerated::equals_initData() initScriptValues(); } -static QString equals_array[] = { +static const char *equals_array[] = { "QScriptValue() <=> QScriptValue()", "QScriptValue(QScriptValue::UndefinedValue) <=> QScriptValue(QScriptValue::UndefinedValue)", "QScriptValue(QScriptValue::UndefinedValue) <=> QScriptValue(QScriptValue::NullValue)", @@ -1363,17 +1363,16 @@ static QString equals_array[] = { "engine->newQObject(0) <=> engine->newQObject(0)", "engine->newQObject(engine) <=> engine->newQObject(engine)"}; -void tst_QScriptValueGenerated::equals_makeData(const char *expr) +void tst_QScriptValueGenerated::equals_makeData(const char *exprC) { - static QSet<QString> equals; - if (equals.isEmpty()) { - equals.reserve(1307); - for (unsigned i = 0; i < 1307; ++i) - equals.insert(equals_array[i]); - } - QHash<QString, QScriptValue>::const_iterator it; - for (it = m_values.constBegin(); it != m_values.constEnd(); ++it) { - QString tag = QString::fromLatin1("%20 <=> %21").arg(expr).arg(it.key()); + typedef QHash<QString, QScriptValue>::const_iterator ValuesIterator; + static const QSet<QString> equals = + charArrayToQStringSet(equals_array, int(sizeof(equals_array) / sizeof(const char *))); + + const ValuesIterator cend = m_values.constEnd(); + const QString tagPrefix = QLatin1String(exprC) + QLatin1String(" <=> "); + for (ValuesIterator it = m_values.constBegin(); it != cend; ++it) { + const QString tag = tagPrefix + it.key(); newRow(tag.toLatin1()) << it.value() << equals.contains(tag); } } @@ -1395,7 +1394,7 @@ void tst_QScriptValueGenerated::strictlyEquals_initData() initScriptValues(); } -static QString strictlyEquals_array[] = { +static const char *strictlyEquals_array[] = { "QScriptValue() <=> QScriptValue()", "QScriptValue(QScriptValue::UndefinedValue) <=> QScriptValue(QScriptValue::UndefinedValue)", "QScriptValue(QScriptValue::UndefinedValue) <=> QScriptValue(0, QScriptValue::UndefinedValue)", @@ -1928,15 +1927,16 @@ static QString strictlyEquals_array[] = { void tst_QScriptValueGenerated::strictlyEquals_makeData(const char *expr) { - static QSet<QString> equals; - if (equals.isEmpty()) { - equals.reserve(529); - for (unsigned i = 0; i < 529; ++i) - equals.insert(strictlyEquals_array[i]); - } - QHash<QString, QScriptValue>::const_iterator it; - for (it = m_values.constBegin(); it != m_values.constEnd(); ++it) { - QString tag = QString::fromLatin1("%20 <=> %21").arg(expr).arg(it.key()); + typedef QHash<QString, QScriptValue>::const_iterator ValueIterator; + + static const QSet<QString> equals = + charArrayToQStringSet(strictlyEquals_array, + int(sizeof(strictlyEquals_array) / sizeof(const char *))); + + const ValueIterator cend = m_values.constEnd(); + const QString tagPrefix = QLatin1String(expr) + QLatin1String(" <=> "); + for (ValueIterator it = m_values.constBegin(); it != cend; ++it) { + const QString tag = tagPrefix + it.key(); newRow(tag.toLatin1()) << it.value() << equals.contains(tag); } } @@ -1958,7 +1958,7 @@ void tst_QScriptValueGenerated::lessThan_initData() initScriptValues(); } -static QString lessThan_array[] = { +static const char *lessThan_array[] = { "QScriptValue(QScriptValue::NullValue) <=> QScriptValue(true)", "QScriptValue(QScriptValue::NullValue) <=> QScriptValue(int(122))", "QScriptValue(QScriptValue::NullValue) <=> QScriptValue(uint(124))", @@ -7438,15 +7438,15 @@ static QString lessThan_array[] = { void tst_QScriptValueGenerated::lessThan_makeData(const char *expr) { - static QSet<QString> equals; - if (equals.isEmpty()) { - equals.reserve(5476); - for (unsigned i = 0; i < 5476; ++i) - equals.insert(lessThan_array[i]); - } - QHash<QString, QScriptValue>::const_iterator it; - for (it = m_values.constBegin(); it != m_values.constEnd(); ++it) { - QString tag = QString::fromLatin1("%20 <=> %21").arg(expr).arg(it.key()); + typedef QHash<QString, QScriptValue>::const_iterator ValuesIterator; + + static const QSet<QString> equals = + charArrayToQStringSet(lessThan_array, int(sizeof(lessThan_array) / sizeof(const char *))); + + const ValuesIterator cend = m_values.constEnd(); + const QString tagPrefix = QLatin1String(expr) + QLatin1String(" <=> "); + for (ValuesIterator it = m_values.constBegin(); it != cend; ++it) { + const QString tag = tagPrefix + it.key(); newRow(tag.toLatin1()) << it.value() << equals.contains(tag); } } @@ -7468,7 +7468,7 @@ void tst_QScriptValueGenerated::instanceOf_initData() initScriptValues(); } -static QString instanceOf_array[] = { +static const char *instanceOf_array[] = { "engine->evaluate(\"[]\") <=> engine->evaluate(\"Object\")", "engine->evaluate(\"[]\") <=> engine->evaluate(\"Array\")", "engine->evaluate(\"Date.prototype\") <=> engine->evaluate(\"Object\")", @@ -7519,16 +7519,16 @@ static QString instanceOf_array[] = { void tst_QScriptValueGenerated::instanceOf_makeData(const char *expr) { - static QSet<QString> equals; - if (equals.isEmpty()) { - equals.reserve(47); - for (unsigned i = 0; i < 47; ++i) - equals.insert(instanceOf_array[i]); - } - QHash<QString, QScriptValue>::const_iterator it; - for (it = m_values.constBegin(); it != m_values.constEnd(); ++it) { - QString tag = QString::fromLatin1("%20 <=> %21").arg(expr).arg(it.key()); - newRow(tag.toLatin1()) << it.value() << equals.contains(tag); + typedef QHash<QString, QScriptValue>::const_iterator ValuesIterator; + + static const QSet<QString> instanceOf = + charArrayToQStringSet(instanceOf_array, int(sizeof(instanceOf_array) / sizeof(const char *))); + + const ValuesIterator cend = m_values.constEnd(); + const QString tagPrefix = QLatin1String(expr) + QLatin1String(" <=> "); + for (ValuesIterator it = m_values.constBegin(); it != cend; ++it) { + const QString tag = tagPrefix + it.key(); + newRow(tag.toLatin1()) << it.value() << instanceOf.contains(tag); } } diff --git a/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_isXXX.cpp b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_isXXX.cpp index cdf0361..c790725 100644 --- a/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_isXXX.cpp +++ b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_isXXX.cpp @@ -52,7 +52,7 @@ void tst_QScriptValueGenerated::isValid_initData() initScriptValues(); } -static QString isValid_array[] = { +static const char *isValid_array[] = { "QScriptValue(QScriptValue::UndefinedValue)", "QScriptValue(QScriptValue::NullValue)", "QScriptValue(true)", @@ -204,12 +204,8 @@ static QString isValid_array[] = { void tst_QScriptValueGenerated::isValid_makeData(const char* expr) { - static QSet<QString> isValid; - if (isValid.isEmpty()) { - isValid.reserve(147); - for (unsigned i = 0; i < 147; ++i) - isValid.insert(isValid_array[i]); - } + static const QSet<QString> isValid = + charArrayToQStringSet(isValid_array, int(sizeof(isValid_array) / sizeof(const char *))); newRow(expr) << isValid.contains(expr); } @@ -229,7 +225,7 @@ void tst_QScriptValueGenerated::isBool_initData() initScriptValues(); } -static QString isBool_array[] = { +static const char *isBool_array[] = { "QScriptValue(true)", "QScriptValue(false)", "QScriptValue(0, true)", @@ -242,12 +238,8 @@ static QString isBool_array[] = { void tst_QScriptValueGenerated::isBool_makeData(const char* expr) { - static QSet<QString> isBool; - if (isBool.isEmpty()) { - isBool.reserve(8); - for (unsigned i = 0; i < 8; ++i) - isBool.insert(isBool_array[i]); - } + static const QSet<QString> isBool = + charArrayToQStringSet(isBool_array, int(sizeof(isBool_array) / sizeof(const char *))); newRow(expr) << isBool.contains(expr); } @@ -267,7 +259,7 @@ void tst_QScriptValueGenerated::isBoolean_initData() initScriptValues(); } -static QString isBoolean_array[] = { +static const char * isBoolean_array[] = { "QScriptValue(true)", "QScriptValue(false)", "QScriptValue(0, true)", @@ -280,12 +272,8 @@ static QString isBoolean_array[] = { void tst_QScriptValueGenerated::isBoolean_makeData(const char* expr) { - static QSet<QString> isBoolean; - if (isBoolean.isEmpty()) { - isBoolean.reserve(8); - for (unsigned i = 0; i < 8; ++i) - isBoolean.insert(isBoolean_array[i]); - } + static const QSet<QString> isBoolean = + charArrayToQStringSet(isBoolean_array, int(sizeof(isBoolean_array) / sizeof(const char *))); newRow(expr) << isBoolean.contains(expr); } @@ -305,7 +293,7 @@ void tst_QScriptValueGenerated::isNumber_initData() initScriptValues(); } -static QString isNumber_array[] = { +static const char *isNumber_array[] = { "QScriptValue(int(122))", "QScriptValue(uint(124))", "QScriptValue(0)", @@ -366,12 +354,8 @@ static QString isNumber_array[] = { void tst_QScriptValueGenerated::isNumber_makeData(const char* expr) { - static QSet<QString> isNumber; - if (isNumber.isEmpty()) { - isNumber.reserve(56); - for (unsigned i = 0; i < 56; ++i) - isNumber.insert(isNumber_array[i]); - } + static const QSet<QString> isNumber = + charArrayToQStringSet(isNumber_array, int(sizeof(isNumber_array) / sizeof(const char *))); newRow(expr) << isNumber.contains(expr); } @@ -391,7 +375,7 @@ void tst_QScriptValueGenerated::isFunction_initData() initScriptValues(); } -static QString isFunction_array[] = { +static const char *isFunction_array[] = { "engine->evaluate(\"Function.prototype\")", "engine->evaluate(\"Object\")", "engine->evaluate(\"Array\")", @@ -408,12 +392,8 @@ static QString isFunction_array[] = { void tst_QScriptValueGenerated::isFunction_makeData(const char* expr) { - static QSet<QString> isFunction; - if (isFunction.isEmpty()) { - isFunction.reserve(12); - for (unsigned i = 0; i < 12; ++i) - isFunction.insert(isFunction_array[i]); - } + static const QSet<QString> isFunction + = charArrayToQStringSet(isFunction_array, int(sizeof(isFunction_array) / sizeof(const char *))); newRow(expr) << isFunction.contains(expr); } @@ -433,7 +413,7 @@ void tst_QScriptValueGenerated::isNull_initData() initScriptValues(); } -static QString isNull_array[] = { +static const char *isNull_array[] = { "QScriptValue(QScriptValue::NullValue)", "QScriptValue(0, QScriptValue::NullValue)", "QScriptValue(engine, QScriptValue::NullValue)", @@ -444,12 +424,8 @@ static QString isNull_array[] = { void tst_QScriptValueGenerated::isNull_makeData(const char* expr) { - static QSet<QString> isNull; - if (isNull.isEmpty()) { - isNull.reserve(6); - for (unsigned i = 0; i < 6; ++i) - isNull.insert(isNull_array[i]); - } + static const QSet<QString> isNull = + charArrayToQStringSet(isNull_array, int(sizeof(isNull_array) / sizeof(const char *))); newRow(expr) << isNull.contains(expr); } @@ -469,7 +445,7 @@ void tst_QScriptValueGenerated::isString_initData() initScriptValues(); } -static QString isString_array[] = { +static const char *isString_array[] = { "QScriptValue(\"NaN\")", "QScriptValue(\"Infinity\")", "QScriptValue(\"-Infinity\")", @@ -509,12 +485,8 @@ static QString isString_array[] = { void tst_QScriptValueGenerated::isString_makeData(const char* expr) { - static QSet<QString> isString; - if (isString.isEmpty()) { - isString.reserve(35); - for (unsigned i = 0; i < 35; ++i) - isString.insert(isString_array[i]); - } + static const QSet<QString> isString = + charArrayToQStringSet(isString_array, int(sizeof(isString_array) / sizeof(const char *))); newRow(expr) << isString.contains(expr); } @@ -534,7 +506,7 @@ void tst_QScriptValueGenerated::isUndefined_initData() initScriptValues(); } -static QString isUndefined_array[] = { +static const char *isUndefined_array[] = { "QScriptValue(QScriptValue::UndefinedValue)", "QScriptValue(0, QScriptValue::UndefinedValue)", "QScriptValue(engine, QScriptValue::UndefinedValue)", @@ -545,12 +517,8 @@ static QString isUndefined_array[] = { void tst_QScriptValueGenerated::isUndefined_makeData(const char* expr) { - static QSet<QString> isUndefined; - if (isUndefined.isEmpty()) { - isUndefined.reserve(6); - for (unsigned i = 0; i < 6; ++i) - isUndefined.insert(isUndefined_array[i]); - } + static const QSet<QString> isUndefined = + charArrayToQStringSet(isUndefined_array, int(sizeof(isUndefined_array) / sizeof(const char *))); newRow(expr) << isUndefined.contains(expr); } @@ -570,7 +538,7 @@ void tst_QScriptValueGenerated::isVariant_initData() initScriptValues(); } -static QString isVariant_array[] = { +static const char *isVariant_array[] = { "engine->newVariant(QVariant())", "engine->newVariant(QVariant(123))", "engine->newVariant(QVariant(false))" @@ -578,12 +546,8 @@ static QString isVariant_array[] = { void tst_QScriptValueGenerated::isVariant_makeData(const char* expr) { - static QSet<QString> isVariant; - if (isVariant.isEmpty()) { - isVariant.reserve(3); - for (unsigned i = 0; i < 3; ++i) - isVariant.insert(isVariant_array[i]); - } + static QSet<QString> isVariant = + charArrayToQStringSet(isVariant_array, int(sizeof(isVariant_array) / sizeof(const char *))); newRow(expr) << isVariant.contains(expr); } @@ -603,19 +567,9 @@ void tst_QScriptValueGenerated::isQObject_initData() initScriptValues(); } -static QString isQObject_array[] = { - "engine->newQObject(engine)" -}; - void tst_QScriptValueGenerated::isQObject_makeData(const char* expr) { - static QSet<QString> isQObject; - if (isQObject.isEmpty()) { - isQObject.reserve(1); - for (unsigned i = 0; i < 1; ++i) - isQObject.insert(isQObject_array[i]); - } - newRow(expr) << isQObject.contains(expr); + newRow(expr) << (qstrcmp(expr, "engine->newQObject(engine)") == 0); } void tst_QScriptValueGenerated::isQObject_test(const char*, const QScriptValue& value) @@ -634,19 +588,9 @@ void tst_QScriptValueGenerated::isQMetaObject_initData() initScriptValues(); } -static QString isQMetaObject_array[] = { - "engine->newQMetaObject(&QObject::staticMetaObject)" -}; - void tst_QScriptValueGenerated::isQMetaObject_makeData(const char* expr) { - static QSet<QString> isQMetaObject; - if (isQMetaObject.isEmpty()) { - isQMetaObject.reserve(1); - for (unsigned i = 0; i < 1; ++i) - isQMetaObject.insert(isQMetaObject_array[i]); - } - newRow(expr) << isQMetaObject.contains(expr); + newRow(expr) << (qstrcmp(expr, "engine->newQMetaObject(&QObject::staticMetaObject)") == 0); } void tst_QScriptValueGenerated::isQMetaObject_test(const char*, const QScriptValue& value) @@ -665,7 +609,7 @@ void tst_QScriptValueGenerated::isObject_initData() initScriptValues(); } -static QString isObject_array[] = { +static const char *isObject_array[] = { "engine->evaluate(\"[]\")", "engine->evaluate(\"Object.prototype\")", "engine->evaluate(\"Date.prototype\")", @@ -706,12 +650,8 @@ static QString isObject_array[] = { void tst_QScriptValueGenerated::isObject_makeData(const char* expr) { - static QSet<QString> isObject; - if (isObject.isEmpty()) { - isObject.reserve(36); - for (unsigned i = 0; i < 36; ++i) - isObject.insert(isObject_array[i]); - } + static const QSet<QString> isObject = + charArrayToQStringSet(isObject_array, int(sizeof(isObject_array) / sizeof(const char *))); newRow(expr) << isObject.contains(expr); } @@ -731,19 +671,15 @@ void tst_QScriptValueGenerated::isDate_initData() initScriptValues(); } -static QString isDate_array[] = { +static const char *isDate_array[] = { "engine->evaluate(\"Date.prototype\")", "engine->newDate(QDateTime())" }; void tst_QScriptValueGenerated::isDate_makeData(const char* expr) { - static QSet<QString> isDate; - if (isDate.isEmpty()) { - isDate.reserve(2); - for (unsigned i = 0; i < 2; ++i) - isDate.insert(isDate_array[i]); - } + static const QSet<QString> isDate = + charArrayToQStringSet(isDate_array, int(sizeof(isDate_array) / sizeof(const char *))); newRow(expr) << isDate.contains(expr); } @@ -763,7 +699,7 @@ void tst_QScriptValueGenerated::isRegExp_initData() initScriptValues(); } -static QString isRegExp_array[] = { +static const char *isRegExp_array[] = { "engine->evaluate(\"/foo/\")", "engine->evaluate(\"new RegExp('foo', 'gim')\")", "engine->newRegExp(\"foo\", \"gim\")" @@ -771,12 +707,8 @@ static QString isRegExp_array[] = { void tst_QScriptValueGenerated::isRegExp_makeData(const char* expr) { - static QSet<QString> isRegExp; - if (isRegExp.isEmpty()) { - isRegExp.reserve(3); - for (unsigned i = 0; i < 3; ++i) - isRegExp.insert(isRegExp_array[i]); - } + static const QSet<QString> isRegExp = + charArrayToQStringSet(isRegExp_array, int(sizeof(isRegExp_array) / sizeof(const char *))); newRow(expr) << isRegExp.contains(expr); } @@ -796,7 +728,7 @@ void tst_QScriptValueGenerated::isArray_initData() initScriptValues(); } -static QString isArray_array[] = { +static const char *isArray_array[] = { "engine->evaluate(\"[]\")", "engine->evaluate(\"Array.prototype\")", "engine->evaluate(\"new Array()\")", @@ -806,12 +738,8 @@ static QString isArray_array[] = { void tst_QScriptValueGenerated::isArray_makeData(const char* expr) { - static QSet<QString> isArray; - if (isArray.isEmpty()) { - isArray.reserve(5); - for (unsigned i = 0; i < 5; ++i) - isArray.insert(isArray_array[i]); - } + static const QSet<QString> isArray = + charArrayToQStringSet(isArray_array, int(sizeof(isArray_array) / sizeof(const char *))); newRow(expr) << isArray.contains(expr); } @@ -831,7 +759,7 @@ void tst_QScriptValueGenerated::isError_initData() initScriptValues(); } -static QString isError_array[] = { +static const char *isError_array[] = { "engine->evaluate(\"Error.prototype\")", "engine->evaluate(\"new Error()\")", "engine->evaluate(\"Undefined\")", @@ -842,12 +770,8 @@ static QString isError_array[] = { void tst_QScriptValueGenerated::isError_makeData(const char* expr) { - static QSet<QString> isError; - if (isError.isEmpty()) { - isError.reserve(6); - for (unsigned i = 0; i < 6; ++i) - isError.insert(isError_array[i]); - } + static QSet<QString> isError = + charArrayToQStringSet(isError_array, int(sizeof(isError_array) / sizeof(const char *))); newRow(expr) << isError.contains(expr); } diff --git a/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_toXXX.cpp b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_toXXX.cpp index 2c6ab1e..2c7db4a 100644 --- a/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_toXXX.cpp +++ b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_toXXX.cpp @@ -53,7 +53,7 @@ void tst_QScriptValueGenerated::toString_initData() initScriptValues(); } -static QString toString_tagArray[] = { +static const char *toString_tagArray[] = { "QScriptValue()", "QScriptValue(QScriptValue::UndefinedValue)", "QScriptValue(QScriptValue::NullValue)", @@ -203,7 +203,7 @@ static QString toString_tagArray[] = { "engine->newQObject(0)", "engine->newQObject(engine)"}; -static QString toString_valueArray[] = { +static const char *toString_valueArray[] = { "", "undefined", "null", "true", "false", "122", @@ -281,12 +281,9 @@ static QString toString_valueArray[] = { void tst_QScriptValueGenerated::toString_makeData(const char* expr) { - static QHash<QString, QString> toString; - if (toString.isEmpty()) { - toString.reserve(148); - for (unsigned i = 0; i < 148; ++i) - toString.insert(toString_tagArray[i], toString_valueArray[i]); - } + static const QHash<QString, QString> toString = + charArraysToStringHash(toString_tagArray, toString_valueArray, + int(sizeof(toString_tagArray) / sizeof(const char *))); newRow(expr) << toString.value(expr); } @@ -306,7 +303,7 @@ void tst_QScriptValueGenerated::toNumber_initData() initScriptValues(); } -static QString toNumber_tagArray[] = { +static const char *toNumber_tagArray[] = { "QScriptValue()", "QScriptValue(QScriptValue::UndefinedValue)", "QScriptValue(QScriptValue::NullValue)", @@ -473,12 +470,9 @@ static qsreal toNumber_valueArray[] = { qQNaN(), qQNaN(), qQNaN(), qQNaN(), 123, 0, 0, qQNaN()}; void tst_QScriptValueGenerated::toNumber_makeData(const char* expr) { - static QHash<QString, qsreal> toNumber; - if (toNumber.isEmpty()) { - toNumber.reserve(148); - for (unsigned i = 0; i < 148; ++i) - toNumber.insert(toNumber_tagArray[i], toNumber_valueArray[i]); - } + static const QHash<QString, qsreal> toNumber = + charValueArraysToHash(toNumber_tagArray, toNumber_valueArray, + int(sizeof(toNumber_tagArray) / sizeof(const char *))); newRow(expr) << toNumber.value(expr); } @@ -507,7 +501,7 @@ void tst_QScriptValueGenerated::toBool_initData() initScriptValues(); } -static QString toBool_tagArray[] = { +static const char *toBool_tagArray[] = { "QScriptValue()", "QScriptValue(QScriptValue::UndefinedValue)", "QScriptValue(QScriptValue::NullValue)", @@ -735,12 +729,9 @@ static bool toBool_valueArray[] = { void tst_QScriptValueGenerated::toBool_makeData(const char* expr) { - static QHash<QString, bool> toBool; - if (toBool.isEmpty()) { - toBool.reserve(148); - for (unsigned i = 0; i < 148; ++i) - toBool.insert(toBool_tagArray[i], toBool_valueArray[i]); - } + static const QHash<QString, bool> toBool = + charValueArraysToHash(toBool_tagArray, toBool_valueArray, + int(sizeof(toBool_tagArray) / sizeof(const char *))); newRow(expr) << toBool.value(expr); } @@ -760,7 +751,7 @@ void tst_QScriptValueGenerated::toBoolean_initData() initScriptValues(); } -static QString toBoolean_tagArray[] = { +static const char *toBoolean_tagArray[] = { "QScriptValue()", "QScriptValue(QScriptValue::UndefinedValue)", "QScriptValue(QScriptValue::NullValue)", @@ -988,12 +979,9 @@ static bool toBoolean_valueArray[] = { void tst_QScriptValueGenerated::toBoolean_makeData(const char* expr) { - static QHash<QString, bool> toBoolean; - if (toBoolean.isEmpty()) { - toBoolean.reserve(148); - for (unsigned i = 0; i < 148; ++i) - toBoolean.insert(toBoolean_tagArray[i], toBoolean_valueArray[i]); - } + static const QHash<QString, bool> toBoolean = + charValueArraysToHash(toBoolean_tagArray, toBoolean_valueArray, + int(sizeof(toBoolean_tagArray) / sizeof(const char *))); newRow(expr) << toBoolean.value(expr); } @@ -1013,7 +1001,7 @@ void tst_QScriptValueGenerated::toInteger_initData() initScriptValues(); } -static QString toInteger_tagArray[] = { +static const char *toInteger_tagArray[] = { "QScriptValue()", "QScriptValue(QScriptValue::UndefinedValue)", "QScriptValue(QScriptValue::NullValue)", @@ -1180,12 +1168,9 @@ static qsreal toInteger_valueArray[] = { 0, 0, 0, 0, 123, 0, 0, 0}; void tst_QScriptValueGenerated::toInteger_makeData(const char* expr) { - static QHash<QString, qsreal> toInteger; - if (toInteger.isEmpty()) { - toInteger.reserve(148); - for (unsigned i = 0; i < 148; ++i) - toInteger.insert(toInteger_tagArray[i], toInteger_valueArray[i]); - } + static const QHash<QString, qsreal> toInteger = + charValueArraysToHash(toInteger_tagArray, toInteger_valueArray, + int(sizeof(toInteger_tagArray) / sizeof(const char *))); newRow(expr) << toInteger.value(expr); } @@ -1210,7 +1195,7 @@ void tst_QScriptValueGenerated::toInt32_initData() initScriptValues(); } -static QString toInt32_tagArray[] = { +static const char *toInt32_tagArray[] = { "QScriptValue()", "QScriptValue(QScriptValue::UndefinedValue)", "QScriptValue(QScriptValue::NullValue)", @@ -1438,12 +1423,9 @@ static qint32 toInt32_valueArray[] = { void tst_QScriptValueGenerated::toInt32_makeData(const char* expr) { - static QHash<QString, qint32> toInt32; - if (toInt32.isEmpty()) { - toInt32.reserve(148); - for (unsigned i = 0; i < 148; ++i) - toInt32.insert(toInt32_tagArray[i], toInt32_valueArray[i]); - } + static const QHash<QString, qint32> toInt32 = + charValueArraysToHash(toInt32_tagArray, toInt32_valueArray, + int(sizeof(toInt32_tagArray) / sizeof(const char *))); newRow(expr) << toInt32.value(expr); } @@ -1463,7 +1445,7 @@ void tst_QScriptValueGenerated::toUInt32_initData() initScriptValues(); } -static QString toUInt32_tagArray[] = { +static const char *toUInt32_tagArray[] = { "QScriptValue()", "QScriptValue(QScriptValue::UndefinedValue)", "QScriptValue(QScriptValue::NullValue)", @@ -1691,12 +1673,9 @@ static quint32 toUInt32_valueArray[] = { void tst_QScriptValueGenerated::toUInt32_makeData(const char* expr) { - static QHash<QString, quint32> toUInt32; - if (toUInt32.isEmpty()) { - toUInt32.reserve(148); - for (unsigned i = 0; i < 148; ++i) - toUInt32.insert(toUInt32_tagArray[i], toUInt32_valueArray[i]); - } + static const QHash<QString, quint32> toUInt32 = + charValueArraysToHash(toUInt32_tagArray, toUInt32_valueArray, + int(sizeof(toUInt32_tagArray) / sizeof(const char *))); newRow(expr) << toUInt32.value(expr); } @@ -1716,7 +1695,7 @@ void tst_QScriptValueGenerated::toUInt16_initData() initScriptValues(); } -static QString toUInt16_tagArray[] = { +static const char *toUInt16_tagArray[] = { "QScriptValue()", "QScriptValue(QScriptValue::UndefinedValue)", "QScriptValue(QScriptValue::NullValue)", @@ -1944,12 +1923,9 @@ static quint16 toUInt16_valueArray[] = { void tst_QScriptValueGenerated::toUInt16_makeData(const char* expr) { - static QHash<QString, quint16> toUInt16; - if (toUInt16.isEmpty()) { - toUInt16.reserve(148); - for (unsigned i = 0; i < 148; ++i) - toUInt16.insert(toUInt16_tagArray[i], toUInt16_valueArray[i]); - } + static const QHash<QString, quint16> toUInt16 = + charValueArraysToHash(toUInt16_tagArray, toUInt16_valueArray, + int(sizeof(toUInt16_tagArray) / sizeof(const char *))); newRow(expr) << toUInt16.value(expr); } |