2 #include "mockclient.h"
3 #include "mockcompositor.h"
4 #include <libds-tizen/screen_rotation.h>
5 #include <tizen-extension-client-protocol.h>
7 #define TIZEN_SCREEN_ROTATION_VERSION 1
9 class MockScreenRotationCompositor : public MockCompositor
12 MockScreenRotationCompositor()
13 : MockCompositor(&MockScreenRotationCompositor::TestSetup, this)
15 ds_inf("%s : this(%p)", __func__, this);
17 // initialize the flags to check
18 bSurfaceDestroyed = false;
21 bGetIgnoreOutputTransform = false;
22 bDestroyScreenRotationInfo = false;
25 ~MockScreenRotationCompositor()
27 ds_inf("%s : this(%p)", __func__, this);
30 static void TestSetup(void *data)
32 MockScreenRotationCompositor *mockComp =
33 static_cast<MockScreenRotationCompositor *>(data);
34 Compositor *comp = mockComp->compositor;
36 ds_inf("%s: mockComp(%p)", __func__, mockComp);
38 // new surface listener
39 mockComp->mNewSurfaceListener.notify =
40 MockScreenRotationCompositor::NewSurfaceCallback;
41 mockComp->mNewSurfaceListener.parent = mockComp;
42 ds_compositor_add_new_surface_listener(comp->compositor,
43 &mockComp->mNewSurfaceListener);
45 mockComp->mScreenRotation =
46 ds_tizen_screen_rotation_create(comp->display);
49 mockComp->mDestroyListener.notify =
50 MockScreenRotationCompositor::DestroyCallback;
51 mockComp->mDestroyListener.parent = mockComp;
52 ds_tizen_screen_rotation_add_destroy_listener(mockComp->mScreenRotation,
53 &mockComp->mDestroyListener);
55 // add_ignore_output_transform listener
56 mockComp->mGetIgnoreOutputTransformListener.notify =
57 MockScreenRotationCompositor::GetIgnoreOutputTransformCallback;
58 mockComp->mGetIgnoreOutputTransformListener.parent = mockComp;
59 ds_tizen_screen_rotation_add_get_ignore_output_transform_info_listener(
60 mockComp->mScreenRotation,
61 &mockComp->mGetIgnoreOutputTransformListener);
64 static void NewSurfaceCallback(struct wl_listener *listener, void *data)
66 MockScreenRotationCompositor *mockComp =
67 reinterpret_cast<NewSurfaceListener *>(listener)->parent;
68 struct ds_surface *surface = static_cast<struct ds_surface *>(data);
70 ds_inf("%s: mockComp(%p), surface(%p)", __func__, mockComp, surface);
72 mockComp->mSurface = surface;
74 // del surface listener
75 mockComp->mDelSurfaceListener.notify =
76 MockScreenRotationCompositor::DelSurfaceCallback;
77 mockComp->mDelSurfaceListener.parent = mockComp;
78 ds_surface_add_destroy_listener(surface,
79 &mockComp->mDelSurfaceListener);
82 static void DelSurfaceCallback(struct wl_listener *listener, void *data)
84 MockScreenRotationCompositor *mockComp =
85 reinterpret_cast<DelSurfaceListener *>(listener)->parent;
86 struct ds_surface *surface = static_cast<struct ds_surface *>(data);
88 ds_inf("%s: mockComp(%p), surface(%p)", __func__, mockComp, surface);
90 if (ds_surface_get_wl_resource(mockComp->mSurface) ==
91 ds_surface_get_wl_resource(surface)) {
92 ds_inf("%s: surface is deleted.", __func__);
93 mockComp->bSurfaceDestroyed = true;
97 static void DestroyCallback(struct wl_listener *listener, void *data)
99 ds_inf("%s", __func__);
101 MockScreenRotationCompositor *mockComp =
102 reinterpret_cast<DestroyListener *>(listener)->parent;
104 mockComp->bDestroyed = true;
107 static void GetIgnoreOutputTransformCallback(struct wl_listener *listener,
110 ds_inf("%s", __func__);
112 MockScreenRotationCompositor *mockComp =
113 reinterpret_cast<GetIgnoreOutputTransformListener *>(listener)->parent;
114 struct ds_tizen_screen_rotation_info *info =
115 static_cast<struct ds_tizen_screen_rotation_info *>(data);
117 ds_inf("%s: mockComp(%p), info(%p)", __func__, mockComp, info);
119 mockComp->bGetIgnoreOutputTransform = true;
121 mockComp->mInfo = info;
123 ds_tizen_screen_rotation_info_get_surface(mockComp->mInfo);
125 // info destroy listener
126 mockComp->mScreenRotationInfoDestroyListener.notify =
127 MockScreenRotationCompositor::ScreenRotationInfoDestroyCallback;
128 mockComp->mScreenRotationInfoDestroyListener.parent = mockComp;
129 ds_tizen_screen_rotation_info_add_destroy_listener(mockComp->mInfo,
130 &mockComp->mScreenRotationInfoDestroyListener);
133 static void ScreenRotationInfoDestroyCallback(struct wl_listener *listener,
136 ds_inf("%s", __func__);
138 MockScreenRotationCompositor *mockComp =
139 reinterpret_cast<ScreenRotationInfoDestroyListener *>(listener)->parent;
140 struct ds_tizen_screen_rotation_info *info =
141 static_cast<struct ds_tizen_screen_rotation_info *>(data);
143 ds_inf("%s: mockComp(%p), info(%p)", __func__, mockComp, info);
145 if (mockComp->mInfo == info) {
146 ds_inf("%s: info is deleted.", __func__);
147 mockComp->bDestroyScreenRotationInfo = true;
151 void SendIgnoreOutputTransform(uint32_t ignore)
153 ds_inf("%s", __func__);
155 ds_tizen_screen_rotation_send_ignore_output_transform(mInfo, ignore);
159 bool bSurfaceDestroyed;
161 bool bGetIgnoreOutputTransform;
162 bool bDestroyScreenRotationInfo;
165 struct ds_tizen_screen_rotation_info *mInfo;
166 struct ds_surface *mSurface;
168 struct NewSurfaceListener : ::wl_listener {
169 MockScreenRotationCompositor *parent;
171 NewSurfaceListener mNewSurfaceListener;
173 struct DelSurfaceListener : ::wl_listener {
174 MockScreenRotationCompositor *parent;
176 DelSurfaceListener mDelSurfaceListener;
178 struct ds_tizen_screen_rotation *mScreenRotation;
180 struct DestroyListener : ::wl_listener {
181 MockScreenRotationCompositor *parent;
183 DestroyListener mDestroyListener;
185 struct GetIgnoreOutputTransformListener : ::wl_listener {
186 MockScreenRotationCompositor *parent;
188 GetIgnoreOutputTransformListener mGetIgnoreOutputTransformListener;
190 struct ScreenRotationInfoDestroyListener : ::wl_listener {
191 MockScreenRotationCompositor *parent;
193 ScreenRotationInfoDestroyListener mScreenRotationInfoDestroyListener;
196 class MockScreenRotationClient : public MockClient
199 MockScreenRotationClient()
200 : bIgnoreOutputTransformEvent(false),
202 compositor_res(nullptr),
203 screen_rotation_res(nullptr)
205 MockScreenRotationClient(const struct wl_registry_listener *listener)
206 : MockClient(listener, this)
208 ds_inf("%s", __func__);
210 bIgnoreOutputTransformEvent = false;
213 ~MockScreenRotationClient()
215 ds_inf("%s", __func__);
218 void SetWlCompositor(struct wl_compositor *global_res)
220 ds_inf("%s", __func__);
222 compositor_res = global_res;
225 struct wl_compositor *GetWlCompositor()
227 ds_inf("%s", __func__);
229 return compositor_res;
232 void SetTizenScreenRotation(struct tizen_screen_rotation *resource)
234 ds_inf("%s", __func__);
236 screen_rotation_res = resource;
239 struct tizen_screen_rotation *GetTizenScreenRotation()
241 ds_inf("%s", __func__);
243 return screen_rotation_res;
247 bool bIgnoreOutputTransformEvent;
251 struct wl_compositor *compositor_res;
252 struct tizen_screen_rotation *screen_rotation_res;
256 client_tizen_screen_rotation_cb_ignore_output_transform(void *data,
257 struct tizen_screen_rotation *screen_rotation_res,
258 struct wl_surface *surface_resource, uint32_t ignore)
260 ds_inf("%s", __func__);
262 MockScreenRotationClient *client = static_cast<MockScreenRotationClient *>(data);
264 client->bIgnoreOutputTransformEvent = true;
265 client->mIgnore = ignore;
269 tizen_screen_rotation_listener screen_rotation_cb_listener = {
270 .ignore_output_transform = client_tizen_screen_rotation_cb_ignore_output_transform,
274 client_registry_cb_global(void *data, struct wl_registry *registry,
275 uint32_t name, const char *interface, uint32_t version)
277 ds_inf("%s", __func__);
279 MockScreenRotationClient *client = static_cast<MockScreenRotationClient *>(data);
280 struct wl_compositor *compositor_res;
281 struct tizen_screen_rotation *screen_rotation_res;
283 if (!strcmp(interface, "wl_compositor")) {
284 compositor_res = (struct wl_compositor *)wl_registry_bind(registry,
285 name, &wl_compositor_interface, 1);
286 if (compositor_res == nullptr) {
287 ds_err("wl_registry_bind() failed. wl_compositor resource.");
290 client->SetWlCompositor(compositor_res);
291 } else if (!strcmp(interface, "tizen_screen_rotation")) {
292 screen_rotation_res = (struct tizen_screen_rotation *)wl_registry_bind(registry,
293 name, &tizen_screen_rotation_interface, TIZEN_SCREEN_ROTATION_VERSION);
294 if (screen_rotation_res == nullptr) {
295 ds_err("wl_registry_bind() failed. tizen_screen_rotation resource.");
298 client->SetTizenScreenRotation(screen_rotation_res);
300 tizen_screen_rotation_add_listener(screen_rotation_res,
301 &screen_rotation_cb_listener, client);
306 client_registry_cb_global_remove(void *data, struct wl_registry *registry,
309 ds_inf("%s", __func__);
311 MockScreenRotationClient *client = static_cast<MockScreenRotationClient *>(data);
312 struct wl_compositor *compositor_res = client->GetWlCompositor();
313 struct tizen_screen_rotation *screen_rotation_res = client->GetTizenScreenRotation();
315 tizen_screen_rotation_destroy(screen_rotation_res);
316 wl_compositor_destroy(compositor_res);
319 static const struct wl_registry_listener registry_listener = {
320 .global = client_registry_cb_global,
321 .global_remove = client_registry_cb_global_remove
324 class ScreenRotationTest : public ::testing::Test
327 void SetUp(void) override;
328 void TearDown(void) override;
330 MockScreenRotationCompositor *comp;
331 MockScreenRotationClient *client;
332 struct wl_compositor *compositor_res;
333 struct tizen_screen_rotation *screen_rotation_res;
334 struct wl_surface *surface_res;
338 ScreenRotationTest::SetUp(void)
340 //ds_log_init(DS_DBG, NULL);
342 ds_inf("%s", __func__);
344 comp = new MockScreenRotationCompositor();
345 client = new MockScreenRotationClient(®istry_listener);
346 compositor_res = client->GetWlCompositor();
347 screen_rotation_res = client->GetTizenScreenRotation();
348 surface_res = wl_compositor_create_surface(compositor_res);
354 ScreenRotationTest::TearDown(void)
356 ds_inf("%s", __func__);
358 wl_surface_destroy(surface_res);
360 EXPECT_TRUE(comp->bSurfaceDestroyed);
366 TEST_F(ScreenRotationTest, Create_P)
371 TEST_F(ScreenRotationTest, Req_TizenScreenRotationGetIgnoreOutputTransform)
373 tizen_screen_rotation_get_ignore_output_transform(screen_rotation_res, surface_res);
375 EXPECT_TRUE(comp->bGetIgnoreOutputTransform);
378 TEST_F(ScreenRotationTest, Ev_TizenScreenRotationSurfaceRedraw)
380 tizen_screen_rotation_get_ignore_output_transform(screen_rotation_res, surface_res);
382 EXPECT_TRUE(comp->bGetIgnoreOutputTransform);
384 comp->SendIgnoreOutputTransform(1);
388 EXPECT_TRUE(client->bIgnoreOutputTransformEvent);
389 EXPECT_TRUE(client->mIgnore == 1);