| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2018 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the test suite of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
| 21 | ** included in the packaging of this file. Please review the following |
| 22 | ** information to ensure the GNU General Public License requirements will |
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 24 | ** |
| 25 | ** $QT_END_LICENSE$ |
| 26 | ** |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | #include "tst_qscriptvalue.h" |
| 30 | |
| 31 | |
| 32 | void tst_QScriptValueGenerated::isValid_initData() |
| 33 | { |
| 34 | QTest::addColumn<bool>(name: "expected" ); |
| 35 | initScriptValues(); |
| 36 | } |
| 37 | |
| 38 | static const char *isValid_array[] = { |
| 39 | "QScriptValue(QScriptValue::UndefinedValue)" , |
| 40 | "QScriptValue(QScriptValue::NullValue)" , |
| 41 | "QScriptValue(true)" , |
| 42 | "QScriptValue(false)" , |
| 43 | "QScriptValue(int(122))" , |
| 44 | "QScriptValue(uint(124))" , |
| 45 | "QScriptValue(0)" , |
| 46 | "QScriptValue(0.0)" , |
| 47 | "QScriptValue(123.0)" , |
| 48 | "QScriptValue(6.37e-8)" , |
| 49 | "QScriptValue(-6.37e-8)" , |
| 50 | "QScriptValue(0x43211234)" , |
| 51 | "QScriptValue(0x10000)" , |
| 52 | "QScriptValue(0x10001)" , |
| 53 | "QScriptValue(qSNaN())" , |
| 54 | "QScriptValue(qQNaN())" , |
| 55 | "QScriptValue(qInf())" , |
| 56 | "QScriptValue(-qInf())" , |
| 57 | "QScriptValue(\"NaN\")" , |
| 58 | "QScriptValue(\"Infinity\")" , |
| 59 | "QScriptValue(\"-Infinity\")" , |
| 60 | "QScriptValue(\"ciao\")" , |
| 61 | "QScriptValue(QString::fromLatin1(\"ciao\"))" , |
| 62 | "QScriptValue(QString(\"\"))" , |
| 63 | "QScriptValue(QString())" , |
| 64 | "QScriptValue(QString(\"0\"))" , |
| 65 | "QScriptValue(QString(\"123\"))" , |
| 66 | "QScriptValue(QString(\"12.4\"))" , |
| 67 | "QScriptValue(0, QScriptValue::UndefinedValue)" , |
| 68 | "QScriptValue(0, QScriptValue::NullValue)" , |
| 69 | "QScriptValue(0, true)" , |
| 70 | "QScriptValue(0, false)" , |
| 71 | "QScriptValue(0, int(122))" , |
| 72 | "QScriptValue(0, uint(124))" , |
| 73 | "QScriptValue(0, 0)" , |
| 74 | "QScriptValue(0, 0.0)" , |
| 75 | "QScriptValue(0, 123.0)" , |
| 76 | "QScriptValue(0, 6.37e-8)" , |
| 77 | "QScriptValue(0, -6.37e-8)" , |
| 78 | "QScriptValue(0, 0x43211234)" , |
| 79 | "QScriptValue(0, 0x10000)" , |
| 80 | "QScriptValue(0, 0x10001)" , |
| 81 | "QScriptValue(0, qSNaN())" , |
| 82 | "QScriptValue(0, qQNaN())" , |
| 83 | "QScriptValue(0, qInf())" , |
| 84 | "QScriptValue(0, -qInf())" , |
| 85 | "QScriptValue(0, \"NaN\")" , |
| 86 | "QScriptValue(0, \"Infinity\")" , |
| 87 | "QScriptValue(0, \"-Infinity\")" , |
| 88 | "QScriptValue(0, \"ciao\")" , |
| 89 | "QScriptValue(0, QString::fromLatin1(\"ciao\"))" , |
| 90 | "QScriptValue(0, QString(\"\"))" , |
| 91 | "QScriptValue(0, QString())" , |
| 92 | "QScriptValue(0, QString(\"0\"))" , |
| 93 | "QScriptValue(0, QString(\"123\"))" , |
| 94 | "QScriptValue(0, QString(\"12.3\"))" , |
| 95 | "QScriptValue(engine, QScriptValue::UndefinedValue)" , |
| 96 | "QScriptValue(engine, QScriptValue::NullValue)" , |
| 97 | "QScriptValue(engine, true)" , |
| 98 | "QScriptValue(engine, false)" , |
| 99 | "QScriptValue(engine, int(122))" , |
| 100 | "QScriptValue(engine, uint(124))" , |
| 101 | "QScriptValue(engine, 0)" , |
| 102 | "QScriptValue(engine, 0.0)" , |
| 103 | "QScriptValue(engine, 123.0)" , |
| 104 | "QScriptValue(engine, 6.37e-8)" , |
| 105 | "QScriptValue(engine, -6.37e-8)" , |
| 106 | "QScriptValue(engine, 0x43211234)" , |
| 107 | "QScriptValue(engine, 0x10000)" , |
| 108 | "QScriptValue(engine, 0x10001)" , |
| 109 | "QScriptValue(engine, qSNaN())" , |
| 110 | "QScriptValue(engine, qQNaN())" , |
| 111 | "QScriptValue(engine, qInf())" , |
| 112 | "QScriptValue(engine, -qInf())" , |
| 113 | "QScriptValue(engine, \"NaN\")" , |
| 114 | "QScriptValue(engine, \"Infinity\")" , |
| 115 | "QScriptValue(engine, \"-Infinity\")" , |
| 116 | "QScriptValue(engine, \"ciao\")" , |
| 117 | "QScriptValue(engine, QString::fromLatin1(\"ciao\"))" , |
| 118 | "QScriptValue(engine, QString(\"\"))" , |
| 119 | "QScriptValue(engine, QString())" , |
| 120 | "QScriptValue(engine, QString(\"0\"))" , |
| 121 | "QScriptValue(engine, QString(\"123\"))" , |
| 122 | "QScriptValue(engine, QString(\"1.23\"))" , |
| 123 | "engine->evaluate(\"[]\")" , |
| 124 | "engine->evaluate(\"{}\")" , |
| 125 | "engine->evaluate(\"Object.prototype\")" , |
| 126 | "engine->evaluate(\"Date.prototype\")" , |
| 127 | "engine->evaluate(\"Array.prototype\")" , |
| 128 | "engine->evaluate(\"Function.prototype\")" , |
| 129 | "engine->evaluate(\"Error.prototype\")" , |
| 130 | "engine->evaluate(\"Object\")" , |
| 131 | "engine->evaluate(\"Array\")" , |
| 132 | "engine->evaluate(\"Number\")" , |
| 133 | "engine->evaluate(\"Function\")" , |
| 134 | "engine->evaluate(\"(function() { return 1; })\")" , |
| 135 | "engine->evaluate(\"(function() { return 'ciao'; })\")" , |
| 136 | "engine->evaluate(\"(function() { throw new Error('foo'); })\")" , |
| 137 | "engine->evaluate(\"/foo/\")" , |
| 138 | "engine->evaluate(\"new Object()\")" , |
| 139 | "engine->evaluate(\"new Array()\")" , |
| 140 | "engine->evaluate(\"new Error()\")" , |
| 141 | "engine->evaluate(\"new Boolean(true)\")" , |
| 142 | "engine->evaluate(\"new Boolean(false)\")" , |
| 143 | "engine->evaluate(\"new Number(123)\")" , |
| 144 | "engine->evaluate(\"new RegExp('foo', 'gim')\")" , |
| 145 | "engine->evaluate(\"new String('ciao')\")" , |
| 146 | "engine->evaluate(\"a = new Object(); a.foo = 22; a.foo\")" , |
| 147 | "engine->evaluate(\"Undefined\")" , |
| 148 | "engine->evaluate(\"Null\")" , |
| 149 | "engine->evaluate(\"True\")" , |
| 150 | "engine->evaluate(\"False\")" , |
| 151 | "engine->evaluate(\"undefined\")" , |
| 152 | "engine->evaluate(\"null\")" , |
| 153 | "engine->evaluate(\"true\")" , |
| 154 | "engine->evaluate(\"false\")" , |
| 155 | "engine->evaluate(\"122\")" , |
| 156 | "engine->evaluate(\"124\")" , |
| 157 | "engine->evaluate(\"0\")" , |
| 158 | "engine->evaluate(\"0.0\")" , |
| 159 | "engine->evaluate(\"123.0\")" , |
| 160 | "engine->evaluate(\"6.37e-8\")" , |
| 161 | "engine->evaluate(\"-6.37e-8\")" , |
| 162 | "engine->evaluate(\"0x43211234\")" , |
| 163 | "engine->evaluate(\"0x10000\")" , |
| 164 | "engine->evaluate(\"0x10001\")" , |
| 165 | "engine->evaluate(\"NaN\")" , |
| 166 | "engine->evaluate(\"Infinity\")" , |
| 167 | "engine->evaluate(\"-Infinity\")" , |
| 168 | "engine->evaluate(\"'ciao'\")" , |
| 169 | "engine->evaluate(\"''\")" , |
| 170 | "engine->evaluate(\"'0'\")" , |
| 171 | "engine->evaluate(\"'123'\")" , |
| 172 | "engine->evaluate(\"'12.4'\")" , |
| 173 | "engine->nullValue()" , |
| 174 | "engine->undefinedValue()" , |
| 175 | "engine->newObject()" , |
| 176 | "engine->newArray()" , |
| 177 | "engine->newArray(10)" , |
| 178 | "engine->newDate(QDateTime())" , |
| 179 | "engine->newQMetaObject(&QObject::staticMetaObject)" , |
| 180 | "engine->newRegExp(\"foo\", \"gim\")" , |
| 181 | "engine->newVariant(QVariant())" , |
| 182 | "engine->newVariant(QVariant(123))" , |
| 183 | "engine->newVariant(QVariant(false))" , |
| 184 | "engine->newQObject(0)" , |
| 185 | "engine->newQObject(engine)" |
| 186 | }; |
| 187 | |
| 188 | void tst_QScriptValueGenerated::isValid_makeData(const char* expr) |
| 189 | { |
| 190 | static const QSet<QString> isValid = |
| 191 | charArrayToQStringSet(array: isValid_array, size: int(sizeof(isValid_array) / sizeof(const char *))); |
| 192 | newRow(tag: expr) << isValid.contains(value: expr); |
| 193 | } |
| 194 | |
| 195 | void tst_QScriptValueGenerated::isValid_test(const char*, const QScriptValue& value) |
| 196 | { |
| 197 | QFETCH(bool, expected); |
| 198 | QCOMPARE(value.isValid(), expected); |
| 199 | QCOMPARE(value.isValid(), expected); |
| 200 | } |
| 201 | |
| 202 | DEFINE_TEST_FUNCTION(isValid) |
| 203 | |
| 204 | |
| 205 | void tst_QScriptValueGenerated::isBool_initData() |
| 206 | { |
| 207 | QTest::addColumn<bool>(name: "expected" ); |
| 208 | initScriptValues(); |
| 209 | } |
| 210 | |
| 211 | static const char *isBool_array[] = { |
| 212 | "QScriptValue(true)" , |
| 213 | "QScriptValue(false)" , |
| 214 | "QScriptValue(0, true)" , |
| 215 | "QScriptValue(0, false)" , |
| 216 | "QScriptValue(engine, true)" , |
| 217 | "QScriptValue(engine, false)" , |
| 218 | "engine->evaluate(\"true\")" , |
| 219 | "engine->evaluate(\"false\")" |
| 220 | }; |
| 221 | |
| 222 | void tst_QScriptValueGenerated::isBool_makeData(const char* expr) |
| 223 | { |
| 224 | static const QSet<QString> isBool = |
| 225 | charArrayToQStringSet(array: isBool_array, size: int(sizeof(isBool_array) / sizeof(const char *))); |
| 226 | newRow(tag: expr) << isBool.contains(value: expr); |
| 227 | } |
| 228 | |
| 229 | void tst_QScriptValueGenerated::isBool_test(const char*, const QScriptValue& value) |
| 230 | { |
| 231 | QFETCH(bool, expected); |
| 232 | QCOMPARE(value.isBool(), expected); |
| 233 | QCOMPARE(value.isBool(), expected); |
| 234 | } |
| 235 | |
| 236 | DEFINE_TEST_FUNCTION(isBool) |
| 237 | |
| 238 | |
| 239 | void tst_QScriptValueGenerated::isBoolean_initData() |
| 240 | { |
| 241 | QTest::addColumn<bool>(name: "expected" ); |
| 242 | initScriptValues(); |
| 243 | } |
| 244 | |
| 245 | static const char * isBoolean_array[] = { |
| 246 | "QScriptValue(true)" , |
| 247 | "QScriptValue(false)" , |
| 248 | "QScriptValue(0, true)" , |
| 249 | "QScriptValue(0, false)" , |
| 250 | "QScriptValue(engine, true)" , |
| 251 | "QScriptValue(engine, false)" , |
| 252 | "engine->evaluate(\"true\")" , |
| 253 | "engine->evaluate(\"false\")" |
| 254 | }; |
| 255 | |
| 256 | void tst_QScriptValueGenerated::isBoolean_makeData(const char* expr) |
| 257 | { |
| 258 | static const QSet<QString> isBoolean = |
| 259 | charArrayToQStringSet(array: isBoolean_array, size: int(sizeof(isBoolean_array) / sizeof(const char *))); |
| 260 | newRow(tag: expr) << isBoolean.contains(value: expr); |
| 261 | } |
| 262 | |
| 263 | void tst_QScriptValueGenerated::isBoolean_test(const char*, const QScriptValue& value) |
| 264 | { |
| 265 | QFETCH(bool, expected); |
| 266 | QCOMPARE(value.isBoolean(), expected); |
| 267 | QCOMPARE(value.isBoolean(), expected); |
| 268 | } |
| 269 | |
| 270 | DEFINE_TEST_FUNCTION(isBoolean) |
| 271 | |
| 272 | |
| 273 | void tst_QScriptValueGenerated::isNumber_initData() |
| 274 | { |
| 275 | QTest::addColumn<bool>(name: "expected" ); |
| 276 | initScriptValues(); |
| 277 | } |
| 278 | |
| 279 | static const char *isNumber_array[] = { |
| 280 | "QScriptValue(int(122))" , |
| 281 | "QScriptValue(uint(124))" , |
| 282 | "QScriptValue(0)" , |
| 283 | "QScriptValue(0.0)" , |
| 284 | "QScriptValue(123.0)" , |
| 285 | "QScriptValue(6.37e-8)" , |
| 286 | "QScriptValue(-6.37e-8)" , |
| 287 | "QScriptValue(0x43211234)" , |
| 288 | "QScriptValue(0x10000)" , |
| 289 | "QScriptValue(0x10001)" , |
| 290 | "QScriptValue(qSNaN())" , |
| 291 | "QScriptValue(qQNaN())" , |
| 292 | "QScriptValue(qInf())" , |
| 293 | "QScriptValue(-qInf())" , |
| 294 | "QScriptValue(0, int(122))" , |
| 295 | "QScriptValue(0, uint(124))" , |
| 296 | "QScriptValue(0, 0)" , |
| 297 | "QScriptValue(0, 0.0)" , |
| 298 | "QScriptValue(0, 123.0)" , |
| 299 | "QScriptValue(0, 6.37e-8)" , |
| 300 | "QScriptValue(0, -6.37e-8)" , |
| 301 | "QScriptValue(0, 0x43211234)" , |
| 302 | "QScriptValue(0, 0x10000)" , |
| 303 | "QScriptValue(0, 0x10001)" , |
| 304 | "QScriptValue(0, qSNaN())" , |
| 305 | "QScriptValue(0, qQNaN())" , |
| 306 | "QScriptValue(0, qInf())" , |
| 307 | "QScriptValue(0, -qInf())" , |
| 308 | "QScriptValue(engine, int(122))" , |
| 309 | "QScriptValue(engine, uint(124))" , |
| 310 | "QScriptValue(engine, 0)" , |
| 311 | "QScriptValue(engine, 0.0)" , |
| 312 | "QScriptValue(engine, 123.0)" , |
| 313 | "QScriptValue(engine, 6.37e-8)" , |
| 314 | "QScriptValue(engine, -6.37e-8)" , |
| 315 | "QScriptValue(engine, 0x43211234)" , |
| 316 | "QScriptValue(engine, 0x10000)" , |
| 317 | "QScriptValue(engine, 0x10001)" , |
| 318 | "QScriptValue(engine, qSNaN())" , |
| 319 | "QScriptValue(engine, qQNaN())" , |
| 320 | "QScriptValue(engine, qInf())" , |
| 321 | "QScriptValue(engine, -qInf())" , |
| 322 | "engine->evaluate(\"a = new Object(); a.foo = 22; a.foo\")" , |
| 323 | "engine->evaluate(\"122\")" , |
| 324 | "engine->evaluate(\"124\")" , |
| 325 | "engine->evaluate(\"0\")" , |
| 326 | "engine->evaluate(\"0.0\")" , |
| 327 | "engine->evaluate(\"123.0\")" , |
| 328 | "engine->evaluate(\"6.37e-8\")" , |
| 329 | "engine->evaluate(\"-6.37e-8\")" , |
| 330 | "engine->evaluate(\"0x43211234\")" , |
| 331 | "engine->evaluate(\"0x10000\")" , |
| 332 | "engine->evaluate(\"0x10001\")" , |
| 333 | "engine->evaluate(\"NaN\")" , |
| 334 | "engine->evaluate(\"Infinity\")" , |
| 335 | "engine->evaluate(\"-Infinity\")" |
| 336 | }; |
| 337 | |
| 338 | void tst_QScriptValueGenerated::isNumber_makeData(const char* expr) |
| 339 | { |
| 340 | static const QSet<QString> isNumber = |
| 341 | charArrayToQStringSet(array: isNumber_array, size: int(sizeof(isNumber_array) / sizeof(const char *))); |
| 342 | newRow(tag: expr) << isNumber.contains(value: expr); |
| 343 | } |
| 344 | |
| 345 | void tst_QScriptValueGenerated::isNumber_test(const char*, const QScriptValue& value) |
| 346 | { |
| 347 | QFETCH(bool, expected); |
| 348 | QCOMPARE(value.isNumber(), expected); |
| 349 | QCOMPARE(value.isNumber(), expected); |
| 350 | } |
| 351 | |
| 352 | DEFINE_TEST_FUNCTION(isNumber) |
| 353 | |
| 354 | |
| 355 | void tst_QScriptValueGenerated::isFunction_initData() |
| 356 | { |
| 357 | QTest::addColumn<bool>(name: "expected" ); |
| 358 | initScriptValues(); |
| 359 | } |
| 360 | |
| 361 | static const char *isFunction_array[] = { |
| 362 | "engine->evaluate(\"Function.prototype\")" , |
| 363 | "engine->evaluate(\"Object\")" , |
| 364 | "engine->evaluate(\"Array\")" , |
| 365 | "engine->evaluate(\"Number\")" , |
| 366 | "engine->evaluate(\"Function\")" , |
| 367 | "engine->evaluate(\"(function() { return 1; })\")" , |
| 368 | "engine->evaluate(\"(function() { return 'ciao'; })\")" , |
| 369 | "engine->evaluate(\"(function() { throw new Error('foo'); })\")" , |
| 370 | "engine->evaluate(\"/foo/\")" , |
| 371 | "engine->evaluate(\"new RegExp('foo', 'gim')\")" , |
| 372 | "engine->newQMetaObject(&QObject::staticMetaObject)" , |
| 373 | "engine->newRegExp(\"foo\", \"gim\")" |
| 374 | }; |
| 375 | |
| 376 | void tst_QScriptValueGenerated::isFunction_makeData(const char* expr) |
| 377 | { |
| 378 | static const QSet<QString> isFunction |
| 379 | = charArrayToQStringSet(array: isFunction_array, size: int(sizeof(isFunction_array) / sizeof(const char *))); |
| 380 | newRow(tag: expr) << isFunction.contains(value: expr); |
| 381 | } |
| 382 | |
| 383 | void tst_QScriptValueGenerated::isFunction_test(const char*, const QScriptValue& value) |
| 384 | { |
| 385 | QFETCH(bool, expected); |
| 386 | QCOMPARE(value.isFunction(), expected); |
| 387 | QCOMPARE(value.isFunction(), expected); |
| 388 | } |
| 389 | |
| 390 | DEFINE_TEST_FUNCTION(isFunction) |
| 391 | |
| 392 | |
| 393 | void tst_QScriptValueGenerated::isNull_initData() |
| 394 | { |
| 395 | QTest::addColumn<bool>(name: "expected" ); |
| 396 | initScriptValues(); |
| 397 | } |
| 398 | |
| 399 | static const char *isNull_array[] = { |
| 400 | "QScriptValue(QScriptValue::NullValue)" , |
| 401 | "QScriptValue(0, QScriptValue::NullValue)" , |
| 402 | "QScriptValue(engine, QScriptValue::NullValue)" , |
| 403 | "engine->evaluate(\"null\")" , |
| 404 | "engine->nullValue()" , |
| 405 | "engine->newQObject(0)" |
| 406 | }; |
| 407 | |
| 408 | void tst_QScriptValueGenerated::isNull_makeData(const char* expr) |
| 409 | { |
| 410 | static const QSet<QString> isNull = |
| 411 | charArrayToQStringSet(array: isNull_array, size: int(sizeof(isNull_array) / sizeof(const char *))); |
| 412 | newRow(tag: expr) << isNull.contains(value: expr); |
| 413 | } |
| 414 | |
| 415 | void tst_QScriptValueGenerated::isNull_test(const char*, const QScriptValue& value) |
| 416 | { |
| 417 | QFETCH(bool, expected); |
| 418 | QCOMPARE(value.isNull(), expected); |
| 419 | QCOMPARE(value.isNull(), expected); |
| 420 | } |
| 421 | |
| 422 | DEFINE_TEST_FUNCTION(isNull) |
| 423 | |
| 424 | |
| 425 | void tst_QScriptValueGenerated::isString_initData() |
| 426 | { |
| 427 | QTest::addColumn<bool>(name: "expected" ); |
| 428 | initScriptValues(); |
| 429 | } |
| 430 | |
| 431 | static const char *isString_array[] = { |
| 432 | "QScriptValue(\"NaN\")" , |
| 433 | "QScriptValue(\"Infinity\")" , |
| 434 | "QScriptValue(\"-Infinity\")" , |
| 435 | "QScriptValue(\"ciao\")" , |
| 436 | "QScriptValue(QString::fromLatin1(\"ciao\"))" , |
| 437 | "QScriptValue(QString(\"\"))" , |
| 438 | "QScriptValue(QString())" , |
| 439 | "QScriptValue(QString(\"0\"))" , |
| 440 | "QScriptValue(QString(\"123\"))" , |
| 441 | "QScriptValue(QString(\"12.4\"))" , |
| 442 | "QScriptValue(0, \"NaN\")" , |
| 443 | "QScriptValue(0, \"Infinity\")" , |
| 444 | "QScriptValue(0, \"-Infinity\")" , |
| 445 | "QScriptValue(0, \"ciao\")" , |
| 446 | "QScriptValue(0, QString::fromLatin1(\"ciao\"))" , |
| 447 | "QScriptValue(0, QString(\"\"))" , |
| 448 | "QScriptValue(0, QString())" , |
| 449 | "QScriptValue(0, QString(\"0\"))" , |
| 450 | "QScriptValue(0, QString(\"123\"))" , |
| 451 | "QScriptValue(0, QString(\"12.3\"))" , |
| 452 | "QScriptValue(engine, \"NaN\")" , |
| 453 | "QScriptValue(engine, \"Infinity\")" , |
| 454 | "QScriptValue(engine, \"-Infinity\")" , |
| 455 | "QScriptValue(engine, \"ciao\")" , |
| 456 | "QScriptValue(engine, QString::fromLatin1(\"ciao\"))" , |
| 457 | "QScriptValue(engine, QString(\"\"))" , |
| 458 | "QScriptValue(engine, QString())" , |
| 459 | "QScriptValue(engine, QString(\"0\"))" , |
| 460 | "QScriptValue(engine, QString(\"123\"))" , |
| 461 | "QScriptValue(engine, QString(\"1.23\"))" , |
| 462 | "engine->evaluate(\"'ciao'\")" , |
| 463 | "engine->evaluate(\"''\")" , |
| 464 | "engine->evaluate(\"'0'\")" , |
| 465 | "engine->evaluate(\"'123'\")" , |
| 466 | "engine->evaluate(\"'12.4'\")" |
| 467 | }; |
| 468 | |
| 469 | void tst_QScriptValueGenerated::isString_makeData(const char* expr) |
| 470 | { |
| 471 | static const QSet<QString> isString = |
| 472 | charArrayToQStringSet(array: isString_array, size: int(sizeof(isString_array) / sizeof(const char *))); |
| 473 | newRow(tag: expr) << isString.contains(value: expr); |
| 474 | } |
| 475 | |
| 476 | void tst_QScriptValueGenerated::isString_test(const char*, const QScriptValue& value) |
| 477 | { |
| 478 | QFETCH(bool, expected); |
| 479 | QCOMPARE(value.isString(), expected); |
| 480 | QCOMPARE(value.isString(), expected); |
| 481 | } |
| 482 | |
| 483 | DEFINE_TEST_FUNCTION(isString) |
| 484 | |
| 485 | |
| 486 | void tst_QScriptValueGenerated::isUndefined_initData() |
| 487 | { |
| 488 | QTest::addColumn<bool>(name: "expected" ); |
| 489 | initScriptValues(); |
| 490 | } |
| 491 | |
| 492 | static const char *isUndefined_array[] = { |
| 493 | "QScriptValue(QScriptValue::UndefinedValue)" , |
| 494 | "QScriptValue(0, QScriptValue::UndefinedValue)" , |
| 495 | "QScriptValue(engine, QScriptValue::UndefinedValue)" , |
| 496 | "engine->evaluate(\"{}\")" , |
| 497 | "engine->evaluate(\"undefined\")" , |
| 498 | "engine->undefinedValue()" |
| 499 | }; |
| 500 | |
| 501 | void tst_QScriptValueGenerated::isUndefined_makeData(const char* expr) |
| 502 | { |
| 503 | static const QSet<QString> isUndefined = |
| 504 | charArrayToQStringSet(array: isUndefined_array, size: int(sizeof(isUndefined_array) / sizeof(const char *))); |
| 505 | newRow(tag: expr) << isUndefined.contains(value: expr); |
| 506 | } |
| 507 | |
| 508 | void tst_QScriptValueGenerated::isUndefined_test(const char*, const QScriptValue& value) |
| 509 | { |
| 510 | QFETCH(bool, expected); |
| 511 | QCOMPARE(value.isUndefined(), expected); |
| 512 | QCOMPARE(value.isUndefined(), expected); |
| 513 | } |
| 514 | |
| 515 | DEFINE_TEST_FUNCTION(isUndefined) |
| 516 | |
| 517 | |
| 518 | void tst_QScriptValueGenerated::isVariant_initData() |
| 519 | { |
| 520 | QTest::addColumn<bool>(name: "expected" ); |
| 521 | initScriptValues(); |
| 522 | } |
| 523 | |
| 524 | static const char *isVariant_array[] = { |
| 525 | "engine->newVariant(QVariant())" , |
| 526 | "engine->newVariant(QVariant(123))" , |
| 527 | "engine->newVariant(QVariant(false))" |
| 528 | }; |
| 529 | |
| 530 | void tst_QScriptValueGenerated::isVariant_makeData(const char* expr) |
| 531 | { |
| 532 | static QSet<QString> isVariant = |
| 533 | charArrayToQStringSet(array: isVariant_array, size: int(sizeof(isVariant_array) / sizeof(const char *))); |
| 534 | newRow(tag: expr) << isVariant.contains(value: expr); |
| 535 | } |
| 536 | |
| 537 | void tst_QScriptValueGenerated::isVariant_test(const char*, const QScriptValue& value) |
| 538 | { |
| 539 | QFETCH(bool, expected); |
| 540 | QCOMPARE(value.isVariant(), expected); |
| 541 | QCOMPARE(value.isVariant(), expected); |
| 542 | } |
| 543 | |
| 544 | DEFINE_TEST_FUNCTION(isVariant) |
| 545 | |
| 546 | |
| 547 | void tst_QScriptValueGenerated::isQObject_initData() |
| 548 | { |
| 549 | QTest::addColumn<bool>(name: "expected" ); |
| 550 | initScriptValues(); |
| 551 | } |
| 552 | |
| 553 | void tst_QScriptValueGenerated::isQObject_makeData(const char* expr) |
| 554 | { |
| 555 | newRow(tag: expr) << (qstrcmp(str1: expr, str2: "engine->newQObject(engine)" ) == 0); |
| 556 | } |
| 557 | |
| 558 | void tst_QScriptValueGenerated::isQObject_test(const char*, const QScriptValue& value) |
| 559 | { |
| 560 | QFETCH(bool, expected); |
| 561 | QCOMPARE(value.isQObject(), expected); |
| 562 | QCOMPARE(value.isQObject(), expected); |
| 563 | } |
| 564 | |
| 565 | DEFINE_TEST_FUNCTION(isQObject) |
| 566 | |
| 567 | |
| 568 | void tst_QScriptValueGenerated::isQMetaObject_initData() |
| 569 | { |
| 570 | QTest::addColumn<bool>(name: "expected" ); |
| 571 | initScriptValues(); |
| 572 | } |
| 573 | |
| 574 | void tst_QScriptValueGenerated::isQMetaObject_makeData(const char* expr) |
| 575 | { |
| 576 | newRow(tag: expr) << (qstrcmp(str1: expr, str2: "engine->newQMetaObject(&QObject::staticMetaObject)" ) == 0); |
| 577 | } |
| 578 | |
| 579 | void tst_QScriptValueGenerated::isQMetaObject_test(const char*, const QScriptValue& value) |
| 580 | { |
| 581 | QFETCH(bool, expected); |
| 582 | QCOMPARE(value.isQMetaObject(), expected); |
| 583 | QCOMPARE(value.isQMetaObject(), expected); |
| 584 | } |
| 585 | |
| 586 | DEFINE_TEST_FUNCTION(isQMetaObject) |
| 587 | |
| 588 | |
| 589 | void tst_QScriptValueGenerated::isObject_initData() |
| 590 | { |
| 591 | QTest::addColumn<bool>(name: "expected" ); |
| 592 | initScriptValues(); |
| 593 | } |
| 594 | |
| 595 | static const char *isObject_array[] = { |
| 596 | "engine->evaluate(\"[]\")" , |
| 597 | "engine->evaluate(\"Object.prototype\")" , |
| 598 | "engine->evaluate(\"Date.prototype\")" , |
| 599 | "engine->evaluate(\"Array.prototype\")" , |
| 600 | "engine->evaluate(\"Function.prototype\")" , |
| 601 | "engine->evaluate(\"Error.prototype\")" , |
| 602 | "engine->evaluate(\"Object\")" , |
| 603 | "engine->evaluate(\"Array\")" , |
| 604 | "engine->evaluate(\"Number\")" , |
| 605 | "engine->evaluate(\"Function\")" , |
| 606 | "engine->evaluate(\"(function() { return 1; })\")" , |
| 607 | "engine->evaluate(\"(function() { return 'ciao'; })\")" , |
| 608 | "engine->evaluate(\"(function() { throw new Error('foo'); })\")" , |
| 609 | "engine->evaluate(\"/foo/\")" , |
| 610 | "engine->evaluate(\"new Object()\")" , |
| 611 | "engine->evaluate(\"new Array()\")" , |
| 612 | "engine->evaluate(\"new Error()\")" , |
| 613 | "engine->evaluate(\"new Boolean(true)\")" , |
| 614 | "engine->evaluate(\"new Boolean(false)\")" , |
| 615 | "engine->evaluate(\"new Number(123)\")" , |
| 616 | "engine->evaluate(\"new RegExp('foo', 'gim')\")" , |
| 617 | "engine->evaluate(\"new String('ciao')\")" , |
| 618 | "engine->evaluate(\"Undefined\")" , |
| 619 | "engine->evaluate(\"Null\")" , |
| 620 | "engine->evaluate(\"True\")" , |
| 621 | "engine->evaluate(\"False\")" , |
| 622 | "engine->newObject()" , |
| 623 | "engine->newArray()" , |
| 624 | "engine->newArray(10)" , |
| 625 | "engine->newDate(QDateTime())" , |
| 626 | "engine->newQMetaObject(&QObject::staticMetaObject)" , |
| 627 | "engine->newRegExp(\"foo\", \"gim\")" , |
| 628 | "engine->newVariant(QVariant())" , |
| 629 | "engine->newVariant(QVariant(123))" , |
| 630 | "engine->newVariant(QVariant(false))" , |
| 631 | "engine->newQObject(engine)" |
| 632 | }; |
| 633 | |
| 634 | void tst_QScriptValueGenerated::isObject_makeData(const char* expr) |
| 635 | { |
| 636 | static const QSet<QString> isObject = |
| 637 | charArrayToQStringSet(array: isObject_array, size: int(sizeof(isObject_array) / sizeof(const char *))); |
| 638 | newRow(tag: expr) << isObject.contains(value: expr); |
| 639 | } |
| 640 | |
| 641 | void tst_QScriptValueGenerated::isObject_test(const char*, const QScriptValue& value) |
| 642 | { |
| 643 | QFETCH(bool, expected); |
| 644 | QCOMPARE(value.isObject(), expected); |
| 645 | QCOMPARE(value.isObject(), expected); |
| 646 | } |
| 647 | |
| 648 | DEFINE_TEST_FUNCTION(isObject) |
| 649 | |
| 650 | |
| 651 | void tst_QScriptValueGenerated::isDate_initData() |
| 652 | { |
| 653 | QTest::addColumn<bool>(name: "expected" ); |
| 654 | initScriptValues(); |
| 655 | } |
| 656 | |
| 657 | static const char *isDate_array[] = { |
| 658 | "engine->evaluate(\"Date.prototype\")" , |
| 659 | "engine->newDate(QDateTime())" |
| 660 | }; |
| 661 | |
| 662 | void tst_QScriptValueGenerated::isDate_makeData(const char* expr) |
| 663 | { |
| 664 | static const QSet<QString> isDate = |
| 665 | charArrayToQStringSet(array: isDate_array, size: int(sizeof(isDate_array) / sizeof(const char *))); |
| 666 | newRow(tag: expr) << isDate.contains(value: expr); |
| 667 | } |
| 668 | |
| 669 | void tst_QScriptValueGenerated::isDate_test(const char*, const QScriptValue& value) |
| 670 | { |
| 671 | QFETCH(bool, expected); |
| 672 | QCOMPARE(value.isDate(), expected); |
| 673 | QCOMPARE(value.isDate(), expected); |
| 674 | } |
| 675 | |
| 676 | DEFINE_TEST_FUNCTION(isDate) |
| 677 | |
| 678 | |
| 679 | void tst_QScriptValueGenerated::isRegExp_initData() |
| 680 | { |
| 681 | QTest::addColumn<bool>(name: "expected" ); |
| 682 | initScriptValues(); |
| 683 | } |
| 684 | |
| 685 | static const char *isRegExp_array[] = { |
| 686 | "engine->evaluate(\"/foo/\")" , |
| 687 | "engine->evaluate(\"new RegExp('foo', 'gim')\")" , |
| 688 | "engine->newRegExp(\"foo\", \"gim\")" |
| 689 | }; |
| 690 | |
| 691 | void tst_QScriptValueGenerated::isRegExp_makeData(const char* expr) |
| 692 | { |
| 693 | static const QSet<QString> isRegExp = |
| 694 | charArrayToQStringSet(array: isRegExp_array, size: int(sizeof(isRegExp_array) / sizeof(const char *))); |
| 695 | newRow(tag: expr) << isRegExp.contains(value: expr); |
| 696 | } |
| 697 | |
| 698 | void tst_QScriptValueGenerated::isRegExp_test(const char*, const QScriptValue& value) |
| 699 | { |
| 700 | QFETCH(bool, expected); |
| 701 | QCOMPARE(value.isRegExp(), expected); |
| 702 | QCOMPARE(value.isRegExp(), expected); |
| 703 | } |
| 704 | |
| 705 | DEFINE_TEST_FUNCTION(isRegExp) |
| 706 | |
| 707 | |
| 708 | void tst_QScriptValueGenerated::isArray_initData() |
| 709 | { |
| 710 | QTest::addColumn<bool>(name: "expected" ); |
| 711 | initScriptValues(); |
| 712 | } |
| 713 | |
| 714 | static const char *isArray_array[] = { |
| 715 | "engine->evaluate(\"[]\")" , |
| 716 | "engine->evaluate(\"Array.prototype\")" , |
| 717 | "engine->evaluate(\"new Array()\")" , |
| 718 | "engine->newArray()" , |
| 719 | "engine->newArray(10)" |
| 720 | }; |
| 721 | |
| 722 | void tst_QScriptValueGenerated::isArray_makeData(const char* expr) |
| 723 | { |
| 724 | static const QSet<QString> isArray = |
| 725 | charArrayToQStringSet(array: isArray_array, size: int(sizeof(isArray_array) / sizeof(const char *))); |
| 726 | newRow(tag: expr) << isArray.contains(value: expr); |
| 727 | } |
| 728 | |
| 729 | void tst_QScriptValueGenerated::isArray_test(const char*, const QScriptValue& value) |
| 730 | { |
| 731 | QFETCH(bool, expected); |
| 732 | QCOMPARE(value.isArray(), expected); |
| 733 | QCOMPARE(value.isArray(), expected); |
| 734 | } |
| 735 | |
| 736 | DEFINE_TEST_FUNCTION(isArray) |
| 737 | |
| 738 | |
| 739 | void tst_QScriptValueGenerated::isError_initData() |
| 740 | { |
| 741 | QTest::addColumn<bool>(name: "expected" ); |
| 742 | initScriptValues(); |
| 743 | } |
| 744 | |
| 745 | static const char *isError_array[] = { |
| 746 | "engine->evaluate(\"Error.prototype\")" , |
| 747 | "engine->evaluate(\"new Error()\")" , |
| 748 | "engine->evaluate(\"Undefined\")" , |
| 749 | "engine->evaluate(\"Null\")" , |
| 750 | "engine->evaluate(\"True\")" , |
| 751 | "engine->evaluate(\"False\")" |
| 752 | }; |
| 753 | |
| 754 | void tst_QScriptValueGenerated::isError_makeData(const char* expr) |
| 755 | { |
| 756 | static QSet<QString> isError = |
| 757 | charArrayToQStringSet(array: isError_array, size: int(sizeof(isError_array) / sizeof(const char *))); |
| 758 | newRow(tag: expr) << isError.contains(value: expr); |
| 759 | } |
| 760 | |
| 761 | void tst_QScriptValueGenerated::isError_test(const char*, const QScriptValue& value) |
| 762 | { |
| 763 | QFETCH(bool, expected); |
| 764 | QCOMPARE(value.isError(), expected); |
| 765 | QCOMPARE(value.isError(), expected); |
| 766 | } |
| 767 | |
| 768 | DEFINE_TEST_FUNCTION(isError) |
| 769 | |
| 770 | |