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>
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
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";
18 class MockLaunchEffectCompositor : public MockCompositor
21 MockLaunchEffectCompositor()
22 : MockCompositor(&MockLaunchEffectCompositor::TestSetup, this)
24 ds_inf("%s : this(%p)", __func__, this);
26 // initialize the flags to check
36 ~MockLaunchEffectCompositor()
38 ds_inf("%s : this(%p)", __func__, this);
41 static void TestSetup(void *data)
43 MockLaunchEffectCompositor *mockComp =
44 static_cast<MockLaunchEffectCompositor *>(data);
45 Compositor *comp = mockComp->compositor;
47 ds_inf("%s: mockComp(%p)", __func__, mockComp);
49 mockComp->mEffect = ds_tizen_launch_effect_create(comp->display);
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);
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);
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);
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);
80 static void DestroyCallback(struct wl_listener *listener, void *data)
82 ds_inf("%s", __func__);
84 MockLaunchEffectCompositor *mockComp =
85 reinterpret_cast<DestroyListener *>(listener)->parent;
87 mockComp->bDestroyed = true;
90 static void TypeSetCallback(struct wl_listener *listener, void *data)
92 struct ds_tizen_launch_effect_event_type_set *event = (ds_tizen_launch_effect_event_type_set *)data;
93 ds_inf("%s", __func__);
95 MockLaunchEffectCompositor *mockComp =
96 reinterpret_cast<TypeSetListener *>(listener)->parent;
98 mockComp->bTypeSet = true;
99 mockComp->mPid = event->pid;
100 mockComp->mEffectType = event->effect_type;
103 static void TypeUnsetCallback(struct wl_listener *listener, void *data)
105 struct ds_tizen_launch_effect_event_type_unset *event = (ds_tizen_launch_effect_event_type_unset *)data;
106 ds_inf("%s", __func__);
108 MockLaunchEffectCompositor *mockComp =
109 reinterpret_cast<TypeUnsetListener *>(listener)->parent;
111 mockComp->bTypeSet = false;
112 mockComp->mPid = event->pid;
113 mockComp->mEffectType = -1;
117 static void NewSplashCallback(struct wl_listener *listener, void *data)
119 struct ds_tizen_launch_splash *splash = (ds_tizen_launch_splash *)data;
120 ds_inf("%s", __func__);
122 MockLaunchEffectCompositor *mockComp =
123 reinterpret_cast<NewSplashListener *>(listener)->parent;
125 mockComp->bNewSplash = true;
126 mockComp->mSplash = splash;
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);
136 static void OwnerCallback(struct wl_listener *listener, void *data)
138 struct ds_tizen_launch_splash_event_owner *event = (ds_tizen_launch_splash_event_owner *)data;
139 ds_inf("%s", __func__);
141 MockLaunchEffectCompositor *mockComp =
142 reinterpret_cast<OwnerListener *>(listener)->parent;
144 mockComp->mPid = event->pid;
157 struct ds_tizen_launch_effect *mEffect;
158 struct ds_tizen_launch_splash *mSplash;
159 struct DestroyListener: ::wl_listener {
160 MockLaunchEffectCompositor *parent;
162 DestroyListener mDestroyListener;
164 struct TypeSetListener: ::wl_listener {
165 MockLaunchEffectCompositor *parent;
167 TypeSetListener mTypeSetListener;
169 struct TypeUnsetListener: ::wl_listener {
170 MockLaunchEffectCompositor *parent;
172 TypeUnsetListener mTypeUnsetListener;
174 struct NewSplashListener: ::wl_listener {
175 MockLaunchEffectCompositor *parent;
177 NewSplashListener mNewSplashListener;
179 struct OwnerListener: ::wl_listener {
180 MockLaunchEffectCompositor *parent;
182 OwnerListener mOwnerListener;
185 class MockLaunchEffectClient : public MockClient
188 MockLaunchEffectClient()
189 : compositor_res(nullptr),
190 tizen_launch_effect(nullptr)
193 MockLaunchEffectClient(const struct wl_registry_listener *listener)
194 : MockClient(listener, this)
196 ds_inf("%s", __func__);
199 ~MockLaunchEffectClient()
201 ds_inf("%s", __func__);
204 void SetWlCompositor(struct wl_compositor *global_res)
206 ds_inf("%s", __func__);
208 compositor_res = global_res;
211 struct wl_compositor *GetWlCompositor()
213 ds_inf("%s", __func__);
215 return compositor_res;
218 void SetTizenLaunchEffect(struct tizen_launch_effect *global_res)
220 ds_inf("%s", __func__);
221 tizen_launch_effect = global_res;
224 struct tizen_launch_effect *GetTizenLaunchEffect()
226 ds_inf("%s", __func__);
228 return tizen_launch_effect;
234 struct wl_compositor *compositor_res;
235 struct tizen_launch_effect *tizen_launch_effect;
239 client_registry_cb_global(void *data, struct wl_registry *registry,
240 uint32_t name, const char *interface, uint32_t version)
242 ds_inf("%s", __func__);
244 MockLaunchEffectClient *client = static_cast<MockLaunchEffectClient *>(data);
245 struct wl_compositor *compositor_res;
246 struct tizen_launch_effect *tizen_launch_effect;
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.");
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.");
263 client->SetTizenLaunchEffect(tizen_launch_effect);
268 client_registry_cb_global_remove(void *data, struct wl_registry *registry,
271 ds_inf("%s", __func__);
273 MockLaunchEffectClient *client = static_cast<MockLaunchEffectClient *>(data);
274 struct wl_compositor *compositor_res = client->GetWlCompositor();
275 struct tizen_launch_effect *effect_res = client->GetTizenLaunchEffect();
277 tizen_launch_effect_destroy(effect_res);
278 wl_compositor_destroy(compositor_res);
281 static const struct wl_registry_listener registry_listener = {
282 .global = client_registry_cb_global,
283 .global_remove = client_registry_cb_global_remove
286 class LaunchEffectTest : public ::testing::Test
289 void SetUp(void) override;
290 void TearDown(void) override;
292 MockLaunchEffectCompositor *comp;
293 MockLaunchEffectClient *client;
294 struct wl_compositor *compositor_res;
295 struct tizen_launch_effect *effect_res;
299 LaunchEffectTest::SetUp(void)
301 ds_inf("%s", __func__);
303 comp = new MockLaunchEffectCompositor();
304 client = new MockLaunchEffectClient(®istry_listener);
305 compositor_res = client->GetWlCompositor();
306 effect_res = client->GetTizenLaunchEffect();
312 LaunchEffectTest::TearDown(void)
314 ds_inf("%s", __func__);
322 TEST_F(LaunchEffectTest, Create_P)
327 TEST_F(LaunchEffectTest, Req_TizenLaunchEffectTypeSet)
330 const char *effect_type;
332 effect_type = "launch";
333 tizen_launch_effect_type_set(effect_res, effect_type, pid, NULL);
335 EXPECT_TRUE(comp->bTypeSet);
336 EXPECT_TRUE(comp->mPid == pid);
337 EXPECT_TRUE(comp->mEffectType == DS_TIZEN_LAUNCH_EFFECT_TYPE_LAUNCH);
340 TEST_F(LaunchEffectTest, Req_TizenLaunchEffectTypeUnSet)
343 const char *effect_type;
345 effect_type = "depth-in";
346 tizen_launch_effect_type_set(effect_res, effect_type, pid, NULL);
348 EXPECT_TRUE(comp->bTypeSet);
349 EXPECT_TRUE(comp->mPid == pid);
350 EXPECT_TRUE(comp->mEffectType == DS_TIZEN_LAUNCH_EFFECT_TYPE_DEPTH_IN);
352 tizen_launch_effect_type_unset(effect_res, pid);
354 EXPECT_FALSE(comp->bTypeSet);
355 EXPECT_TRUE(comp->mPid == pid);
356 EXPECT_TRUE(comp->mEffectType == -1);
359 TEST_F(LaunchEffectTest, Req_TizenLaunchEffectCreateSplashImg)
361 struct tizen_launch_splash *splash = NULL;
363 splash = tizen_launch_effect_create_splash_img(effect_res);
365 EXPECT_TRUE(splash != NULL);
366 EXPECT_TRUE(comp->bNewSplash);
369 TEST_F(LaunchEffectTest, Req_TizenLaunchSplashLaunch_EDC)
371 struct tizen_launch_splash *splash = NULL;
372 struct wl_array options;
374 splash = tizen_launch_effect_create_splash_img(effect_res);
376 EXPECT_TRUE(splash != NULL);
377 EXPECT_TRUE(comp->bNewSplash);
379 wl_array_init(&options);
381 tizen_launch_splash_launch(splash, path_edc,\
382 SPLASH_TYPE_EDC, 24, 0, 0, "launch", "default", &options);
384 wl_array_release(&options);
385 EXPECT_TRUE(comp->mPid == SPLASH_CLIENT_PID);
386 EXPECT_TRUE(comp->mEffectType == DS_TIZEN_LAUNCH_EFFECT_TYPE_LAUNCH);
389 TEST_F(LaunchEffectTest, Req_TizenLaunchSplashLaunch_IMG)
391 struct tizen_launch_splash *splash = NULL;
392 struct wl_array options;
394 splash = tizen_launch_effect_create_splash_img(effect_res);
396 EXPECT_TRUE(splash != NULL);
397 EXPECT_TRUE(comp->bNewSplash);
399 wl_array_init(&options);
401 tizen_launch_splash_launch(splash, path_img,\
402 SPLASH_TYPE_IMG, 24, 0, 0, "launch", "default", &options);
404 wl_array_release(&options);
405 EXPECT_TRUE(comp->mPid == SPLASH_CLIENT_PID);
406 EXPECT_TRUE(comp->mEffectType == DS_TIZEN_LAUNCH_EFFECT_TYPE_LAUNCH);
409 TEST_F(LaunchEffectTest, Req_TizenLaunchSplashSetOwner)
411 struct tizen_launch_splash *splash = NULL;
412 struct wl_array options;
413 uint32_t pid = 12345;
415 splash = tizen_launch_effect_create_splash_img(effect_res);
417 EXPECT_TRUE(splash != NULL);
418 EXPECT_TRUE(comp->bNewSplash);
420 wl_array_init(&options);
422 tizen_launch_splash_launch(splash, path_img,\
423 SPLASH_TYPE_IMG, 24, 0, 0, "depth-in", "default", &options);
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);
429 tizen_launch_splash_owner(splash, pid);
431 EXPECT_TRUE(comp->mPid == pid);
432 EXPECT_TRUE(comp->mEffectType == DS_TIZEN_LAUNCH_EFFECT_TYPE_DEPTH_IN);
435 TEST_F(LaunchEffectTest, Req_TizenLaunchSplashLaunch_v2)
438 struct tizen_launch_splash *splash = NULL;
439 struct wl_array options;
440 struct wl_array extra_config;
441 int custom_effect = 0;
444 const char *appid = "org.tizen.libds-tizen-launch-effect-test";
446 splash = tizen_launch_effect_create_splash_img(effect_res);
448 EXPECT_TRUE(splash != NULL);
449 EXPECT_TRUE(comp->bNewSplash);
452 wl_array_init(&options);
453 size = strlen(appid) + 1;
454 data = wl_array_add(&options, size);
455 memcpy(data, appid, size);
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);
462 size = strlen(appid) + 1;
463 data = wl_array_add(&extra_config, size);
464 memcpy(data, appid, size);
466 if (extra_config.size > 0)
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);
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);