1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
48 // Replace the TestResult functions in "testCase" with hooks
49 // that record the events but don't send them to QTestLib.
52 property string failmsg: "cleaned"
53 property string actual: ""
54 property string expected: ""
55 property variant functionsToRun: []
57 function fail(msg, file, line) {
61 function verify(cond, msg, file, line) {
71 function compare(success, msg, act, exp, file, line) {
73 failmsg = "compare-ok"
85 function skip(msg, file, line) {
86 failmsg = "skip:" + msg
94 qtest_results: functions
98 compare(functions.failmsg, "cleaned") // Checks for previous cleanup()
99 functions.failmsg = "invalid"
103 functions.failmsg = "cleaned"
106 function test_fail() {
107 compare(functions.failmsg, "invalid") // Checks that init() was run
113 compare(e.message, "QtQuickTest::fail")
114 compare(functions.failmsg, "foo")
123 compare(e.message, "QtQuickTest::fail")
124 compare(functions.failmsg, "")
133 compare(e.message, "QtQuickTest::fail")
134 compare(functions.failmsg, "false")
143 compare(e.message, "QtQuickTest::fail")
144 compare(functions.failmsg, "3")
150 function test_verify() {
151 compare(functions.failmsg, "invalid") // Checks that init() was run
154 testCase.verify(true)
156 fail("verify(true) did not succeed")
158 compare(functions.failmsg, "verify-ok")
162 testCase.verify(false, "foo")
164 compare(e.message, "QtQuickTest::fail")
165 compare(functions.failmsg, "foo")
172 testCase.verify(false)
174 compare(e.message, "QtQuickTest::fail")
175 compare(functions.failmsg, "")
181 function test_compare() {
182 compare(functions.failmsg, "invalid") // Checks that init() was run
185 testCase.compare(23, 23)
187 fail("compare(23, 23) did not succeed")
189 compare(functions.failmsg, "compare-ok")
193 testCase.compare(23, 42, "foo")
195 compare(e.message, "QtQuickTest::fail")
196 compare(functions.failmsg, "foo")
197 compare(functions.actual, "23")
198 compare(functions.expected, "42")
205 testCase.compare("abcdef", 42)
207 compare(e.message, "QtQuickTest::fail")
208 compare(functions.failmsg, "Compared values are not the same")
209 compare(functions.actual, "abcdef")
210 compare(functions.expected, "42")
218 testCase.compare(Qt.vector3d(1, 2, 3), Qt.vector3d(-1, 2, 3), "x")
220 compare(e.message, "QtQuickTest::fail")
221 compare(functions.failmsg, "x")
222 compare(functions.actual, "Qt.vector3d(1, 2, 3)")
223 compare(functions.expected, "Qt.vector3d(-1, 2, 3)")
230 testCase.compare(Qt.vector3d(1, 2, 3), Qt.vector3d(1, -2, 3), "y")
232 compare(e.message, "QtQuickTest::fail")
233 compare(functions.failmsg, "y")
234 compare(functions.actual, "Qt.vector3d(1, 2, 3)")
235 compare(functions.expected, "Qt.vector3d(1, -2, 3)")
242 testCase.compare(Qt.vector3d(1, 2, 3), Qt.vector3d(1, 2, -3), "z")
244 compare(e.message, "QtQuickTest::fail")
245 compare(functions.failmsg, "z")
246 compare(functions.actual, "Qt.vector3d(1, 2, 3)")
247 compare(functions.expected, "Qt.vector3d(1, 2, -3)")
254 testCase.compare(Qt.vector3d(1, 2, 3), Qt.vector3d(1, 2, 3))
256 fail("vector compare did not succeed")
258 compare(functions.failmsg, "compare-ok")
262 function test_skip() {
263 compare(functions.failmsg, "invalid") // Checks that init() was run
269 compare(e.message, "QtQuickTest::skip")
270 compare(functions.failmsg, "skip:foo")
279 compare(e.message, "QtQuickTest::skip")
280 compare(functions.failmsg, "skip:")