use namespaces
[test/generic/wayland-fits.git] / src / test / efl / test_window_fullscreen.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 "window.h"
24 #include "elmtestharness.h"
25
26 namespace wfits {
27 namespace test {
28 namespace efl {
29
30 class WindowFullscreenTest : public ElmTestHarness
31 {
32 public:
33         WindowFullscreenTest()
34                 : ElmTestHarness::ElmTestHarness()
35                 , window_("WindowFullscreenTest", "Window Fullscreen Test")
36                 , geometry_()
37                 , fullscreenDone_(false)
38                 , unfullscreenDone_(false)
39                 , configureDone_(false)
40                 , resizeDone_(false)
41                 , rendered_(false)
42         {
43                 return;
44         }
45
46         void setup()
47         {
48                 evas_event_callback_add(evas_object_evas_get(window_), EVAS_CALLBACK_RENDER_POST, onPostRender, this);
49                 evas_object_event_callback_add(window_, EVAS_CALLBACK_RESIZE, &onResize, this);
50                 ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_CONFIGURE, onConfigure, this);
51
52                 evas_object_smart_callback_add(window_, "fullscreen", onFullscreen, this);
53                 evas_object_smart_callback_add(window_, "unfullscreen", onUnFullscreen, this);
54
55                 window_.show();
56
57                 for(unsigned i(0); i < 5; ++i) {
58                         queueStep(boost::bind(&WindowFullscreenTest::test, boost::ref(*this)));
59                 }
60         }
61
62         void test()
63         {
64                 static bool initial(true);
65
66                 fullscreenDone_         = false;
67                 configureDone_          = false;
68                 resizeDone_             = false;
69                 unfullscreenDone_       = false;
70
71                 YIELD_UNTIL(rendered_);
72
73                 if (initial) {
74                         geometry_ = getSurfaceGeometry(window_.get_wl_surface());
75
76                         std::cout << "...initial server geometry is: "
77                                 << geometry_.x << ","
78                                 << geometry_.y << " "
79                                 << geometry_.width << "x"
80                                 << geometry_.height << std::endl;
81                         initial = false;
82                 }
83
84                 std::cout << "...asserting client geometry == server geometry == initial server geometry" << std::endl;
85                 ASSERT(isInitialGeometry());
86
87                 ASSERT(not fullscreenDone_);
88                 ASSERT(not configureDone_);
89                 ASSERT(not resizeDone_);
90
91                 std::cout << "...setting fullscreen" << std::endl;
92                 window_.fullscreen(EINA_TRUE);
93
94                 std::cout << "...checking for fullscreen events" << std::endl;
95                 YIELD_UNTIL(fullscreenDone_ and configureDone_ and resizeDone_);
96
97                 window_.checkFullscreen(EINA_TRUE);
98
99                 std::cout << "...checking client geometry == server geometry == screen geometry" << std::endl;
100                 YIELD_UNTIL(isScreenGeometry());
101
102                 configureDone_ = false;
103                 resizeDone_ = false;
104
105                 ASSERT(not unfullscreenDone_);
106
107                 std::cout << "...setting unfullscreen" << std::endl;
108                 window_.fullscreen(EINA_FALSE);
109
110                 std::cout << "...checking for unfullscreen events" << std::endl;
111                 YIELD_UNTIL(unfullscreenDone_ and configureDone_ and resizeDone_);
112
113                 window_.checkFullscreen(EINA_FALSE);
114
115                 std::cout << "...checking client geometry == server geometry == initial server geometry" << std::endl;
116                 YIELD_UNTIL(isInitialGeometry());
117         }
118
119         bool isInitialGeometry()
120         {
121                 const Geometry sg(getSurfaceGeometry(window_.get_wl_surface()));
122                 const Geometry fg(window_.getFramespaceGeometry());
123         
124                 return sg.x == geometry_.x
125                         and sg.y == geometry_.y
126                         and sg.width == geometry_.width
127                         and sg.height == geometry_.height
128                         and window_.getWidth() + fg.width == geometry_.width
129                         and window_.getHeight() + fg.height == geometry_.height
130                 ;
131                 // NOTE: server does not support client side positioning
132         }
133
134         bool isScreenGeometry()
135         {
136                 int sx, sy, sw, sh;
137                 elm_win_screen_size_get(window_, &sx, &sy, &sw, &sh);
138                 const Geometry g(getSurfaceGeometry(window_.get_wl_surface()));
139
140                 return g.x == sx
141                         and g.y == sy
142                         and g.width == sw
143                         and g.height == sh
144                         and window_.getX() == sx
145                         and window_.getY() == sy
146                         and window_.getWidth() == sw
147                         and window_.getHeight() == sh
148                 ;
149         }
150
151         static void onPostRender(void *data, Evas *e, void *info)
152         {
153                 evas_event_callback_del(e, EVAS_CALLBACK_RENDER_POST, onPostRender);
154
155                 WindowFullscreenTest *test = static_cast<WindowFullscreenTest*>(data);
156                 test->rendered_ = true;
157                 std::cout << "...got post render event" << std::endl;
158         }
159
160         static Eina_Bool onConfigure(void *data, int type, void *event)
161         {
162                 WindowFullscreenTest *test = static_cast<WindowFullscreenTest*>(data);
163                 Ecore_Wl_Event_Window_Configure *ev = static_cast<Ecore_Wl_Event_Window_Configure *>(event);
164                 test->configureDone_ = true;
165                 std::cout << "...got configure event: "
166                         << ev->x << ","
167                         << ev->y << " "
168                         << ev->w << "x"
169                         << ev->h << std::endl;
170                 return ECORE_CALLBACK_PASS_ON;
171         }
172
173         static void onResize(void *data, Evas*, Evas_Object*, void*)
174         {
175                 WindowFullscreenTest *test = static_cast<WindowFullscreenTest*>(data);
176                 test->resizeDone_ = true;
177                 std::cout << "...got resize event" << std::endl;
178         }
179
180         static void onFullscreen(void* data, Evas_Object *obj, void* event_info)
181         {
182                 WindowFullscreenTest *test = static_cast<WindowFullscreenTest*>(data);
183                 test->fullscreenDone_ = true;
184                 std::cout << "...got fullscreen event" << std::endl;
185         }
186
187         static void onUnFullscreen(void *data, Evas_Object*, void*)
188         {
189                 WindowFullscreenTest *test = static_cast<WindowFullscreenTest*>(data);
190                 test->unfullscreenDone_ = true;
191                 std::cout << "...got unfullscreen event" << std::endl;
192         }
193         
194 private:
195         Window          window_;
196         Geometry        geometry_;
197         bool            fullscreenDone_;
198         bool            unfullscreenDone_;
199         bool            configureDone_;
200         bool            resizeDone_;
201         bool            rendered_;
202 };
203
204 WAYLAND_ELM_HARNESS_TEST_CASE(WindowFullscreenTest, "Window")
205
206 } // namespace efl
207 } // namespace test
208 } // namespace wfits