tinyds: fix the SVACE issue
[platform/core/uifw/libds-tizen.git] / tests / tc_launch_effect.cpp
1 #include "tc_main.h"
2 #include "mockclient.h"
3 #include "mockcompositor.h"
4 #include <libds-tizen/launch.h>
5 #include <tizen-launch-server-protocol.h>
6 #include <tizen-launch-client-protocol.h>
7
8 #define TIZEN_EFFECT_VERSION 1
9 #define SPLASH_CLIENT_PID 321 // no meaning
10 #define CUSTOM_EFFECT_CALLEE "_CUSTOM_EFFECT_CALLEE_"
11 #define SPLASH_TYPE_IMG 0
12 #define SPLASH_TYPE_EDC 1
13
14 //code from e-tizen-testcase
15 char const *path_edc = "/usr/share/e_tizen_unittests/data/launch_splash.edj";
16 char const *path_img = "/usr/share/e_tizen_unittests/data/launchimg_splash.png";
17
18 class MockLaunchEffectCompositor : public MockCompositor
19 {
20 public:
21     MockLaunchEffectCompositor()
22         : MockCompositor(&MockLaunchEffectCompositor::TestSetup, this)
23     {
24         ds_inf("%s : this(%p)", __func__, this);
25
26         // initialize the flags to check
27         bDestroyed = false;
28         bTypeSet = false;
29         bNewSplash = false;
30         bOwner = false;
31
32         mPid = 0;
33         mEffectType = -1;
34     }
35
36     ~MockLaunchEffectCompositor()
37     {
38         ds_inf("%s : this(%p)", __func__, this);
39     }
40
41     static void TestSetup(void *data)
42     {
43         MockLaunchEffectCompositor *mockComp =
44             static_cast<MockLaunchEffectCompositor *>(data);
45         Compositor *comp = mockComp->compositor;
46
47         ds_inf("%s: mockComp(%p)", __func__, mockComp);
48
49         mockComp->mEffect = ds_tizen_launch_effect_create(comp->display);
50
51         // destroy listener
52         mockComp->mDestroyListener.notify =
53             MockLaunchEffectCompositor::DestroyCallback;
54         mockComp->mDestroyListener.parent = mockComp;
55         ds_tizen_launch_effect_add_destroy_listener(mockComp->mEffect,
56             &mockComp->mDestroyListener);
57
58         // type_set listener
59         mockComp->mTypeSetListener.notify =
60             MockLaunchEffectCompositor::TypeSetCallback;
61         mockComp->mTypeSetListener.parent = mockComp;
62         ds_tizen_launch_effect_add_type_set_listener(mockComp->mEffect,
63             &mockComp->mTypeSetListener);
64
65         // type_unset listener
66         mockComp->mTypeUnsetListener.notify =
67             MockLaunchEffectCompositor::TypeUnsetCallback;
68         mockComp->mTypeUnsetListener.parent = mockComp;
69         ds_tizen_launch_effect_add_type_unset_listener(mockComp->mEffect,
70             &mockComp->mTypeUnsetListener);
71
72         // new_splash listener
73         mockComp->mNewSplashListener.notify =
74             MockLaunchEffectCompositor::NewSplashCallback;
75         mockComp->mNewSplashListener.parent = mockComp;
76         ds_tizen_launch_effect_add_new_splash_listener(mockComp->mEffect,
77             &mockComp->mNewSplashListener);
78     }
79
80     static void DestroyCallback(struct wl_listener *listener, void *data)
81     {
82         ds_inf("%s", __func__);
83
84         MockLaunchEffectCompositor *mockComp =
85             reinterpret_cast<DestroyListener *>(listener)->parent;
86
87         mockComp->bDestroyed = true;
88     }
89
90     static void TypeSetCallback(struct wl_listener *listener, void *data)
91     {
92         struct ds_tizen_launch_effect_event_type_set *event = (ds_tizen_launch_effect_event_type_set *)data;
93         ds_inf("%s", __func__);
94
95         MockLaunchEffectCompositor *mockComp =
96             reinterpret_cast<TypeSetListener *>(listener)->parent;
97
98         mockComp->bTypeSet = true;
99         mockComp->mPid = event->pid;
100         mockComp->mEffectType = event->effect_type;
101     }
102
103     static void TypeUnsetCallback(struct wl_listener *listener, void *data)
104     {
105         struct ds_tizen_launch_effect_event_type_unset *event = (ds_tizen_launch_effect_event_type_unset *)data;
106         ds_inf("%s", __func__);
107
108         MockLaunchEffectCompositor *mockComp =
109             reinterpret_cast<TypeUnsetListener *>(listener)->parent;
110
111         mockComp->bTypeSet = false;
112         mockComp->mPid = event->pid;
113         mockComp->mEffectType = -1;
114     }
115
116
117     static void NewSplashCallback(struct wl_listener *listener, void *data)
118     {
119         struct ds_tizen_launch_splash *splash = (ds_tizen_launch_splash *)data;
120         ds_inf("%s", __func__);
121
122         MockLaunchEffectCompositor *mockComp =
123             reinterpret_cast<NewSplashListener *>(listener)->parent;
124
125         mockComp->bNewSplash = true;
126         mockComp->mSplash = splash;
127
128         // owner listener
129         mockComp->mOwnerListener.notify =
130             MockLaunchEffectCompositor::OwnerCallback;
131         mockComp->mOwnerListener.parent = mockComp;
132         ds_tizen_launch_splash_add_owner_listener(mockComp->mSplash,
133             &mockComp->mOwnerListener);
134     }
135
136     static void OwnerCallback(struct wl_listener *listener, void *data)
137     {
138         struct ds_tizen_launch_splash_event_owner *event = (ds_tizen_launch_splash_event_owner *)data;
139         ds_inf("%s", __func__);
140
141         MockLaunchEffectCompositor *mockComp =
142             reinterpret_cast<OwnerListener *>(listener)->parent;
143
144         mockComp->mPid = event->pid;
145     }
146
147 public:
148     bool bDestroyed;
149     bool bTypeSet;
150     bool bNewSplash;
151     bool bOwner;
152
153     uint32_t mPid;
154     int mEffectType;
155
156 private:
157     struct ds_tizen_launch_effect *mEffect;
158     struct ds_tizen_launch_splash *mSplash;
159     struct DestroyListener: ::wl_listener {
160         MockLaunchEffectCompositor *parent;
161     };
162     DestroyListener mDestroyListener;
163
164     struct TypeSetListener: ::wl_listener {
165         MockLaunchEffectCompositor *parent;
166     };
167     TypeSetListener mTypeSetListener;
168
169     struct TypeUnsetListener: ::wl_listener {
170         MockLaunchEffectCompositor *parent;
171     };
172     TypeUnsetListener mTypeUnsetListener;
173
174     struct NewSplashListener: ::wl_listener {
175         MockLaunchEffectCompositor *parent;
176     };
177     NewSplashListener mNewSplashListener;
178
179     struct OwnerListener: ::wl_listener {
180         MockLaunchEffectCompositor *parent;
181     };
182     OwnerListener mOwnerListener;
183 };
184
185 class MockLaunchEffectClient : public MockClient
186 {
187 public:
188     MockLaunchEffectClient()
189         : compositor_res(nullptr),
190           tizen_launch_effect(nullptr)
191     {}
192
193     MockLaunchEffectClient(const struct wl_registry_listener *listener)
194         : MockClient(listener, this)
195     {
196         ds_inf("%s", __func__);
197     }
198
199     ~MockLaunchEffectClient()
200     {
201         ds_inf("%s", __func__);
202     }
203
204     void SetWlCompositor(struct wl_compositor *global_res)
205     {
206         ds_inf("%s", __func__);
207
208         compositor_res = global_res;
209     }
210
211     struct wl_compositor *GetWlCompositor()
212     {
213         ds_inf("%s", __func__);
214
215         return compositor_res;
216     }
217
218     void SetTizenLaunchEffect(struct tizen_launch_effect *global_res)
219     {
220         ds_inf("%s", __func__);
221         tizen_launch_effect = global_res;
222     }
223
224     struct tizen_launch_effect *GetTizenLaunchEffect()
225     {
226         ds_inf("%s", __func__);
227
228         return tizen_launch_effect;
229     }
230
231 public:
232
233 private:
234     struct wl_compositor *compositor_res;
235     struct tizen_launch_effect *tizen_launch_effect;
236 };
237
238 static void
239 client_registry_cb_global(void *data, struct wl_registry *registry,
240     uint32_t name, const char *interface, uint32_t version)
241 {
242     ds_inf("%s", __func__);
243
244     MockLaunchEffectClient *client = static_cast<MockLaunchEffectClient *>(data);
245     struct wl_compositor *compositor_res;
246     struct tizen_launch_effect *tizen_launch_effect;
247
248     if (!strcmp(interface, "wl_compositor")) {
249         compositor_res = (struct wl_compositor *)wl_registry_bind(registry,
250             name, &wl_compositor_interface, 1);
251         if (compositor_res == nullptr) {
252             ds_err("wl_registry_bind() failed. wl_compositor resource.");
253             return;
254         }
255         client->SetWlCompositor(compositor_res);
256     } else if (!strcmp(interface, "tizen_launch_effect")) {
257         tizen_launch_effect = (struct tizen_launch_effect *)wl_registry_bind(registry,
258             name, &tizen_launch_effect_interface, TIZEN_EFFECT_VERSION);
259         if (tizen_launch_effect == nullptr) {
260             ds_err("wl_registry_bind() failed. tizen_launch_effect resource.");
261             return;
262         }
263         client->SetTizenLaunchEffect(tizen_launch_effect);
264     }
265 }
266
267 static void
268 client_registry_cb_global_remove(void *data, struct wl_registry *registry,
269     uint32_t name)
270 {
271     ds_inf("%s", __func__);
272
273     MockLaunchEffectClient *client = static_cast<MockLaunchEffectClient *>(data);
274     struct wl_compositor *compositor_res = client->GetWlCompositor();
275     struct tizen_launch_effect *effect_res = client->GetTizenLaunchEffect();
276
277     tizen_launch_effect_destroy(effect_res);
278     wl_compositor_destroy(compositor_res);
279 }
280
281 static const struct wl_registry_listener registry_listener = {
282     .global = client_registry_cb_global,
283     .global_remove = client_registry_cb_global_remove
284 };
285
286 class LaunchEffectTest : public ::testing::Test
287 {
288 public:
289     void SetUp(void) override;
290     void TearDown(void) override;
291
292     MockLaunchEffectCompositor *comp;
293     MockLaunchEffectClient *client;
294     struct wl_compositor *compositor_res;
295     struct tizen_launch_effect *effect_res;
296 };
297
298 void
299 LaunchEffectTest::SetUp(void)
300 {
301     ds_inf("%s", __func__);
302
303     comp = new MockLaunchEffectCompositor();
304     client = new MockLaunchEffectClient(&registry_listener);
305     compositor_res = client->GetWlCompositor();
306     effect_res = client->GetTizenLaunchEffect();
307
308     client->RoundTrip();
309 }
310
311 void
312 LaunchEffectTest::TearDown(void)
313 {
314     ds_inf("%s", __func__);
315
316     client->RoundTrip();
317
318     delete client;
319     delete comp;
320 }
321
322 TEST_F(LaunchEffectTest, Create_P)
323 {
324     EXPECT_TRUE(true);
325 }
326
327 TEST_F(LaunchEffectTest, Req_TizenLaunchEffectTypeSet)
328 {
329     uint pid = 12345;
330     const char *effect_type;
331
332     effect_type = "launch";
333     tizen_launch_effect_type_set(effect_res, effect_type, pid, NULL);
334     client->RoundTrip();
335     EXPECT_TRUE(comp->bTypeSet);
336     EXPECT_TRUE(comp->mPid == pid);
337     EXPECT_TRUE(comp->mEffectType == DS_TIZEN_LAUNCH_EFFECT_TYPE_LAUNCH);
338 }
339
340 TEST_F(LaunchEffectTest, Req_TizenLaunchEffectTypeUnSet)
341 {
342     uint pid = 12345;
343     const char *effect_type;
344
345     effect_type = "depth-in";
346     tizen_launch_effect_type_set(effect_res, effect_type, pid, NULL);
347     client->RoundTrip();
348     EXPECT_TRUE(comp->bTypeSet);
349     EXPECT_TRUE(comp->mPid == pid);
350     EXPECT_TRUE(comp->mEffectType == DS_TIZEN_LAUNCH_EFFECT_TYPE_DEPTH_IN);
351
352     tizen_launch_effect_type_unset(effect_res, pid);
353     client->RoundTrip();
354     EXPECT_FALSE(comp->bTypeSet);
355     EXPECT_TRUE(comp->mPid == pid);
356     EXPECT_TRUE(comp->mEffectType == -1);
357 }
358
359 TEST_F(LaunchEffectTest, Req_TizenLaunchEffectCreateSplashImg)
360 {
361     struct tizen_launch_splash *splash = NULL;
362
363     splash = tizen_launch_effect_create_splash_img(effect_res);
364     client->RoundTrip();
365     EXPECT_TRUE(splash != NULL);
366     EXPECT_TRUE(comp->bNewSplash);
367 }
368
369 TEST_F(LaunchEffectTest, Req_TizenLaunchSplashLaunch_EDC)
370 {
371     struct tizen_launch_splash *splash = NULL;
372     struct wl_array options;
373
374     splash = tizen_launch_effect_create_splash_img(effect_res);
375     client->RoundTrip();
376     EXPECT_TRUE(splash != NULL);
377     EXPECT_TRUE(comp->bNewSplash);
378
379     wl_array_init(&options);
380
381     tizen_launch_splash_launch(splash, path_edc,\
382         SPLASH_TYPE_EDC, 24, 0, 0, "launch", "default", &options);
383     client->RoundTrip();
384     wl_array_release(&options);
385     EXPECT_TRUE(comp->mPid == SPLASH_CLIENT_PID);
386     EXPECT_TRUE(comp->mEffectType == DS_TIZEN_LAUNCH_EFFECT_TYPE_LAUNCH);
387 }
388
389 TEST_F(LaunchEffectTest, Req_TizenLaunchSplashLaunch_IMG)
390 {
391     struct tizen_launch_splash *splash = NULL;
392     struct wl_array options;
393
394     splash = tizen_launch_effect_create_splash_img(effect_res);
395     client->RoundTrip();
396     EXPECT_TRUE(splash != NULL);
397     EXPECT_TRUE(comp->bNewSplash);
398
399     wl_array_init(&options);
400
401     tizen_launch_splash_launch(splash, path_img,\
402         SPLASH_TYPE_IMG, 24, 0, 0, "launch", "default", &options);
403     client->RoundTrip();
404     wl_array_release(&options);
405     EXPECT_TRUE(comp->mPid == SPLASH_CLIENT_PID);
406     EXPECT_TRUE(comp->mEffectType == DS_TIZEN_LAUNCH_EFFECT_TYPE_LAUNCH);
407 }
408
409 TEST_F(LaunchEffectTest, Req_TizenLaunchSplashSetOwner)
410 {
411     struct tizen_launch_splash *splash = NULL;
412     struct wl_array options;
413     uint32_t pid = 12345;
414
415     splash = tizen_launch_effect_create_splash_img(effect_res);
416     client->RoundTrip();
417     EXPECT_TRUE(splash != NULL);
418     EXPECT_TRUE(comp->bNewSplash);
419
420     wl_array_init(&options);
421
422     tizen_launch_splash_launch(splash, path_img,\
423         SPLASH_TYPE_IMG, 24, 0, 0, "depth-in", "default", &options);
424     client->RoundTrip();
425     wl_array_release(&options);
426     EXPECT_TRUE(comp->mPid == SPLASH_CLIENT_PID);
427     EXPECT_TRUE(comp->mEffectType == DS_TIZEN_LAUNCH_EFFECT_TYPE_DEPTH_IN);
428
429     tizen_launch_splash_owner(splash, pid);
430     client->RoundTrip();
431     EXPECT_TRUE(comp->mPid == pid);
432     EXPECT_TRUE(comp->mEffectType == DS_TIZEN_LAUNCH_EFFECT_TYPE_DEPTH_IN);
433 }
434
435 TEST_F(LaunchEffectTest, Req_TizenLaunchSplashLaunch_v2)
436
437 {
438     struct tizen_launch_splash *splash = NULL;
439     struct wl_array options;
440     struct wl_array extra_config;
441     int custom_effect = 0;
442     void *data;
443     int size;
444     const char *appid = "org.tizen.libds-tizen-launch-effect-test";
445
446     splash = tizen_launch_effect_create_splash_img(effect_res);
447     client->RoundTrip();
448     EXPECT_TRUE(splash != NULL);
449     EXPECT_TRUE(comp->bNewSplash);
450
451     // set
452     wl_array_init(&options);
453     size = strlen(appid) + 1;
454     data = wl_array_add(&options, size);
455     memcpy(data, appid, size);
456
457     wl_array_init(&extra_config);
458     size = strlen(CUSTOM_EFFECT_CALLEE) + 1;
459     data = wl_array_add(&extra_config, size);
460     memcpy(data, CUSTOM_EFFECT_CALLEE, size);
461
462     size = strlen(appid) + 1;
463     data = wl_array_add(&extra_config, size);
464     memcpy(data, appid, size);
465
466     if (extra_config.size > 0)
467         custom_effect = 1;
468
469     tizen_launch_splash_launch_v2(splash, path_edc,\
470         SPLASH_TYPE_EDC, 24, 0, 0, "depth-in", "default", &options, custom_effect ? &extra_config : NULL);
471     client->RoundTrip();
472     wl_array_release(&options);
473     wl_array_release(&extra_config);
474     EXPECT_TRUE(comp->mPid == SPLASH_CLIENT_PID);
475     EXPECT_TRUE(comp->mEffectType == DS_TIZEN_LAUNCH_EFFECT_TYPE_DEPTH_IN);
476 }