From daf671b42241533a2db1e598487256d616edf290 Mon Sep 17 00:00:00 2001 From: Charles Yin Date: Fri, 20 May 2011 11:57:29 +1000 Subject: Integrate QtQuickTest into Qt Change-Id: I558821c0dec9166ea1d0d2e1e2f889553c436316 Task-number:QTBUG-16082 --- tests/auto/auto.pro | 2 + tests/auto/qmltest/buttonclick/Button.qml | 74 ++ tests/auto/qmltest/buttonclick/tst_buttonclick.qml | 66 + tests/auto/qmltest/createbenchmark/item.qml | 75 ++ .../createbenchmark/tst_createbenchmark.qml | 55 + tests/auto/qmltest/events/tst_events.qml | 86 ++ .../qmltest/qdecarativebinding/tst_binding.qml | 75 ++ .../qmltest/qdecarativebinding/tst_binding2.qml | 70 + .../qdecarativeborderimage/InvalidSciFile.qml | 48 + .../qdecarativeborderimage/colors-round.sci | 7 + .../auto/qmltest/qdecarativeborderimage/colors.png | Bin 0 -> 1655 bytes .../qmltest/qdecarativeborderimage/invalid.sci | 7 + .../qdecarativeborderimage/tst_borderimage.qml | 247 ++++ tests/auto/qmltest/qmltest.pro | 11 + tests/auto/qmltest/selftests/tst_compare.qml | 1391 ++++++++++++++++++++ .../qmltest/selftests/tst_compare_quickobjects.qml | 81 ++ tests/auto/qmltest/selftests/tst_selftests.qml | 307 +++++ tests/auto/qmltest/tst_qmltest.cpp | 43 + 18 files changed, 2645 insertions(+) create mode 100644 tests/auto/qmltest/buttonclick/Button.qml create mode 100644 tests/auto/qmltest/buttonclick/tst_buttonclick.qml create mode 100644 tests/auto/qmltest/createbenchmark/item.qml create mode 100644 tests/auto/qmltest/createbenchmark/tst_createbenchmark.qml create mode 100644 tests/auto/qmltest/events/tst_events.qml create mode 100644 tests/auto/qmltest/qdecarativebinding/tst_binding.qml create mode 100644 tests/auto/qmltest/qdecarativebinding/tst_binding2.qml create mode 100644 tests/auto/qmltest/qdecarativeborderimage/InvalidSciFile.qml create mode 100644 tests/auto/qmltest/qdecarativeborderimage/colors-round.sci create mode 100644 tests/auto/qmltest/qdecarativeborderimage/colors.png create mode 100644 tests/auto/qmltest/qdecarativeborderimage/invalid.sci create mode 100644 tests/auto/qmltest/qdecarativeborderimage/tst_borderimage.qml create mode 100644 tests/auto/qmltest/qmltest.pro create mode 100644 tests/auto/qmltest/selftests/tst_compare.qml create mode 100644 tests/auto/qmltest/selftests/tst_compare_quickobjects.qml create mode 100644 tests/auto/qmltest/selftests/tst_selftests.qml create mode 100644 tests/auto/qmltest/tst_qmltest.cpp (limited to 'tests') diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 1edeaaa956..2543261eeb 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -2,4 +2,6 @@ TEMPLATE=subdirs SUBDIRS=\ declarative \ +contains(QT_CONFIG, qmltest): SUBDIRS += qmltest + !cross_compile: SUBDIRS += host.pro diff --git a/tests/auto/qmltest/buttonclick/Button.qml b/tests/auto/qmltest/buttonclick/Button.qml new file mode 100644 index 0000000000..6b195ff7c4 --- /dev/null +++ b/tests/auto/qmltest/buttonclick/Button.qml @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + id: container + + property string text: "Button" + + signal clicked + + width: buttonLabel.width + 20; height: buttonLabel.height + 5 + border { width: 1; color: "black" } + smooth: true + radius: 8 + + // color the button with a gradient + gradient: Gradient { + GradientStop { position: 0.0; color: "blue" } + GradientStop { position: 1.0; color: "lightblue" } + } + + MouseArea { + id: mouseArea + anchors.fill: parent + onClicked: container.clicked(); + } + + Text { + id: buttonLabel + anchors.centerIn: container + color: "white" + text: container.text + } +} diff --git a/tests/auto/qmltest/buttonclick/tst_buttonclick.qml b/tests/auto/qmltest/buttonclick/tst_buttonclick.qml new file mode 100644 index 0000000000..a875daa7d7 --- /dev/null +++ b/tests/auto/qmltest/buttonclick/tst_buttonclick.qml @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 + +Button { + id: button + onClicked: text = "Clicked" + + SignalSpy { + id: spy + target: button + signalName: "clicked" + } + + TestCase { + name: "ButtonClick" + when: windowShown + + function test_click() { + compare(spy.count, 0) + button.clicked(); + compare(button.text, "Clicked"); + compare(spy.count, 1) + } + } +} diff --git a/tests/auto/qmltest/createbenchmark/item.qml b/tests/auto/qmltest/createbenchmark/item.qml new file mode 100644 index 0000000000..e3a3491f41 --- /dev/null +++ b/tests/auto/qmltest/createbenchmark/item.qml @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} + Item {} +} diff --git a/tests/auto/qmltest/createbenchmark/tst_createbenchmark.qml b/tests/auto/qmltest/createbenchmark/tst_createbenchmark.qml new file mode 100644 index 0000000000..b484020d3c --- /dev/null +++ b/tests/auto/qmltest/createbenchmark/tst_createbenchmark.qml @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 + +TestCase { + id: top + name: "CreateBenchmark" + + function benchmark_create_component() { + var component = Qt.createComponent("item.qml") + var obj = component.createObject(top) + obj.destroy() + component.destroy() + } +} diff --git a/tests/auto/qmltest/events/tst_events.qml b/tests/auto/qmltest/events/tst_events.qml new file mode 100644 index 0000000000..bc358d95a6 --- /dev/null +++ b/tests/auto/qmltest/events/tst_events.qml @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 + +Rectangle { + width: 50; height: 50 + id: top + focus: true + + property bool leftKeyPressed: false + property bool leftKeyReleased: false + + Keys.onLeftPressed: { + leftKeyPressed = true + } + + Keys.onReleased: { + if (event.key == Qt.Key_Left) + leftKeyReleased = true + } + + property bool mouseHasBeenClicked: false + + MouseArea { + anchors.fill: parent + onClicked: { + mouseHasBeenClicked = true + } + } + + TestCase { + name: "Events" + when: windowShown // Must have this line for events to work. + + function test_key_click() { + keyClick(Qt.Key_Left) + tryCompare(top, "leftKeyPressed", true) + tryCompare(top, "leftKeyReleased", true) + } + + function test_mouse_click() { + mouseClick(top, 25, 30) + tryCompare(top, "mouseHasBeenClicked", true) + } + } +} diff --git a/tests/auto/qmltest/qdecarativebinding/tst_binding.qml b/tests/auto/qmltest/qdecarativebinding/tst_binding.qml new file mode 100644 index 0000000000..5c883c52d1 --- /dev/null +++ b/tests/auto/qmltest/qdecarativebinding/tst_binding.qml @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 + +Rectangle { + id: screen + width: 320; height: 240 + property string text + property bool changeColor: false + + Text { id: s1; text: "Hello" } + Rectangle { id: r1; width: 1; height: 1; color: "yellow" } + Rectangle { id: r2; width: 1; height: 1; color: "red" } + + Binding { target: screen; property: "text"; value: s1.text; id: binding1 } + Binding { target: screen; property: "color"; value: r1.color } + Binding { target: screen; property: "color"; when: screen.changeColor == true; value: r2.color; id: binding3 } + + TestCase { + name: "Binding" + + function test_binding() { + compare(screen.color, "#ffff00") // Yellow + compare(screen.text, "Hello") + verify(!binding3.when) + + screen.changeColor = true + compare(screen.color, "#ff0000") // Red + + verify(binding1.target == screen) + compare(binding1.property, "text") + compare(binding1.value, "Hello") + } + } +} diff --git a/tests/auto/qmltest/qdecarativebinding/tst_binding2.qml b/tests/auto/qmltest/qdecarativebinding/tst_binding2.qml new file mode 100644 index 0000000000..85e1951ba7 --- /dev/null +++ b/tests/auto/qmltest/qdecarativebinding/tst_binding2.qml @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 + +Rectangle { + id: screen + width: 320; height: 240 + property string text + property bool changeColor: false + + Text { id: s1; text: "Hello" } + Rectangle { id: r1; width: 1; height: 1; color: "yellow" } + Rectangle { id: r2; width: 1; height: 1; color: "red" } + + Binding { target: screen; property: "text"; value: s1.text } + Binding { target: screen; property: "color"; value: r1.color } + Binding { target: screen; property: "color"; value: r2.color; when: screen.changeColor == true } + + TestCase { + name: "Binding2" + + function test_binding2() { + compare(screen.color, "#ffff00") // Yellow + compare(screen.text, "Hello") + + screen.changeColor = true + compare(screen.color, "#ff0000") // Red + } + } +} diff --git a/tests/auto/qmltest/qdecarativeborderimage/InvalidSciFile.qml b/tests/auto/qmltest/qdecarativeborderimage/InvalidSciFile.qml new file mode 100644 index 0000000000..d8a6d89b92 --- /dev/null +++ b/tests/auto/qmltest/qdecarativeborderimage/InvalidSciFile.qml @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +BorderImage { + source: "invalid.sci" + width: 300 + height: 300 +} diff --git a/tests/auto/qmltest/qdecarativeborderimage/colors-round.sci b/tests/auto/qmltest/qdecarativeborderimage/colors-round.sci new file mode 100644 index 0000000000..5d2f49f0e1 --- /dev/null +++ b/tests/auto/qmltest/qdecarativeborderimage/colors-round.sci @@ -0,0 +1,7 @@ +border.left:10 +border.top:20 +border.right:30 +border.bottom:40 +horizontalTileRule:Round +verticalTileRule:Repeat +source:colors.png diff --git a/tests/auto/qmltest/qdecarativeborderimage/colors.png b/tests/auto/qmltest/qdecarativeborderimage/colors.png new file mode 100644 index 0000000000..dfb62f3d64 Binary files /dev/null and b/tests/auto/qmltest/qdecarativeborderimage/colors.png differ diff --git a/tests/auto/qmltest/qdecarativeborderimage/invalid.sci b/tests/auto/qmltest/qdecarativeborderimage/invalid.sci new file mode 100644 index 0000000000..98c72c9bf1 --- /dev/null +++ b/tests/auto/qmltest/qdecarativeborderimage/invalid.sci @@ -0,0 +1,7 @@ +border.left:10 +border.top:20 +border.down:30 +border.up:40 +horizontalTileRule:Roun +verticalTileRule:Repea +source:colors.png diff --git a/tests/auto/qmltest/qdecarativeborderimage/tst_borderimage.qml b/tests/auto/qmltest/qdecarativeborderimage/tst_borderimage.qml new file mode 100644 index 0000000000..4c2c369fe6 --- /dev/null +++ b/tests/auto/qmltest/qdecarativeborderimage/tst_borderimage.qml @@ -0,0 +1,247 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 + +Item { + id: top + + BorderImage { + id: noSource + source: "" + } + + property string srcImage: "colors.png" + + BorderImage { + id: clearSource + source: srcImage + } + + BorderImage { + id: resized + source: "colors.png" + width: 300 + height: 300 + } + + BorderImage { + id: smooth + source: "colors.png" + smooth: true + width: 300 + height: 300 + } + + BorderImage { + id: tileModes1 + source: "colors.png" + width: 100 + height: 300 + horizontalTileMode: BorderImage.Repeat + verticalTileMode: BorderImage.Repeat + } + + BorderImage { + id: tileModes2 + source: "colors.png" + width: 300 + height: 150 + horizontalTileMode: BorderImage.Round + verticalTileMode: BorderImage.Round + } + + TestCase { + name: "BorderImage" + + function test_noSource() { + compare(noSource.source, "") + compare(noSource.width, 0) + compare(noSource.height, 0) + compare(noSource.horizontalTileMode, BorderImage.Stretch) + compare(noSource.verticalTileMode, BorderImage.Stretch) + } + + function test_imageSource_data() { + return [ + { + tag: "local", + source: "colors.png", + remote: false, + error: "" + }, + { + tag: "local not found", + source: "no-such-file.png", + remote: false, + error: "SUBinline:1:21: QML BorderImage: Cannot open: SUBno-such-file.png" + } + // TODO: remote tests that need to use http + ] + } + + function test_imageSource(row) { + var expectError = (row.error.length != 0) + if (expectError) { + var parentUrl = Qt.resolvedUrl(".") + ignoreWarning(row.error.replace(/SUB/g, parentUrl)) + } + + var img = Qt.createQmlObject + ('import QtQuick 1.0; BorderImage { source: "' + + row.source + '" }', top) + + if (row.remote) + tryCompare(img, "status", BorderImage.Loading) + + if (!expectError) { + tryCompare(img, "status", BorderImage.Ready) + compare(img.width, 120) + compare(img.height, 120) + compare(img.horizontalTileMode, BorderImage.Stretch) + compare(img.verticalTileMode, BorderImage.Stretch) + } else { + tryCompare(img, "status", BorderImage.Error) + } + + img.destroy() + } + + function test_clearSource() { + compare(clearSource.source, Qt.resolvedUrl("colors.png")) + compare(clearSource.width, 120) + compare(clearSource.height, 120) + + srcImage = "" + compare(clearSource.source, "") + compare(clearSource.width, 0) + compare(clearSource.height, 0) + } + + function test_resized() { + compare(resized.width, 300) + compare(resized.height, 300) + compare(resized.horizontalTileMode, BorderImage.Stretch) + compare(resized.verticalTileMode, BorderImage.Stretch) + } + + function test_smooth() { + compare(smooth.smooth, true) + compare(smooth.width, 300) + compare(smooth.height, 300) + compare(smooth.horizontalTileMode, BorderImage.Stretch) + compare(smooth.verticalTileMode, BorderImage.Stretch) + } + + function test_tileModes() { + compare(tileModes1.width, 100) + compare(tileModes1.height, 300) + compare(tileModes1.horizontalTileMode, BorderImage.Repeat) + compare(tileModes1.verticalTileMode, BorderImage.Repeat) + + compare(tileModes2.width, 300) + compare(tileModes2.height, 150) + compare(tileModes2.horizontalTileMode, BorderImage.Round) + compare(tileModes2.verticalTileMode, BorderImage.Round) + } + + function test_sciSource_data() { + return [ + { + tag: "local", + source: "colors-round.sci", + remote: false, + valid: true + }, + { + tag: "local not found", + source: "no-such-file.sci", + remote: false, + valid: false + } + // TODO: remote tests that need to use http + ] + } + + function test_sciSource(row) { + var img = Qt.createQmlObject + ('import QtQuick 1.0; BorderImage { source: "' + + row.source + '"; width: 300; height: 300 }', top) + + if (row.remote) + tryCompare(img, "status", BorderImage.Loading) + + compare(img.source, Qt.resolvedUrl(row.source)) + compare(img.width, 300) + compare(img.height, 300) + + if (row.valid) { + tryCompare(img, "status", BorderImage.Ready) + compare(img.border.left, 10) + compare(img.border.top, 20) + compare(img.border.right, 30) + compare(img.border.bottom, 40) + compare(img.horizontalTileMode, BorderImage.Round) + compare(img.verticalTileMode, BorderImage.Repeat) + } else { + tryCompare(img, "status", BorderImage.Error) + } + + img.destroy() + } + + + function test_invalidSciFile() { + ignoreWarning("QDeclarativeGridScaledImage: Invalid tile rule specified. Using Stretch.") // for "Roun" + ignoreWarning("QDeclarativeGridScaledImage: Invalid tile rule specified. Using Stretch.") // for "Repea" + + var component = Qt.createComponent("InvalidSciFile.qml") + var invalidSciFile = component.createObject(top) + + compare(invalidSciFile.status, Image.Error) + compare(invalidSciFile.width, 300) + compare(invalidSciFile.height, 300) + compare(invalidSciFile.horizontalTileMode, BorderImage.Stretch) + compare(invalidSciFile.verticalTileMode, BorderImage.Stretch) + } + } +} diff --git a/tests/auto/qmltest/qmltest.pro b/tests/auto/qmltest/qmltest.pro new file mode 100644 index 0000000000..3ee655d55c --- /dev/null +++ b/tests/auto/qmltest/qmltest.pro @@ -0,0 +1,11 @@ +TEMPLATE=app +TARGET=tst_qmltest +CONFIG += warn_on qmltestcase +SOURCES += tst_qmltest.cpp + +OTHER_FILES += \ + selftests/tst_selftests.qml \ + qdecarativebinding/tst_binding2.qml \ + qdecarativebinding/tst_binding.qml \ + selftests/tst_compare.qml \ + selftests/tst_compare_quickobjects.qml diff --git a/tests/auto/qmltest/selftests/tst_compare.qml b/tests/auto/qmltest/selftests/tst_compare.qml new file mode 100644 index 0000000000..b775b75143 --- /dev/null +++ b/tests/auto/qmltest/selftests/tst_compare.qml @@ -0,0 +1,1391 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 + +TestCase { + name: "SelfTests_compare" + + function test_primitives_and_constants() { + compare(qtest_compareInternal(null, null), true, "null"); + compare(qtest_compareInternal(null, {}), false, "null"); + compare(qtest_compareInternal(null, undefined), false, "null"); + compare(qtest_compareInternal(null, 0), false, "null"); + compare(qtest_compareInternal(null, false), false, "null"); + compare(qtest_compareInternal(null, ''), false, "null"); + compare(qtest_compareInternal(null, []), false, "null"); + + compare(qtest_compareInternal(undefined, undefined), true, "undefined"); + compare(qtest_compareInternal(undefined, null), false, "undefined"); + compare(qtest_compareInternal(undefined, 0), false, "undefined"); + compare(qtest_compareInternal(undefined, false), false, "undefined"); + compare(qtest_compareInternal(undefined, {}), false, "undefined"); + compare(qtest_compareInternal(undefined, []), false, "undefined"); + compare(qtest_compareInternal(undefined, ""), false, "undefined"); + + // Nan usually doest not equal to Nan using the '==' operator. + // Only isNaN() is able to do it. + compare(qtest_compareInternal(0/0, 0/0), true, "NaN"); // NaN VS NaN + compare(qtest_compareInternal(1/0, 2/0), true, "Infinity"); // Infinity VS Infinity + compare(qtest_compareInternal(-1/0, 2/0), false, "-Infinity, Infinity"); // -Infinity VS Infinity + compare(qtest_compareInternal(-1/0, -2/0), true, "-Infinity, -Infinity"); // -Infinity VS -Infinity + compare(qtest_compareInternal(0/0, 1/0), false, "NaN, Infinity"); // Nan VS Infinity + compare(qtest_compareInternal(1/0, 0/0), false, "NaN, Infinity"); // Nan VS Infinity + compare(qtest_compareInternal(0/0, null), false, "NaN"); + compare(qtest_compareInternal(0/0, undefined), false, "NaN"); + compare(qtest_compareInternal(0/0, 0), false, "NaN"); + compare(qtest_compareInternal(0/0, false), false, "NaN"); + //compare(qtest_compareInternal(0/0, function () {}), false, "NaN"); // Do we really need that? + compare(qtest_compareInternal(1/0, null), false, "NaN, Infinity"); + compare(qtest_compareInternal(1/0, undefined), false, "NaN, Infinity"); + compare(qtest_compareInternal(1/0, 0), false, "NaN, Infinity"); + compare(qtest_compareInternal(1/0, 1), false, "NaN, Infinity"); + compare(qtest_compareInternal(1/0, false), false, "NaN, Infinity"); + compare(qtest_compareInternal(1/0, true), false, "NaN, Infinity"); + //compare(qtest_compareInternal(1/0, function () {}), false, "NaN"); // Do we really need that? + + compare(qtest_compareInternal(0, 0), true, "number"); + compare(qtest_compareInternal(0, 1), false, "number"); + compare(qtest_compareInternal(1, 0), false, "number"); + compare(qtest_compareInternal(1, 1), true, "number"); + compare(qtest_compareInternal(1.1, 1.1), true, "number"); + compare(qtest_compareInternal(0.0000005, 0.0000005), true, "number"); + compare(qtest_compareInternal(0, ''), false, "number"); + compare(qtest_compareInternal(0, '0'), false, "number"); + compare(qtest_compareInternal(1, '1'), false, "number"); + compare(qtest_compareInternal(0, false), false, "number"); + compare(qtest_compareInternal(1, true), false, "number"); + + compare(qtest_compareInternal(true, true), true, "boolean"); + compare(qtest_compareInternal(true, false), false, "boolean"); + compare(qtest_compareInternal(false, true), false, "boolean"); + compare(qtest_compareInternal(false, 0), false, "boolean"); + compare(qtest_compareInternal(false, null), false, "boolean"); + compare(qtest_compareInternal(false, undefined), false, "boolean"); + compare(qtest_compareInternal(true, 1), false, "boolean"); + compare(qtest_compareInternal(true, null), false, "boolean"); + compare(qtest_compareInternal(true, undefined), false, "boolean"); + + compare(qtest_compareInternal('', ''), true, "string"); + compare(qtest_compareInternal('a', 'a'), true, "string"); + compare(qtest_compareInternal("foobar", "foobar"), true, "string"); + compare(qtest_compareInternal("foobar", "foo"), false, "string"); + compare(qtest_compareInternal('', 0), false, "string"); + compare(qtest_compareInternal('', false), false, "string"); + compare(qtest_compareInternal('', null), false, "string"); + compare(qtest_compareInternal('', undefined), false, "string"); + + // Short annotation VS new annotation + compare(qtest_compareInternal(0, new Number()), true, "short annotation VS new annotation"); + compare(qtest_compareInternal(new Number(), 0), true, "short annotation VS new annotation"); + compare(qtest_compareInternal(1, new Number(1)), true, "short annotation VS new annotation"); + compare(qtest_compareInternal(new Number(1), 1), true, "short annotation VS new annotation"); + compare(qtest_compareInternal(new Number(0), 1), false, "short annotation VS new annotation"); + compare(qtest_compareInternal(0, new Number(1)), false, "short annotation VS new annotation"); + + compare(qtest_compareInternal(new String(), ""), true, "short annotation VS new annotation"); + compare(qtest_compareInternal("", new String()), true, "short annotation VS new annotation"); + compare(qtest_compareInternal(new String("My String"), "My String"), true, "short annotation VS new annotation"); + compare(qtest_compareInternal("My String", new String("My String")), true, "short annotation VS new annotation"); + compare(qtest_compareInternal("Bad String", new String("My String")), false, "short annotation VS new annotation"); + compare(qtest_compareInternal(new String("Bad String"), "My String"), false, "short annotation VS new annotation"); + + compare(qtest_compareInternal(false, new Boolean()), true, "short annotation VS new annotation"); + compare(qtest_compareInternal(new Boolean(), false), true, "short annotation VS new annotation"); + compare(qtest_compareInternal(true, new Boolean(true)), true, "short annotation VS new annotation"); + compare(qtest_compareInternal(new Boolean(true), true), true, "short annotation VS new annotation"); + compare(qtest_compareInternal(true, new Boolean(1)), true, "short annotation VS new annotation"); + compare(qtest_compareInternal(false, new Boolean(false)), true, "short annotation VS new annotation"); + compare(qtest_compareInternal(new Boolean(false), false), true, "short annotation VS new annotation"); + compare(qtest_compareInternal(false, new Boolean(0)), true, "short annotation VS new annotation"); + compare(qtest_compareInternal(true, new Boolean(false)), false, "short annotation VS new annotation"); + compare(qtest_compareInternal(new Boolean(false), true), false, "short annotation VS new annotation"); + + compare(qtest_compareInternal(new Object(), {}), true, "short annotation VS new annotation"); + compare(qtest_compareInternal({}, new Object()), true, "short annotation VS new annotation"); + compare(qtest_compareInternal(new Object(), {a:1}), false, "short annotation VS new annotation"); + compare(qtest_compareInternal({a:1}, new Object()), false, "short annotation VS new annotation"); + compare(qtest_compareInternal({a:undefined}, new Object()), false, "short annotation VS new annotation"); + compare(qtest_compareInternal(new Object(), {a:undefined}), false, "short annotation VS new annotation"); + } + + function test_objects_basics() { + compare(qtest_compareInternal({}, {}), true); + compare(qtest_compareInternal({}, null), false); + compare(qtest_compareInternal({}, undefined), false); + compare(qtest_compareInternal({}, 0), false); + compare(qtest_compareInternal({}, false), false); + + // This test is a hard one, it is very important + // REASONS: + // 1) They are of the same type "object" + // 2) [] instanceof Object is true + // 3) Their properties are the same (doesn't exists) + compare(qtest_compareInternal({}, []), false); + + compare(qtest_compareInternal({a:1}, {a:1}), true); + compare(qtest_compareInternal({a:1}, {a:"1"}), false); + compare(qtest_compareInternal({a:[]}, {a:[]}), true); + compare(qtest_compareInternal({a:{}}, {a:null}), false); + compare(qtest_compareInternal({a:1}, {}), false); + compare(qtest_compareInternal({}, {a:1}), false); + + // Hard ones + compare(qtest_compareInternal({a:undefined}, {}), false); + compare(qtest_compareInternal({}, {a:undefined}), false); + compare(qtest_compareInternal( + { + a: [{ bar: undefined }] + }, + { + a: [{ bat: undefined }] + } + ), false); + } + + function test_arrays_basics() { + compare(qtest_compareInternal([], []), true); + + // May be a hard one, can invoke a crash at execution. + // because their types are both "object" but null isn't + // like a true object, it doesn't have any property at all. + compare(qtest_compareInternal([], null), false); + + compare(qtest_compareInternal([], undefined), false); + compare(qtest_compareInternal([], false), false); + compare(qtest_compareInternal([], 0), false); + compare(qtest_compareInternal([], ""), false); + + // May be a hard one, but less hard + // than {} with [] (note the order) + compare(qtest_compareInternal([], {}), false); + + compare(qtest_compareInternal([null],[]), false); + compare(qtest_compareInternal([undefined],[]), false); + compare(qtest_compareInternal([],[null]), false); + compare(qtest_compareInternal([],[undefined]), false); + compare(qtest_compareInternal([null],[undefined]), false); + compare(qtest_compareInternal([[]],[[]]), true); + compare(qtest_compareInternal([[],[],[]],[[],[],[]]), true); + compare(qtest_compareInternal( + [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]], + [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]), + true); + compare(qtest_compareInternal( + [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]], + [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]), // shorter + false); + compare(qtest_compareInternal( + [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{}]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]], + [[],[],[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]), // deepest element not an array + false); + + // same multidimensional + compare(qtest_compareInternal( + [1,2,3,4,5,6,7,8,9, [ + 1,2,3,4,5,6,7,8,9, [ + 1,2,3,4,5,[ + [6,7,8,9, [ + [ + 1,2,3,4,[ + 2,3,4,[ + 1,2,[ + 1,2,3,4,[ + 1,2,3,4,5,6,7,8,9,[ + 0 + ],1,2,3,4,5,6,7,8,9 + ],5,6,7,8,9 + ],4,5,6,7,8,9 + ],5,6,7,8,9 + ],5,6,7 + ] + ] + ] + ] + ]]], + [1,2,3,4,5,6,7,8,9, [ + 1,2,3,4,5,6,7,8,9, [ + 1,2,3,4,5,[ + [6,7,8,9, [ + [ + 1,2,3,4,[ + 2,3,4,[ + 1,2,[ + 1,2,3,4,[ + 1,2,3,4,5,6,7,8,9,[ + 0 + ],1,2,3,4,5,6,7,8,9 + ],5,6,7,8,9 + ],4,5,6,7,8,9 + ],5,6,7,8,9 + ],5,6,7 + ] + ] + ] + ] + ]]]), + true, "Multidimensional"); + + // different multidimensional + compare(qtest_compareInternal( + [1,2,3,4,5,6,7,8,9, [ + 1,2,3,4,5,6,7,8,9, [ + 1,2,3,4,5,[ + [6,7,8,9, [ + [ + 1,2,3,4,[ + 2,3,4,[ + 1,2,[ + 1,2,3,4,[ + 1,2,3,4,5,6,7,8,9,[ + 0 + ],1,2,3,4,5,6,7,8,9 + ],5,6,7,8,9 + ],4,5,6,7,8,9 + ],5,6,7,8,9 + ],5,6,7 + ] + ] + ] + ] + ]]], + [1,2,3,4,5,6,7,8,9, [ + 1,2,3,4,5,6,7,8,9, [ + 1,2,3,4,5,[ + [6,7,8,9, [ + [ + 1,2,3,4,[ + 2,3,4,[ + 1,2,[ + '1',2,3,4,[ // string instead of number + 1,2,3,4,5,6,7,8,9,[ + 0 + ],1,2,3,4,5,6,7,8,9 + ],5,6,7,8,9 + ],4,5,6,7,8,9 + ],5,6,7,8,9 + ],5,6,7 + ] + ] + ] + ] + ]]]), + false, "Multidimensional"); + + // different multidimensional + compare(qtest_compareInternal( + [1,2,3,4,5,6,7,8,9, [ + 1,2,3,4,5,6,7,8,9, [ + 1,2,3,4,5,[ + [6,7,8,9, [ + [ + 1,2,3,4,[ + 2,3,4,[ + 1,2,[ + 1,2,3,4,[ + 1,2,3,4,5,6,7,8,9,[ + 0 + ],1,2,3,4,5,6,7,8,9 + ],5,6,7,8,9 + ],4,5,6,7,8,9 + ],5,6,7,8,9 + ],5,6,7 + ] + ] + ] + ] + ]]], + [1,2,3,4,5,6,7,8,9, [ + 1,2,3,4,5,6,7,8,9, [ + 1,2,3,4,5,[ + [6,7,8,9, [ + [ + 1,2,3,4,[ + 2,3,[ // missing an element (4) + 1,2,[ + 1,2,3,4,[ + 1,2,3,4,5,6,7,8,9,[ + 0 + ],1,2,3,4,5,6,7,8,9 + ],5,6,7,8,9 + ],4,5,6,7,8,9 + ],5,6,7,8,9 + ],5,6,7 + ] + ] + ] + ] + ]]]), + false, "Multidimensional"); + } + + function test_date_instances() { + // Date, we don't need to test Date.parse() because it returns a number. + // Only test the Date instances by setting them a fix date. + // The date use is midnight January 1, 1970 + + var d1 = new Date(); + d1.setTime(0); // fix the date + + var d2 = new Date(); + d2.setTime(0); // fix the date + + var d3 = new Date(); // The very now + + // Anyway their types differs, just in case the code fails in the order in which it deals with date + compare(qtest_compareInternal(d1, 0), false); // d1.valueOf() returns 0, but d1 and 0 are different + // test same values date and different instances equality + compare(qtest_compareInternal(d1, d2), true); + // test different date and different instances difference + compare(qtest_compareInternal(d1, d3), false); + + // try to fool equiv by adding a valueOf function to an object + // that would return the same value of a real date instance. + var d4 = new Date(); + d4.setFullYear(2010); + d4.setMonth(1); + d4.setDate(1); + d4.setHours(1); + d4.setMinutes(1); + d4.setSeconds(1); + d4.setMilliseconds(1); + var o4 = { + valueOf: function () { + return d4.valueOf(); + } + } + compare(qtest_compareInternal(d4, o4), false); // o4 isn't an instance of Date + } + + + function test_regexp() { + // Must test cases that imply those traps: + // var a = /./; + // a instanceof Object; // Oops + // a instanceof RegExp; // Oops + // typeof a === "function"; // Oops, false in IE and Opera, true in FF and Safari ("object") + + // Tests same regex with same modifiers in different order + var r = /foo/; + var r5 = /foo/gim; + var r6 = /foo/gmi; + var r7 = /foo/igm; + var r8 = /foo/img; + var r9 = /foo/mig; + var r10 = /foo/mgi; + var ri1 = /foo/i; + var ri2 = /foo/i; + var rm1 = /foo/m; + var rm2 = /foo/m; + var rg1 = /foo/g; + var rg2 = /foo/g; + + compare(qtest_compareInternal(r5, r6), true, "Modifier order"); + compare(qtest_compareInternal(r5, r7), true, "Modifier order"); + compare(qtest_compareInternal(r5, r8), true, "Modifier order"); + compare(qtest_compareInternal(r5, r9), true, "Modifier order"); + compare(qtest_compareInternal(r5, r10), true, "Modifier order"); + compare(qtest_compareInternal(r, r5), false, "Modifier"); + + compare(qtest_compareInternal(ri1, ri2), true, "Modifier"); + compare(qtest_compareInternal(r, ri1), false, "Modifier"); + compare(qtest_compareInternal(ri1, rm1), false, "Modifier"); + compare(qtest_compareInternal(r, rm1), false, "Modifier"); + compare(qtest_compareInternal(rm1, ri1), false, "Modifier"); + compare(qtest_compareInternal(rm1, rm2), true, "Modifier"); + compare(qtest_compareInternal(rg1, rm1), false, "Modifier"); + compare(qtest_compareInternal(rm1, rg1), false, "Modifier"); + compare(qtest_compareInternal(rg1, rg2), true, "Modifier"); + + // Different regex, same modifiers + var r11 = /[a-z]/gi; + var r13 = /[0-9]/gi; // oops! different + compare(qtest_compareInternal(r11, r13), false, "Regex pattern"); + + var r14 = /0/ig; + var r15 = /"0"/ig; // oops! different + compare(qtest_compareInternal(r14, r15), false, "Regex pattern"); + + var r1 = /[\n\r\u2028\u2029]/g; + var r2 = /[\n\r\u2028\u2029]/g; + var r3 = /[\n\r\u2028\u2028]/g; // differs from r1 + var r4 = /[\n\r\u2028\u2029]/; // differs from r1 + + compare(qtest_compareInternal(r1, r2), true, "Regex pattern"); + compare(qtest_compareInternal(r1, r3), false, "Regex pattern"); + compare(qtest_compareInternal(r1, r4), false, "Regex pattern"); + + // More complex regex + var regex1 = "^[-_.a-z0-9]+@([-_a-z0-9]+\\.)+([A-Za-z][A-Za-z]|[A-Za-z][A-Za-z][A-Za-z])|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$"; + var regex2 = "^[-_.a-z0-9]+@([-_a-z0-9]+\\.)+([A-Za-z][A-Za-z]|[A-Za-z][A-Za-z][A-Za-z])|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$"; + // regex 3 is different: '.' not escaped + var regex3 = "^[-_.a-z0-9]+@([-_a-z0-9]+.)+([A-Za-z][A-Za-z]|[A-Za-z][A-Za-z][A-Za-z])|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$"; + + var r21 = new RegExp(regex1); + var r22 = new RegExp(regex2); + var r23 = new RegExp(regex3); // diff from r21, not same pattern + var r23a = new RegExp(regex3, "gi"); // diff from r23, not same modifier + var r24a = new RegExp(regex3, "ig"); // same as r23a + + compare(qtest_compareInternal(r21, r22), true, "Complex Regex"); + compare(qtest_compareInternal(r21, r23), false, "Complex Regex"); + compare(qtest_compareInternal(r23, r23a), false, "Complex Regex"); + compare(qtest_compareInternal(r23a, r24a), true, "Complex Regex"); + + // typeof r1 is "function" in some browsers and "object" in others so we must cover this test + var re = / /; + compare(qtest_compareInternal(re, function () {}), false, "Regex internal"); + compare(qtest_compareInternal(re, {}), false, "Regex internal"); + } + + + function test_complex_objects() { + + function fn1() { + return "fn1"; + } + function fn2() { + return "fn2"; + } + + // Try to invert the order of some properties to make sure it is covered. + // It can failed when properties are compared between unsorted arrays. + compare(qtest_compareInternal( + { + a: 1, + b: null, + c: [{}], + d: { + a: 3.14159, + b: false, + c: { + e: fn1, + f: [[[]]], + g: { + j: { + k: { + n: { + r: "r", + s: [1,2,3], + t: undefined, + u: 0, + v: { + w: { + x: { + y: "Yahoo!", + z: null + } + } + } + }, + q: [], + p: 1/0, + o: 99 + }, + l: undefined, + m: null + } + }, + d: 0, + i: true, + h: "false" + } + }, + e: undefined, + g: "", + h: "h", + f: {}, + i: [] + }, + { + a: 1, + b: null, + c: [{}], + d: { + b: false, + a: 3.14159, + c: { + d: 0, + e: fn1, + f: [[[]]], + g: { + j: { + k: { + n: { + r: "r", + t: undefined, + u: 0, + s: [1,2,3], + v: { + w: { + x: { + z: null, + y: "Yahoo!" + } + } + } + }, + o: 99, + p: 1/0, + q: [] + }, + l: undefined, + m: null + } + }, + i: true, + h: "false" + } + }, + e: undefined, + g: "", + f: {}, + h: "h", + i: [] + } + ), true); + + compare(qtest_compareInternal( + { + a: 1, + b: null, + c: [{}], + d: { + a: 3.14159, + b: false, + c: { + d: 0, + e: fn1, + f: [[[]]], + g: { + j: { + k: { + n: { + //r: "r", // different: missing a property + s: [1,2,3], + t: undefined, + u: 0, + v: { + w: { + x: { + y: "Yahoo!", + z: null + } + } + } + }, + o: 99, + p: 1/0, + q: [] + }, + l: undefined, + m: null + } + }, + h: "false", + i: true + } + }, + e: undefined, + f: {}, + g: "", + h: "h", + i: [] + }, + { + a: 1, + b: null, + c: [{}], + d: { + a: 3.14159, + b: false, + c: { + d: 0, + e: fn1, + f: [[[]]], + g: { + j: { + k: { + n: { + r: "r", + s: [1,2,3], + t: undefined, + u: 0, + v: { + w: { + x: { + y: "Yahoo!", + z: null + } + } + } + }, + o: 99, + p: 1/0, + q: [] + }, + l: undefined, + m: null + } + }, + h: "false", + i: true + } + }, + e: undefined, + f: {}, + g: "", + h: "h", + i: [] + } + ), false); + + compare(qtest_compareInternal( + { + a: 1, + b: null, + c: [{}], + d: { + a: 3.14159, + b: false, + c: { + d: 0, + e: fn1, + f: [[[]]], + g: { + j: { + k: { + n: { + r: "r", + s: [1,2,3], + t: undefined, + u: 0, + v: { + w: { + x: { + y: "Yahoo!", + z: null + } + } + } + }, + o: 99, + p: 1/0, + q: [] + }, + l: undefined, + m: null + } + }, + h: "false", + i: true + } + }, + e: undefined, + f: {}, + g: "", + h: "h", + i: [] + }, + { + a: 1, + b: null, + c: [{}], + d: { + a: 3.14159, + b: false, + c: { + d: 0, + e: fn1, + f: [[[]]], + g: { + j: { + k: { + n: { + r: "r", + s: [1,2,3], + //t: undefined, // different: missing a property with an undefined value + u: 0, + v: { + w: { + x: { + y: "Yahoo!", + z: null + } + } + } + }, + o: 99, + p: 1/0, + q: [] + }, + l: undefined, + m: null + } + }, + h: "false", + i: true + } + }, + e: undefined, + f: {}, + g: "", + h: "h", + i: [] + } + ), false); + + compare(qtest_compareInternal( + { + a: 1, + b: null, + c: [{}], + d: { + a: 3.14159, + b: false, + c: { + d: 0, + e: fn1, + f: [[[]]], + g: { + j: { + k: { + n: { + r: "r", + s: [1,2,3], + t: undefined, + u: 0, + v: { + w: { + x: { + y: "Yahoo!", + z: null + } + } + } + }, + o: 99, + p: 1/0, + q: [] + }, + l: undefined, + m: null + } + }, + h: "false", + i: true + } + }, + e: undefined, + f: {}, + g: "", + h: "h", + i: [] + }, + { + a: 1, + b: null, + c: [{}], + d: { + a: 3.14159, + b: false, + c: { + d: 0, + e: fn1, + f: [[[]]], + g: { + j: { + k: { + n: { + r: "r", + s: [1,2,3], + t: undefined, + u: 0, + v: { + w: { + x: { + y: "Yahoo!", + z: null + } + } + } + }, + o: 99, + p: 1/0, + q: {} // different was [] + }, + l: undefined, + m: null + } + }, + h: "false", + i: true + } + }, + e: undefined, + f: {}, + g: "", + h: "h", + i: [] + } + ), false); + + var same1 = { + a: [ + "string", null, 0, "1", 1, { + prop: null, + foo: [1,2,null,{}, [], [1,2,3]], + bar: undefined + }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας" + ], + unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争", + b: "b", + c: fn1 + }; + + var same2 = { + a: [ + "string", null, 0, "1", 1, { + prop: null, + foo: [1,2,null,{}, [], [1,2,3]], + bar: undefined + }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας" + ], + unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争", + b: "b", + c: fn1 + }; + + var diff1 = { + a: [ + "string", null, 0, "1", 1, { + prop: null, + foo: [1,2,null,{}, [], [1,2,3,4]], // different: 4 was add to the array + bar: undefined + }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας" + ], + unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争", + b: "b", + c: fn1 + }; + + var diff2 = { + a: [ + "string", null, 0, "1", 1, { + prop: null, + foo: [1,2,null,{}, [], [1,2,3]], + newprop: undefined, // different: newprop was added + bar: undefined + }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας" + ], + unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争", + b: "b", + c: fn1 + }; + + var diff3 = { + a: [ + "string", null, 0, "1", 1, { + prop: null, + foo: [1,2,null,{}, [], [1,2,3]], + bar: undefined + }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ α" // different: missing last char + ], + unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争", + b: "b", + c: fn1 + }; + + var diff4 = { + a: [ + "string", null, 0, "1", 1, { + prop: null, + foo: [1,2,undefined,{}, [], [1,2,3]], // different: undefined instead of null + bar: undefined + }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας" + ], + unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争", + b: "b", + c: fn1 + }; + + var diff5 = { + a: [ + "string", null, 0, "1", 1, { + prop: null, + foo: [1,2,null,{}, [], [1,2,3]], + bat: undefined // different: property name not "bar" + }, 3, "Hey!", "Κάνε πάντα γνωρίζουμε ας των, μηχανής επιδιόρθωσης επιδιορθώσεις ώς μια. Κλπ ας" + ], + unicode: "老 汉语中存在 港澳和海外的华人圈中 贵州 我去了书店 现在尚有争", + b: "b", + c: fn1 + }; + + compare(qtest_compareInternal(same1, same2), true); + compare(qtest_compareInternal(same2, same1), true); + compare(qtest_compareInternal(same2, diff1), false); + compare(qtest_compareInternal(diff1, same2), false); + + compare(qtest_compareInternal(same1, diff1), false); + compare(qtest_compareInternal(same1, diff2), false); + compare(qtest_compareInternal(same1, diff3), false); + compare(qtest_compareInternal(same1, diff3), false); + compare(qtest_compareInternal(same1, diff4), false); + compare(qtest_compareInternal(same1, diff5), false); + compare(qtest_compareInternal(diff5, diff1), false); + } + + + function test_complex_arrays() { + + function fn() { + } + + compare(qtest_compareInternal( + [1, 2, 3, true, {}, null, [ + { + a: ["", '1', 0] + }, + 5, 6, 7 + ], "foo"], + [1, 2, 3, true, {}, null, [ + { + a: ["", '1', 0] + }, + 5, 6, 7 + ], "foo"]), + true); + + compare(qtest_compareInternal( + [1, 2, 3, true, {}, null, [ + { + a: ["", '1', 0] + }, + 5, 6, 7 + ], "foo"], + [1, 2, 3, true, {}, null, [ + { + b: ["", '1', 0] // not same property name + }, + 5, 6, 7 + ], "foo"]), + false); + + var a = [{ + b: fn, + c: false, + "do": "reserved word", + "for": { + ar: [3,5,9,"hey!", [], { + ar: [1,[ + 3,4,6,9, null, [], [] + ]], + e: fn, + f: undefined + }] + }, + e: 0.43445 + }, 5, "string", 0, fn, false, null, undefined, 0, [ + 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0 + ], [], [[[], "foo", null, { + n: 1/0, + z: { + a: [3,4,5,6,"yep!", undefined, undefined], + b: {} + } + }, {}]]]; + + compare(qtest_compareInternal(a, + [{ + b: fn, + c: false, + "do": "reserved word", + "for": { + ar: [3,5,9,"hey!", [], { + ar: [1,[ + 3,4,6,9, null, [], [] + ]], + e: fn, + f: undefined + }] + }, + e: 0.43445 + }, 5, "string", 0, fn, false, null, undefined, 0, [ + 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0 + ], [], [[[], "foo", null, { + n: 1/0, + z: { + a: [3,4,5,6,"yep!", undefined, undefined], + b: {} + } + }, {}]]]), true); + + compare(qtest_compareInternal(a, + [{ + b: fn, + c: false, + "do": "reserved word", + "for": { + ar: [3,5,9,"hey!", [], { + ar: [1,[ + 3,4,6,9, null, [], [] + ]], + e: fn, + f: undefined + }] + }, + e: 0.43445 + }, 5, "string", 0, fn, false, null, undefined, 0, [ + 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[2]]]], "3"], {}, 1/0 // different: [[[[[2]]]]] instead of [[[[[3]]]]] + ], [], [[[], "foo", null, { + n: 1/0, + z: { + a: [3,4,5,6,"yep!", undefined, undefined], + b: {} + } + }, {}]]]), false); + + compare(qtest_compareInternal(a, + [{ + b: fn, + c: false, + "do": "reserved word", + "for": { + ar: [3,5,9,"hey!", [], { + ar: [1,[ + 3,4,6,9, null, [], [] + ]], + e: fn, + f: undefined + }] + }, + e: 0.43445 + }, 5, "string", 0, fn, false, null, undefined, 0, [ + 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0 + ], [], [[[], "foo", null, { + n: -1/0, // different, -Infinity instead of Infinity + z: { + a: [3,4,5,6,"yep!", undefined, undefined], + b: {} + } + }, {}]]]), false); + + compare(qtest_compareInternal(a, + [{ + b: fn, + c: false, + "do": "reserved word", + "for": { + ar: [3,5,9,"hey!", [], { + ar: [1,[ + 3,4,6,9, null, [], [] + ]], + e: fn, + f: undefined + }] + }, + e: 0.43445 + }, 5, "string", 0, fn, false, null, undefined, 0, [ + 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0 + ], [], [[[], "foo", { // different: null is missing + n: 1/0, + z: { + a: [3,4,5,6,"yep!", undefined, undefined], + b: {} + } + }, {}]]]), false); + + compare(qtest_compareInternal(a, + [{ + b: fn, + c: false, + "do": "reserved word", + "for": { + ar: [3,5,9,"hey!", [], { + ar: [1,[ + 3,4,6,9, null, [], [] + ]], + e: fn + // different: missing property f: undefined + }] + }, + e: 0.43445 + }, 5, "string", 0, fn, false, null, undefined, 0, [ + 4,5,6,7,8,9,11,22,33,44,55,"66", null, [], [[[[[3]]]], "3"], {}, 1/0 + ], [], [[[], "foo", null, { + n: 1/0, + z: { + a: [3,4,5,6,"yep!", undefined, undefined], + b: {} + } + }, {}]]]), false); + } + + + function test_prototypal_inheritance() { + function Gizmo(id) { + this.id = id; + } + + function Hoozit(id) { + this.id = id; + } + Hoozit.prototype = new Gizmo(); + + var gizmo = new Gizmo("ok"); + var hoozit = new Hoozit("ok"); + + // Try this test many times after test on instances that hold function + // to make sure that our code does not mess with last object constructor memoization. + compare(qtest_compareInternal(function () {}, function () {}), false); + + // Hoozit inherit from Gizmo + // hoozit instanceof Hoozit; // true + // hoozit instanceof Gizmo; // true + compare(qtest_compareInternal(hoozit, gizmo), true); + + Gizmo.prototype.bar = true; // not a function just in case we skip them + + // Hoozit inherit from Gizmo + // They are equivalent + compare(qtest_compareInternal(hoozit, gizmo), true); + + // Make sure this is still true !important + // The reason for this is that I forgot to reset the last + // caller to where it were called from. + compare(qtest_compareInternal(function () {}, function () {}), false); + + // Make sure this is still true !important + compare(qtest_compareInternal(hoozit, gizmo), true); + + Hoozit.prototype.foo = true; // not a function just in case we skip them + + // Gizmo does not inherit from Hoozit + // gizmo instanceof Gizmo; // true + // gizmo instanceof Hoozit; // false + // They are not equivalent + compare(qtest_compareInternal(hoozit, gizmo), false); + + // Make sure this is still true !important + compare(qtest_compareInternal(function () {}, function () {}), false); + } + + + function test_instances() { + function A() {} + var a1 = new A(); + var a2 = new A(); + + function B() { + this.fn = function () {}; + } + var b1 = new B(); + var b2 = new B(); + + compare(qtest_compareInternal(a1, a2), true, "Same property, same constructor"); + + // b1.fn and b2.fn are functions but they are different references + // But we decided to skip function for instances. + expectFail("", "Don't know if we want to take over function checking like in QUnit") + compare(qtest_compareInternal(b1, b2), true, "Same property, same constructor"); + compare(qtest_compareInternal(a1, b1), false, "Same properties but different constructor"); // failed + + function Car(year) { + var privateVar = 0; + this.year = year; + this.isOld = function() { + return year > 10; + }; + } + + function Human(year) { + var privateVar = 1; + this.year = year; + this.isOld = function() { + return year > 80; + }; + } + + var car = new Car(30); + var carSame = new Car(30); + var carDiff = new Car(10); + var human = new Human(30); + + var diff = { + year: 30 + }; + + var same = { + year: 30, + isOld: function () {} + }; + + compare(qtest_compareInternal(car, car), true); + compare(qtest_compareInternal(car, carDiff), false); + compare(qtest_compareInternal(car, carSame), true); + compare(qtest_compareInternal(car, human), false); + } + + + function test_complex_instances_nesting() { + //"Complex Instances Nesting (with function value in literals and/or in nested instances)" + function A(fn) { + this.a = {}; + this.fn = fn; + this.b = {a: []}; + this.o = {}; + this.fn1 = fn; + } + function B(fn) { + this.fn = fn; + this.fn1 = function () {}; + this.a = new A(function () {}); + } + + function fnOutside() { + } + + function C(fn) { + function fnInside() { + } + this.x = 10; + this.fn = fn; + this.fn1 = function () {}; + this.fn2 = fnInside; + this.fn3 = { + a: true, + b: fnOutside // ok make reference to a function in all instances scope + }; + this.o1 = {}; + + // This function will be ignored. + // Even if it is not visible for all instances (e.g. locked in a closures), + // it is from a property that makes part of an instance (e.g. from the C constructor) + this.b1 = new B(function () {}); + this.b2 = new B({ + x: { + b2: new B(function() {}) + } + }); + } + + function D(fn) { + function fnInside() { + } + this.x = 10; + this.fn = fn; + this.fn1 = function () {}; + this.fn2 = fnInside; + this.fn3 = { + a: true, + b: fnOutside, // ok make reference to a function in all instances scope + + // This function won't be ingored. + // It isn't visible for all C insances + // and it is not in a property of an instance. (in an Object instances e.g. the object literal) + c: fnInside + }; + this.o1 = {}; + + // This function will be ignored. + // Even if it is not visible for all instances (e.g. locked in a closures), + // it is from a property that makes part of an instance (e.g. from the C constructor) + this.b1 = new B(function () {}); + this.b2 = new B({ + x: { + b2: new B(function() {}) + } + }); + } + + function E(fn) { + function fnInside() { + } + this.x = 10; + this.fn = fn; + this.fn1 = function () {}; + this.fn2 = fnInside; + this.fn3 = { + a: true, + b: fnOutside // ok make reference to a function in all instances scope + }; + this.o1 = {}; + + // This function will be ignored. + // Even if it is not visible for all instances (e.g. locked in a closures), + // it is from a property that makes part of an instance (e.g. from the C constructor) + this.b1 = new B(function () {}); + this.b2 = new B({ + x: { + b1: new B({a: function() {}}), + b2: new B(function() {}) + } + }); + } + + + var a1 = new A(function () {}); + var a2 = new A(function () {}); + expectFail("", "Don't know if we want to take over function checking like in QUnit") + compare(qtest_compareInternal(a1, a2), true); + + compare(qtest_compareInternal(a1, a2), true); // different instances + + var b1 = new B(function () {}); + var b2 = new B(function () {}); + compare(qtest_compareInternal(a1, a2), true); + + var c1 = new C(function () {}); + var c2 = new C(function () {}); + compare(qtest_compareInternal(c1, c2), true); + + var d1 = new D(function () {}); + var d2 = new D(function () {}); + compare(qtest_compareInternal(d1, d2), false); + + var e1 = new E(function () {}); + var e2 = new E(function () {}); + compare(qtest_compareInternal(e1, e2), false); + + } +} diff --git a/tests/auto/qmltest/selftests/tst_compare_quickobjects.qml b/tests/auto/qmltest/selftests/tst_compare_quickobjects.qml new file mode 100644 index 0000000000..7a8dc74347 --- /dev/null +++ b/tests/auto/qmltest/selftests/tst_compare_quickobjects.qml @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 + +TestCase { + name: "SelfTests_compare_QuickObjects" + id: testParent + + Rectangle { + id: item1 + color: "#000000" + } + Rectangle { + id: item2 + color: "#000000" + } + Rectangle { + id: item3 + color: "#ffffff" + } + + Component { + id: item4 + + Rectangle { + color: "#ffffff" + } + } + + function test_quickobjects() { + compare(qtest_compareInternal(item1, item1), true, "Identical QtQuick instances"); + compare(qtest_compareInternal(item1, item3), false, "QtQuick instances with different properties"); + + expectFail("", "Unsure if we want this."); + compare(qtest_compareInternal(item1, item2), true, "QtQuick instances with same properties"); + + expectFail("", "Unsure if we want this."); + compare(qtest_compareInternal(item4.createObject(testParent), + item4.createObject(testParent)), true, "QtQuick dynamic instances"); + } +} diff --git a/tests/auto/qmltest/selftests/tst_selftests.qml b/tests/auto/qmltest/selftests/tst_selftests.qml new file mode 100644 index 0000000000..16a539e895 --- /dev/null +++ b/tests/auto/qmltest/selftests/tst_selftests.qml @@ -0,0 +1,307 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 + +TestCase { + name: "SelfTests" + + // Replace the TestResult functions in "testCase" with hooks + // that record the events but don't send them to QTestLib. + QtObject { + id: functions + property string failmsg: "cleaned" + property string actual: "" + property string expected: "" + property variant functionsToRun: [] + + function fail(msg, file, line) { + failmsg = msg + } + + function verify(cond, msg, file, line) { + if (cond) { + failmsg = "verify-ok" + return true + } else { + failmsg = msg + return false + } + } + + function compare(success, msg, act, exp, file, line) { + if (success) { + failmsg = "compare-ok" + actual = "" + expected = "" + return true + } else { + failmsg = msg + actual = act + expected = exp + return false + } + } + + function skipSingle(msg, file, line) { + failmsg = "skipSingle:" + msg + } + + function skipAll(msg, file, line) { + failmsg = "skipAll:" + msg + } + } + + TestCase { + id: testCase + when: false + optional: true + qtest_results: functions + } + + function init() { + compare(functions.failmsg, "cleaned") // Checks for previous cleanup() + functions.failmsg = "invalid" + } + + function cleanup() { + functions.failmsg = "cleaned" + } + + function test_fail() { + compare(functions.failmsg, "invalid") // Checks that init() was run + + var caught = false + try { + testCase.fail("foo") + } catch (e) { + compare(e.message, "QtQuickTest::fail") + compare(functions.failmsg, "foo") + caught = true + } + verify(caught) + + caught = false + try { + testCase.fail() + } catch (e) { + compare(e.message, "QtQuickTest::fail") + compare(functions.failmsg, "") + caught = true + } + verify(caught) + + caught = false + try { + testCase.fail(false) + } catch (e) { + compare(e.message, "QtQuickTest::fail") + compare(functions.failmsg, "false") + caught = true + } + verify(caught) + + caught = false + try { + testCase.fail(3) + } catch (e) { + compare(e.message, "QtQuickTest::fail") + compare(functions.failmsg, "3") + caught = true + } + verify(caught) + } + + function test_verify() { + compare(functions.failmsg, "invalid") // Checks that init() was run + + try { + testCase.verify(true) + } catch (e) { + fail("verify(true) did not succeed") + } + compare(functions.failmsg, "verify-ok") + + var caught = false; + try { + testCase.verify(false, "foo") + } catch (e) { + compare(e.message, "QtQuickTest::fail") + compare(functions.failmsg, "foo") + caught = true + } + verify(caught) + + caught = false; + try { + testCase.verify(false) + } catch (e) { + compare(e.message, "QtQuickTest::fail") + compare(functions.failmsg, "") + caught = true + } + verify(caught) + } + + function test_compare() { + compare(functions.failmsg, "invalid") // Checks that init() was run + + try { + testCase.compare(23, 23) + } catch (e) { + fail("compare(23, 23) did not succeed") + } + compare(functions.failmsg, "compare-ok") + + var caught = false; + try { + testCase.compare(23, 42, "foo") + } catch (e) { + compare(e.message, "QtQuickTest::fail") + compare(functions.failmsg, "foo") + compare(functions.actual, "23") + compare(functions.expected, "42") + caught = true + } + verify(caught) + + caught = false; + try { + testCase.compare("abcdef", 42) + } catch (e) { + compare(e.message, "QtQuickTest::fail") + compare(functions.failmsg, "Compared values are not the same") + compare(functions.actual, "abcdef") + compare(functions.expected, "42") + caught = true + } + verify(caught) + + caught = false; + try { + testCase.compare(Qt.vector3d(1, 2, 3), Qt.vector3d(-1, 2, 3), "x") + } catch (e) { + compare(e.message, "QtQuickTest::fail") + compare(functions.failmsg, "x") + compare(functions.actual, "Qt.vector3d(1, 2, 3)") + compare(functions.expected, "Qt.vector3d(-1, 2, 3)") + caught = true + } + verify(caught) + + caught = false; + try { + testCase.compare(Qt.vector3d(1, 2, 3), Qt.vector3d(1, -2, 3), "y") + } catch (e) { + compare(e.message, "QtQuickTest::fail") + compare(functions.failmsg, "y") + compare(functions.actual, "Qt.vector3d(1, 2, 3)") + compare(functions.expected, "Qt.vector3d(1, -2, 3)") + caught = true + } + verify(caught) + + caught = false; + try { + testCase.compare(Qt.vector3d(1, 2, 3), Qt.vector3d(1, 2, -3), "z") + } catch (e) { + compare(e.message, "QtQuickTest::fail") + compare(functions.failmsg, "z") + compare(functions.actual, "Qt.vector3d(1, 2, 3)") + compare(functions.expected, "Qt.vector3d(1, 2, -3)") + caught = true + } + verify(caught) + + caught = false; + try { + testCase.compare(Qt.vector3d(1, 2, 3), Qt.vector3d(1, 2, 3)) + } catch (e) { + fail("vector compare did not succeed") + } + compare(functions.failmsg, "compare-ok") + } + + function test_skip() { + compare(functions.failmsg, "invalid") // Checks that init() was run + + var caught = false + try { + testCase.skip("foo") + } catch (e) { + compare(e.message, "QtQuickTest::skip") + compare(functions.failmsg, "skipSingle:foo") + caught = true + } + verify(caught) + + caught = false + try { + testCase.skip() + } catch (e) { + compare(e.message, "QtQuickTest::skip") + compare(functions.failmsg, "skipSingle:") + caught = true + } + verify(caught) + + caught = false + try { + testCase.skipAll("foo") + } catch (e) { + compare(e.message, "QtQuickTest::skip") + compare(functions.failmsg, "skipAll:foo") + caught = true + } + verify(caught) + + caught = false + try { + testCase.skipAll() + } catch (e) { + compare(e.message, "QtQuickTest::skip") + compare(functions.failmsg, "skipAll:") + caught = true + } + verify(caught) + } +} diff --git a/tests/auto/qmltest/tst_qmltest.cpp b/tests/auto/qmltest/tst_qmltest.cpp new file mode 100644 index 0000000000..37d47ac0d0 --- /dev/null +++ b/tests/auto/qmltest/tst_qmltest.cpp @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +QUICK_TEST_MAIN(qmlauto) -- cgit v1.2.3