on xenial help sign in
Add unit test and fix bug(s) exposed by unit test
commit37dabe352372e6f3c10cd4193f7ef6e6d9298a10 authorJosh Arenson <joshua.arenson@canonical.com> dateTue 9 Dec 2014, 16:35 (12 years ago) parent63d4385
3 files changed+106
qml/Components/PhysicalKeysFilter.qml+2 tests/qmltests/CMakeLists.txt+1 tests/qmltests/Components/tst_PhysicalKeysFilter.qml+103
qml/Components/PhysicalKeysFilter.qml+2
@@ -36,6 +36,7 @@ import QtQuick 2.0
3636QtObject {
3737 id: root
3838
39+ signal bothVolumeKeysPressed();
3940 signal powerPressed()
4041 signal screenshotPressed()
4142 signal volumeDownPressed()
@@ -55,6 +56,7 @@ QtObject {
5556
5657 // Power Key
5758 if (key == Qt.Key_PowerDown || key == Qt.Key_PowerOff) {
59+ powerPressed();
5860 eventAccepted = true;
5961 powerKeyPressed = true;
6062 }
tests/qmltests/CMakeLists.txt+1
@@ -27,6 +27,7 @@ add_qml_test(Components DraggingArea)
2727add_qml_test(Components EdgeDemoOverlay)
2828add_qml_test(Components LazyImage)
2929add_qml_test(Components Lockscreen)
30+add_qml_test(Components PhysicalKeysFilter)
3031add_qml_test(Components Rating)
3132add_qml_test(Components ResponsiveGridView)
3233add_qml_test(Components ResponsiveVerticalJournal IMPORT_PATHS ${qmltest_DEFAULT_IMPORT_PATHS} ${CMAKE_BINARY_DIR}/plugins)
tests/qmltests/Components/tst_PhysicalKeysFilter.qmlnew file+103
@@ -0,0 +1,103 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
4+ * Authors:
5+ * Josh Arenson <joshua.arenson@canonical.com>
6+ *
7+ * This program is free software; you can redistribute it and/or modify
8+ * it under the terms of the GNU General Public License as published by
9+ * the Free Software Foundation; version 3.
10+ *
11+ * This program is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU General Public License
17+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
18+ */
19+
20+import QtQuick 2.0
21+import QtTest 1.0
22+import "../../../qml/Components"
23+import Unity.Test 0.1 as UT
24+
25+Item {
26+
27+ property int onBothVolumeKeysPressedCount: 0
28+ property int onPowerPressedCount: 0
29+ property int onScreenshotPressedCount: 0
30+ property int onVolumeDownPressedCount: 0
31+ property int onVolumeUpPressedCount: 0
32+
33+ PhysicalKeysFilter {
34+ id: physicalKeysFilter
35+
36+ onBothVolumeKeysPressed: onBothVolumeKeysPressedCount += 1
37+ onPowerPressed: onPowerPressedCount += 1
38+ onScreenshotPressed: onScreenshotPressedCount += 1
39+ onVolumeDownPressed: onVolumeDownPressedCount += 1
40+ onVolumeUpPressed: onVolumeUpPressedCount += 1
41+ }
42+
43+ UT.UnityTestCase {
44+ name: "PhysicalKeyFilter"
45+ when: windowShown
46+
47+ function cleanup() {
48+ physicalKeysFilter.onKeyReleased(Qt.Key_PowerDown);
49+ physicalKeysFilter.onKeyReleased(Qt.Key_PowerOff);
50+ physicalKeysFilter.onKeyReleased(Qt.Key_VolumeDown);
51+ physicalKeysFilter.onKeyReleased(Qt.Key_VolumeUp);
52+
53+ onBothVolumeKeysPressedCount = 0;
54+ onPowerPressedCount = 0;
55+ onScreenshotPressedCount = 0;
56+ onVolumeDownPressedCount = 0;
57+ onVolumeUpPressedCount = 0;
58+ }
59+
60+ function test_both_volume_keys_simultaneously() {
61+ physicalKeysFilter.onKeyPressed(Qt.Key_VolumeDown);
62+ physicalKeysFilter.onKeyPressed(Qt.Key_VolumeUp);
63+
64+ compare(onBothVolumeKeysPressedCount, 1);
65+
66+ // Simulate holding the keys down
67+ sleep(3);
68+ compare(onBothVolumeKeysPressedCount, 1);
69+ }
70+
71+ function test_power_button() {
72+ physicalKeysFilter.onKeyPressed(Qt.Key_PowerDown);
73+ compare(onPowerPressedCount, 1);
74+
75+ sleep(3);
76+ compare(onPowerPressedCount, 1);
77+ }
78+
79+ function test_screenshot_buttons() {
80+ physicalKeysFilter.onKeyPressed(Qt.Key_PowerDown);
81+ physicalKeysFilter.onKeyPressed(Qt.Key_VolumeDown);
82+
83+ compare(onPowerPressedCount, 1);
84+ compare(onScreenshotPressedCount, 1);
85+ compare(onVolumeDownPressedCount, 0);
86+
87+ sleep(3);
88+ compare(onPowerPressedCount, 1);
89+ compare(onScreenshotPressedCount, 1);
90+ compare(onVolumeDownPressedCount, 0);
91+ }
92+
93+ function test_volume_down_button() {
94+ physicalKeysFilter.onKeyPressed(Qt.Key_VolumeDown);
95+ compare(onVolumeDownPressedCount, 1);
96+ }
97+
98+ function test_volume_up_button() {
99+ physicalKeysFilter.onKeyPressed(Qt.Key_VolumeUp);
100+ compare(onVolumeUpPressedCount, 1);
101+ }
102+ }
103+}