summaryrefslogtreecommitdiffstats
path: root/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-07-27 15:25:50 +0200
committerOlivier Goffart <ogoffart@trolltech.com>2009-07-27 15:43:33 +0200
commitf41b7967b279609d9d4e1a872c92e753f9aefad3 (patch)
tree12b0c6155e8e169919f3b403a77478b47a855679 /tests/auto/qscriptcontext/tst_qscriptcontext.cpp
parent76d112eb3c7ea9045f26bee070302924a84fb15c (diff)
Fix tst_QScriptContext::arguments
Diffstat (limited to 'tests/auto/qscriptcontext/tst_qscriptcontext.cpp')
-rw-r--r--tests/auto/qscriptcontext/tst_qscriptcontext.cpp45
1 files changed, 43 insertions, 2 deletions
diff --git a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
index 0e6a9a8302..f1f0e97981 100644
--- a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
+++ b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
@@ -73,6 +73,7 @@ private slots:
void pushAndPopScope();
void getSetActivationObject();
void toString();
+ void argumentsObjectInNative();
};
tst_QScriptContext::tst_QScriptContext()
@@ -144,13 +145,11 @@ void tst_QScriptContext::arguments()
{
QScriptEngine eng;
-#if 0 // ### crashes
{
QScriptValue args = eng.currentContext()->argumentsObject();
QVERIFY(args.isObject());
QCOMPARE(args.property("length").toInt32(), 0);
}
-#endif
{
QScriptValue fun = eng.newFunction(get_arguments);
eng.globalObject().setProperty("get_arguments", fun);
@@ -741,5 +740,47 @@ void tst_QScriptContext::toString()
QCOMPARE(ret.toString(), QString::fromLatin1("foo (first=1, second=2, third=3) at script.qs:2"));
}
+static QScriptValue argumentsObjectInNative_test1(QScriptContext *ctx, QScriptEngine *)
+{
+#define VERIFY(statement) \
+ do {\
+ if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\
+ return QString::fromLatin1("Failed " #statement);\
+ } while (0)
+
+ QScriptValue obj = ctx->argumentsObject();
+ VERIFY(obj.isObject());
+ VERIFY(obj.property(0).toUInt32() == 123);
+ VERIFY(obj.property(1).toString() == QString::fromLatin1("456"));
+ return QString::fromLatin1("success");
+#undef VERIFY
+}
+
+void tst_QScriptContext::argumentsObjectInNative()
+{
+ {
+ QScriptEngine eng;
+ QScriptValue fun = eng.newFunction(argumentsObjectInNative_test1);
+ QScriptValueList args;
+ args << QScriptValue(&eng, 123.0);
+ args << QScriptValue(&eng, QString::fromLatin1("456"));
+ QScriptValue result = fun.call(eng.undefinedValue(), args);
+ QVERIFY(!eng.hasUncaughtException());
+ QCOMPARE(result.toString(), QString::fromLatin1("success"));
+ }
+
+
+
+ {
+ QScriptEngine eng;
+ QScriptValue fun = eng.newFunction(argumentsObjectInNative_test1);
+ eng.globalObject().setProperty("func", fun);
+ QScriptValue result = eng.evaluate("func(123.0 , 456);");
+ QVERIFY(!eng.hasUncaughtException());
+ QCOMPARE(result.toString(), QString::fromLatin1("success"));
+ }
+
+}
+
QTEST_MAIN(tst_QScriptContext)
#include "tst_qscriptcontext.moc"