2 #include "mockclient.h"
3 #include "mockcompositor.h"
4 #include <libds-tizen/memory_flusher.h>
5 #include <tizen-surface-client-protocol.h>
7 #define TIZEN_MEMORY_FLUSHER_VERSION 2
9 class MockMemoryFlusherCompositor : public MockCompositor
12 MockMemoryFlusherCompositor()
13 : MockCompositor(&MockMemoryFlusherCompositor::TestSetup, this)
15 ds_inf("%s : this(%p)", __func__, this);
17 // initialize the flags to check
18 bSurfaceDestroyed = false;
21 bGetFlusherInfo = false;
22 bDestroyFlusherInfo = false;
25 ~MockMemoryFlusherCompositor()
27 ds_inf("%s : this(%p)", __func__, this);
30 static void TestSetup(void *data)
32 MockMemoryFlusherCompositor *mockComp =
33 static_cast<MockMemoryFlusherCompositor *>(data);
34 Compositor *comp = mockComp->compositor;
36 ds_inf("%s: mockComp(%p)", __func__, mockComp);
38 // new surface listener
39 mockComp->mNewSurfaceListener.notify =
40 MockMemoryFlusherCompositor::NewSurfaceCallback;
41 mockComp->mNewSurfaceListener.parent = mockComp;
42 ds_compositor_add_new_surface_listener(comp->compositor,
43 &mockComp->mNewSurfaceListener);
45 mockComp->mMemoryFlusher =
46 ds_tizen_memory_flusher_create(comp->display);
49 mockComp->mDestroyListener.notify =
50 MockMemoryFlusherCompositor::DestroyCallback;
51 mockComp->mDestroyListener.parent = mockComp;
52 ds_tizen_memory_flusher_add_destroy_listener(mockComp->mMemoryFlusher,
53 &mockComp->mDestroyListener);
55 // get_flusher_info listener
56 mockComp->mGetFlusherInfoListener.notify =
57 MockMemoryFlusherCompositor::GetFlusherInfoCallback;
58 mockComp->mGetFlusherInfoListener.parent = mockComp;
59 ds_tizen_memory_flusher_add_get_flusher_info_listener(
60 mockComp->mMemoryFlusher,
61 &mockComp->mGetFlusherInfoListener);
64 static void NewSurfaceCallback(struct wl_listener *listener, void *data)
66 MockMemoryFlusherCompositor *mockComp =
67 reinterpret_cast<NewSurfaceListener *>(listener)->parent;
68 struct ds_surface *surface = static_cast<struct ds_surface *>(data);
70 ds_inf("%s: mockComp(%p), surface(%p)", __func__, mockComp, surface);
72 mockComp->mSurface = surface;
74 // del surface listener
75 mockComp->mDelSurfaceListener.notify =
76 MockMemoryFlusherCompositor::DelSurfaceCallback;
77 mockComp->mDelSurfaceListener.parent = mockComp;
78 ds_surface_add_destroy_listener(surface,
79 &mockComp->mDelSurfaceListener);
82 static void DelSurfaceCallback(struct wl_listener *listener, void *data)
84 MockMemoryFlusherCompositor *mockComp =
85 reinterpret_cast<DelSurfaceListener *>(listener)->parent;
86 struct ds_surface *surface = static_cast<struct ds_surface *>(data);
88 ds_inf("%s: mockComp(%p), surface(%p)", __func__, mockComp, surface);
90 if (ds_surface_get_wl_resource(mockComp->mSurface) ==
91 ds_surface_get_wl_resource(surface)) {
92 ds_inf("%s: surface is deleted.", __func__);
93 mockComp->bSurfaceDestroyed = true;
97 static void DestroyCallback(struct wl_listener *listener, void *data)
99 ds_inf("%s", __func__);
101 MockMemoryFlusherCompositor *mockComp =
102 reinterpret_cast<DestroyListener *>(listener)->parent;
104 mockComp->bDestroyed = true;
107 static void GetFlusherInfoCallback(struct wl_listener *listener,
110 ds_inf("%s", __func__);
112 MockMemoryFlusherCompositor *mockComp =
113 reinterpret_cast<GetFlusherInfoListener *>(listener)->parent;
114 struct ds_tizen_memory_flusher_info *info =
115 static_cast<struct ds_tizen_memory_flusher_info *>(data);
117 ds_inf("%s: mockComp(%p), info(%p)", __func__, mockComp, info);
119 mockComp->bGetFlusherInfo = true;
121 mockComp->mInfo = info;
123 ds_tizen_memory_flusher_info_get_surface(mockComp->mInfo);
125 // info destroy listener
126 mockComp->mFlusherInfoDestroyListener.notify =
127 MockMemoryFlusherCompositor::FlusherInfoDestroyCallback;
128 mockComp->mFlusherInfoDestroyListener.parent = mockComp;
129 ds_tizen_memory_flusher_info_add_destroy_listener(mockComp->mInfo,
130 &mockComp->mFlusherInfoDestroyListener);
133 static void FlusherInfoDestroyCallback(struct wl_listener *listener,
136 ds_inf("%s", __func__);
138 MockMemoryFlusherCompositor *mockComp =
139 reinterpret_cast<FlusherInfoDestroyListener *>(listener)->parent;
140 struct ds_tizen_memory_flusher_info *info =
141 static_cast<struct ds_tizen_memory_flusher_info *>(data);
143 ds_inf("%s: mockComp(%p), info(%p)", __func__, mockComp, info);
145 if (mockComp->mInfo == info) {
146 ds_inf("%s: info is deleted.", __func__);
147 mockComp->bDestroyFlusherInfo = true;
151 void SendMemoryFlusherInfoFlush()
153 ds_inf("%s", __func__);
155 ds_tizen_memory_flusher_info_send_flush(mInfo);
158 void SendMemoryFlusherInfoFreeFlush()
160 ds_inf("%s", __func__);
162 ds_tizen_memory_flusher_info_send_free_flush(mInfo);
166 bool bSurfaceDestroyed;
168 bool bGetFlusherInfo;
169 bool bDestroyFlusherInfo;
172 struct ds_tizen_memory_flusher_info *mInfo;
173 struct ds_surface *mSurface;
175 struct NewSurfaceListener : ::wl_listener {
176 MockMemoryFlusherCompositor *parent;
178 NewSurfaceListener mNewSurfaceListener;
180 struct DelSurfaceListener : ::wl_listener {
181 MockMemoryFlusherCompositor *parent;
183 DelSurfaceListener mDelSurfaceListener;
185 struct ds_tizen_memory_flusher *mMemoryFlusher;
187 struct DestroyListener : ::wl_listener {
188 MockMemoryFlusherCompositor *parent;
190 DestroyListener mDestroyListener;
192 struct GetFlusherInfoListener : ::wl_listener {
193 MockMemoryFlusherCompositor *parent;
195 GetFlusherInfoListener mGetFlusherInfoListener;
197 struct FlusherInfoDestroyListener : ::wl_listener {
198 MockMemoryFlusherCompositor *parent;
200 FlusherInfoDestroyListener mFlusherInfoDestroyListener;
203 class MockMemoryFlusherClient : public MockClient
206 MockMemoryFlusherClient()
207 : bFlushEvent(false),
208 bFreeFlushEvent(false),
209 compositor_res(nullptr),
210 tizen_surface_shm(nullptr)
212 MockMemoryFlusherClient(const struct wl_registry_listener *listener)
213 : MockClient(listener, this)
215 ds_inf("%s", __func__);
218 bFreeFlushEvent = false;
220 ~MockMemoryFlusherClient()
222 ds_inf("%s", __func__);
225 void SetWlCompositor(struct wl_compositor *global_res)
227 ds_inf("%s", __func__);
229 compositor_res = global_res;
232 struct wl_compositor *GetWlCompositor()
234 ds_inf("%s", __func__);
236 return compositor_res;
239 void SetTizenSurfaceShm(struct tizen_surface_shm *global_res)
241 ds_inf("%s", __func__);
243 tizen_surface_shm = global_res;
246 struct tizen_surface_shm *GetTizenSurfaceShm()
248 ds_inf("%s", __func__);
250 return tizen_surface_shm;
255 bool bFreeFlushEvent;
258 struct wl_compositor *compositor_res;
259 struct tizen_surface_shm *tizen_surface_shm;
263 client_registry_cb_global(void *data, struct wl_registry *registry,
264 uint32_t name, const char *interface, uint32_t version)
266 ds_inf("%s", __func__);
268 MockMemoryFlusherClient *client = static_cast<MockMemoryFlusherClient *>(data);
269 struct wl_compositor *compositor_res;
270 struct tizen_surface_shm *surface_shm_res;
272 if (!strcmp(interface, "wl_compositor")) {
273 compositor_res = (struct wl_compositor *)wl_registry_bind(registry,
274 name, &wl_compositor_interface, 1);
275 if (compositor_res == nullptr) {
276 ds_err("wl_registry_bind() failed. wl_compositor resource.");
279 client->SetWlCompositor(compositor_res);
280 } else if (!strcmp(interface, "tizen_surface_shm")) {
281 surface_shm_res = (struct tizen_surface_shm *)wl_registry_bind(registry,
282 name, &tizen_surface_shm_interface, TIZEN_MEMORY_FLUSHER_VERSION);
283 if (surface_shm_res == nullptr) {
284 ds_err("wl_registry_bind() failed. tizen_surface_shm resource.");
287 client->SetTizenSurfaceShm(surface_shm_res);
292 client_registry_cb_global_remove(void *data, struct wl_registry *registry,
295 ds_inf("%s", __func__);
297 MockMemoryFlusherClient *client = static_cast<MockMemoryFlusherClient *>(data);
298 struct wl_compositor *compositor_res = client->GetWlCompositor();
299 struct tizen_surface_shm *surface_shm_res = client->GetTizenSurfaceShm();
301 tizen_surface_shm_destroy(surface_shm_res);
302 wl_compositor_destroy(compositor_res);
305 static const struct wl_registry_listener registry_listener = {
306 .global = client_registry_cb_global,
307 .global_remove = client_registry_cb_global_remove
311 client_tizen_surface_shm_flusher_cb_flush(void *data,
312 struct tizen_surface_shm_flusher *surface_shm_flusher_res)
314 ds_inf("%s", __func__);
316 MockMemoryFlusherClient *client = static_cast<MockMemoryFlusherClient *>(data);
318 client->bFlushEvent = true;
322 client_tizen_surface_shm_flusher_cb_free_flush(void *data,
323 struct tizen_surface_shm_flusher *surface_shm_flusher_res)
325 ds_inf("%s", __func__);
327 MockMemoryFlusherClient *client = static_cast<MockMemoryFlusherClient *>(data);
329 client->bFreeFlushEvent = true;
333 tizen_surface_shm_flusher_listener surface_shm_flusher_cb_listener = {
334 .flush = client_tizen_surface_shm_flusher_cb_flush,
335 .free_flush = client_tizen_surface_shm_flusher_cb_free_flush,
338 class MemoryFlusherTest : public ::testing::Test
341 void SetUp(void) override;
342 void TearDown(void) override;
344 MockMemoryFlusherCompositor *comp;
345 MockMemoryFlusherClient *client;
346 struct wl_compositor *compositor_res;
347 struct tizen_surface_shm *surface_shm_res;
348 struct wl_surface *surface_res;
349 struct tizen_surface_shm_flusher *surface_shm_flusher_res;
353 MemoryFlusherTest::SetUp(void)
355 //ds_log_init(DS_DBG, NULL);
357 ds_inf("%s", __func__);
359 comp = new MockMemoryFlusherCompositor();
360 client = new MockMemoryFlusherClient(®istry_listener);
361 compositor_res = client->GetWlCompositor();
362 surface_shm_res = client->GetTizenSurfaceShm();
363 surface_res = wl_compositor_create_surface(compositor_res);
365 surface_shm_flusher_res =
366 tizen_surface_shm_get_flusher(surface_shm_res, surface_res);
368 tizen_surface_shm_flusher_add_listener(surface_shm_flusher_res,
369 &surface_shm_flusher_cb_listener, client);
375 MemoryFlusherTest::TearDown(void)
377 ds_inf("%s", __func__);
379 tizen_surface_shm_flusher_destroy(surface_shm_flusher_res);
381 EXPECT_TRUE(comp->bDestroyFlusherInfo);
383 wl_surface_destroy(surface_res);
385 EXPECT_TRUE(comp->bSurfaceDestroyed);
391 TEST_F(MemoryFlusherTest, Create_P)
394 EXPECT_TRUE(comp->bGetFlusherInfo);
397 TEST_F(MemoryFlusherTest, Ev_TizenSurfaceShmFlusherFlush)
399 comp->SendMemoryFlusherInfoFlush();
403 EXPECT_TRUE(client->bFlushEvent);
406 TEST_F(MemoryFlusherTest, Ev_TizenSurfaceShmFlusherFreeFlush)
408 comp->SendMemoryFlusherInfoFreeFlush();
412 EXPECT_TRUE(client->bFreeFlushEvent);