change wl_signal_emit_mutable into wl_signal_emit
[platform/core/uifw/libds-tizen.git] / tests / tc_launch_appinfo.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_APPINFO_VERSION 1
9
10 class MockLaunchAppinfoCompositor : public MockCompositor
11 {
12 public:
13     MockLaunchAppinfoCompositor()
14         : MockCompositor(&MockLaunchAppinfoCompositor::TestSetup, this)
15     {
16         ds_inf("%s : this(%p)", __func__, this);
17
18         // initialize the flags to check
19         bDestroyed = false;
20
21         bSetPid = false;
22         bSetAppid = false;
23         bMetadataReady = false;
24     }
25
26     ~MockLaunchAppinfoCompositor()
27     {
28         ds_inf("%s : this(%p)", __func__, this);
29     }
30
31     static void TestSetup(void *data)
32     {
33         MockLaunchAppinfoCompositor *mockComp =
34             static_cast<MockLaunchAppinfoCompositor *>(data);
35         Compositor *comp = mockComp->compositor;
36
37         ds_inf("%s: mockComp(%p)", __func__, mockComp);
38
39         mockComp->mAppinfoMgr = ds_tizen_launch_appinfo_mgr_create(comp->display);
40
41         // destroy listener
42         mockComp->mDestroyListener.notify =
43             MockLaunchAppinfoCompositor::DestroyCallback;
44         mockComp->mDestroyListener.parent = mockComp;
45         ds_tizen_launch_appinfo_mgr_add_destroy_listener(mockComp->mAppinfoMgr,
46             &mockComp->mDestroyListener);
47
48         // set_pid listener
49         mockComp->mSetPidListener.notify =
50             MockLaunchAppinfoCompositor::SetPidCallback;
51         mockComp->mSetPidListener.parent = mockComp;
52         ds_tizen_launch_appinfo_mgr_add_set_pid_listener(mockComp->mAppinfoMgr,
53             &mockComp->mSetPidListener);
54
55         // set_appid listener
56         mockComp->mSetAppidListener.notify =
57             MockLaunchAppinfoCompositor::SetAppidCallback;
58         mockComp->mSetAppidListener.parent = mockComp;
59         ds_tizen_launch_appinfo_mgr_add_set_appid_listener(mockComp->mAppinfoMgr,
60             &mockComp->mSetAppidListener);
61
62         // metadata_ready listener
63         mockComp->mMetadataReadyListener.notify =
64             MockLaunchAppinfoCompositor::MetadataReadyCallback;
65         mockComp->mMetadataReadyListener.parent = mockComp;
66         ds_tizen_launch_appinfo_mgr_add_metadata_ready_listener(
67             mockComp->mAppinfoMgr,
68             &mockComp->mMetadataReadyListener);
69     }
70
71     static void DestroyCallback(struct wl_listener *listener, void *data)
72     {
73         ds_inf("%s", __func__);
74
75         MockLaunchAppinfoCompositor *mockComp =
76             reinterpret_cast<DestroyListener *>(listener)->parent;
77
78         mockComp->bDestroyed = true;
79     }
80
81     static void SetPidCallback(struct wl_listener *listener, void *data)
82     {
83         ds_inf("%s", __func__);
84
85         MockLaunchAppinfoCompositor *mockComp =
86             reinterpret_cast<SetPidListener *>(listener)->parent;
87         struct ds_tizen_launch_appinfo *info = static_cast<struct ds_tizen_launch_appinfo *>(data);
88
89         ds_inf("%s: mockComp(%p), appinfo(%p)", __func__, mockComp, info);
90
91         mockComp->bSetPid = true;
92     }
93
94     static void SetAppidCallback(struct wl_listener *listener, void *data)
95     {
96         ds_inf("%s", __func__);
97
98         MockLaunchAppinfoCompositor *mockComp =
99             reinterpret_cast<SetAppidListener *>(listener)->parent;
100         struct ds_tizen_launch_appinfo *info = static_cast<struct ds_tizen_launch_appinfo *>(data);
101
102         ds_inf("%s: mockComp(%p), appinfo(%p)", __func__, mockComp, info);
103
104         mockComp->bSetAppid = true;
105     }
106
107
108     static void MetadataReadyCallback(struct wl_listener *listener, void *data)
109     {
110         ds_inf("%s", __func__);
111
112         MockLaunchAppinfoCompositor *mockComp =
113             reinterpret_cast<MetadataReadyListener *>(listener)->parent;
114         struct ds_tizen_launch_appinfo *info = static_cast<struct ds_tizen_launch_appinfo *>(data);
115
116         ds_inf("%s: mockComp(%p), appinfo(%p)", __func__, mockComp, info);
117
118         mockComp->bMetadataReady = true;
119     }
120
121     void SendBaseOutputResolutionDone(uint32_t pid, uint32_t width, uint32_t height)
122     {
123         ds_inf("%s", __func__);
124
125         wl_resource *res_appinfo = ds_tizen_launch_appinfo_mgr_get_appinfo_resource(mAppinfoMgr);
126
127         tizen_launch_appinfo_send_base_output_resolution_done(res_appinfo, pid, width, height);
128     }
129
130 public:
131     bool bDestroyed;
132     bool bSetPid;
133     bool bSetAppid;
134     bool bMetadataReady;
135
136 private:
137     struct ds_tizen_launch_appinfo_mgr *mAppinfoMgr;
138     struct DestroyListener: ::wl_listener {
139         MockLaunchAppinfoCompositor *parent;
140     };
141     DestroyListener mDestroyListener;
142     struct SetPidListener: ::wl_listener {
143         MockLaunchAppinfoCompositor *parent;
144     };
145     SetPidListener mSetPidListener;
146     struct SetAppidListener: ::wl_listener {
147         MockLaunchAppinfoCompositor *parent;
148     };
149     SetAppidListener mSetAppidListener;
150     struct MetadataReadyListener: ::wl_listener {
151         MockLaunchAppinfoCompositor *parent;
152     };
153     MetadataReadyListener mMetadataReadyListener;
154 };
155
156 class MockLaunchAppinfoClient : public MockClient
157 {
158 public:
159     MockLaunchAppinfoClient()
160         : bBaseOutputResolutionDone(false),
161           mBaseOutputResolutionWidth(0),
162           mBaseOutputResolutionHeight(0),
163           compositor_res(nullptr),
164           tizen_launch_appinfo(nullptr)
165     {}
166     MockLaunchAppinfoClient(const struct wl_registry_listener *listener)
167         : MockClient(listener, this)
168     {
169         ds_inf("%s", __func__);
170
171         bBaseOutputResolutionDone = false;
172         mBaseOutputResolutionWidth = 0;
173         mBaseOutputResolutionHeight = 0;
174     }
175     ~MockLaunchAppinfoClient()
176     {
177         ds_inf("%s", __func__);
178     }
179
180     void SetWlCompositor(struct wl_compositor *global_res)
181     {
182         ds_inf("%s", __func__);
183
184         compositor_res = global_res;
185     }
186
187     struct wl_compositor *GetWlCompositor()
188     {
189         ds_inf("%s", __func__);
190
191         return compositor_res;
192     }
193
194     void SetTizenLaunchAppinfo(struct tizen_launch_appinfo *global_res)
195     {
196         ds_inf("%s", __func__);
197         tizen_launch_appinfo = global_res;
198     }
199
200     struct tizen_launch_appinfo *GetTizenLaunchAppinfo()
201     {
202         ds_inf("%s", __func__);
203
204         return tizen_launch_appinfo;
205     }
206
207 public:
208     bool bBaseOutputResolutionDone;
209     uint32_t mBaseOutputResolutionWidth;
210     uint32_t mBaseOutputResolutionHeight;
211
212 private:
213     struct wl_compositor *compositor_res;
214     struct tizen_launch_appinfo *tizen_launch_appinfo;
215 };
216
217 static void
218 client_tizen_appinfo_cb_base_output_resolution_done(void *data,
219     struct tizen_launch_appinfo *appinfo, uint32_t pid,
220     uint32_t width, uint32_t height)
221 {
222     ds_inf("%s", __func__);
223
224     MockLaunchAppinfoClient *client = static_cast<MockLaunchAppinfoClient *>(data);
225
226     client->bBaseOutputResolutionDone = true;
227     client->mBaseOutputResolutionWidth = width;
228     client->mBaseOutputResolutionHeight = height;
229 }
230
231 static const struct tizen_launch_appinfo_listener appinfo_cb_listener = {
232     .base_output_resolution_done = client_tizen_appinfo_cb_base_output_resolution_done,
233 };
234
235 static void
236 client_registry_cb_global(void *data, struct wl_registry *registry,
237     uint32_t name, const char *interface, uint32_t version)
238 {
239     ds_inf("%s", __func__);
240
241     MockLaunchAppinfoClient *client = static_cast<MockLaunchAppinfoClient *>(data);
242     struct wl_compositor *compositor_res;
243     struct tizen_launch_appinfo *tizen_launch_appinfo;
244
245     if (!strcmp(interface, "wl_compositor")) {
246         compositor_res = (struct wl_compositor *)wl_registry_bind(registry,
247             name, &wl_compositor_interface, 1);
248         if (compositor_res == nullptr) {
249             ds_err("wl_registry_bind() failed. wl_compositor resource.");
250             return;
251         }
252         client->SetWlCompositor(compositor_res);
253     } else if (!strcmp(interface, "tizen_launch_appinfo")) {
254         tizen_launch_appinfo = (struct tizen_launch_appinfo *)wl_registry_bind(registry,
255             name, &tizen_launch_appinfo_interface, TIZEN_APPINFO_VERSION);
256         if (tizen_launch_appinfo == nullptr) {
257             ds_err("wl_registry_bind() failed. tizen_launch_appinfo resource.");
258             return;
259         }
260         client->SetTizenLaunchAppinfo(tizen_launch_appinfo);
261
262         tizen_launch_appinfo_add_listener(tizen_launch_appinfo, &appinfo_cb_listener,
263             client);
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     MockLaunchAppinfoClient *client = static_cast<MockLaunchAppinfoClient *>(data);
274     struct wl_compositor *compositor_res = client->GetWlCompositor();
275     struct tizen_launch_appinfo *appinfo_res = client->GetTizenLaunchAppinfo();
276
277     tizen_launch_appinfo_destroy(appinfo_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 LaunchAppinfoTest : public ::testing::Test
287 {
288 public:
289     void SetUp(void) override;
290     void TearDown(void) override;
291
292     MockLaunchAppinfoCompositor *comp;
293     MockLaunchAppinfoClient *client;
294     struct wl_compositor *compositor_res;
295     struct tizen_launch_appinfo *appinfo_res;
296 };
297
298 void
299 LaunchAppinfoTest::SetUp(void)
300 {
301     ds_inf("%s", __func__);
302
303     comp = new MockLaunchAppinfoCompositor();
304     client = new MockLaunchAppinfoClient(&registry_listener);
305     compositor_res = client->GetWlCompositor();
306     appinfo_res = client->GetTizenLaunchAppinfo();
307
308     client->RoundTrip();
309 }
310
311 void
312 LaunchAppinfoTest::TearDown(void)
313 {
314     ds_inf("%s", __func__);
315
316     client->RoundTrip();
317
318     delete client;
319     delete comp;
320 }
321
322 TEST_F(LaunchAppinfoTest, Create_P)
323 {
324     EXPECT_TRUE(true);
325 }
326
327 TEST_F(LaunchAppinfoTest, Req_TizenLaunchAppinfoRegisterPid)
328 {
329     uint32_t pid = 1234;
330
331     tizen_launch_appinfo_register_pid(appinfo_res, pid);
332     client->RoundTrip();
333     EXPECT_TRUE(comp->bSetPid);
334 }
335
336 TEST_F(LaunchAppinfoTest, Req_TizenLaunchAppinfoSetAppid)
337 {
338     uint32_t pid = 1234;
339     const char *appid = "org.tizen.libds-tizen-appinfo-test";
340
341     tizen_launch_appinfo_register_pid(appinfo_res, pid);
342     client->RoundTrip();
343     EXPECT_TRUE(comp->bSetPid);
344
345     tizen_launch_appinfo_set_appid(appinfo_res, pid, appid);
346     client->RoundTrip();
347     EXPECT_TRUE(comp->bSetAppid);
348 }
349
350 TEST_F(LaunchAppinfoTest, Req_TizenLaunchAppinfoRegisterAppid)
351 {
352     const char *appid = "org.tizen.libds-tizen-appinfo-test";
353
354     tizen_launch_appinfo_register_appid(appinfo_res, appid);
355     client->RoundTrip();
356     EXPECT_TRUE(comp->bSetAppid);
357 }
358
359 TEST_F(LaunchAppinfoTest, Req_TizenLaunchAppinfoSetPid)
360 {
361     uint32_t pid = 1234;
362     const char *appid = "org.tizen.libds-tizen-appinfo-test";
363
364     tizen_launch_appinfo_register_appid(appinfo_res, appid);
365     client->RoundTrip();
366     EXPECT_TRUE(comp->bSetAppid);
367
368     tizen_launch_appinfo_set_pid(appinfo_res, appid, pid);
369     client->RoundTrip();
370     EXPECT_TRUE(comp->bSetPid);
371 }
372
373 TEST_F(LaunchAppinfoTest, Req_TizenLaunchAppinfoMetadataReady)
374 {
375     const char *appid = "org.tizen.libds-tizen-appinfo-test";
376     uint32_t pid = 1234;
377
378     tizen_launch_appinfo_register_appid(appinfo_res, appid);
379     client->RoundTrip();
380     EXPECT_TRUE(comp->bSetAppid);
381
382     tizen_launch_appinfo_ready_metadata(appinfo_res, appid, pid);
383     client->RoundTrip();
384     EXPECT_TRUE(comp->bMetadataReady);
385 }
386
387 TEST_F(LaunchAppinfoTest, Req_TizenLaunchAppinfoGetBaseOutputResolution)
388 {
389     uint32_t pid = 1234;
390
391     tizen_launch_appinfo_register_pid(appinfo_res, pid);
392     client->RoundTrip();
393     EXPECT_TRUE(comp->bSetPid);
394
395     tizen_launch_appinfo_get_base_output_resolution(appinfo_res, pid);
396     client->RoundTrip();
397
398     EXPECT_TRUE(client->bBaseOutputResolutionDone);
399     EXPECT_TRUE(client->mBaseOutputResolutionWidth == 1080); //default value
400     EXPECT_TRUE(client->mBaseOutputResolutionHeight == 1920); // default value
401 }
402
403 TEST_F(LaunchAppinfoTest, Ev_TizenLaunchAppinfoBaseOutputResolutionDone)
404 {
405     uint32_t pid = 1234, width = 1920, height = 1080;
406
407     tizen_launch_appinfo_register_pid(appinfo_res, pid);
408     client->RoundTrip();
409     EXPECT_TRUE(comp->bSetPid);
410
411     tizen_launch_appinfo_get_base_output_resolution(appinfo_res, pid);
412     client->RoundTrip();
413
414     comp->SendBaseOutputResolutionDone(pid, width, height);
415     comp->Process();
416
417     client->RoundTrip();
418     EXPECT_TRUE(client->bBaseOutputResolutionDone);
419     EXPECT_TRUE(client->mBaseOutputResolutionWidth == 1920);
420     EXPECT_TRUE(client->mBaseOutputResolutionHeight == 1080);
421 }