Skip to content

Commit

Permalink
unittest: add a test folder
Browse files Browse the repository at this point in the history
This folder consists of 3 parts:
- client: test ivi-layermanagement-api (ilmCommon, ilmControl, ilmInput).
- server: test ivi-id-agent-modules, ivi-input-modules and weston-ivi-shell.
- common: contains common fake APIs for both client and server.

Signed-off-by: Au Doan Ngoc <au.doanngoc@vn.bosch.com>
  • Loading branch information
audoan99 committed Mar 24, 2023
1 parent b090cb0 commit a93e13e
Show file tree
Hide file tree
Showing 27 changed files with 16,949 additions and 0 deletions.
32 changes: 32 additions & 0 deletions unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
############################################################################
#
# Copyright (C) 2023 Advanced Driver Information Technology Joint Venture GmbH
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
############################################################################

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

find_package(gtest REQUIRED)

IF(NOT gtest_FOUND)
MESSAGE(STATUS "gtest not found, disabling unit tests (BUILD_ILM_UNIT_TESTS=OFF)")
SET(BUILD_ILM_UNIT_TESTS FALSE CACHE BOOL "Build unit tests for IVI LayerManagement API" FORCE)
ENDIF()

IF(BUILD_ILM_UNIT_TESTS)
add_subdirectory(client)
add_subdirectory(server)
ENDIF()
89 changes: 89 additions & 0 deletions unittest/client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
############################################################################
#
# Copyright (C) 2023 Advanced Driver Information Technology Joint Venture GmbH
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
############################################################################

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
cmake_policy(SET CMP0046 OLD)

PROJECT(ilm_client_unittest)

INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}/../../ivi-layermanagement-api/ilmCommon/include
${CMAKE_CURRENT_SOURCE_DIR}/../../ivi-layermanagement-api/ilmControl/include
${CMAKE_CURRENT_SOURCE_DIR}/../../ivi-layermanagement-api/ilmInput/include
${CMAKE_CURRENT_BINARY_DIR}/../../ivi-layermanagement-api/ilmControl
${CMAKE_CURRENT_BINARY_DIR}/../../protocol
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/../common
${WAYLAND_CLIENT_INCLUDE_DIRS}
${gtest_INCLUDE_DIRS}
)

LINK_DIRECTORIES(
${WAYLAND_CLIENT_LIBRARY_DIRS}
)

SET(LIBS
ilmCommon
ilmControl
ilmInput
${gtest_LIBRARIES}
)

SET(SRC_COMMON_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/client_api_fake.c
${CMAKE_CURRENT_SOURCE_DIR}/../common/common_fake_api.c
)

SET(SRC_IVI_COMMON_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/ilm_common_unittests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../ivi-layermanagement-api/ilmCommon/src/ilm_common.c
${CMAKE_CURRENT_SOURCE_DIR}/../../ivi-layermanagement-api/ilmCommon/src/ilm_common_wayland_platform.c
)

SET(SRC_IVI_CONTROL_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/ilm_control_base_class.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ilm_control_unittests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../ivi-layermanagement-api/ilmControl/src/ilm_control_wayland_platform.c
)

SET(SRC_IVI_INPUT_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/ilm_input_uinttests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../ivi-layermanagement-api/ilmInput/src/ilm_input.c
)

SET(COVERAGE_COMPILER_FLAGS "-g --coverage")
SET(GCC_SANITIZER_COMPILE_FLAGS "-fsanitize=address -fsanitize=undefined -fno-sanitize-recover -fstack-protector-all -fpermissive")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_SANITIZER_COMPILE_FLAGS} -pthread ${COVERAGE_COMPILER_FLAGS}")
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -static-libasan -static-libubsan ${COVERAGE_COMPILER_FLAGS}")

ADD_EXECUTABLE(unittest-ilm-common ${SRC_COMMON_FILES} ${SRC_IVI_COMMON_FILES})
TARGET_LINK_LIBRARIES(unittest-ilm-common ${LIBS})
ADD_DEPENDENCIES(unittest-ilm-common ${LIBS})
INSTALL(TARGETS unittest-ilm-common DESTINATION bin)

