1 /****************************************************************************
3 ** Copyright (C) 2010 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 skipSingle(msg, file, line) {
86 failmsg = "skipSingle:" + msg
89 function skipAll(msg, file, line) {
90 failmsg = "skipAll:" + msg
98 qtest_results: functions
102 compare(functions.failmsg, "cleaned") // Checks for previous cleanup()
103 functions.failmsg = "invalid"
107 functions.failmsg = "cleaned"
110 function test_fail() {
111 compare(functions.failmsg, "invalid") // Checks that init() was run
117 compare(e.message, "QtQuickTest::fail")
118 compare(functions.failmsg, "foo")
127 compare(e.message, "QtQuickTest::fail")
128 compare(functions.failmsg, "")
137 compare(e.message, "QtQuickTest::fail")
138 compare(functions.failmsg, "false")
147 compare(e.message, "QtQuickTest::fail")
148 compare(functions.failmsg, "3")
154 function test_verify() {
155 compare(functions.failmsg, "invalid") // Checks that init() was run
158 testCase.verify(true)
160 fail("verify(true) did not succeed")
162 compare(functions.failmsg, "verify-ok")
166 testCase.verify(false, "foo")
168 compare(e.message, "QtQuickTest::fail")
169 compare(functions.failmsg, "foo")
176 testCase.verify(false)
178 compare(e.message, "QtQuickTest::fail")
179 compare(functions.failmsg, "")
185 function test_compare() {
186 compare(functions.failmsg, "invalid") // Checks that init() was run
189 testCase.compare(23, 23)
191 fail("compare(23, 23) did not succeed")
193 compare(functions.failmsg, "compare-ok")
197 testCase.compare(23, 42, "foo")
199 compare(e.message, "QtQuickTest::fail")
200 compare(functions.failmsg, "foo")
201 compare(functions.actual, "23")
202 compare(functions.expected, "42")
209 testCase.compare("abcdef", 42)
211 compare(e.message, "QtQuickTest::fail")
212 compare(functions.failmsg, "Compared values are not the same")
213 compare(functions.actual, "abcdef")
214 compare(functions.expected, "42")
221 testCase.compare(Qt.vector3d(1, 2, 3), Qt.vector3d(-1, 2, 3), "x")
223 compare(e.message, "QtQuickTest::fail")
224 compare(functions.failmsg, "x")
225 compare(functions.actual, "Qt.vector3d(1, 2, 3)")
226 compare(functions.expected, "Qt.vector3d(-1, 2, 3)")
233 testCase.compare(Qt.vector3d(1, 2, 3), Qt.vector3d(1, -2, 3), "y")
235 compare(e.message, "QtQuickTest::fail")
236 compare(functions.failmsg, "y")
237 compare(functions.actual, "Qt.vector3d(1, 2, 3)")
238 compare(functions.expected, "Qt.vector3d(1, -2, 3)")
245 testCase.compare(Qt.vector3d(1, 2, 3), Qt.vector3d(1, 2, -3), "z")
247 compare(e.message, "QtQuickTest::fail")
248 compare(functions.failmsg, "z")
249 compare(functions.actual, "Qt.vector3d(1, 2, 3)")
250 compare(functions.expected, "Qt.vector3d(1, 2, -3)")
257 testCase.compare(Qt.vector3d(1, 2, 3), Qt.vector3d(1, 2, 3))
259 fail("vector compare did not succeed")
261 compare(functions.failmsg, "compare-ok")
264 function test_skip() {
265 compare(functions.failmsg, "invalid") // Checks that init() was run
271 compare(e.message, "QtQuickTest::skip")
272 compare(functions.failmsg, "skipSingle:foo")
281 compare(e.message, "QtQuickTest::skip")
282 compare(functions.failmsg, "skipSingle:")
289 testCase.skipAll("foo")
291 compare(e.message, "QtQuickTest::skip")
292 compare(functions.failmsg, "skipAll:foo")
301 compare(e.message, "QtQuickTest::skip")
302 compare(functions.failmsg, "skipAll:")