From a331cffba16a71019651f38933659b84816ac57c Mon Sep 17 00:00:00 2001 From: Youngjae Shin Date: Wed, 20 May 2020 13:38:13 +0900 Subject: [PATCH] apply testing in build time Change-Id: I56ebd55063afa6021e0662a016ab0f5c3db701aa --- CMakeLists.txt | 3 +- common/sst.h | 24 +++++ common/sst_log.h | 139 +++++++++++++++++++++++++++ packaging/capi-system-system-settings.spec | 10 +- src/sys_settings.c | 36 +++---- src/sys_settings_json.c | 2 - src/sys_settings_platform.c | 6 +- tests/CMakeLists.txt | 14 +-- tests/mocks/libc.c | 69 +++++++++++++ tests/mocks/pkgmgrinfo_appinfo.c | 5 +- tests/mocks/system_info.c | 80 +++++++++++++++ tests/mocks/vconf.cpp | 69 +++++++------ tests/run_coverage.sh | 110 --------------------- tests/scripts/convert_vconf_script_to_sql.sh | 8 +- tests/scripts/vconf_golden_master.sh | 18 ++++ utils/sys_settings_util.c | 21 ++-- utils/sys_settings_util.h | 1 - 17 files changed, 409 insertions(+), 206 deletions(-) create mode 100644 common/sst.h create mode 100644 common/sst_log.h create mode 100644 tests/mocks/libc.c create mode 100644 tests/mocks/system_info.c delete mode 100755 tests/run_coverage.sh create mode 100755 tests/scripts/vconf_golden_master.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bd9a1f..c02b061 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,11 +3,12 @@ PROJECT(capi-system-system-settings) INCLUDE(FindPkgConfig) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common) SET(SETTING_TZONE_SYMLINK_PATH "\"/opt/etc/localtime\"") SET(EXTRA_FLAGS "-Wall -Werror -fvisibility=hidden") -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_FLAGS}") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_FLAGS} -std=c++11") SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") diff --git a/common/sst.h b/common/sst.h new file mode 100644 index 0000000..c142578 --- /dev/null +++ b/common/sst.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ +#pragma once + +//#include "sst_log.h" + +#ifdef API +#undef API +#endif +#define API __attribute__((visibility("default"))) + diff --git a/common/sst_log.h b/common/sst_log.h new file mode 100644 index 0000000..58adb69 --- /dev/null +++ b/common/sst_log.h @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ +#pragma once + +#define SST_LOG_RED "\033[31m" +#define SST_LOG_GREEN "\033[32m" +#define SST_LOG_BROWN "\033[33m" +#define SST_LOG_BLUE "\033[34m" +#define SST_LOG_END "\033[0m" + +#undef __DBG +#undef __INFO +#undef __WARN +#undef __ERR + +#undef _DBG +#undef _INFO +#undef _WARN +#undef _ERR + +#undef DBG +#undef INFO +#undef WARN +#undef ERR + +#ifdef SST_STDOUT +#include +#include +#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) +#define __DBG(fmt, arg...) printf("[SST]%s(%d):" fmt "\n", __FILENAME__, __LINE__, ##arg) +#define __INFO(fmt, arg...) printf("[SST]%s(%d):" fmt "\n", __FILENAME__, __LINE__, ##arg) +#define __WARN(fmt, arg...) printf("[SST]%s(%d):" fmt "\n", __FILENAME__, __LINE__, ##arg) +#define __ERR(fmt, arg...) printf("[SST]%s(%d):" fmt "\n", __FILENAME__, __LINE__, ##arg) +#define __SECU_DBG(fmt, arg...) printf("[SST]%s(%d):" fmt "\n", __FILENAME__, __LINE__, ##arg) +#define __SECU_INFO(fmt, arg...) printf("[SST]%s(%d):" fmt "\n", __FILENAME__, __LINE__, ##arg) +#else +#define LOG_TAG "SYSTEM-SETTINGS" +#include +#define __DBG(fmt, arg...) SLOGD(fmt, ##arg) +#define __INFO(fmt, arg...) SLOGI(fmt, ##arg) +#define __WARN(fmt, arg...) SLOGW(fmt, ##arg) +#define __ERR(fmt, arg...) SLOGE(fmt, ##arg) +#define __SECU_DBG(fmt, arg...) SECURE_SLOGD(fmt, ##arg) +#define __SECU_INFO(fmt, arg...) SECURE_SLOGI(fmt, ##arg) +#endif /* SST_STDOUT */ + + +#ifdef SST_TEST +#define _DBG(fmt, arg...) __DBG(SST_LOG_BROWN "" SST_LOG_END fmt, ##arg) +#define _INFO(fmt, arg...) __INFO(SST_LOG_BLUE "" SST_LOG_END fmt, ##arg) +#define _WARN(fmt, arg...) __WARN(SST_LOG_GREEN "" SST_LOG_END fmt, ##arg) +#define _ERR(fmt, arg...) __ERR(SST_LOG_RED "" SST_LOG_END fmt, ##arg) +#else +#define _DBG(fmt, arg...) __DBG(fmt, ##arg) +#define _INFO(fmt, arg...) __INFO(fmt, ##arg) +#define _WARN(fmt, arg...) __WARN(fmt, ##arg) +#define _ERR(fmt, arg...) __ERR(fmt, ##arg) +#endif + +#define SST_DEBUGGING + +#ifdef SST_DEBUGGING +#define DBG(fmt, arg...) _DBG(fmt, ##arg) +#define WARN(fmt, arg...) _WARN(fmt, ##arg) +#define ERR(fmt, arg...) _ERR(fmt, ##arg) +#define INFO(fmt, arg...) _INFO(fmt, ##arg) +#define SST_SECURE_DEBUG(fmt, arg...) __SECU_DBG(SST_LOG_BROWN fmt SST_LOG_END, ##arg) +#define SST_SECURE_TRACE(fmt, arg...) __SECU_INFO(SST_LOG_GREEN fmt SST_LOG_END, ##arg) +#define SST_SECURE_BEGIN __SECU_DBG(SST_LOG_BLUE "ENTER FUNCTION: %s\n" SST_LOG_END, __FUNCTION__) +#define SST_SECURE_END __SECU_DBG(SST_LOG_BLUE "EXIT FUNCTION: %s\n" SST_LOG_END, __FUNCTION__) + +#else /* SST_DEBUGGING */ +#define DBG(fmt, arg...) +#define WARN(fmt, arg...) +#define ERR(fmt, arg...) +#define INFO(fmt, arg...) +#define SECURE_DBG(fmt, arg...) +#define SECURE_ERR(fmt, arg...) + +#endif /* SST_DEBUGGING */ + +#define RET_IF(expr) \ + do { \ + if (expr) { \ + ERR("(%s)", #expr); \ + return; \ + } \ + } while (0) + +#define RETV_IF(expr, val) \ + do { \ + if (expr) { \ + ERR("(%s)", #expr); \ + return (val); \ + } \ + } while (0) + +#define RETM_IF(expr, fmt, arg...) \ + do { \ + if (expr) { \ + ERR(fmt, ##arg); \ + return; \ + } \ + } while (0) + +#define RETVM_IF(expr, val, fmt, arg...) \ + do { \ + if (expr) { \ + ERR(fmt, ##arg); \ + return (val); \ + } \ + } while (0) + +#define ERR_IF(expr) \ + do { \ + if (expr) { \ + ERR("(%s)", #expr); \ + } \ + } while (0) + +#define WARN_IF(expr, fmt, arg...) \ + do { \ + if (expr) { \ + WARN(fmt, ##arg); \ + } \ + } while (0) diff --git a/packaging/capi-system-system-settings.spec b/packaging/capi-system-system-settings.spec index ad04476..a76785a 100644 --- a/packaging/capi-system-system-settings.spec +++ b/packaging/capi-system-system-settings.spec @@ -97,12 +97,6 @@ export CXXFLAGS="$CXXFLAGS -DTIZEN_ENGINEER_MODE" export FFLAGS="$FFLAGS -DTIZEN_ENGINEER_MODE" %endif -%ifarch aarch64 x86_64 -export CFLAGS+="$CFLAGS -DSETTING_ARCH_64" -export CXXFLAGS+="$CXXFLAGS -DSETTING_ARCH_64" -export FFLAGS+="$FFLAGS -DSETTING_ARCH_64" -%endif - %if 0%{?gcov:1} export CFLAGS+=" -fprofile-arcs -ftest-coverage" export CXXFLAGS+=" -fprofile-arcs -ftest-coverage" @@ -137,8 +131,8 @@ tar xf %{name}-gcov.tar -C %{buildroot}%{_datadir}/gcov/obj %endif %check -#cd tests -#bash ./run_coverage.sh +bash tests/scripts/vconf_golden_master.sh +LD_LIBRARY_PATH=.:tests:utils LD_PRELOAD=tests/libsys-settings-mock.so tests/sys-settings-test %post unittests XDG_RUNTIME_DIR=/run %{sys_setting_test_dir}/sys-settings-test diff --git a/src/sys_settings.c b/src/sys_settings.c index 8d037a7..0a58966 100644 --- a/src/sys_settings.c +++ b/src/sys_settings.c @@ -18,6 +18,7 @@ #include #include +#include "sst.h" #include "system_settings.h" #include "sys_settings.h" @@ -857,7 +858,7 @@ int system_setting_set_vconf(system_setting_h item, void *value) } /* LCOV_EXCL_STOP */ -int system_settings_get_value(system_settings_key_e key, system_setting_data_type_e data_type, void **value) +API int system_settings_get_value(system_settings_key_e key, system_setting_data_type_e data_type, void **value) { LOGE("Enter [%s]", __FUNCTION__); if (!(key >= 0 && SYSTEM_SETTINGS_KEY_MAX > key)) @@ -892,7 +893,7 @@ int system_settings_get_value(system_settings_key_e key, system_setting_data_typ } /* LCOV_EXCL_START */ -int system_settings_set_value(system_settings_key_e key, system_setting_data_type_e data_type, void *value) +API int system_settings_set_value(system_settings_key_e key, system_setting_data_type_e data_type, void *value) { LOGE("Enter [%s]", __FUNCTION__); if (!(key >= 0 && SYSTEM_SETTINGS_KEY_MAX > key) || value == NULL) @@ -965,7 +966,7 @@ int system_settings_add_value(system_settings_key_e key, system_setting_data_typ /* LCOV_EXCL_START */ -int system_settings_del_value(system_settings_key_e key, system_setting_data_type_e data_type, void *value) +API int system_settings_del_value(system_settings_key_e key, system_setting_data_type_e data_type, void *value) { LOGE("Enter [%s]", __FUNCTION__); if (!(key >= 0 && SYSTEM_SETTINGS_KEY_MAX > key) || value == NULL) @@ -1000,7 +1001,7 @@ int system_settings_del_value(system_settings_key_e key, system_setting_data_typ /* LCOV_EXCL_START */ -int system_settings_list_value(system_settings_key_e key, system_setting_data_type_e data_type, bool(*system_setting_data_iterator)(int, const char*, void *), void *user_data) +API int system_settings_list_value(system_settings_key_e key, system_setting_data_type_e data_type, bool(*system_setting_data_iterator)(int, const char*, void *), void *user_data) { LOGE("Enter [%s]", __FUNCTION__); if (!(key >= 0 && SYSTEM_SETTINGS_KEY_MAX > key)) @@ -1036,7 +1037,7 @@ int system_settings_list_value(system_settings_key_e key, system_setting_data_ty /* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ -int system_settings_set_value_int(system_settings_key_e key, int value) +API int system_settings_set_value_int(system_settings_key_e key, int value) { LOGE("Enter [%s]", __FUNCTION__); if (!(key >= 0 && SYSTEM_SETTINGS_KEY_MAX > key)) @@ -1048,7 +1049,7 @@ int system_settings_set_value_int(system_settings_key_e key, int value) } /* LCOV_EXCL_STOP */ -int system_settings_get_value_int(system_settings_key_e key, int *value) +API int system_settings_get_value_int(system_settings_key_e key, int *value) { LOGE("Enter [%s]", __FUNCTION__); if (!(key >= 0 && SYSTEM_SETTINGS_KEY_MAX > key)) @@ -1064,7 +1065,7 @@ int system_settings_get_value_int(system_settings_key_e key, int *value) } /* LCOV_EXCL_START */ -int system_settings_set_value_bool(system_settings_key_e key, bool value) +API int system_settings_set_value_bool(system_settings_key_e key, bool value) { LOGE("Enter [%s]", __FUNCTION__); if (!(key >= 0 && SYSTEM_SETTINGS_KEY_MAX > key)) @@ -1075,7 +1076,7 @@ int system_settings_set_value_bool(system_settings_key_e key, bool value) } /* LCOV_EXCL_STOP */ -int system_settings_get_value_bool(system_settings_key_e key, bool *value) +API int system_settings_get_value_bool(system_settings_key_e key, bool *value) { LOGE("Enter [%s]", __FUNCTION__); SETTING_TRACE(" SIGNED LONG here ******************* log here *************** "); @@ -1103,7 +1104,7 @@ int system_settings_get_value_bool(system_settings_key_e key, bool *value) } /* LCOV_EXCL_START */ -int system_settings_set_value_string(system_settings_key_e key, const char *value) +API int system_settings_set_value_string(system_settings_key_e key, const char *value) { LOGE("Enter [%s]", __FUNCTION__); if (!(key >= 0 && SYSTEM_SETTINGS_KEY_MAX > key)) @@ -1116,7 +1117,7 @@ int system_settings_set_value_string(system_settings_key_e key, const char *valu } /* LCOV_EXCL_STOP */ -int system_settings_get_value_string(system_settings_key_e key, char **value) +API int system_settings_get_value_string(system_settings_key_e key, char **value) { LOGE("Enter [%s]", __FUNCTION__); if (!(key >= 0 && SYSTEM_SETTINGS_KEY_MAX > key)) @@ -1137,8 +1138,7 @@ int system_setting_unset_changed_vconf_genernal_callback(system_setting_h item) return system_setting_vconf_unset_changed_cb(item->vconf_key, GET_SLOT(item->key)); } -/*PUBLIC*/ -int system_settings_set_changed_cb(system_settings_key_e key, system_settings_changed_cb callback, void *user_data) +API int system_settings_set_changed_cb(system_settings_key_e key, system_settings_changed_cb callback, void *user_data) { LOGE("Enter [%s]", __FUNCTION__); system_setting_h system_setting_item; @@ -1176,7 +1176,7 @@ int system_settings_set_changed_cb(system_settings_key_e key, system_settings_ch } -int system_settings_unset_changed_cb(system_settings_key_e key) +API int system_settings_unset_changed_cb(system_settings_key_e key) { LOGE("Enter [%s]", __FUNCTION__); system_setting_h system_setting_item; @@ -1210,7 +1210,7 @@ int system_settings_unset_changed_cb(system_settings_key_e key) return system_setting_unset_changed_cb(system_setting_item); } -int system_settings_add_changed_cb(system_settings_key_e key, system_settings_changed_cb callback, void *user_data) +API int system_settings_add_changed_cb(system_settings_key_e key, system_settings_changed_cb callback, void *user_data) { LOGE("Enter [%s]", __FUNCTION__); system_setting_h system_setting_item; @@ -1252,7 +1252,7 @@ int system_settings_add_changed_cb(system_settings_key_e key, system_settings_ch return SYSTEM_SETTINGS_ERROR_NONE; } -int system_settings_remove_changed_cb(system_settings_key_e key, system_settings_changed_cb callback) +API int system_settings_remove_changed_cb(system_settings_key_e key, system_settings_changed_cb callback) { LOGE("Enter [%s]", __FUNCTION__); system_setting_h system_setting_item; @@ -1291,7 +1291,7 @@ int system_settings_remove_changed_cb(system_settings_key_e key, system_settings // list ////////////////////////////////////////////////////////////////////////////////////////////////// -int system_settings_foreach_value_string(system_settings_key_e key, system_settings_iter_cb callback, void *value) +API int system_settings_foreach_value_string(system_settings_key_e key, system_settings_iter_cb callback, void *value) { LOGE("Enter [%s]", __FUNCTION__); if (!(key >= 0 && SYSTEM_SETTINGS_KEY_MAX > key)) @@ -1304,7 +1304,7 @@ int system_settings_foreach_value_string(system_settings_key_e key, system_setti // add ////////////////////////////////////////////////////////////////////////////////////////////////// -int system_settings_add_value_string(system_settings_key_e key, const char* value) +API int system_settings_add_value_string(system_settings_key_e key, const char* value) { LOGE("Enter [%s]", __FUNCTION__); if (!(key >= 0 && SYSTEM_SETTINGS_KEY_MAX > key)) @@ -1317,7 +1317,7 @@ int system_settings_add_value_string(system_settings_key_e key, const char* valu // del ////////////////////////////////////////////////////////////////////////////////////////////////// -int system_settings_delete_value_string(system_settings_key_e key, const char* value) +API int system_settings_delete_value_string(system_settings_key_e key, const char* value) { LOGE("Enter [%s]", __FUNCTION__); if (!(key >= 0 && SYSTEM_SETTINGS_KEY_MAX > key)) diff --git a/src/sys_settings_json.c b/src/sys_settings_json.c index 118be84..f4863c3 100644 --- a/src/sys_settings_json.c +++ b/src/sys_settings_json.c @@ -178,5 +178,3 @@ void ss_json_ringtone_list(JsonNode *root) } } /* LCOV_EXCL_STOP */ - - diff --git a/src/sys_settings_platform.c b/src/sys_settings_platform.c index ddbe4db..a6d8cc9 100644 --- a/src/sys_settings_platform.c +++ b/src/sys_settings_platform.c @@ -65,11 +65,7 @@ } while (0); #define FREE(arg) __FREE(free, arg) -#ifdef SETTING_ARCH_64 -#define SETTING_UTILS_SO_FILE_PATH "/usr/lib64/libsystem-settings-util.so" -#else -#define SETTING_UTILS_SO_FILE_PATH "/usr/lib/libsystem-settings-util.so" -#endif +#define SETTING_UTILS_SO_FILE_PATH "libsystem-settings-util.so" int _is_file_accessible(const char *path); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f47cc05..7fa9f43 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,15 +1,15 @@ SET(UNITTEST "sys-settings-test") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE") +ADD_DEFINITIONS("-DSST_TEST") -SET(VCONF_MOCK "vconf-mock") -ADD_LIBRARY(${VCONF_MOCK} SHARED mocks/vconf.cpp) +FILE(GLOB MOCK_SRCS mocks/*.c mocks/*.cpp) +SET(MOCK_LIB "sys-settings-mock") +ADD_LIBRARY(${MOCK_LIB} SHARED ${MOCK_SRCS}) -SET(PKGMGR_INFO_MOCK "pkgmgr-info-mock") -ADD_LIBRARY(${PKGMGR_INFO_MOCK} SHARED mocks/pkgmgrinfo_appinfo.c) - -SET(EFL_EXTENSION_INFO_MOCK "efl-extension-mock") -ADD_LIBRARY(${EFL_EXTENSION_INFO_MOCK} SHARED mocks/efl-extension.c) +SET(EFL_EXTENSION_MOCK "efl-extension") +ADD_LIBRARY(${EFL_EXTENSION_MOCK} SHARED mocks/efl-extension.c) +SET_TARGET_PROPERTIES(${EFL_EXTENSION_MOCK} PROPERTIES SOVERSION 0) FILE(GLOB TEST_SRCS *.c) ADD_DEFINITIONS("-DN_THREADS=${N_THREADS}") diff --git a/tests/mocks/libc.c b/tests/mocks/libc.c new file mode 100644 index 0000000..53c30d5 --- /dev/null +++ b/tests/mocks/libc.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include "sst.h" + +API int access(const char *pathname, int mode) +{ + if (0 == strcmp(pathname, "/opt/usr/data/settings/Ringtones/ringtone_sdk.mp3")) + return 0; + if (0 == strcmp(pathname, "/opt/usr/data/settings/Alerts/Over the horizon.mp3")) + return 0; + if (0 == strcmp(pathname, "/usr/bin/sys-settings/ringtone_sdk.mp3")) + return 0; + if (0 == strcmp(pathname, "/opt/usr/test/big_buck_bunny.mp4")) + return 0; + if (0 == strcmp(pathname, "/opt/usr/test/daliTestVideo.mp4")) + return 0; + if (0 == strcmp(pathname, "/opt/usr/test/sound_5.wav")) + return 0; + if (0 == strcmp(pathname, "/opt/usr/test/tct-content-tizen-tests_video.mp4")) + return 0; + + int (*org_fn)(const char *, int) = NULL; + org_fn = dlsym(RTLD_NEXT, "access"); + return org_fn(pathname, mode); +} + +API ssize_t readlink(const char *restrict path, char *restrict buf, size_t len) +{ + if (0 == strcmp(path, "/opt/etc/localtime")) { + memcpy(buf, "123456789012345678901234567890", len); + return 30; + } + + ssize_t(*org_fn)(const char *restrict, char *restrict, size_t) = NULL; + org_fn = dlsym(RTLD_NEXT, "readlink"); + return org_fn(path, buf, len); +} + +API DIR* opendir(const char *name) +{ + DIR* (*org_fn)(const char *) = NULL; + org_fn = dlsym(RTLD_NEXT, "opendir"); + + if (0 == strcmp(name, SETTING_DEF_RES"/Ringtones")) { + org_fn = dlsym(RTLD_NEXT, "opendir"); + return org_fn("tests/res"); + } + + return org_fn(name); +} diff --git a/tests/mocks/pkgmgrinfo_appinfo.c b/tests/mocks/pkgmgrinfo_appinfo.c index bdea937..b041832 100644 --- a/tests/mocks/pkgmgrinfo_appinfo.c +++ b/tests/mocks/pkgmgrinfo_appinfo.c @@ -19,10 +19,7 @@ #include #include - -#ifndef API -#define API __attribute__ ((visibility("default"))) -#endif +#include "sst.h" API int pkgmgrinfo_appinfo_get_usr_disabled_appinfo(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle) diff --git a/tests/mocks/system_info.c b/tests/mocks/system_info.c new file mode 100644 index 0000000..c52197d --- /dev/null +++ b/tests/mocks/system_info.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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. + */ +#define _GNU_SOURCE +#include +#include +#include +#include "sst.h" + +API int system_info_get_platform_bool(const char *key, bool *value) +{ + if (0 == strcmp(key, "tizen.org/feature/systemsetting.font")) { + *value = true; + return 0; + } + if (0 == strcmp(key, "tizen.org/feature/systemsetting.incoming_call")) { + *value = true; + return 0; + } + if (0 == strcmp(key, "tizen.org/feature/systemsetting.home_screen")) { + *value = true; + return 0; + } + if (0 == strcmp(key, "tizen.org/feature/systemsetting.lock_screen")) { + *value = true; + return 0; + } + if (0 == strcmp(key, "tizen.org/feature/systemsetting.notification_email")) { + *value = true; + return 0; + } + if (0 == strcmp(key, "tizen.org/feature/network.wifi")) { + *value = true; + return 0; + } + if (0 == strcmp(key, "tizen.org/feature/network.telephony")) { + *value = true; + return 0; + } + if (0 == strcmp(key, "tizen.org/feature/accessibility.grayscale")) { + *value = true; + return 0; + } + if (0 == strcmp(key, "tizen.org/feature/accessibility.negative")) { + *value = true; + return 0; + } + if (0 == strcmp(key, "tizen.org/feature/input.rotating_bezel")) { + *value = true; + return 0; + } + + int (*fn_org)(const char *, bool *) = NULL; + fn_org = dlsym(RTLD_NEXT, "system_info_get_platform_bool"); + return fn_org(key, value); +} + +API int system_info_get_platform_string(const char *key, char **value) +{ + if (0 == strcmp(key, "tizen.org/feature/profile")) { + *value = strdup("mobile"); + return 0; + } + + int (*fn_org)(const char *, char **) = NULL; + fn_org = dlsym(RTLD_NEXT, "system_info_get_platform_string"); + return fn_org(key, value); +} diff --git a/tests/mocks/vconf.cpp b/tests/mocks/vconf.cpp index adebfcf..e2a76b6 100644 --- a/tests/mocks/vconf.cpp +++ b/tests/mocks/vconf.cpp @@ -23,16 +23,13 @@ #include #include #include +#include "sst.h" #define LOG_D(fmt, arg...) //fprintf(fmt, arg...) #define LOG_E fprintf using namespace std; -#ifndef EXPORT -# define EXPORT __attribute__((visibility("default"))) -#endif - typedef std::map> NotifyMap; static NotifyMap notifyCallBackMap; @@ -169,32 +166,32 @@ int _sqlite_connect() /************************************************ * keynode handling APIs * ************************************************/ -EXPORT char *vconf_keynode_get_name(keynode_t *keynode) +API char *vconf_keynode_get_name(keynode_t *keynode) { return NULL; } -EXPORT int vconf_keynode_get_type(keynode_t *keynode) +API int vconf_keynode_get_type(keynode_t *keynode) { return 0; } -EXPORT int vconf_keynode_get_int(keynode_t *keynode) +API int vconf_keynode_get_int(keynode_t *keynode) { return 0; } -EXPORT double vconf_keynode_get_dbl(keynode_t *keynode) +API double vconf_keynode_get_dbl(keynode_t *keynode) { return 0; } -EXPORT int vconf_keynode_get_bool(keynode_t *keynode) +API int vconf_keynode_get_bool(keynode_t *keynode) { return 0; } -EXPORT char *vconf_keynode_get_str(keynode_t *keynode) +API char *vconf_keynode_get_str(keynode_t *keynode) { return NULL; } @@ -208,57 +205,57 @@ keylist_t *vconf_keylist_new(void) return NULL; } -EXPORT int vconf_keylist_rewind(keylist_t *keylist) +API int vconf_keylist_rewind(keylist_t *keylist) { return 0; } -EXPORT int vconf_keylist_free(keylist_t *keylist) +API int vconf_keylist_free(keylist_t *keylist) { return 0; } -EXPORT int vconf_keylist_lookup(keylist_t *keylist, const char *keyname, +API int vconf_keylist_lookup(keylist_t *keylist, const char *keyname, keynode_t **return_node) { return 0; } -EXPORT keynode_t *vconf_keylist_nextnode(keylist_t *keylist) +API keynode_t *vconf_keylist_nextnode(keylist_t *keylist) { return NULL; } -EXPORT int vconf_keylist_add_int(keylist_t *keylist, const char *keyname, +API int vconf_keylist_add_int(keylist_t *keylist, const char *keyname, const int value) { return 0; } -EXPORT int vconf_keylist_add_bool(keylist_t *keylist, const char *keyname, +API int vconf_keylist_add_bool(keylist_t *keylist, const char *keyname, const int value) { return 0; } -EXPORT int vconf_keylist_add_dbl(keylist_t *keylist, const char *keyname, +API int vconf_keylist_add_dbl(keylist_t *keylist, const char *keyname, const double value) { return 0; } -EXPORT int vconf_keylist_add_str(keylist_t *keylist, const char *keyname, +API int vconf_keylist_add_str(keylist_t *keylist, const char *keyname, const char *value) { return 0; } -EXPORT int vconf_keylist_add_null(keylist_t *keylist, const char *keyname) +API int vconf_keylist_add_null(keylist_t *keylist, const char *keyname) { return 0; } -EXPORT int vconf_keylist_del(keylist_t *keylist, const char *keyname) +API int vconf_keylist_del(keylist_t *keylist, const char *keyname) { return 0; } @@ -375,12 +372,12 @@ int _vconf_set_str(const char *in_key, const char *strval) return VCONF_OK; } -EXPORT int vconf_set(keylist_t *keylist) +API int vconf_set(keylist_t *keylist) { return 0; } -EXPORT int vconf_set_int(const char *in_key, const int intval) +API int vconf_set_int(const char *in_key, const int intval) { int rc; char buf[MAX_BUF_LEN + 1]; @@ -399,7 +396,7 @@ EXPORT int vconf_set_int(const char *in_key, const int intval) return VCONF_OK; } -EXPORT int vconf_set_bool(const char *in_key, const int boolval) +API int vconf_set_bool(const char *in_key, const int boolval) { int rc; char buf[MAX_BUF_LEN + 1]; @@ -418,7 +415,7 @@ EXPORT int vconf_set_bool(const char *in_key, const int boolval) return VCONF_OK; } -EXPORT int vconf_set_dbl(const char *in_key, const double dblval) +API int vconf_set_dbl(const char *in_key, const double dblval) { int rc; char buf[MAX_BUF_LEN + 1]; @@ -437,7 +434,7 @@ EXPORT int vconf_set_dbl(const char *in_key, const double dblval) return VCONF_OK; } -EXPORT int vconf_set_str(const char *in_key, const char *strval) +API int vconf_set_str(const char *in_key, const char *strval) { int rc; @@ -454,12 +451,12 @@ EXPORT int vconf_set_str(const char *in_key, const char *strval) return VCONF_OK; } -EXPORT int vconf_get(keylist_t *keylist, const char *in_parentDIR, get_option_t option) +API int vconf_get(keylist_t *keylist, const char *in_parentDIR, get_option_t option) { return 0; } -EXPORT char *vconf_get_str(const char *in_key) +API char *vconf_get_str(const char *in_key) { int rc; char sql[MAX_BUF_LEN + 1]; @@ -519,7 +516,7 @@ EXPORT char *vconf_get_str(const char *in_key) return str; } -EXPORT int vconf_get_int(const char *in_key, int *intval) +API int vconf_get_int(const char *in_key, int *intval) { LOG_D(stdout, "[%s][%d] start!\n", __func__, __LINE__); @@ -534,7 +531,7 @@ EXPORT int vconf_get_int(const char *in_key, int *intval) return VCONF_OK; } -EXPORT int vconf_get_bool(const char *in_key, int *boolval) +API int vconf_get_bool(const char *in_key, int *boolval) { LOG_D(stdout, "[%s][%d] start! key [%s] \n", __func__, __LINE__, in_key); @@ -554,7 +551,7 @@ EXPORT int vconf_get_bool(const char *in_key, int *boolval) return VCONF_OK; } -EXPORT int vconf_get_dbl(const char *in_key, double *dblval) +API int vconf_get_dbl(const char *in_key, double *dblval) { LOG_D(stdout, "[%s][%d] start!\n", __func__, __LINE__); @@ -570,22 +567,22 @@ EXPORT int vconf_get_dbl(const char *in_key, double *dblval) return VCONF_OK; } -EXPORT int vconf_unset(const char *in_key) +API int vconf_unset(const char *in_key) { return 0; } -EXPORT int vconf_sync_key(const char *in_key) +API int vconf_sync_key(const char *in_key) { return 0; } -EXPORT int vconf_unset_recursive(const char *in_dir) +API int vconf_unset_recursive(const char *in_dir) { return 0; } -EXPORT int vconf_notify_key_changed(const char *in_key, vconf_callback_fn cb, +API int vconf_notify_key_changed(const char *in_key, vconf_callback_fn cb, void *user_data) { string str; @@ -601,7 +598,7 @@ EXPORT int vconf_notify_key_changed(const char *in_key, vconf_callback_fn cb, return VCONF_OK; } -EXPORT int vconf_ignore_key_changed(const char *in_key, vconf_callback_fn cb) +API int vconf_ignore_key_changed(const char *in_key, vconf_callback_fn cb) { string str; str = in_key; @@ -610,7 +607,7 @@ EXPORT int vconf_ignore_key_changed(const char *in_key, vconf_callback_fn cb) return VCONF_OK; } -EXPORT int vconf_get_ext_errno(void) +API int vconf_get_ext_errno(void) { return 0; } diff --git a/tests/run_coverage.sh b/tests/run_coverage.sh deleted file mode 100755 index 30ccc34..0000000 --- a/tests/run_coverage.sh +++ /dev/null @@ -1,110 +0,0 @@ -#!/bin/bash -pushd ../ -RootDir=$PWD -popd - -createVconfDb() { - pushd scripts - ./convert_vconf_script_to_sql.sh - - if [ ! -f vconf.db ] - then - echo "vconf.db create failed!" - exit -1 - fi - - cp vconf.db ../ - popd -} - - -if [ ! -f vconf.db ] -then - createVconfDb -fi - -#======================================================================================== -# /etc/config/model-config.xml <= tm1 -system_info_init_db -k "tizen.org/feature/profile" -t string -g platform -v "mobile" -system_info_init_db -k "tizen.org/feature/systemsetting.incoming_call" -t bool -g platform -v true -system_info_init_db -k "tizen.org/feature/systemsetting.home_screen" -t bool -g platform -v true -system_info_init_db -k "tizen.org/feature/systemsetting.lock_screen" -t bool -g platform -v true -system_info_init_db -k "tizen.org/feature/systemsetting.notification_email" -t bool -g platform -v true -system_info_init_db -k "tizen.org/feature/network.wifi" -t bool -g platform -v true -system_info_init_db -k "tizen.org/feature/systemsetting.font" -t bool -g platform -v true -system_info_init_db -k "tizen.org/feature/network.telephony" -t bool -g platform -v true -system_info_init_db -k "tizen.org/feature/accessibility.grayscale" -t bool -g platform -v false -system_info_init_db -k "tizen.org/feature/accessibility.negative" -t bool -g platform -v false -system_info_init_db -k "tizen.org/feature/input.rotating_bezel" -t bool -g platform -v false -#======================================================================================== - -#======================================================================================== -# Causion : Need to root permission -#======================================================================================== -cp -f ../utils/libsystem-settings-util.so* /usr/lib - -echo "link [/opt/etc/localtime]" -ln -sf /etc/localtime /opt/etc/localtime - -if [ -f /usr/lib/libefl-extension.so.0 ] -then - cp -f /usr/lib/libefl-extension.so.0 /usr/lib/libefl-extension.so.0.back -fi -cp -f ./libefl-extension.so.0 /usr/lib/libefl-extension.so.0 - -#======================================================================================== -# Dummy MP3 File List -#======================================================================================== -mkdir -p "/opt/usr/data/settings/Ringtones" -touch "/opt/usr/data/settings/Ringtones/ringtone_sdk.mp3" - -mkdir -p "/opt/usr/data/settings/Alerts" -touch "/opt/usr/data/settings/Alerts/Over the horizon.mp3" - -mkdir -p "/opt/usr/share/" -touch "/opt/usr/share/ringtone_sdk.mp3" - -mkdir -p "/opt/usr/test" -touch "/opt/usr/test/big_buck_bunny.mp4" -touch "/opt/usr/test/daliTestVideo.mp4" -touch "/opt/usr/test/sound_5.wav" -touch "/opt/usr/test/tct-content-tizen-tests_video.mp4" -#======================================================================================== - -unitTestFile=sys-settings-test -if [ ! -x "${unitTestFile}" ] -then - echo "${unitTestFile} file does not exist!" - exit -1 -fi - -LD_PRELOAD=./libvconf-mock.so:./libpkgmgr-info-mock.so ./${unitTestFile} - -#======================================================================================== -# Causion : Need to root permission -#======================================================================================== -if [ -f /usr/lib/libefl-extension.so.0.back ] -then - cp -f /usr/lib/libefl-extension.so.0.back /usr/lib/libefl-extension.so.0 -fi -#======================================================================================== - -CMakeDir=${RootDir}/CMakeFiles/capi-system-system-settings.dir/src -CoverageDir=${RootDir}/coverage - -pushd $CMakeDir - for obj in `ls *.o` - do - gcov -b -c $obj - done - - if [ -f /usr/bin/lcov ] - then - lcov -c -d . -o cov.info - genhtml cov.info -o ${CoverageDir} - echo "Coverage test result created! [${CoverageDir}]" - else - echo "lcov does not exist!" - fi -popd - diff --git a/tests/scripts/convert_vconf_script_to_sql.sh b/tests/scripts/convert_vconf_script_to_sql.sh index 602ea9d..0b97eba 100755 --- a/tests/scripts/convert_vconf_script_to_sql.sh +++ b/tests/scripts/convert_vconf_script_to_sql.sh @@ -1,11 +1,11 @@ #!/bin/bash - +MY_DIR="$( cd "$(dirname $(readlink -f "$0"))" ; pwd -P )" db_name=vconf.db tableName=vconf -vconf_internal_keys_script=./vconf_all.sh -vconf_internal_keys_script_copy=./vconf_all_copy.sh +vconf_internal_keys_script=$MY_DIR/vconf_all.sh +vconf_internal_keys_script_copy=$MY_DIR/vconf_all_copy.sh dbScriptFile=vconf.sql create_table(){ @@ -52,7 +52,7 @@ fi sed -i 's/\${TZ_SYS_GLOBALUSER_DATA}/\/opt\/usr\/data/g' ${vconf_internal_keys_script_copy} - cat vconf_all_copy.sh | grep buxton2ctl | awk -v tableName=$tableName -F'\"' '{ printf "INSERT INTO %s ( layer, key, value, type, read_privilege, write_privilege ) values ( \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\" );\n", tableName, $4, $6, $8, $2, $10, $12 }' > ${dbScriptFile} + cat ${vconf_internal_keys_script_copy} | grep buxton2ctl | awk -v tableName=$tableName -F'\"' '{ printf "INSERT INTO %s ( layer, key, value, type, read_privilege, write_privilege ) values ( \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\" );\n", tableName, $4, $6, $8, $2, $10, $12 }' > ${dbScriptFile} echo "COMMIT TRANSACTION;" diff --git a/tests/scripts/vconf_golden_master.sh b/tests/scripts/vconf_golden_master.sh new file mode 100755 index 0000000..0239f80 --- /dev/null +++ b/tests/scripts/vconf_golden_master.sh @@ -0,0 +1,18 @@ +#!/bin/bash +CURRENT_DIR=$(pwd -P) +MY_DIR="$( cd "$(dirname $(readlink -f "$0"))" ; pwd -P )" + +createVconfDb() { + $MY_DIR/convert_vconf_script_to_sql.sh + + if [ ! -f vconf.db ] + then + echo "vconf.db create failed!" + exit -1 + fi +} + +if [ ! -f vconf.db ] +then + createVconfDb +fi diff --git a/utils/sys_settings_util.c b/utils/sys_settings_util.c index 99def20..2aaf48b 100644 --- a/utils/sys_settings_util.c +++ b/utils/sys_settings_util.c @@ -20,6 +20,7 @@ #include #include "system_settings.h" +#include "sst.h" #include "sys_settings.h" #include "sys_settings_util.h" #include "sys_settings_font.h" @@ -48,10 +49,10 @@ #define SETTING_FONT_TIZEN_FONT_ALIAS "Tizen" #define SETTING_FONT_TIZEN_DEFAULT_FONT_ALIAS "TizenDefaultFont" -#define SETTING_FONT_CONFIG_SO_PATH "/usr/lib/libfontconfig.so.1" -#define SETTING_ECORE_EVAS_SO_PATH "/usr/lib/libecore_evas.so.1" -#define SETTING_EFL_EXTENSION_SO_PATH "/usr/lib/libefl-extension.so.0" -#define SETTING_EVAS_SO_PATH "/usr/lib/libevas.so.1" +#define SETTING_FONT_CONFIG_SO_PATH "libfontconfig.so.1" +#define SETTING_ECORE_EVAS_SO_PATH "libecore_evas.so.1" +#define SETTING_EFL_EXTENSION_SO_PATH "libefl-extension.so.0" +#define SETTING_EVAS_SO_PATH "libevas.so.1" static int __font_size_get(); @@ -241,7 +242,7 @@ char *__get_main_font_family_name_by_alias(char *alias) } /* LCOV_EXCL_START */ -bool __is_supported_image_type_load(char *path) +API bool __is_supported_image_type_load(char *path) { SETTING_TRACE_BEGIN; e_libs efl_libs; @@ -281,14 +282,14 @@ bool __is_supported_image_type_load(char *path) /* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ -void font_config_set_notification() +API void font_config_set_notification() { SETTING_TRACE_BEGIN; } /* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ -int __is_available_font(char *font_name) +API int __is_available_font(char *font_name) { SETTING_TRACE_BEGIN; FcObjectSet *os = NULL; @@ -391,14 +392,14 @@ int __is_available_font(char *font_name) /* LCOV_EXCL_STOP */ -char *_get_default_font() +API char *_get_default_font() { return __get_main_font_family_name_by_alias(SETTING_FONT_TIZEN_DEFAULT_FONT_ALIAS); } /* LCOV_EXCL_START */ -bool font_config_set(char *font_name) +API bool font_config_set(char *font_name) { SETTING_TRACE_BEGIN; ex_libs eext_libs; @@ -412,7 +413,7 @@ bool font_config_set(char *font_name) /* LCOV_EXCL_STOP */ /* LCOV_EXCL_START */ -void __font_size_set() +API void __font_size_set() { SETTING_TRACE_BEGIN; ex_libs eext_libs; diff --git a/utils/sys_settings_util.h b/utils/sys_settings_util.h index 4df2829..ec118ea 100644 --- a/utils/sys_settings_util.h +++ b/utils/sys_settings_util.h @@ -16,7 +16,6 @@ bool font_config_set(char *font_name); int __is_available_font(char *font_name); char *_get_default_font(); -char *_get_cur_font(); bool __is_supported_image_type_load(char *path); void __font_size_set(); void font_config_set_notification(); -- 2.7.4