3
* Andrew Hayzen <ahayzen@gmail.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; version 3.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21
import Ubuntu.Components 1.1
22
import "../../components"
24
// See more details @ http://doc.qt.io/qt-5/qml-qttest-testcase.html
25
// Ensure qml-module-qttest is installed
26
// Execute tests with:
31
* Basic game scene with a ball in the air and ground underneath
32
* If the ball collides with anything it will store that in the
33
* property collidedWith
38
gravity: Qt.point(0, 20)
39
pixelsPerMeter: units.gu(3)
51
property var collidedWith
53
onContact: collidedWith = other
71
console.debug(">> init");
72
compare(scene.running, false, "Scene.Running was not false");
73
fuzzyCompare(ball.y, 100, 1, "ball.y was not at start position");
74
console.debug("<< init");
78
// Reset the ball position and any game states
79
console.debug(">> cleanup");
82
console.debug("<< cleanup");
85
function initTestCase() {
86
console.debug(">> initTestCase");
87
console.debug("<< initTestCase");
90
function cleanupTestCase() {
91
console.debug(">> cleanupTestCase");
92
console.debug("<< cleanupTestCase");
95
function test_ball_collides_with_ground() {
96
// When the game is running, test the ball collides with the ground
99
tryCompare(ball, "collidedWith", ground, 2000,
100
"Ball did not collided with wall")
103
function test_ball_falls() {
104
// When the game is running, test the ball falls
105
scene.running = true;
107
wait(100); // wait for the ball to fall
109
// Need to check ball.y != 100 so expect failure
110
expectFail("", "Ball.y should change (it is falling)")
112
fuzzyCompare(ball.y, 100, 1, "Ball.y equals inital y")
115
function test_ball_stationary() {
116
// When the game is not running, test the ball remains stationary
118
wait(100); // wait to check the ball doesn't fall
120
// fuzzyCompare as ball.y could be 100.abc
121
fuzzyCompare(ball.y, 100, 1, "Ball.y doesn't equal inital y")