~robertcarr/mir/client-focus-notifications

« back to all changes in this revision

Viewing changes to tests/unit-tests/input/android/test_android_pointer_controller.cpp

  • Committer: Robert Carr
  • Date: 2013-07-22 17:54:06 UTC
  • mfrom: (706.2.171 trunk)
  • Revision ID: robert.carr@canonical.com-20130722175406-kpheyf06xm7ibc3s
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
#include "src/server/input/android/android_pointer_controller.h"
20
20
 
21
 
#include "mir_test_doubles/mock_viewable_area.h"
 
21
#include "mir_test_doubles/mock_input_region.h"
22
22
#include "mir_test/event_factory.h"
23
23
#include "mir_test/fake_shared.h"
24
24
 
30
30
namespace mi = mir::input;
31
31
namespace mia = mi::android;
32
32
namespace mis = mi::synthesis;
33
 
namespace mg = mir::graphics;
34
33
namespace geom = mir::geometry;
35
34
namespace mt = mir::test;
36
35
namespace mtd = mir::test::doubles;
46
45
public:
47
46
    void SetUp()
48
47
    {
49
 
        controller = std::make_shared<mia::PointerController>(mt::fake_shared(viewable_area));
 
48
        controller = std::make_shared<mia::PointerController>(mt::fake_shared(input_region));
50
49
    }
51
50
protected:
52
 
    mtd::MockViewableArea viewable_area;
 
51
    mtd::MockInputRegion input_region;
53
52
    std::shared_ptr<mia::PointerController> controller;
54
53
};
55
54
 
69
68
 
70
69
    static const float stored_x = 100;
71
70
    static const float stored_y = 200;
 
71
    geom::Point stored{stored_x, stored_y};
72
72
 
73
 
    EXPECT_CALL(viewable_area, view_area()).WillOnce(Return(default_view_area));
 
73
    EXPECT_CALL(input_region, confine(stored));
74
74
 
75
75
    controller->setPosition(stored_x, stored_y);
76
76
 
85
85
{
86
86
    using namespace ::testing;
87
87
 
88
 
    EXPECT_CALL(viewable_area, view_area()).Times(2)
89
 
        .WillRepeatedly(Return(default_view_area));
90
 
 
91
88
    static const float start_x = 100;
92
89
    static const float start_y = 100;
93
90
    static const float dx = 100;
94
91
    static const float dy = 50;
 
92
    geom::Point start{start_x, start_y};
 
93
    geom::Point moved{start_x + dx, start_y + dy};
 
94
 
 
95
    EXPECT_CALL(input_region, confine(start));
 
96
    EXPECT_CALL(input_region, confine(moved));
95
97
 
96
98
    controller->setPosition(start_x, start_y);
97
99
    controller->move(dx, dy);
106
108
TEST_F(AndroidPointerControllerSetup, returns_bounds_of_view_area)
107
109
{
108
110
    using namespace ::testing;
109
 
    EXPECT_CALL(viewable_area, view_area()).WillOnce(Return(default_view_area));
 
111
    EXPECT_CALL(input_region, bounding_rectangle())
 
112
        .WillOnce(Return(default_view_area));
110
113
 
111
114
    float controller_min_x, controller_min_y, controller_max_x, controller_max_y;
112
115
    controller->getBounds(&controller_min_x, &controller_min_y,
122
125
    EXPECT_EQ(controller_max_x, area_max_x);
123
126
    EXPECT_EQ(controller_max_y, area_max_y);
124
127
}
125
 
 
126
 
TEST_F(AndroidPointerControllerSetup, clips_to_view_area)
127
 
{
128
 
    using namespace ::testing;
129
 
 
130
 
    float min_x_bound = default_view_area.top_left.x.as_float();
131
 
    float min_y_bound = default_view_area.top_left.x.as_float();
132
 
    float max_x_bound = min_x_bound + default_view_area.size.width.as_float();
133
 
    float max_y_bound = min_y_bound + default_view_area.size.height.as_float();
134
 
 
135
 
    static const float invalid_lower_bound_x = min_x_bound - 1;
136
 
    static const float invalid_lower_bound_y = min_y_bound - 1;
137
 
    static const float invalid_upper_bound_x = max_x_bound + 1;
138
 
    static const float invalid_upper_bound_y = max_y_bound + 1;
139
 
 
140
 
    EXPECT_CALL(viewable_area, view_area()).Times(4).WillRepeatedly(Return(default_view_area));
141
 
 
142
 
    float bounded_x, bounded_y;
143
 
 
144
 
    controller->setPosition(invalid_lower_bound_x, 0);
145
 
    controller->getPosition(&bounded_x, &bounded_y);
146
 
    EXPECT_EQ(min_x_bound, bounded_x);
147
 
 
148
 
    controller->setPosition(0, invalid_lower_bound_y);
149
 
    controller->getPosition(&bounded_x, &bounded_y);
150
 
    EXPECT_EQ(min_y_bound, bounded_y);
151
 
 
152
 
    controller->setPosition(invalid_upper_bound_x, 0);
153
 
    controller->getPosition(&bounded_x, &bounded_y);
154
 
    EXPECT_EQ(max_x_bound, bounded_x);
155
 
 
156
 
    controller->setPosition(0, invalid_upper_bound_y);
157
 
    controller->getPosition(&bounded_x, &bounded_y);
158
 
    EXPECT_EQ(max_y_bound, bounded_y);
159
 
}