ADD_EXECUTABLE(unittest-ilm-input ${SRC_COMMON_FILES} ${SRC_IVI_INPUT_FILES})
TARGET_LINK_LIBRARIES(unittest-ilm-input ${LIBS})
ADD_DEPENDENCIES(unittest-ilm-input ${LIBS})
INSTALL(TARGETS unittest-ilm-input DESTINATION bin)

ADD_EXECUTABLE(unittest-ilm-control ${SRC_COMMON_FILES} ${SRC_IVI_CONTROL_FILES})
TARGET_LINK_LIBRARIES(unittest-ilm-control ${LIBS})
ADD_DEPENDENCIES(unittest-ilm-control ${LIBS})
INSTALL(TARGETS unittest-ilm-control DESTINATION bin)
95 changes: 95 additions & 0 deletions unittest/client/include/client_api_fake.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/***************************************************************************
*
* Copyright (C) 2023 Advanced Driver Information Technology Joint Venture GmbH
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
****************************************************************************/

#ifndef CLIENT_API_FAKE
#define CLIENT_API_FAKE

#include "stdint.h"
#include <pthread.h>
#include "fff.h"
#include "common_fake_api.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef void (**registerHandler) (void);
typedef void *(*threadEntry) (void *);

DECLARE_FAKE_VALUE_FUNC(struct wl_display *, wl_display_connect, const char *);
DECLARE_FAKE_VALUE_FUNC(struct wl_event_queue *, wl_display_create_queue, struct wl_display *);
DECLARE_FAKE_VALUE_FUNC(int, wl_display_roundtrip, struct wl_display *);
DECLARE_FAKE_VALUE_FUNC(int, wl_proxy_add_listener, struct wl_proxy *, registerHandler, void *);
DECLARE_FAKE_VALUE_FUNC(int, wl_display_roundtrip_queue, struct wl_display *, struct wl_event_queue *);
DECLARE_FAKE_VALUE_FUNC(int, pthread_create, pthread_t *, const pthread_attr_t *, threadEntry, void *);
DECLARE_FAKE_VALUE_FUNC(int, wl_display_flush, struct wl_display *);
DECLARE_FAKE_VALUE_FUNC(int, wl_display_dispatch_queue, struct wl_display *, struct wl_event_queue *);
DECLARE_FAKE_VALUE_FUNC(int, wl_display_dispatch_queue_pending, struct wl_display *, struct wl_event_queue *);
DECLARE_FAKE_VALUE_FUNC(int, wl_display_get_error, struct wl_display *);
DECLARE_FAKE_VALUE_FUNC(int, wl_display_get_fd, struct wl_display *);
DECLARE_FAKE_VALUE_FUNC(int, wl_display_prepare_read_queue, struct wl_display *, struct wl_event_queue *);
DECLARE_FAKE_VALUE_FUNC(int, wl_display_read_events, struct wl_display *);
DECLARE_FAKE_VALUE_FUNC(uint32_t, wl_proxy_get_version, struct wl_proxy *);
DECLARE_FAKE_VOID_FUNC(wl_display_disconnect, struct wl_display *);
DECLARE_FAKE_VOID_FUNC(wl_event_queue_destroy, struct wl_event_queue *);
DECLARE_FAKE_VOID_FUNC(wl_proxy_set_queue, struct wl_proxy *, struct wl_event_queue *);
DECLARE_FAKE_VOID_FUNC(wl_proxy_destroy, struct wl_proxy *);
DECLARE_FAKE_VOID_FUNC(wl_display_cancel_read, struct wl_display *);
DECLARE_FAKE_VOID_FUNC(wl_list_insert, struct wl_list *, struct wl_list *);
DECLARE_FAKE_VALUE_FUNC(void *, wl_array_add, struct wl_array *, size_t);
DECLARE_FAKE_VALUE_FUNC_VARARG(struct wl_proxy *, wl_proxy_marshal_flags, struct wl_proxy *, uint32_t, const struct wl_interface *, uint32_t, uint32_t, ...);
DECLARE_FAKE_VOID_FUNC(wl_array_init, struct wl_array *);
DECLARE_FAKE_VOID_FUNC(wl_array_release, struct wl_array *);
DECLARE_FAKE_VOID_FUNC(wl_list_init, struct wl_list *);
DECLARE_FAKE_VOID_FUNC(wl_list_remove, struct wl_list *);
// DECLARE_FAKE_VALUE_FUNC(int, wl_list_length, const struct wl_list *);

