summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-11-06 02:17:00 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-11-06 02:17:00 (GMT)
commit8b01937c36632fca8774e90d22ce2aaeb2df883d (patch)
tree1f036bcd4d27744c7a4db995d07251ef0e7f3a45 /tests/auto
parent7f6deb2d42933f59adbebc95b872e670978de3e6 (diff)
parent0c95cffd81a21f63f647dccd79ae425d157e9758 (diff)
downloadQt-8b01937c36632fca8774e90d22ce2aaeb2df883d.zip
Qt-8b01937c36632fca8774e90d22ce2aaeb2df883d.tar.gz
Qt-8b01937c36632fca8774e90d22ce2aaeb2df883d.tar.bz2
Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into master-integration
* 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1: (45 commits) mkspecs: Move QMAKE_CC and QMAKE_CXX from gcc-base.conf to g++-base.conf mkspecs: Make linux-x86-openkode-g++ not include g++.conf directly mkspecs: Include gcc-base-unix.conf from g++.conf to match old behavior configure: Deal with multiple redefinitions of qmake variables Split QScriptValue::call autotest into smaller tests. Optimize and clean up QClipData::fixup() There is no predefined qmake x11 scope for x11 builds. Refactor tst_QScriptContext::throwError test. Fixed whitespace. Don't use scopes in mkspecs as configure does not support them Fixed destination path for the S60 feedback plugin. Don't put Objective-C sources in SOURCES Fix regression in tst_maketestselftest::naming_convention. Split monolithic QScriptEngine autotests into smaller tests Add SunSpider and V8 benchmarks to benchmarks/script.pro Push and pop the thread-default context for the current thread Silence preprocessor warnings about __TARGET_ARCH_ARM not being defined. Import SunSpider benchmarks for QtScript Import V8 benchmarks for QtScript Add more microbenchmarks for QScriptValue ...
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/guiapplauncher/guiapplauncher.pro1
-rw-r--r--tests/auto/qobject/tst_qobject.cpp78
-rw-r--r--tests/auto/qscriptable/tst_qscriptable.cpp4
-rw-r--r--tests/auto/qscriptclass/tst_qscriptclass.cpp40
-rw-r--r--tests/auto/qscriptcontext/tst_qscriptcontext.cpp158
-rw-r--r--tests/auto/qscriptengine/tst_qscriptengine.cpp293
-rw-r--r--tests/auto/qscriptextensionplugin/qscriptextensionplugin.pro3
-rw-r--r--tests/auto/qscriptextensionplugin/simpleplugin/simpleplugin.cpp79
-rw-r--r--tests/auto/qscriptextensionplugin/simpleplugin/simpleplugin.pro10
-rw-r--r--tests/auto/qscriptextensionplugin/staticplugin/__init__.js6
-rw-r--r--tests/auto/qscriptextensionplugin/staticplugin/staticplugin.cpp75
-rw-r--r--tests/auto/qscriptextensionplugin/staticplugin/staticplugin.pro7
-rw-r--r--tests/auto/qscriptextensionplugin/staticplugin/staticplugin.qrc6
-rw-r--r--tests/auto/qscriptextensionplugin/test/test.pro18
-rw-r--r--tests/auto/qscriptextensionplugin/tst_qscriptextensionplugin.cpp167
-rw-r--r--tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp100
-rw-r--r--tests/auto/qscriptvalue/qscriptvalue.pro8
-rw-r--r--tests/auto/qscriptvalue/tst_qscriptvalue.cpp1512
-rw-r--r--tests/auto/qscriptvalue/tst_qscriptvalue.h401
-rw-r--r--tests/auto/qscriptvaluegenerated/.gitignore1
-rw-r--r--tests/auto/qscriptvaluegenerated/qscriptvaluegenerated.pro18
-rw-r--r--tests/auto/qscriptvaluegenerated/testgen/data.txt (renamed from tests/auto/qscriptvalue/testgen/data.txt)0
-rwxr-xr-xtests/auto/qscriptvaluegenerated/testgen/gen.py (renamed from tests/auto/qscriptvalue/testgen/gen.py)0
-rw-r--r--tests/auto/qscriptvaluegenerated/testgen/main.cpp (renamed from tests/auto/qscriptvalue/testgen/main.cpp)0
-rw-r--r--tests/auto/qscriptvaluegenerated/testgen/testgen.pro (renamed from tests/auto/qscriptvalue/testgen/testgen.pro)0
-rw-r--r--tests/auto/qscriptvaluegenerated/testgen/testgenerator.cpp (renamed from tests/auto/qscriptvalue/testgen/testgenerator.cpp)0
-rw-r--r--tests/auto/qscriptvaluegenerated/testgen/testgenerator.h (renamed from tests/auto/qscriptvalue/testgen/testgenerator.h)0
-rw-r--r--tests/auto/qscriptvaluegenerated/tst_qscriptvalue.cpp116
-rw-r--r--tests/auto/qscriptvaluegenerated/tst_qscriptvalue.h370
-rw-r--r--tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_cast.cpp (renamed from tests/auto/qscriptvalue/tst_qscriptvalue_generated_cast.cpp)36
-rw-r--r--tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_comparison.cpp (renamed from tests/auto/qscriptvalue/tst_qscriptvalue_generated_comparison.cpp)24
-rw-r--r--tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_init.cpp (renamed from tests/auto/qscriptvalue/tst_qscriptvalue_generated_init.cpp)2
-rw-r--r--tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_isXXX.cpp (renamed from tests/auto/qscriptvalue/tst_qscriptvalue_generated_isXXX.cpp)96
-rw-r--r--tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_toXXX.cpp (renamed from tests/auto/qscriptvalue/tst_qscriptvalue_generated_toXXX.cpp)48
-rw-r--r--tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp21
-rw-r--r--tests/auto/qthread/tst_qthread.cpp14
-rw-r--r--tests/auto/script.pro2
37 files changed, 2562 insertions, 1152 deletions
diff --git a/tests/auto/guiapplauncher/guiapplauncher.pro b/tests/auto/guiapplauncher/guiapplauncher.pro
index 30f5cf4..1fe9c8b 100644
--- a/tests/auto/guiapplauncher/guiapplauncher.pro
+++ b/tests/auto/guiapplauncher/guiapplauncher.pro
@@ -3,6 +3,7 @@
# -------------------------------------------------
# Link against gui for X11,etc.
+load(qttest_p4)
DEFINES += SRCDIR=\\\"$$PWD/\\\"
TARGET = tst_guiapplauncher
diff --git a/tests/auto/qobject/tst_qobject.cpp b/tests/auto/qobject/tst_qobject.cpp
index 24cd5a3..a09f109 100644
--- a/tests/auto/qobject/tst_qobject.cpp
+++ b/tests/auto/qobject/tst_qobject.cpp
@@ -134,6 +134,7 @@ private slots:
void connectConstructorByMetaMethod();
void disconnectByMetaMethod();
void disconnectNotSignalMetaMethod();
+ void autoConnectionBehavior();
protected:
};
@@ -3847,5 +3848,82 @@ void tst_QObject::disconnectNotSignalMetaMethod()
QVERIFY(!QObject::disconnect(&s, slot, &r, QMetaMethod()));
}
+class ThreadAffinityThread : public QThread
+{
+public:
+ SenderObject *sender;
+
+ ThreadAffinityThread(SenderObject *sender)
+ : sender(sender)
+ { }
+ void run()
+ {
+ sender->emitSignal1();
+ }
+};
+
+void tst_QObject::autoConnectionBehavior()
+{
+ SenderObject *sender = new SenderObject;
+ ReceiverObject *receiver = new ReceiverObject;
+ connect(sender, SIGNAL(signal1()), receiver, SLOT(slot1()));
+
+ // at emit, currentThread == sender->thread(), currentThread == receiver->thread(), sender->thread() == receiver->thread()
+ QVERIFY(!receiver->called(1));
+ sender->emitSignal1();
+ QVERIFY(receiver->called(1));
+ receiver->reset();
+
+ // at emit, currentThread != sender->thread(), currentThread != receiver->thread(), sender->thread() == receiver->thread()
+ ThreadAffinityThread emitThread1(sender);
+ QVERIFY(!receiver->called(1));
+ emitThread1.start();
+ QVERIFY(emitThread1.wait(30000));
+ QVERIFY(!receiver->called(1));
+ QCoreApplication::sendPostedEvents(receiver, QEvent::MetaCall);
+ QVERIFY(receiver->called(1));
+ receiver->reset();
+
+ // at emit, currentThread == sender->thread(), currentThread != receiver->thread(), sender->thread() != receiver->thread()
+ sender->moveToThread(&emitThread1);
+ QVERIFY(!receiver->called(1));
+ emitThread1.start();
+ QVERIFY(emitThread1.wait(30000));
+ QVERIFY(!receiver->called(1));
+ QCoreApplication::sendPostedEvents(receiver, QEvent::MetaCall);
+ QVERIFY(receiver->called(1));
+ receiver->reset();
+
+ // at emit, currentThread != sender->thread(), currentThread == receiver->thread(), sender->thread() != receiver->thread()
+ QVERIFY(!receiver->called(1));
+ sender->emitSignal1();
+ QVERIFY(receiver->called(1));
+ receiver->reset();
+
+ // at emit, currentThread != sender->thread(), currentThread != receiver->thread(), sender->thread() != receiver->thread()
+ ThreadAffinityThread emitThread2(sender);
+ QThread receiverThread;
+ QTimer *timer = new QTimer;
+ timer->setSingleShot(true);
+ timer->setInterval(100);
+ connect(&receiverThread, SIGNAL(started()), timer, SLOT(start()));
+ connect(timer, SIGNAL(timeout()), &receiverThread, SLOT(quit()), Qt::DirectConnection);
+ connect(&receiverThread, SIGNAL(finished()), timer, SLOT(deleteLater()));
+ timer->moveToThread(&receiverThread);
+
+ receiver->moveToThread(&receiverThread);
+ QVERIFY(!receiver->called(1));
+ emitThread2.start();
+ QVERIFY(emitThread2.wait(30000));
+ QVERIFY(!receiver->called(1));
+ receiverThread.start();
+ QVERIFY(receiverThread.wait(30000));
+ QVERIFY(receiver->called(1));
+ receiver->reset();
+
+ delete sender;
+ delete receiver;
+}
+
QTEST_MAIN(tst_QObject)
#include "tst_qobject.moc"
diff --git a/tests/auto/qscriptable/tst_qscriptable.cpp b/tests/auto/qscriptable/tst_qscriptable.cpp
index 3c781b1..86dd80e 100644
--- a/tests/auto/qscriptable/tst_qscriptable.cpp
+++ b/tests/auto/qscriptable/tst_qscriptable.cpp
@@ -131,7 +131,7 @@ QScriptValue MyScriptable::getArguments()
int MyScriptable::getArgumentCount()
{
- return context()->argumentCount();
+ return argumentCount();
}
void MyScriptable::foo()
@@ -283,6 +283,8 @@ void tst_QScriptable::engine()
void tst_QScriptable::thisObject()
{
+ QVERIFY(!m_scriptable.thisObject().isValid());
+
m_engine.evaluate("o = { }");
{
QScriptValue ret = m_engine.evaluate("o.__proto__ = scriptable;"
diff --git a/tests/auto/qscriptclass/tst_qscriptclass.cpp b/tests/auto/qscriptclass/tst_qscriptclass.cpp
index b4dbe73..2c669f3 100644
--- a/tests/auto/qscriptclass/tst_qscriptclass.cpp
+++ b/tests/auto/qscriptclass/tst_qscriptclass.cpp
@@ -68,6 +68,7 @@ private slots:
void getAndSetProperty();
void enumerate();
void extension();
+ void defaultImplementations();
};
tst_QScriptClass::tst_QScriptClass()
@@ -603,6 +604,8 @@ void tst_QScriptClass::newInstance()
QVERIFY(obj2.data().strictlyEquals(num));
QVERIFY(obj2.prototype().strictlyEquals(cls.prototype()));
QCOMPARE(obj2.scriptClass(), (QScriptClass*)&cls);
+ QVERIFY(!obj2.equals(obj1));
+ QVERIFY(!obj2.strictlyEquals(obj1));
QScriptValue obj3 = eng.newObject();
QCOMPARE(obj3.scriptClass(), (QScriptClass*)0);
@@ -730,6 +733,14 @@ void tst_QScriptClass::getAndSetProperty()
QCOMPARE(cls.lastPropertyId(), foo2Id);
}
+ // attempt to delete custom property
+ obj1.setProperty(foo2, QScriptValue());
+ // delete real property
+ obj1.setProperty(foo, QScriptValue());
+ QVERIFY(!obj1.property(foo).isValid());
+ obj1.setProperty(foo, num);
+ QVERIFY(obj1.property(foo).equals(num));
+
// remove script class; normal properties should remain
obj1.setScriptClass(0);
QCOMPARE(obj1.scriptClass(), (QScriptClass*)0);
@@ -805,6 +816,7 @@ void tst_QScriptClass::extension()
QCOMPARE((int)cls.lastExtensionType(), -1);
QVERIFY(!obj.instanceOf(obj));
QCOMPARE((int)cls.lastExtensionType(), -1);
+ QVERIFY(!obj.construct().isValid());
}
// Callable
{
@@ -1017,5 +1029,33 @@ void tst_QScriptClass::extension()
}
}
+void tst_QScriptClass::defaultImplementations()
+{
+ QScriptEngine eng;
+
+ QScriptClass defaultClass(&eng);
+ QCOMPARE(defaultClass.engine(), &eng);
+ QVERIFY(!defaultClass.prototype().isValid());
+ QCOMPARE(defaultClass.name(), QString());
+
+ QScriptValue obj = eng.newObject(&defaultClass);
+ QCOMPARE(obj.scriptClass(), &defaultClass);
+
+ QScriptString name = eng.toStringHandle("foo");
+ uint id = -1;
+ QCOMPARE(defaultClass.queryProperty(obj, name, QScriptClass::HandlesReadAccess, &id), QScriptClass::QueryFlags(0));
+ QVERIFY(!defaultClass.property(obj, name, id).isValid());
+ QCOMPARE(defaultClass.propertyFlags(obj, name, id), QScriptValue::PropertyFlags(0));
+ defaultClass.setProperty(obj, name, id, 123);
+ QVERIFY(!obj.property(name).isValid());
+
+ QCOMPARE(defaultClass.newIterator(obj), (QScriptClassPropertyIterator*)0);
+
+ QVERIFY(!defaultClass.supportsExtension(QScriptClass::Callable));
+ QVERIFY(!defaultClass.supportsExtension(QScriptClass::HasInstance));
+ QVERIFY(!defaultClass.extension(QScriptClass::Callable).isValid());
+ QVERIFY(!defaultClass.extension(QScriptClass::HasInstance).isValid());
+}
+
QTEST_MAIN(tst_QScriptClass)
#include "tst_qscriptclass.moc"
diff --git a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
index 617c183..cbcd16a 100644
--- a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
+++ b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
@@ -44,6 +44,7 @@
#include <QtScript/qscriptcontext.h>
#include <QtScript/qscriptengine.h>
+#include <QtScript/qscriptvalueiterator.h>
//TESTED_CLASS=
//TESTED_FILES=
@@ -67,7 +68,11 @@ private slots:
void arguments();
void thisObject();
void returnValue();
- void throwError();
+ void throwError_data();
+ void throwError_fromEvaluate_data();
+ void throwError_fromEvaluate();
+ void throwError_fromCpp_data();
+ void throwError_fromCpp();
void throwValue();
void evaluateInFunction();
void pushAndPopContext();
@@ -77,6 +82,7 @@ private slots:
void scopeChain();
void pushAndPopScope();
void getSetActivationObject();
+ void getSetActivationObject_customContext();
void inheritActivationAndThisObject();
void toString();
void calledAsConstructor();
@@ -360,73 +366,71 @@ static QScriptValue throw_ErrorAndReturnUndefined(QScriptContext *ctx, QScriptEn
return eng->undefinedValue();
}
-void tst_QScriptContext::throwError()
+static QScriptValue throw_ErrorAndReturnString(QScriptContext *ctx, QScriptEngine *)
{
- QScriptEngine eng;
+ return ctx->throwError(QScriptContext::UnknownError, "foo").toString();
+}
- {
- QScriptValue fun = eng.newFunction(throw_Error);
- eng.globalObject().setProperty("throw_Error", fun);
- QScriptValue result = eng.evaluate("throw_Error()");
- QCOMPARE(eng.hasUncaughtException(), true);
- QCOMPARE(result.isError(), true);
- QCOMPARE(result.toString(), QString("Error: foo"));
- }
+static QScriptValue throw_ErrorAndReturnObject(QScriptContext *ctx, QScriptEngine *eng)
+{
+ ctx->throwError(QScriptContext::UnknownError, "foo");
+ return eng->newObject();
+}
- {
- QScriptValue fun = eng.newFunction(throw_TypeError);
- eng.globalObject().setProperty("throw_TypeError", fun);
- QScriptValue result = eng.evaluate("throw_TypeError()");
- QCOMPARE(eng.hasUncaughtException(), true);
- QCOMPARE(result.isError(), true);
- QCOMPARE(result.toString(), QString("TypeError: foo"));
- }
+void tst_QScriptContext::throwError_data()
+{
+ QTest::addColumn<void*>("nativeFunctionPtr");
+ QTest::addColumn<QString>("stringRepresentation");
+
+ QTest::newRow("Error") << reinterpret_cast<void*>(throw_Error) << QString("Error: foo");
+ QTest::newRow("TypeError") << reinterpret_cast<void*>(throw_TypeError) << QString("TypeError: foo");
+ QTest::newRow("ReferenceError") << reinterpret_cast<void*>(throw_ReferenceError) << QString("ReferenceError: foo");
+ QTest::newRow("SyntaxError") << reinterpret_cast<void*>(throw_SyntaxError) << QString("SyntaxError: foo");
+ QTest::newRow("RangeError") << reinterpret_cast<void*>(throw_RangeError) << QString("RangeError: foo");
+ QTest::newRow("URIError") << reinterpret_cast<void*>(throw_URIError) << QString("URIError: foo");
+ QTest::newRow("ErrorAndReturnUndefined") << reinterpret_cast<void*>(throw_ErrorAndReturnUndefined) << QString("Error: foo");
+ QTest::newRow("ErrorAndReturnString") << reinterpret_cast<void*>(throw_ErrorAndReturnString) << QString("Error: foo");
+ QTest::newRow("ErrorAndReturnObject") << reinterpret_cast<void*>(throw_ErrorAndReturnObject) << QString("Error: foo");
+}
- {
- QScriptValue fun = eng.newFunction(throw_ReferenceError);
- eng.globalObject().setProperty("throw_ReferenceError", fun);
- QScriptValue result = eng.evaluate("throw_ReferenceError()");
- QCOMPARE(eng.hasUncaughtException(), true);
- QCOMPARE(result.isError(), true);
- QCOMPARE(result.toString(), QString("ReferenceError: foo"));
- }
+void tst_QScriptContext::throwError_fromEvaluate_data()
+{
+ throwError_data();
+}
- {
- QScriptValue fun = eng.newFunction(throw_SyntaxError);
- eng.globalObject().setProperty("throw_SyntaxError", fun);
- QScriptValue result = eng.evaluate("throw_SyntaxError()");
- QCOMPARE(eng.hasUncaughtException(), true);
- QCOMPARE(result.isError(), true);
- QCOMPARE(result.toString(), QString("SyntaxError: foo"));
- }
+void tst_QScriptContext::throwError_fromEvaluate()
+{
+ QFETCH(void*, nativeFunctionPtr);
+ QScriptEngine::FunctionSignature nativeFunction = reinterpret_cast<QScriptEngine::FunctionSignature>(nativeFunctionPtr);
+ QFETCH(QString, stringRepresentation);
+ QScriptEngine engine;
- {
- QScriptValue fun = eng.newFunction(throw_RangeError);
- eng.globalObject().setProperty("throw_RangeError", fun);
- QScriptValue result = eng.evaluate("throw_RangeError()");
- QCOMPARE(eng.hasUncaughtException(), true);
- QCOMPARE(result.isError(), true);
- QCOMPARE(result.toString(), QString("RangeError: foo"));
- }
+ QScriptValue fun = engine.newFunction(nativeFunction);
+ engine.globalObject().setProperty("throw_Error", fun);
+ QScriptValue result = engine.evaluate("throw_Error()");
+ QCOMPARE(engine.hasUncaughtException(), true);
+ QCOMPARE(result.isError(), true);
+ QCOMPARE(result.toString(), stringRepresentation);
+}
- {
- QScriptValue fun = eng.newFunction(throw_URIError);
- eng.globalObject().setProperty("throw_URIError", fun);
- QScriptValue result = eng.evaluate("throw_URIError()");
- QCOMPARE(eng.hasUncaughtException(), true);
- QCOMPARE(result.isError(), true);
- QCOMPARE(result.toString(), QString("URIError: foo"));
- }
+void tst_QScriptContext::throwError_fromCpp_data()
+{
+ throwError_data();
+}
- {
- QScriptValue fun = eng.newFunction(throw_ErrorAndReturnUndefined);
- eng.globalObject().setProperty("throw_ErrorAndReturnUndefined", fun);
- QScriptValue result = eng.evaluate("throw_ErrorAndReturnUndefined()");
- QVERIFY(eng.hasUncaughtException());
- QVERIFY(result.isError());
- QCOMPARE(result.toString(), QString("Error: foo"));
- }
+void tst_QScriptContext::throwError_fromCpp()
+{
+ QFETCH(void*, nativeFunctionPtr);
+ QScriptEngine::FunctionSignature nativeFunction = reinterpret_cast<QScriptEngine::FunctionSignature>(nativeFunctionPtr);
+ QFETCH(QString, stringRepresentation);
+ QScriptEngine engine;
+ QScriptValue fun = engine.newFunction(nativeFunction);
+ engine.globalObject().setProperty("throw_Error", fun);
+ QScriptValue result = fun.call();
+ QCOMPARE(engine.hasUncaughtException(), true);
+ QCOMPARE(result.isError(), true);
+ QCOMPARE(result.toString(), stringRepresentation);
}
static QScriptValue throw_value(QScriptContext *ctx, QScriptEngine *)
@@ -513,8 +517,30 @@ void tst_QScriptContext::pushAndPopContext()
QScriptContext *ctx3 = eng.pushContext();
ctx3->activationObject().setProperty("foo", QScriptValue(&eng, 123));
QVERIFY(eng.evaluate("foo").strictlyEquals(QScriptValue(&eng, 123)));
+ QCOMPARE(ctx3->activationObject().propertyFlags("foo"), QScriptValue::PropertyFlags(0));
+
+ ctx3->activationObject().setProperty(4, 456);
+ QVERIFY(ctx3->activationObject().property(4, QScriptValue::ResolveLocal).equals(456));
+
eng.evaluate("var bar = 'ciao'");
QVERIFY(ctx3->activationObject().property("bar", QScriptValue::ResolveLocal).strictlyEquals(QScriptValue(&eng, "ciao")));
+
+ ctx3->activationObject().setProperty("baz", 789, QScriptValue::ReadOnly);
+ QVERIFY(eng.evaluate("baz").equals(789));
+ QCOMPARE(ctx3->activationObject().propertyFlags("baz"), QScriptValue::ReadOnly);
+
+ QSet<QString> activationPropertyNames;
+ QScriptValueIterator it(ctx3->activationObject());
+ while (it.hasNext()) {
+ it.next();
+ activationPropertyNames.insert(it.name());
+ }
+ QCOMPARE(activationPropertyNames.size(), 4);
+ QVERIFY(activationPropertyNames.contains("foo"));
+ QVERIFY(activationPropertyNames.contains("4"));
+ QVERIFY(activationPropertyNames.contains("bar"));
+ QVERIFY(activationPropertyNames.contains("baz"));
+
eng.popContext();
}
@@ -1054,6 +1080,20 @@ void tst_QScriptContext::getSetActivationObject()
}
}
+void tst_QScriptContext::getSetActivationObject_customContext()
+{
+ QScriptEngine eng;
+ QScriptContext *ctx = eng.pushContext();
+ QVERIFY(ctx->activationObject().isObject());
+ QScriptValue act = eng.newObject();
+ ctx->setActivationObject(act);
+ QVERIFY(ctx->activationObject().equals(act));
+ eng.evaluate("var foo = 123");
+ QCOMPARE(act.property("foo").toInt32(), 123);
+ eng.popContext();
+ QCOMPARE(act.property("foo").toInt32(), 123);
+}
+
static QScriptValue myEval(QScriptContext *ctx, QScriptEngine *eng)
{
QString code = ctx->argument(0).toString();
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp
index 7133a6c..5f38c22 100644
--- a/tests/auto/qscriptengine/tst_qscriptengine.cpp
+++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp
@@ -95,16 +95,33 @@ private slots:
void pushPopContext();
void getSetDefaultPrototype();
void newFunction();
+ void newFunctionWithArg();
+ void newFunctionWithProto();
void newObject();
void newArray();
+ void newArray_HooliganTask218092();
+ void newArray_HooliganTask233836();
void newVariant();
+ void newVariant_defaultPrototype();
+ void newVariant_promoteObject();
+ void newVariant_replaceValue();
+ void newVariant_valueOfToString();
+ void newVariant_promoteNonObject();
+ void newVariant_promoteNonQScriptObject();
void newRegExp();
void newDate();
void newQObject();
+ void newQObject_ownership();
+ void newQObject_promoteObject();
+ void newQObject_sameQObject();
+ void newQObject_defaultPrototype();
+ void newQObject_promoteNonObject();
+ void newQObject_promoteNonQScriptObject();
void newQMetaObject();
void newActivationObject();
void getSetGlobalObject();
void globalObjectProperties();
+ void createGlobalObjectProperty();
void globalObjectGetterSetterProperty();
void customGlobalObjectWithPrototype();
void globalObjectWithCustomPrototype();
@@ -120,6 +137,7 @@ private slots:
void uncaughtException();
void errorMessage_QT679();
void valueConversion();
+ void qScriptValueFromValue_noEngine();
void importExtension();
void infiniteRecursion();
void castWithPrototypeChain();
@@ -129,6 +147,7 @@ private slots:
void gcWithNestedDataStructure();
void processEventsWhileRunning();
void throwErrorFromProcessEvents();
+ void disableProcessEventsInterval();
void stacktrace();
void numberParsing_data();
void numberParsing();
@@ -144,7 +163,10 @@ private slots:
void forInStatement();
void functionExpression();
void stringObjects();
- void getterSetterThisObject();
+ void getterSetterThisObject_global();
+ void getterSetterThisObject_plain();
+ void getterSetterThisObject_prototypeChain();
+ void getterSetterThisObject_activation();
void continueInSwitch();
void readOnlyPrototypeProperty();
void toObject();
@@ -167,8 +189,14 @@ private slots:
void functionScopes();
void nativeFunctionScopes();
void evaluateProgram();
+ void evaluateProgram_customScope();
+ void evaluateProgram_closure();
+ void evaluateProgram_executeLater();
+ void evaluateProgram_multipleEngines();
+ void evaluateProgram_empty();
void collectGarbageAfterConnect();
void promoteThisObjectToQObjectInConstructor();
+ void scriptValueFromQMetaObject();
void qRegExpInport_data();
void qRegExpInport();
@@ -288,8 +316,11 @@ void tst_QScriptEngine::newFunction()
QCOMPARE(fun.call().isNull(), true);
QCOMPARE(fun.construct().isObject(), true);
}
+}
- // the overload that takes a void*
+void tst_QScriptEngine::newFunctionWithArg()
+{
+ QScriptEngine eng;
{
QScriptValue fun = eng.newFunction(myFunctionWithVoidArg, (void*)this);
QVERIFY(fun.isFunction());
@@ -310,8 +341,11 @@ void tst_QScriptEngine::newFunction()
QCOMPARE(fun.call().isNull(), true);
QCOMPARE(fun.construct().isObject(), true);
}
+}
- // the overload that takes a prototype
+void tst_QScriptEngine::newFunctionWithProto()
+{
+ QScriptEngine eng;
{
QScriptValue proto = eng.newObject();
QScriptValue fun = eng.newFunction(myFunction, proto);
@@ -361,8 +395,11 @@ void tst_QScriptEngine::newArray()
QCOMPARE(array.prototype().isValid(), true);
QCOMPARE(array.prototype().isArray(), true);
QCOMPARE(array.prototype().strictlyEquals(eng.evaluate("Array.prototype")), true);
+}
- // task 218092
+void tst_QScriptEngine::newArray_HooliganTask218092()
+{
+ QScriptEngine eng;
{
QScriptValue ret = eng.evaluate("[].splice(0, 0, 'a')");
QVERIFY(ret.isArray());
@@ -388,8 +425,11 @@ void tst_QScriptEngine::newArray()
QVERIFY(ret.isArray());
QCOMPARE(ret.property("length").toInt32(), 2);
}
+}
- // task 233836
+void tst_QScriptEngine::newArray_HooliganTask233836()
+{
+ QScriptEngine eng;
{
QScriptValue ret = eng.evaluate("a = new Array(4294967295); a.push('foo')");
QVERIFY(ret.isNumber());
@@ -423,7 +463,12 @@ void tst_QScriptEngine::newVariant()
QCOMPARE(opaque.prototype().isVariant(), true);
QVERIFY(opaque.property("valueOf").call(opaque).isUndefined());
}
+}
+
+void tst_QScriptEngine::newVariant_defaultPrototype()
+{
// default prototype should be set automatically
+ QScriptEngine eng;
{
QScriptValue proto = eng.newObject();
eng.setDefaultPrototype(qMetaTypeId<QString>(), proto);
@@ -436,7 +481,12 @@ void tst_QScriptEngine::newVariant()
QVERIFY(ret2.isVariant());
QVERIFY(!ret2.prototype().strictlyEquals(proto));
}
+}
+
+void tst_QScriptEngine::newVariant_promoteObject()
+{
// "promote" plain object to variant
+ QScriptEngine eng;
{
QScriptValue object = eng.newObject();
object.setProperty("foo", eng.newObject());
@@ -453,17 +503,28 @@ void tst_QScriptEngine::newVariant()
QCOMPARE(ret.toVariant(), QVariant(123));
QVERIFY(ret.prototype().strictlyEquals(originalProto));
}
+}
+
+void tst_QScriptEngine::newVariant_replaceValue()
+{
// replace value of existing object
+ QScriptEngine eng;
{
QScriptValue object = eng.newVariant(QVariant(123));
- QScriptValue ret = eng.newVariant(object, QVariant(456));
- QVERIFY(ret.isValid());
- QVERIFY(ret.strictlyEquals(object));
- QVERIFY(ret.isVariant());
- QCOMPARE(ret.toVariant(), QVariant(456));
+ for (int x = 0; x < 2; ++x) {
+ QScriptValue ret = eng.newVariant(object, QVariant(456));
+ QVERIFY(ret.isValid());
+ QVERIFY(ret.strictlyEquals(object));
+ QVERIFY(ret.isVariant());
+ QCOMPARE(ret.toVariant(), QVariant(456));
+ }
}
+}
+void tst_QScriptEngine::newVariant_valueOfToString()
+{
// valueOf() and toString()
+ QScriptEngine eng;
{
QScriptValue object = eng.newVariant(QVariant(123));
QScriptValue value = object.property("valueOf").call(object);
@@ -497,6 +558,27 @@ void tst_QScriptEngine::newVariant()
}
}
+void tst_QScriptEngine::newVariant_promoteNonObject()
+{
+ QScriptEngine eng;
+ {
+ QVariant var(456);
+ QScriptValue ret = eng.newVariant(123, var);
+ QVERIFY(ret.isVariant());
+ QCOMPARE(ret.toVariant(), var);
+ }
+}
+
+void tst_QScriptEngine::newVariant_promoteNonQScriptObject()
+{
+ QScriptEngine eng;
+ {
+ QTest::ignoreMessage(QtWarningMsg, "QScriptEngine::newVariant(): changing class of non-QScriptObject not supported");
+ QScriptValue ret = eng.newVariant(eng.newArray(), 123);
+ QVERIFY(!ret.isValid());
+ }
+}
+
void tst_QScriptEngine::newRegExp()
{
QScriptEngine eng;
@@ -645,8 +727,11 @@ void tst_QScriptEngine::newQObject()
QCOMPARE(qobject.prototype().isQObject(), true);
QCOMPARE(qobject.scriptClass(), (QScriptClass*)0);
}
+}
- // test ownership
+void tst_QScriptEngine::newQObject_ownership()
+{
+ QScriptEngine eng;
{
QPointer<QObject> ptr = new QObject();
QVERIFY(ptr != 0);
@@ -701,7 +786,11 @@ void tst_QScriptEngine::newQObject()
QVERIFY(child != 0);
delete parent;
}
+}
+void tst_QScriptEngine::newQObject_promoteObject()
+{
+ QScriptEngine eng;
// "promote" plain object to QObject
{
QScriptValue obj = eng.newObject();
@@ -733,14 +822,20 @@ void tst_QScriptEngine::newQObject()
QScriptValue object = eng.newVariant(123);
QScriptValue originalProto = object.prototype();
QObject otherQObject;
- QScriptValue ret = eng.newQObject(object, &otherQObject);
- QVERIFY(ret.isValid());
- QVERIFY(ret.isQObject());
- QVERIFY(ret.strictlyEquals(object));
- QCOMPARE(ret.toQObject(), (QObject *)&otherQObject);
- QVERIFY(ret.prototype().strictlyEquals(originalProto));
+ for (int x = 0; x < 2; ++x) {
+ QScriptValue ret = eng.newQObject(object, &otherQObject);
+ QVERIFY(ret.isValid());
+ QVERIFY(ret.isQObject());
+ QVERIFY(ret.strictlyEquals(object));
+ QCOMPARE(ret.toQObject(), (QObject *)&otherQObject);
+ QVERIFY(ret.prototype().strictlyEquals(originalProto));
+ }
}
+}
+void tst_QScriptEngine::newQObject_sameQObject()
+{
+ QScriptEngine eng;
// calling newQObject() several times with same object
for (int x = 0; x < 2; ++x) {
QObject qobj;
@@ -771,7 +866,11 @@ void tst_QScriptEngine::newQObject()
QScriptEngine::ExcludeSuperClassMethods | opt);
QCOMPARE(obj8.strictlyEquals(obj7), preferExisting);
}
+}
+void tst_QScriptEngine::newQObject_defaultPrototype()
+{
+ QScriptEngine eng;
// newQObject() should set the default prototype, if one has been registered
{
QScriptValue oldQObjectProto = eng.defaultPrototype(qMetaTypeId<QObject*>());
@@ -795,6 +894,26 @@ void tst_QScriptEngine::newQObject()
}
}
+void tst_QScriptEngine::newQObject_promoteNonObject()
+{
+ QScriptEngine eng;
+ {
+ QScriptValue ret = eng.newQObject(123, this);
+ QVERIFY(ret.isQObject());
+ QCOMPARE(ret.toQObject(), this);
+ }
+}
+
+void tst_QScriptEngine::newQObject_promoteNonQScriptObject()
+{
+ QScriptEngine eng;
+ {
+ QTest::ignoreMessage(QtWarningMsg, "QScriptEngine::newQObject(): changing class of non-QScriptObject not supported");
+ QScriptValue ret = eng.newQObject(eng.newArray(), this);
+ QVERIFY(!ret.isValid());
+ }
+}
+
QT_BEGIN_NAMESPACE
Q_SCRIPT_DECLARE_QMETAOBJECT(QObject, QObject*)
Q_SCRIPT_DECLARE_QMETAOBJECT(QWidget, QWidget*)
@@ -981,6 +1100,11 @@ void tst_QScriptEngine::getSetGlobalObject()
QCOMPARE(glob.prototype().isObject(), true);
QCOMPARE(glob.prototype().strictlyEquals(eng.evaluate("Object.prototype")), true);
+ eng.setGlobalObject(glob);
+ QVERIFY(eng.globalObject().equals(glob));
+ eng.setGlobalObject(123);
+ QVERIFY(eng.globalObject().equals(glob));
+
QScriptValue obj = eng.newObject();
eng.setGlobalObject(obj);
QVERIFY(eng.globalObject().strictlyEquals(obj));
@@ -1030,6 +1154,28 @@ void tst_QScriptEngine::getSetGlobalObject()
QScriptValue ret = eng.evaluate("(function() { return this; })()");
QVERIFY(ret.strictlyEquals(obj));
}
+
+ // Delete property.
+ {
+ QScriptValue ret = eng.evaluate("delete foo");
+ QVERIFY(ret.isBool());
+ QVERIFY(ret.toBool());
+ QVERIFY(!obj.property("foo").isValid());
+ }
+
+ // Getter/setter property.
+ QVERIFY(eng.evaluate("this.__defineGetter__('oof', function() { return this.bar; })").isUndefined());
+ QVERIFY(eng.evaluate("this.__defineSetter__('oof', function(v) { this.bar = v; })").isUndefined());
+ QVERIFY(eng.evaluate("this.__lookupGetter__('oof')").isFunction());
+ QVERIFY(eng.evaluate("this.__lookupSetter__('oof')").isFunction());
+ eng.evaluate("oof = 123");
+ QVERIFY(eng.evaluate("oof").equals(obj.property("bar")));
+
+ // Enumeration.
+ {
+ QScriptValue ret = eng.evaluate("a = []; for (var p in this) a.push(p); a");
+ QCOMPARE(ret.toString(), QString::fromLatin1("bar,baz,oof,p,a"));
+ }
}
static QScriptValue getSetFoo(QScriptContext *ctx, QScriptEngine *)
@@ -1176,7 +1322,12 @@ void tst_QScriptEngine::globalObjectProperties()
}
}
QVERIFY(remainingNames.isEmpty());
+}
+void tst_QScriptEngine::createGlobalObjectProperty()
+{
+ QScriptEngine eng;
+ QScriptValue global = eng.globalObject();
// create property with no attributes
{
QString name = QString::fromLatin1("foo");
@@ -2256,6 +2407,14 @@ void tst_QScriptEngine::valueConversion()
QEXPECT_FAIL("", "QTBUG-6136: JSC-based back-end doesn't preserve QRegExp::minimal (always false)", Continue);
QCOMPARE(val.toRegExp().isMinimal(), in.isMinimal());
}
+
+ QCOMPARE(qscriptvalue_cast<QVariant>(QScriptValue(123)), QVariant(123));
+}
+
+void tst_QScriptEngine::qScriptValueFromValue_noEngine()
+{
+ QVERIFY(!qScriptValueFromValue(0, 123).isValid());
+ QVERIFY(!qScriptValueFromValue(0, QVariant(123)).isValid());
}
static QScriptValue __import__(QScriptContext *ctx, QScriptEngine *eng)
@@ -2694,6 +2853,19 @@ void tst_QScriptEngine::throwErrorFromProcessEvents()
QCOMPARE(ret.toString(), QString::fromLatin1("Error: Killed"));
}
+void tst_QScriptEngine::disableProcessEventsInterval()
+{
+ QScriptEngine eng;
+ eng.setProcessEventsInterval(100);
+ QCOMPARE(eng.processEventsInterval(), 100);
+ eng.setProcessEventsInterval(0);
+ QCOMPARE(eng.processEventsInterval(), 0);
+ eng.setProcessEventsInterval(-1);
+ QCOMPARE(eng.processEventsInterval(), -1);
+ eng.setProcessEventsInterval(-100);
+ QCOMPARE(eng.processEventsInterval(), -100);
+}
+
void tst_QScriptEngine::stacktrace()
{
QString script = QString::fromLatin1(
@@ -3730,9 +3902,8 @@ void tst_QScriptEngine::stringObjects()
}
}
-void tst_QScriptEngine::getterSetterThisObject()
+void tst_QScriptEngine::getterSetterThisObject_global()
{
- // Global Object
{
QScriptEngine eng;
// read
@@ -3790,8 +3961,10 @@ void tst_QScriptEngine::getterSetterThisObject()
QCOMPARE(ret.toString(), QString::fromLatin1("foo"));
}
}
+}
- // other object
+void tst_QScriptEngine::getterSetterThisObject_plain()
+{
{
QScriptEngine eng;
eng.evaluate("o = {}");
@@ -3808,8 +3981,10 @@ void tst_QScriptEngine::getterSetterThisObject()
QVERIFY(eng.evaluate("with (o) x = 'foo'").equals("foo"));
QVERIFY(eng.evaluate("with (o) with (q) x = 'foo'").equals("foo"));
}
+}
- // getter+setter in prototype chain
+void tst_QScriptEngine::getterSetterThisObject_prototypeChain()
+{
{
QScriptEngine eng;
eng.evaluate("o = {}; p = {}; o.__proto__ = p");
@@ -3827,8 +4002,10 @@ void tst_QScriptEngine::getterSetterThisObject()
QVERIFY(eng.evaluate("with (o) x = 'foo'").equals("foo"));
QVERIFY(eng.evaluate("with (o) with (q) x = 'foo'").equals("foo"));
}
+}
- // getter+setter in activation
+void tst_QScriptEngine::getterSetterThisObject_activation()
+{
{
QScriptEngine eng;
QScriptContext *ctx = eng.pushContext();
@@ -4522,6 +4699,17 @@ void tst_QScriptEngine::installTranslatorFunctions()
QVERIFY(ret.isString());
QCOMPARE(ret.toString(), QString::fromLatin1("foobar"));
}
+ {
+ QScriptValue ret = eng.evaluate("'foo%0'.arg(123)");
+ QVERIFY(ret.isString());
+ QCOMPARE(ret.toString(), QString::fromLatin1("foo123"));
+ }
+ {
+ // Maybe this should throw an error?
+ QScriptValue ret = eng.evaluate("'foo%0'.arg()");
+ QVERIFY(ret.isString());
+ QCOMPARE(ret.toString(), QString());
+ }
{
QScriptValue ret = eng.evaluate("qsTrId('foo')");
@@ -4533,6 +4721,7 @@ void tst_QScriptEngine::installTranslatorFunctions()
QVERIFY(ret.isString());
QCOMPARE(ret.toString(), QString::fromLatin1("foo"));
}
+ QVERIFY(eng.evaluate("QT_TRID_NOOP()").isUndefined());
}
static QScriptValue callQsTr(QScriptContext *ctx, QScriptEngine *eng)
@@ -4567,9 +4756,14 @@ void tst_QScriptEngine::translateScript()
QCOMPARE(engine.evaluate("eval('qsTranslate(\\'FooContext\\', \\'Goodbye\\')')", fileName).toString(), QString::fromLatin1("Farvel"));
QCOMPARE(engine.evaluate("qsTranslate('FooContext', 'Goodbye', '', 'UnicodeUTF8')", fileName).toString(), QString::fromLatin1("Farvel"));
+ QCOMPARE(engine.evaluate("qsTranslate('FooContext', 'Goodbye', '', 'CodecForTr')", fileName).toString(), QString::fromLatin1("Farvel"));
+
+ QCOMPARE(engine.evaluate("qsTranslate('FooContext', 'Goodbye', '', 'UnicodeUTF8', 42)", fileName).toString(), QString::fromLatin1("Goodbye"));
QCOMPARE(engine.evaluate("qsTr('One', 'not the same one')", fileName).toString(), QString::fromLatin1("Enda en"));
+ QCOMPARE(engine.evaluate("qsTr('One', 'not the same one', 42)", fileName).toString(), QString::fromLatin1("One"));
+
QVERIFY(engine.evaluate("QT_TR_NOOP()").isUndefined());
QCOMPARE(engine.evaluate("QT_TR_NOOP('One')").toString(), QString::fromLatin1("One"));
@@ -4638,6 +4832,7 @@ void tst_QScriptEngine::translateWithInvalidArgs_data()
QTest::newRow("qsTranslate()") << "qsTranslate()" << "Error: qsTranslate() requires at least two arguments";
QTest::newRow("qsTranslate('foo')") << "qsTranslate('foo')" << "Error: qsTranslate() requires at least two arguments";
+ QTest::newRow("qsTranslate(123, 'foo')") << "qsTranslate(123, 'foo')" << "Error: qsTranslate(): first argument (context) must be a string";
QTest::newRow("qsTranslate('foo', 123)") << "qsTranslate('foo', 123)" << "Error: qsTranslate(): second argument (text) must be a string";
QTest::newRow("qsTranslate('foo', 'bar', 123)") << "qsTranslate('foo', 'bar', 123)" << "Error: qsTranslate(): third argument (comment) must be a string";
QTest::newRow("qsTranslate('foo', 'bar', 'baz', 123)") << "qsTranslate('foo', 'bar', 'baz', 123)" << "Error: qsTranslate(): fourth argument (encoding) must be a string";
@@ -4932,8 +5127,11 @@ void tst_QScriptEngine::evaluateProgram()
QVERIFY(differentProgram != program);
QVERIFY(!eng.evaluate(differentProgram).equals(expected));
}
+}
- // Program that accesses variable in the scope
+void tst_QScriptEngine::evaluateProgram_customScope()
+{
+ QScriptEngine eng;
{
QScriptProgram program("a");
QVERIFY(!program.isNull());
@@ -4970,8 +5168,11 @@ void tst_QScriptEngine::evaluateProgram()
ctx->popScope();
}
+}
- // Program that creates closure
+void tst_QScriptEngine::evaluateProgram_closure()
+{
+ QScriptEngine eng;
{
QScriptProgram program("(function() { var count = 0; return function() { return count++; }; })");
QVERIFY(!program.isNull());
@@ -4991,7 +5192,11 @@ void tst_QScriptEngine::evaluateProgram()
QVERIFY(ret.isNumber());
}
}
+}
+void tst_QScriptEngine::evaluateProgram_executeLater()
+{
+ QScriptEngine eng;
// Program created in a function call, then executed later
{
QScriptValue fun = eng.newFunction(createProgram);
@@ -5012,8 +5217,11 @@ void tst_QScriptEngine::evaluateProgram()
QCOMPARE(ret.toInt32(), 123);
}
}
+}
- // Same program run in different engines
+void tst_QScriptEngine::evaluateProgram_multipleEngines()
+{
+ QScriptEngine eng;
{
QString code("1 + 2");
QScriptProgram program(code);
@@ -5027,8 +5235,11 @@ void tst_QScriptEngine::evaluateProgram()
}
}
}
+}
- // No program
+void tst_QScriptEngine::evaluateProgram_empty()
+{
+ QScriptEngine eng;
{
QScriptProgram program;
QVERIFY(program.isNull());
@@ -5101,6 +5312,10 @@ void tst_QScriptEngine::qRegExpInport_data()
QTest::newRow("aaa") << QRegExp("a{2,5}") << "aAaAaaaaaAa";
QTest::newRow("aaa minimal") << minimal(QRegExp("a{2,5}")) << "aAaAaaaaaAa";
QTest::newRow("minimal") << minimal(QRegExp(".*\\} [*8]")) << "}?} ?} *";
+ QTest::newRow(".? minimal") << minimal(QRegExp(".?")) << ".?";
+ QTest::newRow(".+ minimal") << minimal(QRegExp(".+")) << ".+";
+ QTest::newRow("[.?] minimal") << minimal(QRegExp("[.?]")) << ".?";
+ QTest::newRow("[.+] minimal") << minimal(QRegExp("[.+]")) << ".+";
}
void tst_QScriptEngine::qRegExpInport()
@@ -5445,5 +5660,31 @@ void tst_QScriptEngine::newGrowingStaticScopeObject()
eng.popContext();
}
+QT_BEGIN_NAMESPACE
+Q_SCRIPT_DECLARE_QMETAOBJECT(QStandardItemModel, QObject*)
+QT_END_NAMESPACE
+
+void tst_QScriptEngine::scriptValueFromQMetaObject()
+{
+ QScriptEngine eng;
+ {
+ QScriptValue meta = eng.scriptValueFromQMetaObject<QScriptEngine>();
+ QVERIFY(meta.isQMetaObject());
+ QCOMPARE(meta.toQMetaObject(), &QScriptEngine::staticMetaObject);
+ // Because of missing Q_SCRIPT_DECLARE_QMETAOBJECT() for QScriptEngine.
+ QVERIFY(!meta.construct().isValid());
+ }
+ {
+ QScriptValue meta = eng.scriptValueFromQMetaObject<QStandardItemModel>();
+ QVERIFY(meta.isQMetaObject());
+ QCOMPARE(meta.toQMetaObject(), &QStandardItemModel::staticMetaObject);
+ QScriptValue obj = meta.construct(QScriptValueList() << eng.newQObject(&eng));
+ QVERIFY(obj.isQObject());
+ QStandardItemModel *model = qobject_cast<QStandardItemModel*>(obj.toQObject());
+ QVERIFY(model != 0);
+ QCOMPARE(model->parent(), (QObject*)&eng);
+ }
+}
+
QTEST_MAIN(tst_QScriptEngine)
#include "tst_qscriptengine.moc"
diff --git a/tests/auto/qscriptextensionplugin/qscriptextensionplugin.pro b/tests/auto/qscriptextensionplugin/qscriptextensionplugin.pro
new file mode 100644
index 0000000..d4671c8
--- /dev/null
+++ b/tests/auto/qscriptextensionplugin/qscriptextensionplugin.pro
@@ -0,0 +1,3 @@
+TEMPLATE = subdirs
+CONFIG -= app_bundle
+SUBDIRS = simpleplugin staticplugin test
diff --git a/tests/auto/qscriptextensionplugin/simpleplugin/simpleplugin.cpp b/tests/auto/qscriptextensionplugin/simpleplugin/simpleplugin.cpp
new file mode 100644
index 0000000..1679512
--- /dev/null
+++ b/tests/auto/qscriptextensionplugin/simpleplugin/simpleplugin.cpp
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtScript/qscriptextensionplugin.h>
+#include <QtScript/qscriptengine.h>
+#include <qdebug.h>
+
+class SimplePlugin : public QScriptExtensionPlugin
+{
+public:
+ SimplePlugin(QObject *parent = 0);
+ ~SimplePlugin();
+
+ virtual QStringList keys() const;
+ virtual void initialize(const QString &key, QScriptEngine *engine);
+};
+
+SimplePlugin::SimplePlugin(QObject *parent)
+ : QScriptExtensionPlugin(parent)
+{
+}
+
+SimplePlugin::~SimplePlugin()
+{
+}
+
+QStringList SimplePlugin::keys() const
+{
+ return QStringList() << "simple"
+ << "simple.foo"
+ << "simple.foo.bar";
+}
+
+void SimplePlugin::initialize(const QString &key, QScriptEngine *engine)
+{
+ engine->globalObject().setProperty("pluginKey", key);
+ QScriptValue package = setupPackage(key, engine);
+ engine->globalObject().setProperty("package", package);
+}
+
+Q_EXPORT_PLUGIN2(simpleplugin, SimplePlugin)
diff --git a/tests/auto/qscriptextensionplugin/simpleplugin/simpleplugin.pro b/tests/auto/qscriptextensionplugin/simpleplugin/simpleplugin.pro
new file mode 100644
index 0000000..e184ca4
--- /dev/null
+++ b/tests/auto/qscriptextensionplugin/simpleplugin/simpleplugin.pro
@@ -0,0 +1,10 @@
+TEMPLATE = lib
+CONFIG += plugin
+SOURCES = simpleplugin.cpp
+QT = core script
+TARGET = simpleplugin
+DESTDIR = ../plugins/script
+
+symbian {
+ TARGET.EPOCALLOWDLLDATA=1
+}
diff --git a/tests/auto/qscriptextensionplugin/staticplugin/__init__.js b/tests/auto/qscriptextensionplugin/staticplugin/__init__.js
new file mode 100644
index 0000000..4e462ae
--- /dev/null
+++ b/tests/auto/qscriptextensionplugin/staticplugin/__init__.js
@@ -0,0 +1,6 @@
+spy = {
+ extension: __extension__,
+ setupPackage: __setupPackage__,
+ postInit: __postInit__
+};
+__postInit__ = function() { postInitWasCalled = true; };
diff --git a/tests/auto/qscriptextensionplugin/staticplugin/staticplugin.cpp b/tests/auto/qscriptextensionplugin/staticplugin/staticplugin.cpp
new file mode 100644
index 0000000..b13f723
--- /dev/null
+++ b/tests/auto/qscriptextensionplugin/staticplugin/staticplugin.cpp
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtScript/qscriptextensionplugin.h>
+#include <QtScript/qscriptengine.h>
+#include <qdebug.h>
+
+class StaticPlugin : public QScriptExtensionPlugin
+{
+public:
+ StaticPlugin(QObject *parent = 0);
+ ~StaticPlugin();
+
+ virtual QStringList keys() const;
+ virtual void initialize(const QString &key, QScriptEngine *engine);
+};
+
+StaticPlugin::StaticPlugin(QObject *parent)
+ : QScriptExtensionPlugin(parent)
+{
+}
+
+StaticPlugin::~StaticPlugin()
+{
+}
+
+QStringList StaticPlugin::keys() const
+{
+ return QStringList() << "static";
+}
+
+void StaticPlugin::initialize(const QString &key, QScriptEngine *engine)
+{
+ engine->globalObject().setProperty("pluginKey", key);
+}
+
+Q_EXPORT_PLUGIN2(staticplugin, StaticPlugin)
diff --git a/tests/auto/qscriptextensionplugin/staticplugin/staticplugin.pro b/tests/auto/qscriptextensionplugin/staticplugin/staticplugin.pro
new file mode 100644
index 0000000..a003338
--- /dev/null
+++ b/tests/auto/qscriptextensionplugin/staticplugin/staticplugin.pro
@@ -0,0 +1,7 @@
+TEMPLATE = lib
+CONFIG += static plugin
+SOURCES = staticplugin.cpp
+RESOURCES = staticplugin.qrc
+QT = core script
+TARGET = staticplugin
+DESTDIR = ../plugins/script
diff --git a/tests/auto/qscriptextensionplugin/staticplugin/staticplugin.qrc b/tests/auto/qscriptextensionplugin/staticplugin/staticplugin.qrc
new file mode 100644
index 0000000..293bf0e
--- /dev/null
+++ b/tests/auto/qscriptextensionplugin/staticplugin/staticplugin.qrc
@@ -0,0 +1,6 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/qtscriptextension/static/">
+<file>__init__.js</file>
+</qresource>
+</RCC>
+
diff --git a/tests/auto/qscriptextensionplugin/test/test.pro b/tests/auto/qscriptextensionplugin/test/test.pro
new file mode 100644
index 0000000..549bac2
--- /dev/null
+++ b/tests/auto/qscriptextensionplugin/test/test.pro
@@ -0,0 +1,18 @@
+load(qttest_p4)
+
+QT = core script
+SOURCES = ../tst_qscriptextensionplugin.cpp
+CONFIG -= app_bundle
+LIBS += -L../plugins/script -lstaticplugin
+
+TARGET = tst_qscriptextensionplugin
+CONFIG(debug_and_release) {
+ CONFIG(debug, debug|release) {
+ DESTDIR = ../debug
+ } else {
+ DESTDIR = ../release
+ }
+} else {
+ DESTDIR = ..
+}
+
diff --git a/tests/auto/qscriptextensionplugin/tst_qscriptextensionplugin.cpp b/tests/auto/qscriptextensionplugin/tst_qscriptextensionplugin.cpp
new file mode 100644
index 0000000..e8b5e0a
--- /dev/null
+++ b/tests/auto/qscriptextensionplugin/tst_qscriptextensionplugin.cpp
@@ -0,0 +1,167 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtTest/QtTest>
+
+#include <QtScript/qscriptengine.h>
+
+//TESTED_CLASS=
+//TESTED_FILES=
+
+class tst_QScriptExtensionPlugin : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QScriptExtensionPlugin();
+ virtual ~tst_QScriptExtensionPlugin();
+
+private slots:
+ void importSimplePlugin();
+ void importStaticPlugin();
+};
+
+tst_QScriptExtensionPlugin::tst_QScriptExtensionPlugin()
+{
+}
+
+tst_QScriptExtensionPlugin::~tst_QScriptExtensionPlugin()
+{
+}
+
+void tst_QScriptExtensionPlugin::importSimplePlugin()
+{
+ QScriptEngine eng;
+ QCoreApplication::addLibraryPath("plugins");
+
+ QVERIFY(eng.importedExtensions().isEmpty());
+
+ QStringList available = eng.availableExtensions();
+ QVERIFY(available.contains("simple"));
+ QVERIFY(available.contains("simple.foo"));
+ QVERIFY(available.contains("simple.foo.bar"));
+
+ QScriptValue extensionObject;
+ {
+ QVERIFY(eng.importExtension("simple").isUndefined());
+ QCOMPARE(eng.importedExtensions().size(), 1);
+ QCOMPARE(eng.importedExtensions().at(0), QString::fromLatin1("simple"));
+ QVERIFY(eng.availableExtensions().contains("simple"));
+ QVERIFY(eng.globalObject().property("pluginKey").equals("simple"));
+ QVERIFY(eng.globalObject().property("package").isObject());
+ extensionObject = eng.globalObject().property("simple");
+ QVERIFY(extensionObject.isObject());
+ QVERIFY(extensionObject.equals(eng.globalObject().property("package")));
+ }
+
+ {
+ QVERIFY(eng.importExtension("simple.foo").isUndefined());
+ QCOMPARE(eng.importedExtensions().size(), 2);
+ QCOMPARE(eng.importedExtensions().at(1), QString::fromLatin1("simple.foo"));
+ QVERIFY(eng.availableExtensions().contains("simple.foo"));
+ QVERIFY(eng.globalObject().property("pluginKey").equals("simple.foo"));
+ QVERIFY(eng.globalObject().property("package").isObject());
+ QVERIFY(!extensionObject.equals(eng.globalObject().property("package")));
+ QVERIFY(extensionObject.equals(eng.globalObject().property("simple")));
+ QVERIFY(extensionObject.property("foo").isObject());
+ QVERIFY(extensionObject.property("foo").equals(eng.globalObject().property("package")));
+ }
+
+ {
+ QVERIFY(eng.importExtension("simple.foo.bar").isUndefined());
+ QCOMPARE(eng.importedExtensions().size(), 3);
+ QCOMPARE(eng.importedExtensions().at(2), QString::fromLatin1("simple.foo.bar"));
+ QVERIFY(eng.availableExtensions().contains("simple.foo.bar"));
+ QVERIFY(eng.globalObject().property("pluginKey").equals("simple.foo.bar"));
+ QVERIFY(eng.globalObject().property("package").isObject());
+ QVERIFY(!extensionObject.equals(eng.globalObject().property("package")));
+ QVERIFY(extensionObject.equals(eng.globalObject().property("simple")));
+ QVERIFY(extensionObject.property("foo").property("bar").isObject());
+ QVERIFY(extensionObject.property("foo").property("bar").equals(eng.globalObject().property("package")));
+ }
+
+ // Extensions can't be imported multiple times.
+ eng.globalObject().setProperty("pluginKey", QScriptValue());
+ QVERIFY(eng.importExtension("simple").isUndefined());
+ QCOMPARE(eng.importedExtensions().size(), 3);
+ QVERIFY(!eng.globalObject().property("pluginKey").isValid());
+
+ QVERIFY(eng.importExtension("simple.foo").isUndefined());
+ QCOMPARE(eng.importedExtensions().size(), 3);
+ QVERIFY(!eng.globalObject().property("pluginKey").isValid());
+
+ QVERIFY(eng.importExtension("simple.foo.bar").isUndefined());
+ QCOMPARE(eng.importedExtensions().size(), 3);
+ QVERIFY(!eng.globalObject().property("pluginKey").isValid());
+}
+
+void tst_QScriptExtensionPlugin::importStaticPlugin()
+{
+ Q_INIT_RESOURCE(staticplugin);
+ QScriptEngine eng;
+ QVERIFY(eng.availableExtensions().contains("static"));
+ QVERIFY(eng.importExtension("static").isUndefined());
+ QCOMPARE(eng.importedExtensions().size(), 1);
+ QCOMPARE(eng.importedExtensions().at(0), QString::fromLatin1("static"));
+ QVERIFY(eng.availableExtensions().contains("static"));
+ QVERIFY(eng.globalObject().property("pluginKey").equals("static"));
+
+ // Verify that :/qtscriptextension/static/__init__.js was evaluated.
+ QVERIFY(eng.evaluate("spy").isObject());
+ QVERIFY(eng.evaluate("spy.extension").equals("static"));
+ QVERIFY(eng.evaluate("spy.setupPackage").isFunction());
+ QVERIFY(eng.evaluate("spy.postInit").isUndefined());
+
+ QVERIFY(eng.evaluate("postInitWasCalled").isBool());
+ QVERIFY(eng.evaluate("postInitWasCalled").toBool());
+
+ // Extensions can't be imported multiple times.
+ eng.globalObject().setProperty("pluginKey", QScriptValue());
+ QVERIFY(eng.importExtension("static").isUndefined());
+ QCOMPARE(eng.importedExtensions().size(), 1);
+ QVERIFY(!eng.globalObject().property("pluginKey").isValid());
+}
+
+Q_IMPORT_PLUGIN(staticplugin)
+
+QTEST_MAIN(tst_QScriptExtensionPlugin)
+#include "tst_qscriptextensionplugin.moc"
diff --git a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
index 0d57f0c..1562118 100644
--- a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
+++ b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
@@ -329,6 +329,18 @@ public:
{ m_qtFunctionInvoked = 58; m_actuals << int(arg); return arg; }
Q_INVOKABLE MyQObject::Ability myInvokableWithQualifiedFlagsArg(MyQObject::Ability arg)
{ m_qtFunctionInvoked = 59; m_actuals << int(arg); return arg; }
+ Q_INVOKABLE QWidget *myInvokableWithQWidgetStarArg(QWidget *arg)
+ { m_qtFunctionInvoked = 63; m_actuals << qVariantFromValue((QWidget*)arg); return arg; }
+ Q_INVOKABLE short myInvokableWithShortArg(short arg)
+ { m_qtFunctionInvoked = 64; m_actuals << qVariantFromValue(arg); return arg; }
+ Q_INVOKABLE unsigned short myInvokableWithUShortArg(unsigned short arg)
+ { m_qtFunctionInvoked = 65; m_actuals << qVariantFromValue(arg); return arg; }
+ Q_INVOKABLE char myInvokableWithCharArg(char arg)
+ { m_qtFunctionInvoked = 66; m_actuals << qVariantFromValue(arg); return arg; }
+ Q_INVOKABLE unsigned char myInvokableWithUCharArg(unsigned char arg)
+ { m_qtFunctionInvoked = 67; m_actuals << qVariantFromValue(arg); return arg; }
+ Q_INVOKABLE qulonglong myInvokableWithULonglongArg(qulonglong arg)
+ { m_qtFunctionInvoked = 68; m_actuals << qVariantFromValue(arg); return arg; }
Q_INVOKABLE QObjectList findObjects() const
{ return findChildren<QObject *>(); }
@@ -394,6 +406,8 @@ public Q_SLOTS:
{ m_qtFunctionInvoked = 32; m_actuals << arg; }
void myOverloadedSlot(const QDate &arg)
{ m_qtFunctionInvoked = 33; m_actuals << arg; }
+ void myOverloadedSlot(const QTime &arg)
+ { m_qtFunctionInvoked = 69; m_actuals << arg; }
void myOverloadedSlot(const QRegExp &arg)
{ m_qtFunctionInvoked = 34; m_actuals << arg; }
void myOverloadedSlot(const QVariant &arg)
@@ -519,6 +533,7 @@ private slots:
void callQtInvokable();
void connectAndDisconnect();
void connectAndDisconnectWithBadArgs();
+ void connectAndDisconnect_senderDeleted();
void cppConnectAndDisconnect();
void classEnums();
void classConstructor();
@@ -1361,6 +1376,17 @@ void tst_QScriptExtQObject::callQtInvokable()
m_myObject->resetQtFunctionInvoked();
{
+ QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithQWidgetStarArg(null)");
+ QVERIFY(ret.isNull());
+ QCOMPARE(m_myObject->qtFunctionInvoked(), 63);
+ QCOMPARE(m_myObject->qtFunctionActuals().size(), 1);
+ QVariant v = m_myObject->qtFunctionActuals().at(0);
+ QCOMPARE(v.userType(), int(QMetaType::QWidgetStar));
+ QCOMPARE(qvariant_cast<QWidget*>(v), (QObject *)0);
+ }
+
+ m_myObject->resetQtFunctionInvoked();
+ {
// no implicit conversion from integer to QObject*
QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithQObjectStarArg(123)");
QCOMPARE(ret.isError(), true);
@@ -1368,6 +1394,61 @@ void tst_QScriptExtQObject::callQtInvokable()
m_myObject->resetQtFunctionInvoked();
{
+ QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithShortArg(123)");
+ QVERIFY(ret.isNumber());
+ QCOMPARE(m_myObject->qtFunctionInvoked(), 64);
+ QCOMPARE(m_myObject->qtFunctionActuals().size(), 1);
+ QVariant v = m_myObject->qtFunctionActuals().at(0);
+ QCOMPARE(v.userType(), int(QMetaType::Short));
+ QCOMPARE(qvariant_cast<short>(v), short(123));
+ }
+
+ m_myObject->resetQtFunctionInvoked();
+ {
+ QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithUShortArg(123)");
+ QVERIFY(ret.isNumber());
+ QCOMPARE(m_myObject->qtFunctionInvoked(), 65);
+ QCOMPARE(m_myObject->qtFunctionActuals().size(), 1);
+ QVariant v = m_myObject->qtFunctionActuals().at(0);
+ QCOMPARE(v.userType(), int(QMetaType::UShort));
+ QCOMPARE(qvariant_cast<ushort>(v), ushort(123));
+ }
+
+ m_myObject->resetQtFunctionInvoked();
+ {
+ QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithCharArg(123)");
+ QVERIFY(ret.isNumber());
+ QCOMPARE(m_myObject->qtFunctionInvoked(), 66);
+ QCOMPARE(m_myObject->qtFunctionActuals().size(), 1);
+ QVariant v = m_myObject->qtFunctionActuals().at(0);
+ QCOMPARE(v.userType(), int(QMetaType::Char));
+ QCOMPARE(qvariant_cast<char>(v), char(123));
+ }
+
+ m_myObject->resetQtFunctionInvoked();
+ {
+ QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithUCharArg(123)");
+ QVERIFY(ret.isNumber());
+ QCOMPARE(m_myObject->qtFunctionInvoked(), 67);
+ QCOMPARE(m_myObject->qtFunctionActuals().size(), 1);
+ QVariant v = m_myObject->qtFunctionActuals().at(0);
+ QCOMPARE(v.userType(), int(QMetaType::UChar));
+ QCOMPARE(qvariant_cast<uchar>(v), uchar(123));
+ }
+
+ m_myObject->resetQtFunctionInvoked();
+ {
+ QScriptValue ret = m_engine->evaluate("myObject.myInvokableWithULonglongArg(123)");
+ QVERIFY(ret.isNumber());
+ QCOMPARE(m_myObject->qtFunctionInvoked(), 68);
+ QCOMPARE(m_myObject->qtFunctionActuals().size(), 1);
+ QVariant v = m_myObject->qtFunctionActuals().at(0);
+ QCOMPARE(v.userType(), int(QMetaType::ULongLong));
+ QCOMPARE(qvariant_cast<qulonglong>(v), qulonglong(123));
+ }
+
+ m_myObject->resetQtFunctionInvoked();
+ {
QScriptValue fun = m_engine->evaluate("myObject.myInvokableWithQBrushArg");
QVERIFY(fun.isFunction());
QColor color(10, 20, 30, 40);
@@ -1916,6 +1997,25 @@ void tst_QScriptExtQObject::connectAndDisconnectWithBadArgs()
}
}
+void tst_QScriptExtQObject::connectAndDisconnect_senderDeleted()
+{
+ QScriptEngine eng;
+ QObject *obj = new QObject;
+ eng.globalObject().setProperty("obj", eng.newQObject(obj));
+ eng.evaluate("signal = obj.destroyed");
+ delete obj;
+ {
+ QScriptValue ret = eng.evaluate("signal.connect(function(){})");
+ QVERIFY(ret.isError());
+ QCOMPARE(ret.toString(), QString::fromLatin1("TypeError: Function.prototype.connect: cannot connect to deleted QObject"));
+ }
+ {
+ QScriptValue ret = eng.evaluate("signal.disconnect(function(){})");
+ QVERIFY(ret.isError());
+ QCOMPARE(ret.toString(), QString::fromLatin1("TypeError: Function.prototype.discconnect: cannot disconnect from deleted QObject"));
+ }
+}
+
void tst_QScriptExtQObject::cppConnectAndDisconnect()
{
QScriptEngine eng;
diff --git a/tests/auto/qscriptvalue/qscriptvalue.pro b/tests/auto/qscriptvalue/qscriptvalue.pro
index c3e9912..0474c32 100644
--- a/tests/auto/qscriptvalue/qscriptvalue.pro
+++ b/tests/auto/qscriptvalue/qscriptvalue.pro
@@ -3,14 +3,6 @@ QT = core gui script
SOURCES += tst_qscriptvalue.cpp
HEADERS += tst_qscriptvalue.h
-# Generated by testgen
-SOURCES += \
- tst_qscriptvalue_generated_init.cpp \
- tst_qscriptvalue_generated_cast.cpp \
- tst_qscriptvalue_generated_comparison.cpp \
- tst_qscriptvalue_generated_isXXX.cpp \
- tst_qscriptvalue_generated_toXXX.cpp
-
win32-msvc* {
# With -O2, MSVC takes up to 24 minutes to compile this test!
QMAKE_CXXFLAGS_RELEASE -= -O1 -O2
diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
index 5e42921a..be51cf2 100644
--- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
+++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
@@ -56,64 +56,11 @@ tst_QScriptValue::tst_QScriptValue()
tst_QScriptValue::~tst_QScriptValue()
{
- delete engine;
+ if (engine)
+ delete engine;
}
-void tst_QScriptValue::dataHelper(InitDataFunction init, DefineDataFunction define)
-{
- QTest::addColumn<QString>("__expression__");
- (this->*init)();
- QHash<QString,QScriptValue>::const_iterator it;
- for (it = m_values.constBegin(); it != m_values.constEnd(); ++it) {
- m_currentExpression = it.key();
- (this->*define)(it.key().toLatin1());
- }
- m_currentExpression = QString();
-}
-
-QTestData &tst_QScriptValue::newRow(const char *tag)
-{
- return QTest::newRow(tag) << m_currentExpression;
-}
-
-void tst_QScriptValue::testHelper(TestFunction fun)
-{
- QFETCH(QString, __expression__);
- QScriptValue value = m_values.value(__expression__);
- (this->*fun)(__expression__.toLatin1(), value);
-}
-
-void tst_QScriptValue::assignAndCopyConstruct_initData()
-{
- QTest::addColumn<int>("dummy");
- initScriptValues();
-}
-
-void tst_QScriptValue::assignAndCopyConstruct_makeData(const char *expr)
-{
- newRow(expr) << 0;
-}
-
-void tst_QScriptValue::assignAndCopyConstruct_test(const char *, const QScriptValue &value)
-{
- QScriptValue copy(value);
- QCOMPARE(copy.strictlyEquals(value), !value.isNumber() || !qIsNaN(value.toNumber()));
- QCOMPARE(copy.engine(), value.engine());
-
- QScriptValue assigned = copy;
- QCOMPARE(assigned.strictlyEquals(value), !copy.isNumber() || !qIsNaN(copy.toNumber()));
- QCOMPARE(assigned.engine(), assigned.engine());
-
- QScriptValue other(!value.toBool());
- assigned = other;
- QVERIFY(!assigned.strictlyEquals(copy));
- QVERIFY(assigned.strictlyEquals(other));
- QCOMPARE(assigned.engine(), other.engine());
-}
-
-DEFINE_TEST_FUNCTION(assignAndCopyConstruct)
-
-void tst_QScriptValue::ctor()
+void tst_QScriptValue::ctor_invalid()
{
QScriptEngine eng;
{
@@ -121,6 +68,11 @@ void tst_QScriptValue::ctor()
QCOMPARE(v.isValid(), false);
QCOMPARE(v.engine(), (QScriptEngine *)0);
}
+}
+
+void tst_QScriptValue::ctor_undefinedWithEngine()
+{
+ QScriptEngine eng;
{
QScriptValue v(&eng, QScriptValue::UndefinedValue);
QCOMPARE(v.isValid(), true);
@@ -128,6 +80,11 @@ void tst_QScriptValue::ctor()
QCOMPARE(v.isObject(), false);
QCOMPARE(v.engine(), &eng);
}
+}
+
+void tst_QScriptValue::ctor_nullWithEngine()
+{
+ QScriptEngine eng;
{
QScriptValue v(&eng, QScriptValue::NullValue);
QCOMPARE(v.isValid(), true);
@@ -135,6 +92,11 @@ void tst_QScriptValue::ctor()
QCOMPARE(v.isObject(), false);
QCOMPARE(v.engine(), &eng);
}
+}
+
+void tst_QScriptValue::ctor_boolWithEngine()
+{
+ QScriptEngine eng;
{
QScriptValue v(&eng, false);
QCOMPARE(v.isValid(), true);
@@ -144,6 +106,11 @@ void tst_QScriptValue::ctor()
QCOMPARE(v.toBoolean(), false);
QCOMPARE(v.engine(), &eng);
}
+}
+
+void tst_QScriptValue::ctor_intWithEngine()
+{
+ QScriptEngine eng;
{
QScriptValue v(&eng, int(1));
QCOMPARE(v.isValid(), true);
@@ -152,132 +119,102 @@ void tst_QScriptValue::ctor()
QCOMPARE(v.toNumber(), 1.0);
QCOMPARE(v.engine(), &eng);
}
+}
+
+void tst_QScriptValue::ctor_int()
+{
{
QScriptValue v(int(0x43211234));
QVERIFY(v.isNumber());
QCOMPARE(v.toInt32(), 0x43211234);
}
{
- QScriptValue v(&eng, uint(1));
+ QScriptValue v(int(1));
QCOMPARE(v.isValid(), true);
QCOMPARE(v.isNumber(), true);
QCOMPARE(v.isObject(), false);
QCOMPARE(v.toNumber(), 1.0);
- QCOMPARE(v.engine(), &eng);
- }
- {
- QScriptValue v(uint(0x43211234));
- QVERIFY(v.isNumber());
- QCOMPARE(v.toUInt32(), uint(0x43211234));
+ QCOMPARE(v.engine(), (QScriptEngine *)0);
}
+}
+
+void tst_QScriptValue::ctor_uintWithEngine()
+{
+ QScriptEngine eng;
{
- QScriptValue v(&eng, 1.0);
+ QScriptValue v(&eng, uint(1));
QCOMPARE(v.isValid(), true);
QCOMPARE(v.isNumber(), true);
QCOMPARE(v.isObject(), false);
QCOMPARE(v.toNumber(), 1.0);
QCOMPARE(v.engine(), &eng);
}
+}
+
+void tst_QScriptValue::ctor_uint()
+{
{
- QScriptValue v(12345678910.5);
+ QScriptValue v(uint(0x43211234));
QVERIFY(v.isNumber());
- QCOMPARE(v.toNumber(), 12345678910.5);
- }
- {
- QScriptValue v(&eng, "ciao");
- QCOMPARE(v.isValid(), true);
- QCOMPARE(v.isString(), true);
- QCOMPARE(v.isObject(), false);
- QCOMPARE(v.toString(), QLatin1String("ciao"));
- QCOMPARE(v.engine(), &eng);
+ QCOMPARE(v.toUInt32(), uint(0x43211234));
}
{
- QScriptValue v(&eng, QString("ciao"));
+ QScriptValue v(uint(1));
QCOMPARE(v.isValid(), true);
- QCOMPARE(v.isString(), true);
+ QCOMPARE(v.isNumber(), true);
QCOMPARE(v.isObject(), false);
- QCOMPARE(v.toString(), QLatin1String("ciao"));
- QCOMPARE(v.engine(), &eng);
- }
- // copy constructor, operator=
- {
- QScriptValue v(&eng, 1.0);
- QScriptValue v2(v);
- QCOMPARE(v2.strictlyEquals(v), true);
- QCOMPARE(v2.engine(), &eng);
-
- QScriptValue v3(v);
- QCOMPARE(v3.strictlyEquals(v), true);
- QCOMPARE(v3.strictlyEquals(v2), true);
- QCOMPARE(v3.engine(), &eng);
-
- QScriptValue v4(&eng, 2.0);
- QCOMPARE(v4.strictlyEquals(v), false);
- v3 = v4;
- QCOMPARE(v3.strictlyEquals(v), false);
- QCOMPARE(v3.strictlyEquals(v4), true);
-
- v2 = QScriptValue();
- QCOMPARE(v2.strictlyEquals(v), false);
QCOMPARE(v.toNumber(), 1.0);
-
- QScriptValue v5(v);
- QCOMPARE(v5.strictlyEquals(v), true);
- v = QScriptValue();
- QCOMPARE(v5.strictlyEquals(v), false);
- QCOMPARE(v5.toNumber(), 1.0);
- }
-
- // constructors that take no engine argument
- {
- QScriptValue v(QScriptValue::UndefinedValue);
- QCOMPARE(v.isValid(), true);
- QCOMPARE(v.isUndefined(), true);
- QCOMPARE(v.isObject(), false);
- QCOMPARE(v.engine(), (QScriptEngine *)0);
- }
- {
- QScriptValue v(QScriptValue::NullValue);
- QCOMPARE(v.isValid(), true);
- QCOMPARE(v.isNull(), true);
- QCOMPARE(v.isObject(), false);
- QCOMPARE(v.engine(), (QScriptEngine *)0);
- }
- {
- QScriptValue v(false);
- QCOMPARE(v.isValid(), true);
- QCOMPARE(v.isBoolean(), true);
- QCOMPARE(v.isBool(), true);
- QCOMPARE(v.isObject(), false);
- QCOMPARE(v.toBoolean(), false);
QCOMPARE(v.engine(), (QScriptEngine *)0);
}
+}
+
+void tst_QScriptValue::ctor_floatWithEngine()
+{
+ QScriptEngine eng;
{
- QScriptValue v(int(1));
+ QScriptValue v(&eng, 1.0);
QCOMPARE(v.isValid(), true);
QCOMPARE(v.isNumber(), true);
QCOMPARE(v.isObject(), false);
QCOMPARE(v.toNumber(), 1.0);
- QCOMPARE(v.engine(), (QScriptEngine *)0);
+ QCOMPARE(v.engine(), &eng);
+ }
+}
+
+void tst_QScriptValue::ctor_float()
+{
+ {
+ QScriptValue v(12345678910.5);
+ QVERIFY(v.isNumber());
+ QCOMPARE(v.toNumber(), 12345678910.5);
}
{
- QScriptValue v(uint(1));
+ QScriptValue v(1.0);
QCOMPARE(v.isValid(), true);
QCOMPARE(v.isNumber(), true);
QCOMPARE(v.isObject(), false);
QCOMPARE(v.toNumber(), 1.0);
QCOMPARE(v.engine(), (QScriptEngine *)0);
}
+}
+
+void tst_QScriptValue::ctor_stringWithEngine()
+{
+ QScriptEngine eng;
{
- QScriptValue v(1.0);
+ QScriptValue v(&eng, "ciao");
QCOMPARE(v.isValid(), true);
- QCOMPARE(v.isNumber(), true);
+ QCOMPARE(v.isString(), true);
QCOMPARE(v.isObject(), false);
- QCOMPARE(v.toNumber(), 1.0);
- QCOMPARE(v.engine(), (QScriptEngine *)0);
+ QCOMPARE(v.toString(), QLatin1String("ciao"));
+ QCOMPARE(v.engine(), &eng);
}
+}
+
+void tst_QScriptValue::ctor_string()
+{
{
- QScriptValue v("ciao");
+ QScriptValue v(QString("ciao"));
QCOMPARE(v.isValid(), true);
QCOMPARE(v.isString(), true);
QCOMPARE(v.isObject(), false);
@@ -285,26 +222,31 @@ void tst_QScriptValue::ctor()
QCOMPARE(v.engine(), (QScriptEngine *)0);
}
{
- QScriptValue v(QString("ciao"));
+ QScriptValue v("ciao");
QCOMPARE(v.isValid(), true);
QCOMPARE(v.isString(), true);
QCOMPARE(v.isObject(), false);
QCOMPARE(v.toString(), QLatin1String("ciao"));
QCOMPARE(v.engine(), (QScriptEngine *)0);
}
+}
+
+void tst_QScriptValue::ctor_copyAndAssignWithEngine()
+{
+ QScriptEngine eng;
// copy constructor, operator=
{
- QScriptValue v(1.0);
+ QScriptValue v(&eng, 1.0);
QScriptValue v2(v);
QCOMPARE(v2.strictlyEquals(v), true);
- QCOMPARE(v2.engine(), (QScriptEngine *)0);
+ QCOMPARE(v2.engine(), &eng);
QScriptValue v3(v);
QCOMPARE(v3.strictlyEquals(v), true);
QCOMPARE(v3.strictlyEquals(v2), true);
- QCOMPARE(v3.engine(), (QScriptEngine *)0);
+ QCOMPARE(v3.engine(), &eng);
- QScriptValue v4(2.0);
+ QScriptValue v4(&eng, 2.0);
QCOMPARE(v4.strictlyEquals(v), false);
v3 = v4;
QCOMPARE(v3.strictlyEquals(v), false);
@@ -320,7 +262,68 @@ void tst_QScriptValue::ctor()
QCOMPARE(v5.strictlyEquals(v), false);
QCOMPARE(v5.toNumber(), 1.0);
}
+}
+
+void tst_QScriptValue::ctor_undefined()
+{
+ QScriptValue v(QScriptValue::UndefinedValue);
+ QCOMPARE(v.isValid(), true);
+ QCOMPARE(v.isUndefined(), true);
+ QCOMPARE(v.isObject(), false);
+ QCOMPARE(v.engine(), (QScriptEngine *)0);
+}
+
+void tst_QScriptValue::ctor_null()
+{
+ QScriptValue v(QScriptValue::NullValue);
+ QCOMPARE(v.isValid(), true);
+ QCOMPARE(v.isNull(), true);
+ QCOMPARE(v.isObject(), false);
+ QCOMPARE(v.engine(), (QScriptEngine *)0);
+}
+void tst_QScriptValue::ctor_bool()
+{
+ QScriptValue v(false);
+ QCOMPARE(v.isValid(), true);
+ QCOMPARE(v.isBoolean(), true);
+ QCOMPARE(v.isBool(), true);
+ QCOMPARE(v.isObject(), false);
+ QCOMPARE(v.toBoolean(), false);
+ QCOMPARE(v.engine(), (QScriptEngine *)0);
+}
+
+void tst_QScriptValue::ctor_copyAndAssign()
+{
+ QScriptValue v(1.0);
+ QScriptValue v2(v);
+ QCOMPARE(v2.strictlyEquals(v), true);
+ QCOMPARE(v2.engine(), (QScriptEngine *)0);
+
+ QScriptValue v3(v);
+ QCOMPARE(v3.strictlyEquals(v), true);
+ QCOMPARE(v3.strictlyEquals(v2), true);
+ QCOMPARE(v3.engine(), (QScriptEngine *)0);
+
+ QScriptValue v4(2.0);
+ QCOMPARE(v4.strictlyEquals(v), false);
+ v3 = v4;
+ QCOMPARE(v3.strictlyEquals(v), false);
+ QCOMPARE(v3.strictlyEquals(v4), true);
+
+ v2 = QScriptValue();
+ QCOMPARE(v2.strictlyEquals(v), false);
+ QCOMPARE(v.toNumber(), 1.0);
+
+ QScriptValue v5(v);
+ QCOMPARE(v5.strictlyEquals(v), true);
+ v = QScriptValue();
+ QCOMPARE(v5.strictlyEquals(v), false);
+ QCOMPARE(v5.toNumber(), 1.0);
+}
+
+void tst_QScriptValue::ctor_nullEngine()
+{
// 0 engine
QVERIFY(QScriptValue(0, QScriptValue::UndefinedValue).isUndefined());
QVERIFY(QScriptValue(0, QScriptValue::NullValue).isNull());
@@ -337,7 +340,7 @@ static QScriptValue myFunction(QScriptContext *, QScriptEngine *eng)
return eng->undefinedValue();
}
-void tst_QScriptValue::toString_old()
+void tst_QScriptValue::toString()
{
QScriptEngine eng;
@@ -451,7 +454,7 @@ void tst_QScriptValue::toString_old()
QVERIFY(variant.toString().isEmpty());
}
-void tst_QScriptValue::toNumber_old()
+void tst_QScriptValue::toNumber()
{
QScriptEngine eng;
@@ -524,7 +527,7 @@ void tst_QScriptValue::toNumber_old()
}
}
-void tst_QScriptValue::toBoolean_old() // deprecated
+void tst_QScriptValue::toBoolean() // deprecated
{
QScriptEngine eng;
@@ -621,7 +624,7 @@ void tst_QScriptValue::toBoolean_old() // deprecated
}
}
-void tst_QScriptValue::toBool_old()
+void tst_QScriptValue::toBool()
{
QScriptEngine eng;
@@ -718,7 +721,7 @@ void tst_QScriptValue::toBool_old()
}
}
-void tst_QScriptValue::toInteger_old()
+void tst_QScriptValue::toInteger()
{
QScriptEngine eng;
@@ -805,7 +808,7 @@ void tst_QScriptValue::toInteger_old()
QCOMPARE(inv.toInteger(), 0.0);
}
-void tst_QScriptValue::toInt32_old()
+void tst_QScriptValue::toInt32()
{
QScriptEngine eng;
@@ -941,7 +944,7 @@ void tst_QScriptValue::toInt32_old()
QCOMPARE(qscriptvalue_cast<qint32>(inv), 0);
}
-void tst_QScriptValue::toUInt32_old()
+void tst_QScriptValue::toUInt32()
{
QScriptEngine eng;
@@ -1073,7 +1076,7 @@ void tst_QScriptValue::toUInt32_old()
QCOMPARE(qscriptvalue_cast<quint32>(inv), quint32(0));
}
-void tst_QScriptValue::toUInt16_old()
+void tst_QScriptValue::toUInt16()
{
QScriptEngine eng;
@@ -1234,7 +1237,7 @@ void tst_QScriptValue::toUInt16_old()
Q_DECLARE_METATYPE(QVariant)
#endif
-void tst_QScriptValue::toVariant_old()
+void tst_QScriptValue::toVariant()
{
QScriptEngine eng;
@@ -1341,7 +1344,7 @@ void tst_QScriptValue::toVariant_old()
// unfortunately, this is necessary in order to do qscriptvalue_cast<QPushButton*>(...)
Q_DECLARE_METATYPE(QPushButton*)
-void tst_QScriptValue::toQObject_old()
+void tst_QScriptValue::toQObject()
{
QScriptEngine eng;
@@ -1548,7 +1551,7 @@ void tst_QScriptValue::toObject()
}
}
-void tst_QScriptValue::toDateTime_old()
+void tst_QScriptValue::toDateTime()
{
QScriptEngine eng;
QDateTime dt = eng.evaluate("new Date(0)").toDateTime();
@@ -1566,7 +1569,7 @@ void tst_QScriptValue::toDateTime_old()
QVERIFY(!eng.undefinedValue().toDateTime().isValid());
}
-void tst_QScriptValue::toRegExp_old()
+void tst_QScriptValue::toRegExp()
{
QScriptEngine eng;
{
@@ -1596,7 +1599,16 @@ void tst_QScriptValue::toRegExp_old()
QVERIFY(eng.undefinedValue().toRegExp().isEmpty());
}
-void tst_QScriptValue::instanceOf_old()
+void tst_QScriptValue::instanceOf_twoEngines()
+{
+ QScriptEngine eng;
+ QScriptValue obj = eng.newObject();
+ QScriptEngine otherEngine;
+ QTest::ignoreMessage(QtWarningMsg, "QScriptValue::instanceof: cannot perform operation on a value created in a different engine");
+ QCOMPARE(obj.instanceOf(otherEngine.globalObject().property("Object")), false);
+}
+
+void tst_QScriptValue::instanceOf()
{
QScriptEngine eng;
QScriptValue obj = eng.newObject();
@@ -1626,40 +1638,60 @@ void tst_QScriptValue::instanceOf_old()
QCOMPARE(arr.instanceOf(eng.evaluate("QObject")), false);
QCOMPARE(QScriptValue().instanceOf(arr), false);
+}
- QScriptEngine otherEngine;
- QTest::ignoreMessage(QtWarningMsg, "QScriptValue::instanceof: cannot perform operation on a value created in a different engine");
- QCOMPARE(obj.instanceOf(otherEngine.globalObject().property("Object")), false);
+void tst_QScriptValue::isArray_data()
+{
+ newEngine();
+
+ QTest::addColumn<QScriptValue>("value");
+ QTest::addColumn<bool>("array");
+
+ QTest::newRow("[]") << engine->evaluate("[]") << true;
+ QTest::newRow("{}") << engine->evaluate("{}") << false;
+ QTest::newRow("globalObject") << engine->globalObject() << false;
+ QTest::newRow("invalid") << QScriptValue() << false;
+ QTest::newRow("number") << QScriptValue(123) << false;
+ QTest::newRow("bool") << QScriptValue(false) << false;
+ QTest::newRow("null") << engine->nullValue() << false;
+ QTest::newRow("undefined") << engine->undefinedValue() << false;
}
-void tst_QScriptValue::isArray_old()
+void tst_QScriptValue::isArray()
{
- QScriptEngine eng;
- QVERIFY(eng.evaluate("[]").isArray());
- QVERIFY(!eng.evaluate("{}").isArray());
- QVERIFY(!eng.globalObject().isArray());
- QVERIFY(!QScriptValue().isArray());
- QVERIFY(!QScriptValue(123).isArray());
- QVERIFY(!QScriptValue(false).isArray());
- QVERIFY(!eng.nullValue().isArray());
- QVERIFY(!eng.undefinedValue().isArray());
+ QFETCH(QScriptValue, value);
+ QFETCH(bool, array);
+
+ QCOMPARE(value.isArray(), array);
}
-void tst_QScriptValue::isDate_old()
+void tst_QScriptValue::isDate_data()
{
- QScriptEngine eng;
- QVERIFY(eng.evaluate("new Date()").isDate());
- QVERIFY(!eng.evaluate("[]").isDate());
- QVERIFY(!eng.evaluate("{}").isDate());
- QVERIFY(!eng.globalObject().isDate());
- QVERIFY(!QScriptValue().isDate());
- QVERIFY(!QScriptValue(123).isDate());
- QVERIFY(!QScriptValue(false).isDate());
- QVERIFY(!eng.nullValue().isDate());
- QVERIFY(!eng.undefinedValue().isDate());
+ newEngine();
+
+ QTest::addColumn<QScriptValue>("value");
+ QTest::addColumn<bool>("date");
+
+ QTest::newRow("date") << engine->evaluate("new Date()") << true;
+ QTest::newRow("[]") << engine->evaluate("[]") << false;
+ QTest::newRow("{}") << engine->evaluate("{}") << false;
+ QTest::newRow("globalObject") << engine->globalObject() << false;
+ QTest::newRow("invalid") << QScriptValue() << false;
+ QTest::newRow("number") << QScriptValue(123) << false;
+ QTest::newRow("bool") << QScriptValue(false) << false;
+ QTest::newRow("null") << engine->nullValue() << false;
+ QTest::newRow("undefined") << engine->undefinedValue() << false;
}
-void tst_QScriptValue::isError_old()
+void tst_QScriptValue::isDate()
+{
+ QFETCH(QScriptValue, value);
+ QFETCH(bool, date);
+
+ QCOMPARE(value.isDate(), date);
+}
+
+void tst_QScriptValue::isError_propertiesOfGlobalObject()
{
QStringList errors;
errors << "Error"
@@ -1675,27 +1707,60 @@ void tst_QScriptValue::isError_old()
QVERIFY(ctor.isFunction());
QVERIFY(ctor.property("prototype").isError());
}
- QVERIFY(!eng.globalObject().isError());
- QVERIFY(!QScriptValue().isError());
- QVERIFY(!QScriptValue(123).isError());
- QVERIFY(!QScriptValue(false).isError());
- QVERIFY(!eng.nullValue().isError());
- QVERIFY(!eng.undefinedValue().isError());
- QVERIFY(!eng.evaluate("new Object()").isError());
}
-void tst_QScriptValue::isRegExp_old()
+void tst_QScriptValue::isError_data()
{
- QScriptEngine eng;
- QVERIFY(eng.evaluate("/foo/").isRegExp());
- QVERIFY(!eng.evaluate("[]").isRegExp());
- QVERIFY(!eng.evaluate("{}").isRegExp());
- QVERIFY(!eng.globalObject().isRegExp());
- QVERIFY(!QScriptValue().isRegExp());
- QVERIFY(!QScriptValue(123).isRegExp());
- QVERIFY(!QScriptValue(false).isRegExp());
- QVERIFY(!eng.nullValue().isRegExp());
- QVERIFY(!eng.undefinedValue().isRegExp());
+ newEngine();
+
+ QTest::addColumn<QScriptValue>("value");
+ QTest::addColumn<bool>("error");
+
+ QTest::newRow("syntax error") << engine->evaluate("%fsdg's") << true;
+ QTest::newRow("[]") << engine->evaluate("[]") << false;
+ QTest::newRow("{}") << engine->evaluate("{}") << false;
+ QTest::newRow("globalObject") << engine->globalObject() << false;
+ QTest::newRow("invalid") << QScriptValue() << false;
+ QTest::newRow("number") << QScriptValue(123) << false;
+ QTest::newRow("bool") << QScriptValue(false) << false;
+ QTest::newRow("null") << engine->nullValue() << false;
+ QTest::newRow("undefined") << engine->undefinedValue() << false;
+ QTest::newRow("newObject") << engine->newObject() << false;
+ QTest::newRow("new Object") << engine->evaluate("new Object()") << false;
+}
+
+void tst_QScriptValue::isError()
+{
+ QFETCH(QScriptValue, value);
+ QFETCH(bool, error);
+
+ QCOMPARE(value.isError(), error);
+}
+
+void tst_QScriptValue::isRegExp_data()
+{
+ newEngine();
+
+ QTest::addColumn<QScriptValue>("value");
+ QTest::addColumn<bool>("regexp");
+
+ QTest::newRow("/foo/") << engine->evaluate("/foo/") << true;
+ QTest::newRow("[]") << engine->evaluate("[]") << false;
+ QTest::newRow("{}") << engine->evaluate("{}") << false;
+ QTest::newRow("globalObject") << engine->globalObject() << false;
+ QTest::newRow("invalid") << QScriptValue() << false;
+ QTest::newRow("number") << QScriptValue(123) << false;
+ QTest::newRow("bool") << QScriptValue(false) << false;
+ QTest::newRow("null") << engine->nullValue() << false;
+ QTest::newRow("undefined") << engine->undefinedValue() << false;
+}
+
+void tst_QScriptValue::isRegExp()
+{
+ QFETCH(QScriptValue, value);
+ QFETCH(bool, regexp);
+
+ QCOMPARE(value.isRegExp(), regexp);
}
static QScriptValue getter(QScriptContext *ctx, QScriptEngine *)
@@ -1731,48 +1796,9 @@ static QScriptValue getSet__proto__(QScriptContext *ctx, QScriptEngine *)
return ctx->callee().property("value");
}
-void tst_QScriptValue::getSetProperty()
+void tst_QScriptValue::getSetProperty_HooliganTask162051()
{
QScriptEngine eng;
-
- QScriptValue object = eng.newObject();
-
- QScriptValue str = QScriptValue(&eng, "bar");
- object.setProperty("foo", str);
- QCOMPARE(object.property("foo").toString(), str.toString());
-
- QScriptValue num = QScriptValue(&eng, 123.0);
- object.setProperty("baz", num);
- QCOMPARE(object.property("baz").toNumber(), num.toNumber());
-
- QScriptValue strstr = QScriptValue("bar");
- QCOMPARE(strstr.engine(), (QScriptEngine *)0);
- object.setProperty("foo", strstr);
- QCOMPARE(object.property("foo").toString(), strstr.toString());
- QCOMPARE(strstr.engine(), &eng); // the value has been bound to the engine
-
- QScriptValue numnum = QScriptValue(123.0);
- object.setProperty("baz", numnum);
- QCOMPARE(object.property("baz").toNumber(), numnum.toNumber());
-
- QScriptValue inv;
- inv.setProperty("foo", num);
- QCOMPARE(inv.property("foo").isValid(), false);
-
- QScriptValue array = eng.newArray();
- QVERIFY(array.isArray());
- array.setProperty(0, num);
- QCOMPARE(array.property(0).toNumber(), num.toNumber());
- QCOMPARE(array.property("0").toNumber(), num.toNumber());
- QCOMPARE(array.property("length").toUInt32(), quint32(1));
- array.setProperty(1, str);
- QCOMPARE(array.property(1).toString(), str.toString());
- QCOMPARE(array.property("1").toString(), str.toString());
- QCOMPARE(array.property("length").toUInt32(), quint32(2));
- array.setProperty("length", QScriptValue(&eng, 1));
- QCOMPARE(array.property("length").toUInt32(), quint32(1));
- QCOMPARE(array.property(1).isValid(), false);
-
// task 162051 -- detecting whether the property is an array index or not
QVERIFY(eng.evaluate("a = []; a['00'] = 123; a['00']").strictlyEquals(QScriptValue(&eng, 123)));
QVERIFY(eng.evaluate("a.length").strictlyEquals(QScriptValue(&eng, 0)));
@@ -1785,24 +1811,62 @@ void tst_QScriptValue::getSetProperty()
QVERIFY(eng.evaluate("a[0]").isUndefined());
QVERIFY(eng.evaluate("a[0] = 789; a[0]").strictlyEquals(QScriptValue(&eng, 789)));
QVERIFY(eng.evaluate("a.length").strictlyEquals(QScriptValue(&eng, 1)));
+}
+void tst_QScriptValue::getSetProperty_HooliganTask183072()
+{
+ QScriptEngine eng;
// task 183072 -- 0x800000000 is not an array index
eng.evaluate("a = []; a[0x800000000] = 123");
QVERIFY(eng.evaluate("a.length").strictlyEquals(QScriptValue(&eng, 0)));
QVERIFY(eng.evaluate("a[0]").isUndefined());
QVERIFY(eng.evaluate("a[0x800000000]").strictlyEquals(QScriptValue(&eng, 123)));
+}
- QScriptEngine otherEngine;
- QScriptValue otherNum = QScriptValue(&otherEngine, 123);
- QTest::ignoreMessage(QtWarningMsg, "QScriptValue::setProperty(oof) failed: cannot set value created in a different engine");
- object.setProperty("oof", otherNum);
- QCOMPARE(object.property("oof").isValid(), false);
+void tst_QScriptValue::getSetProperty_propertyRemoval()
+{
+ // test property removal (setProperty(QScriptValue()))
+ QScriptEngine eng;
+ QScriptValue object = eng.newObject();
+ QScriptValue str = QScriptValue(&eng, "bar");
+ QScriptValue num = QScriptValue(&eng, 123.0);
+ object.setProperty("foo", num);
+ QCOMPARE(object.property("foo").strictlyEquals(num), true);
+ object.setProperty("bar", str);
+ QCOMPARE(object.property("bar").strictlyEquals(str), true);
+ object.setProperty("foo", QScriptValue());
+ QCOMPARE(object.property("foo").isValid(), false);
+ QCOMPARE(object.property("bar").strictlyEquals(str), true);
+ object.setProperty("foo", num);
+ QCOMPARE(object.property("foo").strictlyEquals(num), true);
+ QCOMPARE(object.property("bar").strictlyEquals(str), true);
+ object.setProperty("bar", QScriptValue());
+ QCOMPARE(object.property("bar").isValid(), false);
+ QCOMPARE(object.property("foo").strictlyEquals(num), true);
+ object.setProperty("foo", QScriptValue());
+ object.setProperty("foo", QScriptValue());
+
+ eng.globalObject().setProperty("object3", object);
+ QCOMPARE(eng.evaluate("object3.hasOwnProperty('foo')")
+ .strictlyEquals(QScriptValue(&eng, false)), true);
+ object.setProperty("foo", num);
+ QCOMPARE(eng.evaluate("object3.hasOwnProperty('foo')")
+ .strictlyEquals(QScriptValue(&eng, true)), true);
+ eng.globalObject().setProperty("object3", QScriptValue());
+ QCOMPARE(eng.evaluate("this.hasOwnProperty('object3')")
+ .strictlyEquals(QScriptValue(&eng, false)), true);
+}
+
+void tst_QScriptValue::getSetProperty_resolveMode()
+{
// test ResolveMode
- QScriptValue object2 = eng.newObject();
- object.setPrototype(object2);
+ QScriptEngine eng;
+ QScriptValue object = eng.newObject();
+ QScriptValue prototype = eng.newObject();
+ object.setPrototype(prototype);
QScriptValue num2 = QScriptValue(&eng, 456.0);
- object2.setProperty("propertyInPrototype", num2);
+ prototype.setProperty("propertyInPrototype", num2);
// default is ResolvePrototype
QCOMPARE(object.property("propertyInPrototype")
.strictlyEquals(num2), true);
@@ -1814,199 +1878,247 @@ void tst_QScriptValue::getSetProperty()
.strictlyEquals(num2), false);
QCOMPARE(object.property("propertyInPrototype", QScriptValue::ResolveFull)
.strictlyEquals(num2), true);
+}
- // test property removal (setProperty(QScriptValue()))
- QScriptValue object3 = eng.newObject();
- object3.setProperty("foo", num);
- QCOMPARE(object3.property("foo").strictlyEquals(num), true);
- object3.setProperty("bar", str);
- QCOMPARE(object3.property("bar").strictlyEquals(str), true);
- object3.setProperty("foo", QScriptValue());
- QCOMPARE(object3.property("foo").isValid(), false);
- QCOMPARE(object3.property("bar").strictlyEquals(str), true);
- object3.setProperty("foo", num);
- QCOMPARE(object3.property("foo").strictlyEquals(num), true);
- QCOMPARE(object3.property("bar").strictlyEquals(str), true);
- object3.setProperty("bar", QScriptValue());
- QCOMPARE(object3.property("bar").isValid(), false);
- QCOMPARE(object3.property("foo").strictlyEquals(num), true);
- object3.setProperty("foo", QScriptValue());
- object3.setProperty("foo", QScriptValue());
-
- eng.globalObject().setProperty("object3", object3);
- QCOMPARE(eng.evaluate("object3.hasOwnProperty('foo')")
- .strictlyEquals(QScriptValue(&eng, false)), true);
- object3.setProperty("foo", num);
- QCOMPARE(eng.evaluate("object3.hasOwnProperty('foo')")
- .strictlyEquals(QScriptValue(&eng, true)), true);
- eng.globalObject().setProperty("object3", QScriptValue());
- QCOMPARE(eng.evaluate("this.hasOwnProperty('object3')")
- .strictlyEquals(QScriptValue(&eng, false)), true);
+void tst_QScriptValue::getSetProperty_twoEngines()
+{
+ QScriptEngine engine;
+ QScriptValue object = engine.newObject();
- // getters and setters
- {
- QScriptValue object4 = eng.newObject();
- for (int x = 0; x < 2; ++x) {
- object4.setProperty("foo", QScriptValue());
- // getter() returns this.x
- object4.setProperty("foo", eng.newFunction(getter),
- QScriptValue::PropertyGetter | QScriptValue::UserRange);
- QCOMPARE(object4.propertyFlags("foo") & ~QScriptValue::UserRange,
- QScriptValue::PropertyGetter );
-
- QEXPECT_FAIL("", "User-range flags are not retained for getter/setter properties", Continue);
- QCOMPARE(object4.propertyFlags("foo"),
- QScriptValue::PropertyGetter | QScriptValue::UserRange);
- object4.setProperty("x", num);
- QCOMPARE(object4.property("foo").strictlyEquals(num), true);
-
- // setter() sets this.x
- object4.setProperty("foo", eng.newFunction(setter),
- QScriptValue::PropertySetter);
- QCOMPARE(object4.propertyFlags("foo") & ~QScriptValue::UserRange,
- QScriptValue::PropertySetter | QScriptValue::PropertyGetter);
-
- QCOMPARE(object4.propertyFlags("foo"),
- QScriptValue::PropertySetter | QScriptValue::PropertyGetter);
- object4.setProperty("foo", str);
- QCOMPARE(object4.property("x").strictlyEquals(str), true);
- QCOMPARE(object4.property("foo").strictlyEquals(str), true);
-
- // kill the getter
- object4.setProperty("foo", QScriptValue(), QScriptValue::PropertyGetter);
- QVERIFY(!(object4.propertyFlags("foo") & QScriptValue::PropertyGetter));
- QVERIFY(object4.propertyFlags("foo") & QScriptValue::PropertySetter);
- QCOMPARE(object4.property("foo").isUndefined(), true);
-
- // setter should still work
- object4.setProperty("foo", num);
- QCOMPARE(object4.property("x").strictlyEquals(num), true);
-
- // kill the setter too
- object4.setProperty("foo", QScriptValue(), QScriptValue::PropertySetter);
- QVERIFY(!(object4.propertyFlags("foo") & QScriptValue::PropertySetter));
- // now foo is just a regular property
- object4.setProperty("foo", str);
- QCOMPARE(object4.property("x").strictlyEquals(num), true);
- QCOMPARE(object4.property("foo").strictlyEquals(str), true);
- }
+ QScriptEngine otherEngine;
+ QScriptValue otherNum = QScriptValue(&otherEngine, 123);
+ QTest::ignoreMessage(QtWarningMsg, "QScriptValue::setProperty(oof) failed: cannot set value created in a different engine");
+ object.setProperty("oof", otherNum);
+ QCOMPARE(object.property("oof").isValid(), false);
+}
- for (int x = 0; x < 2; ++x) {
- object4.setProperty("foo", QScriptValue());
- // setter() sets this.x
- object4.setProperty("foo", eng.newFunction(setter), QScriptValue::PropertySetter);
- object4.setProperty("foo", str);
- QCOMPARE(object4.property("x").strictlyEquals(str), true);
- QCOMPARE(object4.property("foo").isUndefined(), true);
-
- // getter() returns this.x
- object4.setProperty("foo", eng.newFunction(getter), QScriptValue::PropertyGetter);
- object4.setProperty("x", num);
- QCOMPARE(object4.property("foo").strictlyEquals(num), true);
-
- // kill the setter
- object4.setProperty("foo", QScriptValue(), QScriptValue::PropertySetter);
- QTest::ignoreMessage(QtWarningMsg, "QScriptValue::setProperty() failed: property 'foo' has a getter but no setter");
- object4.setProperty("foo", str);
-
- // getter should still work
- QCOMPARE(object4.property("foo").strictlyEquals(num), true);
-
- // kill the getter too
- object4.setProperty("foo", QScriptValue(), QScriptValue::PropertyGetter);
- // now foo is just a regular property
- object4.setProperty("foo", str);
- QCOMPARE(object4.property("x").strictlyEquals(num), true);
- QCOMPARE(object4.property("foo").strictlyEquals(str), true);
- }
- // use a single function as both getter and setter
- object4.setProperty("foo", QScriptValue());
- object4.setProperty("foo", eng.newFunction(getterSetter),
- QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- QCOMPARE(object4.propertyFlags("foo"),
- QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- object4.setProperty("x", num);
- QCOMPARE(object4.property("foo").strictlyEquals(num), true);
-
- // killing the getter will preserve the setter, even though they are the same function
- object4.setProperty("foo", QScriptValue(), QScriptValue::PropertyGetter);
- QVERIFY(object4.propertyFlags("foo") & QScriptValue::PropertySetter);
- QCOMPARE(object4.property("foo").isUndefined(), true);
-
- // getter/setter that throws an error
- {
- QScriptValue object5 = eng.newObject();
- object5.setProperty("foo", eng.newFunction(getterSetterThrowingError),
- QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- QVERIFY(!eng.hasUncaughtException());
- QScriptValue ret = object5.property("foo");
- QVERIFY(ret.isError());
- QVERIFY(eng.hasUncaughtException());
- QVERIFY(ret.strictlyEquals(eng.uncaughtException()));
- eng.evaluate("Object"); // clear exception state...
- QVERIFY(!eng.hasUncaughtException());
- object5.setProperty("foo", str);
- QVERIFY(eng.hasUncaughtException());
- QCOMPARE(eng.uncaughtException().toString(), QLatin1String("Error: set foo"));
- }
+void tst_QScriptValue::getSetProperty_gettersAndSetters()
+{
+ QScriptEngine eng;
+ QScriptValue str = QScriptValue(&eng, "bar");
+ QScriptValue num = QScriptValue(&eng, 123.0);
+ QScriptValue object = eng.newObject();
+ for (int x = 0; x < 2; ++x) {
+ object.setProperty("foo", QScriptValue());
+ // getter() returns this.x
+ object.setProperty("foo", eng.newFunction(getter),
+ QScriptValue::PropertyGetter | QScriptValue::UserRange);
+ QCOMPARE(object.propertyFlags("foo") & ~QScriptValue::UserRange,
+ QScriptValue::PropertyGetter );
+
+ QEXPECT_FAIL("", "User-range flags are not retained for getter/setter properties", Continue);
+ QCOMPARE(object.propertyFlags("foo"),
+ QScriptValue::PropertyGetter | QScriptValue::UserRange);
+ object.setProperty("x", num);
+ QCOMPARE(object.property("foo").strictlyEquals(num), true);
+
+ // setter() sets this.x
+ object.setProperty("foo", eng.newFunction(setter),
+ QScriptValue::PropertySetter);
+ QCOMPARE(object.propertyFlags("foo") & ~QScriptValue::UserRange,
+ QScriptValue::PropertySetter | QScriptValue::PropertyGetter);
+
+ QCOMPARE(object.propertyFlags("foo"),
+ QScriptValue::PropertySetter | QScriptValue::PropertyGetter);
+ object.setProperty("foo", str);
+ QCOMPARE(object.property("x").strictlyEquals(str), true);
+ QCOMPARE(object.property("foo").strictlyEquals(str), true);
+
+ // kill the getter
+ object.setProperty("foo", QScriptValue(), QScriptValue::PropertyGetter);
+ QVERIFY(!(object.propertyFlags("foo") & QScriptValue::PropertyGetter));
+ QVERIFY(object.propertyFlags("foo") & QScriptValue::PropertySetter);
+ QCOMPARE(object.property("foo").isUndefined(), true);
+
+ // setter should still work
+ object.setProperty("foo", num);
+ QCOMPARE(object.property("x").strictlyEquals(num), true);
+
+ // kill the setter too
+ object.setProperty("foo", QScriptValue(), QScriptValue::PropertySetter);
+ QVERIFY(!(object.propertyFlags("foo") & QScriptValue::PropertySetter));
+ // now foo is just a regular property
+ object.setProperty("foo", str);
+ QCOMPARE(object.property("x").strictlyEquals(num), true);
+ QCOMPARE(object.property("foo").strictlyEquals(str), true);
+ }
+
+ for (int x = 0; x < 2; ++x) {
+ object.setProperty("foo", QScriptValue());
+ // setter() sets this.x
+ object.setProperty("foo", eng.newFunction(setter), QScriptValue::PropertySetter);
+ object.setProperty("foo", str);
+ QCOMPARE(object.property("x").strictlyEquals(str), true);
+ QCOMPARE(object.property("foo").isUndefined(), true);
+
+ // getter() returns this.x
+ object.setProperty("foo", eng.newFunction(getter), QScriptValue::PropertyGetter);
+ object.setProperty("x", num);
+ QCOMPARE(object.property("foo").strictlyEquals(num), true);
+
+ // kill the setter
+ object.setProperty("foo", QScriptValue(), QScriptValue::PropertySetter);
+ QTest::ignoreMessage(QtWarningMsg, "QScriptValue::setProperty() failed: property 'foo' has a getter but no setter");
+ object.setProperty("foo", str);
+
+ // getter should still work
+ QCOMPARE(object.property("foo").strictlyEquals(num), true);
+
+ // kill the getter too
+ object.setProperty("foo", QScriptValue(), QScriptValue::PropertyGetter);
+ // now foo is just a regular property
+ object.setProperty("foo", str);
+ QCOMPARE(object.property("x").strictlyEquals(num), true);
+ QCOMPARE(object.property("foo").strictlyEquals(str), true);
+ }
+
+ // use a single function as both getter and setter
+ object.setProperty("foo", QScriptValue());
+ object.setProperty("foo", eng.newFunction(getterSetter),
+ QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ QCOMPARE(object.propertyFlags("foo"),
+ QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ object.setProperty("x", num);
+ QCOMPARE(object.property("foo").strictlyEquals(num), true);
+
+ // killing the getter will preserve the setter, even though they are the same function
+ object.setProperty("foo", QScriptValue(), QScriptValue::PropertyGetter);
+ QVERIFY(object.propertyFlags("foo") & QScriptValue::PropertySetter);
+ QCOMPARE(object.property("foo").isUndefined(), true);
+}
- // attempt to install getter+setter on built-in (native) property
- {
- QScriptValue object6 = eng.newObject();
- QVERIFY(object6.property("__proto__").strictlyEquals(object6.prototype()));
-
- QScriptValue fun = eng.newFunction(getSet__proto__);
- fun.setProperty("value", QScriptValue(&eng, "boo"));
- QTest::ignoreMessage(QtWarningMsg, "QScriptValue::setProperty() failed: "
- "cannot set getter or setter of native property "
- "`__proto__'");
- object6.setProperty("__proto__", fun,
- QScriptValue::PropertyGetter | QScriptValue::PropertySetter
- | QScriptValue::UserRange);
- QVERIFY(object6.property("__proto__").strictlyEquals(object6.prototype()));
-
- object6.setProperty("__proto__", QScriptValue(),
- QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- QVERIFY(object6.property("__proto__").strictlyEquals(object6.prototype()));
- }
+void tst_QScriptValue::getSetProperty_gettersAndSettersThrowError()
+{
+ // getter/setter that throws an error
+ QScriptEngine eng;
+ QScriptValue str = QScriptValue(&eng, "bar");
+ QScriptValue object = eng.newObject();
- // global property that's a getter+setter
- {
- eng.globalObject().setProperty("globalGetterSetterProperty", eng.newFunction(getterSetter),
- QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- eng.evaluate("globalGetterSetterProperty = 123");
- {
- QScriptValue ret = eng.evaluate("globalGetterSetterProperty");
- QVERIFY(ret.isNumber());
- QVERIFY(ret.strictlyEquals(QScriptValue(&eng, 123)));
- }
- QCOMPARE(eng.evaluate("typeof globalGetterSetterProperty").toString(),
- QString::fromLatin1("number"));
- {
- QScriptValue ret = eng.evaluate("this.globalGetterSetterProperty()");
- QVERIFY(ret.isError());
- QCOMPARE(ret.toString(), QString::fromLatin1("TypeError: Result of expression 'this.globalGetterSetterProperty' [123] is not a function."));
- }
- {
- QScriptValue ret = eng.evaluate("new this.globalGetterSetterProperty()");
- QVERIFY(ret.isError());
- QCOMPARE(ret.toString(), QString::fromLatin1("TypeError: Result of expression 'this.globalGetterSetterProperty' [123] is not a constructor."));
- }
- }
+ object.setProperty("foo", eng.newFunction(getterSetterThrowingError),
+ QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ QVERIFY(!eng.hasUncaughtException());
+ QScriptValue ret = object.property("foo");
+ QVERIFY(ret.isError());
+ QVERIFY(eng.hasUncaughtException());
+ QVERIFY(ret.strictlyEquals(eng.uncaughtException()));
+ eng.evaluate("Object"); // clear exception state...
+ QVERIFY(!eng.hasUncaughtException());
+ object.setProperty("foo", str);
+ QVERIFY(eng.hasUncaughtException());
+ QCOMPARE(eng.uncaughtException().toString(), QLatin1String("Error: set foo"));
+}
- // "upgrading" an existing property to become a getter+setter
- {
- QScriptValue object7 = eng.newObject();
- QScriptValue num(&eng, 123);
- object7.setProperty("foo", num);
- object7.setProperty("foo", eng.newFunction(getterSetter),
- QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
- QVERIFY(!object7.property("x").isValid());
- object7.setProperty("foo", num);
- QVERIFY(object7.property("x").equals(num));
- }
+void tst_QScriptValue::getSetProperty_gettersAndSettersOnNative()
+{
+ // attempt to install getter+setter on built-in (native) property
+ QScriptEngine eng;
+ QScriptValue object = eng.newObject();
+ QVERIFY(object.property("__proto__").strictlyEquals(object.prototype()));
+
+ QScriptValue fun = eng.newFunction(getSet__proto__);
+ fun.setProperty("value", QScriptValue(&eng, "boo"));
+ QTest::ignoreMessage(QtWarningMsg, "QScriptValue::setProperty() failed: "
+ "cannot set getter or setter of native property "
+ "`__proto__'");
+ object.setProperty("__proto__", fun,
+ QScriptValue::PropertyGetter | QScriptValue::PropertySetter
+ | QScriptValue::UserRange);
+ QVERIFY(object.property("__proto__").strictlyEquals(object.prototype()));
+
+ object.setProperty("__proto__", QScriptValue(),
+ QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ QVERIFY(object.property("__proto__").strictlyEquals(object.prototype()));
+}
+
+void tst_QScriptValue::getSetProperty_gettersAndSettersOnGlobalObject()
+{
+ // global property that's a getter+setter
+ QScriptEngine eng;
+ eng.globalObject().setProperty("globalGetterSetterProperty", eng.newFunction(getterSetter),
+ QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ eng.evaluate("globalGetterSetterProperty = 123");
+ {
+ QScriptValue ret = eng.evaluate("globalGetterSetterProperty");
+ QVERIFY(ret.isNumber());
+ QVERIFY(ret.strictlyEquals(QScriptValue(&eng, 123)));
}
+ QCOMPARE(eng.evaluate("typeof globalGetterSetterProperty").toString(),
+ QString::fromLatin1("number"));
+ {
+ QScriptValue ret = eng.evaluate("this.globalGetterSetterProperty()");
+ QVERIFY(ret.isError());
+ QCOMPARE(ret.toString(), QString::fromLatin1("TypeError: Result of expression 'this.globalGetterSetterProperty' [123] is not a function."));
+ }
+ {
+ QScriptValue ret = eng.evaluate("new this.globalGetterSetterProperty()");
+ QVERIFY(ret.isError());
+ QCOMPARE(ret.toString(), QString::fromLatin1("TypeError: Result of expression 'this.globalGetterSetterProperty' [123] is not a constructor."));
+ }
+}
+
+void tst_QScriptValue::getSetProperty_gettersAndSettersChange()
+{
+ // "upgrading" an existing property to become a getter+setter
+ QScriptEngine eng;
+ QScriptValue object = eng.newObject();
+ QScriptValue num(&eng, 123);
+ object.setProperty("foo", num);
+ object.setProperty("foo", eng.newFunction(getterSetter),
+ QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
+ QVERIFY(!object.property("x").isValid());
+ object.setProperty("foo", num);
+ QVERIFY(object.property("x").equals(num));
+}
+
+void tst_QScriptValue::getSetProperty_array()
+{
+ QScriptEngine eng;
+ QScriptValue str = QScriptValue(&eng, "bar");
+ QScriptValue num = QScriptValue(&eng, 123.0);
+ QScriptValue array = eng.newArray();
+
+ QVERIFY(array.isArray());
+ array.setProperty(0, num);
+ QCOMPARE(array.property(0).toNumber(), num.toNumber());
+ QCOMPARE(array.property("0").toNumber(), num.toNumber());
+ QCOMPARE(array.property("length").toUInt32(), quint32(1));
+ array.setProperty(1, str);
+ QCOMPARE(array.property(1).toString(), str.toString());
+ QCOMPARE(array.property("1").toString(), str.toString());
+ QCOMPARE(array.property("length").toUInt32(), quint32(2));
+ array.setProperty("length", QScriptValue(&eng, 1));
+ QCOMPARE(array.property("length").toUInt32(), quint32(1));
+ QCOMPARE(array.property(1).isValid(), false);
+}
+
+void tst_QScriptValue::getSetProperty()
+{
+ QScriptEngine eng;
+
+ QScriptValue object = eng.newObject();
+
+ QScriptValue str = QScriptValue(&eng, "bar");
+ object.setProperty("foo", str);
+ QCOMPARE(object.property("foo").toString(), str.toString());
+
+ QScriptValue num = QScriptValue(&eng, 123.0);
+ object.setProperty("baz", num);
+ QCOMPARE(object.property("baz").toNumber(), num.toNumber());
+
+ QScriptValue strstr = QScriptValue("bar");
+ QCOMPARE(strstr.engine(), (QScriptEngine *)0);
+ object.setProperty("foo", strstr);
+ QCOMPARE(object.property("foo").toString(), strstr.toString());
+ QCOMPARE(strstr.engine(), &eng); // the value has been bound to the engine
+
+ QScriptValue numnum = QScriptValue(123.0);
+ object.setProperty("baz", numnum);
+ QCOMPARE(object.property("baz").toNumber(), numnum.toNumber());
+
+ QScriptValue inv;
+ inv.setProperty("foo", num);
+ QCOMPARE(inv.property("foo").isValid(), false);
eng.globalObject().setProperty("object", object);
@@ -2155,50 +2267,78 @@ void tst_QScriptValue::arrayElementGetterSetter()
QVERIFY(obj.propertyFlags("1") == 0);
}
-void tst_QScriptValue::getSetPrototype()
+void tst_QScriptValue::getSetPrototype_cyclicPrototype()
{
QScriptEngine eng;
-
+ QScriptValue prototype = eng.newObject();
QScriptValue object = eng.newObject();
+ object.setPrototype(prototype);
- QScriptValue object2 = eng.newObject();
- object2.setPrototype(object);
+ QScriptValue previousPrototype = prototype.prototype();
+ QTest::ignoreMessage(QtWarningMsg, "QScriptValue::setPrototype() failed: cyclic prototype value");
+ prototype.setPrototype(prototype);
+ QCOMPARE(prototype.prototype().strictlyEquals(previousPrototype), true);
+
+ object.setPrototype(prototype);
+ QTest::ignoreMessage(QtWarningMsg, "QScriptValue::setPrototype() failed: cyclic prototype value");
+ prototype.setPrototype(object);
+ QCOMPARE(prototype.prototype().strictlyEquals(previousPrototype), true);
+
+}
- QCOMPARE(object2.prototype().strictlyEquals(object), true);
+void tst_QScriptValue::getSetPrototype_evalCyclicPrototype()
+{
+ QScriptEngine eng;
+ QScriptValue ret = eng.evaluate("o = { }; p = { }; o.__proto__ = p; p.__proto__ = o");
+ QCOMPARE(eng.hasUncaughtException(), true);
+ QVERIFY(ret.strictlyEquals(eng.uncaughtException()));
+ QCOMPARE(ret.isError(), true);
+ QCOMPARE(ret.toString(), QLatin1String("Error: cyclic __proto__ value"));
+}
+
+void tst_QScriptValue::getSetPrototype_eval()
+{
+ QScriptEngine eng;
+ QScriptValue ret = eng.evaluate("p = { }; p.__proto__ = { }");
+ QCOMPARE(eng.hasUncaughtException(), false);
+ QCOMPARE(ret.isError(), false);
+}
+void tst_QScriptValue::getSetPrototype_invalidPrototype()
+{
+ QScriptEngine eng;
QScriptValue inv;
+ QScriptValue object = eng.newObject();
+ QScriptValue proto = object.prototype();
+ QVERIFY(object.prototype().strictlyEquals(proto));
inv.setPrototype(object);
QCOMPARE(inv.prototype().isValid(), false);
+ object.setPrototype(inv);
+ // FIXME should it be invalid or proto?
+ QVERIFY(object.prototype().strictlyEquals(inv));
+}
+void tst_QScriptValue::getSetPrototype_twoEngines()
+{
+ QScriptEngine eng;
+ QScriptValue prototype = eng.newObject();
+ QScriptValue object = eng.newObject();
+ object.setPrototype(prototype);
QScriptEngine otherEngine;
- QScriptValue object3 = otherEngine.newObject();
+ QScriptValue newPrototype = otherEngine.newObject();
QTest::ignoreMessage(QtWarningMsg, "QScriptValue::setPrototype() failed: cannot set a prototype created in a different engine");
- object2.setPrototype(object3);
- QCOMPARE(object2.prototype().strictlyEquals(object), true);
+ object.setPrototype(newPrototype);
+ QCOMPARE(object.prototype().strictlyEquals(prototype), true);
- // cyclic prototypes
- QScriptValue old = object.prototype();
- QTest::ignoreMessage(QtWarningMsg, "QScriptValue::setPrototype() failed: cyclic prototype value");
- object.setPrototype(object);
- QCOMPARE(object.prototype().strictlyEquals(old), true);
-
- object2.setPrototype(object);
- QTest::ignoreMessage(QtWarningMsg, "QScriptValue::setPrototype() failed: cyclic prototype value");
- object.setPrototype(object2);
- QCOMPARE(object.prototype().strictlyEquals(old), true);
+}
- {
- QScriptValue ret = eng.evaluate("o = { }; p = { }; o.__proto__ = p; p.__proto__ = o");
- QCOMPARE(eng.hasUncaughtException(), true);
- QVERIFY(ret.strictlyEquals(eng.uncaughtException()));
- QCOMPARE(ret.isError(), true);
- QCOMPARE(ret.toString(), QLatin1String("Error: cyclic __proto__ value"));
- }
- {
- QScriptValue ret = eng.evaluate("p.__proto__ = { }");
- QCOMPARE(eng.hasUncaughtException(), false);
- QCOMPARE(ret.isError(), false);
- }
+void tst_QScriptValue::getSetPrototype()
+{
+ QScriptEngine eng;
+ QScriptValue prototype = eng.newObject();
+ QScriptValue object = eng.newObject();
+ object.setPrototype(prototype);
+ QCOMPARE(object.prototype().strictlyEquals(prototype), true);
}
void tst_QScriptValue::getSetScope()
@@ -2235,39 +2375,71 @@ void tst_QScriptValue::getSetScope()
QVERIFY(!object2.scope().isValid());
}
-void tst_QScriptValue::getSetData()
+void tst_QScriptValue::getSetData_objects_data()
{
- QScriptEngine eng;
- {
- QScriptValue object = eng.newObject();
- QVERIFY(!object.data().isValid());
- QScriptValue v1(true);
- object.setData(v1);
- QVERIFY(object.data().strictlyEquals(v1));
- QScriptValue v2(123);
- object.setData(v2);
- QVERIFY(object.data().strictlyEquals(v2));
- QScriptValue v3 = eng.newObject();
- object.setData(v3);
- QVERIFY(object.data().strictlyEquals(v3));
- object.setData(QScriptValue());
- QVERIFY(!object.data().isValid());
- }
- {
- QScriptValue value = eng.undefinedValue();
- QVERIFY(!value.data().isValid());
- QScriptValue v1(true);
- value.setData(v1);
- QVERIFY(!value.data().isValid());
- QScriptValue v2(123);
- value.setData(v2);
- QVERIFY(!value.data().isValid());
- QScriptValue v3 = eng.newObject();
- value.setData(v3);
- QVERIFY(!value.data().isValid());
- value.setData(QScriptValue());
- QVERIFY(!value.data().isValid());
- }
+ newEngine();
+
+ QTest::addColumn<QScriptValue>("object");
+
+ QTest::newRow("object from evaluate") << engine->evaluate("new Object()");
+ QTest::newRow("object from engine") << engine->newObject();
+ QTest::newRow("Array") << engine->newArray();
+ QTest::newRow("Date") << engine->newDate(12324);
+ QTest::newRow("QObject") << engine->newQObject(this);
+ QTest::newRow("RegExp") << engine->newRegExp(QRegExp());
+}
+
+void tst_QScriptValue::getSetData_objects()
+{
+ QFETCH(QScriptValue, object);
+
+ QVERIFY(!object.data().isValid());
+ QScriptValue v1(true);
+ object.setData(v1);
+ QVERIFY(object.data().strictlyEquals(v1));
+ QScriptValue v2(123);
+ object.setData(v2);
+ QVERIFY(object.data().strictlyEquals(v2));
+ QScriptValue v3 = engine->newObject();
+ object.setData(v3);
+ QVERIFY(object.data().strictlyEquals(v3));
+ object.setData(QScriptValue());
+ QVERIFY(!object.data().isValid());
+}
+
+void tst_QScriptValue::getSetData_nonObjects_data()
+{
+ newEngine();
+
+ QTest::addColumn<QScriptValue>("value");
+
+ QTest::newRow("undefined (bound)") << engine->undefinedValue();
+ QTest::newRow("null (bound)") << engine->nullValue();
+ QTest::newRow("string (bound)") << QScriptValue(engine, "Pong");
+ QTest::newRow("bool (bound)") << QScriptValue(engine, false);
+
+ QTest::newRow("undefined") << QScriptValue(QScriptValue::UndefinedValue);
+ QTest::newRow("null") << QScriptValue(QScriptValue::NullValue);
+ QTest::newRow("string") << QScriptValue("Pong");
+ QTest::newRow("bool") << QScriptValue(true);
+}
+
+void tst_QScriptValue::getSetData_nonObjects()
+{
+ QFETCH(QScriptValue, value);
+
+ QVERIFY(!value.data().isValid());
+ QScriptValue v1(true);
+ value.setData(v1);
+ QVERIFY(!value.data().isValid());
+ QScriptValue v2(123);
+ value.setData(v2);
+ QVERIFY(!value.data().isValid());
+ QScriptValue v3 = engine->newObject();
+ value.setData(v3);
+ QVERIFY(!value.data().isValid());
+ value.setData(QScriptValue());
+ QVERIFY(!value.data().isValid());
}
class TestScriptClass : public QScriptClass
@@ -2276,24 +2448,52 @@ public:
TestScriptClass(QScriptEngine *engine) : QScriptClass(engine) {}
};
-void tst_QScriptValue::getSetScriptClass()
+void tst_QScriptValue::getSetScriptClass_emptyClass_data()
{
- QScriptEngine eng;
- QScriptValue inv;
- QCOMPARE(inv.scriptClass(), (QScriptClass*)0);
- QScriptValue num(123);
- QCOMPARE(num.scriptClass(), (QScriptClass*)0);
+ newEngine();
+ QTest::addColumn<QScriptValue>("value");
+
+ QTest::newRow("invalid") << QScriptValue();
+ QTest::newRow("number") << QScriptValue(123);
+ QTest::newRow("string") << QScriptValue("pong");
+ QTest::newRow("bool") << QScriptValue(false);
+ QTest::newRow("null") << QScriptValue(QScriptValue::NullValue);
+ QTest::newRow("undefined") << QScriptValue(QScriptValue::UndefinedValue);
+
+ QTest::newRow("number") << QScriptValue(engine, 123);
+ QTest::newRow("string") << QScriptValue(engine, "pong");
+ QTest::newRow("bool") << QScriptValue(engine, true);
+ QTest::newRow("null") << QScriptValue(engine->nullValue());
+ QTest::newRow("undefined") << QScriptValue(engine->undefinedValue());
+ QTest::newRow("object") << QScriptValue(engine->newObject());
+ QTest::newRow("date") << QScriptValue(engine->evaluate("new Date()"));
+ QTest::newRow("qobject") << QScriptValue(engine->newQObject(this));
+}
+void tst_QScriptValue::getSetScriptClass_emptyClass()
+{
+ QFETCH(QScriptValue, value);
+ QCOMPARE(value.scriptClass(), (QScriptClass*)0);
+}
+
+void tst_QScriptValue::getSetScriptClass_JSObjectFromCpp()
+{
+ QScriptEngine eng;
TestScriptClass testClass(&eng);
// object created in C++ (newObject())
{
QScriptValue obj = eng.newObject();
- QCOMPARE(obj.scriptClass(), (QScriptClass*)0);
obj.setScriptClass(&testClass);
QCOMPARE(obj.scriptClass(), (QScriptClass*)&testClass);
obj.setScriptClass(0);
QCOMPARE(obj.scriptClass(), (QScriptClass*)0);
}
+}
+
+void tst_QScriptValue::getSetScriptClass_JSObjectFromJS()
+{
+ QScriptEngine eng;
+ TestScriptClass testClass(&eng);
// object created in JS
{
QScriptValue obj = eng.evaluate("new Object");
@@ -2308,6 +2508,12 @@ void tst_QScriptValue::getSetScriptClass()
obj.setScriptClass(0);
QCOMPARE(obj.scriptClass(), (QScriptClass*)0);
}
+}
+
+void tst_QScriptValue::getSetScriptClass_QVariant()
+{
+ QScriptEngine eng;
+ TestScriptClass testClass(&eng);
// object that already has a(n internal) class
{
QScriptValue obj = eng.newVariant(QUrl("http://example.com"));
@@ -2319,10 +2525,15 @@ void tst_QScriptValue::getSetScriptClass()
QVERIFY(!obj.isVariant());
QCOMPARE(obj.toVariant(), QVariant(QVariantMap()));
}
+}
+
+void tst_QScriptValue::getSetScriptClass_QObject()
+{
+ QScriptEngine eng;
+ TestScriptClass testClass(&eng);
{
QScriptValue obj = eng.newQObject(this);
QVERIFY(obj.isQObject());
- QCOMPARE(obj.scriptClass(), (QScriptClass*)0);
obj.setScriptClass(&testClass);
QCOMPARE(obj.scriptClass(), (QScriptClass*)&testClass);
QVERIFY(obj.isObject());
@@ -2351,83 +2562,89 @@ static QScriptValue returnInvalidValue(QScriptContext *, QScriptEngine *)
return QScriptValue();
}
-void tst_QScriptValue::call()
+void tst_QScriptValue::call_function()
{
QScriptEngine eng;
+ QScriptValue fun = eng.evaluate("(function() { return 1; })");
+ QVERIFY(fun.isFunction());
+ QScriptValue result = fun.call();
+ QVERIFY(result.isNumber());
+ QCOMPARE(result.toInt32(), 1);
+}
- {
- QScriptValue fun = eng.evaluate("(function() { return 1; })");
- QVERIFY(fun.isFunction());
- QScriptValue result = fun.call();
- QVERIFY(result.isNumber());
- QCOMPARE(result.toInt32(), 1);
- }
-
+void tst_QScriptValue::call_object()
+{
+ QScriptEngine eng;
QScriptValue Object = eng.evaluate("Object");
QCOMPARE(Object.isFunction(), true);
- {
- QScriptValue result = Object.call(Object);
- QCOMPARE(result.isObject(), true);
- }
+ QScriptValue result = Object.call(Object);
+ QCOMPARE(result.isObject(), true);
+}
+void tst_QScriptValue::call_newObjects()
+{
+ QScriptEngine eng;
// test that call() doesn't construct new objects
QScriptValue Number = eng.evaluate("Number");
+ QScriptValue Object = eng.evaluate("Object");
QCOMPARE(Object.isFunction(), true);
- {
- QScriptValueList args;
- args << QScriptValue(&eng, 123);
- QScriptValue result = Number.call(Object, args);
- QCOMPARE(result.strictlyEquals(args.at(0)), true);
- }
+ QScriptValueList args;
+ args << QScriptValue(&eng, 123);
+ QScriptValue result = Number.call(Object, args);
+ QCOMPARE(result.strictlyEquals(args.at(0)), true);
+}
+void tst_QScriptValue::call_this()
+{
+ QScriptEngine eng;
// test that correct "this" object is used
- {
- QScriptValue fun = eng.evaluate("(function() { return this; })");
- QCOMPARE(fun.isFunction(), true);
+ QScriptValue fun = eng.evaluate("(function() { return this; })");
+ QCOMPARE(fun.isFunction(), true);
- {
- QScriptValue numberObject = QScriptValue(&eng, 123.0).toObject();
- QScriptValue result = fun.call(numberObject);
- QCOMPARE(result.isObject(), true);
- QCOMPARE(result.toNumber(), 123.0);
- }
- }
+ QScriptValue numberObject = QScriptValue(&eng, 123.0).toObject();
+ QScriptValue result = fun.call(numberObject);
+ QCOMPARE(result.isObject(), true);
+ QCOMPARE(result.toNumber(), 123.0);
+}
+void tst_QScriptValue::call_arguments()
+{
+ QScriptEngine eng;
// test that correct arguments are passed
- {
- QScriptValue fun = eng.evaluate("(function() { return arguments[0]; })");
- QCOMPARE(fun.isFunction(), true);
-
- {
- QScriptValue result = fun.call(eng.undefinedValue());
- QCOMPARE(result.isUndefined(), true);
- }
-
- {
- QScriptValueList args;
- args << QScriptValue(&eng, 123.0);
- QScriptValue result = fun.call(eng.undefinedValue(), args);
- QCOMPARE(result.isNumber(), true);
- QCOMPARE(result.toNumber(), 123.0);
- }
- // V2 constructors
- {
- QScriptValueList args;
- args << QScriptValue(123.0);
- QScriptValue result = fun.call(eng.undefinedValue(), args);
- QCOMPARE(result.isNumber(), true);
- QCOMPARE(result.toNumber(), 123.0);
- }
- {
- QScriptValue args = eng.newArray();
- args.setProperty(0, 123);
- QScriptValue result = fun.call(eng.undefinedValue(), args);
- QVERIFY(result.isNumber());
- QCOMPARE(result.toNumber(), 123.0);
- }
+ QScriptValue fun = eng.evaluate("(function() { return arguments[0]; })");
+ QCOMPARE(fun.isFunction(), true);
+ {
+ QScriptValue result = fun.call(eng.undefinedValue());
+ QCOMPARE(result.isUndefined(), true);
+ }
+ {
+ QScriptValueList args;
+ args << QScriptValue(&eng, 123.0);
+ QScriptValue result = fun.call(eng.undefinedValue(), args);
+ QCOMPARE(result.isNumber(), true);
+ QCOMPARE(result.toNumber(), 123.0);
}
+ // V2 constructors
+ {
+ QScriptValueList args;
+ args << QScriptValue(123.0);
+ QScriptValue result = fun.call(eng.undefinedValue(), args);
+ QCOMPARE(result.isNumber(), true);
+ QCOMPARE(result.toNumber(), 123.0);
+ }
+ {
+ QScriptValue args = eng.newArray();
+ args.setProperty(0, 123);
+ QScriptValue result = fun.call(eng.undefinedValue(), args);
+ QVERIFY(result.isNumber());
+ QCOMPARE(result.toNumber(), 123.0);
+ }
+}
+void tst_QScriptValue::call()
+{
+ QScriptEngine eng;
{
QScriptValue fun = eng.evaluate("(function() { return arguments[1]; })");
QCOMPARE(fun.isFunction(), true);
@@ -2448,7 +2665,6 @@ void tst_QScriptValue::call()
QCOMPARE(result.toNumber(), 456.0);
}
}
-
{
QScriptValue fun = eng.evaluate("(function() { throw new Error('foo'); })");
QCOMPARE(fun.isFunction(), true);
@@ -2461,7 +2677,6 @@ void tst_QScriptValue::call()
QVERIFY(result.strictlyEquals(eng.uncaughtException()));
}
}
-
{
eng.clearExceptions();
QScriptValue fun = eng.newFunction(getArg);
@@ -2489,7 +2704,6 @@ void tst_QScriptValue::call()
QCOMPARE(result.toNumber(), 123.0);
}
}
-
{
QScriptValue fun = eng.newFunction(evaluateArg);
{
@@ -2501,11 +2715,12 @@ void tst_QScriptValue::call()
QCOMPARE(result.toNumber(), 123.0);
}
}
+}
- QScriptValue inv;
- QCOMPARE(inv.call().isValid(), false);
-
+void tst_QScriptValue::call_invalidArguments()
+{
// test that invalid arguments are handled gracefully
+ QScriptEngine eng;
{
QScriptValue fun = eng.newFunction(getArg);
{
@@ -2538,6 +2753,35 @@ void tst_QScriptValue::call()
QCOMPARE(qIsNaN(ret.toNumber()), true);
}
}
+}
+
+void tst_QScriptValue::call_invalidReturn()
+{
+ // test that invalid return value is handled gracefully
+ QScriptEngine eng;
+ QScriptValue fun = eng.newFunction(returnInvalidValue);
+ eng.globalObject().setProperty("returnInvalidValue", fun);
+ QScriptValue ret = eng.evaluate("returnInvalidValue() + returnInvalidValue()");
+ QCOMPARE(ret.isValid(), true);
+ QCOMPARE(ret.isNumber(), true);
+ QCOMPARE(qIsNaN(ret.toNumber()), true);
+}
+
+void tst_QScriptValue::call_twoEngines()
+{
+ QScriptEngine eng;
+ QScriptValue object = eng.evaluate("Object");
+ QScriptEngine otherEngine;
+ QScriptValue fun = otherEngine.evaluate("(function() { return 1; })");
+ QVERIFY(fun.isFunction());
+ QTest::ignoreMessage(QtWarningMsg, "QScriptValue::call() failed: "
+ "cannot call function with thisObject created in "
+ "a different engine");
+ QCOMPARE(fun.call(object).isValid(), false);
+ QTest::ignoreMessage(QtWarningMsg, "QScriptValue::call() failed: "
+ "cannot call function with argument created in "
+ "a different engine");
+ QCOMPARE(fun.call(QScriptValue(), QScriptValueList() << QScriptValue(&eng, 123)).isValid(), false);
{
QScriptValue fun = eng.evaluate("Object");
QVERIFY(fun.isFunction());
@@ -2548,76 +2792,74 @@ void tst_QScriptValue::call()
QTest::ignoreMessage(QtWarningMsg, "QScriptValue::call() failed: cannot call function with argument created in a different engine");
fun.call(QScriptValue(), args);
}
+}
- // test that invalid return value is handled gracefully
- {
- QScriptValue fun = eng.newFunction(returnInvalidValue);
- eng.globalObject().setProperty("returnInvalidValue", fun);
- QScriptValue ret = eng.evaluate("returnInvalidValue() + returnInvalidValue()");
- QCOMPARE(ret.isValid(), true);
- QCOMPARE(ret.isNumber(), true);
- QCOMPARE(qIsNaN(ret.toNumber()), true);
- }
+void tst_QScriptValue::call_array()
+{
+ QScriptEngine eng;
+ QScriptValue fun = eng.evaluate("(function() { return arguments; })");
+ QVERIFY(fun.isFunction());
+ QScriptValue array = eng.newArray(3);
+ array.setProperty(0, QScriptValue(&eng, 123.0));
+ array.setProperty(1, QScriptValue(&eng, 456.0));
+ array.setProperty(2, QScriptValue(&eng, 789.0));
+ // call with single array object as arguments
+ QScriptValue ret = fun.call(QScriptValue(), array);
+ QVERIFY(!eng.hasUncaughtException());
+ QCOMPARE(ret.isError(), false);
+ QCOMPARE(ret.property(0).strictlyEquals(array.property(0)), true);
+ QCOMPARE(ret.property(1).strictlyEquals(array.property(1)), true);
+ QCOMPARE(ret.property(2).strictlyEquals(array.property(2)), true);
+ // call with arguments object as arguments
+ QScriptValue ret2 = fun.call(QScriptValue(), ret);
+ QCOMPARE(ret2.isError(), false);
+ QCOMPARE(ret2.property(0).strictlyEquals(ret.property(0)), true);
+ QCOMPARE(ret2.property(1).strictlyEquals(ret.property(1)), true);
+ QCOMPARE(ret2.property(2).strictlyEquals(ret.property(2)), true);
+ // call with null as arguments
+ QScriptValue ret3 = fun.call(QScriptValue(), eng.nullValue());
+ QCOMPARE(ret3.isError(), false);
+ QCOMPARE(ret3.property("length").isNumber(), true);
+ QCOMPARE(ret3.property("length").toNumber(), 0.0);
+ // call with undefined as arguments
+ QScriptValue ret4 = fun.call(QScriptValue(), eng.undefinedValue());
+ QCOMPARE(ret4.isError(), false);
+ QCOMPARE(ret4.property("length").isNumber(), true);
+ QCOMPARE(ret4.property("length").toNumber(), 0.0);
+ // call with something else as arguments
+ QScriptValue ret5 = fun.call(QScriptValue(), QScriptValue(&eng, 123.0));
+ QCOMPARE(ret5.isError(), true);
+ // call with a non-array object as arguments
+ QScriptValue ret6 = fun.call(QScriptValue(), eng.globalObject());
+ QVERIFY(ret6.isError());
+ QCOMPARE(ret6.toString(), QString::fromLatin1("TypeError: Arguments must be an array"));
+}
- {
- QScriptEngine otherEngine;
- QScriptValue fun = otherEngine.evaluate("(function() { return 1; })");
- QVERIFY(fun.isFunction());
- QTest::ignoreMessage(QtWarningMsg, "QScriptValue::call() failed: "
- "cannot call function with thisObject created in "
- "a different engine");
- QCOMPARE(fun.call(Object).isValid(), false);
- QTest::ignoreMessage(QtWarningMsg, "QScriptValue::call() failed: "
- "cannot call function with argument created in "
- "a different engine");
- QCOMPARE(fun.call(QScriptValue(), QScriptValueList() << QScriptValue(&eng, 123)).isValid(), false);
- }
- {
- QScriptValue fun = eng.evaluate("(function() { return arguments; })");
- QVERIFY(fun.isFunction());
- QScriptValue array = eng.newArray(3);
- array.setProperty(0, QScriptValue(&eng, 123.0));
- array.setProperty(1, QScriptValue(&eng, 456.0));
- array.setProperty(2, QScriptValue(&eng, 789.0));
- // call with single array object as arguments
- QScriptValue ret = fun.call(QScriptValue(), array);
- QVERIFY(!eng.hasUncaughtException());
- QCOMPARE(ret.isError(), false);
- QCOMPARE(ret.property(0).strictlyEquals(array.property(0)), true);
- QCOMPARE(ret.property(1).strictlyEquals(array.property(1)), true);
- QCOMPARE(ret.property(2).strictlyEquals(array.property(2)), true);
- // call with arguments object as arguments
- QScriptValue ret2 = fun.call(QScriptValue(), ret);
- QCOMPARE(ret2.isError(), false);
- QCOMPARE(ret2.property(0).strictlyEquals(ret.property(0)), true);
- QCOMPARE(ret2.property(1).strictlyEquals(ret.property(1)), true);
- QCOMPARE(ret2.property(2).strictlyEquals(ret.property(2)), true);
- // call with null as arguments
- QScriptValue ret3 = fun.call(QScriptValue(), eng.nullValue());
- QCOMPARE(ret3.isError(), false);
- QCOMPARE(ret3.property("length").isNumber(), true);
- QCOMPARE(ret3.property("length").toNumber(), 0.0);
- // call with undefined as arguments
- QScriptValue ret4 = fun.call(QScriptValue(), eng.undefinedValue());
- QCOMPARE(ret4.isError(), false);
- QCOMPARE(ret4.property("length").isNumber(), true);
- QCOMPARE(ret4.property("length").toNumber(), 0.0);
- // call with something else as arguments
- QScriptValue ret5 = fun.call(QScriptValue(), QScriptValue(&eng, 123.0));
- QCOMPARE(ret5.isError(), true);
- // call with a non-array object as arguments
- QScriptValue ret6 = fun.call(QScriptValue(), eng.globalObject());
- QVERIFY(ret6.isError());
- QCOMPARE(ret6.toString(), QString::fromLatin1("TypeError: Arguments must be an array"));
- }
+void tst_QScriptValue::call_nonFunction_data()
+{
+ newEngine();
+ QTest::addColumn<QScriptValue>("value");
+
+ QTest::newRow("invalid") << QScriptValue();
+ QTest::newRow("bool") << QScriptValue(false);
+ QTest::newRow("int") << QScriptValue(123);
+ QTest::newRow("string") << QScriptValue(QString::fromLatin1("ciao"));
+ QTest::newRow("undefined") << QScriptValue(QScriptValue::UndefinedValue);
+ QTest::newRow("null") << QScriptValue(QScriptValue::NullValue);
+
+ QTest::newRow("bool bound") << QScriptValue(engine, false);
+ QTest::newRow("int bound") << QScriptValue(engine, 123);
+ QTest::newRow("string bound") << QScriptValue(engine, QString::fromLatin1("ciao"));
+ QTest::newRow("undefined bound") << engine->undefinedValue();
+ QTest::newRow("null bound") << engine->nullValue();
+}
+void tst_QScriptValue::call_nonFunction()
+{
// calling things that are not functions
- QVERIFY(!QScriptValue(false).call().isValid());
- QVERIFY(!QScriptValue(123).call().isValid());
- QVERIFY(!QScriptValue(QString::fromLatin1("ciao")).call().isValid());
- QVERIFY(!QScriptValue(QScriptValue::UndefinedValue).call().isValid());
- QVERIFY(!QScriptValue(QScriptValue::NullValue).call().isValid());
+ QFETCH(QScriptValue, value);
+ QVERIFY(!value.call().isValid());
}
static QScriptValue ctorReturningUndefined(QScriptContext *ctx, QScriptEngine *)
@@ -2781,7 +3023,7 @@ void tst_QScriptValue::construct_constructorThrowsPrimitive()
}
}
-void tst_QScriptValue::lessThan_old()
+void tst_QScriptValue::lessThan()
{
QScriptEngine eng;
@@ -2875,7 +3117,7 @@ void tst_QScriptValue::lessThan_old()
QCOMPARE(date1.lessThan(QScriptValue(&otherEngine, 123)), false);
}
-void tst_QScriptValue::equals_old()
+void tst_QScriptValue::equals()
{
QScriptEngine eng;
@@ -3068,7 +3310,7 @@ void tst_QScriptValue::equals_old()
QCOMPARE(date1.equals(QScriptValue(&otherEngine, 123)), false);
}
-void tst_QScriptValue::strictlyEquals_old()
+void tst_QScriptValue::strictlyEquals()
{
QScriptEngine eng;
diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.h b/tests/auto/qscriptvalue/tst_qscriptvalue.h
index 462749a..45a109e 100644
--- a/tests/auto/qscriptvalue/tst_qscriptvalue.h
+++ b/tests/auto/qscriptvalue/tst_qscriptvalue.h
@@ -49,8 +49,6 @@
#include <QtScript/qscriptvalue.h>
#include <QtTest/QtTest>
-#define DEFINE_TEST_VALUE(expr) m_values.insert(QString::fromLatin1(#expr), expr)
-
Q_DECLARE_METATYPE(QVariant)
Q_DECLARE_METATYPE(QScriptValue)
@@ -63,161 +61,97 @@ public:
virtual ~tst_QScriptValue();
private slots:
- // Generated test functions
- void isArray_data();
- void isArray();
-
- void isBool_data();
- void isBool();
+ void toObject();
- void isBoolean_data();
- void isBoolean();
+ void ctor_invalid();
+ void ctor_undefinedWithEngine();
+ void ctor_undefined();
+ void ctor_nullWithEngine();
+ void ctor_null();
+ void ctor_boolWithEngine();
+ void ctor_bool();
+ void ctor_intWithEngine();
+ void ctor_int();
+ void ctor_uintWithEngine();
+ void ctor_uint();
+ void ctor_floatWithEngine();
+ void ctor_float();
+ void ctor_stringWithEngine();
+ void ctor_string();
+ void ctor_copyAndAssignWithEngine();
+ void ctor_copyAndAssign();
+ void ctor_nullEngine();
- void isDate_data();
+ void toString();
+ void toNumber();
+ void toBoolean();
+ void toBool();
+ void toInteger();
+ void toInt32();
+ void toUInt32();
+ void toUInt16();
+ void toVariant();
+ void toQObject();
+ void toDateTime();
+ void toRegExp();
+ void instanceOf_twoEngines();
+ void instanceOf();
+ void isArray_data();
+ void isArray();
void isDate();
-
+ void isDate_data();
+ void isError_propertiesOfGlobalObject();
void isError_data();
void isError();
-
- void isFunction_data();
- void isFunction();
-
- void isNull_data();
- void isNull();
-
- void isNumber_data();
- void isNumber();
-
- void isObject_data();
- void isObject();
-
- void isQMetaObject_data();
- void isQMetaObject();
-
- void isQObject_data();
- void isQObject();
-
void isRegExp_data();
void isRegExp();
- void isString_data();
- void isString();
-
- void isUndefined_data();
- void isUndefined();
-
- void isValid_data();
- void isValid();
-
- void isVariant_data();
- void isVariant();
-
- void toBool_data();
- void toBool();
-
- void toBoolean_data();
- void toBoolean();
-
-// void toDateTime_data();
-// void toDateTime();
-
- void toInt32_data();
- void toInt32();
-
- void toInteger_data();
- void toInteger();
-
- void toNumber_data();
- void toNumber();
-
-// void toQMetaObject_data();
-// void toQMetaObject();
-
-// void toQObject_data();
-// void toQObject();
-
-// void toRegExp_data();
-// void toRegExp();
-
- void toString_data();
- void toString();
-
- void toUInt16_data();
- void toUInt16();
-
- void toUInt32_data();
- void toUInt32();
-
-// void toVariant_data();
-// void toVariant();
-
- void equals_data();
+ void lessThan();
void equals();
-
- void strictlyEquals_data();
void strictlyEquals();
- void lessThan_data();
- void lessThan();
-
- void instanceOf_data();
- void instanceOf();
-
- void assignAndCopyConstruct_data();
- void assignAndCopyConstruct();
-
- void qscriptvalue_castQString_data();
- void qscriptvalue_castQString();
-
- void qscriptvalue_castqsreal_data();
- void qscriptvalue_castqsreal();
-
- void qscriptvalue_castbool_data();
- void qscriptvalue_castbool();
-
- void qscriptvalue_castqint32_data();
- void qscriptvalue_castqint32();
-
- void qscriptvalue_castquint32_data();
- void qscriptvalue_castquint32();
-
- void qscriptvalue_castquint16_data();
- void qscriptvalue_castquint16();
-
- // Non-generated test functions
-
- void toObject();
- void ctor();
-
- void toString_old();
- void toNumber_old();
- void toBoolean_old();
- void toBool_old();
- void toInteger_old();
- void toInt32_old();
- void toUInt32_old();
- void toUInt16_old();
- void toVariant_old();
- void toQObject_old();
- void toDateTime_old();
- void toRegExp_old();
- void instanceOf_old();
- void isArray_old();
- void isDate_old();
- void isError_old();
- void isRegExp_old();
-
- void lessThan_old();
- void equals_old();
- void strictlyEquals_old();
-
+ void getSetPrototype_cyclicPrototype();
+ void getSetPrototype_evalCyclicPrototype();
+ void getSetPrototype_eval();
+ void getSetPrototype_invalidPrototype();
+ void getSetPrototype_twoEngines();
void getSetPrototype();
void getSetScope();
+ void getSetProperty_HooliganTask162051();
+ void getSetProperty_HooliganTask183072();
+ void getSetProperty_propertyRemoval();
+ void getSetProperty_resolveMode();
+ void getSetProperty_twoEngines();
+ void getSetProperty_gettersAndSetters();
+ void getSetProperty_gettersAndSettersThrowError();
+ void getSetProperty_gettersAndSettersOnNative();
+ void getSetProperty_gettersAndSettersOnGlobalObject();
+ void getSetProperty_gettersAndSettersChange();
+ void getSetProperty_array();
void getSetProperty();
void arrayElementGetterSetter();
- void getSetData();
- void getSetScriptClass();
+ void getSetData_objects_data();
+ void getSetData_objects();
+ void getSetData_nonObjects_data();
+ void getSetData_nonObjects();
+ void getSetScriptClass_emptyClass_data();
+ void getSetScriptClass_emptyClass();
+ void getSetScriptClass_JSObjectFromCpp();
+ void getSetScriptClass_JSObjectFromJS();
+ void getSetScriptClass_QVariant();
+ void getSetScriptClass_QObject();
+ void call_function();
+ void call_object();
+ void call_newObjects();
+ void call_this();
+ void call_arguments();
void call();
+ void call_invalidArguments();
+ void call_invalidReturn();
+ void call_twoEngines();
+ void call_array();
+ void call_nonFunction_data();
+ void call_nonFunction();
void construct();
void construct_constructorThrowsPrimitive();
void castToPointer();
@@ -230,186 +164,13 @@ private slots:
void nestedObjectToVariant();
private:
- typedef void (tst_QScriptValue::*InitDataFunction)();
- typedef void (tst_QScriptValue::*DefineDataFunction)(const char *);
- void dataHelper(InitDataFunction init, DefineDataFunction define);
- QTestData &newRow(const char *tag);
-
- typedef void (tst_QScriptValue::*TestFunction)(const char *, const QScriptValue &);
- void testHelper(TestFunction fun);
-
- // Generated functions
-
- void initScriptValues();
-
- void isArray_initData();
- void isArray_makeData(const char *expr);
- void isArray_test(const char *expr, const QScriptValue &value);
-
- void isBool_initData();
- void isBool_makeData(const char *expr);
- void isBool_test(const char *expr, const QScriptValue &value);
-
- void isBoolean_initData();
- void isBoolean_makeData(const char *expr);
- void isBoolean_test(const char *expr, const QScriptValue &value);
-
- void isDate_initData();
- void isDate_makeData(const char *expr);
- void isDate_test(const char *expr, const QScriptValue &value);
-
- void isError_initData();
- void isError_makeData(const char *expr);
- void isError_test(const char *expr, const QScriptValue &value);
-
- void isFunction_initData();
- void isFunction_makeData(const char *expr);
- void isFunction_test(const char *expr, const QScriptValue &value);
-
- void isNull_initData();
- void isNull_makeData(const char *expr);
- void isNull_test(const char *expr, const QScriptValue &value);
-
- void isNumber_initData();
- void isNumber_makeData(const char *expr);
- void isNumber_test(const char *expr, const QScriptValue &value);
-
- void isObject_initData();
- void isObject_makeData(const char *expr);
- void isObject_test(const char *expr, const QScriptValue &value);
-
- void isQMetaObject_initData();
- void isQMetaObject_makeData(const char *expr);
- void isQMetaObject_test(const char *expr, const QScriptValue &value);
-
- void isQObject_initData();
- void isQObject_makeData(const char *expr);
- void isQObject_test(const char *expr, const QScriptValue &value);
-
- void isRegExp_initData();
- void isRegExp_makeData(const char *expr);
- void isRegExp_test(const char *expr, const QScriptValue &value);
-
- void isString_initData();
- void isString_makeData(const char *expr);
- void isString_test(const char *expr, const QScriptValue &value);
-
- void isUndefined_initData();
- void isUndefined_makeData(const char *expr);
- void isUndefined_test(const char *expr, const QScriptValue &value);
-
- void isValid_initData();
- void isValid_makeData(const char *expr);
- void isValid_test(const char *expr, const QScriptValue &value);
-
- void isVariant_initData();
- void isVariant_makeData(const char *expr);
- void isVariant_test(const char *expr, const QScriptValue &value);
-
- void toBool_initData();
- void toBool_makeData(const char *);
- void toBool_test(const char *, const QScriptValue &value);
-
- void toBoolean_initData();
- void toBoolean_makeData(const char *);
- void toBoolean_test(const char *, const QScriptValue &value);
-
- void toDateTime_initData();
- void toDateTime_makeData(const char *);
- void toDateTime_test(const char *, const QScriptValue &value);
-
- void toInt32_initData();
- void toInt32_makeData(const char *);
- void toInt32_test(const char *, const QScriptValue &value);
-
- void toInteger_initData();
- void toInteger_makeData(const char *);
- void toInteger_test(const char *, const QScriptValue &value);
-
- void toNumber_initData();
- void toNumber_makeData(const char *);
- void toNumber_test(const char *, const QScriptValue &value);
-
- void toQMetaObject_initData();
- void toQMetaObject_makeData(const char *);
- void toQMetaObject_test(const char *, const QScriptValue &value);
-
- void toQObject_initData();
- void toQObject_makeData(const char *);
- void toQObject_test(const char *, const QScriptValue &value);
-
- void toRegExp_initData();
- void toRegExp_makeData(const char *);
- void toRegExp_test(const char *, const QScriptValue &value);
-
- void toString_initData();
- void toString_makeData(const char *);
- void toString_test(const char *, const QScriptValue &value);
-
- void toUInt16_initData();
- void toUInt16_makeData(const char *);
- void toUInt16_test(const char *, const QScriptValue &value);
-
- void toUInt32_initData();
- void toUInt32_makeData(const char *);
- void toUInt32_test(const char *, const QScriptValue &value);
-
- void toVariant_initData();
- void toVariant_makeData(const char *);
- void toVariant_test(const char *, const QScriptValue &value);
-
- void equals_initData();
- void equals_makeData(const char *);
- void equals_test(const char *, const QScriptValue &value);
-
- void strictlyEquals_initData();
- void strictlyEquals_makeData(const char *);
- void strictlyEquals_test(const char *, const QScriptValue &value);
-
- void lessThan_initData();
- void lessThan_makeData(const char *);
- void lessThan_test(const char *, const QScriptValue &value);
-
- void instanceOf_initData();
- void instanceOf_makeData(const char *);
- void instanceOf_test(const char *, const QScriptValue &value);
-
- void assignAndCopyConstruct_initData();
- void assignAndCopyConstruct_makeData(const char *);
- void assignAndCopyConstruct_test(const char *, const QScriptValue &value);
-
- void qscriptvalue_castQString_initData();
- void qscriptvalue_castQString_makeData(const char *);
- void qscriptvalue_castQString_test(const char *, const QScriptValue &value);
-
- void qscriptvalue_castqsreal_initData();
- void qscriptvalue_castqsreal_makeData(const char *);
- void qscriptvalue_castqsreal_test(const char *, const QScriptValue &value);
-
- void qscriptvalue_castbool_initData();
- void qscriptvalue_castbool_makeData(const char *);
- void qscriptvalue_castbool_test(const char *, const QScriptValue &value);
-
- void qscriptvalue_castqint32_initData();
- void qscriptvalue_castqint32_makeData(const char *);
- void qscriptvalue_castqint32_test(const char *, const QScriptValue &value);
-
- void qscriptvalue_castquint32_initData();
- void qscriptvalue_castquint32_makeData(const char *);
- void qscriptvalue_castquint32_test(const char *, const QScriptValue &value);
-
- void qscriptvalue_castquint16_initData();
- void qscriptvalue_castquint16_makeData(const char *);
- void qscriptvalue_castquint16_test(const char *, const QScriptValue &value);
-
-private:
+ void newEngine()
+ {
+ if (engine)
+ delete engine;
+ engine = new QScriptEngine();
+ }
QScriptEngine *engine;
- QHash<QString, QScriptValue> m_values;
- QString m_currentExpression;
};
-#define DEFINE_TEST_FUNCTION(name) \
-void tst_QScriptValue::name##_data() { dataHelper(&tst_QScriptValue::name##_initData, &tst_QScriptValue::name##_makeData); } \
-void tst_QScriptValue::name() { testHelper(&tst_QScriptValue::name##_test); }
-
#endif
diff --git a/tests/auto/qscriptvaluegenerated/.gitignore b/tests/auto/qscriptvaluegenerated/.gitignore
new file mode 100644
index 0000000..f724cb9
--- /dev/null
+++ b/tests/auto/qscriptvaluegenerated/.gitignore
@@ -0,0 +1 @@
+tst_qscriptvalue
diff --git a/tests/auto/qscriptvaluegenerated/qscriptvaluegenerated.pro b/tests/auto/qscriptvaluegenerated/qscriptvaluegenerated.pro
new file mode 100644
index 0000000..c3e9912
--- /dev/null
+++ b/tests/auto/qscriptvaluegenerated/qscriptvaluegenerated.pro
@@ -0,0 +1,18 @@
+load(qttest_p4)
+QT = core gui script
+SOURCES += tst_qscriptvalue.cpp
+HEADERS += tst_qscriptvalue.h
+
+# Generated by testgen
+SOURCES += \
+ tst_qscriptvalue_generated_init.cpp \
+ tst_qscriptvalue_generated_cast.cpp \
+ tst_qscriptvalue_generated_comparison.cpp \
+ tst_qscriptvalue_generated_isXXX.cpp \
+ tst_qscriptvalue_generated_toXXX.cpp
+
+win32-msvc* {
+ # With -O2, MSVC takes up to 24 minutes to compile this test!
+ QMAKE_CXXFLAGS_RELEASE -= -O1 -O2
+ QMAKE_CXXFLAGS_RELEASE += -Od
+}
diff --git a/tests/auto/qscriptvalue/testgen/data.txt b/tests/auto/qscriptvaluegenerated/testgen/data.txt
index 73677ec..73677ec 100644
--- a/tests/auto/qscriptvalue/testgen/data.txt
+++ b/tests/auto/qscriptvaluegenerated/testgen/data.txt
diff --git a/tests/auto/qscriptvalue/testgen/gen.py b/tests/auto/qscriptvaluegenerated/testgen/gen.py
index 6e48f46..6e48f46 100755
--- a/tests/auto/qscriptvalue/testgen/gen.py
+++ b/tests/auto/qscriptvaluegenerated/testgen/gen.py
diff --git a/tests/auto/qscriptvalue/testgen/main.cpp b/tests/auto/qscriptvaluegenerated/testgen/main.cpp
index 0672635..0672635 100644
--- a/tests/auto/qscriptvalue/testgen/main.cpp
+++ b/tests/auto/qscriptvaluegenerated/testgen/main.cpp
diff --git a/tests/auto/qscriptvalue/testgen/testgen.pro b/tests/auto/qscriptvaluegenerated/testgen/testgen.pro
index 47709a8..47709a8 100644
--- a/tests/auto/qscriptvalue/testgen/testgen.pro
+++ b/tests/auto/qscriptvaluegenerated/testgen/testgen.pro
diff --git a/tests/auto/qscriptvalue/testgen/testgenerator.cpp b/tests/auto/qscriptvaluegenerated/testgen/testgenerator.cpp
index 9d7d33d..9d7d33d 100644
--- a/tests/auto/qscriptvalue/testgen/testgenerator.cpp
+++ b/tests/auto/qscriptvaluegenerated/testgen/testgenerator.cpp
diff --git a/tests/auto/qscriptvalue/testgen/testgenerator.h b/tests/auto/qscriptvaluegenerated/testgen/testgenerator.h
index 1c61fc5..1c61fc5 100644
--- a/tests/auto/qscriptvalue/testgen/testgenerator.h
+++ b/tests/auto/qscriptvaluegenerated/testgen/testgenerator.h
diff --git a/tests/auto/qscriptvaluegenerated/tst_qscriptvalue.cpp b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue.cpp
new file mode 100644
index 0000000..962a2af
--- /dev/null
+++ b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue.cpp
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "tst_qscriptvalue.h"
+#include <QtGui/QPushButton>
+
+//TESTED_CLASS=
+//TESTED_FILES=
+
+QT_BEGIN_NAMESPACE
+extern bool qt_script_isJITEnabled();
+QT_END_NAMESPACE
+
+tst_QScriptValueGenerated::tst_QScriptValueGenerated()
+ : engine(0)
+{
+}
+
+tst_QScriptValueGenerated::~tst_QScriptValueGenerated()
+{
+ delete engine;
+}
+
+void tst_QScriptValueGenerated::dataHelper(InitDataFunction init, DefineDataFunction define)
+{
+ QTest::addColumn<QString>("__expression__");
+ (this->*init)();
+ QHash<QString,QScriptValue>::const_iterator it;
+ for (it = m_values.constBegin(); it != m_values.constEnd(); ++it) {
+ m_currentExpression = it.key();
+ (this->*define)(it.key().toLatin1());
+ }
+ m_currentExpression = QString();
+}
+
+QTestData &tst_QScriptValueGenerated::newRow(const char *tag)
+{
+ return QTest::newRow(tag) << m_currentExpression;
+}
+
+void tst_QScriptValueGenerated::testHelper(TestFunction fun)
+{
+ QFETCH(QString, __expression__);
+ QScriptValue value = m_values.value(__expression__);
+ (this->*fun)(__expression__.toLatin1(), value);
+}
+
+void tst_QScriptValueGenerated::assignAndCopyConstruct_initData()
+{
+ QTest::addColumn<int>("dummy");
+ initScriptValues();
+}
+
+void tst_QScriptValueGenerated::assignAndCopyConstruct_makeData(const char *expr)
+{
+ newRow(expr) << 0;
+}
+
+void tst_QScriptValueGenerated::assignAndCopyConstruct_test(const char *, const QScriptValue &value)
+{
+ QScriptValue copy(value);
+ QCOMPARE(copy.strictlyEquals(value), !value.isNumber() || !qIsNaN(value.toNumber()));
+ QCOMPARE(copy.engine(), value.engine());
+
+ QScriptValue assigned = copy;
+ QCOMPARE(assigned.strictlyEquals(value), !copy.isNumber() || !qIsNaN(copy.toNumber()));
+ QCOMPARE(assigned.engine(), assigned.engine());
+
+ QScriptValue other(!value.toBool());
+ assigned = other;
+ QVERIFY(!assigned.strictlyEquals(copy));
+ QVERIFY(assigned.strictlyEquals(other));
+ QCOMPARE(assigned.engine(), other.engine());
+}
+
+DEFINE_TEST_FUNCTION(assignAndCopyConstruct)
+
+QTEST_MAIN(tst_QScriptValueGenerated)
diff --git a/tests/auto/qscriptvaluegenerated/tst_qscriptvalue.h b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue.h
new file mode 100644
index 0000000..8248ef3
--- /dev/null
+++ b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue.h
@@ -0,0 +1,370 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TST_QSCRIPTVALUE_H
+#define TST_QSCRIPTVALUE_H
+
+#include <QtCore/qobject.h>
+#include <QtCore/qnumeric.h>
+#include <QtScript/qscriptclass.h>
+#include <QtScript/qscriptengine.h>
+#include <QtScript/qscriptvalue.h>
+#include <QtTest/QtTest>
+
+#define DEFINE_TEST_VALUE(expr) m_values.insert(QString::fromLatin1(#expr), expr)
+
+Q_DECLARE_METATYPE(QVariant)
+Q_DECLARE_METATYPE(QScriptValue)
+
+class tst_QScriptValueGenerated : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QScriptValueGenerated();
+ virtual ~tst_QScriptValueGenerated();
+
+private slots:
+ // Generated test functions
+ void isArray_data();
+ void isArray();
+
+ void isBool_data();
+ void isBool();
+
+ void isBoolean_data();
+ void isBoolean();
+
+ void isDate_data();
+ void isDate();
+
+ void isError_data();
+ void isError();
+
+ void isFunction_data();
+ void isFunction();
+
+ void isNull_data();
+ void isNull();
+
+ void isNumber_data();
+ void isNumber();
+
+ void isObject_data();
+ void isObject();
+
+ void isQMetaObject_data();
+ void isQMetaObject();
+
+ void isQObject_data();
+ void isQObject();
+
+ void isRegExp_data();
+ void isRegExp();
+
+ void isString_data();
+ void isString();
+
+ void isUndefined_data();
+ void isUndefined();
+
+ void isValid_data();
+ void isValid();
+
+ void isVariant_data();
+ void isVariant();
+
+ void toBool_data();
+ void toBool();
+
+ void toBoolean_data();
+ void toBoolean();
+
+// void toDateTime_data();
+// void toDateTime();
+
+ void toInt32_data();
+ void toInt32();
+
+ void toInteger_data();
+ void toInteger();
+
+ void toNumber_data();
+ void toNumber();
+
+// void toQMetaObject_data();
+// void toQMetaObject();
+
+// void toQObject_data();
+// void toQObject();
+
+// void toRegExp_data();
+// void toRegExp();
+
+ void toString_data();
+ void toString();
+
+ void toUInt16_data();
+ void toUInt16();
+
+ void toUInt32_data();
+ void toUInt32();
+
+// void toVariant_data();
+// void toVariant();
+
+ void equals_data();
+ void equals();
+
+ void strictlyEquals_data();
+ void strictlyEquals();
+
+ void lessThan_data();
+ void lessThan();
+
+ void instanceOf_data();
+ void instanceOf();
+
+ void assignAndCopyConstruct_data();
+ void assignAndCopyConstruct();
+
+ void qscriptvalue_castQString_data();
+ void qscriptvalue_castQString();
+
+ void qscriptvalue_castqsreal_data();
+ void qscriptvalue_castqsreal();
+
+ void qscriptvalue_castbool_data();
+ void qscriptvalue_castbool();
+
+ void qscriptvalue_castqint32_data();
+ void qscriptvalue_castqint32();
+
+ void qscriptvalue_castquint32_data();
+ void qscriptvalue_castquint32();
+
+ void qscriptvalue_castquint16_data();
+ void qscriptvalue_castquint16();
+
+private:
+ typedef void (tst_QScriptValueGenerated::*InitDataFunction)();
+ typedef void (tst_QScriptValueGenerated::*DefineDataFunction)(const char *);
+ void dataHelper(InitDataFunction init, DefineDataFunction define);
+ QTestData &newRow(const char *tag);
+
+ typedef void (tst_QScriptValueGenerated::*TestFunction)(const char *, const QScriptValue &);
+ void testHelper(TestFunction fun);
+
+ // Generated functions
+
+ void initScriptValues();
+
+ void isArray_initData();
+ void isArray_makeData(const char *expr);
+ void isArray_test(const char *expr, const QScriptValue &value);
+
+ void isBool_initData();
+ void isBool_makeData(const char *expr);
+ void isBool_test(const char *expr, const QScriptValue &value);
+
+ void isBoolean_initData();
+ void isBoolean_makeData(const char *expr);
+ void isBoolean_test(const char *expr, const QScriptValue &value);
+
+ void isDate_initData();
+ void isDate_makeData(const char *expr);
+ void isDate_test(const char *expr, const QScriptValue &value);
+
+ void isError_initData();
+ void isError_makeData(const char *expr);
+ void isError_test(const char *expr, const QScriptValue &value);
+
+ void isFunction_initData();
+ void isFunction_makeData(const char *expr);
+ void isFunction_test(const char *expr, const QScriptValue &value);
+
+ void isNull_initData();
+ void isNull_makeData(const char *expr);
+ void isNull_test(const char *expr, const QScriptValue &value);
+
+ void isNumber_initData();
+ void isNumber_makeData(const char *expr);
+ void isNumber_test(const char *expr, const QScriptValue &value);
+
+ void isObject_initData();
+ void isObject_makeData(const char *expr);
+ void isObject_test(const char *expr, const QScriptValue &value);
+
+ void isQMetaObject_initData();
+ void isQMetaObject_makeData(const char *expr);
+ void isQMetaObject_test(const char *expr, const QScriptValue &value);
+
+ void isQObject_initData();
+ void isQObject_makeData(const char *expr);
+ void isQObject_test(const char *expr, const QScriptValue &value);
+
+ void isRegExp_initData();
+ void isRegExp_makeData(const char *expr);
+ void isRegExp_test(const char *expr, const QScriptValue &value);
+
+ void isString_initData();
+ void isString_makeData(const char *expr);
+ void isString_test(const char *expr, const QScriptValue &value);
+
+ void isUndefined_initData();
+ void isUndefined_makeData(const char *expr);
+ void isUndefined_test(const char *expr, const QScriptValue &value);
+
+ void isValid_initData();
+ void isValid_makeData(const char *expr);
+ void isValid_test(const char *expr, const QScriptValue &value);
+
+ void isVariant_initData();
+ void isVariant_makeData(const char *expr);
+ void isVariant_test(const char *expr, const QScriptValue &value);
+
+ void toBool_initData();
+ void toBool_makeData(const char *);
+ void toBool_test(const char *, const QScriptValue &value);
+
+ void toBoolean_initData();
+ void toBoolean_makeData(const char *);
+ void toBoolean_test(const char *, const QScriptValue &value);
+
+ void toDateTime_initData();
+ void toDateTime_makeData(const char *);
+ void toDateTime_test(const char *, const QScriptValue &value);
+
+ void toInt32_initData();
+ void toInt32_makeData(const char *);
+ void toInt32_test(const char *, const QScriptValue &value);
+
+ void toInteger_initData();
+ void toInteger_makeData(const char *);
+ void toInteger_test(const char *, const QScriptValue &value);
+
+ void toNumber_initData();
+ void toNumber_makeData(const char *);
+ void toNumber_test(const char *, const QScriptValue &value);
+
+ void toQMetaObject_initData();
+ void toQMetaObject_makeData(const char *);
+ void toQMetaObject_test(const char *, const QScriptValue &value);
+
+ void toQObject_initData();
+ void toQObject_makeData(const char *);
+ void toQObject_test(const char *, const QScriptValue &value);
+
+ void toRegExp_initData();
+ void toRegExp_makeData(const char *);
+ void toRegExp_test(const char *, const QScriptValue &value);
+
+ void toString_initData();
+ void toString_makeData(const char *);
+ void toString_test(const char *, const QScriptValue &value);
+
+ void toUInt16_initData();
+ void toUInt16_makeData(const char *);
+ void toUInt16_test(const char *, const QScriptValue &value);
+
+ void toUInt32_initData();
+ void toUInt32_makeData(const char *);
+ void toUInt32_test(const char *, const QScriptValue &value);
+
+ void toVariant_initData();
+ void toVariant_makeData(const char *);
+ void toVariant_test(const char *, const QScriptValue &value);
+
+ void equals_initData();
+ void equals_makeData(const char *);
+ void equals_test(const char *, const QScriptValue &value);
+
+ void strictlyEquals_initData();
+ void strictlyEquals_makeData(const char *);
+ void strictlyEquals_test(const char *, const QScriptValue &value);
+
+ void lessThan_initData();
+ void lessThan_makeData(const char *);
+ void lessThan_test(const char *, const QScriptValue &value);
+
+ void instanceOf_initData();
+ void instanceOf_makeData(const char *);
+ void instanceOf_test(const char *, const QScriptValue &value);
+
+ void assignAndCopyConstruct_initData();
+ void assignAndCopyConstruct_makeData(const char *);
+ void assignAndCopyConstruct_test(const char *, const QScriptValue &value);
+
+ void qscriptvalue_castQString_initData();
+ void qscriptvalue_castQString_makeData(const char *);
+ void qscriptvalue_castQString_test(const char *, const QScriptValue &value);
+
+ void qscriptvalue_castqsreal_initData();
+ void qscriptvalue_castqsreal_makeData(const char *);
+ void qscriptvalue_castqsreal_test(const char *, const QScriptValue &value);
+
+ void qscriptvalue_castbool_initData();
+ void qscriptvalue_castbool_makeData(const char *);
+ void qscriptvalue_castbool_test(const char *, const QScriptValue &value);
+
+ void qscriptvalue_castqint32_initData();
+ void qscriptvalue_castqint32_makeData(const char *);
+ void qscriptvalue_castqint32_test(const char *, const QScriptValue &value);
+
+ void qscriptvalue_castquint32_initData();
+ void qscriptvalue_castquint32_makeData(const char *);
+ void qscriptvalue_castquint32_test(const char *, const QScriptValue &value);
+
+ void qscriptvalue_castquint16_initData();
+ void qscriptvalue_castquint16_makeData(const char *);
+ void qscriptvalue_castquint16_test(const char *, const QScriptValue &value);
+
+private:
+ QScriptEngine *engine;
+ QHash<QString, QScriptValue> m_values;
+ QString m_currentExpression;
+};
+
+#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); }
+
+#endif
diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue_generated_cast.cpp b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_cast.cpp
index e651810..90bc104 100644
--- a/tests/auto/qscriptvalue/tst_qscriptvalue_generated_cast.cpp
+++ b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_cast.cpp
@@ -47,7 +47,7 @@
-void tst_QScriptValue::qscriptvalue_castQString_initData()
+void tst_QScriptValueGenerated::qscriptvalue_castQString_initData()
{
QTest::addColumn<QString>("expected");
initScriptValues();
@@ -268,7 +268,7 @@ static QString qscriptvalue_castQString_valueArray [] = {
"[object QMetaObject]", "undefined",
"123", "false",
"", "QScriptEngine(name = \"\")", };
-void tst_QScriptValue::qscriptvalue_castQString_makeData(const char* expr)
+void tst_QScriptValueGenerated::qscriptvalue_castQString_makeData(const char* expr)
{
static QHash<QString, QString> value;
if (value.isEmpty()) {
@@ -279,7 +279,7 @@ void tst_QScriptValue::qscriptvalue_castQString_makeData(const char* expr)
newRow(expr) << value.value(expr);
}
-void tst_QScriptValue::qscriptvalue_castQString_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::qscriptvalue_castQString_test(const char*, const QScriptValue& value)
{
QFETCH(QString, expected);
QCOMPARE(qscriptvalue_cast<QString>(value), expected);
@@ -289,7 +289,7 @@ void tst_QScriptValue::qscriptvalue_castQString_test(const char*, const QScriptV
DEFINE_TEST_FUNCTION(qscriptvalue_castQString)
-void tst_QScriptValue::qscriptvalue_castqsreal_initData()
+void tst_QScriptValueGenerated::qscriptvalue_castqsreal_initData()
{
QTest::addColumn<qsreal>("expected");
initScriptValues();
@@ -454,7 +454,7 @@ static qsreal qscriptvalue_castqsreal_valueArray [] = {
65536, 65537, qQNaN(), qInf(), qInf(), qQNaN(), 0, 0, 123, 12.4,
0, qQNaN(), qQNaN(), 0, qQNaN(), qQNaN(), qQNaN(), qQNaN(), 123, 0,
0, qQNaN(), };
-void tst_QScriptValue::qscriptvalue_castqsreal_makeData(const char* expr)
+void tst_QScriptValueGenerated::qscriptvalue_castqsreal_makeData(const char* expr)
{
static QHash<QString, qsreal> value;
if (value.isEmpty()) {
@@ -465,7 +465,7 @@ void tst_QScriptValue::qscriptvalue_castqsreal_makeData(const char* expr)
newRow(expr) << value.value(expr);
}
-void tst_QScriptValue::qscriptvalue_castqsreal_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::qscriptvalue_castqsreal_test(const char*, const QScriptValue& value)
{
QFETCH(qsreal, expected);
if (qIsNaN(expected)) {
@@ -485,7 +485,7 @@ void tst_QScriptValue::qscriptvalue_castqsreal_test(const char*, const QScriptVa
DEFINE_TEST_FUNCTION(qscriptvalue_castqsreal)
-void tst_QScriptValue::qscriptvalue_castbool_initData()
+void tst_QScriptValueGenerated::qscriptvalue_castbool_initData()
{
QTest::addColumn<bool>("expected");
initScriptValues();
@@ -706,7 +706,7 @@ static bool qscriptvalue_castbool_valueArray [] = {
true, true,
true, true,
false, true, };
-void tst_QScriptValue::qscriptvalue_castbool_makeData(const char* expr)
+void tst_QScriptValueGenerated::qscriptvalue_castbool_makeData(const char* expr)
{
static QHash<QString, bool> value;
if (value.isEmpty()) {
@@ -717,7 +717,7 @@ void tst_QScriptValue::qscriptvalue_castbool_makeData(const char* expr)
newRow(expr) << value.value(expr);
}
-void tst_QScriptValue::qscriptvalue_castbool_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::qscriptvalue_castbool_test(const char*, const QScriptValue& value)
{
QFETCH(bool, expected);
QCOMPARE(qscriptvalue_cast<bool>(value), expected);
@@ -727,7 +727,7 @@ void tst_QScriptValue::qscriptvalue_castbool_test(const char*, const QScriptValu
DEFINE_TEST_FUNCTION(qscriptvalue_castbool)
-void tst_QScriptValue::qscriptvalue_castqint32_initData()
+void tst_QScriptValueGenerated::qscriptvalue_castqint32_initData()
{
QTest::addColumn<qint32>("expected");
initScriptValues();
@@ -948,7 +948,7 @@ static qint32 qscriptvalue_castqint32_valueArray [] = {
0, 0,
123, 0,
0, 0, };
-void tst_QScriptValue::qscriptvalue_castqint32_makeData(const char* expr)
+void tst_QScriptValueGenerated::qscriptvalue_castqint32_makeData(const char* expr)
{
static QHash<QString, qint32> value;
if (value.isEmpty()) {
@@ -959,7 +959,7 @@ void tst_QScriptValue::qscriptvalue_castqint32_makeData(const char* expr)
newRow(expr) << value.value(expr);
}
-void tst_QScriptValue::qscriptvalue_castqint32_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::qscriptvalue_castqint32_test(const char*, const QScriptValue& value)
{
QFETCH(qint32, expected);
QCOMPARE(qscriptvalue_cast<qint32>(value), expected);
@@ -969,7 +969,7 @@ void tst_QScriptValue::qscriptvalue_castqint32_test(const char*, const QScriptVa
DEFINE_TEST_FUNCTION(qscriptvalue_castqint32)
-void tst_QScriptValue::qscriptvalue_castquint32_initData()
+void tst_QScriptValueGenerated::qscriptvalue_castquint32_initData()
{
QTest::addColumn<quint32>("expected");
initScriptValues();
@@ -1190,7 +1190,7 @@ static quint32 qscriptvalue_castquint32_valueArray [] = {
0, 0,
123, 0,
0, 0, };
-void tst_QScriptValue::qscriptvalue_castquint32_makeData(const char* expr)
+void tst_QScriptValueGenerated::qscriptvalue_castquint32_makeData(const char* expr)
{
static QHash<QString, quint32> value;
if (value.isEmpty()) {
@@ -1201,7 +1201,7 @@ void tst_QScriptValue::qscriptvalue_castquint32_makeData(const char* expr)
newRow(expr) << value.value(expr);
}
-void tst_QScriptValue::qscriptvalue_castquint32_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::qscriptvalue_castquint32_test(const char*, const QScriptValue& value)
{
QFETCH(quint32, expected);
QCOMPARE(qscriptvalue_cast<quint32>(value), expected);
@@ -1211,7 +1211,7 @@ void tst_QScriptValue::qscriptvalue_castquint32_test(const char*, const QScriptV
DEFINE_TEST_FUNCTION(qscriptvalue_castquint32)
-void tst_QScriptValue::qscriptvalue_castquint16_initData()
+void tst_QScriptValueGenerated::qscriptvalue_castquint16_initData()
{
QTest::addColumn<quint16>("expected");
initScriptValues();
@@ -1432,7 +1432,7 @@ static quint16 qscriptvalue_castquint16_valueArray [] = {
0, 0,
123, 0,
0, 0, };
-void tst_QScriptValue::qscriptvalue_castquint16_makeData(const char* expr)
+void tst_QScriptValueGenerated::qscriptvalue_castquint16_makeData(const char* expr)
{
static QHash<QString, quint16> value;
if (value.isEmpty()) {
@@ -1443,7 +1443,7 @@ void tst_QScriptValue::qscriptvalue_castquint16_makeData(const char* expr)
newRow(expr) << value.value(expr);
}
-void tst_QScriptValue::qscriptvalue_castquint16_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::qscriptvalue_castquint16_test(const char*, const QScriptValue& value)
{
QFETCH(quint16, expected);
QCOMPARE(qscriptvalue_cast<quint16>(value), expected);
diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue_generated_comparison.cpp b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_comparison.cpp
index 6e1f8ee..02243de 100644
--- a/tests/auto/qscriptvalue/tst_qscriptvalue_generated_comparison.cpp
+++ b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_comparison.cpp
@@ -47,7 +47,7 @@
-void tst_QScriptValue::equals_initData()
+void tst_QScriptValueGenerated::equals_initData()
{
QTest::addColumn<QScriptValue>("other");
QTest::addColumn<bool>("expected");
@@ -1273,7 +1273,7 @@ static QString equals_array [] = {
"engine->newQObject(0) <=> engine->newQObject(0)",
"engine->newQObject(engine) <=> engine->newQObject(engine)",};
-void tst_QScriptValue::equals_makeData(const char *expr)
+void tst_QScriptValueGenerated::equals_makeData(const char *expr)
{
static QSet<QString> equals;
if (equals.isEmpty()) {
@@ -1288,7 +1288,7 @@ void tst_QScriptValue::equals_makeData(const char *expr)
}
}
-void tst_QScriptValue::equals_test(const char *, const QScriptValue& value)
+void tst_QScriptValueGenerated::equals_test(const char *, const QScriptValue& value)
{
QFETCH(QScriptValue, other);
QFETCH(bool, expected);
@@ -1298,7 +1298,7 @@ void tst_QScriptValue::equals_test(const char *, const QScriptValue& value)
DEFINE_TEST_FUNCTION(equals)
-void tst_QScriptValue::strictlyEquals_initData()
+void tst_QScriptValueGenerated::strictlyEquals_initData()
{
QTest::addColumn<QScriptValue>("other");
QTest::addColumn<bool>("expected");
@@ -1830,7 +1830,7 @@ static QString strictlyEquals_array [] = {
"engine->newQObject(0) <=> engine->newQObject(0)",
"engine->newQObject(engine) <=> engine->newQObject(engine)",};
-void tst_QScriptValue::strictlyEquals_makeData(const char *expr)
+void tst_QScriptValueGenerated::strictlyEquals_makeData(const char *expr)
{
static QSet<QString> equals;
if (equals.isEmpty()) {
@@ -1845,7 +1845,7 @@ void tst_QScriptValue::strictlyEquals_makeData(const char *expr)
}
}
-void tst_QScriptValue::strictlyEquals_test(const char *, const QScriptValue& value)
+void tst_QScriptValueGenerated::strictlyEquals_test(const char *, const QScriptValue& value)
{
QFETCH(QScriptValue, other);
QFETCH(bool, expected);
@@ -1855,7 +1855,7 @@ void tst_QScriptValue::strictlyEquals_test(const char *, const QScriptValue& val
DEFINE_TEST_FUNCTION(strictlyEquals)
-void tst_QScriptValue::lessThan_initData()
+void tst_QScriptValueGenerated::lessThan_initData()
{
QTest::addColumn<QScriptValue>("other");
QTest::addColumn<bool>("expected");
@@ -6927,7 +6927,7 @@ static QString lessThan_array [] = {
"engine->newQObject(engine) <=> engine->newObject()",
"engine->newQObject(engine) <=> engine->newQMetaObject(&QObject::staticMetaObject)",};
-void tst_QScriptValue::lessThan_makeData(const char *expr)
+void tst_QScriptValueGenerated::lessThan_makeData(const char *expr)
{
static QSet<QString> equals;
if (equals.isEmpty()) {
@@ -6942,7 +6942,7 @@ void tst_QScriptValue::lessThan_makeData(const char *expr)
}
}
-void tst_QScriptValue::lessThan_test(const char *, const QScriptValue& value)
+void tst_QScriptValueGenerated::lessThan_test(const char *, const QScriptValue& value)
{
QFETCH(QScriptValue, other);
QFETCH(bool, expected);
@@ -6952,7 +6952,7 @@ void tst_QScriptValue::lessThan_test(const char *, const QScriptValue& value)
DEFINE_TEST_FUNCTION(lessThan)
-void tst_QScriptValue::instanceOf_initData()
+void tst_QScriptValueGenerated::instanceOf_initData()
{
QTest::addColumn<QScriptValue>("other");
QTest::addColumn<bool>("expected");
@@ -7001,7 +7001,7 @@ static QString instanceOf_array [] = {
"engine->newVariant(QVariant(false)) <=> engine->evaluate(\"Object\")",
"engine->newQObject(engine) <=> engine->evaluate(\"Object\")",};
-void tst_QScriptValue::instanceOf_makeData(const char *expr)
+void tst_QScriptValueGenerated::instanceOf_makeData(const char *expr)
{
static QSet<QString> equals;
if (equals.isEmpty()) {
@@ -7016,7 +7016,7 @@ void tst_QScriptValue::instanceOf_makeData(const char *expr)
}
}
-void tst_QScriptValue::instanceOf_test(const char *, const QScriptValue& value)
+void tst_QScriptValueGenerated::instanceOf_test(const char *, const QScriptValue& value)
{
QFETCH(QScriptValue, other);
QFETCH(bool, expected);
diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue_generated_init.cpp b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_init.cpp
index a9eb2ca..8c8a7d1 100644
--- a/tests/auto/qscriptvalue/tst_qscriptvalue_generated_init.cpp
+++ b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_init.cpp
@@ -46,7 +46,7 @@
#include "tst_qscriptvalue.h"
-void tst_QScriptValue::initScriptValues()
+void tst_QScriptValueGenerated::initScriptValues()
{
m_values.clear();
if (engine)
diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue_generated_isXXX.cpp b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_isXXX.cpp
index 106043b..71a5c1d 100644
--- a/tests/auto/qscriptvalue/tst_qscriptvalue_generated_isXXX.cpp
+++ b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_isXXX.cpp
@@ -46,7 +46,7 @@
#include "tst_qscriptvalue.h"
-void tst_QScriptValue::isValid_initData()
+void tst_QScriptValueGenerated::isValid_initData()
{
QTest::addColumn<bool>("expected");
initScriptValues();
@@ -195,7 +195,7 @@ static QString isValid_array [] = {
"engine->newQObject(0)",
"engine->newQObject(engine)",};
-void tst_QScriptValue::isValid_makeData(const char* expr)
+void tst_QScriptValueGenerated::isValid_makeData(const char* expr)
{
static QSet<QString> isValid;
if (isValid.isEmpty()) {
@@ -206,7 +206,7 @@ void tst_QScriptValue::isValid_makeData(const char* expr)
newRow(expr) << isValid.contains(expr);
}
-void tst_QScriptValue::isValid_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::isValid_test(const char*, const QScriptValue& value)
{
QFETCH(bool, expected);
QCOMPARE(value.isValid(), expected);
@@ -216,7 +216,7 @@ void tst_QScriptValue::isValid_test(const char*, const QScriptValue& value)
DEFINE_TEST_FUNCTION(isValid)
-void tst_QScriptValue::isBool_initData()
+void tst_QScriptValueGenerated::isBool_initData()
{
QTest::addColumn<bool>("expected");
initScriptValues();
@@ -232,7 +232,7 @@ static QString isBool_array [] = {
"engine->evaluate(\"true\")",
"engine->evaluate(\"false\")",};
-void tst_QScriptValue::isBool_makeData(const char* expr)
+void tst_QScriptValueGenerated::isBool_makeData(const char* expr)
{
static QSet<QString> isBool;
if (isBool.isEmpty()) {
@@ -243,7 +243,7 @@ void tst_QScriptValue::isBool_makeData(const char* expr)
newRow(expr) << isBool.contains(expr);
}
-void tst_QScriptValue::isBool_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::isBool_test(const char*, const QScriptValue& value)
{
QFETCH(bool, expected);
QCOMPARE(value.isBool(), expected);
@@ -253,7 +253,7 @@ void tst_QScriptValue::isBool_test(const char*, const QScriptValue& value)
DEFINE_TEST_FUNCTION(isBool)
-void tst_QScriptValue::isBoolean_initData()
+void tst_QScriptValueGenerated::isBoolean_initData()
{
QTest::addColumn<bool>("expected");
initScriptValues();
@@ -269,7 +269,7 @@ static QString isBoolean_array [] = {
"engine->evaluate(\"true\")",
"engine->evaluate(\"false\")",};
-void tst_QScriptValue::isBoolean_makeData(const char* expr)
+void tst_QScriptValueGenerated::isBoolean_makeData(const char* expr)
{
static QSet<QString> isBoolean;
if (isBoolean.isEmpty()) {
@@ -280,7 +280,7 @@ void tst_QScriptValue::isBoolean_makeData(const char* expr)
newRow(expr) << isBoolean.contains(expr);
}
-void tst_QScriptValue::isBoolean_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::isBoolean_test(const char*, const QScriptValue& value)
{
QFETCH(bool, expected);
QCOMPARE(value.isBoolean(), expected);
@@ -290,7 +290,7 @@ void tst_QScriptValue::isBoolean_test(const char*, const QScriptValue& value)
DEFINE_TEST_FUNCTION(isBoolean)
-void tst_QScriptValue::isNumber_initData()
+void tst_QScriptValueGenerated::isNumber_initData()
{
QTest::addColumn<bool>("expected");
initScriptValues();
@@ -354,7 +354,7 @@ static QString isNumber_array [] = {
"engine->evaluate(\"Infinity\")",
"engine->evaluate(\"-Infinity\")",};
-void tst_QScriptValue::isNumber_makeData(const char* expr)
+void tst_QScriptValueGenerated::isNumber_makeData(const char* expr)
{
static QSet<QString> isNumber;
if (isNumber.isEmpty()) {
@@ -365,7 +365,7 @@ void tst_QScriptValue::isNumber_makeData(const char* expr)
newRow(expr) << isNumber.contains(expr);
}
-void tst_QScriptValue::isNumber_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::isNumber_test(const char*, const QScriptValue& value)
{
QFETCH(bool, expected);
QCOMPARE(value.isNumber(), expected);
@@ -375,7 +375,7 @@ void tst_QScriptValue::isNumber_test(const char*, const QScriptValue& value)
DEFINE_TEST_FUNCTION(isNumber)
-void tst_QScriptValue::isFunction_initData()
+void tst_QScriptValueGenerated::isFunction_initData()
{
QTest::addColumn<bool>("expected");
initScriptValues();
@@ -393,7 +393,7 @@ static QString isFunction_array [] = {
"engine->evaluate(\"/foo/\")",
"engine->newQMetaObject(&QObject::staticMetaObject)",};
-void tst_QScriptValue::isFunction_makeData(const char* expr)
+void tst_QScriptValueGenerated::isFunction_makeData(const char* expr)
{
static QSet<QString> isFunction;
if (isFunction.isEmpty()) {
@@ -404,7 +404,7 @@ void tst_QScriptValue::isFunction_makeData(const char* expr)
newRow(expr) << isFunction.contains(expr);
}
-void tst_QScriptValue::isFunction_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::isFunction_test(const char*, const QScriptValue& value)
{
QFETCH(bool, expected);
QCOMPARE(value.isFunction(), expected);
@@ -414,7 +414,7 @@ void tst_QScriptValue::isFunction_test(const char*, const QScriptValue& value)
DEFINE_TEST_FUNCTION(isFunction)
-void tst_QScriptValue::isNull_initData()
+void tst_QScriptValueGenerated::isNull_initData()
{
QTest::addColumn<bool>("expected");
initScriptValues();
@@ -428,7 +428,7 @@ static QString isNull_array [] = {
"engine->nullValue()",
"engine->newQObject(0)",};
-void tst_QScriptValue::isNull_makeData(const char* expr)
+void tst_QScriptValueGenerated::isNull_makeData(const char* expr)
{
static QSet<QString> isNull;
if (isNull.isEmpty()) {
@@ -439,7 +439,7 @@ void tst_QScriptValue::isNull_makeData(const char* expr)
newRow(expr) << isNull.contains(expr);
}
-void tst_QScriptValue::isNull_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::isNull_test(const char*, const QScriptValue& value)
{
QFETCH(bool, expected);
QCOMPARE(value.isNull(), expected);
@@ -449,7 +449,7 @@ void tst_QScriptValue::isNull_test(const char*, const QScriptValue& value)
DEFINE_TEST_FUNCTION(isNull)
-void tst_QScriptValue::isString_initData()
+void tst_QScriptValueGenerated::isString_initData()
{
QTest::addColumn<bool>("expected");
initScriptValues();
@@ -492,7 +492,7 @@ static QString isString_array [] = {
"engine->evaluate(\"'123'\")",
"engine->evaluate(\"'12.4'\")",};
-void tst_QScriptValue::isString_makeData(const char* expr)
+void tst_QScriptValueGenerated::isString_makeData(const char* expr)
{
static QSet<QString> isString;
if (isString.isEmpty()) {
@@ -503,7 +503,7 @@ void tst_QScriptValue::isString_makeData(const char* expr)
newRow(expr) << isString.contains(expr);
}
-void tst_QScriptValue::isString_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::isString_test(const char*, const QScriptValue& value)
{
QFETCH(bool, expected);
QCOMPARE(value.isString(), expected);
@@ -513,7 +513,7 @@ void tst_QScriptValue::isString_test(const char*, const QScriptValue& value)
DEFINE_TEST_FUNCTION(isString)
-void tst_QScriptValue::isUndefined_initData()
+void tst_QScriptValueGenerated::isUndefined_initData()
{
QTest::addColumn<bool>("expected");
initScriptValues();
@@ -527,7 +527,7 @@ static QString isUndefined_array [] = {
"engine->evaluate(\"undefined\")",
"engine->undefinedValue()",};
-void tst_QScriptValue::isUndefined_makeData(const char* expr)
+void tst_QScriptValueGenerated::isUndefined_makeData(const char* expr)
{
static QSet<QString> isUndefined;
if (isUndefined.isEmpty()) {
@@ -538,7 +538,7 @@ void tst_QScriptValue::isUndefined_makeData(const char* expr)
newRow(expr) << isUndefined.contains(expr);
}
-void tst_QScriptValue::isUndefined_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::isUndefined_test(const char*, const QScriptValue& value)
{
QFETCH(bool, expected);
QCOMPARE(value.isUndefined(), expected);
@@ -548,7 +548,7 @@ void tst_QScriptValue::isUndefined_test(const char*, const QScriptValue& value)
DEFINE_TEST_FUNCTION(isUndefined)
-void tst_QScriptValue::isVariant_initData()
+void tst_QScriptValueGenerated::isVariant_initData()
{
QTest::addColumn<bool>("expected");
initScriptValues();
@@ -559,7 +559,7 @@ static QString isVariant_array [] = {
"engine->newVariant(QVariant(123))",
"engine->newVariant(QVariant(false))",};
-void tst_QScriptValue::isVariant_makeData(const char* expr)
+void tst_QScriptValueGenerated::isVariant_makeData(const char* expr)
{
static QSet<QString> isVariant;
if (isVariant.isEmpty()) {
@@ -570,7 +570,7 @@ void tst_QScriptValue::isVariant_makeData(const char* expr)
newRow(expr) << isVariant.contains(expr);
}
-void tst_QScriptValue::isVariant_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::isVariant_test(const char*, const QScriptValue& value)
{
QFETCH(bool, expected);
QCOMPARE(value.isVariant(), expected);
@@ -580,7 +580,7 @@ void tst_QScriptValue::isVariant_test(const char*, const QScriptValue& value)
DEFINE_TEST_FUNCTION(isVariant)
-void tst_QScriptValue::isQObject_initData()
+void tst_QScriptValueGenerated::isQObject_initData()
{
QTest::addColumn<bool>("expected");
initScriptValues();
@@ -589,7 +589,7 @@ void tst_QScriptValue::isQObject_initData()
static QString isQObject_array [] = {
"engine->newQObject(engine)",};
-void tst_QScriptValue::isQObject_makeData(const char* expr)
+void tst_QScriptValueGenerated::isQObject_makeData(const char* expr)
{
static QSet<QString> isQObject;
if (isQObject.isEmpty()) {
@@ -600,7 +600,7 @@ void tst_QScriptValue::isQObject_makeData(const char* expr)
newRow(expr) << isQObject.contains(expr);
}
-void tst_QScriptValue::isQObject_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::isQObject_test(const char*, const QScriptValue& value)
{
QFETCH(bool, expected);
QCOMPARE(value.isQObject(), expected);
@@ -610,7 +610,7 @@ void tst_QScriptValue::isQObject_test(const char*, const QScriptValue& value)
DEFINE_TEST_FUNCTION(isQObject)
-void tst_QScriptValue::isQMetaObject_initData()
+void tst_QScriptValueGenerated::isQMetaObject_initData()
{
QTest::addColumn<bool>("expected");
initScriptValues();
@@ -619,7 +619,7 @@ void tst_QScriptValue::isQMetaObject_initData()
static QString isQMetaObject_array [] = {
"engine->newQMetaObject(&QObject::staticMetaObject)",};
-void tst_QScriptValue::isQMetaObject_makeData(const char* expr)
+void tst_QScriptValueGenerated::isQMetaObject_makeData(const char* expr)
{
static QSet<QString> isQMetaObject;
if (isQMetaObject.isEmpty()) {
@@ -630,7 +630,7 @@ void tst_QScriptValue::isQMetaObject_makeData(const char* expr)
newRow(expr) << isQMetaObject.contains(expr);
}
-void tst_QScriptValue::isQMetaObject_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::isQMetaObject_test(const char*, const QScriptValue& value)
{
QFETCH(bool, expected);
QCOMPARE(value.isQMetaObject(), expected);
@@ -640,7 +640,7 @@ void tst_QScriptValue::isQMetaObject_test(const char*, const QScriptValue& value
DEFINE_TEST_FUNCTION(isQMetaObject)
-void tst_QScriptValue::isObject_initData()
+void tst_QScriptValueGenerated::isObject_initData()
{
QTest::addColumn<bool>("expected");
initScriptValues();
@@ -678,7 +678,7 @@ static QString isObject_array [] = {
"engine->newVariant(QVariant(false))",
"engine->newQObject(engine)",};
-void tst_QScriptValue::isObject_makeData(const char* expr)
+void tst_QScriptValueGenerated::isObject_makeData(const char* expr)
{
static QSet<QString> isObject;
if (isObject.isEmpty()) {
@@ -689,7 +689,7 @@ void tst_QScriptValue::isObject_makeData(const char* expr)
newRow(expr) << isObject.contains(expr);
}
-void tst_QScriptValue::isObject_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::isObject_test(const char*, const QScriptValue& value)
{
QFETCH(bool, expected);
QCOMPARE(value.isObject(), expected);
@@ -699,7 +699,7 @@ void tst_QScriptValue::isObject_test(const char*, const QScriptValue& value)
DEFINE_TEST_FUNCTION(isObject)
-void tst_QScriptValue::isDate_initData()
+void tst_QScriptValueGenerated::isDate_initData()
{
QTest::addColumn<bool>("expected");
initScriptValues();
@@ -709,7 +709,7 @@ static QString isDate_array [] = {
"engine->evaluate(\"Date.prototype\")",
"engine->newDate(QDateTime())",};
-void tst_QScriptValue::isDate_makeData(const char* expr)
+void tst_QScriptValueGenerated::isDate_makeData(const char* expr)
{
static QSet<QString> isDate;
if (isDate.isEmpty()) {
@@ -720,7 +720,7 @@ void tst_QScriptValue::isDate_makeData(const char* expr)
newRow(expr) << isDate.contains(expr);
}
-void tst_QScriptValue::isDate_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::isDate_test(const char*, const QScriptValue& value)
{
QFETCH(bool, expected);
QCOMPARE(value.isDate(), expected);
@@ -730,7 +730,7 @@ void tst_QScriptValue::isDate_test(const char*, const QScriptValue& value)
DEFINE_TEST_FUNCTION(isDate)
-void tst_QScriptValue::isRegExp_initData()
+void tst_QScriptValueGenerated::isRegExp_initData()
{
QTest::addColumn<bool>("expected");
initScriptValues();
@@ -739,7 +739,7 @@ void tst_QScriptValue::isRegExp_initData()
static QString isRegExp_array [] = {
"engine->evaluate(\"/foo/\")",};
-void tst_QScriptValue::isRegExp_makeData(const char* expr)
+void tst_QScriptValueGenerated::isRegExp_makeData(const char* expr)
{
static QSet<QString> isRegExp;
if (isRegExp.isEmpty()) {
@@ -750,7 +750,7 @@ void tst_QScriptValue::isRegExp_makeData(const char* expr)
newRow(expr) << isRegExp.contains(expr);
}
-void tst_QScriptValue::isRegExp_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::isRegExp_test(const char*, const QScriptValue& value)
{
QFETCH(bool, expected);
QCOMPARE(value.isRegExp(), expected);
@@ -760,7 +760,7 @@ void tst_QScriptValue::isRegExp_test(const char*, const QScriptValue& value)
DEFINE_TEST_FUNCTION(isRegExp)
-void tst_QScriptValue::isArray_initData()
+void tst_QScriptValueGenerated::isArray_initData()
{
QTest::addColumn<bool>("expected");
initScriptValues();
@@ -773,7 +773,7 @@ static QString isArray_array [] = {
"engine->newArray()",
"engine->newArray(10)",};
-void tst_QScriptValue::isArray_makeData(const char* expr)
+void tst_QScriptValueGenerated::isArray_makeData(const char* expr)
{
static QSet<QString> isArray;
if (isArray.isEmpty()) {
@@ -784,7 +784,7 @@ void tst_QScriptValue::isArray_makeData(const char* expr)
newRow(expr) << isArray.contains(expr);
}
-void tst_QScriptValue::isArray_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::isArray_test(const char*, const QScriptValue& value)
{
QFETCH(bool, expected);
QCOMPARE(value.isArray(), expected);
@@ -794,7 +794,7 @@ void tst_QScriptValue::isArray_test(const char*, const QScriptValue& value)
DEFINE_TEST_FUNCTION(isArray)
-void tst_QScriptValue::isError_initData()
+void tst_QScriptValueGenerated::isError_initData()
{
QTest::addColumn<bool>("expected");
initScriptValues();
@@ -808,7 +808,7 @@ static QString isError_array [] = {
"engine->evaluate(\"True\")",
"engine->evaluate(\"False\")",};
-void tst_QScriptValue::isError_makeData(const char* expr)
+void tst_QScriptValueGenerated::isError_makeData(const char* expr)
{
static QSet<QString> isError;
if (isError.isEmpty()) {
@@ -819,7 +819,7 @@ void tst_QScriptValue::isError_makeData(const char* expr)
newRow(expr) << isError.contains(expr);
}
-void tst_QScriptValue::isError_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::isError_test(const char*, const QScriptValue& value)
{
QFETCH(bool, expected);
QCOMPARE(value.isError(), expected);
diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue_generated_toXXX.cpp b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_toXXX.cpp
index 754f4e0..cb75ded 100644
--- a/tests/auto/qscriptvalue/tst_qscriptvalue_generated_toXXX.cpp
+++ b/tests/auto/qscriptvaluegenerated/tst_qscriptvalue_generated_toXXX.cpp
@@ -47,7 +47,7 @@
-void tst_QScriptValue::toString_initData()
+void tst_QScriptValueGenerated::toString_initData()
{
QTest::addColumn<QString>("expected");
initScriptValues();
@@ -270,7 +270,7 @@ static QString toString_valueArray [] = {
"123", "false",
"null", "QScriptEngine(name = \"\")", };
-void tst_QScriptValue::toString_makeData(const char* expr)
+void tst_QScriptValueGenerated::toString_makeData(const char* expr)
{
static QHash<QString, QString> toString;
if (toString.isEmpty()) {
@@ -281,7 +281,7 @@ void tst_QScriptValue::toString_makeData(const char* expr)
newRow(expr) << toString.value(expr);
}
-void tst_QScriptValue::toString_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::toString_test(const char*, const QScriptValue& value)
{
QFETCH(QString, expected);
QCOMPARE(value.toString(), expected);
@@ -291,7 +291,7 @@ void tst_QScriptValue::toString_test(const char*, const QScriptValue& value)
DEFINE_TEST_FUNCTION(toString)
-void tst_QScriptValue::toNumber_initData()
+void tst_QScriptValueGenerated::toNumber_initData()
{
QTest::addColumn<qsreal>("expected");
initScriptValues();
@@ -456,7 +456,7 @@ static qsreal toNumber_valueArray [] = {
65536, 65537, qQNaN(), qInf(), qInf(), qQNaN(), 0, 0, 123, 12.4,
0, qQNaN(), qQNaN(), 0, qQNaN(), qQNaN(), qQNaN(), qQNaN(), 123, 0,
0, qQNaN(), };
-void tst_QScriptValue::toNumber_makeData(const char* expr)
+void tst_QScriptValueGenerated::toNumber_makeData(const char* expr)
{
static QHash<QString, qsreal> toNumber;
if (toNumber.isEmpty()) {
@@ -467,7 +467,7 @@ void tst_QScriptValue::toNumber_makeData(const char* expr)
newRow(expr) << toNumber.value(expr);
}
-void tst_QScriptValue::toNumber_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::toNumber_test(const char*, const QScriptValue& value)
{
QFETCH(qsreal, expected);
if (qIsNaN(expected)) {
@@ -486,7 +486,7 @@ void tst_QScriptValue::toNumber_test(const char*, const QScriptValue& value)
DEFINE_TEST_FUNCTION(toNumber)
-void tst_QScriptValue::toBool_initData()
+void tst_QScriptValueGenerated::toBool_initData()
{
QTest::addColumn<bool>("expected");
initScriptValues();
@@ -709,7 +709,7 @@ static bool toBool_valueArray [] = {
true, true,
false, true, };
-void tst_QScriptValue::toBool_makeData(const char* expr)
+void tst_QScriptValueGenerated::toBool_makeData(const char* expr)
{
static QHash<QString, bool> toBool;
if (toBool.isEmpty()) {
@@ -720,7 +720,7 @@ void tst_QScriptValue::toBool_makeData(const char* expr)
newRow(expr) << toBool.value(expr);
}
-void tst_QScriptValue::toBool_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::toBool_test(const char*, const QScriptValue& value)
{
QFETCH(bool, expected);
QCOMPARE(value.toBool(), expected);
@@ -730,7 +730,7 @@ void tst_QScriptValue::toBool_test(const char*, const QScriptValue& value)
DEFINE_TEST_FUNCTION(toBool)
-void tst_QScriptValue::toBoolean_initData()
+void tst_QScriptValueGenerated::toBoolean_initData()
{
QTest::addColumn<bool>("expected");
initScriptValues();
@@ -953,7 +953,7 @@ static bool toBoolean_valueArray [] = {
true, true,
false, true, };
-void tst_QScriptValue::toBoolean_makeData(const char* expr)
+void tst_QScriptValueGenerated::toBoolean_makeData(const char* expr)
{
static QHash<QString, bool> toBoolean;
if (toBoolean.isEmpty()) {
@@ -964,7 +964,7 @@ void tst_QScriptValue::toBoolean_makeData(const char* expr)
newRow(expr) << toBoolean.value(expr);
}
-void tst_QScriptValue::toBoolean_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::toBoolean_test(const char*, const QScriptValue& value)
{
QFETCH(bool, expected);
QCOMPARE(value.toBoolean(), expected);
@@ -974,7 +974,7 @@ void tst_QScriptValue::toBoolean_test(const char*, const QScriptValue& value)
DEFINE_TEST_FUNCTION(toBoolean)
-void tst_QScriptValue::toInteger_initData()
+void tst_QScriptValueGenerated::toInteger_initData()
{
QTest::addColumn<qsreal>("expected");
initScriptValues();
@@ -1139,7 +1139,7 @@ static qsreal toInteger_valueArray [] = {
65536, 65537, 0, qInf(), qInf(), 0, 0, 0, 123, 12,
0, 0, 0, 0, 0, 0, 0, 0, 123, 0,
0, 0, };
-void tst_QScriptValue::toInteger_makeData(const char* expr)
+void tst_QScriptValueGenerated::toInteger_makeData(const char* expr)
{
static QHash<QString, qsreal> toInteger;
if (toInteger.isEmpty()) {
@@ -1150,7 +1150,7 @@ void tst_QScriptValue::toInteger_makeData(const char* expr)
newRow(expr) << toInteger.value(expr);
}
-void tst_QScriptValue::toInteger_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::toInteger_test(const char*, const QScriptValue& value)
{
QFETCH(qsreal, expected);
if (qIsInf(expected)) {
@@ -1165,7 +1165,7 @@ void tst_QScriptValue::toInteger_test(const char*, const QScriptValue& value)
DEFINE_TEST_FUNCTION(toInteger)
-void tst_QScriptValue::toInt32_initData()
+void tst_QScriptValueGenerated::toInt32_initData()
{
QTest::addColumn<qint32>("expected");
initScriptValues();
@@ -1388,7 +1388,7 @@ static qint32 toInt32_valueArray [] = {
123, 0,
0, 0, };
-void tst_QScriptValue::toInt32_makeData(const char* expr)
+void tst_QScriptValueGenerated::toInt32_makeData(const char* expr)
{
static QHash<QString, qint32> toInt32;
if (toInt32.isEmpty()) {
@@ -1399,7 +1399,7 @@ void tst_QScriptValue::toInt32_makeData(const char* expr)
newRow(expr) << toInt32.value(expr);
}
-void tst_QScriptValue::toInt32_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::toInt32_test(const char*, const QScriptValue& value)
{
QFETCH(qint32, expected);
QCOMPARE(value.toInt32(), expected);
@@ -1409,7 +1409,7 @@ void tst_QScriptValue::toInt32_test(const char*, const QScriptValue& value)
DEFINE_TEST_FUNCTION(toInt32)
-void tst_QScriptValue::toUInt32_initData()
+void tst_QScriptValueGenerated::toUInt32_initData()
{
QTest::addColumn<quint32>("expected");
initScriptValues();
@@ -1632,7 +1632,7 @@ static quint32 toUInt32_valueArray [] = {
123, 0,
0, 0, };
-void tst_QScriptValue::toUInt32_makeData(const char* expr)
+void tst_QScriptValueGenerated::toUInt32_makeData(const char* expr)
{
static QHash<QString, quint32> toUInt32;
if (toUInt32.isEmpty()) {
@@ -1643,7 +1643,7 @@ void tst_QScriptValue::toUInt32_makeData(const char* expr)
newRow(expr) << toUInt32.value(expr);
}
-void tst_QScriptValue::toUInt32_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::toUInt32_test(const char*, const QScriptValue& value)
{
QFETCH(quint32, expected);
QCOMPARE(value.toUInt32(), expected);
@@ -1653,7 +1653,7 @@ void tst_QScriptValue::toUInt32_test(const char*, const QScriptValue& value)
DEFINE_TEST_FUNCTION(toUInt32)
-void tst_QScriptValue::toUInt16_initData()
+void tst_QScriptValueGenerated::toUInt16_initData()
{
QTest::addColumn<quint16>("expected");
initScriptValues();
@@ -1876,7 +1876,7 @@ static quint16 toUInt16_valueArray [] = {
123, 0,
0, 0, };
-void tst_QScriptValue::toUInt16_makeData(const char* expr)
+void tst_QScriptValueGenerated::toUInt16_makeData(const char* expr)
{
static QHash<QString, quint16> toUInt16;
if (toUInt16.isEmpty()) {
@@ -1887,7 +1887,7 @@ void tst_QScriptValue::toUInt16_makeData(const char* expr)
newRow(expr) << toUInt16.value(expr);
}
-void tst_QScriptValue::toUInt16_test(const char*, const QScriptValue& value)
+void tst_QScriptValueGenerated::toUInt16_test(const char*, const QScriptValue& value)
{
QFETCH(quint16, expected);
QCOMPARE(value.toUInt16(), expected);
diff --git a/tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp b/tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp
index 55773f0..df11537 100644
--- a/tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp
+++ b/tests/auto/qscriptvalueiterator/tst_qscriptvalueiterator.cpp
@@ -71,6 +71,7 @@ private slots:
void iterateString();
void iterateGetterSetter();
void assignObjectToIterator();
+ void iterateNonObject();
};
tst_QScriptValueIterator::tst_QScriptValueIterator()
@@ -583,5 +584,25 @@ void tst_QScriptValueIterator::assignObjectToIterator()
QCOMPARE(it.name(), QString::fromLatin1("bar"));
}
+void tst_QScriptValueIterator::iterateNonObject()
+{
+ QScriptValueIterator it(123);
+ QVERIFY(!it.hasNext());
+ it.next();
+ QVERIFY(!it.hasPrevious());
+ it.previous();
+ it.toFront();
+ it.toBack();
+ it.name();
+ it.scriptName();
+ it.flags();
+ it.value();
+ it.setValue(1);
+ it.remove();
+ QScriptValue num(5);
+ it = num;
+ QVERIFY(!it.hasNext());
+}
+
QTEST_MAIN(tst_QScriptValueIterator)
#include "tst_qscriptvalueiterator.moc"
diff --git a/tests/auto/qthread/tst_qthread.cpp b/tests/auto/qthread/tst_qthread.cpp
index 843749a..f290a2b 100644
--- a/tests/auto/qthread/tst_qthread.cpp
+++ b/tests/auto/qthread/tst_qthread.cpp
@@ -106,6 +106,7 @@ private slots:
void adoptMultipleThreads();
void QTBUG13810_exitAndStart();
+ void connectThreadFinishedSignalToObjectDeleteLaterSlot();
void stressTest();
};
@@ -975,6 +976,19 @@ void tst_QThread::QTBUG13810_exitAndStart()
QCOMPARE(sync1.m_prop, 89);
}
+void tst_QThread::connectThreadFinishedSignalToObjectDeleteLaterSlot()
+{
+ QThread thread;
+ QObject *object = new QObject;
+ QWeakPointer<QObject> p = object;
+ QVERIFY(!p.isNull());
+ connect(&thread, SIGNAL(started()), &thread, SLOT(quit()), Qt::DirectConnection);
+ connect(&thread, SIGNAL(finished()), object, SLOT(deleteLater()));
+ object->moveToThread(&thread);
+ thread.start();
+ QVERIFY(thread.wait(30000));
+ QVERIFY(p.isNull());
+}
QTEST_MAIN(tst_QThread)
#include "tst_qthread.moc"
diff --git a/tests/auto/script.pro b/tests/auto/script.pro
index 06f51b5..c4d0544 100644
--- a/tests/auto/script.pro
+++ b/tests/auto/script.pro
@@ -7,10 +7,12 @@ SUBDIRS=\
qscriptengine \
qscriptengineagent \
qscriptenginedebugger \
+ qscriptextensionplugin \
qscriptextqobject \
qscriptjstestsuite \
qscriptstring \
qscriptv8testsuite \
qscriptvalue \
+ qscriptvaluegenerated \
qscriptvalueiterator \