From d65adaebc70cd36da3878c44980fcd99d24c9b6c Mon Sep 17 00:00:00 2001 From: "Tran Ba Khang(MS/EMC31-XC)" Date: Fri, 24 Feb 2023 14:08:06 +0700 Subject: tests: create tests for new screenshot functions with callbacks Two new screenshot async functions, it help to capture a screen or a surface without blocking. Write the notification test for them, make sure the done and error callback is trigged Signed-off-by: Tran Ba Khang(MS/EMC31-XC) --- .../test/ilm_control_notification_test.cpp | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/ivi-layermanagement-api/test/ilm_control_notification_test.cpp b/ivi-layermanagement-api/test/ilm_control_notification_test.cpp index 2638a03..b918e42 100644 --- a/ivi-layermanagement-api/test/ilm_control_notification_test.cpp +++ b/ivi-layermanagement-api/test/ilm_control_notification_test.cpp @@ -33,6 +33,12 @@ extern "C" { #include "ilm_control.h" } +struct screenshot_data_t { + std::atomic fd; + std::atomic error; + ilmErrorTypes result = ILM_SUCCESS; +}; + void add_nsecs(struct timespec *tv, long nsec) { assert(nsec < 1000000000); @@ -230,6 +236,25 @@ public: pthread_cond_signal( &waiterVariable ); } + + static ilmErrorTypes ScreenshotDoneCallbackFunc(void *user_data, t_ilm_int fd, t_ilm_uint width, t_ilm_uint height, t_ilm_uint stride, t_ilm_uint format, t_ilm_uint timestamp) + { + PthreadMutexLock lock(notificationMutex); + screenshot_data_t *screenshotData = static_cast(user_data); + screenshotData->fd.store(fd); + timesCalled++; + pthread_cond_signal( &waiterVariable ); + return screenshotData->result; + } + + static void ScreenshotErrorCallbackFunc(void *user_data, t_ilm_uint error, const char *message) + { + PthreadMutexLock lock(notificationMutex); + screenshot_data_t *screenshotData = static_cast(user_data); + screenshotData->error.store(error); + timesCalled++; + pthread_cond_signal( &waiterVariable ); + } }; // Pointers where to put received values for current Test @@ -726,3 +751,38 @@ TEST_F(NotificationTest, DefaultIsNotToReceiveNotificationsSurface) // assert that we have not been notified assertNoCallbackIsCalled(); } + +TEST_F(NotificationTest, getNotificationWhenScreenshotDone) +{ + /* Call ilm_takeAsyncScreenshot with right screen id + * The ilm_takeAsyncScreenshot should return ILM_SUCCESS + * Screenshot done callback should trigged + */ + screenshot_data_t screenshotData; + screenshotData.fd.store(-1); + ASSERT_EQ(ILM_SUCCESS, ilm_takeAsyncScreenshot(0, ScreenshotDoneCallbackFunc, ScreenshotErrorCallbackFunc, &screenshotData)); + assertCallbackcalled(); + ASSERT_NE(screenshotData.fd.load(), -1); + + /* Call ilm_takeAsyncSurfaceScreenshot with right surface id + * The ilm_takeAsyncSurfaceScreenshot should return ILM_SUCCESS + * Screenshot done callback should trigged + */ + screenshotData.fd.store(-1); + ASSERT_EQ(ILM_SUCCESS, ilm_takeAsyncSurfaceScreenshot(surface, ScreenshotDoneCallbackFunc, ScreenshotErrorCallbackFunc, &screenshotData)); + assertCallbackcalled(); + ASSERT_NE(screenshotData.fd.load(), -1); +} + +TEST_F(NotificationTest, getNotificationWhenScreenshotError) +{ + /* Call ilm_takeAsyncSurfaceScreenshot with wrong surface id + * The ilm_takeAsyncSurfaceScreenshot should return ILM_SUCCESS + * Screenshot error callback should trigged + */ + screenshot_data_t screenshotData; + screenshotData.error.store(0); + ASSERT_EQ(ILM_SUCCESS, ilm_takeAsyncSurfaceScreenshot(surface + 1, ScreenshotDoneCallbackFunc, ScreenshotErrorCallbackFunc, &screenshotData)); + assertCallbackcalled(); + ASSERT_EQ(screenshotData.error.load(), 3); //IVI_SCREENSHOT_ERROR_NO_SURFACE is 3 +} -- cgit v1.2.1