#define CLIENT_API_FAKE_LIST(FAKE) \
FAKE(wl_display_connect) \
FAKE(wl_display_create_queue) \
FAKE(wl_display_roundtrip) \
FAKE(wl_proxy_add_listener) \
FAKE(wl_display_roundtrip_queue) \
FAKE(pthread_create) \
FAKE(wl_display_flush) \
FAKE(wl_display_dispatch_queue) \
FAKE(wl_display_dispatch_queue_pending) \
FAKE(wl_display_get_error) \
FAKE(wl_display_get_fd) \
FAKE(wl_display_prepare_read_queue) \
FAKE(wl_display_read_events) \
FAKE(wl_proxy_get_version) \
FAKE(wl_display_disconnect) \
FAKE(wl_event_queue_destroy) \
FAKE(wl_proxy_set_queue) \
FAKE(wl_proxy_destroy) \
FAKE(wl_display_cancel_read) \
FAKE(wl_list_insert) \
FAKE(wl_array_add) \
FAKE(wl_proxy_marshal_flags) \
FAKE(wl_array_init) \
FAKE(wl_array_release) \
FAKE(wl_list_init) \
FAKE(wl_list_remove) \
FFF_RESET_HISTORY()

#ifdef __cplusplus
}
#endif
#endif // CLIENT_API_FAKE
100 changes: 100 additions & 0 deletions unittest/client/include/ilm_control_base_class.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/***************************************************************************
*
* Copyright (C) 2023 Advanced Driver Information Technology Joint Venture GmbH
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
****************************************************************************/

#ifndef ILM_CONTROL_BASE_CLASS
#define ILM_CONTROL_BASE_CLASS

#include "client_api_fake.h"
#include "ivi-wm-client-protocol.h"
#include "ivi-input-client-protocol.h"
#include "ilm_control_platform.h"

/**
* @note struct layer_context is in ilm_control_wayland_platform.c
* @note any changes from the original file should be updated here
*/
struct layer_context {
struct wl_list link;
t_ilm_uint id_layer;
struct ilmLayerProperties prop;
layerNotificationFunc notification;
struct wl_array render_order;
struct wayland_context *ctx;
};

/** @note struct screen_context is in ilm_control_wayland_platform.c
* @note any changes from the original file should be updated here
*/
struct screen_context {
struct wl_list link;
struct wl_output *output;
struct ivi_wm_screen *controller;
t_ilm_uint id_screen;
t_ilm_uint name;
int32_t transform;
struct ilmScreenProperties prop;
struct wl_array render_order;
struct wayland_context *ctx;
};

