2 #include "mockclient.h"
3 #include "mockcompositor.h"
4 #include <libds-tizen/indicator.h>
5 #include <tizen-extension-client-protocol.h>
7 #define TIZEN_INDICATOR_VERSION 1
8 class MockIndicatorCompositor : public MockCompositor
11 MockIndicatorCompositor()
12 : MockCompositor(&MockIndicatorCompositor::TestSetup, this)
14 ds_inf("%s : this(%p)", __func__, this);
16 // initialize the flags to check
17 bSurfaceDestroyed = false;
24 bOpacityModeOpque = false;
25 bOpacityModeTranslucent = false;
26 bOpacityModeTransparent = false;
27 bOpacityModeBgTransparent = false;
29 bVisibleTypeHidden = false;
30 bVisibleTypeShown = false;
33 ~MockIndicatorCompositor()
35 ds_inf("%s : this(%p)", __func__, this);
38 static void TestSetup(void *data)
40 MockIndicatorCompositor *mockComp =
41 static_cast<MockIndicatorCompositor *>(data);
42 Compositor *comp = mockComp->compositor;
44 ds_inf("%s: mockComp(%p)", __func__, mockComp);
46 // new surface listener
47 mockComp->mNewSurfaceListener.notify =
48 MockIndicatorCompositor::NewSurfaceCallback;
49 mockComp->mNewSurfaceListener.parent = mockComp;
50 ds_compositor_add_new_surface_listener(comp->compositor,
51 &mockComp->mNewSurfaceListener);
53 mockComp->mIndicator = ds_tizen_indicator_create(comp->display);
56 mockComp->mDestroyListener.notify =
57 MockIndicatorCompositor::DestroyCallback;
58 mockComp->mDestroyListener.parent = mockComp;
59 ds_tizen_indicator_add_destroy_listener(mockComp->mIndicator,
60 &mockComp->mDestroyListener);
62 // change_state listener
63 mockComp->mChangeStateListener.notify =
64 MockIndicatorCompositor::ChangeStateCallback;
65 mockComp->mChangeStateListener.parent = mockComp;
66 ds_tizen_indicator_add_change_state_listener(mockComp->mIndicator,
67 &mockComp->mChangeStateListener);
69 // change_opacity_mode listener
70 mockComp->mChangeOpacityModeListener.notify =
71 MockIndicatorCompositor::ChangeOpacityModeCallback;
72 mockComp->mChangeOpacityModeListener.parent = mockComp;
73 ds_tizen_indicator_add_change_opacity_mode_listener(
75 &mockComp->mChangeOpacityModeListener);
77 // change_visible_type listener
78 mockComp->mChangeVisibleTypeListener.notify =
79 MockIndicatorCompositor::ChangeVisibleTypeCallback;
80 mockComp->mChangeVisibleTypeListener.parent = mockComp;
81 ds_tizen_indicator_add_change_visible_type_listener(
83 &mockComp->mChangeVisibleTypeListener);
86 static void NewSurfaceCallback(struct wl_listener *listener, void *data)
88 MockIndicatorCompositor *mockComp =
89 reinterpret_cast<NewSurfaceListener *>(listener)->parent;
90 struct ds_surface *surface = static_cast<struct ds_surface *>(data);
92 ds_inf("%s: mockComp(%p), surface(%p)", __func__, mockComp, surface);
94 mockComp->mSurface = surface;
96 // del surface listener
97 mockComp->mDelSurfaceListener.notify =
98 MockIndicatorCompositor::DelSurfaceCallback;
99 mockComp->mDelSurfaceListener.parent = mockComp;
100 ds_surface_add_destroy_listener(surface,
101 &mockComp->mDelSurfaceListener);
104 static void DelSurfaceCallback(struct wl_listener *listener, void *data)
106 MockIndicatorCompositor *mockComp =
107 reinterpret_cast<DelSurfaceListener *>(listener)->parent;
108 struct ds_surface *surface = static_cast<struct ds_surface *>(data);
110 ds_inf("%s: mockComp(%p), surface(%p)", __func__, mockComp, surface);
112 if (ds_surface_get_wl_resource(mockComp->mSurface) ==
113 ds_surface_get_wl_resource(surface)) {
114 ds_inf("%s: surface is deleted.", __func__);
115 mockComp->bSurfaceDestroyed = true;
119 static void DestroyCallback(struct wl_listener *listener, void *data)
121 ds_inf("%s", __func__);
123 MockIndicatorCompositor *mockComp =
124 reinterpret_cast<DestroyListener *>(listener)->parent;
126 mockComp->bDestroyed = true;
129 static void ChangeStateCallback(struct wl_listener *listener, void *data)
131 ds_inf("%s", __func__);
133 MockIndicatorCompositor *mockComp =
134 reinterpret_cast<ChangeStateListener *>(listener)->parent;
135 struct ds_surface *surface = static_cast<struct ds_surface *>(data);
136 enum ds_tizen_indicator_state state;
138 ds_inf("%s: mockComp(%p), surface(%p)", __func__, mockComp, surface);
140 state = ds_tizen_indicator_get_state(mockComp->mIndicator,
143 if (state == DS_TIZEN_INDICATOR_STATE_ON)
144 mockComp->bStateOn = true;
145 if (state == DS_TIZEN_INDICATOR_STATE_OFF)
146 mockComp->bStateOff = true;
149 static void ChangeOpacityModeCallback(struct wl_listener *listener,
152 ds_inf("%s", __func__);
154 MockIndicatorCompositor *mockComp =
155 reinterpret_cast<ChangeVisibleTypeListener *>(listener)->parent;
156 struct ds_surface *surface = static_cast<struct ds_surface *>(data);
157 enum ds_tizen_indicator_opacity_mode opacity_mode;
159 ds_inf("%s: mockComp(%p), surface(%p)", __func__, mockComp, surface);
161 opacity_mode = ds_tizen_indicator_get_opacity_mode(mockComp->mIndicator,
164 if (opacity_mode == DS_TIZEN_INDICATOR_OPACITY_MODE_OPAQUE)
165 mockComp->bOpacityModeOpque = true;
166 if (opacity_mode == DS_TIZEN_INDICATOR_OPACITY_MODE_TRANSLUCENT)
167 mockComp->bOpacityModeTranslucent = true;
168 if (opacity_mode == DS_TIZEN_INDICATOR_OPACITY_MODE_TRANSPARENT)
169 mockComp->bOpacityModeTransparent = true;
170 if (opacity_mode == DS_TIZEN_INDICATOR_OPACITY_MODE_BG_TRANSPARENT)
171 mockComp->bOpacityModeBgTransparent = true;
174 static void ChangeVisibleTypeCallback(struct wl_listener *listener,
177 ds_inf("%s", __func__);
179 MockIndicatorCompositor *mockComp =
180 reinterpret_cast<ChangeOpacityModeListener *>(listener)->parent;
181 struct ds_surface *surface = static_cast<struct ds_surface *>(data);
182 enum ds_tizen_indicator_visible_type visible_type;
184 ds_inf("%s: mockComp(%p), surface(%p)", __func__, mockComp, surface);
186 visible_type = ds_tizen_indicator_get_visible_type(mockComp->mIndicator,
189 if (visible_type == DS_TIZEN_INDICATOR_VISIBLE_TYPE_HIDDEN)
190 mockComp->bVisibleTypeHidden = true;
191 if (visible_type == DS_TIZEN_INDICATOR_VISIBLE_TYPE_SHOWN)
192 mockComp->bVisibleTypeShown = true;
197 ds_inf("%s", __func__);
199 ds_tizen_indicator_send_flick(mIndicator, mSurface);
203 bool bSurfaceDestroyed;
207 bool bOpacityModeOpque;
208 bool bOpacityModeTranslucent;
209 bool bOpacityModeTransparent;
210 bool bOpacityModeBgTransparent;
211 bool bVisibleTypeHidden;
212 bool bVisibleTypeShown;
215 struct ds_surface *mSurface;
216 struct NewSurfaceListener : ::wl_listener {
217 MockIndicatorCompositor *parent;
219 NewSurfaceListener mNewSurfaceListener;
220 struct DelSurfaceListener : ::wl_listener {
221 MockIndicatorCompositor *parent;
223 DelSurfaceListener mDelSurfaceListener;
225 struct ds_tizen_indicator *mIndicator;
226 struct DestroyListener : ::wl_listener {
227 MockIndicatorCompositor *parent;
229 DestroyListener mDestroyListener;
230 struct ChangeStateListener : ::wl_listener {
231 MockIndicatorCompositor *parent;
233 ChangeStateListener mChangeStateListener;
234 struct ChangeOpacityModeListener : ::wl_listener {
235 MockIndicatorCompositor *parent;
237 ChangeOpacityModeListener mChangeOpacityModeListener;
238 struct ChangeVisibleTypeListener : ::wl_listener {
239 MockIndicatorCompositor *parent;
241 ChangeVisibleTypeListener mChangeVisibleTypeListener;
244 class MockIndicatorClient : public MockClient
247 MockIndicatorClient()
248 : bFlickEvent(false),
249 compositor_res(nullptr),
250 tizen_indicator(nullptr)
252 MockIndicatorClient(const struct wl_registry_listener *listener)
253 : MockClient(listener, this)
255 ds_inf("%s", __func__);
259 ~MockIndicatorClient()
261 ds_inf("%s", __func__);
264 void SetWlCompositor(struct wl_compositor *global_res)
266 ds_inf("%s", __func__);
268 compositor_res = global_res;
271 struct wl_compositor *GetWlCompositor()
273 ds_inf("%s", __func__);
275 return compositor_res;
278 void SetTizenIndicator(struct tizen_indicator *global_res)
280 ds_inf("%s", __func__);
282 tizen_indicator = global_res;
285 struct tizen_indicator *GetTizenIndicator()
287 ds_inf("%s", __func__);
289 return tizen_indicator;
296 struct wl_compositor *compositor_res;
297 struct tizen_indicator *tizen_indicator;
301 client_tizen_indicator_cb_flick(void *data, struct tizen_indicator *indicator,
302 struct wl_surface *surface, int32_t type)
304 ds_inf("%s", __func__);
306 MockIndicatorClient *client = static_cast<MockIndicatorClient *>(data);
308 client->bFlickEvent = true;
311 static const struct tizen_indicator_listener indicator_cb_listener = {
312 .flick = client_tizen_indicator_cb_flick
316 client_registry_cb_global(void *data, struct wl_registry *registry,
317 uint32_t name, const char *interface, uint32_t version)
319 ds_inf("%s", __func__);
321 MockIndicatorClient *client = static_cast<MockIndicatorClient *>(data);
322 struct wl_compositor *compositor_res;
323 struct tizen_indicator *tizen_indicator;
325 if (!strcmp(interface, "wl_compositor")) {
326 compositor_res = (struct wl_compositor *)wl_registry_bind(registry,
327 name, &wl_compositor_interface, 1);
328 if (compositor_res == nullptr) {
329 ds_err("wl_registry_bind() failed. wl_compositor resource.");
332 client->SetWlCompositor(compositor_res);
333 } else if (!strcmp(interface, "tizen_indicator")) {
334 tizen_indicator = (struct tizen_indicator *)wl_registry_bind(registry,
335 name, &tizen_indicator_interface, TIZEN_INDICATOR_VERSION);
336 if (tizen_indicator == nullptr) {
337 ds_err("wl_registry_bind() failed. tizen_indicator resource.");
340 client->SetTizenIndicator(tizen_indicator);
342 tizen_indicator_add_listener(tizen_indicator, &indicator_cb_listener,
348 client_registry_cb_global_remove(void *data, struct wl_registry *registry,
351 ds_inf("%s", __func__);
353 MockIndicatorClient *client = static_cast<MockIndicatorClient *>(data);
354 struct wl_compositor *compositor_res = client->GetWlCompositor();
355 struct tizen_indicator *indicator_res = client->GetTizenIndicator();
357 tizen_indicator_destroy(indicator_res);
358 wl_compositor_destroy(compositor_res);
361 static const struct wl_registry_listener registry_listener = {
362 .global = client_registry_cb_global,
363 .global_remove = client_registry_cb_global_remove
366 class IndicatorTest : public ::testing::Test
369 void SetUp(void) override;
370 void TearDown(void) override;
372 MockIndicatorCompositor *comp;
373 MockIndicatorClient *client;
374 struct wl_compositor *compositor_res;
375 struct tizen_indicator *indicator_res;
376 struct wl_surface *surface_res;
380 IndicatorTest::SetUp(void)
382 //ds_log_init(DS_DBG, NULL);
384 ds_inf("%s", __func__);
386 comp = new MockIndicatorCompositor();
387 client = new MockIndicatorClient(®istry_listener);
388 compositor_res = client->GetWlCompositor();
389 indicator_res = client->GetTizenIndicator();
390 surface_res = wl_compositor_create_surface(compositor_res);
396 IndicatorTest::TearDown(void)
398 ds_inf("%s", __func__);
400 wl_surface_destroy(surface_res);
402 EXPECT_TRUE(comp->bSurfaceDestroyed);
409 TEST_F(IndicatorTest, Create_P)
414 TEST_F(IndicatorTest, Req_TizenIndicatorStateOn)
416 tizen_indicator_set_state(indicator_res, surface_res,
417 TIZEN_INDICATOR_STATE_ON);
419 EXPECT_TRUE(comp->bStateOn);
420 EXPECT_FALSE(comp->bStateOff);
423 TEST_F(IndicatorTest, Req_TizenIndicatorStateOff)
425 tizen_indicator_set_state(indicator_res, surface_res,
426 TIZEN_INDICATOR_STATE_OFF);
428 EXPECT_FALSE(comp->bStateOn);
429 EXPECT_TRUE(comp->bStateOff);
432 TEST_F(IndicatorTest, Req_TizenIndicatorOpacityModeOpaque)
434 tizen_indicator_set_opacity_mode(indicator_res, surface_res,
435 TIZEN_INDICATOR_OPACITY_MODE_OPAQUE);
437 EXPECT_TRUE(comp->bOpacityModeOpque);
438 EXPECT_FALSE(comp->bOpacityModeTranslucent);
439 EXPECT_FALSE(comp->bOpacityModeTransparent);
440 EXPECT_FALSE(comp->bOpacityModeBgTransparent);
443 TEST_F(IndicatorTest, Req_TizenIndicatorOpacityModeTranslucent)
445 tizen_indicator_set_opacity_mode(indicator_res, surface_res,
446 TIZEN_INDICATOR_OPACITY_MODE_TRANSLUCENT);
448 EXPECT_FALSE(comp->bOpacityModeOpque);
449 EXPECT_TRUE(comp->bOpacityModeTranslucent);
450 EXPECT_FALSE(comp->bOpacityModeTransparent);
451 EXPECT_FALSE(comp->bOpacityModeBgTransparent);
454 TEST_F(IndicatorTest, Req_TizenIndicatorOpacityModeTransparent)
456 tizen_indicator_set_opacity_mode(indicator_res, surface_res,
457 TIZEN_INDICATOR_OPACITY_MODE_TRANSPARENT);
459 EXPECT_FALSE(comp->bOpacityModeOpque);
460 EXPECT_FALSE(comp->bOpacityModeTranslucent);
461 EXPECT_TRUE(comp->bOpacityModeTransparent);
462 EXPECT_FALSE(comp->bOpacityModeBgTransparent);
465 TEST_F(IndicatorTest, Req_TizenIndicatorOpacityModeBgTransparent)
467 tizen_indicator_set_opacity_mode(indicator_res, surface_res,
468 TIZEN_INDICATOR_OPACITY_MODE_BG_TRANSPARENT);
470 EXPECT_FALSE(comp->bOpacityModeOpque);
471 EXPECT_FALSE(comp->bOpacityModeTranslucent);
472 EXPECT_FALSE(comp->bOpacityModeTransparent);
473 EXPECT_TRUE(comp->bOpacityModeBgTransparent);
476 TEST_F(IndicatorTest, Req_TizenIndicatorVisibleTypeHidden)
478 tizen_indicator_set_visible_type(indicator_res, surface_res,
479 TIZEN_INDICATOR_VISIBLE_TYPE_HIDDEN);
481 EXPECT_TRUE(comp->bVisibleTypeHidden);
482 EXPECT_FALSE(comp->bVisibleTypeShown);
485 TEST_F(IndicatorTest, Req_TizenIndicatorVisibleTypeShown)
487 tizen_indicator_set_visible_type(indicator_res, surface_res,
488 TIZEN_INDICATOR_VISIBLE_TYPE_SHOWN);
490 EXPECT_FALSE(comp->bVisibleTypeHidden);
491 EXPECT_TRUE(comp->bVisibleTypeShown);
494 TEST_F(IndicatorTest, Ev_TizenIndicatorFlick)
496 tizen_indicator_set_state(indicator_res, surface_res,
497 TIZEN_INDICATOR_STATE_ON);
499 EXPECT_TRUE(comp->bStateOn);
505 EXPECT_TRUE(client->bFlickEvent);