summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTran Ba Khang(MS/EMC31-XC) <Khang.TranBa@vn.bosch.com>2023-02-24 14:08:06 +0700
committerTran Ba Khang(MS/EMC31-XC) <Khang.TranBa@vn.bosch.com>2023-03-20 14:23:52 +0700
commitd65adaebc70cd36da3878c44980fcd99d24c9b6c (patch)
tree383b38f6d0bb6ac99b0796b83796647561ace715
parent85be38aed104e41311763361052364f02702d8b4 (diff)
downloadwayland-ivi-extension-d65adaebc70cd36da3878c44980fcd99d24c9b6c.tar.gz
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) <Khang.TranBa@vn.bosch.com>
-rw-r--r--ivi-layermanagement-api/test/ilm_control_notification_test.cpp60
1 files changed, 60 insertions, 0 deletions
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<int32_t> fd;
+ std::atomic<uint32_t> 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<screenshot_data_t*>(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<screenshot_data_t*>(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
+}