/**
* \brief: IlmControlInitBase will help to show all callback functions in ilmControl, there are 34 callbacks
*/
class IlmControlInitBase
{
public:
IlmControlInitBase() {}
virtual ~IlmControlInitBase() {}
virtual bool initBaseModule();
void wm_screen_listener_screen_id(void *data, struct ivi_wm_screen *ivi_wm_screen, uint32_t id);
void wm_screen_listener_layer_added(void *data, struct ivi_wm_screen *ivi_wm_screen, uint32_t layer_id);
void wm_screen_listener_connector_name(void *data, struct ivi_wm_screen *ivi_wm_screen, const char *process_name);
void wm_screen_listener_error(void *data, struct ivi_wm_screen *ivi_wm_screen, uint32_t error, const char *message);
void wm_listener_surface_visibility(void *data, struct ivi_wm *ivi_wm, uint32_t surface_id, int32_t visibility);
void wm_listener_layer_visibility(void *data, struct ivi_wm *ivi_wm, uint32_t layer_id, int32_t visibility);
void wm_listener_surface_opacity(void *data, struct ivi_wm *ivi_wm, uint32_t surface_id, wl_fixed_t opacity);
void wm_listener_layer_opacity(void *data, struct ivi_wm *ivi_wm, uint32_t layer_id, wl_fixed_t opacity);
void wm_listener_surface_source_rectangle(void *data, struct ivi_wm *ivi_wm, uint32_t surface_id, int32_t x, int32_t y, int32_t width, int32_t height);
void wm_listener_layer_source_rectangle(void *data, struct ivi_wm *ivi_wm, uint32_t layer_id, int32_t x, int32_t y, int32_t width, int32_t height);
void wm_listener_surface_destination_rectangle(void *data, struct ivi_wm *ivi_wm, uint32_t surface_id, int32_t x, int32_t y, int32_t width, int32_t height);
void wm_listener_layer_destination_rectangle(void *data, struct ivi_wm *ivi_wm, uint32_t layer_id, int32_t x, int32_t y, int32_t width, int32_t height);
void wm_listener_surface_created(void *data, struct ivi_wm *ivi_wm, uint32_t surface_id);
void wm_listener_layer_created(void *data, struct ivi_wm *ivi_wm, uint32_t layer_id);
void wm_listener_surface_destroyed(void *data, struct ivi_wm *ivi_wm, uint32_t surface_id);
void wm_listener_layer_destroyed(void *data, struct ivi_wm *ivi_wm, uint32_t layer_id);
void wm_listener_surface_error(void *data, struct ivi_wm *ivi_wm, uint32_t object_id, uint32_t error, const char *message);
void wm_listener_layer_error(void *data, struct ivi_wm *ivi_wm, uint32_t object_id, uint32_t error, const char *message);
void wm_listener_surface_size(void *data, struct ivi_wm *ivi_wm, uint32_t surface_id, int32_t width, int32_t height);
void wm_listener_surface_stats(void *data, struct ivi_wm *ivi_wm, uint32_t surface_id, uint32_t frame_count, uint32_t pid);
void wm_listener_layer_surface_added(void *data, struct ivi_wm *ivi_wm, uint32_t layer_id, uint32_t surface_id);
void input_listener_seat_created(void *data, struct ivi_input *ivi_input, const char *name, uint32_t capabilities);
void input_listener_seat_capabilities(void *data, struct ivi_input *ivi_input, const char *name, uint32_t capabilities);
void input_listener_seat_destroyed(void *data, struct ivi_input *ivi_input, const char *name);
void input_listener_input_focus(void *data, struct ivi_input *ivi_input, uint32_t surface, uint32_t device, int32_t enabled);
void input_listener_input_acceptance(void *data, struct ivi_input *ivi_input, uint32_t surface, const char *seat, int32_t accepted);
void output_listener_geometry(void *data, struct wl_output *wl_output, int32_t x, int32_t y, int32_t physical_width, int32_t physical_height, int32_t subpixel, const char *make, const char *model, int32_t transform);
void output_listener_mode(void *data, struct wl_output *wl_output, uint32_t flags, int32_t width, int32_t height, int32_t refresh);
void output_listener_done(void *data, struct wl_output *wl_output);
void output_listener_scale(void *data, struct wl_output *wl_output, int32_t factor);
void registry_handle_control(void *data, struct wl_registry *wl_registry, uint32_t name, const char *interface, uint32_t version);
void registry_handle_control_remove(void *data, struct wl_registry *wl_registry, uint32_t name);
void screenshot_done(void *data, struct ivi_screenshot *ivi_screenshot, int32_t fd, int32_t width, int32_t height, int32_t stride, uint32_t format, uint32_t timestamp);
void screenshot_error(void *data, struct ivi_screenshot *ivi_screenshot, uint32_t error, const char *message);
};
#endif // ILM_CONTROL_BASE_CLASS
53 changes: 53 additions & 0 deletions unittest/client/src/client_api_fake.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/***************************************************************************
*
* Copyright (C) 2023 Advanced Driver Information Technology Joint Venture GmbH
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
****************************************************************************/

