aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmltest/TestCase.qml
diff options
context:
space:
mode:
Diffstat (limited to 'src/qmltest/TestCase.qml')
-rw-r--r--src/qmltest/TestCase.qml339
1 files changed, 237 insertions, 102 deletions
diff --git a/src/qmltest/TestCase.qml b/src/qmltest/TestCase.qml
index b7848a9fd7..9dac6ae249 100644
--- a/src/qmltest/TestCase.qml
+++ b/src/qmltest/TestCase.qml
@@ -66,7 +66,8 @@ import "testlogger.js" as TestLogger
Table data can be provided to a test using a function name that ends
with "_data". Alternatively, the \c init_data() function can be used
- to provide default test data for all test functions in a TestCase type:
+ to provide default test data for all test functions without a matching
+ "_data" function in a TestCase type:
\code
@@ -95,7 +96,7 @@ import "testlogger.js" as TestLogger
compare(data.a + data.b, data.answer)
}
- function test__default_table(data) {
+ function test_default_table(data) {
//data comes from init_data
compare(data.a + data.b, data.answer)
}
@@ -121,8 +122,8 @@ import "testlogger.js" as TestLogger
name: "CreateBenchmark"
function benchmark_create_component() {
- var component = Qt.createComponent("item.qml")
- var obj = component.createObject(top)
+ let component = Qt.createComponent("item.qml")
+ let obj = component.createObject(top)
obj.destroy()
component.destroy()
}
@@ -165,6 +166,15 @@ import "testlogger.js" as TestLogger
and mouseMove() methods can be used to simulate mouse events in a
similar fashion.
+ If your test creates other windows, it's possible that those windows
+ become active, stealing the focus from the TestCase's window. To ensure
+ that the TestCase's window is active, use the following code:
+
+ \code
+ testCase.Window.window.requestActivate()
+ tryCompare(testCase.Window.window, "active", true)
+ \endcode
+
\b{Note:} keyboard and mouse events can only be delivered once the
main window has been shown. Attempts to deliver events before then
will fail. Use the \l when and windowShown properties to track
@@ -183,7 +193,7 @@ import "testlogger.js" as TestLogger
when: windowShown
function test_click() {
- var item = Qt.createQmlObject("import QtQuick 2.0; Item {}", testCase);
+ let item = Qt.createQmlObject("import QtQuick 2.0; Item {}", testCase);
verify(item);
// Test item...
@@ -210,7 +220,7 @@ import "testlogger.js" as TestLogger
when: windowShown
function test_click() {
- var item = createTemporaryQmlObject("import QtQuick 2.0; Item {}", testCase);
+ let item = createTemporaryQmlObject("import QtQuick 2.0; Item {}", testCase);
verify(item);
// Test item...
@@ -224,6 +234,114 @@ import "testlogger.js" as TestLogger
of \l Component, the \l createTemporaryObject() function can be used.
\sa {QtTest::SignalSpy}{SignalSpy}, {Qt Quick Test}
+
+ \section1 Separating Tests from Application Logic
+
+ In most cases, you would want to separate your tests from the application
+ logic by splitting them into different projects and linking them.
+
+ For example, you could have the following project structure:
+
+ \badcode
+ .
+ | — CMakeLists.txt
+ | - main.qml
+ | — src
+ | — main.cpp
+ | — MyModule
+ | — MyButton.qml
+ | — CMakeLists.txt
+ | — tests
+ | — tst_testqml.qml
+ | — main.cpp
+ | — setup.cpp
+ | — setup.h
+ \endcode
+
+ Now, to test \c MyModule/MyButton.qml, create a library for
+ \c MyModule in \c MyModule/CMakeLists.txt and link it to your
+ test project, \c tests/UnitQMLTests/CMakeLists.txt:
+
+ \if defined(onlinedocs)
+ \tab {build-qt-app}{tab-cmake-add-library}{MyModule/CMakeLists.txt}{checked}
+ \tab {build-qt-app}{tab-cmake-link-against-library}{tests/CMakeLists.txt}{}
+ \tab {build-qt-app}{tab-tests_main}{tests/main.cpp}{}
+ \tab {build-qt-app}{tab-tests-setup-cpp}{tests/setup.cpp}{}
+ \tab
+ {build-qt-app}{tab-tests-setup-h}{tests/setup.h}{}
+ \tab {build-qt-app}{tab-project-cmake}{CMakeLists.txt}{}
+ \tabcontent {tab-cmake-add-library}
+ \else
+ \section2 Add Library
+ \endif
+ \dots
+ \snippet testApp/MyModule/CMakeLists.txt add library
+ \dots
+ \if defined(onlinedocs)
+ \endtabcontent
+ \tabcontent {tab-cmake-link-against-library}
+ \else
+ \section2 Link Against Library
+ \endif
+ \dots
+ \snippet testApp/tests/CMakeLists.txt link against library
+ \dots
+ \if defined(onlinedocs)
+ \endtabcontent
+ \tabcontent {tab-tests_main}
+ \else
+ \section2 Test main.cpp
+ \endif
+ \snippet testApp/tests/main.cpp main
+ \if defined(onlinedocs)
+ \endtabcontent
+ \tabcontent {tab-tests-setup-cpp}
+ \else
+ \section2 Test Setup C++
+ \endif
+ \snippet testApp/tests/setup.cpp setup
+ \if defined(onlinedocs)
+ \endtabcontent
+ \tabcontent {tab-tests-setup-h}
+ \else
+ \section2 Test Setup Header
+ \endif
+ \snippet testApp/tests/setup.h setup
+ \if defined(onlinedocs)
+ \endtabcontent
+ \tabcontent {tab-project-cmake}
+ \else
+ \section2 Project CMakeLists
+ \endif
+ \dots
+ \snippet testApp/CMakeLists.txt project-cmake
+ \dots
+ \if defined(onlinedocs)
+ \endtabcontent
+ \endif
+
+
+ Then, in \c tests/tst_testqml.qml, you can import
+ \c MyModule/MyButton.qml:
+
+ \if defined(onlinedocs)
+ \tab {test-qml}{tab-qml-import}{tests/tst_testqml.qml}{checked}
+ \tab {test-qml}{tab-qml-my-button}{MyModule/MyButton.qml}{}
+ \tabcontent {tab-qml-import}
+ \else
+ \section2 Import QML
+ \endif
+ \snippet testApp/tests/tst_testqml.qml import
+ \if defined(onlinedocs)
+ \endtabcontent
+ \tabcontent {tab-qml-my-button}
+ \else
+ \section2 Define QML Button
+ \endif
+ \snippet testApp/MyModule/MyButton.qml define
+ \if defined(onlinedocs)
+ \endtabcontent
+ \endif
*/
@@ -473,7 +591,7 @@ Item {
if (!expressionFunction())
wait(0)
- var i = 0
+ let i = 0
while (i < timeout && !expressionFunction()) {
wait(50)
i += 50
@@ -567,7 +685,7 @@ Item {
throw new Error("QtQuickTest::fail")
}
- if (timeout !== undefined && typeof(timeout) != "number") {
+ if (timeout !== undefined && typeof(timeout) !== "number") {
qtest_results.fail("Second argument must be a number; actual type is " + typeof timeout,
util.callerFile(), util.callerLine())
throw new Error("QtQuickTest::fail")
@@ -620,7 +738,7 @@ Item {
throw new Error("QtQuickTest::fail");
}
- var object = Qt.createQmlObject(qml, parent, filePath);
+ let object = Qt.createQmlObject(qml, parent, filePath);
qtest_temporaryObjects.push(object);
return object;
}
@@ -661,7 +779,7 @@ Item {
if (parent === undefined)
parent = null
- var object = component.createObject(parent, properties ? properties : ({}));
+ let object = component.createObject(parent, properties ? properties : ({}));
qtest_temporaryObjects.push(object);
return object;
}
@@ -672,8 +790,8 @@ Item {
Destroys all temporary objects that still exist.
*/
function qtest_destroyTemporaryObjects() {
- for (var i = 0; i < qtest_temporaryObjects.length; ++i) {
- var temporaryObject = qtest_temporaryObjects[i];
+ for (let i = 0; i < qtest_temporaryObjects.length; ++i) {
+ let temporaryObject = qtest_temporaryObjects[i];
// ### the typeof check can be removed when QTBUG-57749 is fixed
if (temporaryObject && typeof temporaryObject.destroy === "function")
temporaryObject.destroy();
@@ -743,27 +861,27 @@ Item {
// Test suites: http://philrathe.com/tests/equiv
// Author: Philippe Rathé <prathe@gmail.com>
function qtest_compareInternal(act, exp) {
- var success = false;
+ let success = false;
if (act === exp) {
success = true; // catch the most you can
} else if (act === null || exp === null || typeof act === "undefined" || typeof exp === "undefined") {
success = false; // don't lose time with error prone cases
} else {
- var typeExp = qtest_typeof(exp), typeAct = qtest_typeof(act)
+ let typeExp = qtest_typeof(exp), typeAct = qtest_typeof(act)
if (typeExp !== typeAct) {
// allow object vs string comparison (e.g. for colors)
// else break on different types
- if ((typeExp === "string" && (typeAct === "object") || typeAct == "declarativeitem")
- || ((typeExp === "object" || typeExp == "declarativeitem") && typeAct === "string")) {
- success = (act == exp)
+ if ((typeExp === "string" && (typeAct === "object") || typeAct === "declarativeitem")
+ || ((typeExp === "object" || typeExp === "declarativeitem") && typeAct === "string")) {
+ success = (act == exp) // @disable-check M126
}
} else if (typeExp === "string" || typeExp === "boolean" ||
typeExp === "null" || typeExp === "undefined") {
if (exp instanceof act.constructor || act instanceof exp.constructor) {
// to catch short annotaion VS 'new' annotation of act declaration
- // e.g. var i = 1;
- // var j = new Number(1);
- success = (act == exp)
+ // e.g. let i = 1;
+ // let j = new Number(1);
+ success = (act == exp) // @disable-check M126
} else {
success = (act === exp)
}
@@ -798,9 +916,9 @@ Item {
/*! \internal */
function qtest_compareInternalObjects(act, exp) {
- var i;
- var eq = true; // unless we can proove it
- var aProperties = [], bProperties = []; // collection of strings
+ let i;
+ let eq = true; // unless we can proove it
+ let aProperties = [], bProperties = []; // collection of strings
// comparing constructors is more strict than using instanceof
if (act.constructor !== exp.constructor) {
@@ -819,8 +937,8 @@ Item {
bProperties.push(i); // collect exp's properties
}
- if (aProperties.length == 0 && bProperties.length == 0) { // at least a special case for QUrl
- return eq && (JSON.stringify(act) == JSON.stringify(exp));
+ if (aProperties.length === 0 && bProperties.length === 0) { // at least a special case for QUrl
+ return eq && (JSON.stringify(act) === JSON.stringify(exp));
}
// Ensures identical properties name
@@ -830,11 +948,11 @@ Item {
/*! \internal */
function qtest_compareInternalArrays(actual, expected) {
- if (actual.length != expected.length) {
+ if (actual.length !== expected.length) {
return false
}
- for (var i = 0, len = actual.length; i < len; i++) {
+ for (let i = 0, len = actual.length; i < len; i++) {
if (!qtest_compareInternal(actual[i], expected[i])) {
return false
}
@@ -853,10 +971,10 @@ Item {
\sa tryCompare(), fuzzyCompare
*/
function compare(actual, expected, msg) {
- var act = qtest_results.stringify(actual)
- var exp = qtest_results.stringify(expected)
+ let act = qtest_results.stringify(actual)
+ let exp = qtest_results.stringify(expected)
- var success = qtest_compareInternal(actual, expected)
+ let success = qtest_compareInternal(actual, expected)
if (msg === undefined) {
if (success)
msg = "COMPARE()"
@@ -885,7 +1003,7 @@ Item {
if (delta === undefined)
qtest_fail("A delta value is required for fuzzyCompare", 2)
- var success = qtest_results.fuzzyCompare(actual, expected, delta)
+ let success = qtest_results.fuzzyCompare(actual, expected, delta)
if (msg === undefined) {
if (success)
msg = "FUZZYCOMPARE()"
@@ -923,12 +1041,12 @@ Item {
For example:
\code
- var image = grabImage(rect);
+ let image = grabImage(rect);
compare(image.red(10, 10), 255);
compare(image.pixel(20, 20), Qt.rgba(255, 0, 0, 255));
rect.width += 10;
- var newImage = grabImage(rect);
+ let newImage = grabImage(rect);
verify(!newImage.equals(image));
\endcode
@@ -939,7 +1057,7 @@ Item {
example:
\code
- var image = grabImage(rect);
+ let image = grabImage(rect);
try {
compare(image.width, 100);
} catch (ex) {
@@ -968,7 +1086,7 @@ Item {
*/
function findChild(parent, objectName) {
// First, search the visual item hierarchy.
- var child = qtest_findVisualChild(parent, objectName);
+ let child = qtest_findVisualChild(parent, objectName);
if (child)
return child;
@@ -981,16 +1099,16 @@ Item {
if (!parent || parent.children === undefined)
return null;
- for (var i = 0; i < parent.children.length; ++i) {
+ for (let i = 0; i < parent.children.length; ++i) {
// Is this direct child of ours the child we're after?
- var child = parent.children[i];
+ let child = parent.children[i];
if (child.objectName === objectName)
return child;
}
- for (i = 0; i < parent.children.length; ++i) {
+ for (let i = 0; i < parent.children.length; ++i) {
// Try the direct child's children.
- child = qtest_findVisualChild(parent.children[i], objectName);
+ let child = qtest_findVisualChild(parent.children[i], objectName);
if (child)
return child;
}
@@ -1023,18 +1141,18 @@ Item {
\sa compare(), SignalSpy::wait()
*/
function tryCompare(obj, prop, ...args) {
- if (typeof(prop) != "string" && typeof(prop) != "number") {
+ if (typeof(prop) !== "string" && typeof(prop) !== "number") {
qtest_results.fail("A property name as string or index is required for tryCompare",
util.callerFile(), util.callerLine())
throw new Error("QtQuickTest::fail")
}
- if (args.length == 0) {
+ if (args.length === 0) {
qtest_results.fail("A value is required for tryCompare",
util.callerFile(), util.callerLine())
throw new Error("QtQuickTest::fail")
}
let [value, timeout, msg] = args
- if (timeout !== undefined && typeof(timeout) != "number") {
+ if (timeout !== undefined && typeof(timeout) !== "number") {
qtest_results.fail("timeout should be a number",
util.callerFile(), util.callerLine())
throw new Error("QtQuickTest::fail")
@@ -1045,15 +1163,15 @@ Item {
msg = "property " + prop
if (!qtest_compareInternal(obj[prop], value))
wait(0)
- var i = 0
+ let i = 0
while (i < timeout && !qtest_compareInternal(obj[prop], value)) {
wait(50)
i += 50
}
- var actual = obj[prop]
- var act = qtest_results.stringify(actual)
- var exp = qtest_results.stringify(value)
- var success = qtest_compareInternal(actual, value)
+ let actual = obj[prop]
+ let act = qtest_results.stringify(actual)
+ let exp = qtest_results.stringify(value)
+ let success = qtest_compareInternal(actual, value)
if (!qtest_results.compare(success, msg, act, exp, util.callerFile(), util.callerLine()))
throw new Error("QtQuickTest::fail")
}
@@ -1229,7 +1347,16 @@ Item {
Waits for \a ms milliseconds while processing Qt events.
- \sa sleep(), waitForRendering()
+ \note This methods uses a precise timer to do the actual waiting. The
+ event you are waiting for may not. In particular, any animations as
+ well as the \l{Timer} QML type can use either precise or coarse
+ timers, depending on various factors. For a coarse timer you have
+ to expect a drift of around 5% in relation to the precise timer used
+ by TestCase::wait(). Qt cannot give hard guarantees on the drift,
+ though, because the operating system usually doesn't offer hard
+ guarantees on timers.
+
+ \sa sleep(), waitForRendering(), Qt::TimerType
*/
function wait(ms) {
qtest_results.wait(ms)
@@ -1280,9 +1407,9 @@ Item {
function keyPress(key, modifiers, delay) {
if (modifiers === undefined)
modifiers = Qt.NoModifier
- if (delay == undefined)
+ if (delay === undefined)
delay = -1
- if (typeof(key) == "string" && key.length == 1) {
+ if (typeof(key) === "string" && key.length === 1) {
if (!qtest_events.keyPressChar(key, modifiers, delay))
qtest_fail("window not shown", 2)
} else {
@@ -1306,9 +1433,9 @@ Item {
function keyRelease(key, modifiers, delay) {
if (modifiers === undefined)
modifiers = Qt.NoModifier
- if (delay == undefined)
+ if (delay === undefined)
delay = -1
- if (typeof(key) == "string" && key.length == 1) {
+ if (typeof(key) === "string" && key.length === 1) {
if (!qtest_events.keyReleaseChar(key, modifiers, delay))
qtest_fail("window not shown", 2)
} else {
@@ -1332,9 +1459,9 @@ Item {
function keyClick(key, modifiers, delay) {
if (modifiers === undefined)
modifiers = Qt.NoModifier
- if (delay == undefined)
+ if (delay === undefined)
delay = -1
- if (typeof(key) == "string" && key.length == 1) {
+ if (typeof(key) === "string" && key.length === 1) {
if (!qtest_events.keyClickChar(key, modifiers, delay))
qtest_fail("window not shown", 2)
} else {
@@ -1387,7 +1514,7 @@ Item {
button = Qt.LeftButton
if (modifiers === undefined)
modifiers = Qt.NoModifier
- if (delay == undefined)
+ if (delay === undefined)
delay = -1
if (x === undefined)
x = item.width / 2
@@ -1421,7 +1548,7 @@ Item {
button = Qt.LeftButton
if (modifiers === undefined)
modifiers = Qt.NoModifier
- if (delay == undefined)
+ if (delay === undefined)
delay = -1
if (x === undefined)
x = item.width / 2
@@ -1456,17 +1583,17 @@ Item {
button = Qt.LeftButton
if (modifiers === undefined)
modifiers = Qt.NoModifier
- if (delay == undefined)
+ if (delay === undefined)
delay = -1
- var moveDelay = Math.max(1, delay === -1 ? qtest_events.defaultMouseDelay : delay)
+ let moveDelay = Math.max(1, delay === -1 ? qtest_events.defaultMouseDelay : delay)
// Divide dx and dy to have intermediate mouseMove while dragging
// Fractions of dx/dy need be superior to the dragThreshold
// to make the drag works though
- var intermediateDx = Math.round(dx/3)
+ let intermediateDx = Math.round(dx/3)
if (Math.abs(intermediateDx) < (util.dragThreshold + 1))
intermediateDx = 0
- var intermediateDy = Math.round(dy/3)
+ let intermediateDy = Math.round(dy/3)
if (Math.abs(intermediateDy) < (util.dragThreshold + 1))
intermediateDy = 0
@@ -1474,14 +1601,14 @@ Item {
// Trigger dragging by dragging past the drag threshold, but making sure to only drag
// along a certain axis if a distance greater than zero was given for that axis.
- var dragTriggerXDistance = dx > 0 ? (util.dragThreshold + 1) : 0
- var dragTriggerYDistance = dy > 0 ? (util.dragThreshold + 1) : 0
- mouseMove(item, x + dragTriggerXDistance, y + dragTriggerYDistance, moveDelay, button)
+ let dragTriggerXDistance = dx > 0 ? (util.dragThreshold + 1) : 0
+ let dragTriggerYDistance = dy > 0 ? (util.dragThreshold + 1) : 0
+ mouseMove(item, x + dragTriggerXDistance, y + dragTriggerYDistance, moveDelay, button, modifiers)
if (intermediateDx !== 0 || intermediateDy !== 0) {
- mouseMove(item, x + intermediateDx, y + intermediateDy, moveDelay, button)
- mouseMove(item, x + 2*intermediateDx, y + 2*intermediateDy, moveDelay, button)
+ mouseMove(item, x + intermediateDx, y + intermediateDy, moveDelay, button, modifiers)
+ mouseMove(item, x + 2*intermediateDx, y + 2*intermediateDy, moveDelay, button, modifiers)
}
- mouseMove(item, x + dx, y + dy, moveDelay, button)
+ mouseMove(item, x + dx, y + dy, moveDelay, button, modifiers)
mouseRelease(item, x + dx, y + dy, button, modifiers, delay)
}
@@ -1509,7 +1636,7 @@ Item {
button = Qt.LeftButton
if (modifiers === undefined)
modifiers = Qt.NoModifier
- if (delay == undefined)
+ if (delay === undefined)
delay = -1
if (x === undefined)
x = item.width / 2
@@ -1550,7 +1677,7 @@ Item {
button = Qt.LeftButton
if (modifiers === undefined)
modifiers = Qt.NoModifier
- if (delay == undefined)
+ if (delay === undefined)
delay = -1
if (x === undefined)
x = item.width / 2
@@ -1577,19 +1704,21 @@ Item {
\sa mousePress(), mouseRelease(), mouseClick(), mouseDoubleClickSequence(), mouseDrag(), mouseWheel()
*/
- function mouseMove(item, x, y, delay, buttons) {
+ function mouseMove(item, x, y, delay, buttons, modifiers) {
if (!qtest_verifyItem(item, "mouseMove"))
return
- if (delay == undefined)
+ if (delay === undefined)
delay = -1
- if (buttons == undefined)
+ if (buttons === undefined)
buttons = Qt.NoButton
+ if (modifiers === undefined)
+ modifiers = Qt.NoModifiers
if (x === undefined)
x = item.width / 2
if (y === undefined)
y = item.height / 2
- if (!qtest_events.mouseMove(item, x, y, delay, buttons))
+ if (!qtest_events.mouseMove(item, x, y, delay, buttons, modifiers))
qtest_fail("window not shown", 2)
}
@@ -1613,15 +1742,15 @@ Item {
if (!qtest_verifyItem(item, "mouseWheel"))
return
- if (delay == undefined)
+ if (delay === undefined)
delay = -1
- if (buttons == undefined)
+ if (buttons === undefined)
buttons = Qt.NoButton
if (modifiers === undefined)
modifiers = Qt.NoModifier
- if (xDelta == undefined)
+ if (xDelta === undefined)
xDelta = 0
- if (yDelta == undefined)
+ if (yDelta === undefined)
yDelta = 0
if (!qtest_events.mouseWheel(item, x, y, buttons, modifiers, xDelta, yDelta, delay))
qtest_fail("window not shown", 2)
@@ -1658,7 +1787,7 @@ Item {
id: test1
function test_touch() {
- var touch = touchEvent(area);
+ let touch = touchEvent(area);
touch.press(0, area, 10, 10);
touch.commit();
verify(area.touched);
@@ -1803,7 +1932,7 @@ Item {
qtest_testCaseResult = testCase[prop](arg)
} catch (e) {
qtest_testCaseResult = []
- if (e.message.indexOf("QtQuickTest::") != 0) {
+ if (e.message.indexOf("QtQuickTest::") !== 0) {
// Test threw an unrecognized exception - fail.
qtest_results.fail("Uncaught exception: " + e.message,
e.fileName, e.lineNumber)
@@ -1820,10 +1949,12 @@ Item {
qtest_results.finishTestData()
qtest_runInternal("cleanup")
qtest_destroyTemporaryObjects()
- qtest_results.finishTestDataCleanup()
+
// wait(0) will call processEvents() so objects marked for deletion
// in the test function will be deleted.
wait(0)
+
+ qtest_results.finishTestDataCleanup()
}
}
@@ -1839,12 +1970,12 @@ Item {
break
// Execute the benchmark function.
- if (prop.indexOf("benchmark_once_") != 0)
+ if (prop.indexOf("benchmark_once_") !== 0)
qtest_results.startBenchmark(TestResult.RepeatUntilValidMeasurement, qtest_results.dataTag)
else
qtest_results.startBenchmark(TestResult.RunOnce, qtest_results.dataTag)
while (!qtest_results.isBenchmarkDone()) {
- var success = qtest_runInternal(prop, arg)
+ let success = qtest_runInternal(prop, arg)
qtest_results.finishTestData()
if (!success)
break
@@ -1868,7 +1999,11 @@ Item {
if (!when || completed || running || !qtest_componentCompleted)
return;
- verify(TestLogger.log_can_start_test(qtest_testId))
+ if (!TestLogger.log_can_start_test(qtest_testId)) {
+ console.error("Interleaved test execution detected. This shouldn't happen")
+ return;
+ }
+
if (TestLogger.log_start_test(qtest_testId)) {
qtest_results.reset()
qtest_results.testCaseName = name
@@ -1884,12 +2019,12 @@ Item {
if (qtest_results.functionsToRun.length > 0) {
checkNames = true
- var found = false
+ let found = false
if (name.length > 0) {
- for (var index in qtest_results.functionsToRun) {
+ for (let index in qtest_results.functionsToRun) {
let caseFuncName = qtest_results.functionsToRun[index]
- if (caseFuncName.indexOf(name + "::") != 0)
+ if (caseFuncName.indexOf(name + "::") !== 0)
continue
found = true
@@ -1916,7 +2051,7 @@ Item {
// Run the initTestCase function.
qtest_results.functionName = "initTestCase"
- var runTests = true
+ let runTests = true
if (!qtest_runInternal("initTestCase"))
runTests = false
qtest_results.finishTestData()
@@ -1924,27 +2059,27 @@ Item {
qtest_results.finishTestFunction()
// Run the test methods.
- var testList = []
+ let testList = []
if (runTests) {
- for (var prop in testCase) {
- if (prop.indexOf("test_") != 0 && prop.indexOf("benchmark_") != 0)
+ for (let prop in testCase) {
+ if (prop.indexOf("test_") !== 0 && prop.indexOf("benchmark_") !== 0)
continue
- var tail = prop.lastIndexOf("_data");
- if (tail != -1 && tail == (prop.length - 5))
+ let tail = prop.lastIndexOf("_data");
+ if (tail !== -1 && tail === (prop.length - 5))
continue
testList.push(prop)
}
testList.sort()
}
- for (var index in testList) {
- var prop = testList[index]
+ for (let index in testList) {
+ let prop = testList[index]
if (checkNames && !(prop in testsToRun))
continue
- var datafunc = prop + "_data"
- var isBenchmark = (prop.indexOf("benchmark_") == 0)
+ let datafunc = prop + "_data"
+ let isBenchmark = (prop.indexOf("benchmark_") === 0)
qtest_results.functionName = prop
if (!(datafunc in testCase))
@@ -1952,15 +2087,15 @@ Item {
if (datafunc in testCase) {
if (qtest_runInternal(datafunc)) {
- var table = qtest_testCaseResult
- var haveData = false
+ let table = qtest_testCaseResult
+ let haveData = false
let checkTags = (checkNames && testsToRun[prop].length > 0)
qtest_results.initTestTable()
- for (var index in table) {
+ for (let index in table) {
haveData = true
- var row = table[index]
+ let row = table[index]
if (!row.tag)
row.tag = "row " + index // Must have something
if (checkTags) {
@@ -2007,13 +2142,13 @@ Item {
// Complain about missing functions that we were supposed to run.
if (checkNames) {
let missingTests = []
- for (var func in testsToRun) {
+ for (let func in testsToRun) {
let caseFuncName = name + '::' + func
let tags = testsToRun[func]
if (tags.length <= 0)
missingTests.push(caseFuncName)
else
- for (var i in tags)
+ for (let i in tags)
missingTests.push(caseFuncName + ':' + tags[i])
}
missingTests.sort()
@@ -2038,7 +2173,7 @@ Item {
}
onWhenChanged: {
- if (when != qtest_prevWhen) {
+ if (when !== qtest_prevWhen) {
qtest_prevWhen = when
if (when)
TestSchedule.testCases.push(testCase)