diff --git a/unittest/client/CMakeLists.txt b/unittest/client/CMakeLists.txt index d30edf0..66e4c6b 100644 --- a/unittest/client/CMakeLists.txt +++ b/unittest/client/CMakeLists.txt @@ -32,6 +32,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/../common ${WAYLAND_CLIENT_INCLUDE_DIRS} + ${WESTON_INCLUDE_DIRS} ${gtest_INCLUDE_DIRS} ) diff --git a/unittest/client/src/ilm_control_unittests.cpp b/unittest/client/src/ilm_control_unittests.cpp index 88c1ab5..f2f942a 100644 --- a/unittest/client/src/ilm_control_unittests.cpp +++ b/unittest/client/src/ilm_control_unittests.cpp @@ -83,6 +83,12 @@ WL_EXPORT const struct wl_interface wl_output_interface = { FAKE_VALUE_FUNC(int, save_as_png, const char *, const char *, int32_t , int32_t , uint32_t ); FAKE_VALUE_FUNC(int, save_as_bitmap, const char *, const char *, int32_t , int32_t , uint32_t ); +struct screenshot_data_t { + std::atomic fd; + std::atomic error; + ilmErrorTypes result = ILM_SUCCESS; +}; + } extern "C"{ @@ -289,6 +295,20 @@ class IlmControlTest : public ::testing::Test int mp_successResult[1] = {0}; int mp_failureResult[1] = {-1}; ilmErrorTypes mp_ilmErrorType[1]; + + 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) + { + screenshot_data_t *screenshotData = static_cast(user_data); + screenshotData->fd.store(fd); + return screenshotData->result; + } + + static void ScreenshotErrorCallbackFunc(void *user_data, t_ilm_uint error, const char *message) + { + screenshot_data_t *screenshotData = static_cast(user_data); + screenshotData->error.store(error); + } + }; /** ================================================================================================ @@ -4218,6 +4238,159 @@ TEST_F(IlmControlTest, ilm_takeScreenshot_validScreen) ASSERT_EQ(ILM_SUCCESS, ilm_takeScreenshot(10, NULL)); } +/** ================================================================================================ + * @test_id ilm_takeScreenshot_validScreenAndHas_argb8888AndHas_wl_shm + * @brief Test case of ilm_takeScreenshot() where valid input screen + * @test_procedure Steps: + * -# Calling the ilm_takeScreenshot() time 1 + * -# Mocking the wl_proxy_marshal_flags() does return an object + * -# Mocking the wl_display_dispatch_queue() does return -1 (failure) + * -# Calling the ilm_takeScreenshot() time 2 + * -# Mocking the wl_display_dispatch_queue() does return 0 (success) + * -# Calling the ilm_takeScreenshot() time 3 + * -# Verification point: + * +# ilm_takeScreenshot() time 1 and time 2 and time 3 must return ILM_FAILED + */ + +TEST_F(IlmControlTest, ilm_takeScreenshot_validScreenAndHas_argb8888AndNo_wl_shm) +{ + ilm_context.wl.wl_shm = NULL; + ilm_context.wl.has_argb8888 = true; + void *screenshot[3] = {0xFFFFFFFF, 0xFFFFFFFF, NULL}; + int version[1] = {1}; + SET_RETURN_SEQ(wl_proxy_marshal_flags, screenshot, 3); + SET_RETURN_SEQ(wl_display_dispatch_queue, mp_successResult, 1); + SET_RETURN_SEQ(wl_proxy_get_version, version, 1); + ASSERT_EQ(ILM_FAILED, ilm_takeScreenshot(10, "test")); + ASSERT_EQ(wl_proxy_marshal_flags_fake.call_count, 0); + ilm_context.wl.wl_shm = NULL; + ilm_context.wl.has_argb8888 = false; +} + +/** ================================================================================================ + * @test_id ilm_takeScreenshot_validScreenAndHas_argb8888AndHas_wl_shm_AndSendScreenshotRequestFailed + * @brief Test case of ilm_takeScreenshot() where valid input screen + * @test_procedure Steps: + * -# Calling the ilm_takeScreenshot() time 1 + * -# Mocking the wl_proxy_marshal_flags() does return an object + * -# Mocking the wl_display_dispatch_queue() does return -1 (failure) + * -# Calling the ilm_takeScreenshot() time 2 + * -# Mocking the wl_display_dispatch_queue() does return 0 (success) + * -# Calling the ilm_takeScreenshot() time 3 + * -# Verification point: + * +# ilm_takeScreenshot() time 1 and time 2 and time 3 must return ILM_FAILED + */ + +TEST_F(IlmControlTest, ilm_takeScreenshot_validScreenAndHas_argb8888AndHas_wl_shm_AndSendScreenshotRequestFailed) +{ + ilm_context.wl.wl_shm = 0xFFFFFFFF; + ilm_context.wl.has_argb8888 = true; + void *screenshot[3] = {0xFFFFFFFF, 0xFFFFFFFF, NULL}; + int version[1] = {1}; + SET_RETURN_SEQ(wl_proxy_marshal_flags, screenshot, 3); + SET_RETURN_SEQ(wl_display_dispatch_queue, mp_successResult, 1); + SET_RETURN_SEQ(wl_proxy_get_version, version, 1); + ASSERT_EQ(ILM_FAILED, ilm_takeScreenshot(10, "test")); + ASSERT_EQ(wl_proxy_marshal_flags_fake.call_count, 5); + ilm_context.wl.wl_shm = NULL; + ilm_context.wl.has_argb8888 = false; +} + +/** ================================================================================================ + * @test_id ilm_takeScreenshot_validScreenAndHas_argb8888AndHas_wl_shm_AndCreateBufferFailed + * @brief Test case of ilm_takeScreenshot() where valid input screen + * @test_procedure Steps: + * -# Calling the ilm_takeScreenshot() time 1 + * -# Mocking the wl_proxy_marshal_flags() does return an object + * -# Mocking the wl_display_dispatch_queue() does return -1 (failure) + * -# Calling the ilm_takeScreenshot() time 2 + * -# Mocking the wl_display_dispatch_queue() does return 0 (success) + * -# Calling the ilm_takeScreenshot() time 3 + * -# Verification point: + * +# ilm_takeScreenshot() time 1 and time 2 and time 3 must return ILM_FAILED + */ + +TEST_F(IlmControlTest, ilm_takeScreenshot_validScreenAndHas_argb8888AndHas_wl_shm_AndCreateBufferFailed) +{ + ilm_context.wl.wl_shm = 0xFFFFFFFF; + ilm_context.wl.has_argb8888 = true; + void *screenshot[3] = {0xFFFFFFFF, NULL}; + int version[1] = {1}; + SET_RETURN_SEQ(wl_proxy_marshal_flags, screenshot, 2); + SET_RETURN_SEQ(wl_display_dispatch_queue, mp_successResult, 1); + SET_RETURN_SEQ(wl_proxy_get_version, version, 1); + ASSERT_EQ(ILM_FAILED, ilm_takeScreenshot(10, "test")); + ASSERT_EQ(wl_proxy_marshal_flags_fake.call_count, 3); + ilm_context.wl.wl_shm = NULL; + ilm_context.wl.has_argb8888 = false; +} + +/** ================================================================================================ + * @test_id ilm_takeScreenshot_AllInputValid + * @brief Test case of ilm_takeScreenshot() where valid input screen + * @test_procedure Steps: + * -# Calling the ilm_takeScreenshot() time 1 + * -# Mocking the wl_proxy_marshal_flags() does return an object + * -# Mocking the wl_display_dispatch_queue() does return -1 (failure) + * -# Calling the ilm_takeScreenshot() time 2 + * -# Mocking the wl_display_dispatch_queue() does return 0 (success) + * -# Calling the ilm_takeScreenshot() time 3 + * -# Verification point: + * +# ilm_takeScreenshot() time 1 and time 2 and time 3 must return ILM_FAILED + */ + +TEST_F(IlmControlTest, ilm_takeScreenshot_AllInputValid) +{ + ilm_context.wl.wl_shm = 0xFFFFFFFF; + ilm_context.wl.has_argb8888 = true; + void *screenshot[3] = {0xFFFFFFFF}; + int version[1] = {1}; + SET_RETURN_SEQ(wl_proxy_marshal_flags, screenshot, 1); + SET_RETURN_SEQ(wl_display_dispatch_queue, mp_failureResult, 1); + SET_RETURN_SEQ(wl_proxy_get_version, version, 1); + ASSERT_EQ(ILM_FAILED, ilm_takeScreenshot(10, "test")); + ASSERT_EQ(wl_proxy_marshal_flags_fake.call_count, 5); + ASSERT_EQ(wl_proxy_add_listener_fake.call_count, 1); + ilm_context.wl.wl_shm = NULL; + ilm_context.wl.has_argb8888 = false; +} + +/** ================================================================================================ + * @test_id ilm_takeAsyncScreenshot_AllInputValid + * @brief Test case of ilm_takeAsyncScreenshot() where valid input screen + * @test_procedure Steps: + * -# Calling the ilm_takeAsyncScreenshot() time 1 + * -# Mocking the wl_proxy_marshal_flags() does return an object + * -# Mocking the wl_display_dispatch_queue() does return -1 (failure) + * -# Calling the ilm_takeAsyncScreenshot() time 2 + * -# Mocking the wl_display_dispatch_queue() does return 0 (success) + * -# Calling the ilm_takeAsyncScreenshot() time 3 + * -# Verification point: + * +# ilm_takeAsyncScreenshot() time 1 and time 2 and time 3 must return ILM_FAILED + */ + +TEST_F(IlmControlTest, ilm_takeAsyncScreenshot_AllInputValid) +{ + ilm_context.wl.wl_shm = 0xFFFFFFFF; + ilm_context.wl.has_argb8888 = true; + void *screenshot[3] = {0xFFFFFFFF}; + int version[1] = {1}; + SET_RETURN_SEQ(wl_proxy_marshal_flags, screenshot, 1); + SET_RETURN_SEQ(wl_display_dispatch_queue, mp_failureResult, 1); + SET_RETURN_SEQ(wl_proxy_get_version, version, 1); + ASSERT_EQ(ILM_SUCCESS, ilm_takeAsyncScreenshot(10, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF)); + ASSERT_EQ(wl_proxy_marshal_flags_fake.call_count, 4); + ASSERT_EQ(wl_proxy_add_listener_fake.call_count, 1); + struct screenshot_context *ctx_scrshot = wl_proxy_add_listener_fake.arg2_val; + ASSERT_EQ(ctx_scrshot->callback_done, 0xFFFFFFFF); + ASSERT_EQ(ctx_scrshot->callback_error, 0xFFFFFFFF); + ASSERT_EQ(ctx_scrshot->callback_priv, 0xFFFFFFFF); + destroy_shm_buffer(ctx_scrshot->ivi_buffer); + free(ctx_scrshot); + ilm_context.wl.wl_shm = NULL; + ilm_context.wl.has_argb8888 = false; +} + /** ================================================================================================ * @test_id ilm_takeSurfaceScreenshot_invalidScreen * @brief Test case of ilm_takeSurfaceScreenshot() where do not mock for some functions @@ -4232,7 +4405,7 @@ TEST_F(IlmControlTest, ilm_takeSurfaceScreenshot_invalidScreen) } /** ================================================================================================ - * @test_id ilm_takeSurfaceScreenshot_invalidScreen + * @test_id ilm_takeSurfaceScreenshot_validScreen * @brief Test case of ilm_takeSurfaceScreenshot() where do mock for some functions * @test_procedure Steps: * -# Mocking the wl_proxy_marshal_flags() does return an object @@ -4255,3 +4428,563 @@ TEST_F(IlmControlTest, ilm_takeSurfaceScreenshot_validScreen) ASSERT_EQ(ILM_SUCCESS, ilm_takeSurfaceScreenshot(NULL, 1)); } + +/** ================================================================================================ + * @test_id ilm_takeSurfaceScreenshot_controllderIsNull + * @brief Test case of ilm_takeScreenshot() where valid input screen + * @test_procedure Steps: + * -# Calling the ilm_takeScreenshot() time 1 + * -# Mocking the wl_proxy_marshal_flags() does return an object + * -# Mocking the wl_display_dispatch_queue() does return -1 (failure) + * -# Calling the ilm_takeScreenshot() time 2 + * -# Mocking the wl_display_dispatch_queue() does return 0 (success) + * -# Calling the ilm_takeScreenshot() time 3 + * -# Verification point: + * +# ilm_takeScreenshot() time 1 and time 2 and time 3 must return ILM_FAILED + */ + +TEST_F(IlmControlTest, ilm_takeSurfaceScreenshot_controllderIsNull) +{ + ilm_context.wl.controller = NULL; + ASSERT_EQ(ILM_FAILED, ilm_takeSurfaceScreenshot("test", 1)); + ASSERT_EQ(wl_proxy_marshal_flags_fake.call_count, 0); + ASSERT_EQ(wl_display_roundtrip_queue_fake.call_count, 0); +} + +/** ================================================================================================ + * @test_id ilm_takeSurfaceScreenshot_wl_display_roundtrip_queueFailed + * @brief Test case of ilm_takeScreenshot() where valid input screen + * @test_procedure Steps: + * -# Calling the ilm_takeScreenshot() time 1 + * -# Mocking the wl_proxy_marshal_flags() does return an object + * -# Mocking the wl_display_dispatch_queue() does return -1 (failure) + * -# Calling the ilm_takeScreenshot() time 2 + * -# Mocking the wl_display_dispatch_queue() does return 0 (success) + * -# Calling the ilm_takeScreenshot() time 3 + * -# Verification point: + * +# ilm_takeScreenshot() time 1 and time 2 and time 3 must return ILM_FAILED + */ + +TEST_F(IlmControlTest, ilm_takeSurfaceScreenshot_wl_display_roundtrip_queueFailed) +{ + SET_RETURN_SEQ(wl_display_roundtrip_queue, mp_failureResult, 1); + ASSERT_EQ(ILM_FAILED, ilm_takeSurfaceScreenshot("test", 1)); + ASSERT_EQ(wl_proxy_marshal_flags_fake.call_count, 1); + ASSERT_EQ(wl_display_roundtrip_queue_fake.call_count, 1); +} + +/** ================================================================================================ + * @test_id ilm_takeSurfaceScreenshot_InvalidSurfaceID + * @brief Test case of ilm_takeScreenshot() where valid input screen + * @test_procedure Steps: + * -# Calling the ilm_takeScreenshot() time 1 + * -# Mocking the wl_proxy_marshal_flags() does return an object + * -# Mocking the wl_display_dispatch_queue() does return -1 (failure) + * -# Calling the ilm_takeScreenshot() time 2 + * -# Mocking the wl_display_dispatch_queue() does return 0 (success) + * -# Calling the ilm_takeScreenshot() time 3 + * -# Verification point: + * +# ilm_takeScreenshot() time 1 and time 2 and time 3 must return ILM_FAILED + */ + +TEST_F(IlmControlTest, ilm_takeSurfaceScreenshot_InvalidSurfaceID) +{ + SET_RETURN_SEQ(wl_display_roundtrip_queue, mp_successResult, 1); + ASSERT_EQ(ILM_FAILED, ilm_takeSurfaceScreenshot("test", 10)); + ASSERT_EQ(wl_proxy_marshal_flags_fake.call_count, 1); + ASSERT_EQ(wl_display_roundtrip_queue_fake.call_count, 1); +} + +/** ================================================================================================ + * @test_id ilm_takeSurfaceScreenshot_validScreenAndHas_argb8888AndNo_wl_shm + * @brief Test case of ilm_takeSurfaceScreenshot() where valid input screen + * @test_procedure Steps: + * -# Calling the ilm_takeSurfaceScreenshot() time 1 + * -# Mocking the wl_proxy_marshal_flags() does return an object + * -# Mocking the wl_display_dispatch_queue() does return -1 (failure) + * -# Calling the ilm_takeSurfaceScreenshot() time 2 + * -# Mocking the wl_display_dispatch_queue() does return 0 (success) + * -# Calling the ilm_takeSurfaceScreenshot() time 3 + * -# Verification point: + * +# ilm_takeSurfaceScreenshot() time 1 and time 2 and time 3 must return ILM_FAILED + */ + +TEST_F(IlmControlTest, ilm_takeSurfaceScreenshot_validScreenAndHas_argb8888AndNo_wl_shm) +{ + ilm_context.wl.wl_shm = NULL; + ilm_context.wl.has_argb8888 = true; + void *screenshot[1] = {0xFFFFFFFF}; + int version[1] = {1}; + SET_RETURN_SEQ(wl_proxy_marshal_flags, screenshot, 1); + SET_RETURN_SEQ(wl_display_dispatch_queue, mp_failureResult, 1); + SET_RETURN_SEQ(wl_proxy_get_version, version, 1); + SET_RETURN_SEQ(wl_display_roundtrip_queue, mp_failureResult, 1); + ASSERT_EQ(ILM_FAILED, ilm_takeSurfaceScreenshot("test", 1)); + ASSERT_EQ(wl_proxy_marshal_flags_fake.call_count, 1); + ASSERT_EQ(wl_display_roundtrip_queue_fake.call_count, 1); +} + +/** ================================================================================================ + * @test_id ilm_takeSurfaceScreenshot_validScreenAndHas_wl_shmAndNo_argb8888 + * @brief Test case of ilm_takeSurfaceScreenshot() where valid input screen + * @test_procedure Steps: + * -# Calling the ilm_takeSurfaceScreenshot() time 1 + * -# Mocking the wl_proxy_marshal_flags() does return an object + * -# Mocking the wl_display_dispatch_queue() does return -1 (failure) + * -# Calling the ilm_takeSurfaceScreenshot() time 2 + * -# Mocking the wl_display_dispatch_queue() does return 0 (success) + * -# Calling the ilm_takeSurfaceScreenshot() time 3 + * -# Verification point: + * +# ilm_takeSurfaceScreenshot() time 1 and time 2 and time 3 must return ILM_FAILED + */ + +TEST_F(IlmControlTest, ilm_takeSurfaceScreenshot_validScreenAndHas_wl_shmAndNo_argb8888) +{ + ilm_context.wl.wl_shm = 0xFFFFFFFF; + ilm_context.wl.has_argb8888 = false; + void *screenshot[1] = {0xFFFFFFFF}; + int version[1] = {1}; + SET_RETURN_SEQ(wl_proxy_marshal_flags, screenshot, 1); + SET_RETURN_SEQ(wl_display_dispatch_queue, mp_failureResult, 1); + SET_RETURN_SEQ(wl_proxy_get_version, version, 1); + SET_RETURN_SEQ(wl_display_roundtrip_queue, mp_failureResult, 1); + ASSERT_EQ(ILM_FAILED, ilm_takeSurfaceScreenshot("test", 1)); + ASSERT_EQ(wl_proxy_marshal_flags_fake.call_count, 1); + ASSERT_EQ(wl_display_roundtrip_queue_fake.call_count, 1); +} + +/** ================================================================================================ + * @test_id ilm_takeSurfaceScreenshot_CreateBufferFailed + * @brief Test case of ilm_takeSurfaceScreenshot() where valid input screen + * @test_procedure Steps: + * -# Calling the ilm_takeSurfaceScreenshot() time 1 + * -# Mocking the wl_proxy_marshal_flags() does return an object + * -# Mocking the wl_display_dispatch_queue() does return -1 (failure) + * -# Calling the ilm_takeSurfaceScreenshot() time 2 + * -# Mocking the wl_display_dispatch_queue() does return 0 (success) + * -# Calling the ilm_takeSurfaceScreenshot() time 3 + * -# Verification point: + * +# ilm_takeSurfaceScreenshot() time 1 and time 2 and time 3 must return ILM_FAILED + */ + +TEST_F(IlmControlTest, ilm_takeSurfaceScreenshot_CreateBufferFailed) +{ + ilm_context.wl.wl_shm = 0xFFFFFFFF; + ilm_context.wl.has_argb8888 = true; + void *screenshot[3] = {0xFFFFFFFF, 0xFFFFFFFF, NULL}; + int version[1] = {1}; + SET_RETURN_SEQ(wl_proxy_marshal_flags, screenshot, 3); + SET_RETURN_SEQ(wl_display_dispatch_queue, mp_successResult, 1); + SET_RETURN_SEQ(wl_proxy_get_version, version, 1); + ASSERT_EQ(ILM_FAILED, ilm_takeSurfaceScreenshot("test", 1)); + ASSERT_EQ(wl_proxy_marshal_flags_fake.call_count, 4); + ASSERT_EQ(wl_display_roundtrip_queue_fake.call_count, 1); +} + +/** ================================================================================================ + * @test_id ilm_takeSurfaceScreenshot_SendSurfaceScreenShotFailed + * @brief Test case of ilm_takeSurfaceScreenshot() where valid input screen + * @test_procedure Steps: + * -# Calling the ilm_takeSurfaceScreenshot() time 1 + * -# Mocking the wl_proxy_marshal_flags() does return an object + * -# Mocking the wl_display_dispatch_queue() does return -1 (failure) + * -# Calling the ilm_takeSurfaceScreenshot() time 2 + * -# Mocking the wl_display_dispatch_queue() does return 0 (success) + * -# Calling the ilm_takeSurfaceScreenshot() time 3 + * -# Verification point: + * +# ilm_takeSurfaceScreenshot() time 1 and time 2 and time 3 must return ILM_FAILED + */ + +TEST_F(IlmControlTest, ilm_takeSurfaceScreenshot_SendSurfaceScreenShotFailed) +{ + ilm_context.wl.wl_shm = 0xFFFFFFFF; + ilm_context.wl.has_argb8888 = true; + void *screenshot[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, NULL}; + int version[1] = {1}; + SET_RETURN_SEQ(wl_proxy_marshal_flags, screenshot, 4); + SET_RETURN_SEQ(wl_display_dispatch_queue, mp_successResult, 1); + SET_RETURN_SEQ(wl_proxy_get_version, version, 1); + ASSERT_EQ(ILM_FAILED, ilm_takeSurfaceScreenshot("test", 1)); + ASSERT_EQ(wl_proxy_marshal_flags_fake.call_count, 6); + ASSERT_EQ(wl_display_roundtrip_queue_fake.call_count, 1); + ASSERT_EQ(wl_proxy_add_listener_fake.call_count, 0); +} + +/** ================================================================================================ + * @test_id ilm_takeSurfaceScreenshot_SendSurfaceAllValid + * @brief Test case of ilm_takeSurfaceScreenshot() where valid input screen + * @test_procedure Steps: + * -# Calling the ilm_takeSurfaceScreenshot() time 1 + * -# Mocking the wl_proxy_marshal_flags() does return an object + * -# Mocking the wl_display_dispatch_queue() does return -1 (failure) + * -# Calling the ilm_takeSurfaceScreenshot() time 2 + * -# Mocking the wl_display_dispatch_queue() does return 0 (success) + * -# Calling the ilm_takeSurfaceScreenshot() time 3 + * -# Verification point: + * +# ilm_takeSurfaceScreenshot() time 1 and time 2 and time 3 must return ILM_FAILED + */ + +TEST_F(IlmControlTest, ilm_takeSurfaceScreenshot_SendSurfaceAllValid) +{ + ilm_context.wl.wl_shm = 0xFFFFFFFF; + ilm_context.wl.has_argb8888 = true; + void *screenshot[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, NULL}; + int version[1] = {1}; + SET_RETURN_SEQ(wl_proxy_marshal_flags, screenshot, 3); + SET_RETURN_SEQ(wl_display_dispatch_queue, mp_failureResult, 1); + SET_RETURN_SEQ(wl_proxy_get_version, version, 1); + ASSERT_EQ(ILM_FAILED, ilm_takeSurfaceScreenshot("test", 1)); + ASSERT_EQ(wl_proxy_marshal_flags_fake.call_count, 6); + ASSERT_EQ(wl_display_roundtrip_queue_fake.call_count, 1); + ASSERT_EQ(wl_proxy_add_listener_fake.call_count, 1); + ASSERT_EQ(wl_display_flush_fake.call_count, 0); + ASSERT_EQ(wl_display_dispatch_queue_fake.call_count, 1); +} + +/** ================================================================================================ + * @test_id ilm_takeAsyncSurfaceScreenshot_AllInputValid + * @brief Test case of ilm_takeAsyncSurfaceScreenshot() where valid input screen + * @test_procedure Steps: + * -# Calling the ilm_takeAsyncSurfaceScreenshot() time 1 + * -# Mocking the wl_proxy_marshal_flags() does return an object + * -# Mocking the wl_display_dispatch_queue() does return -1 (failure) + * -# Calling the ilm_takeAsyncSurfaceScreenshot() time 2 + * -# Mocking the wl_display_dispatch_queue() does return 0 (success) + * -# Calling the ilm_takeAsyncSurfaceScreenshot() time 3 + * -# Verification point: + * +# ilm_takeAsyncSurfaceScreenshot() time 1 and time 2 and time 3 must return ILM_FAILED + */ + +TEST_F(IlmControlTest, ilm_takeAsyncSurfaceScreenshot_AllInputValid) +{ + ilm_context.wl.wl_shm = 0xFFFFFFFF; + ilm_context.wl.has_argb8888 = true; + void *screenshot[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, NULL}; + int version[1] = {1}; + SET_RETURN_SEQ(wl_proxy_marshal_flags, screenshot, 3); + SET_RETURN_SEQ(wl_display_dispatch_queue, mp_failureResult, 1); + SET_RETURN_SEQ(wl_proxy_get_version, version, 1); + ASSERT_EQ(ILM_SUCCESS, ilm_takeAsyncSurfaceScreenshot(1, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF)); + ASSERT_EQ(wl_proxy_marshal_flags_fake.call_count, 5); + ASSERT_EQ(wl_display_roundtrip_queue_fake.call_count, 1); + ASSERT_EQ(wl_display_flush_fake.call_count, 1); + ASSERT_EQ(wl_proxy_add_listener_fake.call_count, 1); + ASSERT_EQ(wl_display_dispatch_queue_fake.call_count, 0); + struct screenshot_context *ctx_scrshot = wl_proxy_add_listener_fake.arg2_val; + ASSERT_EQ(ctx_scrshot->callback_done, 0xFFFFFFFF); + ASSERT_EQ(ctx_scrshot->callback_error, 0xFFFFFFFF); + ASSERT_EQ(ctx_scrshot->callback_priv, 0xFFFFFFFF); + destroy_shm_buffer(ctx_scrshot->ivi_buffer); + free(ctx_scrshot); + ilm_context.wl.wl_shm = NULL; + ilm_context.wl.has_argb8888 = false; +} + +/** ================================================================================================ + * @test_id screenshot_done_Unknown_file_format + * @brief Test case of ilm_takeAsyncSurfaceScreenshot() where valid input screen + * @test_procedure Steps: + * -# Calling the ilm_takeAsyncSurfaceScreenshot() time 1 + * -# Mocking the wl_proxy_marshal_flags() does return an object + * -# Mocking the wl_display_dispatch_queue() does return -1 (failure) + * -# Calling the ilm_takeAsyncSurfaceScreenshot() time 2 + * -# Mocking the wl_display_dispatch_queue() does return 0 (success) + * -# Calling the ilm_takeAsyncSurfaceScreenshot() time 3 + * -# Verification point: + * +# ilm_takeAsyncSurfaceScreenshot() time 1 and time 2 and time 3 must return ILM_FAILED + */ + +TEST_F(IlmControlTest, screenshot_done_Unknown_file_format) +{ + RESET_FAKE(save_as_png); + RESET_FAKE(save_as_bitmap); + screenshot_data_t screenshotData; + screenshotData.fd.store(-1); + ilm_context.wl.wl_shm = 0xFFFFFFFF; + ilm_context.wl.has_argb8888 = true; + void *screenshot[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, NULL}; + int version[1] = {1}; + SET_RETURN_SEQ(wl_proxy_marshal_flags, screenshot, 3); + SET_RETURN_SEQ(wl_display_dispatch_queue, mp_failureResult, 1); + SET_RETURN_SEQ(wl_proxy_get_version, version, 1); + ASSERT_EQ(ILM_SUCCESS, ilm_takeAsyncSurfaceScreenshot(1, ScreenshotDoneCallbackFunc, ScreenshotErrorCallbackFunc, &screenshotData)); + ASSERT_EQ(wl_proxy_marshal_flags_fake.call_count, 5); + ASSERT_EQ(wl_display_roundtrip_queue_fake.call_count, 1); + ASSERT_EQ(wl_display_flush_fake.call_count, 1); + ASSERT_EQ(wl_proxy_add_listener_fake.call_count, 1); + ASSERT_EQ(wl_display_dispatch_queue_fake.call_count, 0); + struct screenshot_context *ctx_scrshot = wl_proxy_add_listener_fake.arg2_val; + ASSERT_EQ(ctx_scrshot->callback_done, ScreenshotDoneCallbackFunc); + ASSERT_EQ(ctx_scrshot->callback_error, ScreenshotErrorCallbackFunc); + ASSERT_EQ(ctx_scrshot->callback_priv, &screenshotData); + ctx_scrshot->filename = "test.txt"; + screenshot_done(ctx_scrshot, 0xFFFFFFFF, 1); + ASSERT_EQ(save_as_png_fake.call_count, 0); + ASSERT_EQ(save_as_bitmap_fake.call_count, 1); + ilm_context.wl.wl_shm = NULL; + ilm_context.wl.has_argb8888 = false; + destroy_shm_buffer(ctx_scrshot->ivi_buffer); + // make sure call back is called + ASSERT_NE(screenshotData.fd.load(), -1); + free(ctx_scrshot); +} + +/** ================================================================================================ + * @test_id screenshot_done_png_file_format_save_as_png_passed + * @brief Test case of ilm_takeAsyncSurfaceScreenshot() where valid input screen + * @test_procedure Steps: + * -# Calling the ilm_takeAsyncSurfaceScreenshot() time 1 + * -# Mocking the wl_proxy_marshal_flags() does return an object + * -# Mocking the wl_display_dispatch_queue() does return -1 (failure) + * -# Calling the ilm_takeAsyncSurfaceScreenshot() time 2 + * -# Mocking the wl_display_dispatch_queue() does return 0 (success) + * -# Calling the ilm_takeAsyncSurfaceScreenshot() time 3 + * -# Verification point: + * +# ilm_takeAsyncSurfaceScreenshot() time 1 and time 2 and time 3 must return ILM_FAILED + */ + +TEST_F(IlmControlTest, screenshot_done_png_file_format_save_as_png_passed) +{ + RESET_FAKE(save_as_png); + RESET_FAKE(save_as_bitmap); + screenshot_data_t screenshotData; + screenshotData.fd.store(-1); + ilm_context.wl.wl_shm = 0xFFFFFFFF; + ilm_context.wl.has_argb8888 = true; + void *screenshot[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, NULL}; + int version[1] = {1}; + SET_RETURN_SEQ(wl_proxy_marshal_flags, screenshot, 3); + SET_RETURN_SEQ(wl_display_dispatch_queue, mp_failureResult, 1); + SET_RETURN_SEQ(wl_proxy_get_version, version, 1); + SET_RETURN_SEQ(wl_proxy_get_version, version, 1); + ASSERT_EQ(ILM_SUCCESS, ilm_takeAsyncSurfaceScreenshot(1, ScreenshotDoneCallbackFunc, ScreenshotErrorCallbackFunc, &screenshotData)); + ASSERT_EQ(wl_proxy_marshal_flags_fake.call_count, 5); + ASSERT_EQ(wl_display_roundtrip_queue_fake.call_count, 1); + ASSERT_EQ(wl_display_flush_fake.call_count, 1); + ASSERT_EQ(wl_proxy_add_listener_fake.call_count, 1); + ASSERT_EQ(wl_display_dispatch_queue_fake.call_count, 0); + struct screenshot_context *ctx_scrshot = wl_proxy_add_listener_fake.arg2_val; + ASSERT_EQ(ctx_scrshot->callback_done, ScreenshotDoneCallbackFunc); + ASSERT_EQ(ctx_scrshot->callback_error, ScreenshotErrorCallbackFunc); + ASSERT_EQ(ctx_scrshot->callback_priv, &screenshotData); + ctx_scrshot->filename = "test.png"; + int save_as_png_passed[1] = {0}; + SET_RETURN_SEQ(save_as_png, save_as_png_passed, 1); + screenshot_done(ctx_scrshot, 0xFFFFFFFF, 1); + ASSERT_EQ(save_as_png_fake.call_count, 1); + ASSERT_EQ(save_as_bitmap_fake.call_count, 0); + ASSERT_EQ(ctx_scrshot->result, ILM_SUCCESS); + ilm_context.wl.wl_shm = NULL; + ilm_context.wl.has_argb8888 = false; + destroy_shm_buffer(ctx_scrshot->ivi_buffer); + // make sure call back is called + ASSERT_NE(screenshotData.fd.load(), -1); + free(ctx_scrshot); +} + +/** ================================================================================================ + * @test_id screenshot_done_png_file_format_save_as_png_failed + * @brief Test case of ilm_takeAsyncSurfaceScreenshot() where valid input screen + * @test_procedure Steps: + * -# Calling the ilm_takeAsyncSurfaceScreenshot() time 1 + * -# Mocking the wl_proxy_marshal_flags() does return an object + * -# Mocking the wl_display_dispatch_queue() does return -1 (failure) + * -# Calling the ilm_takeAsyncSurfaceScreenshot() time 2 + * -# Mocking the wl_display_dispatch_queue() does return 0 (success) + * -# Calling the ilm_takeAsyncSurfaceScreenshot() time 3 + * -# Verification point: + * +# ilm_takeAsyncSurfaceScreenshot() time 1 and time 2 and time 3 must return ILM_FAILED + */ + +TEST_F(IlmControlTest, screenshot_done_png_file_format_save_as_png_failed) +{ + RESET_FAKE(save_as_png); + RESET_FAKE(save_as_bitmap); + screenshot_data_t screenshotData; + screenshotData.fd.store(-1); + ilm_context.wl.wl_shm = 0xFFFFFFFF; + ilm_context.wl.has_argb8888 = true; + void *screenshot[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, NULL}; + int version[1] = {1}; + SET_RETURN_SEQ(wl_proxy_marshal_flags, screenshot, 3); + SET_RETURN_SEQ(wl_display_dispatch_queue, mp_failureResult, 1); + SET_RETURN_SEQ(wl_proxy_get_version, version, 1); + SET_RETURN_SEQ(wl_proxy_get_version, version, 1); + ASSERT_EQ(ILM_SUCCESS, ilm_takeAsyncSurfaceScreenshot(1, ScreenshotDoneCallbackFunc, ScreenshotErrorCallbackFunc, &screenshotData)); + ASSERT_EQ(wl_proxy_marshal_flags_fake.call_count, 5); + ASSERT_EQ(wl_display_roundtrip_queue_fake.call_count, 1); + ASSERT_EQ(wl_display_flush_fake.call_count, 1); + ASSERT_EQ(wl_proxy_add_listener_fake.call_count, 1); + ASSERT_EQ(wl_display_dispatch_queue_fake.call_count, 0); + struct screenshot_context *ctx_scrshot = wl_proxy_add_listener_fake.arg2_val; + ASSERT_EQ(ctx_scrshot->callback_done, ScreenshotDoneCallbackFunc); + ASSERT_EQ(ctx_scrshot->callback_error, ScreenshotErrorCallbackFunc); + ASSERT_EQ(ctx_scrshot->callback_priv, &screenshotData); + ctx_scrshot->filename = "test.png"; + int save_as_png_failed[1] = {1}; + SET_RETURN_SEQ(save_as_png, save_as_png_failed, 1); + screenshot_done(ctx_scrshot, 0xFFFFFFFF, 1); + ASSERT_EQ(save_as_png_fake.call_count, 1); + ASSERT_EQ(save_as_bitmap_fake.call_count, 0); + ASSERT_EQ(ctx_scrshot->result, ILM_FAILED); + ilm_context.wl.wl_shm = NULL; + ilm_context.wl.has_argb8888 = false; + destroy_shm_buffer(ctx_scrshot->ivi_buffer); + // make sure call back is called + ASSERT_NE(screenshotData.fd.load(), -1); + free(ctx_scrshot); +} + +/** ================================================================================================ + * @test_id screenshot_done_bitmap_file_format_save_as_bitmap_passed + * @brief Test case of ilm_takeAsyncSurfaceScreenshot() where valid input screen + * @test_procedure Steps: + * -# Calling the ilm_takeAsyncSurfaceScreenshot() time 1 + * -# Mocking the wl_proxy_marshal_flags() does return an object + * -# Mocking the wl_display_dispatch_queue() does return -1 (failure) + * -# Calling the ilm_takeAsyncSurfaceScreenshot() time 2 + * -# Mocking the wl_display_dispatch_queue() does return 0 (success) + * -# Calling the ilm_takeAsyncSurfaceScreenshot() time 3 + * -# Verification point: + * +# ilm_takeAsyncSurfaceScreenshot() time 1 and time 2 and time 3 must return ILM_FAILED + */ + +TEST_F(IlmControlTest, screenshot_done_bitmap_file_format_save_as_bitmap_passed) +{ + RESET_FAKE(save_as_png); + RESET_FAKE(save_as_bitmap); + screenshot_data_t screenshotData; + screenshotData.fd.store(-1); + ilm_context.wl.wl_shm = 0xFFFFFFFF; + ilm_context.wl.has_argb8888 = true; + void *screenshot[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, NULL}; + int version[1] = {1}; + SET_RETURN_SEQ(wl_proxy_marshal_flags, screenshot, 3); + SET_RETURN_SEQ(wl_display_dispatch_queue, mp_failureResult, 1); + SET_RETURN_SEQ(wl_proxy_get_version, version, 1); + SET_RETURN_SEQ(wl_proxy_get_version, version, 1); + ASSERT_EQ(ILM_SUCCESS, ilm_takeAsyncSurfaceScreenshot(1, ScreenshotDoneCallbackFunc, ScreenshotErrorCallbackFunc, &screenshotData)); + ASSERT_EQ(wl_proxy_marshal_flags_fake.call_count, 5); + ASSERT_EQ(wl_display_roundtrip_queue_fake.call_count, 1); + ASSERT_EQ(wl_display_flush_fake.call_count, 1); + ASSERT_EQ(wl_proxy_add_listener_fake.call_count, 1); + ASSERT_EQ(wl_display_dispatch_queue_fake.call_count, 0); + struct screenshot_context *ctx_scrshot = wl_proxy_add_listener_fake.arg2_val; + ASSERT_EQ(ctx_scrshot->callback_done, ScreenshotDoneCallbackFunc); + ASSERT_EQ(ctx_scrshot->callback_error, ScreenshotErrorCallbackFunc); + ASSERT_EQ(ctx_scrshot->callback_priv, &screenshotData); + ctx_scrshot->filename = "test.bmp"; + int save_as_bitmap_passed[1] = {0}; + SET_RETURN_SEQ(save_as_bitmap, save_as_bitmap_passed, 1); + screenshot_done(ctx_scrshot, 0xFFFFFFFF, 1); + ASSERT_EQ(save_as_png_fake.call_count, 0); + ASSERT_EQ(save_as_bitmap_fake.call_count, 1); + ASSERT_EQ(ctx_scrshot->result, ILM_SUCCESS); + ilm_context.wl.wl_shm = NULL; + ilm_context.wl.has_argb8888 = false; + destroy_shm_buffer(ctx_scrshot->ivi_buffer); + // make sure call back is called + ASSERT_NE(screenshotData.fd.load(), -1); + free(ctx_scrshot); +} + +/** ================================================================================================ + * @test_id screenshot_done_bitmap_file_format_save_as_bitmap_failed + * @brief Test case of ilm_takeAsyncSurfaceScreenshot() where valid input screen + * @test_procedure Steps: + * -# Calling the ilm_takeAsyncSurfaceScreenshot() time 1 + * -# Mocking the wl_proxy_marshal_flags() does return an object + * -# Mocking the wl_display_dispatch_queue() does return -1 (failure) + * -# Calling the ilm_takeAsyncSurfaceScreenshot() time 2 + * -# Mocking the wl_display_dispatch_queue() does return 0 (success) + * -# Calling the ilm_takeAsyncSurfaceScreenshot() time 3 + * -# Verification point: + * +# ilm_takeAsyncSurfaceScreenshot() time 1 and time 2 and time 3 must return ILM_FAILED + */ + +TEST_F(IlmControlTest, screenshot_done_bitmap_file_format_save_as_bitmap_failed) +{ + RESET_FAKE(save_as_png); + RESET_FAKE(save_as_bitmap); + screenshot_data_t screenshotData; + screenshotData.fd.store(-1); + ilm_context.wl.wl_shm = 0xFFFFFFFF; + ilm_context.wl.has_argb8888 = true; + void *screenshot[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, NULL}; + int version[1] = {1}; + SET_RETURN_SEQ(wl_proxy_marshal_flags, screenshot, 3); + SET_RETURN_SEQ(wl_display_dispatch_queue, mp_failureResult, 1); + SET_RETURN_SEQ(wl_proxy_get_version, version, 1); + ASSERT_EQ(ILM_SUCCESS, ilm_takeAsyncSurfaceScreenshot(1, ScreenshotDoneCallbackFunc, ScreenshotErrorCallbackFunc, &screenshotData)); + ASSERT_EQ(wl_proxy_marshal_flags_fake.call_count, 5); + ASSERT_EQ(wl_display_roundtrip_queue_fake.call_count, 1); + ASSERT_EQ(wl_display_flush_fake.call_count, 1); + ASSERT_EQ(wl_proxy_add_listener_fake.call_count, 1); + ASSERT_EQ(wl_display_dispatch_queue_fake.call_count, 0); + struct screenshot_context *ctx_scrshot = wl_proxy_add_listener_fake.arg2_val; + ASSERT_EQ(ctx_scrshot->callback_done, ScreenshotDoneCallbackFunc); + ASSERT_EQ(ctx_scrshot->callback_error, ScreenshotErrorCallbackFunc); + ASSERT_EQ(ctx_scrshot->callback_priv, &screenshotData); + ctx_scrshot->filename = "test.bmp"; + int save_as_bitmap_failed[1] = {1}; + SET_RETURN_SEQ(save_as_bitmap, save_as_bitmap_failed, 1); + screenshot_done(ctx_scrshot, 0xFFFFFFFF, 1); + ASSERT_EQ(save_as_png_fake.call_count, 0); + ASSERT_EQ(save_as_bitmap_fake.call_count, 1); + ASSERT_EQ(ctx_scrshot->result, ILM_FAILED); + ilm_context.wl.wl_shm = NULL; + ilm_context.wl.has_argb8888 = false; + destroy_shm_buffer(ctx_scrshot->ivi_buffer); + // make sure call back is called + ASSERT_NE(screenshotData.fd.load(), -1); + free(ctx_scrshot); +} + +/** ================================================================================================ + * @test_id screenshot_error_check_call + * @brief Test case of ilm_takeAsyncSurfaceScreenshot() where valid input screen + * @test_procedure Steps: + * -# Calling the ilm_takeAsyncSurfaceScreenshot() time 1 + * -# Mocking the wl_proxy_marshal_flags() does return an object + * -# Mocking the wl_display_dispatch_queue() does return -1 (failure) + * -# Calling the ilm_takeAsyncSurfaceScreenshot() time 2 + * -# Mocking the wl_display_dispatch_queue() does return 0 (success) + * -# Calling the ilm_takeAsyncSurfaceScreenshot() time 3 + * -# Verification point: + * +# ilm_takeAsyncSurfaceScreenshot() time 1 and time 2 and time 3 must return ILM_FAILED + */ + +TEST_F(IlmControlTest, screenshot_error_check_call) +{ + RESET_FAKE(save_as_png); + RESET_FAKE(save_as_bitmap); + screenshot_data_t screenshotData; + screenshotData.error.store(-1); + ilm_context.wl.wl_shm = 0xFFFFFFFF; + ilm_context.wl.has_argb8888 = true; + void *screenshot[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, NULL}; + int version[1] = {1}; + SET_RETURN_SEQ(wl_proxy_marshal_flags, screenshot, 3); + SET_RETURN_SEQ(wl_display_dispatch_queue, mp_failureResult, 1); + SET_RETURN_SEQ(wl_proxy_get_version, version, 1); + ASSERT_EQ(ILM_SUCCESS, ilm_takeAsyncSurfaceScreenshot(1, ScreenshotDoneCallbackFunc, ScreenshotErrorCallbackFunc, &screenshotData)); + ASSERT_EQ(wl_proxy_marshal_flags_fake.call_count, 5); + ASSERT_EQ(wl_display_roundtrip_queue_fake.call_count, 1); + ASSERT_EQ(wl_display_flush_fake.call_count, 1); + ASSERT_EQ(wl_proxy_add_listener_fake.call_count, 1); + ASSERT_EQ(wl_display_dispatch_queue_fake.call_count, 0); + struct screenshot_context *ctx_scrshot = wl_proxy_add_listener_fake.arg2_val; + ASSERT_EQ(ctx_scrshot->callback_done, ScreenshotDoneCallbackFunc); + ASSERT_EQ(ctx_scrshot->callback_error, ScreenshotErrorCallbackFunc); + ASSERT_EQ(ctx_scrshot->callback_priv, &screenshotData); + ctx_scrshot->filename = "test.txt"; + screenshot_error(ctx_scrshot, 0xFFFFFFFF, 1, "Error message"); + ASSERT_EQ(save_as_png_fake.call_count, 0); + ASSERT_EQ(save_as_bitmap_fake.call_count, 0); + ilm_context.wl.wl_shm = NULL; + ilm_context.wl.has_argb8888 = false; + destroy_shm_buffer(ctx_scrshot->ivi_buffer); + // make sure call back is called + ASSERT_NE(screenshotData.error.load(), -1); + free(ctx_scrshot); +} \ No newline at end of file diff --git a/unittest/server/include/ivi_layout_interface_fake.h b/unittest/server/include/ivi_layout_interface_fake.h index 5c8839f..d5da1e5 100644 --- a/unittest/server/include/ivi_layout_interface_fake.h +++ b/unittest/server/include/ivi_layout_interface_fake.h @@ -21,7 +21,7 @@ #define IVI_LAYOUT_INTERFACE_FAKE #include "ivi-wm-server-protocol.h" #include "ivi-layout-export.h" -#include "libweston-desktop/libweston-desktop.h" +#include #include "weston.h" #include "fff.h" diff --git a/unittest/server/include/ivi_layout_structure.hpp b/unittest/server/include/ivi_layout_structure.hpp index 7073711..d655826 100644 --- a/unittest/server/include/ivi_layout_structure.hpp +++ b/unittest/server/include/ivi_layout_structure.hpp @@ -23,7 +23,7 @@ #include #include "libweston/libweston.h" #include "ivi-layout-export.h" -#include "libweston-desktop/libweston-desktop.h" +#include struct ivi_layout_view { struct wl_list link; /* ivi_layout::view_list */ diff --git a/unittest/server/include/server_api_fake.h b/unittest/server/include/server_api_fake.h index 6bb6a9b..c9a1bb3 100644 --- a/unittest/server/include/server_api_fake.h +++ b/unittest/server/include/server_api_fake.h @@ -23,7 +23,7 @@ #include "fff.h" #include "ivi-wm-server-protocol.h" #include "ivi-layout-export.h" -#include "libweston-desktop/libweston-desktop.h" +#include #include "weston.h" #include "common_fake_api.h" diff --git a/unittest/server/src/ivi_controller_uinttests.cpp b/unittest/server/src/ivi_controller_uinttests.cpp index 4716052..7365677 100644 --- a/unittest/server/src/ivi_controller_uinttests.cpp +++ b/unittest/server/src/ivi_controller_uinttests.cpp @@ -1308,6 +1308,8 @@ TEST_F(ControllerTests, controller_screen_screenshot_nullScreenShot) controller_screen_screenshot(nullptr, nullptr, nullptr, l_id); ASSERT_EQ(wl_resource_post_no_memory_fake.call_count, 1); + ASSERT_EQ(wl_resource_post_no_memory_fake.arg0_history[0], NULL); + ASSERT_EQ(wl_resource_get_user_data_fake.return_val_history[0], NULL); } /** ================================================================================================ @@ -1329,10 +1331,41 @@ TEST_F(ControllerTests, controller_screen_screenshot_nullScreen) uint32_t l_id = 10; controller_screen_screenshot(nullptr, nullptr, nullptr, l_id); + ASSERT_EQ(wl_resource_get_user_data_fake.return_val_history[0], NULL); ASSERT_EQ(wl_resource_post_event_fake.call_count, 1); + ASSERT_EQ(wl_resource_post_event_fake.arg1_history[0], IVI_SCREENSHOT_ERROR); ASSERT_EQ(wl_resource_destroy_fake.call_count, 1); } +/** ================================================================================================ + * @test_id controller_screen_screenshot_nullWestonBuffer + * @brief Test case of controller_screen_screenshot() where wl_resource_create() success, return an object + * but wl_resource_get_user_data() fails, return null pointer + * @test_procedure Steps: + * -# Mocking the wl_resource_create() does return an object + * -# Calling the controller_screen_screenshot() + * -# Verification point: + * +# wl_resource_post_event() must be called once time + * +# wl_resource_destroy() must be called once time + */ +TEST_F(ControllerTests, controller_screen_screenshot_nullWestonBuffer) +{ + void * buffer[1] = {nullptr}; + struct wl_resource * screenshot[1] = {(struct wl_resource *)0xFFFFFFFF}; + SET_RETURN_SEQ(wl_resource_create, screenshot, 1); + SET_RETURN_SEQ(wl_resource_get_user_data, (void**)mp_iviScreen, 1); + SET_RETURN_SEQ(weston_buffer_from_resource, buffer, 1); + uint32_t l_id = 10; + controller_screen_screenshot(nullptr, nullptr, nullptr, l_id); + + ASSERT_EQ(wl_resource_post_no_memory_fake.call_count, 0); + ASSERT_EQ(wl_resource_create_fake.call_count, 1); + ASSERT_EQ(weston_buffer_from_resource_fake.call_count, 1); + ASSERT_EQ(wl_resource_post_event_fake.call_count, 1); + ASSERT_EQ(wl_resource_post_event_fake.arg1_history[0], IVI_SCREENSHOT_ERROR); + ASSERT_EQ(wl_shm_buffer_get_data_fake.call_count, 0); +} + /** ================================================================================================ * @test_id controller_screen_screenshot_success * @brief Test case of controller_screen_screenshot() where wl_resource_create() success, return an object @@ -1356,9 +1389,10 @@ TEST_F(ControllerTests, controller_screen_screenshot_success) uint32_t l_id = 10; controller_screen_screenshot(nullptr, nullptr, nullptr, l_id); - ASSERT_EQ(wl_resource_set_implementation_fake.call_count, 1); - ASSERT_EQ(wl_resource_set_implementation_fake.call_count, 1); - ASSERT_EQ(weston_screenshooter_shoot_fake.call_count, 1); + ASSERT_EQ(wl_resource_post_no_memory_fake.call_count, 0); + ASSERT_EQ(wl_resource_create_fake.call_count, 1); + ASSERT_EQ(weston_buffer_from_resource_fake.call_count, 1); + ASSERT_EQ(wl_resource_destroy_fake.call_count, 0); struct screenshot_frame_listener *lp_l = (struct screenshot_frame_listener*)wl_resource_set_implementation_fake.arg2_history[0]; free(lp_l); @@ -2341,8 +2375,11 @@ TEST_F(ControllerTests, controller_surface_screenshot_errByLayoutSurface) controller_surface_screenshot(nullptr, nullptr, nullptr, 1, 1); - ASSERT_EQ(wl_resource_post_event_fake.call_count, 1); + ASSERT_EQ(get_surface_from_id_fake.call_count, 1); ASSERT_EQ(wl_resource_destroy_fake.call_count, 1); + ASSERT_EQ(wl_resource_post_event_fake.call_count, 1); + ASSERT_EQ(wl_resource_post_event_fake.arg1_val, IVI_SCREENSHOT_ERROR); + ASSERT_EQ(surface_get_size_fake.call_count, 0); } /** ================================================================================================ @@ -2370,7 +2407,48 @@ TEST_F(ControllerTests, controller_surface_screenshot_errByResult) controller_surface_screenshot(nullptr, nullptr, nullptr, 1, 1); + ASSERT_EQ(get_surface_from_id_fake.call_count, 1); + ASSERT_EQ(wl_resource_destroy_fake.call_count, 1); ASSERT_EQ(wl_resource_post_event_fake.call_count, 1); + ASSERT_EQ(wl_resource_post_event_fake.arg1_val, IVI_SCREENSHOT_ERROR); + ASSERT_EQ(surface_get_size_fake.call_count, 1); + ASSERT_EQ(weston_buffer_from_resource_fake.call_count, 0); +} + +/** ================================================================================================ + * @test_id controller_surface_screenshot_errWhenGetWestonBuffer + * @brief Test case of controller_surface_screenshot() where surface_dump() fails, return -1 + * @test_procedure Steps: + * -# Mocking the wl_resource_get_user_data() does return an object + * -# Mocking the wl_resource_create() does return an object + * -# Mocking the get_surface_from_id() does return an object + * -# Set the surface_get_size() does return null pointer + * -# Mocking the surface_dump() does return -1 + * -# Calling the controller_surface_screenshot() + * -# Verification point: + * +# wl_resource_post_event() must be called once time + * +# wl_resource_destroy() must be called once time + */ +TEST_F(ControllerTests, controller_surface_screenshot_errWhenGetWestonBuffer) +{ + SET_RETURN_SEQ(wl_resource_get_user_data, (void**)mp_iviController, 1); + struct wl_resource *screenshot[1] = {(struct wl_resource *)0xFFFFFFFF}; + SET_RETURN_SEQ(wl_resource_create, screenshot, 1); + struct ivi_layout_surface *l_layout_surface[1] = {(struct ivi_layout_surface *)0xFFFFFFFF}; + SET_RETURN_SEQ(get_surface_from_id, l_layout_surface, 1); + surface_get_size_fake.custom_fake = custom_surface_get_size; + SET_RETURN_SEQ(surface_dump, &mp_failureResult[0], 1); + struct weston_buffer * westonBuffer[1] = {NULL}; + SET_RETURN_SEQ(weston_buffer_from_resource, (struct weston_buffer **)westonBuffer, 1); + + controller_surface_screenshot(nullptr, nullptr, nullptr, 1, 1); + + ASSERT_EQ(get_surface_from_id_fake.call_count, 1); + ASSERT_EQ(surface_get_size_fake.call_count, 1); + ASSERT_EQ(weston_buffer_from_resource_fake.call_count, 1); + ASSERT_EQ(weston_buffer_from_resource_fake.return_val, NULL); + ASSERT_EQ(wl_resource_post_event_fake.call_count, 1); + ASSERT_EQ(wl_resource_post_event_fake.arg1_val, IVI_SCREENSHOT_ERROR); ASSERT_EQ(wl_resource_destroy_fake.call_count, 1); } @@ -2395,14 +2473,27 @@ TEST_F(ControllerTests, controller_surface_screenshot_errReadpixByResult) SET_RETURN_SEQ(wl_resource_create, screenshot, 1); struct ivi_layout_surface *l_layout_surface[1] = {(struct ivi_layout_surface *)0xFFFFFFFF}; SET_RETURN_SEQ(get_surface_from_id, l_layout_surface, 1); - surface_get_size_fake.custom_fake = custom_surface_get_size; SET_RETURN_SEQ(surface_dump, &mp_failureResult[0], 1); - + struct weston_buffer * westonBuffer = (struct weston_buffer*)malloc(sizeof(weston_buffer)); + westonBuffer->type = 1; + struct weston_buffer * westonBufferRet[1] = {westonBuffer}; + SET_RETURN_SEQ(weston_buffer_from_resource, (struct weston_buffer **)westonBufferRet, 1); + int validStride[1] = {4}; + int validWidth[1] = {1}; + int validheight[1] = {1}; + SET_RETURN_SEQ(wl_shm_buffer_get_stride, validStride, 1); + SET_RETURN_SEQ(wl_shm_buffer_get_width, validWidth, 1); + SET_RETURN_SEQ(wl_shm_buffer_get_height, validheight, 1); controller_surface_screenshot(nullptr, nullptr, nullptr, 1, 1); - ASSERT_EQ(wl_resource_post_event_fake.call_count, 1); + ASSERT_EQ(get_surface_from_id_fake.call_count, 1); ASSERT_EQ(wl_resource_destroy_fake.call_count, 1); + ASSERT_EQ(wl_resource_post_event_fake.call_count, 1); + ASSERT_EQ(wl_resource_post_event_fake.arg1_val, IVI_SCREENSHOT_ERROR); + ASSERT_EQ(surface_get_size_fake.call_count, 1); + ASSERT_EQ(weston_buffer_from_resource_fake.call_count, 1); + free(westonBuffer); } /** ================================================================================================ @@ -2426,14 +2517,151 @@ TEST_F(ControllerTests, controller_surface_screenshot_success) SET_RETURN_SEQ(wl_resource_create, screenshot, 1); struct ivi_layout_surface *l_layout_surface[1] = {(struct ivi_layout_surface *)0xFFFFFFFF}; SET_RETURN_SEQ(get_surface_from_id, l_layout_surface, 1); - surface_get_size_fake.custom_fake = custom_surface_get_size; - SET_RETURN_SEQ(surface_dump, mp_successResult, 1); + struct weston_buffer * westonBuffer = (struct weston_buffer*)malloc(sizeof(weston_buffer)); + westonBuffer->type = 0; // WESTON_BUFFER_SHM + struct weston_buffer * westonBufferRet[1] = {westonBuffer}; + SET_RETURN_SEQ(weston_buffer_from_resource, (struct weston_buffer **)westonBufferRet, 1); + int validStride[1] = {4}; + int validWidth[1] = {1}; + int validheight[1] = {1}; + SET_RETURN_SEQ(wl_shm_buffer_get_stride, validStride, 1); + SET_RETURN_SEQ(wl_shm_buffer_get_width, validWidth, 1); + SET_RETURN_SEQ(wl_shm_buffer_get_height, validheight, 1); controller_surface_screenshot(nullptr, nullptr, nullptr, 1, 1); - ASSERT_EQ(wl_resource_post_event_fake.call_count, 1); + ASSERT_EQ(get_surface_from_id_fake.call_count, 1); ASSERT_EQ(wl_resource_destroy_fake.call_count, 1); + ASSERT_EQ(surface_get_size_fake.call_count, 1); + ASSERT_EQ(weston_buffer_from_resource_fake.call_count, 1); + ASSERT_EQ(surface_dump_fake.call_count, 1); + ASSERT_EQ(wl_resource_post_event_fake.call_count, 1); + ASSERT_EQ(wl_resource_post_event_fake.arg1_val, IVI_SCREENSHOT_DONE); + free(westonBuffer); +} + +/** ================================================================================================ + * @test_id controller_screenshooter_done_case_WESTON_SCREENSHOOTER_SUCCESS + * @brief Test case of controller_surface_screenshot() where surface_dump() success, return 0 + * @test_procedure Steps: + * -# Mocking the wl_resource_get_user_data() does return an object + * -# Mocking the wl_resource_create() does return an object + * -# Mocking the get_surface_from_id() does return an object + * -# Set the surface_get_size() does return null pointer + * -# Mocking the surface_dump() does return 0 + * -# Calling the controller_surface_screenshot() + * -# Verification point: + * +# wl_resource_post_event() must be called once time + * +# wl_resource_destroy() must be called once time + */ +TEST_F(ControllerTests, controller_screenshooter_done_case_WESTON_SCREENSHOOTER_SUCCESS) +{ + struct ivi_screenshooter *screenshooter = (struct ivi_screenshooter *)malloc(sizeof(struct ivi_screenshooter)); + screenshooter->output = &m_westonOutput[0]; + weston_screenshooter_outcome outcome = WESTON_SCREENSHOOTER_SUCCESS; + controller_screenshooter_done(screenshooter, outcome); + ASSERT_EQ(wl_resource_post_event_fake.call_count, 1); + ASSERT_EQ(wl_resource_post_event_fake.arg1_val, IVI_SCREENSHOT_DONE); + free(screenshooter); +} + +/** ================================================================================================ + * @test_id controller_screenshooter_done_case_WESTON_SCREENSHOOTER_NO_MEMORY + * @brief Test case of controller_surface_screenshot() where surface_dump() success, return 0 + * @test_procedure Steps: + * -# Mocking the wl_resource_get_user_data() does return an object + * -# Mocking the wl_resource_create() does return an object + * -# Mocking the get_surface_from_id() does return an object + * -# Set the surface_get_size() does return null pointer + * -# Mocking the surface_dump() does return 0 + * -# Calling the controller_surface_screenshot() + * -# Verification point: + * +# wl_resource_post_event() must be called once time + * +# wl_resource_destroy() must be called once time + */ +TEST_F(ControllerTests, controller_screenshooter_done_case_WESTON_SCREENSHOOTER_NO_MEMORY) +{ + struct ivi_screenshooter *screenshooter = (struct ivi_screenshooter *)malloc(sizeof(struct ivi_screenshooter)); + screenshooter->output = &m_westonOutput[0]; + weston_screenshooter_outcome outcome = WESTON_SCREENSHOOTER_NO_MEMORY; + controller_screenshooter_done(screenshooter, outcome); + ASSERT_EQ(wl_resource_post_event_fake.call_count, 1); + ASSERT_EQ(wl_resource_post_event_fake.arg1_val, IVI_SCREENSHOT_ERROR); + free(screenshooter); +} + +/** ================================================================================================ + * @test_id controller_screenshooter_done_case_WESTON_SCREENSHOOTER_BAD_BUFFER + * @brief Test case of controller_surface_screenshot() where surface_dump() success, return 0 + * @test_procedure Steps: + * -# Mocking the wl_resource_get_user_data() does return an object + * -# Mocking the wl_resource_create() does return an object + * -# Mocking the get_surface_from_id() does return an object + * -# Set the surface_get_size() does return null pointer + * -# Mocking the surface_dump() does return 0 + * -# Calling the controller_surface_screenshot() + * -# Verification point: + * +# wl_resource_post_event() must be called once time + * +# wl_resource_destroy() must be called once time + */ +TEST_F(ControllerTests, controller_screenshooter_done_case_WESTON_SCREENSHOOTER_BAD_BUFFER) +{ + struct ivi_screenshooter *screenshooter = (struct ivi_screenshooter *)malloc(sizeof(struct ivi_screenshooter)); + screenshooter->output = &m_westonOutput[0]; + weston_screenshooter_outcome outcome = WESTON_SCREENSHOOTER_BAD_BUFFER; + controller_screenshooter_done(screenshooter, outcome); + ASSERT_EQ(wl_resource_post_event_fake.call_count, 1); + ASSERT_EQ(wl_resource_post_event_fake.arg1_val, IVI_SCREENSHOT_ERROR); + free(screenshooter); +} + +/** ================================================================================================ + * @test_id controller_screenshooter_done_case_unknown_type + * @brief Test case of controller_surface_screenshot() where surface_dump() success, return 0 + * @test_procedure Steps: + * -# Mocking the wl_resource_get_user_data() does return an object + * -# Mocking the wl_resource_create() does return an object + * -# Mocking the get_surface_from_id() does return an object + * -# Set the surface_get_size() does return null pointer + * -# Mocking the surface_dump() does return 0 + * -# Calling the controller_surface_screenshot() + * -# Verification point: + * +# wl_resource_post_event() must be called once time + * +# wl_resource_destroy() must be called once time + */ +TEST_F(ControllerTests, controller_screenshooter_done_case_unknown_type) +{ + struct ivi_screenshooter *screenshooter = (struct ivi_screenshooter *)malloc(sizeof(struct ivi_screenshooter)); + screenshooter->output = &m_westonOutput[0]; + weston_screenshooter_outcome outcome = (weston_screenshooter_outcome)10; + controller_screenshooter_done(screenshooter, outcome); + ASSERT_EQ(wl_resource_post_event_fake.call_count, 0); + free(screenshooter); +} + +/** ================================================================================================ + * @test_id controller_screenshoot_destroy_call + * @brief Test case of controller_surface_screenshot() where surface_dump() success, return 0 + * @test_procedure Steps: + * -# Mocking the wl_resource_get_user_data() does return an object + * -# Mocking the wl_resource_create() does return an object + * -# Mocking the get_surface_from_id() does return an object + * -# Set the surface_get_size() does return null pointer + * -# Mocking the surface_dump() does return 0 + * -# Calling the controller_surface_screenshot() + * -# Verification point: + * +# wl_resource_post_event() must be called once time + * +# wl_resource_destroy() must be called once time + */ +TEST_F(ControllerTests, controller_screenshoot_destroy_call) +{ + struct ivi_screenshooter * screenshooter = (struct ivi_screenshooter *)malloc(sizeof(struct ivi_screenshooter)); + screenshooter->output = &m_westonOutput[0]; + struct ivi_screenshooter * screenshooterRet[1] = {screenshooter}; + SET_RETURN_SEQ(wl_resource_get_user_data, (struct ivi_screenshooter **)screenshooterRet, 1); + controller_screenshoot_destroy(nullptr); + ASSERT_EQ(wl_resource_get_user_data_fake.call_count, 1); } /** ================================================================================================ @@ -3200,19 +3428,15 @@ TEST_F(ControllerTests, surface_event_remove_success) { mp_iviShell->bkgnd_surface_id = 10; mp_iviShell->bkgnd_surface = mp_iviSurface[0]; - struct weston_view * tmp; mp_iviShell->bkgnd_view = (struct weston_view*)malloc(sizeof(struct weston_view)); - // need this to avoid leak memory - tmp = mp_iviShell->bkgnd_view; surface_event_remove(&mp_iviShell->surface_removed, m_layoutSurface); - ASSERT_EQ(wl_list_remove_fake.call_count, 3); - ASSERT_EQ(weston_layer_entry_remove_fake.call_count, 1); - ASSERT_EQ(weston_view_destroy_fake.call_count, 1); + ASSERT_EQ(wl_list_remove_fake.call_count, 5); + ASSERT_EQ(weston_layer_entry_remove_fake.call_count, 0); + ASSERT_EQ(weston_view_destroy_fake.call_count, 0); free(mp_iviShell->bkgnd_view); - free(tmp); mp_surfaceNotification[0] = (struct notification*)malloc(sizeof(struct notification)); mp_iviSurface[0] = (struct ivisurface*)malloc(sizeof(struct ivisurface));