#include "client_api_fake.h"
#include "ilm_control_platform.h"
#include "wayland-client-protocol.h"

DEFINE_FFF_GLOBALS;

DEFINE_FAKE_VALUE_FUNC(struct wl_display *, wl_display_connect, const char *);
DEFINE_FAKE_VALUE_FUNC(struct wl_event_queue *, wl_display_create_queue, struct wl_display *);
DEFINE_FAKE_VALUE_FUNC(int, wl_display_roundtrip, struct wl_display *);
DEFINE_FAKE_VALUE_FUNC(int, wl_proxy_add_listener, struct wl_proxy *, registerHandler, void *);
DEFINE_FAKE_VALUE_FUNC(int, wl_display_roundtrip_queue, struct wl_display *, struct wl_event_queue *);
DEFINE_FAKE_VALUE_FUNC(int, pthread_create, pthread_t *, const pthread_attr_t *, threadEntry, void *);
DEFINE_FAKE_VALUE_FUNC(int, wl_display_flush, struct wl_display *);
DEFINE_FAKE_VALUE_FUNC(int, wl_display_dispatch_queue, struct wl_display *, struct wl_event_queue *);
DEFINE_FAKE_VALUE_FUNC(int, wl_display_dispatch_queue_pending, struct wl_display *, struct wl_event_queue *);
DEFINE_FAKE_VALUE_FUNC(int, wl_display_get_error, struct wl_display *);
DEFINE_FAKE_VALUE_FUNC(int, wl_display_get_fd, struct wl_display *);
DEFINE_FAKE_VALUE_FUNC(int, wl_display_prepare_read_queue, struct wl_display *, struct wl_event_queue *);
DEFINE_FAKE_VALUE_FUNC(int, wl_display_read_events, struct wl_display *);
DEFINE_FAKE_VOID_FUNC(wl_display_cancel_read, struct wl_display *);
DEFINE_FAKE_VALUE_FUNC(uint32_t, wl_proxy_get_version, struct wl_proxy *);
DEFINE_FAKE_VOID_FUNC(wl_display_disconnect, struct wl_display *);
DEFINE_FAKE_VOID_FUNC(wl_event_queue_destroy, struct wl_event_queue *);
DEFINE_FAKE_VOID_FUNC(wl_proxy_set_queue, struct wl_proxy *, struct wl_event_queue *);
DEFINE_FAKE_VOID_FUNC(wl_proxy_destroy, struct wl_proxy *);
DEFINE_FAKE_VALUE_FUNC(void *, wl_array_add, struct wl_array *, size_t);
DEFINE_FAKE_VOID_FUNC(wl_list_insert, struct wl_list *, struct wl_list *);
DEFINE_FAKE_VALUE_FUNC_VARARG(struct wl_proxy *, wl_proxy_marshal_flags, struct wl_proxy *, uint32_t, const struct wl_interface *, uint32_t, uint32_t, ...);
DEFINE_FAKE_VOID_FUNC(wl_list_remove, struct wl_list *);
DEFINE_FAKE_VOID_FUNC(wl_list_init, struct wl_list *);
DEFINE_FAKE_VOID_FUNC(wl_array_init, struct wl_array *);
DEFINE_FAKE_VOID_FUNC(wl_array_release, struct wl_array *);

//DEFINE_FAKE_VALUE_FUNC(int, wl_list_length, const struct wl_list *);
Loading

0 comments on commit a93e13e

Please sign in to comment.