aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativeecmascript
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2011-05-31 15:25:44 +1000
committerMartin Jones <martin.jones@nokia.com>2011-05-31 15:25:44 +1000
commit766521d62a4cf4598326a510186b080a91bde6dd (patch)
tree5cf89c1338f42122c370c649b73c8193ca079268 /tests/auto/declarative/qdeclarativeecmascript
parenta91b8a041966f8aea4bf01fdcb1d5006547f3902 (diff)
parente7fef9d6115d1a9193c112d8fd4249ae9396dae3 (diff)
Merge branch 'qtquick2'
Conflicts: demos/declarative/flickr/common/Progress.qml demos/declarative/flickr/common/RssModel.qml demos/declarative/flickr/common/ScrollBar.qml demos/declarative/flickr/common/Slider.qml demos/declarative/flickr/mobile/Button.qml demos/declarative/flickr/mobile/GridDelegate.qml demos/declarative/flickr/mobile/ImageDetails.qml demos/declarative/flickr/mobile/ListDelegate.qml demos/declarative/flickr/mobile/TitleBar.qml demos/declarative/flickr/mobile/ToolBar.qml demos/declarative/webbrowser/content/Button.qml demos/declarative/webbrowser/content/FlickableWebView.qml demos/declarative/webbrowser/content/Header.qml demos/declarative/webbrowser/content/ScrollBar.qml demos/declarative/webbrowser/content/UrlInput.qml demos/declarative/webbrowser/webbrowser.qml doc/src/snippets/declarative/mousearea/mousearea-snippet.qml examples/declarative/modelviews/webview/newwindows/qml/alerts.html examples/declarative/modelviews/webview/newwindows/qml/content/Mapping/map.html examples/declarative/modelviews/webview/newwindows/qml/content/pics/cancel.png examples/declarative/modelviews/webview/newwindows/qml/content/pics/ok.png examples/declarative/modelviews/webview/newwindows/qml/newwindows.html src/declarative/graphicsitems/qdeclarativetextinput.cpp src/declarative/qml/qdeclarativecompiledbindings.cpp src/declarative/qml/qdeclarativecompiledbindings_p.h src/declarative/qml/qdeclarativedom.cpp src/declarative/qml/qdeclarativedom_p.h src/declarative/qml/qdeclarativedom_p_p.h src/declarative/qml/qdeclarativeengine.cpp src/declarative/qml/qdeclarativetypeloader.cpp src/imports/particles/particles.cpp tests/auto/declarative/qdeclarativedom/tst_qdeclarativedom.cpp tests/auto/declarative/qmlvisual/qdeclarativeflickable/data/flickable-horizontal.4.png tests/auto/declarative/qmlvisual/qdeclarativepathview/data/test-pathview.6.png tests/auto/declarative/qmlvisual/qdeclarativepositioners/data/usingRepeater.0.png tests/auto/declarative/qmlvisual/qdeclarativespringanimation/data/follow.0.png tests/auto/declarative/qmlvisual/qdeclarativespringanimation/data/follow.1.png tests/auto/declarative/qmlvisual/qdeclarativespringanimation/data/follow.2.png tests/auto/declarative/qmlvisual/qdeclarativespringanimation/data/follow.3.png tests/auto/declarative/qmlvisual/qdeclarativespringanimation/data/follow.4.png tests/auto/declarative/qmlvisual/qdeclarativespringanimation/data/follow.5.png tests/auto/declarative/qmlvisual/qdeclarativespringanimation/data/follow.6.png tests/auto/declarative/qmlvisual/qdeclarativespringanimation/data/follow.7.png tests/auto/declarative/qmlvisual/qdeclarativetext/align/data-MAC/multilineAlign.0.png tests/auto/declarative/qmlvisual/qdeclarativetext/align/data-X11/multilineAlign.0.png tests/auto/declarative/qmlvisual/qdeclarativetext/baseline/data-X11/parentanchor.0.png tests/auto/declarative/qmlvisual/qdeclarativetext/data-MAC/qtbug_14865.0.png tests/auto/declarative/qmlvisual/qdeclarativetext/data-MAC/qtbug_14865.1.png tests/auto/declarative/qmlvisual/qdeclarativetext/data-X11/qtbug_14865.0.png tests/auto/declarative/qmlvisual/qdeclarativetext/data-X11/qtbug_14865.1.png tests/auto/declarative/qmlvisual/qdeclarativetext/elide/data-X11/elide.1.png tests/auto/declarative/qmlvisual/qdeclarativetext/elide/data-X11/elide2.0.png tests/auto/declarative/qmlvisual/qdeclarativetext/elide/data-X11/elide2.1.png tests/auto/declarative/qmlvisual/qdeclarativetext/elide/data-X11/multilength.1.png tests/auto/declarative/qmlvisual/qdeclarativetext/elide/data-X11/multilength.2.png tests/auto/declarative/qmlvisual/qdeclarativetext/elide/data-X11/multilength.3.png tests/auto/declarative/qmlvisual/qdeclarativetext/elide/data-X11/multilength.4.png tests/auto/declarative/qmlvisual/qdeclarativetext/elide/data-X11/multilength.5.png tests/auto/declarative/qmlvisual/qdeclarativetext/font/data-MAC/plaintext2.0.png tests/auto/declarative/qmlvisual/qdeclarativetext/font/data-MAC/plaintext3.0.png tests/auto/declarative/qmlvisual/qdeclarativetext/font/data-X11/plaintext.0.png tests/auto/declarative/qmlvisual/qdeclarativetext/font/data-X11/plaintext2.0.png tests/auto/declarative/qmlvisual/qdeclarativetext/font/data-X11/richtext.0.png tests/auto/declarative/qmlvisual/qdeclarativetext/font/data-X11/richtext2.0.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.0.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.1.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.10.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.11.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.2.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.3.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.4.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.5.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.6.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.7.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.8.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/usingMultilineEdit.9.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/wrap.0.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/wrap.1.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/wrap.2.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/wrap.3.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/wrap.4.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/wrap.5.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-MAC/wrap.6.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/qt-669.0.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/qt-669.1.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/qt-669.2.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/qt-669.3.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/qt-669.4.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/usingMultilineEdit.10.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/usingMultilineEdit.11.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/usingMultilineEdit.12.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/usingMultilineEdit.7.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/usingMultilineEdit.9.png tests/auto/declarative/qmlvisual/qdeclarativetextedit/data-X11/wrap.7.png tests/auto/declarative/qmlvisual/qdeclarativetextinput/data-MAC/echoMode.0.png tests/auto/declarative/qmlvisual/qdeclarativetextinput/data-MAC/echoMode.1.png tests/auto/declarative/qmlvisual/qdeclarativetextinput/data-MAC/echoMode.2.png tests/auto/declarative/qmlvisual/qdeclarativetextinput/data-X11/usingLineEdit.11.png tests/auto/declarative/qmlvisual/tst_qmlvisual.cpp Change-Id: I40df8a9403a58a6c03a0f1734f16a5cbed6c85ff
Diffstat (limited to 'tests/auto/declarative/qdeclarativeecmascript')
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/Scope6Nested.qml7
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.1.qml12
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.2.qml12
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.3.qml12
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.4.qml12
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlots.qml27
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimport/SpecialRectangleOne.qml9
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimport/SpecialRectangleTwo.qml9
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importFive.js3
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importFour.js9
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importOne.js13
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importPragmaLibrary.js9
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importThree.js9
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importTwo.js10
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importWithNoImports.js11
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimport/testImport.qml14
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimport/testImportPragmaLibrary.qml20
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimport/testImportScoping.qml11
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimport/testModuleImport.js8
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimport/testScriptImport.js11
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/failFive.qml11
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/failFour.qml7
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/failOne.qml7
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/failThree.qml8
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/failTwo.qml7
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/importOne.js7
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/importPragmaLibrary.js11
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/importWithImports.js13
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/testImportPragmaLibrary.qml8
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/testModuleImport.js8
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/testScriptImport.js11
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/moduleApi.qml23
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/moduleApiCaching.qml12
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/moduleApiMajorVersionFail.qml10
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/moduleApiMinorVersionFail.qml10
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/moduleApiWriting.qml27
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/realToInt.qml11
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/ScarceResourceSignalComponent.qml9
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopy.qml15
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyFromJs.qml15
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImport.js24
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImport.qml18
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImportFail.js18
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImportFail.qml8
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImportNoBinding.js14
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImportNoBinding.qml12
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyNoBinding.qml14
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceDestroyedCopy.qml14
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceFunction.qml23
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceFunctionFail.qml23
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceSignal.qml29
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceTest.js48
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceTest.qml14
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceTestMultiple.qml16
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceTestPreserve.qml15
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scope.5.qml27
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/data/scope.6.qml10
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/qdeclarativeecmascript.pro1
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp44
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/testtypes.h54
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp457
61 files changed, 1337 insertions, 4 deletions
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/Scope6Nested.qml b/tests/auto/declarative/qdeclarativeecmascript/data/Scope6Nested.qml
new file mode 100644
index 0000000000..a3794df22b
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/Scope6Nested.qml
@@ -0,0 +1,7 @@
+import Qt.test 1.0
+
+MyQmlObject {
+ function runtest(obj) {
+ return obj.MyQmlObject.value == 19;
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.1.qml b/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.1.qml
new file mode 100644
index 0000000000..3182d6b4ab
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.1.qml
@@ -0,0 +1,12 @@
+import QtQuick 1.0
+
+Item {
+ property int changeCount: 0
+
+ property bool _nameWithUnderscore: false
+
+ // this should error, since the first alpha isn't capitalised.
+ on_nameWithUnderscoreChanged: {
+ changeCount = changeCount + 2;
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.2.qml b/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.2.qml
new file mode 100644
index 0000000000..50ef0b34dd
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.2.qml
@@ -0,0 +1,12 @@
+import QtQuick 1.0
+
+Item {
+ property int changeCount: 0
+
+ property bool ____nameWithUnderscores: false
+
+ // this should error, since the first alpha isn't capitalised
+ on____nameWithUnderscoresChanged: {
+ changeCount = changeCount + 3;
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.3.qml b/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.3.qml
new file mode 100644
index 0000000000..343cf91720
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.3.qml
@@ -0,0 +1,12 @@
+import QtQuick 1.0
+
+Item {
+ property int changeCount: 0
+
+ // invalid property name - we don't allow $
+ property bool $nameWithDollarsign: false
+
+ on$NameWithDollarsignChanged: {
+ changeCount = changeCount + 4;
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.4.qml b/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.4.qml
new file mode 100644
index 0000000000..b8459875df
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlotErrors.4.qml
@@ -0,0 +1,12 @@
+import QtQuick 1.0
+
+Item {
+ property int changeCount: 0
+
+ property bool _6nameWithUnderscoreNumber: false
+
+ // invalid property name - the first character after an underscore must be a letter
+ on_6NameWithUnderscoreNumberChanged: {
+ changeCount = changeCount + 3;
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlots.qml b/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlots.qml
new file mode 100644
index 0000000000..d31c89382b
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/changeslots/propertyChangeSlots.qml
@@ -0,0 +1,27 @@
+import QtQuick 1.0
+
+Item {
+ property int changeCount: 0
+
+ property bool normalName: false
+ property bool _nameWithUnderscore: false
+ property bool ____nameWithUnderscores: false
+
+ onNormalNameChanged: {
+ changeCount = changeCount + 1;
+ }
+
+ on_NameWithUnderscoreChanged: {
+ changeCount = changeCount + 2;
+ }
+
+ on____NameWithUnderscoresChanged: {
+ changeCount = changeCount + 3;
+ }
+
+ Component.onCompleted: {
+ normalName = true;
+ _nameWithUnderscore = true;
+ ____nameWithUnderscores = true;
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/SpecialRectangleOne.qml b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/SpecialRectangleOne.qml
new file mode 100644
index 0000000000..698b672259
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/SpecialRectangleOne.qml
@@ -0,0 +1,9 @@
+import QtQuick 1.0
+
+import "importPragmaLibrary.js" as TestPragmaLibraryImport
+
+Rectangle {
+ width: TestPragmaLibraryImport.importIncrementedValue()
+ height: width + 15
+ color: "red"
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/SpecialRectangleTwo.qml b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/SpecialRectangleTwo.qml
new file mode 100644
index 0000000000..581ae671e3
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/SpecialRectangleTwo.qml
@@ -0,0 +1,9 @@
+import QtQuick 1.0
+
+import "importPragmaLibrary.js" as TestPragmaLibraryImport
+
+Rectangle {
+ width: TestPragmaLibraryImport.importIncrementedValue()
+ height: width + 5
+ color: "blue"
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importFive.js b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importFive.js
new file mode 100644
index 0000000000..e458094552
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importFive.js
@@ -0,0 +1,3 @@
+function importFiveFunction() {
+ return '5';
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importFour.js b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importFour.js
new file mode 100644
index 0000000000..faddc15c9d
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importFour.js
@@ -0,0 +1,9 @@
+.pragma library
+
+function importFourFunction() {
+ return '4';
+}
+
+function greetingString() {
+ return 'Hello, World!';
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importOne.js b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importOne.js
new file mode 100644
index 0000000000..338c4e042f
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importOne.js
@@ -0,0 +1,13 @@
+.import "importTwo.js" as ImportTwoJs
+.import "importThree.js" as ImportThreeJs
+
+function greetingString() {
+ if (ImportTwoJs.greetingString().length > 0) {
+ return ImportTwoJs.greetingString();
+ }
+ return ImportThreeJs.greetingString();
+}
+
+function importOneFunction() {
+ return '1';
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importPragmaLibrary.js b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importPragmaLibrary.js
new file mode 100644
index 0000000000..c746fef14b
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importPragmaLibrary.js
@@ -0,0 +1,9 @@
+.pragma library
+
+var i = 4;
+
+// .pragma library, so should be callable from multiple .qml with shared i.
+function importIncrementedValue() {
+ i = i + 1;
+ return i;
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importThree.js b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importThree.js
new file mode 100644
index 0000000000..3917134ee2
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importThree.js
@@ -0,0 +1,9 @@
+.import "importFour.js" as ImportFourJs
+
+function greetingString() {
+ return ImportFourJs.greetingString();
+}
+
+function importThreeFunction() {
+ return '3';
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importTwo.js b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importTwo.js
new file mode 100644
index 0000000000..45b3c9a74d
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importTwo.js
@@ -0,0 +1,10 @@
+.import "importFour.js" as ImportFourJs
+.import "importFive.js" as ImportFiveJs
+
+function greetingString() {
+ return ImportFourJs.greetingString();
+}
+
+function importTwoFunction() {
+ return '2';
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importWithNoImports.js b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importWithNoImports.js
new file mode 100644
index 0000000000..83426c425c
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/importWithNoImports.js
@@ -0,0 +1,11 @@
+// This js file has no imports, and so should inherit
+// scope from the QML file which includes it.
+
+function componentError() {
+ var i = 5;
+ var errorIsOne = Component.error == 1;
+ if (errorIsOne == true) {
+ i = i + 7;
+ }
+ return i;
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/testImport.qml b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/testImport.qml
new file mode 100644
index 0000000000..4a284ad886
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/testImport.qml
@@ -0,0 +1,14 @@
+import QtQuick 1.0
+
+import "testScriptImport.js" as TestScriptImport
+import "testModuleImport.js" as TestModuleImport
+
+QtObject {
+ id: testQtObject
+
+ property string importedScriptStringValue: TestScriptImport.greetingText
+ property int importedScriptFunctionValue: TestScriptImport.randomInteger(1, 20)
+
+ property int importedModuleAttachedPropertyValue: TestModuleImport.importedAttachedPropertyValue(testQtObject)
+ property int importedModuleEnumValue: TestModuleImport.importedEnumValue
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/testImportPragmaLibrary.qml b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/testImportPragmaLibrary.qml
new file mode 100644
index 0000000000..7add311326
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/testImportPragmaLibrary.qml
@@ -0,0 +1,20 @@
+import QtQuick 1.0
+
+// We use the components specified in SpecialRectangleOne.qml and SpecialRectangleTwo.qml
+
+QtObject {
+ id: testQtObject
+
+ property SpecialRectangleOne a;
+ property SpecialRectangleTwo b;
+
+ a: SpecialRectangleOne {
+ id: rectangleOne
+ }
+ b: SpecialRectangleTwo {
+ id: rectangleTwo
+ }
+
+ // this should be: (5 + 15) + (6 + 5) == 31
+ property int testValue: rectangleOne.height + rectangleTwo.height
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/testImportScoping.qml b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/testImportScoping.qml
new file mode 100644
index 0000000000..0df841c78c
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/testImportScoping.qml
@@ -0,0 +1,11 @@
+import QtQuick 1.0
+
+// For backward compatibility, importing a script which has no imports,
+// should run the script in the parent context. See QTBUG-17518.
+
+import "importWithNoImports.js" as TestNoImportScoping
+
+QtObject {
+ id: testQtObject
+ property int componentError: TestNoImportScoping.componentError()
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/testModuleImport.js b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/testModuleImport.js
new file mode 100644
index 0000000000..69bc1c9887
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/testModuleImport.js
@@ -0,0 +1,8 @@
+.import Qt.test 1.0 as JsQtTest // test that we can import elements from .js files
+
+function importedAttachedPropertyValue(obj) {
+ return obj.JsQtTest.MyQmlObject.value; // attached property, value = 19.
+}
+
+var importedEnumValue = JsQtTest.MyQmlObject.EnumValue3 // the actual value of this enum value is "2"
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/testScriptImport.js b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/testScriptImport.js
new file mode 100644
index 0000000000..2ecccd8816
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimport/testScriptImport.js
@@ -0,0 +1,11 @@
+.import "importOne.js" as ImportOneJs // test that we can import scripts from .js files
+
+var greetingText = ImportOneJs.greetingString()
+
+function randomInteger(min, max) {
+ if (max > min) {
+ if (min > 10) return min;
+ return max;
+ }
+ return min;
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/failFive.qml b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/failFive.qml
new file mode 100644
index 0000000000..9bf969cc61
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/failFive.qml
@@ -0,0 +1,11 @@
+import QtQuick 1.0
+
+// This should fail, since if the script does have imports
+// of its own, it should run in its own context.
+
+import "importWithImports.js" as TestImportScoping
+
+QtObject {
+ id: testQtObject
+ property int componentError: TestImportScoping.componentError()
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/failFour.qml b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/failFour.qml
new file mode 100644
index 0000000000..fe7e88a829
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/failFour.qml
@@ -0,0 +1,7 @@
+import QtQuick 1.0
+
+import "testModuleImport.js" as TestModuleImport
+
+QtObject {
+ property int importedModuleEnumValue: JsQtTest.MyQmlObject.EnumValue3 // should fail - the typenames available in TestModuleImport should not be available in this scope
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/failOne.qml b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/failOne.qml
new file mode 100644
index 0000000000..e7fb7656f0
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/failOne.qml
@@ -0,0 +1,7 @@
+import QtQuick 1.0
+
+import "testScriptImport.js" as TestScriptImport
+
+QtObject {
+ property string importScriptFunctionValue: TestScriptImport.ImportOneJs.greetingString() // should fail - the context of TestScriptImport is private to TestScriptImport.
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/failThree.qml b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/failThree.qml
new file mode 100644
index 0000000000..fa720a64eb
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/failThree.qml
@@ -0,0 +1,8 @@
+import QtQuick 1.0
+
+import "testModuleImport.js" as TestModuleImport
+
+QtObject {
+ id: testQtObject
+ property int importedModuleAttachedPropertyValue: testQtObject.TestModuleImport.JsQtTest.MyQmlObject.value // should fail - the context of TestScriptImport is private to TestScriptImport.
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/failTwo.qml b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/failTwo.qml
new file mode 100644
index 0000000000..c2cbce9f80
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/failTwo.qml
@@ -0,0 +1,7 @@
+import QtQuick 1.0
+
+import "testScriptImport.js" as TestScriptImport
+
+QtObject {
+ property string importScriptFunctionValue: ImportOneJs.greetingString() // should fail - the typenames in TestScriptImport should not be visible from this scope
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/importOne.js b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/importOne.js
new file mode 100644
index 0000000000..45fd9c75dd
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/importOne.js
@@ -0,0 +1,7 @@
+function greetingString() {
+ return 'Hello, World!';
+}
+
+function importOneFunction() {
+ return '1';
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/importPragmaLibrary.js b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/importPragmaLibrary.js
new file mode 100644
index 0000000000..ad0e6946a2
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/importPragmaLibrary.js
@@ -0,0 +1,11 @@
+.pragma library
+
+// .pragma library, so shouldn't inherit imports from any .qml file.
+function importValue() {
+ var i = 3;
+ var errorIsOne = Component.error == 1; // this line should fail.
+ if (errorIsOne == true) {
+ i = i + 4;
+ }
+ return i;
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/importWithImports.js b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/importWithImports.js
new file mode 100644
index 0000000000..6d77ceccb1
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/importWithImports.js
@@ -0,0 +1,13 @@
+.import "importOne.js" as ImportOne
+
+// This js file has imports, so should not inherit
+// scope from the QML file which includes it.
+
+function componentError() {
+ var i = 3;
+ var errorIsOne = Component.error == 1; // this line should fail.
+ if (errorIsOne == true) {
+ i = i + 4;
+ }
+ return i;
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/testImportPragmaLibrary.qml b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/testImportPragmaLibrary.qml
new file mode 100644
index 0000000000..7e4a73ae42
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/testImportPragmaLibrary.qml
@@ -0,0 +1,8 @@
+import QtQuick 1.0
+
+import "importPragmaLibrary.js" as ImportPragmaLibrary
+
+QtObject {
+ id: testQtObject
+ property int testValue: ImportPragmaLibrary.importValue()
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/testModuleImport.js b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/testModuleImport.js
new file mode 100644
index 0000000000..69bc1c9887
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/testModuleImport.js
@@ -0,0 +1,8 @@
+.import Qt.test 1.0 as JsQtTest // test that we can import elements from .js files
+
+function importedAttachedPropertyValue(obj) {
+ return obj.JsQtTest.MyQmlObject.value; // attached property, value = 19.
+}
+
+var importedEnumValue = JsQtTest.MyQmlObject.EnumValue3 // the actual value of this enum value is "2"
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/testScriptImport.js b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/testScriptImport.js
new file mode 100644
index 0000000000..2ecccd8816
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/jsimportfail/testScriptImport.js
@@ -0,0 +1,11 @@
+.import "importOne.js" as ImportOneJs // test that we can import scripts from .js files
+
+var greetingText = ImportOneJs.greetingString()
+
+function randomInteger(min, max) {
+ if (max > min) {
+ if (min > 10) return min;
+ return max;
+ }
+ return min;
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/moduleApi.qml b/tests/auto/declarative/qdeclarativeecmascript/data/moduleApi.qml
new file mode 100644
index 0000000000..23c1eb0bb8
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/moduleApi.qml
@@ -0,0 +1,23 @@
+import QtQuick 1.0
+
+import Qt.test 1.0 as QtTest // module API installed into existing uri
+import Qt.test.scriptApi 1.0 as QtTestScriptApi // script module API installed into new uri
+import Qt.test.qobjectApi 1.0 as QtTestQObjectApi // qobject module API installed into new uri
+import Qt.test.qobjectApi 1.3 as QtTestMinorVersionQObjectApi // qobject module API installed into existing uri with new minor version
+import Qt.test.qobjectApi 2.0 as QtTestMajorVersionQObjectApi // qobject module API installed into existing uri with new major version
+import Qt.test.qobjectApiParented 1.0 as QtTestParentedQObjectApi // qobject (with parent) module API installed into a new uri
+
+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/data/moduleApiCaching.qml b/tests/auto/declarative/qdeclarativeecmascript/data/moduleApiCaching.qml
new file mode 100644
index 0000000000..9cee8c3065
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/moduleApiCaching.qml
@@ -0,0 +1,12 @@
+import QtQuick 1.0
+
+import Qt.test 1.0 as QtTest // module API installed into existing uri
+import Qt.test.scriptApi 1.0 as QtTestScriptApi // script module API installed into new uri
+import Qt.test.qobjectApiParented 1.0 as QtTestParentedQObjectApi // qobject (with parent) module API installed into a new uri
+
+QtObject {
+ property int existingUriTest: QtTest.qobjectTestProperty
+ property int scriptTest: QtTestScriptApi.scriptTestProperty
+ property int qobjectParentedTest: QtTestParentedQObjectApi.qobjectTestProperty
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/moduleApiMajorVersionFail.qml b/tests/auto/declarative/qdeclarativeecmascript/data/moduleApiMajorVersionFail.qml
new file mode 100644
index 0000000000..eca29ab2cf
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/moduleApiMajorVersionFail.qml
@@ -0,0 +1,10 @@
+import QtQuick 1.0
+
+// this qml file attempts to import an invalid version of a qobject module API.
+
+import Qt.test.qobjectApi 4.0 as QtTestMajorVersionQObjectApi // qobject module API installed into existing uri with nonexistent major version
+
+QtObject {
+ property int qobjectMajorVersionTest: QtTestMajorVersionQObjectApi.qobjectTestProperty
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/moduleApiMinorVersionFail.qml b/tests/auto/declarative/qdeclarativeecmascript/data/moduleApiMinorVersionFail.qml
new file mode 100644
index 0000000000..e360bd1668
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/moduleApiMinorVersionFail.qml
@@ -0,0 +1,10 @@
+import QtQuick 1.0
+
+// this qml file attempts to import an invalid version of a qobject module API.
+
+import Qt.test.qobjectApi 1.2 as QtTestMinorVersionQObjectApi // qobject module API installed into existing uri with nonexistent minor version
+
+QtObject {
+ property int qobjectMinorVersionTest: QtTestMinorVersionedQObjectApi.qobjectTestProperty
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/moduleApiWriting.qml b/tests/auto/declarative/qdeclarativeecmascript/data/moduleApiWriting.qml
new file mode 100644
index 0000000000..90a674681c
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/moduleApiWriting.qml
@@ -0,0 +1,27 @@
+import QtQuick 1.0
+
+import Qt.test 1.0 as QtTest // module API installed into existing uri
+
+QtObject {
+ property int firstProperty: 1
+ property int secondProperty: 2
+ property int readOnlyProperty: QtTest.qobjectTestProperty
+ property int writableProperty: QtTest.qobjectTestWritableProperty
+
+ onFirstPropertyChanged: {
+ // In this case, we want to attempt to set the module API property.
+ // This should fail, as the module API property is read only.
+ if (firstProperty != QtTest.qobjectTestProperty) {
+ QtTest.qobjectTestProperty = firstProperty; // should silently fail.
+ }
+ }
+
+ onSecondPropertyChanged: {
+ // In this case, we want to attempt to set the module API property.
+ // This should succeed, as the module API property is writable.
+ if (secondProperty != QtTest.qobjectTestWritableProperty) {
+ QtTest.qobjectTestWritableProperty = secondProperty; // should succeed.
+ }
+ }
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/realToInt.qml b/tests/auto/declarative/qdeclarativeecmascript/data/realToInt.qml
new file mode 100644
index 0000000000..cbbbbf921a
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/realToInt.qml
@@ -0,0 +1,11 @@
+import QtQuick 1.0
+import Qt.test 1.0
+
+MyQmlObject {
+ function test1() {
+ value = 4.2
+ }
+ function test2() {
+ value = 7.9
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/ScarceResourceSignalComponent.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/ScarceResourceSignalComponent.qml
new file mode 100644
index 0000000000..fb40bdc2de
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/ScarceResourceSignalComponent.qml
@@ -0,0 +1,9 @@
+import QtQuick 1.0
+
+QtObject {
+ property variant scarceResourceCopy
+ property int width: 5
+ signal testSignal
+ signal testSignal2
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopy.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopy.qml
new file mode 100644
index 0000000000..82184354d8
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopy.qml
@@ -0,0 +1,15 @@
+import QtQuick 1.0
+import Qt.test 1.0
+
+// Here we import a scarce resource directly.
+// The instance has a property which is a copy
+// of the scarce resource, so it should not be
+// detached (but we should automatically release
+// the resource from our engine internal list).
+
+QtObject {
+ property MyScarceResourceObject a;
+ a: MyScarceResourceObject { id: scarceResourceProvider }
+ property variant scarceResourceCopy: scarceResourceProvider.scarceResource
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyFromJs.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyFromJs.qml
new file mode 100644
index 0000000000..60c26ac4f2
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyFromJs.qml
@@ -0,0 +1,15 @@
+import QtQuick 1.0
+import Qt.test 1.0
+import "scarceResourceTest.js" as ScarceResourceProviderJs
+
+// Here we import a scarce resource directly, from JS module.
+// It is not preserved or released manually, so it should be
+// automatically released once evaluation of the binding
+// is complete.
+
+QtObject {
+ property MyScarceResourceObject a;
+ a: MyScarceResourceObject { id: scarceResourceProvider }
+ property variant scarceResourceCopy: ScarceResourceProviderJs.importScarceResource(scarceResourceProvider)
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImport.js b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImport.js
new file mode 100644
index 0000000000..bacc50dcc9
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImport.js
@@ -0,0 +1,24 @@
+.import Qt.test 1.0 as JsQtTest
+
+// In this case, the "retn" variable will be evaluated during import.
+// Since the "importScarceResource()" function depends on this variable,
+// we must explicitly preserve the "retn" variable or the scarce
+// resource would automatically be released after import completes
+// but before the binding is evaluated.
+
+var component = Qt.createComponent("scarceResourceCopy.qml");
+var scarceResourceElement = component.createObject(null);
+var scarceResourceProvider = scarceResourceElement.a;
+var retn = scarceResourceProvider.scarceResource;
+retn.preserve(); // must preserve manually or it will be released!
+
+function importScarceResource() {
+ // if called prior to calling destroyScarceResource(),
+ // this function should return the preserved scarce resource.
+ // otherwise, it should return an invalid variant.
+ return retn;
+}
+
+function destroyScarceResource() {
+ retn.destroy();
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImport.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImport.qml
new file mode 100644
index 0000000000..0513b0840e
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImport.qml
@@ -0,0 +1,18 @@
+import QtQuick 1.0
+import Qt.test 1.0
+import "scarceResourceCopyImport.js" as ScarceResourceCopyImportJs
+
+QtObject {
+ // this binding is evaluated once, prior to the resource being released
+ property variant scarceResourceCopy: ScarceResourceCopyImportJs.importScarceResource()
+
+ // this code is evaluated on completion, and so copy one should be valid, copy two invalid.
+ property variant scarceResourceAssignedCopyOne;
+ property variant scarceResourceAssignedCopyTwo;
+ Component.onCompleted: {
+ scarceResourceAssignedCopyOne = ScarceResourceCopyImportJs.importScarceResource();
+ ScarceResourceCopyImportJs.destroyScarceResource();
+ scarceResourceAssignedCopyTwo = ScarceResourceCopyImportJs.importScarceResource();
+ }
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImportFail.js b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImportFail.js
new file mode 100644
index 0000000000..6c495863b5
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImportFail.js
@@ -0,0 +1,18 @@
+.import Qt.test 1.0 as JsQtTest
+
+// In this case, the "retn" variable will be evaluated during import.
+// Since the importScarceResource() function depends on this variable,
+// because we DO NOT call "retn.preserve()", the scarce resource will
+// be released after the import completes but prior to evaluation of
+// any binding which calls "importScarceResource()".
+// Thus, "importScarceResource()" will return a released (invalid)
+// scarce resource.
+
+var component = Qt.createComponent("scarceResourceCopy.qml");
+var scarceResourceElement = component.createObject(null);
+var scarceResourceProvider = scarceResourceElement.a;
+var retn = scarceResourceProvider.scarceResource;
+
+function importScarceResource() {
+ return retn; // should return a released (invalid) scarce resource
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImportFail.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImportFail.qml
new file mode 100644
index 0000000000..d3c4d4ed65
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImportFail.qml
@@ -0,0 +1,8 @@
+import QtQuick 1.0
+import Qt.test 1.0
+import "scarceResourceCopyImportFail.js" as ScarceResourceCopyImportFailJs
+
+QtObject {
+ property variant scarceResourceCopy: ScarceResourceCopyImportFailJs.importScarceResource()
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImportNoBinding.js b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImportNoBinding.js
new file mode 100644
index 0000000000..4a5b6b4427
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImportNoBinding.js
@@ -0,0 +1,14 @@
+.import Qt.test 1.0 as JsQtTest
+
+// In this case, the "retn" variable will be evaluated during import.
+// Since the importScarceResource() function depends on this variable,
+// because we DO NOT call "retn.preserve()", the scarce resource will
+// be released after the import completes but prior to evaluation of
+// any binding which calls "importScarceResource()".
+// Thus, "importScarceResource()" will return a released (invalid)
+// scarce resource.
+
+var component = Qt.createComponent("scarceResourceCopyNoBinding.qml");
+var scarceResourceElement = component.createObject(null);
+var scarceResourceProvider = scarceResourceElement.a;
+var retn = scarceResourceProvider.scarceResource;
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImportNoBinding.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImportNoBinding.qml
new file mode 100644
index 0000000000..72cd4dac8a
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyImportNoBinding.qml
@@ -0,0 +1,12 @@
+import QtQuick 1.0
+import Qt.test 1.0
+
+// the following js import doesn't manually preserve or destroy any resources
+import "scarceResourceCopyImportNoBinding.js" as ScarceResourceCopyImportNoBindingJs
+
+QtObject {
+ // in this case, there is an import but no binding evaluated.
+ // nonetheless, any resources which are not preserved, should
+ // be automatically released by the engine.
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyNoBinding.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyNoBinding.qml
new file mode 100644
index 0000000000..681a382427
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceCopyNoBinding.qml
@@ -0,0 +1,14 @@
+import QtQuick 1.0
+import Qt.test 1.0
+
+QtObject {
+ // this component doesn't bind any property to a scarce
+ // resource from the scarce resource provider,
+ // so the binding evaluation resource cleanup
+ // codepath shouldn't be activated; so if the resources
+ // are released, it will be due to the import evaluation
+ // resource cleanup codepath being activated correctly.
+ property MyScarceResourceObject a;
+ a: MyScarceResourceObject { id: scarceResourceProvider }
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceDestroyedCopy.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceDestroyedCopy.qml
new file mode 100644
index 0000000000..87ceda9d7a
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceDestroyedCopy.qml
@@ -0,0 +1,14 @@
+import QtQuick 1.0
+import Qt.test 1.0
+import "scarceResourceTest.js" as ScarceResourceProviderJs
+
+// In this case, following the evaluation of the binding,
+// the scarceResourceTest value should be an invalid variant,
+// since the scarce resource will have been released.
+
+QtObject {
+ property MyScarceResourceObject a;
+ a: MyScarceResourceObject { id: scarceResourceProvider }
+ property variant scarceResourceCopy: ScarceResourceProviderJs.importReleasedScarceResource(scarceResourceProvider);
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceFunction.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceFunction.qml
new file mode 100644
index 0000000000..e3e7aed9ee
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceFunction.qml
@@ -0,0 +1,23 @@
+import QtQuick 1.0
+import Qt.test 1.0
+
+// Here we import a scarce resource directly.
+// The copy is only assigned when retrieveScarceResource()
+// is called, and so should be detached prior to that.
+// The copy should be released when releaseScarceResource()
+// is called, and so should be detached after that.
+
+QtObject {
+ id: root
+ property MyScarceResourceObject a: MyScarceResourceObject { id: scarceResourceProvider }
+ property variant scarceResourceCopy;
+
+ function retrieveScarceResource() {
+ root.scarceResourceCopy = scarceResourceProvider.scarceResource;
+ }
+
+ function releaseScarceResource() {
+ root.scarceResourceCopy = null;
+ }
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceFunctionFail.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceFunctionFail.qml
new file mode 100644
index 0000000000..b1342fea90
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceFunctionFail.qml
@@ -0,0 +1,23 @@
+import QtQuick 1.0
+import Qt.test 1.0
+
+// In this example, a common syntax error will only be "caught"
+// when the function is called via:
+// QDeclarativeVMEMetaObject::metaCall->invokeMetaMethod()
+// We would like to ensure that a useful error message is printed,
+// rather than having QScriptValue::call() function fail silently.
+
+QtObject {
+ id: root
+ property MyScarceResourceObject a: MyScarceResourceObject { id: scarceResourceProvider }
+ property variant scarceResourceCopy;
+
+ function retrieveScarceResource() {
+ root.scarceResourceCopy = scarceResourceProvider.scarceResource(); // common syntax error, should throw exception
+ }
+
+ function releaseScarceResource() {
+ root.scarceResourceCopy = null;
+ }
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceSignal.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceSignal.qml
new file mode 100644
index 0000000000..9c920b1aa0
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceSignal.qml
@@ -0,0 +1,29 @@
+import QtQuick 1.0
+import Qt.test 1.0
+
+QtObject {
+ id: root
+
+ property MyScarceResourceObject a;
+ a: MyScarceResourceObject { id: scarceResourceProvider }
+
+ property ScarceResourceSignalComponent b;
+ b: ScarceResourceSignalComponent {
+ objectName: "srsc"
+
+ onTestSignal: {
+ // this signal will be invoked manually in the test.
+ // the scarce resource should be released automatically after evaluation
+ // and since we don't keep a copy of it, the pixmap will be detached.
+ width = (scarceResourceProvider.scarceResource,10)
+ }
+
+ onTestSignal2: {
+ // this signal will be invoked manually in the test.
+ // the scarce resource should be released automatically after evaluation
+ // but since we assign it to a property, the pixmap won't be detached.
+ scarceResourceCopy = scarceResourceProvider.scarceResource
+ }
+ }
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceTest.js b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceTest.js
new file mode 100644
index 0000000000..c904eb3564
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceTest.js
@@ -0,0 +1,48 @@
+.import Qt.test 1.0 as JsQtTest
+
+function importScarceResource(scarceResourceProvider) {
+ // the scarce resource should be automatically released
+ // after the binding is evaluated if preserve is not
+ // called.
+ return scarceResourceProvider.scarceResource;
+}
+
+function importPreservedScarceResource(scarceResourceProvider) {
+ // the scarce resource is manually preserved
+ // during the evaluation of the binding.
+ // it should not be released.
+ var scarceResource = scarceResourceProvider.scarceResource;
+ scarceResource.preserve();
+ return scarceResource;
+}
+
+function importReleasedScarceResource(scarceResourceProvider) {
+ // release the scarce resource during the
+ // evaluation of the binding. The returned
+ // variant will therefore be invalid.
+ var scarceResource = scarceResourceProvider.scarceResource;
+ scarceResource.destroy();
+ return scarceResource;
+}
+
+function importPreservedScarceResourceFromMultiple(scarceResourceProvider) {
+ // some scarce resources are manually preserved,
+ // some of them are manually destroyed,
+ // and some are automatically managed.
+ // We return a preserved resource
+ var sr1 = scarceResourceProvider.scarceResource; // preserved/destroyed.
+ sr1.preserve();
+ var sr2 = scarceResourceProvider.scarceResource; // preserved/destroyed
+ sr2.preserve();
+ var sr3 = scarceResourceProvider.scarceResource; // automatic.
+ var sr4 = scarceResourceProvider.scarceResource; // automatic and returned.
+ var sr5 = scarceResourceProvider.scarceResource; // destroyed
+ sr5.destroy();
+ sr2.destroy();
+ var sr6 = scarceResourceProvider.scarceResource; // destroyed
+ var sr7 = scarceResourceProvider.scarceResource; // automatic
+ sr1.destroy();
+ sr6.destroy();
+ return sr4;
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceTest.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceTest.qml
new file mode 100644
index 0000000000..3775172c04
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceTest.qml
@@ -0,0 +1,14 @@
+import QtQuick 1.0
+import Qt.test 1.0
+
+// Here we import a scarce resource directly, and use it in a binding.
+// It is not preserved or released manually, so it should be
+// automatically released once evaluation of the binding
+// is complete.
+
+QtObject {
+ property MyScarceResourceObject a;
+ a: MyScarceResourceObject { id: scarceResourceProvider }
+ property int scarceResourceTest: scarceResourceProvider.scarceResource,100 // return 100, but include the scarceResource in the binding to be evaluated.
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceTestMultiple.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceTestMultiple.qml
new file mode 100644
index 0000000000..3139382b05
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceTestMultiple.qml
@@ -0,0 +1,16 @@
+import QtQuick 1.0
+import Qt.test 1.0
+import "scarceResourceTest.js" as ScarceResourceProviderJs
+
+// In this case, multiple scarce resource are explicity preserved
+// and then explicitly destroyed, while others are automatically
+// managed. Since none are manually preserved without subsequently
+// being destroyed, after the evaluation of the binding the
+// scarce resource should be detached.
+
+QtObject {
+ property MyScarceResourceObject a;
+ a: MyScarceResourceObject { id: scarceResourceProvider }
+ property int scarceResourceTest: ScarceResourceProviderJs.importPreservedScarceResourceFromMultiple(scarceResourceProvider), 100
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceTestPreserve.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceTestPreserve.qml
new file mode 100644
index 0000000000..d810377a51
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scarceresources/scarceResourceTestPreserve.qml
@@ -0,0 +1,15 @@
+import QtQuick 1.0
+import Qt.test 1.0
+import "scarceResourceTest.js" as ScarceResourceProviderJs
+
+// In this case, the scarce resource is explicity preserved.
+// It should not be automatically released after the evaluation
+// of the binding is complete, but instead will be kept in
+// memory until the JS garbage collector runs.
+
+QtObject {
+ property MyScarceResourceObject a;
+ a: MyScarceResourceObject { id: scarceResourceProvider }
+ property int scarceResourceTest: ScarceResourceProviderJs.importPreservedScarceResource(scarceResourceProvider),100 // return 100, but the resource should be preserved.
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scope.5.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scope.5.qml
new file mode 100644
index 0000000000..405746c459
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scope.5.qml
@@ -0,0 +1,27 @@
+import QtQuick 1.0
+
+Item {
+ property bool test1: false;
+ property bool test2: false;
+
+ property int a: 10
+
+ Item {
+ id: nested
+ property int a: 11
+
+ function mynestedfunction() {
+ return a;
+ }
+ }
+
+ function myouterfunction() {
+ return a;
+ }
+
+ Component.onCompleted: {
+ test1 = (myouterfunction() == 10);
+ test2 = (nested.mynestedfunction() == 11);
+ }
+}
+
diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/scope.6.qml b/tests/auto/declarative/qdeclarativeecmascript/data/scope.6.qml
new file mode 100644
index 0000000000..1c81e4e945
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeecmascript/data/scope.6.qml
@@ -0,0 +1,10 @@
+import QtQuick 1.0
+
+Item {
+ id: me
+ property bool test: nested.runtest(me);
+
+ Scope6Nested {
+ id: nested
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/qdeclarativeecmascript.pro b/tests/auto/declarative/qdeclarativeecmascript/qdeclarativeecmascript.pro
index 69d25a4292..03834ed428 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/qdeclarativeecmascript.pro
+++ b/tests/auto/declarative/qdeclarativeecmascript/qdeclarativeecmascript.pro
@@ -22,3 +22,4 @@ symbian: {
CONFIG += parallel_test
+QT += core-private gui-private declarative-private script-private
diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp b/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp
index 07f5ba706c..ea8d2c01c7 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.cpp
@@ -41,6 +41,8 @@
#include "testtypes.h"
#include <QWidget>
#include <QPlainTextEdit>
+#include <QDeclarativeEngine>
+#include <QScriptEngine>
class BaseExtensionObject : public QObject
{
@@ -99,6 +101,36 @@ public:
void setWidth(int) { }
};
+static QScriptValue script_api(QDeclarativeEngine *engine, QScriptEngine *scriptEngine)
+{
+ Q_UNUSED(engine)
+
+ static int testProperty = 13;
+ QScriptValue v = scriptEngine->newObject();
+ v.setProperty("scriptTestProperty", testProperty++);
+ return v;
+}
+
+static QObject *qobject_api(QDeclarativeEngine *engine, QScriptEngine *scriptEngine)
+{
+ Q_UNUSED(engine)
+ Q_UNUSED(scriptEngine)
+
+ testQObjectApi *o = new testQObjectApi();
+ o->setQObjectTestProperty(20);
+ o->setQObjectTestWritableProperty(50);
+ return o;
+}
+
+static QObject *qobject_api_engine_parent(QDeclarativeEngine *engine, QScriptEngine *scriptEngine)
+{
+ Q_UNUSED(scriptEngine)
+
+ static int testProperty = 26;
+ testQObjectApi *o = new testQObjectApi(engine);
+ o->setQObjectTestProperty(testProperty++);
+ return o;
+}
void registerTypes()
{
@@ -116,6 +148,9 @@ void registerTypes()
qmlRegisterType<MyRevisionedClass>("Qt.test",1,0,"MyRevisionedClass");
qmlRegisterType<MyRevisionedClass,1>("Qt.test",1,1,"MyRevisionedClass");
+ // test scarce resource property binding post-evaluation optimisation
+ qmlRegisterType<ScarceResourceObject>("Qt.test", 1,0, "MyScarceResourceObject");
+
// Register the uncreatable base class
qmlRegisterRevision<MyRevisionedBaseClassRegistered,1>("Qt.test",1,1);
// MyRevisionedSubclass 1.0 uses MyRevisionedClass revision 0
@@ -127,6 +162,15 @@ void registerTypes()
qmlRegisterType<QPlainTextEdit>("Qt.test",1,0,"QPlainTextEdit");
qRegisterMetaType<MyQmlObject::MyType>("MyQmlObject::MyType");
+
+ qmlRegisterModuleApi("Qt.test",1,0,script_api); // register (script) module API for an existing uri which contains elements
+ qmlRegisterModuleApi("Qt.test",1,0,qobject_api); // register (qobject) for an existing uri for which another module API was previously regd. Should replace!
+ qmlRegisterModuleApi("Qt.test.scriptApi",1,0,script_api); // register (script) module API for a uri which doesn't contain elements
+ qmlRegisterModuleApi("Qt.test.qobjectApi",1,0,qobject_api); // register (qobject) module API for a uri which doesn't contain elements
+ qmlRegisterModuleApi("Qt.test.qobjectApi",1,3,qobject_api); // register (qobject) module API for a uri which doesn't contain elements, minor version set
+ qmlRegisterModuleApi("Qt.test.qobjectApi",2,0,qobject_api); // register (qobject) module API for a uri which doesn't contain elements, major version set
+ qmlRegisterModuleApi("Qt.test.qobjectApiParented",1,0,qobject_api_engine_parent); // register (parented qobject) module API for a uri which doesn't contain elements
+
qRegisterMetaType<MyQmlObject::MyType>("MyEnum2");
qRegisterMetaType<Qt::MouseButtons>("Qt::MouseButtons");
}
diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h
index 36572e24c3..aebfb22b7c 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h
+++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h
@@ -51,6 +51,7 @@
#include <QtGui/qmatrix.h>
#include <QtGui/qcolor.h>
#include <QtGui/qvector3d.h>
+#include <QtGui/QPixmap>
#include <QtCore/qdatetime.h>
#include <QtScript/qscriptvalue.h>
#include <QtDeclarative/qdeclarativescriptstring.h>
@@ -909,6 +910,59 @@ QML_DECLARE_TYPE(MyRevisionedClass)
QML_DECLARE_TYPE(MyRevisionedSubclass)
Q_DECLARE_METATYPE(MyQmlObject::MyType)
+
+class ScarceResourceObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QPixmap scarceResource READ scarceResource WRITE setScarceResource NOTIFY scarceResourceChanged)
+public:
+ ScarceResourceObject(QObject *parent = 0) : QObject(parent), m_value(100, 100) { m_value.fill(Qt::blue); }
+ ~ScarceResourceObject() {}
+
+ QPixmap scarceResource() const { return m_value; }
+ void setScarceResource(QPixmap v) { m_value = v; emit scarceResourceChanged(); }
+
+ bool scarceResourceIsDetached() const { return m_value.isDetached(); }
+
+signals:
+ void scarceResourceChanged();
+
+private:
+ QPixmap m_value;
+};
+
+class testQObjectApi : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY (int qobjectTestProperty READ qobjectTestProperty NOTIFY qobjectTestPropertyChanged)
+ Q_PROPERTY (int qobjectTestWritableProperty READ qobjectTestWritableProperty WRITE setQObjectTestWritableProperty NOTIFY qobjectTestWritablePropertyChanged)
+
+public:
+ testQObjectApi(QObject* parent = 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); }
+
+ int qobjectTestWritableProperty() const { return m_testWritableProperty; }
+ void setQObjectTestWritableProperty(int tp) { m_testWritableProperty = tp; emit qobjectTestWritablePropertyChanged(tp); }
+
+signals:
+ void qobjectTestPropertyChanged(int testProperty);
+ void qobjectTestWritablePropertyChanged(int testWritableProperty);
+
+private:
+ int m_testProperty;
+ int m_testWritableProperty;
+ int m_methodCallCount;
+};
+
void registerTypes();
#endif // TESTTYPES_H
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
index 8df18738ae..cabaddeeb7 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
@@ -144,6 +144,10 @@ private slots:
void numberAssignment();
void propertySplicing();
void signalWithUnknownTypes();
+ void moduleApi();
+ void importScripts();
+ void scarceResources();
+ void propertyChangeSlots();
void bug1();
void bug2();
@@ -176,6 +180,7 @@ private slots:
void aliasBindingsOverrideTarget();
void aliasWritesOverrideBindings();
void pushCleanContext();
+ void realToInt();
void include();
@@ -260,6 +265,7 @@ void tst_qdeclarativeecmascript::idShortcutInvalidates()
QVERIFY(object->objectProperty() != 0);
delete object->objectProperty();
QVERIFY(object->objectProperty() == 0);
+ delete object;
}
{
@@ -269,6 +275,7 @@ void tst_qdeclarativeecmascript::idShortcutInvalidates()
QVERIFY(object->objectProperty() != 0);
delete object->objectProperty();
QVERIFY(object->objectProperty() == 0);
+ delete object;
}
}
@@ -279,12 +286,14 @@ void tst_qdeclarativeecmascript::boolPropertiesEvaluateAsBool()
MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
QVERIFY(object != 0);
QCOMPARE(object->stringProperty(), QLatin1String("pass"));
+ delete object;
}
{
QDeclarativeComponent component(&engine, TEST_FILE("boolPropertiesEvaluateAsBool.2.qml"));
MyQmlObject *object = qobject_cast<MyQmlObject *>(component.create());
QVERIFY(object != 0);
QCOMPARE(object->stringProperty(), QLatin1String("pass"));
+ delete object;
}
}
@@ -297,6 +306,7 @@ void tst_qdeclarativeecmascript::signalAssignment()
QCOMPARE(object->string(), QString());
emit object->basicSignal();
QCOMPARE(object->string(), QString("pass"));
+ delete object;
}
{
@@ -306,6 +316,7 @@ void tst_qdeclarativeecmascript::signalAssignment()
QCOMPARE(object->string(), QString());
emit object->argumentSignal(19, "Hello world!", 10.25, MyQmlObject::EnumValue4, Qt::RightButton);
QCOMPARE(object->string(), QString("pass 19 Hello world! 10.25 3 2"));
+ delete object;
}
}
@@ -320,6 +331,7 @@ void tst_qdeclarativeecmascript::methods()
emit object->basicSignal();
QCOMPARE(object->methodCalled(), true);
QCOMPARE(object->methodIntCalled(), false);
+ delete object;
}
{
@@ -331,6 +343,7 @@ void tst_qdeclarativeecmascript::methods()
emit object->basicSignal();
QCOMPARE(object->methodCalled(), false);
QCOMPARE(object->methodIntCalled(), true);
+ delete object;
}
{
@@ -338,6 +351,7 @@ void tst_qdeclarativeecmascript::methods()
QObject *object = component.create();
QVERIFY(object != 0);
QCOMPARE(object->property("test").toInt(), 19);
+ delete object;
}
{
@@ -347,6 +361,7 @@ void tst_qdeclarativeecmascript::methods()
QCOMPARE(object->property("test").toInt(), 19);
QCOMPARE(object->property("test2").toInt(), 17);
QCOMPARE(object->property("test3").toInt(), 16);
+ delete object;
}
{
@@ -354,6 +369,7 @@ void tst_qdeclarativeecmascript::methods()
QObject *object = component.create();
QVERIFY(object != 0);
QCOMPARE(object->property("test").toInt(), 9);
+ delete object;
}
}
@@ -364,6 +380,7 @@ void tst_qdeclarativeecmascript::bindingLoop()
QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData());
QObject *object = component.create();
QVERIFY(object != 0);
+ delete object;
}
void tst_qdeclarativeecmascript::basicExpressions_data()
@@ -508,6 +525,7 @@ void tst_qdeclarativeecmascript::contextPropertiesTriggerReeval()
QCOMPARE(expr.evaluate(), QVariant::fromValue((QObject *)object3));
}
+ delete object3;
}
void tst_qdeclarativeecmascript::objectPropertiesTriggerReeval()
@@ -582,6 +600,8 @@ void tst_qdeclarativeecmascript::deferredProperties()
QCOMPARE(qmlObject->value(), 10);
object->setValue(19);
QCOMPARE(qmlObject->value(), 19);
+
+ delete object;
}
// Check errors on deferred properties are correctly emitted
@@ -625,6 +645,7 @@ void tst_qdeclarativeecmascript::extensionObjects()
QCOMPARE(nested->coreProperty(), 11);
QCOMPARE(nested->baseProperty(), 92);
+ delete object;
}
void tst_qdeclarativeecmascript::overrideExtensionProperties()
@@ -635,6 +656,8 @@ void tst_qdeclarativeecmascript::overrideExtensionProperties()
QVERIFY(object != 0);
QVERIFY(object->secondProperty() != 0);
QVERIFY(object->firstProperty() == 0);
+
+ delete object;
}
void tst_qdeclarativeecmascript::attachedProperties()
@@ -647,6 +670,7 @@ void tst_qdeclarativeecmascript::attachedProperties()
QCOMPARE(object->property("b").toInt(), 19);
QCOMPARE(object->property("c").toInt(), 19);
QCOMPARE(object->property("d").toInt(), 19);
+ delete object;
}
{
@@ -671,6 +695,7 @@ void tst_qdeclarativeecmascript::attachedProperties()
QVERIFY(attached != 0);
QCOMPARE(attached->value2(), 9);
+ delete object;
}
}
@@ -692,6 +717,8 @@ void tst_qdeclarativeecmascript::enums()
QCOMPARE(object->property("h").toInt(), 3);
QCOMPARE(object->property("i").toInt(), 19);
QCOMPARE(object->property("j").toInt(), 19);
+
+ delete object;
}
// Non-existent enums
{
@@ -706,6 +733,8 @@ void tst_qdeclarativeecmascript::enums()
QVERIFY(object != 0);
QCOMPARE(object->property("a").toInt(), 0);
QCOMPARE(object->property("b").toInt(), 0);
+
+ delete object;
}
}
@@ -716,6 +745,8 @@ void tst_qdeclarativeecmascript::valueTypeFunctions()
QVERIFY(obj != 0);
QCOMPARE(obj->rectProperty(), QRect(0,0,100,100));
QCOMPARE(obj->rectFProperty(), QRectF(0,0.5,100,99.5));
+
+ delete obj;
}
/*
@@ -739,6 +770,8 @@ void tst_qdeclarativeecmascript::constantsOverrideBindings()
QCOMPARE(object->property("c2").toInt(), 13);
object->setProperty("c1", QVariant(8));
QCOMPARE(object->property("c2").toInt(), 13);
+
+ delete object;
}
// During construction
@@ -752,6 +785,8 @@ void tst_qdeclarativeecmascript::constantsOverrideBindings()
object->setProperty("c1", QVariant(9));
QCOMPARE(object->property("c1").toInt(), 9);
QCOMPARE(object->property("c2").toInt(), 10);
+
+ delete object;
}
#if 0
@@ -770,6 +805,8 @@ void tst_qdeclarativeecmascript::constantsOverrideBindings()
object->setProperty("c1", QVariant(7));
QCOMPARE(object->property("c1").toInt(), 7);
QCOMPARE(object->property("c2").toInt(), 13);
+
+ delete object;
}
#endif
@@ -784,6 +821,8 @@ void tst_qdeclarativeecmascript::constantsOverrideBindings()
object->setProperty("c1", QVariant(9));
QCOMPARE(object->property("c1").toInt(), 9);
QCOMPARE(object->property("c3").toInt(), 10);
+
+ delete object;
}
}
@@ -811,6 +850,8 @@ void tst_qdeclarativeecmascript::outerBindingOverridesInnerBinding()
QCOMPARE(object->property("c1").toInt(), 9);
QCOMPARE(object->property("c2").toInt(), 8);
QCOMPARE(object->property("c3").toInt(), 8);
+
+ delete object;
}
/*
@@ -827,6 +868,8 @@ void tst_qdeclarativeecmascript::nonExistentAttachedObject()
QObject *object = component.create();
QVERIFY(object != 0);
+
+ delete object;
}
void tst_qdeclarativeecmascript::scope()
@@ -846,6 +889,8 @@ void tst_qdeclarativeecmascript::scope()
QCOMPARE(object->property("test8").toInt(), 2);
QCOMPARE(object->property("test9").toInt(), 1);
QCOMPARE(object->property("test10").toInt(), 3);
+
+ delete object;
}
{
@@ -859,6 +904,8 @@ void tst_qdeclarativeecmascript::scope()
QCOMPARE(object->property("test4").toInt(), 14);
QCOMPARE(object->property("test5").toInt(), 24);
QCOMPARE(object->property("test6").toInt(), 24);
+
+ delete object;
}
{
@@ -869,6 +916,8 @@ void tst_qdeclarativeecmascript::scope()
QCOMPARE(object->property("test1").toBool(), true);
QCOMPARE(object->property("test2").toBool(), true);
QCOMPARE(object->property("test3").toBool(), true);
+
+ delete object;
}
// Signal argument scope
@@ -887,6 +936,27 @@ void tst_qdeclarativeecmascript::scope()
delete object;
}
+
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("scope.5.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->property("test1").toBool(), true);
+ QCOMPARE(object->property("test2").toBool(), true);
+
+ delete object;
+ }
+
+ {
+ QDeclarativeComponent component(&engine, TEST_FILE("scope.6.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->property("test").toBool(), true);
+
+ delete object;
+ }
}
/*
@@ -907,6 +977,8 @@ void tst_qdeclarativeecmascript::signalParameterTypes()
QVERIFY(object->property("variantProperty") == QVariant::fromValue(QColor(255, 0, 255, 255)));
QVERIFY(object->property("enumProperty") == MyQmlObject::EnumValue3);
QVERIFY(object->property("qtEnumProperty") == Qt::LeftButton);
+
+ delete object;
}
/*
@@ -923,6 +995,8 @@ void tst_qdeclarativeecmascript::objectsCompareAsEqual()
QCOMPARE(object->property("test3").toBool(), true);
QCOMPARE(object->property("test4").toBool(), true);
QCOMPARE(object->property("test5").toBool(), true);
+
+ delete object;
}
/*
@@ -943,6 +1017,8 @@ void tst_qdeclarativeecmascript::aliasPropertyAndBinding()
QCOMPARE(object->property("c2").toInt(), 19);
QCOMPARE(object->property("c3").toInt(), 19);
+
+ delete object;
}
void tst_qdeclarativeecmascript::dynamicCreation_data()
@@ -972,6 +1048,8 @@ void tst_qdeclarativeecmascript::dynamicCreation()
QObject *created = object->objectProperty();
QVERIFY(created);
QCOMPARE(created->objectName(), createdName);
+
+ delete object;
}
/*
@@ -1020,6 +1098,8 @@ void tst_qdeclarativeecmascript::objectToString()
QMetaObject::invokeMethod(object, "testToString");
QVERIFY(object->stringProperty().startsWith("MyQmlObject_QML_"));
QVERIFY(object->stringProperty().endsWith(", \"objName\")"));
+
+ delete object;
}
/*
@@ -1034,6 +1114,7 @@ void tst_qdeclarativeecmascript::selfDeletingBinding()
QObject *object = component.create();
QVERIFY(object != 0);
object->setProperty("triggerDelete", true);
+ delete object;
}
{
@@ -1041,6 +1122,7 @@ void tst_qdeclarativeecmascript::selfDeletingBinding()
QObject *object = component.create();
QVERIFY(object != 0);
object->setProperty("triggerDelete", true);
+ delete object;
}
}
@@ -1056,6 +1138,7 @@ void tst_qdeclarativeecmascript::extendedObjectPropertyLookup()
QDeclarativeComponent component(&engine, TEST_FILE("extendedObjectPropertyLookup.qml"));
QObject *object = component.create();
QVERIFY(object != 0);
+ delete object;
}
/*
@@ -1091,6 +1174,8 @@ void tst_qdeclarativeecmascript::scriptErrors()
QTest::ignoreMessage(QtWarningMsg, warning8.toLatin1().constData());
emit object->thirdBasicSignal();
+
+ delete object;
}
/*
@@ -1108,6 +1193,16 @@ void tst_qdeclarativeecmascript::functionErrors()
QObject *object = component.create();
QVERIFY(object != 0);
delete object;
+
+ // test that if an exception occurs while invoking js function from cpp, it is reported as expected.
+ QDeclarativeComponent componentTwo(&engine, TEST_FILE("scarceresources/scarceResourceFunctionFail.qml"));
+ url = componentTwo.url().toString();
+ object = componentTwo.create();
+ QVERIFY(object != 0);
+ warning = url + QLatin1String(":16: TypeError: Result of expression 'scarceResourceProvider.scarceResource' [[object Object]] is not a function.");
+ QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); // we expect a meaningful warning to be printed.
+ QMetaObject::invokeMethod(object, "retrieveScarceResource");
+ delete object;
}
/*
@@ -1156,6 +1251,8 @@ void tst_qdeclarativeecmascript::signalTriggeredBindings()
QCOMPARE(object->property("base").toReal(), 400.);
QCOMPARE(object->property("test1").toReal(), 400.);
QCOMPARE(object->property("test2").toReal(), 400.);
+
+ delete object;
}
/*
@@ -1171,6 +1268,8 @@ void tst_qdeclarativeecmascript::listProperties()
QCOMPARE(object->property("test2").toInt(), 2);
QCOMPARE(object->property("test3").toBool(), true);
QCOMPARE(object->property("test4").toBool(), true);
+
+ delete object;
}
void tst_qdeclarativeecmascript::exceptionClearsOnReeval()
@@ -1192,6 +1291,8 @@ void tst_qdeclarativeecmascript::exceptionClearsOnReeval()
object->setObjectProperty(&object2);
QCOMPARE(object->property("test").toBool(), true);
+
+ delete object;
}
void tst_qdeclarativeecmascript::exceptionSlotProducesWarning()
@@ -1204,6 +1305,7 @@ void tst_qdeclarativeecmascript::exceptionSlotProducesWarning()
QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData());
MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create());
QVERIFY(object != 0);
+ delete object;
}
void tst_qdeclarativeecmascript::exceptionBindingProducesWarning()
@@ -1216,6 +1318,7 @@ void tst_qdeclarativeecmascript::exceptionBindingProducesWarning()
QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData());
MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create());
QVERIFY(object != 0);
+ delete object;
}
static int transientErrorsMsgCount = 0;
@@ -1239,6 +1342,8 @@ void tst_qdeclarativeecmascript::transientErrors()
qInstallMsgHandler(old);
QCOMPARE(transientErrorsMsgCount, 0);
+
+ delete object;
}
// One binding erroring multiple times, but then resolving
@@ -1254,6 +1359,8 @@ void tst_qdeclarativeecmascript::transientErrors()
qInstallMsgHandler(old);
QCOMPARE(transientErrorsMsgCount, 0);
+
+ delete object;
}
}
@@ -1369,6 +1476,8 @@ void tst_qdeclarativeecmascript::dynamicCreationCrash()
QMetaObject::invokeMethod(object, "dontCrash");
QObject *created = object->objectProperty();
QVERIFY(created == 0);
+
+ delete object;
}
//QTBUG-9367
@@ -1378,6 +1487,7 @@ void tst_qdeclarativeecmascript::regExpBug()
MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create());
QVERIFY(object != 0);
QCOMPARE(object->regExp().pattern(), QLatin1String("[a-zA-z]"));
+ delete object;
}
void tst_qdeclarativeecmascript::callQtInvokables()
@@ -2151,6 +2261,8 @@ void tst_qdeclarativeecmascript::ownership()
delete object;
}
+
+ delete context;
}
class CppOwnershipReturnValue : public QObject
@@ -2161,16 +2273,12 @@ public:
~CppOwnershipReturnValue() { delete value; }
Q_INVOKABLE QObject *create() {
- Q_ASSERT(value == 0);
-
value = new QObject;
QDeclarativeEngine::setObjectOwnership(value, QDeclarativeEngine::CppOwnership);
return value;
}
Q_INVOKABLE MyQmlObject *createQmlObject() {
- Q_ASSERT(value == 0);
-
MyQmlObject *rv = new MyQmlObject;
value = rv;
return rv;
@@ -2269,6 +2377,7 @@ void tst_qdeclarativeecmascript::qlistqobjectMethods()
QCOMPARE(object->property("test2").toBool(), true);
delete object;
+ delete context;
}
// QTBUG-9205
@@ -2389,6 +2498,328 @@ void tst_qdeclarativeecmascript::signalWithUnknownTypes()
delete object;
}
+void tst_qdeclarativeecmascript::moduleApi()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("moduleApi.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ 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);
+ delete object;
+
+ // test that caching of module apis works correctly.
+ QDeclarativeComponent componentTwo(&engine, TEST_FILE("moduleApiCaching.qml"));
+ object = componentTwo.create();
+ QVERIFY(object != 0);
+ QCOMPARE(object->property("existingUriTest").toInt(), 20);
+ QCOMPARE(object->property("scriptTest").toInt(), 13); // shouldn't have incremented.
+ QCOMPARE(object->property("qobjectParentedTest").toInt(), 26); // shouldn't have incremented.
+ delete object;
+
+ // test that writing to a property of module apis works correctly.
+ QDeclarativeComponent componentThree(&engine, TEST_FILE("moduleApiWriting.qml"));
+ QString expectedWarning = QLatin1String("file://") + TEST_FILE("moduleApiWriting.qml").toLocalFile() + QLatin1String(":15: Error: Cannot assign to read-only property \"qobjectTestProperty\"");
+ QTest::ignoreMessage(QtWarningMsg, expectedWarning.toAscii().constData());
+ object = componentThree.create();
+ QVERIFY(object != 0);
+ QCOMPARE(object->property("readOnlyProperty").toInt(), 20);
+ QCOMPARE(object->property("writableProperty").toInt(), 50);
+ QVERIFY(object->setProperty("firstProperty", QVariant(30))); // shouldn't affect value of readOnlyProperty
+ QVERIFY(object->setProperty("writableProperty", QVariant(30))); // SHOULD affect value of writableProperty
+ QCOMPARE(object->property("readOnlyProperty").toInt(), 20);
+ QCOMPARE(object->property("writableProperty").toInt(), 30);
+ delete object;
+
+ QDeclarativeComponent failOne(&engine, TEST_FILE("moduleApiMajorVersionFail.qml"));
+ QTest::ignoreMessage(QtWarningMsg, "QDeclarativeComponent: Component is not ready");
+ object = failOne.create();
+ QVERIFY(object == 0); // should have failed: invalid major version
+
+ QDeclarativeComponent failTwo(&engine, TEST_FILE("moduleApiMinorVersionFail.qml"));
+ QTest::ignoreMessage(QtWarningMsg, "QDeclarativeComponent: Component is not ready");
+ object = failTwo.create();
+ QVERIFY(object == 0); // should have failed: invalid minor version
+}
+
+void tst_qdeclarativeecmascript::importScripts()
+{
+ QObject *object = 0;
+
+ // first, ensure that the required behaviour works.
+ QDeclarativeComponent component(&engine, TEST_FILE("jsimport/testImport.qml"));
+ object = component.create();
+ QVERIFY(object != 0);
+ QCOMPARE(object->property("importedScriptStringValue"), QVariant(QString(QLatin1String("Hello, World!"))));
+ QCOMPARE(object->property("importedScriptFunctionValue"), QVariant(20));
+ QCOMPARE(object->property("importedModuleAttachedPropertyValue"), QVariant(19));
+ QCOMPARE(object->property("importedModuleEnumValue"), QVariant(2));
+ delete object;
+
+ QDeclarativeComponent componentTwo(&engine, TEST_FILE("jsimport/testImportScoping.qml"));
+ object = componentTwo.create();
+ QVERIFY(object != 0);
+ QCOMPARE(object->property("componentError"), QVariant(5));
+ delete object;
+
+ // then, ensure that unintended behaviour does not work.
+ QDeclarativeComponent failOneComponent(&engine, TEST_FILE("jsimportfail/failOne.qml"));
+ QString expectedWarning = QLatin1String("file://") + TEST_FILE("jsimportfail/failOne.qml").toLocalFile() + QLatin1String(":6: TypeError: Result of expression 'TestScriptImport.ImportOneJs' [undefined] is not an object.");
+ QTest::ignoreMessage(QtWarningMsg, expectedWarning.toAscii().constData());
+ object = failOneComponent.create();
+ QVERIFY(object != 0);
+ QVERIFY(object->property("importScriptFunctionValue").toString().isEmpty());
+ delete object;
+ QDeclarativeComponent failTwoComponent(&engine, TEST_FILE("jsimportfail/failTwo.qml"));
+ expectedWarning = QLatin1String("file://") + TEST_FILE("jsimportfail/failTwo.qml").toLocalFile() + QLatin1String(":6: ReferenceError: Can't find variable: ImportOneJs");
+ QTest::ignoreMessage(QtWarningMsg, expectedWarning.toAscii().constData());
+ object = failTwoComponent.create();
+ QVERIFY(object != 0);
+ QVERIFY(object->property("importScriptFunctionValue").toString().isEmpty());
+ delete object;
+ QDeclarativeComponent failThreeComponent(&engine, TEST_FILE("jsimportfail/failThree.qml"));
+ expectedWarning = QLatin1String("file://") + TEST_FILE("jsimportfail/failThree.qml").toLocalFile() + QLatin1String(":7: TypeError: Result of expression 'testQtObject.TestModuleImport.JsQtTest' [undefined] is not an object.");
+ QTest::ignoreMessage(QtWarningMsg, expectedWarning.toAscii().constData());
+ object = failThreeComponent.create();
+ QVERIFY(object != 0);
+ QCOMPARE(object->property("importedModuleAttachedPropertyValue"), QVariant(false));
+ delete object;
+ QDeclarativeComponent failFourComponent(&engine, TEST_FILE("jsimportfail/failFour.qml"));
+ expectedWarning = QLatin1String("file://") + TEST_FILE("jsimportfail/failFour.qml").toLocalFile() + QLatin1String(":6: ReferenceError: Can't find variable: JsQtTest");
+ QTest::ignoreMessage(QtWarningMsg, expectedWarning.toAscii().constData());
+ object = failFourComponent.create();
+ QVERIFY(object != 0);
+ QCOMPARE(object->property("importedModuleEnumValue"), QVariant(0));
+ delete object;
+ QDeclarativeComponent failFiveComponent(&engine, TEST_FILE("jsimportfail/failFive.qml"));
+ expectedWarning = QLatin1String("file://") + TEST_FILE("jsimportfail/importWithImports.js").toLocalFile() + QLatin1String(":8: ReferenceError: Can't find variable: Component");
+ QTest::ignoreMessage(QtWarningMsg, expectedWarning.toAscii().constData());
+ expectedWarning = QLatin1String("file://") + TEST_FILE("jsimportfail/importPragmaLibrary.js").toLocalFile() + QLatin1String(":6: ReferenceError: Can't find variable: Component");
+ QTest::ignoreMessage(QtWarningMsg, expectedWarning.toAscii().constData());
+ object = failFiveComponent.create();
+ QVERIFY(object != 0);
+ QCOMPARE(object->property("componentError"), QVariant(0));
+ delete object;
+
+ // also, test that importing scripts with .pragma library works as required
+ QDeclarativeComponent pragmaLibraryComponent(&engine, TEST_FILE("jsimport/testImportPragmaLibrary.qml"));
+ object = pragmaLibraryComponent.create();
+ QVERIFY(object != 0);
+ QCOMPARE(object->property("testValue"), QVariant(31));
+ delete object;
+
+ // and that .pragma library scripts don't inherit imports from any .qml file
+ QDeclarativeComponent pragmaLibraryComponentTwo(&engine, TEST_FILE("jsimportfail/testImportPragmaLibrary.qml"));
+ object = pragmaLibraryComponentTwo.create();
+ QVERIFY(object != 0);
+ QCOMPARE(object->property("testValue"), QVariant(0));
+ delete object;
+}
+
+void tst_qdeclarativeecmascript::scarceResources()
+{
+ QPixmap origPixmap(100, 100);
+ origPixmap.fill(Qt::blue);
+
+ QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(&engine);
+ ScarceResourceObject *eo = 0;
+ QObject *object = 0;
+
+ // in the following three cases, the instance created from the component
+ // has a property which is a copy of the scarce resource; hence, the
+ // resource should NOT be detached prior to deletion of the object instance,
+ // unless the resource is destroyed explicitly.
+ QDeclarativeComponent component(&engine, TEST_FILE("scarceresources/scarceResourceCopy.qml"));
+ object = component.create();
+ QVERIFY(object != 0);
+ QVERIFY(object->property("scarceResourceCopy").isValid());
+ QCOMPARE(object->property("scarceResourceCopy").value<QPixmap>(), origPixmap);
+ QVERIFY(ep->scarceResources == 0); // should have been released by this point.
+ eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
+ QVERIFY(!eo->scarceResourceIsDetached()); // there are two copies of it in existence: the property of object, and the property of eo.
+ delete object;
+
+ QDeclarativeComponent componentTwo(&engine, TEST_FILE("scarceresources/scarceResourceCopyFromJs.qml"));
+ object = componentTwo.create();
+ QVERIFY(object != 0);
+ QVERIFY(object->property("scarceResourceCopy").isValid());
+ QCOMPARE(object->property("scarceResourceCopy").value<QPixmap>(), origPixmap);
+ QVERIFY(ep->scarceResources == 0); // should have been released by this point.
+ eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
+ QVERIFY(!eo->scarceResourceIsDetached()); // there are two copies of it in existence: the property of object, and the property of eo.
+ delete object;
+
+ QDeclarativeComponent componentThree(&engine, TEST_FILE("scarceresources/scarceResourceDestroyedCopy.qml"));
+ object = componentThree.create();
+ QVERIFY(object != 0);
+ QVERIFY(!(object->property("scarceResourceCopy").isValid())); // was manually released prior to being returned.
+ QVERIFY(ep->scarceResources == 0); // should have been released by this point.
+ eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
+ QVERIFY(eo->scarceResourceIsDetached()); // should have explicitly been released during the evaluation of the binding.
+ delete object;
+
+ // in the following three cases, no other copy should exist in memory,
+ // and so it should be detached (unless explicitly preserved).
+ QDeclarativeComponent componentFour(&engine, TEST_FILE("scarceresources/scarceResourceTest.qml"));
+ object = componentFour.create();
+ QVERIFY(object != 0);
+ QVERIFY(object->property("scarceResourceTest").isValid());
+ QCOMPARE(object->property("scarceResourceTest").toInt(), 100);
+ QVERIFY(ep->scarceResources == 0); // should have been released by this point.
+ eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
+ QVERIFY(eo->scarceResourceIsDetached()); // the resource should have been released after the binding was evaluated.
+ delete object;
+
+ QDeclarativeComponent componentFive(&engine, TEST_FILE("scarceresources/scarceResourceTestPreserve.qml"));
+ object = componentFive.create();
+ QVERIFY(object != 0);
+ QVERIFY(object->property("scarceResourceTest").isValid());
+ QCOMPARE(object->property("scarceResourceTest").toInt(), 100);
+ QVERIFY(ep->scarceResources == 0); // should have been released by this point.
+ eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
+ QVERIFY(!eo->scarceResourceIsDetached()); // this won't be detached since we explicitly preserved it.
+ delete object;
+
+ QDeclarativeComponent componentSix(&engine, TEST_FILE("scarceresources/scarceResourceTestMultiple.qml"));
+ object = componentSix.create();
+ QVERIFY(object != 0);
+ QVERIFY(object->property("scarceResourceTest").isValid());
+ QCOMPARE(object->property("scarceResourceTest").toInt(), 100);
+ QVERIFY(ep->scarceResources == 0); // should have been released by this point.
+ eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
+ QVERIFY(eo->scarceResourceIsDetached()); // all resources were released manually or automatically released.
+ delete object;
+
+ // test that scarce resources are handled correctly for imports
+ QDeclarativeComponent componentSeven(&engine, TEST_FILE("scarceresources/scarceResourceCopyImportNoBinding.qml"));
+ object = componentSeven.create();
+ QVERIFY(object != 0); // the import should have caused the addition of a resource to the ScarceResources list
+ QVERIFY(ep->scarceResources == 0); // but they should have been released by this point.
+ delete object;
+
+ QDeclarativeComponent componentEight(&engine, TEST_FILE("scarceresources/scarceResourceCopyImportFail.qml"));
+ object = componentEight.create();
+ QVERIFY(object != 0);
+ QVERIFY(!object->property("scarceResourceCopy").isValid()); // wasn't preserved, so shouldn't be valid.
+ QVERIFY(ep->scarceResources == 0); // should have been released by this point.
+ delete object;
+
+ QDeclarativeComponent componentNine(&engine, TEST_FILE("scarceresources/scarceResourceCopyImport.qml"));
+ object = componentNine.create();
+ QVERIFY(object != 0);
+ QVERIFY(object->property("scarceResourceCopy").isValid()); // preserved, so should be valid.
+ QCOMPARE(object->property("scarceResourceCopy").value<QPixmap>(), origPixmap);
+ QVERIFY(object->property("scarceResourceAssignedCopyOne").isValid()); // assigned before destroy(), so should be valid.
+ QCOMPARE(object->property("scarceResourceAssignedCopyOne").value<QPixmap>(), origPixmap);
+ QVERIFY(!object->property("scarceResourceAssignedCopyTwo").isValid()); // assigned after destroy(), so should be invalid.
+ QVERIFY(ep->scarceResources == 0); // this will still be zero, because "preserve()" REMOVES it from this list.
+ delete object;
+
+ // test that scarce resources are handled properly in signal invocation
+ QDeclarativeComponent componentTen(&engine, TEST_FILE("scarceresources/scarceResourceSignal.qml"));
+ object = componentTen.create();
+ QVERIFY(object != 0);
+ QObject *srsc = object->findChild<QObject*>("srsc");
+ QVERIFY(srsc);
+ QVERIFY(!srsc->property("scarceResourceCopy").isValid()); // hasn't been instantiated yet.
+ QCOMPARE(srsc->property("width"), QVariant(5)); // default value is 5.
+ eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
+ QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage.
+ QMetaObject::invokeMethod(srsc, "testSignal");
+ QVERIFY(!srsc->property("scarceResourceCopy").isValid()); // still hasn't been instantiated
+ QCOMPARE(srsc->property("width"), QVariant(10)); // but width was assigned to 10.
+ eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
+ QVERIFY(eo->scarceResourceIsDetached()); // should still be no other copies of it at this stage.
+ QMetaObject::invokeMethod(srsc, "testSignal2"); // assigns scarceResourceCopy to the scarce pixmap.
+ QVERIFY(srsc->property("scarceResourceCopy").isValid());
+ QCOMPARE(srsc->property("scarceResourceCopy").value<QPixmap>(), origPixmap);
+ eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
+ QVERIFY(!(eo->scarceResourceIsDetached())); // should be another copy of the resource now.
+ QVERIFY(ep->scarceResources == 0); // should have been released by this point.
+ delete object;
+
+ // test that scarce resources are handled properly from js functions in qml files
+ QDeclarativeComponent componentEleven(&engine, TEST_FILE("scarceresources/scarceResourceFunction.qml"));
+ object = componentEleven.create();
+ QVERIFY(object != 0);
+ QVERIFY(!object->property("scarceResourceCopy").isValid()); // not yet assigned, so should not be valid
+ eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
+ QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage.
+ QMetaObject::invokeMethod(object, "retrieveScarceResource");
+ QVERIFY(object->property("scarceResourceCopy").isValid()); // assigned, so should be valid.
+ QCOMPARE(object->property("scarceResourceCopy").value<QPixmap>(), origPixmap);
+ eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
+ QVERIFY(!eo->scarceResourceIsDetached()); // should be a copy of the resource at this stage.
+ QMetaObject::invokeMethod(object, "releaseScarceResource");
+ QVERIFY(!object->property("scarceResourceCopy").isValid()); // just released, so should not be valid
+ eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
+ QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage.
+ QVERIFY(ep->scarceResources == 0); // should have been released by this point.
+ delete object;
+
+ // test that if an exception occurs while invoking js function from cpp, that the resources are released.
+ QDeclarativeComponent componentTwelve(&engine, TEST_FILE("scarceresources/scarceResourceFunctionFail.qml"));
+ object = componentTwelve.create();
+ QVERIFY(object != 0);
+ QVERIFY(!object->property("scarceResourceCopy").isValid()); // not yet assigned, so should not be valid
+ eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
+ QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage.
+ QString expectedWarning = QLatin1String("file://") + TEST_FILE("scarceresources/scarceResourceFunctionFail.qml").toLocalFile() + QLatin1String(":16: TypeError: Result of expression 'scarceResourceProvider.scarceResource' [[object Object]] is not a function.");
+ QTest::ignoreMessage(QtWarningMsg, expectedWarning.toAscii().constData()); // we expect a meaningful warning to be printed.
+ QMetaObject::invokeMethod(object, "retrieveScarceResource");
+ QVERIFY(!object->property("scarceResourceCopy").isValid()); // due to exception, assignment will NOT have occurred.
+ eo = qobject_cast<ScarceResourceObject*>(QDeclarativeProperty::read(object, "a").value<QObject*>());
+ QVERIFY(eo->scarceResourceIsDetached()); // should be no other copies of it at this stage.
+ QVERIFY(ep->scarceResources == 0); // should have been released by this point.
+ delete object;
+}
+
+void tst_qdeclarativeecmascript::propertyChangeSlots()
+{
+ // ensure that allowable property names are allowed and onPropertyNameChanged slots are generated correctly.
+ QDeclarativeComponent component(&engine, TEST_FILE("changeslots/propertyChangeSlots.qml"));
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+ delete object;
+
+ // ensure that invalid property names fail properly.
+ QTest::ignoreMessage(QtWarningMsg, "QDeclarativeComponent: Component is not ready");
+ QDeclarativeComponent e1(&engine, TEST_FILE("changeslots/propertyChangeSlotErrors.1.qml"));
+ QString expectedErrorString = e1.url().toString() + QLatin1String(":9:5: Cannot assign to non-existent property \"on_nameWithUnderscoreChanged\"");
+ QCOMPARE(e1.errors().at(0).toString(), expectedErrorString);
+ object = e1.create();
+ QVERIFY(object == 0);
+ delete object;
+
+ QTest::ignoreMessage(QtWarningMsg, "QDeclarativeComponent: Component is not ready");
+ QDeclarativeComponent e2(&engine, TEST_FILE("changeslots/propertyChangeSlotErrors.2.qml"));
+ expectedErrorString = e2.url().toString() + QLatin1String(":9:5: Cannot assign to non-existent property \"on____nameWithUnderscoresChanged\"");
+ QCOMPARE(e2.errors().at(0).toString(), expectedErrorString);
+ object = e2.create();
+ QVERIFY(object == 0);
+ delete object;
+
+ QTest::ignoreMessage(QtWarningMsg, "QDeclarativeComponent: Component is not ready");
+ QDeclarativeComponent e3(&engine, TEST_FILE("changeslots/propertyChangeSlotErrors.3.qml"));
+ expectedErrorString = e3.url().toString() + QLatin1String(":9:5: Cannot assign to non-existent property \"on$NameWithDollarsignChanged\"");
+ QCOMPARE(e3.errors().at(0).toString(), expectedErrorString);
+ object = e3.create();
+ QVERIFY(object == 0);
+ delete object;
+
+ QTest::ignoreMessage(QtWarningMsg, "QDeclarativeComponent: Component is not ready");
+ QDeclarativeComponent e4(&engine, TEST_FILE("changeslots/propertyChangeSlotErrors.4.qml"));
+ expectedErrorString = e4.url().toString() + QLatin1String(":9:5: Cannot assign to non-existent property \"on_6NameWithUnderscoreNumberChanged\"");
+ QCOMPARE(e4.errors().at(0).toString(), expectedErrorString);
+ object = e4.create();
+ QVERIFY(object == 0);
+ delete object;
+}
+
// Test that assigning a null object works
// Regressed with: df1788b4dbbb2826ae63f26bdf166342595343f4
void tst_qdeclarativeecmascript::nullObjectBinding()
@@ -2970,6 +3401,7 @@ void tst_qdeclarativeecmascript::revisionErrors()
QTest::ignoreMessage(QtWarningMsg, warning3.toLatin1().constData());
MyRevisionedClass *object = qobject_cast<MyRevisionedClass *>(component.create());
QVERIFY(object != 0);
+ delete object;
}
{
QDeclarativeComponent component(&engine, TEST_FILE("metaobjectRevisionErrors2.qml"));
@@ -2991,6 +3423,7 @@ void tst_qdeclarativeecmascript::revisionErrors()
QTest::ignoreMessage(QtWarningMsg, warning5.toLatin1().constData());
MyRevisionedClass *object = qobject_cast<MyRevisionedClass *>(component.create());
QVERIFY(object != 0);
+ delete object;
}
{
QDeclarativeComponent component(&engine, TEST_FILE("metaobjectRevisionErrors3.qml"));
@@ -3006,6 +3439,7 @@ void tst_qdeclarativeecmascript::revisionErrors()
QTest::ignoreMessage(QtWarningMsg, warning3.toLatin1().constData());
MyRevisionedClass *object = qobject_cast<MyRevisionedClass *>(component.create());
QVERIFY(object != 0);
+ delete object;
}
}
@@ -3017,6 +3451,7 @@ void tst_qdeclarativeecmascript::revision()
MyRevisionedClass *object = qobject_cast<MyRevisionedClass *>(component.create());
QVERIFY(object != 0);
+ delete object;
}
{
QDeclarativeComponent component(&engine, TEST_FILE("metaobjectRevision2.qml"));
@@ -3024,6 +3459,7 @@ void tst_qdeclarativeecmascript::revision()
MyRevisionedClass *object = qobject_cast<MyRevisionedClass *>(component.create());
QVERIFY(object != 0);
+ delete object;
}
{
QDeclarativeComponent component(&engine, TEST_FILE("metaobjectRevision3.qml"));
@@ -3031,6 +3467,7 @@ void tst_qdeclarativeecmascript::revision()
MyRevisionedClass *object = qobject_cast<MyRevisionedClass *>(component.create());
QVERIFY(object != 0);
+ delete object;
}
// Test that non-root classes can resolve revisioned methods
{
@@ -3081,6 +3518,18 @@ void tst_qdeclarativeecmascript::pushCleanContext()
QCOMPARE(func2.call().toInt32(), 6);
}
+void tst_qdeclarativeecmascript::realToInt()
+{
+ QDeclarativeComponent component(&engine, TEST_FILE("realToInt.qml"));
+ MyQmlObject *object = qobject_cast<MyQmlObject*>(component.create());
+ QVERIFY(object != 0);
+
+ QMetaObject::invokeMethod(object, "test1");
+ QCOMPARE(object->value(), int(4));
+ QMetaObject::invokeMethod(object, "test2");
+ QCOMPARE(object->value(), int(8));
+}
+
QTEST_MAIN(tst_qdeclarativeecmascript)
#include "tst_qdeclarativeecmascript.moc"