diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2011-07-08 15:56:48 +1000 |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2011-07-08 15:56:48 +1000 |
commit | 26590325b5e9209df4495841b9013d04bbb35515 (patch) | |
tree | 2a4e44ca1e1d4389caf999ee8801a312166bf39c /src/imports/testlib | |
parent | 5a705d8951a0b23c725d99a5a3fce7902ec41374 (diff) | |
parent | 438d50d63c48bbbfd185bd7e1a0d6e6174c1791e (diff) |
Merge branch 'v8'
Conflicts:
src/declarative/qml/qdeclarativescarceresourcescriptclass.cpp
src/declarative/qml/qdeclarativescarceresourcescriptclass_p.h
Change-Id: I54e579307cbeafbbad21884218c5e797ba245c8b
Diffstat (limited to 'src/imports/testlib')
-rw-r--r-- | src/imports/testlib/SignalSpy.qml | 2 | ||||
-rw-r--r-- | src/imports/testlib/TestCase.qml | 31 | ||||
-rw-r--r-- | src/imports/testlib/main.cpp | 98 | ||||
-rw-r--r-- | src/imports/testlib/testlib.pro | 2 |
4 files changed, 66 insertions, 67 deletions
diff --git a/src/imports/testlib/SignalSpy.qml b/src/imports/testlib/SignalSpy.qml index ba51c5a33f..f32a9c6129 100644 --- a/src/imports/testlib/SignalSpy.qml +++ b/src/imports/testlib/SignalSpy.qml @@ -66,7 +66,7 @@ Item { i += 50 } var success = (count >= expected) - if (!qtest_results.verify(success, "wait for signal " + signalName, Qt.qtest_caller_file(), Qt.qtest_caller_line())) + if (!qtest_results.verify(success, "wait for signal " + signalName, QtTest.qtest_caller_file(), QtTest.qtest_caller_line())) throw new Error("QtQuickTest::fail") } diff --git a/src/imports/testlib/TestCase.qml b/src/imports/testlib/TestCase.qml index 5418fe6d8e..22fd5b66bb 100644 --- a/src/imports/testlib/TestCase.qml +++ b/src/imports/testlib/TestCase.qml @@ -46,6 +46,9 @@ import "testlogger.js" as TestLogger Item { id: testCase visible: false + TestUtil { + id:util + } // Name of the test case to prefix the function name in messages. property string name @@ -66,7 +69,7 @@ Item { // Property that is set to true when the main window is shown. // We need to set the property value in an odd way to handle // both qmlviewer and the QtQuickTest module test wrapper. - property bool windowShown: Qt.qtest_wrapper ? qtest.windowShown : false + property bool windowShown: util.wrapper ? qtest.windowShown : false // Internal private state. Identifiers prefixed with qtest are reserved. property bool qtest_prevWhen: true @@ -80,21 +83,21 @@ Item { function fail(msg) { if (msg === undefined) msg = ""; - qtest_results.fail(msg, Qt.qtest_caller_file(), Qt.qtest_caller_line()) + qtest_results.fail(msg, util.callerFile(), util.callerLine()) throw new Error("QtQuickTest::fail") } function qtest_fail(msg, frame) { if (msg === undefined) msg = ""; - qtest_results.fail(msg, Qt.qtest_caller_file(frame), Qt.qtest_caller_line(frame)) + qtest_results.fail(msg, util.callerFile(frame), util.callerLine(frame)) throw new Error("QtQuickTest::fail") } function verify(cond, msg) { if (msg === undefined) msg = ""; - if (!qtest_results.verify(cond, msg, Qt.qtest_caller_file(), Qt.qtest_caller_line())) + if (!qtest_results.verify(cond, msg, util.callerFile(), util.callerLine())) throw new Error("QtQuickTest::fail") } @@ -279,7 +282,7 @@ Item { else msg = "Compared values are not the same" } - if (!qtest_results.compare(success, msg, act, exp, Qt.qtest_caller_file(), Qt.qtest_caller_line())) + if (!qtest_results.compare(success, msg, act, exp, util.callerFile(), util.callerLine())) throw new Error("QtQuickTest::fail") } @@ -297,21 +300,21 @@ Item { var act = qtest_formatValue(actual) var exp = qtest_formatValue(value) var success = qtest_compareInternal(actual, value) - if (!qtest_results.compare(success, "property " + prop, act, exp, Qt.qtest_caller_file(), Qt.qtest_caller_line())) + if (!qtest_results.compare(success, "property " + prop, act, exp, util.callerFile(), util.callerLine())) throw new Error("QtQuickTest::fail") } function skip(msg) { if (msg === undefined) msg = "" - qtest_results.skipSingle(msg, Qt.qtest_caller_file(), Qt.qtest_caller_line()) + qtest_results.skipSingle(msg, util.callerFile(), util.callerLine()) throw new Error("QtQuickTest::skip") } function skipAll(msg) { if (msg === undefined) msg = "" - qtest_results.skipAll(msg, Qt.qtest_caller_file(), Qt.qtest_caller_line()) + qtest_results.skipAll(msg, util.callerFile(), util.callerLine()) throw new Error("QtQuickTest::skip") } @@ -324,7 +327,7 @@ Item { warn("message argument missing from expectFail()") msg = "" } - if (!qtest_results.expectFail(tag, msg, Qt.qtest_caller_file(), Qt.qtest_caller_line())) + if (!qtest_results.expectFail(tag, msg, util.callerFile(), util.callerLine())) throw new Error("QtQuickTest::expectFail") } @@ -337,7 +340,7 @@ Item { warn("message argument missing from expectFailContinue()") msg = "" } - if (!qtest_results.expectFailContinue(tag, msg, Qt.qtest_caller_file(), Qt.qtest_caller_line())) + if (!qtest_results.expectFailContinue(tag, msg, util.callerFile(), util.callerLine())) throw new Error("QtQuickTest::expectFail") } @@ -505,7 +508,7 @@ Item { } function qtest_run() { - if (Qt.qtest_printAvailableFunctions) { + if (util.printAvailableFunctions) { completed = true return } @@ -650,7 +653,7 @@ Item { } } - // The test framework will set qtest.windowShown when the + // The test framework will set util.windowShown when the // window is actually shown. If we are running with qmlviewer, // then this won't happen. So we use a timer instead. Timer { @@ -661,7 +664,7 @@ Item { } Component.onCompleted: { - if (Qt.qtest_printAvailableFunctions) { + if (util.printAvailableFunctions) { var testList = [] for (var prop in testCase) { if (prop.indexOf("test_") != 0 && prop.indexOf("benchmark_") != 0) @@ -683,7 +686,7 @@ Item { if (optional) TestLogger.log_optional_test(qtest_testId) qtest_prevWhen = when - var isQmlViewer = Qt.qtest_wrapper ? false : true + var isQmlViewer = util.wrapper ? false : true if (isQmlViewer) qtest_windowShowTimer.running = true if (when && !completed && !running) diff --git a/src/imports/testlib/main.cpp b/src/imports/testlib/main.cpp index c35db2d312..0f27102764 100644 --- a/src/imports/testlib/main.cpp +++ b/src/imports/testlib/main.cpp @@ -47,56 +47,63 @@ #include <QtScript/qscriptengine.h> #include "QtQuickTest/private/quicktestresult_p.h" #include "QtQuickTest/private/quicktestevent_p.h" +#include "private/qtestoptions_p.h" +#include "QtDeclarative/qsgitem.h" +#include <QtDeclarative/private/qdeclarativeengine_p.h> QT_BEGIN_NAMESPACE QML_DECLARE_TYPE(QuickTestResult) QML_DECLARE_TYPE(QuickTestEvent) -// Copied from qdeclarativedebughelper_p.h in Qt, to avoid a dependency -// on a private header from Qt. -class Q_DECLARATIVE_EXPORT QDeclarativeDebugHelper +#include <QtDebug> + +class QuickTestUtil : public QObject { + Q_OBJECT + Q_PROPERTY(bool printAvailableFunctions READ printAvailableFunctions) + Q_PROPERTY(bool wrapper READ wrapper) public: - static QScriptEngine *getScriptEngine(QDeclarativeEngine *engine); - static void setAnimationSlowDownFactor(qreal factor); - static void enableDebugging(); -}; + QuickTestUtil(QObject *parent = 0) + :QObject(parent) + {} -static QScriptContext *qtest_find_frame(QScriptContext *ctx) -{ - qint32 frame = 1; - if (ctx->argumentCount() > 0) - frame = ctx->argument(0).toInt32(); - ++frame; // Exclude the native function; start at its caller. - while (ctx) { - if (frame-- <= 0) - break; - ctx = ctx->parentContext(); + ~QuickTestUtil() + {} + bool printAvailableFunctions() const + { + return QTest::printAvailableFunctions; } - return ctx; -} - -static QScriptValue qtest_caller_file - (QScriptContext *ctx, QScriptEngine *engine) -{ - ctx = qtest_find_frame(ctx); - if (ctx) { - QScriptContextInfo info(ctx); - return engine->newVariant(info.fileName()); + bool wrapper() const + { + return true; } - return engine->newVariant(QLatin1String("")); -} -static QScriptValue qtest_caller_line - (QScriptContext *ctx, QScriptEngine *engine) -{ - ctx = qtest_find_frame(ctx); - if (ctx) { - QScriptContextInfo info(ctx); - return engine->newVariant(info.lineNumber()); +public Q_SLOTS: + QDeclarativeV8Handle callerFile(int frameIndex = 0) const + { + v8::HandleScope scope; + + v8::Local<v8::StackTrace> stacks = v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed); + int count = stacks->GetFrameCount(); + if (count >= frameIndex + 2) { + v8::Local<v8::StackFrame> frame = stacks->GetFrame(frameIndex + 2); + return QDeclarativeV8Handle::fromHandle(frame->GetScriptNameOrSourceURL()); + } + return QDeclarativeV8Handle(); } - return engine->newVariant(qint32(0)); -} + int callerLine(int frameIndex = 0) const + { + v8::HandleScope scope; + v8::Local<v8::StackTrace> stacks = v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed); + int count = stacks->GetFrameCount(); + if (count >= frameIndex + 2) { + v8::Local<v8::StackFrame> frame = stacks->GetFrame(frameIndex + 2); + return frame->GetLineNumber(); + } + return -1; + } +}; +QML_DECLARE_TYPE(QuickTestUtil) class QTestQmlModule : public QDeclarativeExtensionPlugin { @@ -107,22 +114,11 @@ public: Q_ASSERT(QLatin1String(uri) == QLatin1String("QtTest")); qmlRegisterType<QuickTestResult>(uri,1,0,"TestResult"); qmlRegisterType<QuickTestEvent>(uri,1,0,"TestEvent"); + qmlRegisterType<QuickTestUtil>(uri,1,0,"TestUtil"); } + void initializeEngine(QDeclarativeEngine *engine, const char *) { - // Install some helper functions in the global "Qt" object - // for walking the stack and finding a caller's location. - // Normally we would use an exception's backtrace, but JSC - // only provides the top-most frame in the backtrace. - QScriptEngine *eng = QDeclarativeDebugHelper::getScriptEngine(engine); - QScriptValue qtObject - = eng->globalObject().property(QLatin1String("Qt")); - qtObject.setProperty - (QLatin1String("qtest_caller_file"), - eng->newFunction(qtest_caller_file)); - qtObject.setProperty - (QLatin1String("qtest_caller_line"), - eng->newFunction(qtest_caller_line)); } }; diff --git a/src/imports/testlib/testlib.pro b/src/imports/testlib/testlib.pro index 80bd5c534c..92c5a097cd 100644 --- a/src/imports/testlib/testlib.pro +++ b/src/imports/testlib/testlib.pro @@ -21,7 +21,7 @@ symbian { } -QT += declarative script qmltest qmltest-private +QT += declarative script qmltest qmltest-private declarative-private script-private core-private SOURCES += main.cpp HEADERS += |