harness: move pointer to origin before each test begins
[test/generic/wayland-fits.git] / src / test / core / harness.cpp
1 /*
2  * Copyright © 2013 Intel Corporation
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and
5  * its documentation for any purpose is hereby granted without fee, provided
6  * that the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation, and that the name of the copyright holders not be used in
9  * advertising or publicity pertaining to distribution of the software
10  * without specific, written prior permission.  The copyright holders make
11  * no representations about the suitability of this software for any
12  * purpose.  It is provided "as is" without express or implied warranty.
13  *
14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  */
22
23 #include "harness.h"
24
25 namespace wfits {
26 namespace test {
27 namespace core {
28
29 Client::Client(const Display& display)
30         : test::Client(display)
31         , display_(display)
32 {
33         return;
34 }
35
36 /*virtual*/
37 void Client::doYield(const unsigned time) const
38 {
39         display_.yield(time);
40 }
41
42 Harness::Harness()
43         : test::Harness::Harness()
44         , display_()
45         , client_(display_)
46 {
47         queueStep(
48                 boost::bind(&Harness::setGlobalPointerPosition, boost::ref(*this), 0, 0)
49         );
50 }
51
52 Harness::~Harness()
53 {
54         return;
55 }
56
57 void Harness::runStep(TestStep step) const
58 {
59         step();
60         yield();
61 }
62
63 void Harness::queueStep(TestStep step)
64 {
65         test::Harness::queueStep(
66                 boost::bind(&Harness::runStep, boost::ref(*this), step));
67 }
68
69 const test::Client& Harness::client() const
70 {
71         return client_;
72 }
73
74 class SimpleTest : public Harness
75 {
76 public:
77         SimpleTest() :
78                 Harness::Harness()
79                 , tested(0)
80         {
81                 return;
82         }
83
84         void setup()
85         {
86                 queueStep(boost::bind(&SimpleTest::test, boost::ref(*this)));
87         }
88
89         void test()
90         {
91                 if (++tested < 10)
92                 {
93                         queueStep(boost::bind(&SimpleTest::test, boost::ref(*this)));
94                 }
95         }
96
97         void teardown()
98         {
99                 FAIL_UNLESS_EQUAL(tested, 10);
100         }
101
102         unsigned tested;
103 };
104
105 class GlobalPointerTest : public Harness
106 {
107 public:
108         void setup()
109         {
110                 queueStep(boost::bind(&GlobalPointerTest::test, boost::ref(*this)));
111         }
112
113         void test()
114         {
115                 Position p(getGlobalPointerPosition());
116                 FAIL_IF_EQUAL(p.x, -1);
117                 FAIL_IF_EQUAL(p.y, -1);
118
119                 for (int y(0); y < 480; y += 80) {
120                         for (int x(0); x < 640; x += 80) {
121                                 setGlobalPointerPosition(x, y);
122                                 p = getGlobalPointerPosition();
123                                 FAIL_UNLESS_EQUAL(p.x, x);
124                                 FAIL_UNLESS_EQUAL(p.y, y);
125                         }
126                 }
127         }
128 };
129
130 namespace harness {
131
132         WFITS_CORE_HARNESS_TEST_CASE(SimpleTest)
133         WFITS_CORE_HARNESS_TEST_CASE(GlobalPointerTest)
134
135 } // namespace harness
136
137 } // namespace core
138 } // namespace test
139 } // namespace wfits