From 8b2a1ec43134e191a5f9bb08a73f1a694d52927d Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 30 Jan 2015 20:57:40 +0100 Subject: Import the Qt Quick Controls 2 prototype Change-Id: Ib8c0c4160958e5cfea29a6e9df1b3f1fb19715fc Reviewed-by: Jari-Pekka Nurmi --- tests/auto/auto.pro | 4 + tests/auto/cmake/CMakeLists.txt | 12 + tests/auto/cmake/cmake.pro | 7 + tests/auto/controls/controls.pro | 12 + tests/auto/controls/data/tst_busyindicator.qml | 61 +++++ tests/auto/controls/data/tst_button.qml | 172 ++++++++++++ tests/auto/controls/data/tst_checkbox.qml | 274 +++++++++++++++++++ tests/auto/controls/data/tst_exclusivegroup.qml | 224 ++++++++++++++++ tests/auto/controls/data/tst_frame.qml | 103 +++++++ tests/auto/controls/data/tst_groupbox.qml | 104 +++++++ tests/auto/controls/data/tst_progressbar.qml | 121 +++++++++ tests/auto/controls/data/tst_radiobutton.qml | 274 +++++++++++++++++++ tests/auto/controls/data/tst_scrollbar.qml | 192 +++++++++++++ tests/auto/controls/data/tst_scrollindicator.qml | 121 +++++++++ tests/auto/controls/data/tst_slider.qml | 283 +++++++++++++++++++ tests/auto/controls/data/tst_stackview.qml | 284 ++++++++++++++++++++ tests/auto/controls/data/tst_switch.qml | 287 ++++++++++++++++++++ tests/auto/controls/data/tst_togglebutton.qml | 287 ++++++++++++++++++++ tests/auto/controls/data/tst_toolbar.qml | 103 +++++++ tests/auto/controls/data/tst_toolbutton.qml | 172 ++++++++++++ tests/auto/controls/tst_controls.cpp | 38 +++ tests/auto/extras/data/tst_splitview.qml | 328 +++++++++++++++++++++++ tests/auto/extras/extras.pro | 9 + tests/auto/extras/tst_extras.cpp | 38 +++ 24 files changed, 3510 insertions(+) create mode 100644 tests/auto/auto.pro create mode 100644 tests/auto/cmake/CMakeLists.txt create mode 100644 tests/auto/cmake/cmake.pro create mode 100644 tests/auto/controls/controls.pro create mode 100644 tests/auto/controls/data/tst_busyindicator.qml create mode 100644 tests/auto/controls/data/tst_button.qml create mode 100644 tests/auto/controls/data/tst_checkbox.qml create mode 100644 tests/auto/controls/data/tst_exclusivegroup.qml create mode 100644 tests/auto/controls/data/tst_frame.qml create mode 100644 tests/auto/controls/data/tst_groupbox.qml create mode 100644 tests/auto/controls/data/tst_progressbar.qml create mode 100644 tests/auto/controls/data/tst_radiobutton.qml create mode 100644 tests/auto/controls/data/tst_scrollbar.qml create mode 100644 tests/auto/controls/data/tst_scrollindicator.qml create mode 100644 tests/auto/controls/data/tst_slider.qml create mode 100644 tests/auto/controls/data/tst_stackview.qml create mode 100644 tests/auto/controls/data/tst_switch.qml create mode 100644 tests/auto/controls/data/tst_togglebutton.qml create mode 100644 tests/auto/controls/data/tst_toolbar.qml create mode 100644 tests/auto/controls/data/tst_toolbutton.qml create mode 100644 tests/auto/controls/tst_controls.cpp create mode 100644 tests/auto/extras/data/tst_splitview.qml create mode 100644 tests/auto/extras/extras.pro create mode 100644 tests/auto/extras/tst_extras.cpp (limited to 'tests/auto') diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro new file mode 100644 index 00000000..4e36fdca --- /dev/null +++ b/tests/auto/auto.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs +SUBDIRS += \ + controls \ + extras diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt new file mode 100644 index 00000000..3d77b9e5 --- /dev/null +++ b/tests/auto/cmake/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 2.8) + +project(qmake_cmake_files) + +enable_testing() + +find_package(Qt5Core REQUIRED) + +include("${_Qt5CTestMacros}") + +test_module_includes( +) diff --git a/tests/auto/cmake/cmake.pro b/tests/auto/cmake/cmake.pro new file mode 100644 index 00000000..0a5e7e75 --- /dev/null +++ b/tests/auto/cmake/cmake.pro @@ -0,0 +1,7 @@ + +# Cause make to do nothing. +TEMPLATE = subdirs + +CMAKE_QT_MODULES_UNDER_TEST = quick qml + +CONFIG += ctest_testcase diff --git a/tests/auto/controls/controls.pro b/tests/auto/controls/controls.pro new file mode 100644 index 00000000..81f18623 --- /dev/null +++ b/tests/auto/controls/controls.pro @@ -0,0 +1,12 @@ +TEMPLATE = app +TARGET = tst_controls +CONFIG += qmltestcase + +SOURCES += \ + $$PWD/tst_controls.cpp + +OTHER_FILES += \ + $$PWD/data/* + +TESTDATA += \ + $$PWD/data/* diff --git a/tests/auto/controls/data/tst_busyindicator.qml b/tests/auto/controls/data/tst_busyindicator.qml new file mode 100644 index 00000000..ca8472ed --- /dev/null +++ b/tests/auto/controls/data/tst_busyindicator.qml @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import QtQuick.Controls 2.0 + +TestCase { + id: testCase + width: 400 + height: 400 + visible: true + when: windowShown + name: "BusyIndicator" + + Component { + id: busyIndicator + BusyIndicator { } + } + + function test_running() { + var control = busyIndicator.createObject(testCase) + compare(control.running, false) + control.running = true + compare(control.running, true) + control.destroy() + } +} diff --git a/tests/auto/controls/data/tst_button.qml b/tests/auto/controls/data/tst_button.qml new file mode 100644 index 00000000..1ef76095 --- /dev/null +++ b/tests/auto/controls/data/tst_button.qml @@ -0,0 +1,172 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import QtQuick.Controls 2.0 + +TestCase { + id: testCase + width: 200 + height: 200 + visible: true + when: windowShown + name: "Button" + + SignalSpy { + id: pressedSpy + signalName: "pressedChanged" + } + + SignalSpy { + id: clickedSpy + signalName: "clicked" + } + + Component { + id: button + Button { } + } + + function init() { + verify(!pressedSpy.target) + verify(!clickedSpy.target) + compare(pressedSpy.count, 0) + compare(clickedSpy.count, 0) + } + + function cleanup() { + pressedSpy.target = null + clickedSpy.target = null + pressedSpy.clear() + clickedSpy.clear() + } + + function test_defaults() { + var control = button.createObject(testCase) + verify(control) + verify(control.label) + compare(control.text, "") + compare(control.pressed, false) + control.destroy() + } + + function test_text() { + var control = button.createObject(testCase) + compare(control.text, "") + control.text = "Button" + compare(control.text, "Button") + control.text = "" + compare(control.text, "") + control.destroy() + } + + function test_mouse() { + var control = button.createObject(testCase) + + pressedSpy.target = control + clickedSpy.target = control + verify(pressedSpy.valid) + verify(clickedSpy.valid) + + // check + mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(pressedSpy.count, 1) + compare(control.pressed, true) + mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(clickedSpy.count, 1) + compare(pressedSpy.count, 2) + compare(control.pressed, false) + + // uncheck + mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(pressedSpy.count, 3) + compare(control.pressed, true) + mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(clickedSpy.count, 2) + compare(pressedSpy.count, 4) + compare(control.pressed, false) + + // release outside + mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(pressedSpy.count, 5) + compare(control.pressed, true) + mouseMove(control, control.width * 2, control.height * 2, 0, Qt.LeftButton) + compare(control.pressed, false) + mouseRelease(control, control.width * 2, control.height * 2, Qt.LeftButton) + compare(clickedSpy.count, 2) + compare(pressedSpy.count, 6) + compare(control.pressed, false) + + // right button + mousePress(control, control.width / 2, control.height / 2, Qt.RightButton) + compare(pressedSpy.count, 6) + compare(control.pressed, false) + mouseRelease(control, control.width / 2, control.height / 2, Qt.RightButton) + compare(clickedSpy.count, 2) + compare(pressedSpy.count, 6) + compare(control.pressed, false) + + control.destroy() + } + + function test_keys() { + var control = button.createObject(testCase) + + clickedSpy.target = control + verify(clickedSpy.valid) + + control.forceActiveFocus() + verify(control.activeFocus) + + // check + keyClick(Qt.Key_Space) + compare(clickedSpy.count, 1) + + // uncheck + keyClick(Qt.Key_Space) + compare(clickedSpy.count, 2) + + // no change + var keys = [Qt.Key_Enter, Qt.Key_Return, Qt.Key_Escape, Qt.Key_Tab] + for (var i = 0; i < keys.length; ++i) { + keyClick(keys[i]) + compare(clickedSpy.count, 2) + } + + control.destroy() + } +} diff --git a/tests/auto/controls/data/tst_checkbox.qml b/tests/auto/controls/data/tst_checkbox.qml new file mode 100644 index 00000000..6d4cc703 --- /dev/null +++ b/tests/auto/controls/data/tst_checkbox.qml @@ -0,0 +1,274 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import QtQuick.Controls 2.0 + +TestCase { + id: testCase + width: 200 + height: 200 + visible: true + when: windowShown + name: "CheckBox" + + SignalSpy { + id: checkedSpy + signalName: "checkedChanged" + } + + SignalSpy { + id: pressedSpy + signalName: "pressedChanged" + } + + SignalSpy { + id: clickedSpy + signalName: "clicked" + } + + Component { + id: checkBox + CheckBox { } + } + + function init() { + verify(!checkedSpy.target) + verify(!pressedSpy.target) + verify(!clickedSpy.target) + compare(checkedSpy.count, 0) + compare(pressedSpy.count, 0) + compare(clickedSpy.count, 0) + } + + function cleanup() { + checkedSpy.target = null + pressedSpy.target = null + clickedSpy.target = null + checkedSpy.clear() + pressedSpy.clear() + clickedSpy.clear() + } + + function test_defaults() { + var control = checkBox.createObject(testCase) + verify(control) + verify(control.label) + verify(control.indicator) + compare(control.text, "") + compare(control.pressed, false) + compare(control.checked, false) + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + control.destroy() + } + + function test_layoutDirection() { + var control = checkBox.createObject(testCase) + + verify(!control.LayoutMirroring.enabled) + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + + control.layoutDirection = Qt.RightToLeft + compare(control.layoutDirection, Qt.RightToLeft) + compare(control.effectiveLayoutDirection, Qt.RightToLeft) + + control.LayoutMirroring.enabled = true + compare(control.layoutDirection, Qt.RightToLeft) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + + control.layoutDirection = Qt.LeftToRight + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.RightToLeft) + + control.LayoutMirroring.enabled = false + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + + control.destroy() + } + + function test_text() { + var control = checkBox.createObject(testCase) + compare(control.text, "") + control.text = "CheckBox" + compare(control.text, "CheckBox") + control.text = "" + compare(control.text, "") + control.destroy() + } + + function test_checked() { + var control = checkBox.createObject(testCase) + + checkedSpy.target = control + verify(checkedSpy.valid) + + compare(control.checked, false) + compare(checkedSpy.count, 0) + + control.checked = true + compare(control.checked, true) + compare(checkedSpy.count, 1) + + control.checked = false + compare(control.checked, false) + compare(checkedSpy.count, 2) + + control.destroy() + } + + function test_mouse() { + var control = checkBox.createObject(testCase) + + checkedSpy.target = control + pressedSpy.target = control + clickedSpy.target = control + verify(checkedSpy.valid) + verify(pressedSpy.valid) + verify(clickedSpy.valid) + + // check + mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(pressedSpy.count, 1) + compare(control.pressed, true) + mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(clickedSpy.count, 1) + compare(checkedSpy.count, 1) + compare(pressedSpy.count, 2) + compare(control.checked, true) + compare(control.pressed, false) + + // uncheck + mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(pressedSpy.count, 3) + compare(control.pressed, true) + mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 2) + compare(pressedSpy.count, 4) + compare(control.checked, false) + compare(control.pressed, false) + + // release outside + mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(pressedSpy.count, 5) + compare(control.pressed, true) + mouseMove(control, control.width * 2, control.height * 2, 0, Qt.LeftButton) + compare(control.pressed, false) + mouseRelease(control, control.width * 2, control.height * 2, Qt.LeftButton) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 2) + compare(pressedSpy.count, 6) + compare(control.checked, false) + compare(control.pressed, false) + + // right button + mousePress(control, control.width / 2, control.height / 2, Qt.RightButton) + compare(pressedSpy.count, 6) + compare(control.pressed, false) + mouseRelease(control, control.width / 2, control.height / 2, Qt.RightButton) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 2) + compare(pressedSpy.count, 6) + compare(control.checked, false) + compare(control.pressed, false) + + control.destroy() + } + + function test_keys() { + var control = checkBox.createObject(testCase) + + checkedSpy.target = control + clickedSpy.target = control + verify(checkedSpy.valid) + verify(clickedSpy.valid) + + control.forceActiveFocus() + verify(control.activeFocus) + + // check + keyClick(Qt.Key_Space) + compare(clickedSpy.count, 1) + compare(checkedSpy.count, 1) + compare(control.checked, true) + + // uncheck + keyClick(Qt.Key_Space) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 2) + compare(control.checked, false) + + // no change + var keys = [Qt.Key_Enter, Qt.Key_Return, Qt.Key_Escape, Qt.Key_Tab] + for (var i = 0; i < keys.length; ++i) { + keyClick(keys[i]) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 2) + compare(control.checked, false) + } + + control.destroy() + } + + Component { + id: twoCheckBoxes + Item { + property CheckBox cb1: CheckBox { id: cb1 } + property CheckBox cb2: CheckBox { id: cb2; checked: cb1.checked; enabled: false } + } + } + + function test_binding() { + var container = twoCheckBoxes.createObject(testCase) + + compare(container.cb1.checked, false) + compare(container.cb2.checked, false) + + container.cb1.checked = true + compare(container.cb1.checked, true) + compare(container.cb2.checked, true) + + container.cb1.checked = false + compare(container.cb1.checked, false) + compare(container.cb2.checked, false) + + container.destroy() + } +} diff --git a/tests/auto/controls/data/tst_exclusivegroup.qml b/tests/auto/controls/data/tst_exclusivegroup.qml new file mode 100644 index 00000000..856b7ad5 --- /dev/null +++ b/tests/auto/controls/data/tst_exclusivegroup.qml @@ -0,0 +1,224 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import QtQuick.Controls 2.0 + +TestCase { + id: testCase + width: 200 + height: 200 + visible: true + when: windowShown + name: "ExclusiveGroup" + + SignalSpy { + id: currentSpy + signalName: "currentChanged" + } + + Component { + id: exclusiveGroup + ExclusiveGroup { } + } + + function init() { + verify(!currentSpy.target) + compare(currentSpy.count, 0) + } + + function cleanup() { + currentSpy.target = null + currentSpy.clear() + } + + function test_defaults() { + var group = exclusiveGroup.createObject(testCase) + verify(group) + verify(!group.current) + group.destroy() + } + + Component { + id: checkable + QtObject { property bool checked } + } + + function test_current() { + var group = exclusiveGroup.createObject(testCase) + + currentSpy.target = group + verify(currentSpy.valid) + + var checkable1 = checkable.createObject(testCase, {checked: true}) + var checkable2 = checkable.createObject(testCase, {checked: false}) + var checkable3 = checkable.createObject(testCase, {checked: true}) + + // add checked + group.addCheckable(checkable1) + compare(group.current, checkable1) + compare(checkable1.checked, true) + compare(checkable2.checked, false) + compare(checkable3.checked, true) + compare(currentSpy.count, 1) + + // add non-checked + group.addCheckable(checkable2) + compare(group.current, checkable1) + compare(checkable1.checked, true) + compare(checkable2.checked, false) + compare(checkable3.checked, true) + compare(currentSpy.count, 1) + + // add checked + group.addCheckable(checkable3) + compare(group.current, checkable3) + compare(checkable1.checked, false) + compare(checkable2.checked, false) + compare(checkable3.checked, true) + compare(currentSpy.count, 2) + + // change current + group.current = checkable2 + compare(group.current, checkable2) + compare(checkable1.checked, false) + compare(checkable2.checked, true) + compare(checkable3.checked, false) + compare(currentSpy.count, 3) + + // check + checkable1.checked = true + compare(group.current, checkable1) + compare(checkable1.checked, true) + compare(checkable2.checked, false) + compare(checkable3.checked, false) + compare(currentSpy.count, 4) + + // remove non-checked + group.removeCheckable(checkable2) + compare(group.current, checkable1) + compare(checkable1.checked, true) + compare(checkable2.checked, false) + compare(checkable3.checked, false) + compare(currentSpy.count, 4) + + // remove checked + group.removeCheckable(checkable1) + verify(!group.current) + compare(checkable1.checked, false) + compare(checkable2.checked, false) + compare(checkable3.checked, false) + compare(currentSpy.count, 5) + + group.destroy() + } + + Component { + id: checkBoxes + Item { + property ExclusiveGroup group: ExclusiveGroup { id: group } + property CheckBox control1: CheckBox { Exclusive.group: group } + property CheckBox control2: CheckBox { Exclusive.group: group } + property CheckBox control3: CheckBox { Exclusive.group: group } + } + } + + Component { + id: radioButtons + Item { + property ExclusiveGroup group: ExclusiveGroup { id: group } + property RadioButton control1: RadioButton { Exclusive.group: group } + property RadioButton control2: RadioButton { Exclusive.group: group } + property RadioButton control3: RadioButton { Exclusive.group: group } + } + } + + Component { + id: switches + Item { + property ExclusiveGroup group: ExclusiveGroup { id: group } + property Switch control1: Switch { Exclusive.group: group } + property Switch control2: Switch { Exclusive.group: group } + property Switch control3: Switch { Exclusive.group: group } + } + } + + Component { + id: toggleButtons + Item { + property ExclusiveGroup group: ExclusiveGroup { id: group } + property ToggleButton control1: ToggleButton { Exclusive.group: group } + property ToggleButton control2: ToggleButton { Exclusive.group: group } + property ToggleButton control3: ToggleButton { Exclusive.group: group } + } + } + + function test_controls_data() { + return [ + { tag: "CheckBox", component: checkBoxes }, + { tag: "RadioButton", component: radioButtons }, + { tag: "Switch", component: switches }, + { tag: "ToggleButton", component: toggleButtons } + ] + } + + function test_controls(data) { + var container = data.component.createObject(testCase) + + verify(!container.group.current) + + container.control1.checked = true + compare(container.group.current, container.control1) + compare(container.control1.checked, true) + compare(container.control2.checked, false) + compare(container.control3.checked, false) + + container.control2.checked = true + compare(container.group.current, container.control2) + compare(container.control1.checked, false) + compare(container.control2.checked, true) + compare(container.control3.checked, false) + + container.control3.checked = true + compare(container.group.current, container.control3) + compare(container.control1.checked, false) + compare(container.control2.checked, false) + compare(container.control3.checked, true) + + container.destroy() + } +} diff --git a/tests/auto/controls/data/tst_frame.qml b/tests/auto/controls/data/tst_frame.qml new file mode 100644 index 00000000..276f46e9 --- /dev/null +++ b/tests/auto/controls/data/tst_frame.qml @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import QtQuick.Controls 2.0 + +TestCase { + id: testCase + width: 400 + height: 400 + visible: true + when: windowShown + name: "Frame" + + Component { + id: frame + Frame { } + } + + Component { + id: oneChildFrame + GroupBox { + Item { + implicitWidth: 100 + implicitHeight: 30 + } + } + } + + Component { + id: twoChildrenFrame + GroupBox { + Item { + implicitWidth: 100 + implicitHeight: 30 + } + Item { + implicitWidth: 200 + implicitHeight: 60 + } + } + } + + function test_defaults() { + var control = frame.createObject(testCase) + verify(control.contentItem) + compare(control.contentWidth, 0) + compare(control.contentHeight, 0) + control.destroy() + } + + function test_oneChild() { + var control = oneChildFrame.createObject(testCase) + compare(control.contentWidth, 100) + compare(control.contentHeight, 30) + verify(control.implicitWidth > 100) + verify(control.implicitHeight > 30) + control.destroy() + } + + function test_twoChildren() { + var control = twoChildrenFrame.createObject(testCase) + compare(control.contentWidth, 0) + compare(control.contentHeight, 0) + verify(control.implicitWidth > 0) + verify(control.implicitHeight > 0) + control.destroy() + } +} diff --git a/tests/auto/controls/data/tst_groupbox.qml b/tests/auto/controls/data/tst_groupbox.qml new file mode 100644 index 00000000..4b88b474 --- /dev/null +++ b/tests/auto/controls/data/tst_groupbox.qml @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import QtQuick.Controls 2.0 + +TestCase { + id: testCase + width: 400 + height: 400 + visible: true + when: windowShown + name: "GroupBox" + + Component { + id: groupBox + GroupBox { } + } + + Component { + id: oneChildBox + GroupBox { + Item { + implicitWidth: 100 + implicitHeight: 30 + } + } + } + + Component { + id: twoChildrenBox + GroupBox { + Item { + implicitWidth: 100 + implicitHeight: 30 + } + Item { + implicitWidth: 200 + implicitHeight: 60 + } + } + } + + function test_defaults() { + var control = groupBox.createObject(testCase) + verify(control.contentItem) + compare(control.title, "") + compare(control.contentWidth, 0) + compare(control.contentHeight, 0) + control.destroy() + } + + function test_oneChild() { + var control = oneChildBox.createObject(testCase) + compare(control.contentWidth, 100) + compare(control.contentHeight, 30) + verify(control.implicitWidth > 100) + verify(control.implicitHeight > 30) + control.destroy() + } + + function test_twoChildren() { + var control = twoChildrenBox.createObject(testCase) + compare(control.contentWidth, 0) + compare(control.contentHeight, 0) + verify(control.implicitWidth > 0) + verify(control.implicitHeight > 0) + control.destroy() + } +} diff --git a/tests/auto/controls/data/tst_progressbar.qml b/tests/auto/controls/data/tst_progressbar.qml new file mode 100644 index 00000000..c4a7347c --- /dev/null +++ b/tests/auto/controls/data/tst_progressbar.qml @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import QtQuick.Controls 2.0 + +TestCase { + id: testCase + width: 400 + height: 400 + visible: true + when: windowShown + name: "ProgressBar" + + Component { + id: progressBar + ProgressBar { } + } + + function test_defaults() { + var control = progressBar.createObject(testCase) + compare(control.value, 0) + compare(control.visualPosition, 0) + compare(control.indeterminate, false) + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + control.destroy() + } + + function test_value() { + var control = progressBar.createObject(testCase, {value: 0.5}) + compare(control.value, 0.5) + control.value = 1.0 + compare(control.value, 1.0) + control.value = -1.0 + compare(control.value, 0.0) + control.value = 2.0 + compare(control.value, 1.0) + control.destroy() + } + + function test_layoutDirection() { + var control = progressBar.createObject(testCase) + + verify(!control.LayoutMirroring.enabled) + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + + control.layoutDirection = Qt.RightToLeft + compare(control.layoutDirection, Qt.RightToLeft) + compare(control.effectiveLayoutDirection, Qt.RightToLeft) + + control.LayoutMirroring.enabled = true + compare(control.layoutDirection, Qt.RightToLeft) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + + control.layoutDirection = Qt.LeftToRight + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.RightToLeft) + + control.LayoutMirroring.enabled = false + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + + control.destroy() + } + + function test_visualPosition() { + var control = progressBar.createObject(testCase, {value: 0.25}) + compare(control.value, 0.25) + compare(control.visualPosition, 0.25) + + control.layoutDirection = Qt.RightToLeft + compare(control.visualPosition, 0.75) + + control.LayoutMirroring.enabled = true + compare(control.visualPosition, 0.25) + + control.layoutDirection = Qt.LeftToRight + compare(control.visualPosition, 0.75) + + control.LayoutMirroring.enabled = false + compare(control.visualPosition, 0.25) + + control.destroy() + } +} diff --git a/tests/auto/controls/data/tst_radiobutton.qml b/tests/auto/controls/data/tst_radiobutton.qml new file mode 100644 index 00000000..25a32536 --- /dev/null +++ b/tests/auto/controls/data/tst_radiobutton.qml @@ -0,0 +1,274 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import QtQuick.Controls 2.0 + +TestCase { + id: testCase + width: 200 + height: 200 + visible: true + when: windowShown + name: "RadioButton" + + SignalSpy { + id: checkedSpy + signalName: "checkedChanged" + } + + SignalSpy { + id: pressedSpy + signalName: "pressedChanged" + } + + SignalSpy { + id: clickedSpy + signalName: "clicked" + } + + Component { + id: radioButton + RadioButton { } + } + + function init() { + verify(!checkedSpy.target) + verify(!pressedSpy.target) + verify(!clickedSpy.target) + compare(checkedSpy.count, 0) + compare(pressedSpy.count, 0) + compare(clickedSpy.count, 0) + } + + function cleanup() { + checkedSpy.target = null + pressedSpy.target = null + clickedSpy.target = null + checkedSpy.clear() + pressedSpy.clear() + clickedSpy.clear() + } + + function test_defaults() { + var control = radioButton.createObject(testCase) + verify(control) + verify(control.label) + verify(control.indicator) + compare(control.text, "") + compare(control.pressed, false) + compare(control.checked, false) + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + control.destroy() + } + + function test_layoutDirection() { + var control = radioButton.createObject(testCase) + + verify(!control.LayoutMirroring.enabled) + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + + control.layoutDirection = Qt.RightToLeft + compare(control.layoutDirection, Qt.RightToLeft) + compare(control.effectiveLayoutDirection, Qt.RightToLeft) + + control.LayoutMirroring.enabled = true + compare(control.layoutDirection, Qt.RightToLeft) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + + control.layoutDirection = Qt.LeftToRight + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.RightToLeft) + + control.LayoutMirroring.enabled = false + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + + control.destroy() + } + + function test_text() { + var control = radioButton.createObject(testCase) + compare(control.text, "") + control.text = "RadioButton" + compare(control.text, "RadioButton") + control.text = "" + compare(control.text, "") + control.destroy() + } + + function test_checked() { + var control = radioButton.createObject(testCase) + + checkedSpy.target = control + verify(checkedSpy.valid) + + compare(control.checked, false) + compare(checkedSpy.count, 0) + + control.checked = true + compare(control.checked, true) + compare(checkedSpy.count, 1) + + control.checked = false + compare(control.checked, false) + compare(checkedSpy.count, 2) + + control.destroy() + } + + function test_mouse() { + var control = radioButton.createObject(testCase) + + checkedSpy.target = control + pressedSpy.target = control + clickedSpy.target = control + verify(checkedSpy.valid) + verify(pressedSpy.valid) + verify(clickedSpy.valid) + + // check + mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(pressedSpy.count, 1) + compare(control.pressed, true) + mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(clickedSpy.count, 1) + compare(checkedSpy.count, 1) + compare(pressedSpy.count, 2) + compare(control.checked, true) + compare(control.pressed, false) + + // attempt uncheck + mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(pressedSpy.count, 3) + compare(control.pressed, true) + mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 1) + compare(pressedSpy.count, 4) + compare(control.checked, true) + compare(control.pressed, false) + + // release outside + mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(pressedSpy.count, 5) + compare(control.pressed, true) + mouseMove(control, control.width * 2, control.height * 2, 0, Qt.LeftButton) + compare(control.pressed, false) + mouseRelease(control, control.width * 2, control.height * 2, Qt.LeftButton) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 1) + compare(pressedSpy.count, 6) + compare(control.checked, true) + compare(control.pressed, false) + + // right button + mousePress(control, control.width / 2, control.height / 2, Qt.RightButton) + compare(pressedSpy.count, 6) + compare(control.pressed, false) + mouseRelease(control, control.width / 2, control.height / 2, Qt.RightButton) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 1) + compare(pressedSpy.count, 6) + compare(control.checked, true) + compare(control.pressed, false) + + control.destroy() + } + + function test_keys() { + var control = radioButton.createObject(testCase) + + checkedSpy.target = control + clickedSpy.target = control + verify(checkedSpy.valid) + verify(clickedSpy.valid) + + control.forceActiveFocus() + verify(control.activeFocus) + + // check + keyClick(Qt.Key_Space) + compare(clickedSpy.count, 1) + compare(checkedSpy.count, 1) + compare(control.checked, true) + + // attempt uncheck + keyClick(Qt.Key_Space) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 1) + compare(control.checked, true) + + // no change + var keys = [Qt.Key_Enter, Qt.Key_Return, Qt.Key_Escape, Qt.Key_Tab] + for (var i = 0; i < keys.length; ++i) { + keyClick(keys[i]) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 1) + compare(control.checked, true) + } + + control.destroy() + } + + Component { + id: twoRadioButtones + Item { + property RadioButton rb1: RadioButton { id: rb1 } + property RadioButton rb2: RadioButton { id: rb2; checked: rb1.checked; enabled: false } + } + } + + function test_binding() { + var container = twoRadioButtones.createObject(testCase) + + compare(container.rb1.checked, false) + compare(container.rb2.checked, false) + + container.rb1.checked = true + compare(container.rb1.checked, true) + compare(container.rb2.checked, true) + + container.rb1.checked = false + compare(container.rb1.checked, false) + compare(container.rb2.checked, false) + + container.destroy() + } +} diff --git a/tests/auto/controls/data/tst_scrollbar.qml b/tests/auto/controls/data/tst_scrollbar.qml new file mode 100644 index 00000000..92c7ed48 --- /dev/null +++ b/tests/auto/controls/data/tst_scrollbar.qml @@ -0,0 +1,192 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import QtQuick.Controls 2.0 + +TestCase { + id: testCase + width: 400 + height: 400 + visible: true + when: windowShown + name: "ScrollBar" + + SignalSpy{ + id: pressedSpy + signalName: "pressedChanged" + } + + Component { + id: scrollBar + ScrollBar { } + } + + Component { + id: flickable + Flickable { + width: 100 + height: 100 + contentWidth: 200 + contentHeight: 200 + boundsBehavior: Flickable.StopAtBounds + flickableDirection: Flickable.HorizontalAndVerticalFlick + } + } + + function init() { + verify(!pressedSpy.target) + compare(pressedSpy.count, 0) + } + + function cleanup() { + pressedSpy.target = null + pressedSpy.clear() + } + + function test_defaults() { + var control = scrollBar.createObject(testCase) + verify(control) + verify(control.handle) + compare(control.size, 0.0) + compare(control.position, 0.0) + compare(control.active, false) + compare(control.orientation, Qt.Vertical) + control.destroy() + } + + function test_attach() { + var container = flickable.createObject(testCase) + waitForRendering(container) + + var vertical = scrollBar.createObject() + verify(!vertical.parent) + container.AbstractScrollBar.vertical = vertical + compare(vertical.parent, container) + compare(vertical.orientation, Qt.Vertical) + compare(vertical.size, container.visibleArea.heightRatio) + compare(vertical.position, container.visibleArea.yPosition) + + var horizontal = scrollBar.createObject() + verify(!horizontal.parent) + container.AbstractScrollBar.horizontal = horizontal + compare(horizontal.parent, container) + compare(horizontal.orientation, Qt.Horizontal) + compare(horizontal.size, container.visibleArea.widthRatio) + compare(horizontal.position, container.visibleArea.xPosition) + + var velocity = container.maximumFlickVelocity + + compare(container.flicking, false) + container.flick(-velocity, -velocity) + compare(container.flicking, true) + tryCompare(container, "flicking", false) + + compare(vertical.size, container.visibleArea.heightRatio) + compare(vertical.position, container.visibleArea.yPosition) + compare(horizontal.size, container.visibleArea.widthRatio) + compare(horizontal.position, container.visibleArea.xPosition) + + compare(container.flicking, false) + container.flick(velocity, velocity) + compare(container.flicking, true) + tryCompare(container, "flicking", false) + + compare(vertical.size, container.visibleArea.heightRatio) + compare(vertical.position, container.visibleArea.yPosition) + compare(horizontal.size, container.visibleArea.widthRatio) + compare(horizontal.position, container.visibleArea.xPosition) + + container.destroy() + } + + function test_mouse_data() { + return [ + { tag: "horizontal", properties: { visible: true, orientation: Qt.Horizontal, width: testCase.width } }, + { tag: "vertical", properties: { visible: true, orientation: Qt.Vertical, height: testCase.height } } + ] + } + + function test_mouse(data) { + var control = scrollBar.createObject(testCase, data.properties) + + pressedSpy.target = control + verify(pressedSpy.valid) + + mousePress(control, 0, 0, Qt.LeftButton) + compare(pressedSpy.count, 1) + compare(control.pressed, true) + compare(control.position, 0.0) + + mouseMove(control, -control.width, -control.height, 0, Qt.LeftButton) + compare(pressedSpy.count, 1) + compare(control.pressed, true) + compare(control.position, 0.0) + + mouseMove(control, control.width * 0.5, control.height * 0.5, 0, Qt.LeftButton) + compare(pressedSpy.count, 1) + compare(control.pressed, true) + verify(control.position, 0.5) + + mouseRelease(control, control.width * 0.5, control.height * 0.5, Qt.LeftButton) + compare(pressedSpy.count, 2) + compare(control.pressed, false) + compare(control.position, 0.5) + + mousePress(control, control.width, control.height, Qt.LeftButton) + compare(pressedSpy.count, 3) + compare(control.pressed, true) + compare(control.position, 0.5) + + mouseMove(control, control.width * 2, control.height * 2, 0, Qt.LeftButton) + compare(pressedSpy.count, 3) + compare(control.pressed, true) + compare(control.position, 1.0) + + mouseMove(control, control.width * 0.75, control.height * 0.75, 0, Qt.LeftButton) + compare(pressedSpy.count, 3) + compare(control.pressed, true) + compare(control.position, 0.75) + + mouseRelease(control, control.width * 0.25, control.height * 0.25, Qt.LeftButton) + compare(pressedSpy.count, 4) + compare(control.pressed, false) + compare(control.position, 0.25) + + control.destroy() + } +} diff --git a/tests/auto/controls/data/tst_scrollindicator.qml b/tests/auto/controls/data/tst_scrollindicator.qml new file mode 100644 index 00000000..36149827 --- /dev/null +++ b/tests/auto/controls/data/tst_scrollindicator.qml @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import QtQuick.Controls 2.0 + +TestCase { + id: testCase + width: 400 + height: 400 + visible: true + when: windowShown + name: "ScrollIndicator" + + Component { + id: scrollIndicator + ScrollIndicator { } + } + + Component { + id: flickable + Flickable { + width: 100 + height: 100 + contentWidth: 200 + contentHeight: 200 + boundsBehavior: Flickable.StopAtBounds + flickableDirection: Flickable.HorizontalAndVerticalFlick + } + } + + function test_defaults() { + var control = scrollIndicator.createObject(testCase) + verify(control) + verify(control.indicator) + compare(control.size, 0.0) + compare(control.position, 0.0) + compare(control.active, false) + compare(control.orientation, Qt.Vertical) + control.destroy() + } + + function test_attach() { + var container = flickable.createObject(testCase) + waitForRendering(container) + + var vertical = scrollIndicator.createObject() + verify(!vertical.parent) + container.AbstractScrollIndicator.vertical = vertical + compare(vertical.parent, container) + compare(vertical.orientation, Qt.Vertical) + compare(vertical.size, container.visibleArea.heightRatio) + compare(vertical.position, container.visibleArea.yPosition) + + var horizontal = scrollIndicator.createObject() + verify(!horizontal.parent) + container.AbstractScrollIndicator.horizontal = horizontal + compare(horizontal.parent, container) + compare(horizontal.orientation, Qt.Horizontal) + compare(horizontal.size, container.visibleArea.widthRatio) + compare(horizontal.position, container.visibleArea.xPosition) + + var velocity = container.maximumFlickVelocity + + compare(container.flicking, false) + container.flick(-velocity, -velocity) + compare(container.flicking, true) + tryCompare(container, "flicking", false) + + compare(vertical.size, container.visibleArea.heightRatio) + compare(vertical.position, container.visibleArea.yPosition) + compare(horizontal.size, container.visibleArea.widthRatio) + compare(horizontal.position, container.visibleArea.xPosition) + + compare(container.flicking, false) + container.flick(velocity, velocity) + compare(container.flicking, true) + tryCompare(container, "flicking", false) + + compare(vertical.size, container.visibleArea.heightRatio) + compare(vertical.position, container.visibleArea.yPosition) + compare(horizontal.size, container.visibleArea.widthRatio) + compare(horizontal.position, container.visibleArea.xPosition) + + container.destroy() + } +} diff --git a/tests/auto/controls/data/tst_slider.qml b/tests/auto/controls/data/tst_slider.qml new file mode 100644 index 00000000..5b74f1a6 --- /dev/null +++ b/tests/auto/controls/data/tst_slider.qml @@ -0,0 +1,283 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import QtQuick.Controls 2.0 + +TestCase { + id: testCase + width: 400 + height: 400 + visible: true + when: windowShown + name: "Slider" + + SignalSpy{ + id: pressedSpy + signalName: "pressedChanged" + } + + Component { + id: slider + Slider { } + } + + function init() { + verify(!pressedSpy.target) + compare(pressedSpy.count, 0) + } + + function cleanup() { + pressedSpy.target = null + pressedSpy.clear() + } + + function test_defaults() { + var control = slider.createObject(testCase) + verify(control) + verify(control.handle) + verify(control.track) + compare(control.value, 0) + compare(control.position, 0) + compare(control.visualPosition, 0) + compare(control.stepSize, 0) + compare(control.snapMode, AbstractSlider.NoSnap) + compare(control.pressed, false) + compare(control.orientation, Qt.Horizontal) + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + control.destroy() + } + + function test_layoutDirection() { + var control = slider.createObject(testCase) + + verify(!control.LayoutMirroring.enabled) + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + + control.layoutDirection = Qt.RightToLeft + compare(control.layoutDirection, Qt.RightToLeft) + compare(control.effectiveLayoutDirection, Qt.RightToLeft) + + control.LayoutMirroring.enabled = true + compare(control.layoutDirection, Qt.RightToLeft) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + + control.layoutDirection = Qt.LeftToRight + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.RightToLeft) + + control.LayoutMirroring.enabled = false + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + + control.destroy() + } + + function test_visualPosition() { + var control = slider.createObject(testCase, {value: 0.25}) + compare(control.value, 0.25) + compare(control.visualPosition, 0.25) + + control.layoutDirection = Qt.RightToLeft + compare(control.visualPosition, 0.75) + + control.LayoutMirroring.enabled = true + compare(control.visualPosition, 0.25) + + control.layoutDirection = Qt.LeftToRight + compare(control.visualPosition, 0.75) + + control.LayoutMirroring.enabled = false + compare(control.visualPosition, 0.25) + + control.destroy() + } + + function test_orientation() { + var control = slider.createObject(testCase) + compare(control.orientation, Qt.Horizontal) + verify(control.width > control.height) + control.orientation = Qt.Vertical + compare(control.orientation, Qt.Vertical) + verify(control.width < control.height) + control.destroy() + } + + function test_mouse_data() { + return [ + { tag: "horizontal", orientation: Qt.Horizontal }, + { tag: "vertical", orientation: Qt.Vertical } + ] + } + + function test_mouse(data) { + var control = slider.createObject(testCase, {orientation: data.orientation}) + + pressedSpy.target = control + verify(pressedSpy.valid) + + mousePress(control, 0, 0, Qt.LeftButton) + compare(pressedSpy.count, 1) + compare(control.pressed, true) + compare(control.value, 0.0) + compare(control.position, 0.0) + + mouseMove(control, -control.width, -control.height, 0, Qt.LeftButton) + compare(pressedSpy.count, 1) + compare(control.pressed, true) + compare(control.value, 0.0) + compare(control.position, 0.0) + + mouseMove(control, control.width * 0.5, control.height * 0.5, 0, Qt.LeftButton) + compare(pressedSpy.count, 1) + compare(control.pressed, true) + compare(control.value, 0.0) + verify(control.position, 0.5) + + mouseRelease(control, control.width * 0.5, control.height * 0.5, Qt.LeftButton) + compare(pressedSpy.count, 2) + compare(control.pressed, false) + compare(control.value, 0.5) + compare(control.position, 0.5) + + mousePress(control, control.width, control.height, Qt.LeftButton) + compare(pressedSpy.count, 3) + compare(control.pressed, true) + compare(control.value, 0.5) + compare(control.position, 0.5) + + mouseMove(control, control.width * 2, control.height * 2, 0, Qt.LeftButton) + compare(pressedSpy.count, 3) + compare(control.pressed, true) + compare(control.value, 0.5) + compare(control.position, 1.0) + + mouseMove(control, control.width * 0.75, control.height * 0.75, 0, Qt.LeftButton) + compare(pressedSpy.count, 3) + compare(control.pressed, true) + compare(control.value, 0.5) + verify(control.position >= 0.75) + + mouseRelease(control, control.width * 0.25, control.height * 0.25, Qt.LeftButton) + compare(pressedSpy.count, 4) + compare(control.pressed, false) + compare(control.value, control.position) + verify(control.value <= 0.25 && control.value >= 0.0) + verify(control.position <= 0.25 && control.position >= 0.0) + + control.destroy() + } + + function test_keys_data() { + return [ + { tag: "horizontal", orientation: Qt.Horizontal, decrease: Qt.Key_Left, increase: Qt.Key_Right }, + { tag: "vertical", orientation: Qt.Vertical, decrease: Qt.Key_Down, increase: Qt.Key_Up } + ] + } + + function test_keys(data) { + var control = slider.createObject(testCase, {orientation: data.orientation}) + + var pressedCount = 0 + + pressedSpy.target = control + verify(pressedSpy.valid) + + control.forceActiveFocus() + verify(control.activeFocus) + + control.value = 0.5 + + for (var d1 = 1; d1 <= 10; ++d1) { + keyPress(data.decrease) + compare(control.pressed, true) + compare(pressedSpy.count, ++pressedCount) + + compare(control.value, Math.max(0.0, 0.5 - d1 * 0.1)) + compare(control.value, control.position) + + keyRelease(data.decrease) + compare(control.pressed, false) + compare(pressedSpy.count, ++pressedCount) + } + + for (var i1 = 1; i1 <= 20; ++i1) { + keyPress(data.increase) + compare(control.pressed, true) + compare(pressedSpy.count, ++pressedCount) + + compare(control.value, Math.min(1.0, 0.0 + i1 * 0.1)) + compare(control.value, control.position) + + keyRelease(data.increase) + compare(control.pressed, false) + compare(pressedSpy.count, ++pressedCount) + } + + control.stepSize = 0.25 + + for (var d2 = 1; d2 <= 10; ++d2) { + keyPress(data.decrease) + compare(control.pressed, true) + compare(pressedSpy.count, ++pressedCount) + + compare(control.value, Math.max(0.0, 1.0 - d2 * 0.25)) + compare(control.value, control.position) + + keyRelease(data.decrease) + compare(control.pressed, false) + compare(pressedSpy.count, ++pressedCount) + } + + for (var i2 = 1; i2 <= 10; ++i2) { + keyPress(data.increase) + compare(control.pressed, true) + compare(pressedSpy.count, ++pressedCount) + + compare(control.value, Math.min(1.0, 0.0 + i2 * 0.25)) + compare(control.value, control.position) + + keyRelease(data.increase) + compare(control.pressed, false) + compare(pressedSpy.count, ++pressedCount) + } + + control.destroy() + } +} diff --git a/tests/auto/controls/data/tst_stackview.qml b/tests/auto/controls/data/tst_stackview.qml new file mode 100644 index 00000000..ac317f32 --- /dev/null +++ b/tests/auto/controls/data/tst_stackview.qml @@ -0,0 +1,284 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import QtQuick.Controls 2.0 + +TestCase { + id: testCase + width: 200 + height: 200 + visible: true + when: windowShown + name: "StackView" + + Item { id: item } + TextField { id: textField } + Component { id: component; Item { } } + + Component { + id: stackView + StackView { } + } + + function test_defaults() { + var control = stackView.createObject(testCase) + verify(control) + verify(control.delegate) + compare(control.depth, 0) + compare(control.busy, false) + compare(control.currentItem, null) + compare(control.initialItem, null) + control.destroy() + } + + function test_initialItem() { + var control1 = stackView.createObject(testCase, {initialItem: item}) + compare(control1.currentItem, item) + control1.destroy() + + var control2 = stackView.createObject(testCase, {initialItem: component}) + verify(control2.currentItem) + control2.destroy() + } + + function test_currentItem() { + var control = stackView.createObject(testCase, {initialItem: item}) + compare(control.currentItem, item) + control.push(component) + verify(control.currentItem !== item) + control.pop({immediate: true}) + compare(control.currentItem, item) + control.destroy() + } + + function test_busy() { + var control = stackView.createObject(testCase) + compare(control.busy, false) + control.push(component) + compare(control.busy, false) + control.push(component) + compare(control.busy, true) + tryCompare(control, "busy", false) + control.pop() + compare(control.busy, true) + tryCompare(control, "busy", false) + control.destroy() + } + + function test_status() { + var control = stackView.createObject(testCase) + + var item1 = component.createObject(control) + compare(item1.Stack.status, Stack.Inactive) + control.push(item1) + compare(item1.Stack.status, Stack.Active) + + var item2 = component.createObject(control) + compare(item2.Stack.status, Stack.Inactive) + control.push(item2) + compare(item2.Stack.status, Stack.Activating) + compare(item1.Stack.status, Stack.Deactivating) + tryCompare(item2.Stack, "status", Stack.Active) + tryCompare(item1.Stack, "status", Stack.Inactive) + + control.pop() + compare(item2.Stack.status, Stack.Deactivating) + compare(item1.Stack.status, Stack.Activating) + tryCompare(item2.Stack, "status", Stack.Inactive) + tryCompare(item1.Stack, "status", Stack.Active) + + control.destroy() + } + + function test_depth() { + var control = stackView.createObject(testCase) + compare(control.depth, 0) + control.push(item) + compare(control.depth, 1) + control.push(item) + compare(control.depth, 2) + control.pop() + compare(control.depth, 1) + control.push(component) + compare(control.depth, 2) + control.pop() + compare(control.depth, 1) + control.pop() // ignored + compare(control.depth, 1) + control.clear() + compare(control.depth, 0) + control.destroy() + } + + function test_size() { + var container = component.createObject(testCase, {width: 200, height: 200}) + var control = stackView.createObject(container, {width: 100, height: 100}) + container.width += 10 + container.height += 20 + compare(control.width, 100) + compare(control.height, 100) + container.destroy() + } + + function test_focus() { + var control = stackView.createObject(testCase, {initialItem: item, width: 200, height: 200}) + + control.forceActiveFocus() + verify(control.activeFocus) + + control.push({item: textField, immediate: true}) + compare(control.currentItem, textField) + textField.forceActiveFocus() + verify(textField.activeFocus) + + control.pop({immediate: true}) + compare(control.currentItem, item) + verify(control.activeFocus) + verify(!textField.activeFocus) + + control.destroy() + } + + function test_find() { + var control = stackView.createObject(testCase) + + var item1 = component.createObject(control, {objectName: "1"}) + var item2 = component.createObject(control, {objectName: "2"}) + var item3 = component.createObject(control, {objectName: "3"}) + + control.push(item1, {immediate: true}) + control.push(item2, {immediate: true}) + control.push(item3, {immediate: true}) + + compare(control.find(function(item, index) { return index === 0 }), item1) + compare(control.find(function(item) { return item.objectName === "1" }), item1) + + compare(control.find(function(item, index) { return index === 1 }), item2) + compare(control.find(function(item) { return item.objectName === "2" }), item2) + + compare(control.find(function(item, index) { return index === 2 }), item3) + compare(control.find(function(item) { return item.objectName === "3" }), item3) + + compare(control.find(function() { return false }), null) + compare(control.find(function() { return true }), item3) + + control.destroy() + } + + function test_get() { + var control = stackView.createObject(testCase) + + control.push([item, component, component]) + + verify(!control.get(0, true)) // dontLoad=true + compare(control.get(0, false), item) // dontLoad=false + + verify(!control.get(1, true)) // dontLoad=true + verify(control.get(1, false)) // dontLoad=false + + verify(control.get(2, true)) // dontLoad=true + verify(control.get(2, false)) // dontLoad=false + + control.destroy() + } + + function test_pushpop() { + var control = stackView.createObject(testCase) + + var item1 = component.createObject(control, {objectName:"1"}) + compare(control.push(item1), item1) + compare(control.depth, 1) + compare(control.currentItem, item1) + + var item2 = component.createObject(control, {objectName:"2"}) + compare(control.push({item: item2}), item2) + compare(control.depth, 2) + compare(control.currentItem, item2) + + var item3 = component.createObject(control, {objectName:"3"}) + compare(control.push(item3, {}, true), item3) + compare(control.depth, 3) + compare(control.currentItem, item3) + + var item4 = component.createObject(control, {objectName:"4"}) + compare(control.push(item4, {}, true, true), item4) + compare(control.depth, 3) + compare(control.currentItem, item4) + + var item5 = component.createObject(control, {objectName:"5"}) + compare(control.push({item:item5, immediate:true, replace:true}), item5) + compare(control.depth, 3) + compare(control.currentItem, item5) + + var item6 = control.push(component, {objectName:"6"}) + compare(control.depth, 4) + compare(control.currentItem, item6) + + var item7 = control.push({item:component, properties:{objectName:"7"}}) + compare(control.depth, 5) + compare(control.currentItem, item7) + + var item8 = component.createObject(control, {objectName:"8"}) + var item9 = component.createObject(control, {objectName:"9"}) + compare(control.push([component, {item:component, properties:{objectName:"?"}}, {item:item8}, item9]), item9) + compare(control.depth, 9) + compare(control.currentItem, item9) + + compare(control.pop(), item9) + compare(control.depth, 8) + compare(control.currentItem, item8) + + compare(control.pop(), item8) + compare(control.depth, 7) + + verify(control.pop({immediate:true})) + verify(control.pop({immediate:false})) + compare(control.depth, 5) + compare(control.currentItem, item7) + + compare(control.pop(item5), item7) + compare(control.depth, 3) + compare(control.currentItem, item5) + + control.pop(null) + compare(control.depth, 1) + compare(control.currentItem, item1) + + control.destroy() + } +} diff --git a/tests/auto/controls/data/tst_switch.qml b/tests/auto/controls/data/tst_switch.qml new file mode 100644 index 00000000..faacacfe --- /dev/null +++ b/tests/auto/controls/data/tst_switch.qml @@ -0,0 +1,287 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import QtQuick.Controls 2.0 + +TestCase { + id: testCase + width: 200 + height: 200 + visible: true + when: windowShown + name: "Switch" + + SignalSpy { + id: checkedSpy + signalName: "checkedChanged" + } + + SignalSpy { + id: pressedSpy + signalName: "pressedChanged" + } + + SignalSpy { + id: clickedSpy + signalName: "clicked" + } + + Component { + id: swtch + Switch { } + } + + function init() { + verify(!checkedSpy.target) + verify(!pressedSpy.target) + verify(!clickedSpy.target) + compare(checkedSpy.count, 0) + compare(pressedSpy.count, 0) + compare(clickedSpy.count, 0) + } + + function cleanup() { + checkedSpy.target = null + pressedSpy.target = null + clickedSpy.target = null + checkedSpy.clear() + pressedSpy.clear() + clickedSpy.clear() + } + + function test_defaults() { + var control = swtch.createObject(testCase) + verify(control) + verify(control.label) + verify(control.indicator) + compare(control.text, "") + compare(control.pressed, false) + compare(control.checked, false) + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + control.destroy() + } + + function test_layoutDirection() { + var control = swtch.createObject(testCase) + + verify(!control.LayoutMirroring.enabled) + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + + control.layoutDirection = Qt.RightToLeft + compare(control.layoutDirection, Qt.RightToLeft) + compare(control.effectiveLayoutDirection, Qt.RightToLeft) + + control.LayoutMirroring.enabled = true + compare(control.layoutDirection, Qt.RightToLeft) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + + control.layoutDirection = Qt.LeftToRight + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.RightToLeft) + + control.LayoutMirroring.enabled = false + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + + control.destroy() + } + + function test_text() { + var control = swtch.createObject(testCase) + compare(control.text, "") + control.text = "Switch" + compare(control.text, "Switch") + control.text = "" + compare(control.text, "") + control.destroy() + } + + function test_checked() { + var control = swtch.createObject(testCase) + + checkedSpy.target = control + verify(checkedSpy.valid) + + compare(control.checked, false) + compare(checkedSpy.count, 0) + + control.checked = true + compare(control.checked, true) + compare(checkedSpy.count, 1) + + control.checked = false + compare(control.checked, false) + compare(checkedSpy.count, 2) + + control.destroy() + } + + function test_mouse() { + var control = swtch.createObject(testCase) + + checkedSpy.target = control + pressedSpy.target = control + clickedSpy.target = control + verify(checkedSpy.valid) + verify(pressedSpy.valid) + verify(clickedSpy.valid) + + // check + mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(pressedSpy.count, 1) + compare(control.pressed, true) + mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(clickedSpy.count, 1) + compare(checkedSpy.count, 1) + compare(pressedSpy.count, 2) + compare(control.checked, true) + compare(control.pressed, false) + + // uncheck + mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(pressedSpy.count, 3) + compare(control.pressed, true) + mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 2) + compare(pressedSpy.count, 4) + compare(control.checked, false) + compare(control.pressed, false) + + // release on the right + mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(pressedSpy.count, 5) + compare(control.pressed, true) + mouseMove(control, control.width * 2, control.height / 2, 0, Qt.LeftButton) + compare(control.pressed, true) + mouseRelease(control, control.width * 2, control.height / 2, Qt.LeftButton) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 3) + compare(pressedSpy.count, 6) + compare(control.checked, true) + compare(control.pressed, false) + + // release on the left + mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(pressedSpy.count, 7) + compare(control.pressed, true) + mouseMove(control, -control.width, control.height / 2, 0, Qt.LeftButton) + compare(control.pressed, true) + mouseRelease(control, -control.width, control.height / 2, Qt.LeftButton) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 4) + compare(pressedSpy.count, 8) + compare(control.checked, false) + compare(control.pressed, false) + + // right button + mousePress(control, control.width / 2, control.height / 2, Qt.RightButton) + compare(pressedSpy.count, 8) + compare(control.pressed, false) + mouseRelease(control, control.width / 2, control.height / 2, Qt.RightButton) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 4) + compare(pressedSpy.count, 8) + compare(control.checked, false) + compare(control.pressed, false) + + control.destroy() + } + + function test_keys() { + var control = swtch.createObject(testCase) + + checkedSpy.target = control + clickedSpy.target = control + verify(checkedSpy.valid) + verify(clickedSpy.valid) + + control.forceActiveFocus() + verify(control.activeFocus) + + // check + keyClick(Qt.Key_Space) + compare(clickedSpy.count, 1) + compare(checkedSpy.count, 1) + compare(control.checked, true) + + // uncheck + keyClick(Qt.Key_Space) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 2) + compare(control.checked, false) + + // no change + var keys = [Qt.Key_Enter, Qt.Key_Return, Qt.Key_Escape, Qt.Key_Tab] + for (var i = 0; i < keys.length; ++i) { + keyClick(keys[i]) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 2) + compare(control.checked, false) + } + + control.destroy() + } + + Component { + id: twoSwitches + Item { + property Switch sw1: Switch { id: sw1 } + property Switch sw2: Switch { id: sw2; checked: sw1.checked; enabled: false } + } + } + + function test_binding() { + var container = twoSwitches.createObject(testCase) + + compare(container.sw1.checked, false) + compare(container.sw2.checked, false) + + container.sw1.checked = true + compare(container.sw1.checked, true) + compare(container.sw2.checked, true) + + container.sw1.checked = false + compare(container.sw1.checked, false) + compare(container.sw2.checked, false) + + container.destroy() + } +} diff --git a/tests/auto/controls/data/tst_togglebutton.qml b/tests/auto/controls/data/tst_togglebutton.qml new file mode 100644 index 00000000..834852c5 --- /dev/null +++ b/tests/auto/controls/data/tst_togglebutton.qml @@ -0,0 +1,287 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import QtQuick.Controls 2.0 + +TestCase { + id: testCase + width: 200 + height: 200 + visible: true + when: windowShown + name: "ToggleButton" + + SignalSpy { + id: checkedSpy + signalName: "checkedChanged" + } + + SignalSpy { + id: pressedSpy + signalName: "pressedChanged" + } + + SignalSpy { + id: clickedSpy + signalName: "clicked" + } + + Component { + id: toggleButton + ToggleButton { } + } + + function init() { + verify(!checkedSpy.target) + verify(!pressedSpy.target) + verify(!clickedSpy.target) + compare(checkedSpy.count, 0) + compare(pressedSpy.count, 0) + compare(clickedSpy.count, 0) + } + + function cleanup() { + checkedSpy.target = null + pressedSpy.target = null + clickedSpy.target = null + checkedSpy.clear() + pressedSpy.clear() + clickedSpy.clear() + } + + function test_defaults() { + var control = toggleButton.createObject(testCase) + verify(control) + verify(control.label) + verify(control.indicator) + compare(control.text, "") + compare(control.pressed, false) + compare(control.checked, false) + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + control.destroy() + } + + function test_layoutDirection() { + var control = toggleButton.createObject(testCase) + + verify(!control.LayoutMirroring.enabled) + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + + control.layoutDirection = Qt.RightToLeft + compare(control.layoutDirection, Qt.RightToLeft) + compare(control.effectiveLayoutDirection, Qt.RightToLeft) + + control.LayoutMirroring.enabled = true + compare(control.layoutDirection, Qt.RightToLeft) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + + control.layoutDirection = Qt.LeftToRight + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.RightToLeft) + + control.LayoutMirroring.enabled = false + compare(control.layoutDirection, Qt.LeftToRight) + compare(control.effectiveLayoutDirection, Qt.LeftToRight) + + control.destroy() + } + + function test_text() { + var control = toggleButton.createObject(testCase) + compare(control.text, "") + control.text = "ToggleButton" + compare(control.text, "ToggleButton") + control.text = "" + compare(control.text, "") + control.destroy() + } + + function test_checked() { + var control = toggleButton.createObject(testCase) + + checkedSpy.target = control + verify(checkedSpy.valid) + + compare(control.checked, false) + compare(checkedSpy.count, 0) + + control.checked = true + compare(control.checked, true) + compare(checkedSpy.count, 1) + + control.checked = false + compare(control.checked, false) + compare(checkedSpy.count, 2) + + control.destroy() + } + + function test_mouse() { + var control = toggleButton.createObject(testCase) + + checkedSpy.target = control + pressedSpy.target = control + clickedSpy.target = control + verify(checkedSpy.valid) + verify(pressedSpy.valid) + verify(clickedSpy.valid) + + // check + mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(pressedSpy.count, 1) + compare(control.pressed, true) + mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(clickedSpy.count, 1) + compare(checkedSpy.count, 1) + compare(pressedSpy.count, 2) + compare(control.checked, true) + compare(control.pressed, false) + + // uncheck + mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(pressedSpy.count, 3) + compare(control.pressed, true) + mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 2) + compare(pressedSpy.count, 4) + compare(control.checked, false) + compare(control.pressed, false) + + // release on the right + mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(pressedSpy.count, 5) + compare(control.pressed, true) + mouseMove(control, control.width * 2, control.height / 2, 0, Qt.LeftButton) + compare(control.pressed, true) + mouseRelease(control, control.width * 2, control.height / 2, Qt.LeftButton) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 3) + compare(pressedSpy.count, 6) + compare(control.checked, true) + compare(control.pressed, false) + + // release on the left + mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) + compare(pressedSpy.count, 7) + compare(control.pressed, true) + mouseMove(control, -control.width, control.height / 2, 0, Qt.LeftButton) + compare(control.pressed, true) + mouseRelease(control, -control.width, control.height / 2, Qt.LeftButton) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 4) + compare(pressedSpy.count, 8) + compare(control.checked, false) + compare(control.pressed, false) + + // right button + mousePress(control, control.width / 2, control.height / 2, Qt.RightButton) + compare(pressedSpy.count, 8) + compare(control.pressed, false) + mouseRelease(control, control.width / 2, control.height / 2, Qt.RightButton) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 4) + compare(pressedSpy.count, 8) + compare(control.checked, false) + compare(control.pressed, false) + + control.destroy() + } + + function test_keys() { + var control = toggleButton.createObject(testCase) + + checkedSpy.target = control + clickedSpy.target = control + verify(checkedSpy.valid) + verify(clickedSpy.valid) + + control.forceActiveFocus() + verify(control.activeFocus) + + // check + keyClick(Qt.Key_Space) + compare(clickedSpy.count, 1) + compare(checkedSpy.count, 1) + compare(control.checked, true) + + // uncheck + keyClick(Qt.Key_Space) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 2) + compare(control.checked, false) + + // no change + var keys = [Qt.Key_Enter, Qt.Key_Return, Qt.Key_Escape, Qt.Key_Tab] + for (var i = 0; i < keys.length; ++i) { + keyClick(keys[i]) + compare(clickedSpy.count, 2) + compare(checkedSpy.count, 2) + compare(control.checked, false) + } + + control.destroy() + } + + Component { + id: twoToggleButtones + Item { + property ToggleButton tb1: ToggleButton { id: tb1 } + property ToggleButton tb2: ToggleButton { id: tb2; checked: tb1.checked; enabled: false } + } + } + + function test_binding() { + var container = twoToggleButtones.createObject(testCase) + + compare(container.tb1.checked, false) + compare(container.tb2.checked, false) + + container.tb1.checked = true + compare(container.tb1.checked, true) + compare(container.tb2.checked, true) + + container.tb1.checked = false + compare(container.tb1.checked, false) + compare(container.tb2.checked, false) + + container.destroy() + } +} diff --git a/tests/auto/controls/data/tst_toolbar.qml b/tests/auto/controls/data/tst_toolbar.qml new file mode 100644 index 00000000..683a0918 --- /dev/null +++ b/tests/auto/controls/data/tst_toolbar.qml @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import QtQuick.Controls 2.0 + +TestCase { + id: testCase + width: 400 + height: 400 + visible: true + when: windowShown + name: "ToolBar" + + Component { + id: toolBar + ToolBar { } + } + + Component { + id: oneChildBar + GroupBox { + Item { + implicitWidth: 100 + implicitHeight: 30 + } + } + } + + Component { + id: twoChildrenBar + GroupBox { + Item { + implicitWidth: 100 + implicitHeight: 30 + } + Item { + implicitWidth: 200 + implicitHeight: 60 + } + } + } + + function test_defaults() { + var control = toolBar.createObject(testCase) + verify(control.contentItem) + compare(control.contentWidth, 0) + compare(control.contentHeight, 0) + control.destroy() + } + + function test_oneChild() { + var control = oneChildBar.createObject(testCase) + compare(control.contentWidth, 100) + compare(control.contentHeight, 30) + verify(control.implicitWidth > 100) + verify(control.implicitHeight > 30) + control.destroy() + } + + function test_twoChildren() { + var control = twoChildrenBar.createObject(testCase) + compare(control.contentWidth, 0) + compare(control.contentHeight, 0) + verify(control.implicitWidth > 0) + verify(control.implicitHeight > 0) + control.destroy() + } +} diff --git a/tests/auto/controls/data/tst_toolbutton.qml b/tests/auto/controls/data/tst_toolbutton.qml new file mode 100644 index 00000000..f7f98a5d --- /dev/null +++ b/tests/auto/controls/data/tst_toolbutton.qml @@ -0,0 +1,172 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import QtQuick.Controls 2.0 + +TestCase { + id: testCase + width: 200 + height: 200 + visible: true + when: windowShown + name: "ToolButton" + + SignalSpy { + id: pressedSpy + signalName: "pressedChanged" + } + + SignalSpy { + id: clickedSpy + signalName: "clicked" + } + + Component { + id: toolButton + ToolButton { } + } + + function init() { + verify(!pressedSpy.target) + verify(!clickedSpy.target) + compare(pressedSpy.count, 0) + compare(clickedSpy.count, 0) + } + + function cleanup() { + pressedSpy.target = null + clickedSpy.target = null + pressedSpy.clear() + clickedSpy.clear() + } + + function test_defaults() { + var control = toolButton.createObject(testCase) + verify(control) + verify(control.label) + compare(control.text, "") + compare(control.pressed, false) + control.destroy() + } + + function test_text() { + var control = toolButton.createObject(testCase) + compare(control.text, "") + control.text = "ToolButton" + compare(control.text, "ToolButton") + control.text = "" + compare(control.text, "") + control.destroy() + } + + function test_mouse() { + var control = toolButton.createObject(testCase) + + pressedSpy.target = control + clickedSpy.target = control + verify(pressedSpy.valid) + verify(clickedSpy.valid) + + // check + mousePress(control, control.width / 2, control.height / 2, Qt.LeftToolButton) + compare(pressedSpy.count, 1) + compare(control.pressed, true) + mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftToolButton) + compare(clickedSpy.count, 1) + compare(pressedSpy.count, 2) + compare(control.pressed, false) + + // uncheck + mousePress(control, control.width / 2, control.height / 2, Qt.LeftToolButton) + compare(pressedSpy.count, 3) + compare(control.pressed, true) + mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftToolButton) + compare(clickedSpy.count, 2) + compare(pressedSpy.count, 4) + compare(control.pressed, false) + + // release outside + mousePress(control, control.width / 2, control.height / 2, Qt.LeftToolButton) + compare(pressedSpy.count, 5) + compare(control.pressed, true) + mouseMove(control, control.width * 2, control.height * 2, 0, Qt.LeftToolButton) + compare(control.pressed, false) + mouseRelease(control, control.width * 2, control.height * 2, Qt.LeftToolButton) + compare(clickedSpy.count, 2) + compare(pressedSpy.count, 6) + compare(control.pressed, false) + + // right button + mousePress(control, control.width / 2, control.height / 2, Qt.RightButton) + compare(pressedSpy.count, 6) + compare(control.pressed, false) + mouseRelease(control, control.width / 2, control.height / 2, Qt.RightButton) + compare(clickedSpy.count, 2) + compare(pressedSpy.count, 6) + compare(control.pressed, false) + + control.destroy() + } + + function test_keys() { + var control = toolButton.createObject(testCase) + + clickedSpy.target = control + verify(clickedSpy.valid) + + control.forceActiveFocus() + verify(control.activeFocus) + + // check + keyClick(Qt.Key_Space) + compare(clickedSpy.count, 1) + + // uncheck + keyClick(Qt.Key_Space) + compare(clickedSpy.count, 2) + + // no change + var keys = [Qt.Key_Enter, Qt.Key_Return, Qt.Key_Escape, Qt.Key_Tab] + for (var i = 0; i < keys.length; ++i) { + keyClick(keys[i]) + compare(clickedSpy.count, 2) + } + + control.destroy() + } +} diff --git a/tests/auto/controls/tst_controls.cpp b/tests/auto/controls/tst_controls.cpp new file mode 100644 index 00000000..89cc39f0 --- /dev/null +++ b/tests/auto/controls/tst_controls.cpp @@ -0,0 +1,38 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +QUICK_TEST_MAIN(tst_controls) diff --git a/tests/auto/extras/data/tst_splitview.qml b/tests/auto/extras/data/tst_splitview.qml new file mode 100644 index 00000000..7473cc89 --- /dev/null +++ b/tests/auto/extras/data/tst_splitview.qml @@ -0,0 +1,328 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 +import QtTest 1.0 +import QtQuick.Extras 2.0 +import QtQuick.Layouts 1.0 + +TestCase { + id: testCase + name: "Tests_SplitView" + when: windowShown + width: 400 + height: 500 + visible: true + property int handleWidth: 1 + property int handleHeight: 5 + + Component { + id: splitView + SplitView { + anchors.fill: parent + property alias item1: item1 + property alias item2: item2 + handleDelegate: Rectangle { width: handleWidth; height: handleHeight; color: "black" } + + Rectangle { + id: item1 + width: 100 + height: 80 + color: "red" + } + Rectangle { + id: item2 + width: 200 + height: 90 + color: "blue" + } + } + } + + Component { + id: splitView_hide_item_after_fillWidth + SplitView { + anchors.fill: parent + property alias item3: item3 + handleDelegate: Rectangle { width: handleWidth; height: handleHeight; color: "black" } + Rectangle { + color: "yellow" + Layout.fillWidth: true + } + Rectangle { + color: "green" + Layout.minimumWidth: 100 + visible: false + } + Rectangle { + id: item3 + color: "blue" + Layout.minimumWidth: 100 + } + } + } + + function test_01_splitView() { + var view = splitView.createObject(testCase); + verify (view !== null, "splitview created is null") + waitForRendering(view) + verify (view.orientation === Qt.Horizontal) + compare (view.__items.length, 2) + compare (view.item1.x, 0) + compare (view.item1.y, 0) + compare (view.item1.width, 100) + compare (view.item1.height, 500) + compare (view.item2.x, view.item1.x + view.item1.width + handleWidth) + compare (view.item2.y, 0) + compare (view.item2.width, testCase.width - view.item1.width - handleWidth) + compare (view.item2.height, 500) + view.destroy() + } + + function test_02_splitView_initial_orientation_vertical() { + var view = splitView.createObject(testCase, {orientation:Qt.Vertical}); + verify (view !== null, "splitview created is null") + waitForRendering(view) + compare (view.orientation, Qt.Vertical) + compare (view.__items.length, 2) + compare (view.item1.x, 0) + compare (view.item1.y, 0) + compare (view.item1.width, 400) + compare (view.item1.height, 80) + compare (view.item2.x, 0) + compare (view.item2.y, view.item1.y + view.item1.height + handleHeight) + compare (view.item2.width, 400) + compare (view.item2.height, testCase.height - view.item1.height - handleHeight) + view.destroy() + } + + function test_03_orientation_change() { + var view = splitView.createObject(testCase); + verify (view !== null, "splitview created is null") + waitForRendering(view) + verify (view.orientation === Qt.Horizontal) + + view.orientation = Qt.Vertical + verify (view.orientation === Qt.Vertical) + compare (view.item1.x, 0) + compare (view.item1.y, 0) + compare (view.item1.width, 400) + compare (view.item1.height, 100) + compare (view.item2.x, 0) + // We use handleWidth rather than handleHeight, since the layout is just flipped: + compare (view.item2.y, view.item1.y + view.item1.height + handleWidth) + compare (view.item2.width, 400) + compare (view.item2.height, testCase.height - view.item1.height - handleWidth) + + view.orientation = Qt.Horizontal + verify (view.orientation === Qt.Horizontal) + compare (view.item1.x, 0) + compare (view.item1.y, 0) + compare (view.item1.width, 100) + compare (view.item1.height, 500) + compare (view.item2.x, view.item1.x + view.item1.width + handleWidth) + compare (view.item2.y, 0) + compare (view.item2.width, testCase.width - view.item1.width - handleWidth) + compare (view.item2.height, 500) + view.destroy() + } + + function test_04_hide_item() { + var view = splitView.createObject(testCase); + verify (view !== null, "splitview created is null") + waitForRendering(view) + verify (view.item1.visible) + verify (view.item2.visible) + view.item1.visible = false + verify (view.item1.visible === false) + + compare (view.item1.x, 0) + compare (view.item1.y, 0) + compare (view.item1.width, 100) + compare (view.item1.height, 500) + compare (view.item2.x, 0) + compare (view.item2.y, 0) + compare (view.item2.width, testCase.width) + compare (view.item2.height, 500) + view.destroy() + } + + function test_05_hide_fillWidth_item() { + var view = splitView.createObject(testCase); + verify (view !== null, "splitview created is null") + waitForRendering(view) + verify (view.item1.visible) + verify (view.item2.visible) + view.item2.visible = false + verify (view.item2.visible === false) + + compare (view.item1.x, 0) + compare (view.item1.y, 0) + compare (view.item1.width, 100) + compare (view.item1.height, 500) + compare (view.item2.x, view.item1.x + view.item1.width + handleWidth) + compare (view.item2.y, 0) + compare (view.item2.width, testCase.width - view.item1.width - handleWidth) + compare (view.item2.height, 500) + view.destroy() + } + + function test_hide_item_after_fillWidth() { + // QTBUG-33448 + var view = splitView_hide_item_after_fillWidth.createObject(testCase); + verify (view !== null, "splitview created is null") + waitForRendering(view) + compare (view.item3.x, view.width - view.item3.width) + view.destroy() + } + + Component { + id: item_to_add_dynamically + Rectangle { + width: 50 + height: 100 + color: "yellow" + } + } + + function test_dynamic_item_add() { + // QTBUG-35281 + var view = splitView.createObject(testCase); + verify (view !== null, "splitview created is null") + verify (view.orientation === Qt.Horizontal) + waitForRendering(view) + + var item3 = item_to_add_dynamically.createObject() + view.addItem(item3) + // reset item2 width + view.item2.width = 200 + waitForRendering(view) + + compare (view.__items.length, 3) + + compare (view.item1.x, 0) + compare (view.item1.y, 0) + compare (view.item1.width, 100) + compare (view.item1.height, 500) + + compare (view.item2.x, view.item1.x + view.item1.width + handleWidth) + compare (view.item2.y, 0) + compare (view.item2.width, 200) + compare (view.item2.height, 500) + + compare (item3.x, view.item2.x + view.item2.width + handleWidth) + compare (item3.y, 0) + compare (item3.width, testCase.width - view.item2.width - view.item1.width - (handleWidth*2)) + compare (item3.height, 500) + + view.destroy() + } + + function test_dynamic_item_add_fillWidth() { + var view = splitView.createObject(testCase); + verify (view !== null, "splitview created is null") + verify (view.orientation === Qt.Horizontal) + view.item2.Layout.fillWidth = true + waitForRendering(view) + + var item3 = item_to_add_dynamically.createObject() + view.addItem(item3) + waitForRendering(view) + + compare (view.__items.length, 3) + + compare (view.item1.x, 0) + compare (view.item1.y, 0) + compare (view.item1.width, 100) + compare (view.item1.height, 500) + + compare (view.item2.x, view.item1.x + view.item1.width + handleWidth) + compare (view.item2.y, 0) + compare (view.item2.width, testCase.width - view.item1.width - item3.width - (handleWidth*2)) + compare (view.item2.height, 500) + + compare (item3.x, view.item2.x + view.item2.width + handleWidth) + compare (item3.y, 0) + compare (item3.width, 50) + compare (item3.height, 500) + + view.destroy() + } + + Component { + id: splitViewMargins + SplitView { + anchors.fill: parent + property alias item1: item1 + property alias item2: item2 + handleDelegate: Rectangle { width: handleWidth; height: handleHeight; color: "black" } + + Rectangle { + id: item1 + width: 100 + height: 80 + color: "red" + Layout.margins: 3 + } + Rectangle { + id: item2 + width: 200 + height: 90 + color: "blue" + Layout.margins: 7 + Layout.fillWidth: true + } + } + } + + function test_item_margins() { + var view = splitViewMargins.createObject(testCase); + verify (view !== null, "splitview created is null") + verify (view.orientation === Qt.Horizontal) + compare(view.implicitWidth, 100 + 3*2 + 1 + 200 + 7*2) + waitForRendering(view) + + compare(view.item1.width, 100) + + compare(view.item2.width, testCase.width - 100 - (3*2) - handleWidth - (7*2)) + compare(view.item2.height, testCase.height - 7*2) + + view.item2.Layout.rightMargin = 0 + compare(view.item2.width, testCase.width - 100 - 3*2 - handleWidth - 7) + + view.destroy() + } +} diff --git a/tests/auto/extras/extras.pro b/tests/auto/extras/extras.pro new file mode 100644 index 00000000..29256e33 --- /dev/null +++ b/tests/auto/extras/extras.pro @@ -0,0 +1,9 @@ +TEMPLATE = app +TARGET = tst_extras +CONFIG += qmltestcase + +SOURCES += \ + $$PWD/tst_extras.cpp + +TESTDATA += \ + $$PWD/data/* diff --git a/tests/auto/extras/tst_extras.cpp b/tests/auto/extras/tst_extras.cpp new file mode 100644 index 00000000..057176d1 --- /dev/null +++ b/tests/auto/extras/tst_extras.cpp @@ -0,0 +1,38 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +QUICK_TEST_MAIN(tst_extras) -- cgit v1.2.3