tests: wayland requsets do not allow a null argument.
[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     struct wl_array options;
332
333     effect_type = "launch";
334     wl_array_init(&options);
335     tizen_launch_effect_type_set(effect_res, effect_type, pid, &options);
336     client->RoundTrip();
337     EXPECT_TRUE(comp->bTypeSet);
338     EXPECT_TRUE(comp->mPid == pid);
339     EXPECT_TRUE(comp->mEffectType == DS_TIZEN_LAUNCH_EFFECT_TYPE_LAUNCH);
340     wl_array_release(&options);
341 }
342
343 TEST_F(LaunchEffectTest, Req_TizenLaunchEffectTypeUnSet)
344 {
345     uint pid = 12345;
346     const char *effect_type;
347     struct wl_array options;
348
349     effect_type = "depth-in";
350     wl_array_init(&options);
351     tizen_launch_effect_type_set(effect_res, effect_type, pid, &options);
352     client->RoundTrip();
353     EXPECT_TRUE(comp->bTypeSet);
354     EXPECT_TRUE(comp->mPid == pid);
355     EXPECT_TRUE(comp->mEffectType == DS_TIZEN_LAUNCH_EFFECT_TYPE_DEPTH_IN);
356     wl_array_release(&options);
357
358     tizen_launch_effect_type_unset(effect_res, pid);
359     client->RoundTrip();
360     EXPECT_FALSE(comp->bTypeSet);
361     EXPECT_TRUE(comp->mPid == pid);
362     EXPECT_TRUE(comp->mEffectType == -1);
363 }
364
365 TEST_F(LaunchEffectTest, Req_TizenLaunchEffectCreateSplashImg)
366 {
367     struct tizen_launch_splash *splash = NULL;
368
369     splash = tizen_launch_effect_create_splash_img(effect_res);
370     client->RoundTrip();
371     EXPECT_TRUE(splash != NULL);
372     EXPECT_TRUE(comp->bNewSplash);
373 }
374
375 TEST_F(LaunchEffectTest, Req_TizenLaunchSplashLaunch_EDC)
376 {
377     struct tizen_launch_splash *splash = NULL;
378     struct wl_array options;
379
380     splash = tizen_launch_effect_create_splash_img(effect_res);
381     client->RoundTrip();
382     EXPECT_TRUE(splash != NULL);
383     EXPECT_TRUE(comp->bNewSplash);
384
385     wl_array_init(&options);
386
387     tizen_launch_splash_launch(splash, path_edc,\
388         SPLASH_TYPE_EDC, 24, 0, 0, "launch", "default", &options);
389     client->RoundTrip();
390     wl_array_release(&options);
391     EXPECT_TRUE(comp->mPid == SPLASH_CLIENT_PID);
392     EXPECT_TRUE(comp->mEffectType == DS_TIZEN_LAUNCH_EFFECT_TYPE_LAUNCH);
393 }
394
395 TEST_F(LaunchEffectTest, Req_TizenLaunchSplashLaunch_IMG)
396 {
397     struct tizen_launch_splash *splash = NULL;
398     struct wl_array options;
399
400     splash = tizen_launch_effect_create_splash_img(effect_res);
401     client->RoundTrip();
402     EXPECT_TRUE(splash != NULL);
403     EXPECT_TRUE(comp->bNewSplash);
404
405     wl_array_init(&options);
406
407     tizen_launch_splash_launch(splash, path_img,\
408         SPLASH_TYPE_IMG, 24, 0, 0, "launch", "default", &options);
409     client->RoundTrip();
410     wl_array_release(&options);
411     EXPECT_TRUE(comp->mPid == SPLASH_CLIENT_PID);
412     EXPECT_TRUE(comp->mEffectType == DS_TIZEN_LAUNCH_EFFECT_TYPE_LAUNCH);
413 }
414
415 TEST_F(LaunchEffectTest, Req_TizenLaunchSplashSetOwner)
416 {
417     struct tizen_launch_splash *splash = NULL;
418     struct wl_array options;
419     uint32_t pid = 12345;
420
421     splash = tizen_launch_effect_create_splash_img(effect_res);
422     client->RoundTrip();
423     EXPECT_TRUE(splash != NULL);
424     EXPECT_TRUE(comp->bNewSplash);
425
426     wl_array_init(&options);
427
428     tizen_launch_splash_launch(splash, path_img,\
429         SPLASH_TYPE_IMG, 24, 0, 0, "depth-in", "default", &options);
430     client->RoundTrip();
431     wl_array_release(&options);
432     EXPECT_TRUE(comp->mPid == SPLASH_CLIENT_PID);
433     EXPECT_TRUE(comp->mEffectType == DS_TIZEN_LAUNCH_EFFECT_TYPE_DEPTH_IN);
434
435     tizen_launch_splash_owner(splash, pid);
436     client->RoundTrip();
437     EXPECT_TRUE(comp->mPid == pid);
438     EXPECT_TRUE(comp->mEffectType == DS_TIZEN_LAUNCH_EFFECT_TYPE_DEPTH_IN);
439 }
440
441 TEST_F(LaunchEffectTest, Req_TizenLaunchSplashLaunch_v2)
442
443 {
444     struct tizen_launch_splash *splash = NULL;
445     struct wl_array options;
446     struct wl_array extra_config;
447     int custom_effect = 0;
448     void *data;
449     int size;
450     const char *appid = "org.tizen.libds-tizen-launch-effect-test";
451
452     splash = tizen_launch_effect_create_splash_img(effect_res);
453     client->RoundTrip();
454     EXPECT_TRUE(splash != NULL);
455     EXPECT_TRUE(comp->bNewSplash);
456
457     // set
458     wl_array_init(&options);
459     size = strlen(appid) + 1;
460     data = wl_array_add(&options, size);
461     memcpy(data, appid, size);
462
463     wl_array_init(&extra_config);
464     size = strlen(CUSTOM_EFFECT_CALLEE) + 1;
465     data = wl_array_add(&extra_config, size);
466     memcpy(data, CUSTOM_EFFECT_CALLEE, size);
467
468     size = strlen(appid) + 1;
469     data = wl_array_add(&extra_config, size);
470     memcpy(data, appid, size);
471
472     if (extra_config.size > 0)
473         custom_effect = 1;
474
475     tizen_launch_splash_launch_v2(splash, path_edc,\
476         SPLASH_TYPE_EDC, 24, 0, 0, "depth-in", "default", &options, &extra_config);
477     client->RoundTrip();
478     wl_array_release(&options);
479     wl_array_release(&extra_config);
480     EXPECT_TRUE(comp->mPid == SPLASH_CLIENT_PID);
481     EXPECT_TRUE(comp->mEffectType == DS_TIZEN_LAUNCH_EFFECT_TYPE_DEPTH_IN);
482 }