Skip to content

Commit

Permalink
Create unit test for new APIs of screenshot feature
Browse files Browse the repository at this point in the history
	Screenshot feature have new logic and mechanism
	Create unittest for new APIs, update out-of-date testcase.

Signed-off-by: Phung Van Chien <[email protected]>
  • Loading branch information
chienpv1 committed Oct 26, 2023
1 parent 66b3115 commit 139e1df
Show file tree
Hide file tree
Showing 6 changed files with 979 additions and 21 deletions.
1 change: 1 addition & 0 deletions unittest/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
)

Expand Down
735 changes: 734 additions & 1 deletion unittest/client/src/ilm_control_unittests.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion unittest/server/include/ivi_layout_interface_fake.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <libweston/desktop.h>
#include "weston.h"
#include "fff.h"

Expand Down
2 changes: 1 addition & 1 deletion unittest/server/include/ivi_layout_structure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <stdint.h>
#include "libweston/libweston.h"
#include "ivi-layout-export.h"
#include "libweston-desktop/libweston-desktop.h"
#include <libweston/desktop.h>

struct ivi_layout_view {
struct wl_list link; /* ivi_layout::view_list */
Expand Down
2 changes: 1 addition & 1 deletion unittest/server/include/server_api_fake.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <libweston/desktop.h>
#include "weston.h"
#include "common_fake_api.h"

Expand Down
258 changes: 241 additions & 17 deletions unittest/server/src/ivi_controller_uinttests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/** ================================================================================================
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

/** ================================================================================================
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

/** ================================================================================================
Expand All @@ -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);
}

/** ================================================================================================
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 139e1df

Please sign in to comment.