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 public APIs. Some exist APIs are
	  changed with 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 27, 2023
1 parent 66b3115 commit ca423b5
Show file tree
Hide file tree
Showing 9 changed files with 1,198 additions and 512 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
888 changes: 851 additions & 37 deletions unittest/client/src/ilm_control_unittests.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions unittest/client/src/ilm_input_uinttests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ TEST_F(IlmInputTest, ilm_setInputAcceptanceOn_cannotSyncAcquireInstance)
* -# Calling the ilm_setInputAcceptanceOn() with input seats is SEAT_DEFAULT
* -# Verification point:
* +# ilm_setInputAcceptanceOn() must return ILM_FAILED
* +# impl_sync_and_acquire_instance() must be called once time
* +# release_instance() must be called once time
*/
TEST_F(IlmInputTest, ilm_setInputAcceptanceOn_cannotFindSurfaceId)
{
Expand All @@ -164,7 +164,7 @@ TEST_F(IlmInputTest, ilm_setInputAcceptanceOn_cannotFindSurfaceId)
* -# Calling the ilm_setInputAcceptanceOn() with input seats is SEAT_DEFAULT
* -# Verification point:
* +# ilm_setInputAcceptanceOn() must return ILM_FAILED
* +# impl_sync_and_acquire_instance() must be called once time
* +# release_instance() must be called once time
*/
TEST_F(IlmInputTest, ilm_setInputAcceptanceOn_cannotFindSeat)
{
Expand Down
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
634 changes: 335 additions & 299 deletions unittest/server/src/ivi_controller_uinttests.cpp

Large diffs are not rendered by default.

133 changes: 0 additions & 133 deletions unittest/server/src/ivi_id_agent_unittests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,139 +161,6 @@ static int custom_weston_config_section_get_string(struct weston_config_section
return 0;
}

/** ================================================================================================
* @test_id desktop_surface_event_configure_hasDataInList
* @brief Test case of desktop_surface_event_configure() where
* cfg_app_id and cfg_title are in the same object, get_id_from_config return IVI_SUCCEEDED
* @test_procedure Steps:
* -# Mocking the weston_desktop_surface_get_app_id() to return mp_dbElem[0]->cfg_app_id
* -# Mocking the weston_desktop_surface_get_title() to return mp_dbElem[0]->cfg_title
* -# Calling the desktop_surface_event_configure()
* -# Verification point:
* +# The result output should same with prepare data
* +# surface_set_id() must be called once time
* +# Input surface_set_id() should be mp_dbElem[0]->surface_id
*/
TEST_F(IdAgentTest, desktop_surface_event_configure_hasDataInList)
{
// desktop_surface_event_configure() is removed

// SET_RETURN_SEQ(weston_desktop_surface_get_app_id, (const char**)&mp_dbElem[0]->cfg_app_id, 1);
// SET_RETURN_SEQ(weston_desktop_surface_get_title, (const char**)&mp_dbElem[0]->cfg_title, 1);

// desktop_surface_event_configure(&mp_iviIdAgent->desktop_surface_configured, mp_fakePointer);

// ASSERT_EQ(mp_dbElem[0]->layout_surface, mp_fakePointer);
// ASSERT_EQ(surface_set_id_fake.call_count, 1);
// ASSERT_EQ(surface_set_id_fake.arg1_history[0], mp_dbElem[0]->surface_id);
}

/** ================================================================================================
* @test_id desktop_surface_event_configure_noDataInListNoDefaultBehavior
* @brief Test case of desktop_surface_event_configure() where
* cfg_app_id and cfg_title are in the different object, get_id_from_config return IVI_FAILED
* @test_procedure Steps:
* -# Mocking the weston_desktop_surface_get_app_id() to return mp_dbElem[1]->cfg_app_id
* -# Mocking the weston_desktop_surface_get_title() to return mp_dbElem[0]->cfg_title
* -# Calling the desktop_surface_event_configure()
* -# Verification point:
* +# surface_set_id() not be called
*/
TEST_F(IdAgentTest, desktop_surface_event_configure_noDataInListNoDefaultBehavior)
{
// desktop_surface_event_configure() is removed
// SET_RETURN_SEQ(weston_desktop_surface_get_app_id, (const char**)&mp_dbElem[1]->cfg_app_id, 1);
// SET_RETURN_SEQ(weston_desktop_surface_get_title, (const char**)&mp_dbElem[0]->cfg_title, 1);

// desktop_surface_event_configure(&mp_iviIdAgent->desktop_surface_configured, mp_fakePointer);

// ASSERT_EQ(surface_set_id_fake.call_count, 0);
}

/** ================================================================================================
* @test_id desktop_surface_event_configure_noDataInListHasDefaultBehavior
* @brief Test case of desktop_surface_event_configure() where
* cfg_app_id and cfg_title are in the different object, get_id_from_config return IVI_FAILED
* and enable the default behavior
* @test_procedure Steps:
* -# Set default_behavior_set to 1 (Enable the default behavior)
* -# Mocking the weston_desktop_surface_get_app_id() to return mp_dbElem[1]->cfg_app_id
* -# Mocking the weston_desktop_surface_get_title() to return mp_dbElem[0]->cfg_title
* -# Calling the desktop_surface_event_configure()
* -# Verification point:
* +# surface_set_id() must be called once time
* +# Input surface_set_id() should be {mp_iviIdAgent->default_surface_id - 1}
*/
TEST_F(IdAgentTest, desktop_surface_event_configure_noDataInListHasDefaultBehavior)
{
// desktop_surface_event_configure() is removed
// mp_iviIdAgent->default_behavior_set = 1;
// SET_RETURN_SEQ(weston_desktop_surface_get_app_id, (const char**)&mp_dbElem[1]->cfg_app_id, 1);
// SET_RETURN_SEQ(weston_desktop_surface_get_title, (const char**)&mp_dbElem[0]->cfg_title, 1);

// desktop_surface_event_configure(&mp_iviIdAgent->desktop_surface_configured, mp_fakePointer);

// ASSERT_EQ(surface_set_id_fake.call_count, 1);
// ASSERT_EQ(surface_set_id_fake.arg1_history[0], mp_iviIdAgent->default_surface_id - 1);
}

/** ================================================================================================
* @test_id desktop_surface_event_configure_noDataInListHasDefaultBehaviorExistSurfaceId
* @brief Test case of desktop_surface_event_configure() where
* cfg_app_id and cfg_title are in the different object, get_id_from_config return IVI_FAILED
* and enable the default behavior and exist surface id
* @test_procedure Steps:
* -# Set default_behavior_set to 1 (Enable the default behavior)
* -# Mocking the weston_desktop_surface_get_app_id() to return mp_dbElem[1]->cfg_app_id
* -# Mocking the weston_desktop_surface_get_title() to return mp_dbElem[0]->cfg_title
* -# Mocking the get_surface_from_id() to return an object (not null pointer)
* -# Calling the desktop_surface_event_configure()
* -# Verification point:
* +# surface_set_id() not be called
*/
TEST_F(IdAgentTest, desktop_surface_event_configure_noDataInListHasDefaultBehaviorExistSurfaceId)
{
// desktop_surface_event_configure() is removed
// mp_iviIdAgent->default_behavior_set = 1;
// SET_RETURN_SEQ(weston_desktop_surface_get_app_id, (const char**)&mp_dbElem[1]->cfg_app_id, 1);
// SET_RETURN_SEQ(weston_desktop_surface_get_title, (const char**)&mp_dbElem[0]->cfg_title, 1);

// struct ivi_layout_surface *lp_fakeLayoutLayer = (struct ivi_layout_surface *)0xFFFFFF00;
// SET_RETURN_SEQ(get_surface_from_id, &lp_fakeLayoutLayer, 1);

// desktop_surface_event_configure(&mp_iviIdAgent->desktop_surface_configured, mp_fakePointer);

// ASSERT_EQ(surface_set_id_fake.call_count, 0);
}

/** ================================================================================================
* @test_id desktop_surface_event_configure_noDataInListHasDefaultBehaviorOverMaxId
* @brief Test case of desktop_surface_event_configure() where
* cfg_app_id and cfg_title are in the different object, get_id_from_config return IVI_FAILED
* and enable the default behavior and the default id and default id max are same
* @test_procedure Steps:
* -# Set default_behavior_set to 1 (Enable the default behavior)
* -# Set the default id and default max id are same
* -# Mocking the weston_desktop_surface_get_app_id() to return mp_dbElem[1]->cfg_app_id
* -# Mocking the weston_desktop_surface_get_title() to return mp_dbElem[0]->cfg_title
* -# Calling the desktop_surface_event_configure()
* -# Verification point:
* +# surface_set_id() not be called
*/
TEST_F(IdAgentTest, desktop_surface_event_configure_noDataInListHasDefaultBehaviorOverMaxId)
{
// desktop_surface_event_configure() is removed
// mp_iviIdAgent->default_behavior_set = 1;
// mp_iviIdAgent->default_surface_id = 200;
// mp_iviIdAgent->default_surface_id_max = 200;
// SET_RETURN_SEQ(weston_desktop_surface_get_app_id, (const char**)&mp_dbElem[1]->cfg_app_id, 1);
// SET_RETURN_SEQ(weston_desktop_surface_get_title, (const char**)&mp_dbElem[0]->cfg_title, 1);

// desktop_surface_event_configure(&mp_iviIdAgent->desktop_surface_configured, mp_fakePointer);

// ASSERT_EQ(surface_set_id_fake.call_count, 0);
}

/** ================================================================================================
* @test_id surface_event_remove
* @brief Test case of surface_event_remove() where valid input params
Expand Down
44 changes: 6 additions & 38 deletions unittest/server/src/ivi_input_controller_uinttests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ class InputControllerTest: public ::testing::Test
* @test_procedure Steps:
* -# Calling the handle_seat_create()
* -# Verification point:
* +# wl_list_insert() must be called 3 times
* +# wl_resource_post_event() must be called {MAX_NUMBER} times
* +# wl_list_insert() must be called 5 times
* +# wl_resource_post_event() must be called 6 times
* +# Free resources are allocated when running the test
*/
TEST_F(InputControllerTest, handle_seat_create_customSeat)
Expand Down Expand Up @@ -383,7 +383,7 @@ TEST_F(InputControllerTest, handle_seat_destroy_withSurfaceAccepted)
* @test_procedure Steps:
* -# Calling the input_controller_module_init()
* -# Verification point:
* +# input_controller_module_init() must return 0
* +# input_controller_module_init() must not return 0
*/
TEST_F(InputControllerTest, input_controller_module_init_WrongInput)
{
Expand Down Expand Up @@ -748,7 +748,6 @@ TEST_F(InputControllerTest, pointer_grab_focus_nullSurfCtx)
* -# Calling the pointer_grab_focus()
* -# Verification point:
* +# surface_get_weston_surface() must be called once time
* +# weston_pointer_set_focus() must be called once time
* +# weston_pointer_clear_focus() not be called
* +# Free resources are allocated when running the test
*/
Expand Down Expand Up @@ -776,8 +775,6 @@ TEST_F(InputControllerTest, pointer_grab_focus_success)
pointer_grab_focus(&mpp_ctxSeat[0]->pointer_grab);

ASSERT_EQ(surface_get_weston_surface_fake.call_count, 1);
// maybe logic is changed, need to check
// ASSERT_EQ(weston_pointer_set_focus_fake.call_count, 1);
ASSERT_EQ(weston_pointer_clear_focus_fake.call_count, 0);

free(l_surf[0]);
Expand Down Expand Up @@ -1485,7 +1482,7 @@ TEST_F(InputControllerTest, input_set_input_focus_toTouch)
* -# Mocking the wl_resource_get_user_data() does return an object
* -# Calling the setup_input_acceptance()
* -# Verification point:
* +# wl_resource_get_user_data() must be called once time
* +# get_surface_from_id() not be called
*/
TEST_F(InputControllerTest, input_set_input_acceptance_wrongSeatName)
{
Expand All @@ -1506,6 +1503,8 @@ TEST_F(InputControllerTest, input_set_input_acceptance_wrongSeatName)
* -# Verification point:
* +# wl_resource_get_user_data() must be called once time
* +# get_surface_from_id() must be called once time
* +# weston_seat_get_pointer() not be called
* +# wl_resource_post_event() not be called
*/
TEST_F(InputControllerTest, input_set_input_acceptance_nullSurface)
{
Expand All @@ -1519,35 +1518,6 @@ TEST_F(InputControllerTest, input_set_input_acceptance_nullSurface)
ASSERT_EQ(wl_resource_post_event_fake.call_count, 0);
}

/** ================================================================================================
* @test_id input_set_input_acceptance_withNullPointerAndApccepted
* @brief Test case of setup_input_acceptance() where ctxSeat pointer is null pointer
* and input accepted is enable {1}
* @test_procedure Steps:
* -# Mocking the wl_resource_get_user_data() does return an object
* -# Mocking the get_surface_from_id() does return an object
* -# Calling the setup_input_acceptance() with valid seat name
* -# Verification point:
* +# wl_resource_get_user_data() must be called once time
* +# get_surface_from_id() must be called once time
* +# weston_seat_get_pointer() must be called once time
*/
TEST_F(InputControllerTest, input_set_input_acceptance_withNullPointerAndApccepted)
{
// error runtime: not allow pass nullptr
// struct input_context *l_input[1] = {mp_ctxInput};
// SET_RETURN_SEQ(wl_resource_get_user_data, (void**)l_input, 1);

// struct ivi_layout_surface *l_surface[1] = {mp_layoutSurface};
// SET_RETURN_SEQ(get_surface_from_id, l_surface, 1);

// setup_input_acceptance(nullptr, 10, "default", 1);

// ASSERT_EQ(wl_resource_get_user_data_fake.call_count, 1);
// ASSERT_EQ(get_surface_from_id_fake.call_count, 1);
// ASSERT_EQ(weston_seat_get_pointer_fake.call_count, 1);
}

/** ================================================================================================
* @test_id input_set_input_acceptance_withValidPointerAndUnapccepted
* @brief Test case of setup_input_acceptance() where valid ctxSeat pointer
Expand All @@ -1561,7 +1531,6 @@ TEST_F(InputControllerTest, input_set_input_acceptance_withNullPointerAndApccept
* -# Mocking the get_surface_from_id() does return an object
* -# Calling the setup_input_acceptance() with input accepted is 0
* -# Verification point:
* +# wl_resource_get_user_data() must be called once time
* +# get_surface_from_id() must be called once time
* +# weston_seat_get_pointer() must be called once time
* +# surface_get_weston_surface() must be called once time
Expand Down Expand Up @@ -1609,7 +1578,6 @@ TEST_F(InputControllerTest, input_set_input_acceptance_withValidPointerAndUnapcc
* -# Mocking the weston_seat_get_pointer() does return an object
* -# Calling the setup_input_acceptance() with input accepted is 1
* -# Verification point:
* +# wl_resource_get_user_data() must be called once time
* +# get_surface_from_id() must be called once time
* +# weston_seat_get_pointer() must be called once time
* +# Free resources are allocated when running the test
Expand Down

0 comments on commit ca423b5

Please sign in to comment.