diff options
author | Chris Adams <christopher.adams@nokia.com> | 2011-05-06 13:18:19 +1000 |
---|---|---|
committer | Chris Adams <christopher.adams@nokia.com> | 2011-05-06 13:56:10 +1000 |
commit | 24bb6f90f828c0dbed06a56536a3f33b35d36506 (patch) | |
tree | c5358296315a856f08e219c9c4fcebf300ed72b4 /tests | |
parent | e50b7c92998905efdd40314724480e3070bdbcb5 (diff) |
Add unit test and documentation for module API
Related to commit ae6c7a44394d4a5f943f1fc92f4de015ec7bcc96.
Previously, only property access on module API was tested.
This commit adds a test which calls a method on a module API.
It also adds documentation for the qmlRegisterModuleApi functions.
Task-number: QMLNG-33
Reviewed-by: Martin Jones
Diffstat (limited to 'tests')
4 files changed, 10 insertions, 2 deletions
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/moduleApi.qml b/tests/auto/declarative/qdeclarativeecmascript/data/moduleApi.qml index 62abcb7d83..23c1eb0bb8 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/data/moduleApi.qml +++ b/tests/auto/declarative/qdeclarativeecmascript/data/moduleApi.qml @@ -11,8 +11,13 @@ QtObject { property int existingUriTest: QtTest.qobjectTestProperty property int scriptTest: QtTestScriptApi.scriptTestProperty property int qobjectTest: QtTestQObjectApi.qobjectTestProperty + property int qobjectMethodTest: 2 property int qobjectMinorVersionTest: QtTestMinorVersionQObjectApi.qobjectTestProperty property int qobjectMajorVersionTest: QtTestMajorVersionQObjectApi.qobjectTestProperty property int qobjectParentedTest: QtTestParentedQObjectApi.qobjectTestProperty + + Component.onCompleted: { + qobjectMethodTest = QtTestQObjectApi.qobjectTestMethod(); + } } diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp b/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp index 7256d442e3..44d0046b74 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp @@ -104,7 +104,6 @@ public: static QScriptValue script_api(QDeclarativeEngine *engine, QScriptEngine *scriptEngine) { Q_UNUSED(engine) - Q_UNUSED(scriptEngine) static int testProperty = 13; QScriptValue v = scriptEngine->newObject(); diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h index 320e60c82a..8c7b838976 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h +++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h @@ -939,12 +939,14 @@ class testQObjectApi : public QObject public: testQObjectApi(QObject* parent = 0) - : QObject(parent), m_testProperty(0) + : QObject(parent), m_testProperty(0), m_testWritableProperty(0), m_methodCallCount(0) { } ~testQObjectApi() {} + Q_INVOKABLE int qobjectTestMethod() { m_methodCallCount += 1; return m_methodCallCount; } + int qobjectTestProperty() const { return m_testProperty; } void setQObjectTestProperty(int tp) { m_testProperty = tp; emit qobjectTestPropertyChanged(tp); } @@ -958,6 +960,7 @@ signals: private: int m_testProperty; int m_testWritableProperty; + int m_methodCallCount; }; void registerTypes(); diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index efa95d36b6..d9cd8250f7 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -2509,6 +2509,7 @@ void tst_qdeclarativeecmascript::moduleApi() QCOMPARE(object->property("existingUriTest").toInt(), 20); QCOMPARE(object->property("scriptTest").toInt(), 13); QCOMPARE(object->property("qobjectTest").toInt(), 20); + QCOMPARE(object->property("qobjectMethodTest").toInt(), 1); // first call of method, so count = 1. QCOMPARE(object->property("qobjectMinorVersionTest").toInt(), 20); QCOMPARE(object->property("qobjectMajorVersionTest").toInt(), 20); QCOMPARE(object->property("qobjectParentedTest").toInt(), 26); |