2015-01-30 19:57:40 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2017-01-09 16:13:48 +00:00
|
|
|
** Copyright (C) 2017 The Qt Company Ltd.
|
2017-02-22 12:59:07 +00:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-01-30 19:57:40 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2015-03-04 15:54:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:BSD$
|
2017-02-22 12:59:07 +00:00
|
|
|
** 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 https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
**
|
|
|
|
** BSD License Usage
|
|
|
|
** Alternatively, you may use this file under the terms of the BSD license
|
|
|
|
** as follows:
|
2015-01-30 19:57:40 +00:00
|
|
|
**
|
2015-03-04 15:54:27 +00:00
|
|
|
** "Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions are
|
|
|
|
** met:
|
|
|
|
** * Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** * Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in
|
|
|
|
** the documentation and/or other materials provided with the
|
|
|
|
** distribution.
|
|
|
|
** * Neither the name of The Qt Company Ltd nor the names of its
|
|
|
|
** contributors may be used to endorse or promote products derived
|
|
|
|
** from this software without specific prior written permission.
|
2015-01-30 19:57:40 +00:00
|
|
|
**
|
2015-03-04 15:54:27 +00:00
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
2015-01-30 19:57:40 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
import QtQuick 2.2
|
|
|
|
import QtTest 1.0
|
2017-01-12 10:34:27 +00:00
|
|
|
import QtQuick.Controls 2.2
|
2015-01-30 19:57:40 +00:00
|
|
|
|
|
|
|
TestCase {
|
|
|
|
id: testCase
|
|
|
|
width: 200
|
|
|
|
height: 200
|
|
|
|
visible: true
|
|
|
|
when: windowShown
|
|
|
|
name: "ToolButton"
|
|
|
|
|
2016-10-07 12:51:51 +00:00
|
|
|
Component {
|
|
|
|
id: signalSpy
|
|
|
|
SignalSpy { }
|
2015-01-30 19:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: toolButton
|
|
|
|
ToolButton { }
|
|
|
|
}
|
|
|
|
|
2015-06-29 17:14:55 +00:00
|
|
|
function test_text() {
|
2016-12-20 11:48:27 +00:00
|
|
|
var control = createTemporaryObject(toolButton, testCase)
|
2015-01-30 19:57:40 +00:00
|
|
|
verify(control)
|
|
|
|
|
|
|
|
compare(control.text, "")
|
|
|
|
control.text = "ToolButton"
|
|
|
|
compare(control.text, "ToolButton")
|
|
|
|
control.text = ""
|
|
|
|
compare(control.text, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_mouse() {
|
2016-12-20 11:48:27 +00:00
|
|
|
var control = createTemporaryObject(toolButton, testCase)
|
2015-06-29 17:14:55 +00:00
|
|
|
verify(control)
|
2015-01-30 19:57:40 +00:00
|
|
|
|
2016-10-07 12:51:51 +00:00
|
|
|
var pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"})
|
2015-01-30 19:57:40 +00:00
|
|
|
verify(pressedSpy.valid)
|
2016-10-07 12:51:51 +00:00
|
|
|
|
|
|
|
var downSpy = signalSpy.createObject(control, {target: control, signalName: "downChanged"})
|
2016-04-12 14:19:58 +00:00
|
|
|
verify(downSpy.valid)
|
2016-10-07 12:51:51 +00:00
|
|
|
|
|
|
|
var clickedSpy = signalSpy.createObject(control, {target: control, signalName: "clicked"})
|
2015-01-30 19:57:40 +00:00
|
|
|
verify(clickedSpy.valid)
|
|
|
|
|
|
|
|
// check
|
2017-01-12 13:59:44 +00:00
|
|
|
mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(pressedSpy.count, 1)
|
2016-04-12 14:19:58 +00:00
|
|
|
compare(downSpy.count, 1)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.pressed, true)
|
2016-04-12 14:19:58 +00:00
|
|
|
compare(control.down, true)
|
2017-01-12 13:59:44 +00:00
|
|
|
mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(clickedSpy.count, 1)
|
|
|
|
compare(pressedSpy.count, 2)
|
2016-04-12 14:19:58 +00:00
|
|
|
compare(downSpy.count, 2)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.pressed, false)
|
2016-04-12 14:19:58 +00:00
|
|
|
compare(control.down, false)
|
2015-01-30 19:57:40 +00:00
|
|
|
|
|
|
|
// uncheck
|
2017-01-12 13:59:44 +00:00
|
|
|
mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(pressedSpy.count, 3)
|
2016-04-12 14:19:58 +00:00
|
|
|
compare(downSpy.count, 3)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.pressed, true)
|
2016-04-12 14:19:58 +00:00
|
|
|
compare(control.down, true)
|
2017-01-12 13:59:44 +00:00
|
|
|
mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(clickedSpy.count, 2)
|
|
|
|
compare(pressedSpy.count, 4)
|
2016-04-12 14:19:58 +00:00
|
|
|
compare(downSpy.count, 4)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.pressed, false)
|
2016-04-12 14:19:58 +00:00
|
|
|
compare(control.down, false)
|
2015-01-30 19:57:40 +00:00
|
|
|
|
|
|
|
// release outside
|
2017-01-12 13:59:44 +00:00
|
|
|
mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(pressedSpy.count, 5)
|
2016-04-12 14:19:58 +00:00
|
|
|
compare(downSpy.count, 5)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.pressed, true)
|
2016-04-12 14:19:58 +00:00
|
|
|
compare(control.down, true)
|
2017-01-20 11:55:54 +00:00
|
|
|
mouseMove(control, control.width * 2, control.height * 2)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.pressed, false)
|
2016-04-12 14:19:58 +00:00
|
|
|
compare(control.down, false)
|
2017-01-12 13:59:44 +00:00
|
|
|
mouseRelease(control, control.width * 2, control.height * 2, Qt.LeftButton)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(clickedSpy.count, 2)
|
|
|
|
compare(pressedSpy.count, 6)
|
2016-04-12 14:19:58 +00:00
|
|
|
compare(downSpy.count, 6)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.pressed, false)
|
2016-04-12 14:19:58 +00:00
|
|
|
compare(control.down, false)
|
2015-01-30 19:57:40 +00:00
|
|
|
|
|
|
|
// right button
|
|
|
|
mousePress(control, control.width / 2, control.height / 2, Qt.RightButton)
|
|
|
|
compare(pressedSpy.count, 6)
|
2016-04-12 14:19:58 +00:00
|
|
|
compare(downSpy.count, 6)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.pressed, false)
|
2016-04-12 14:19:58 +00:00
|
|
|
compare(control.down, false)
|
2015-01-30 19:57:40 +00:00
|
|
|
mouseRelease(control, control.width / 2, control.height / 2, Qt.RightButton)
|
|
|
|
compare(clickedSpy.count, 2)
|
|
|
|
compare(pressedSpy.count, 6)
|
2016-04-12 14:19:58 +00:00
|
|
|
compare(downSpy.count, 6)
|
2015-01-30 19:57:40 +00:00
|
|
|
compare(control.pressed, false)
|
2016-04-12 14:19:58 +00:00
|
|
|
compare(control.down, false)
|
2015-01-30 19:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_keys() {
|
2016-12-20 11:48:27 +00:00
|
|
|
var control = createTemporaryObject(toolButton, testCase)
|
2015-06-29 17:14:55 +00:00
|
|
|
verify(control)
|
2015-01-30 19:57:40 +00:00
|
|
|
|
2016-10-07 12:51:51 +00:00
|
|
|
var clickedSpy = signalSpy.createObject(control, {target: control, signalName: "clicked"})
|
2015-01-30 19:57:40 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2015-11-25 00:04:19 +00:00
|
|
|
|
|
|
|
function test_baseline() {
|
2016-12-20 11:48:27 +00:00
|
|
|
var control = createTemporaryObject(toolButton, testCase)
|
2015-11-25 00:04:19 +00:00
|
|
|
verify(control)
|
2016-02-04 16:34:19 +00:00
|
|
|
compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset)
|
2015-11-25 00:04:19 +00:00
|
|
|
}
|
2015-01-30 19:57:40 +00:00
|
|
|
}
|