CMAKE_MINIMUM_REQUIRED(VERSION 3.9)
-PROJECT(capi-telephony C)
+PROJECT(capi-telephony)
INCLUDE(FindPkgConfig)
INCLUDE_DIRECTORIES(common)
ENDIF(STDOUT_LOG)
PKG_CHECK_MODULES(pkgs REQUIRED dlog tapi glib-2.0 capi-base-common openssl1.1
- capi-system-info cynara-client cynara-session cynara-creds-self)
+ capi-system-info cynara-client cynara-session cynara-creds-self gio-2.0)
INCLUDE_DIRECTORIES(${pkgs_INCLUDE_DIRS})
LINK_DIRECTORIES(${pkgs_LIBRARY_DIRS})
BuildRequires: pkgconfig(cynara-client)
BuildRequires: pkgconfig(cynara-session)
BuildRequires: pkgconfig(cynara-creds-self)
+BuildRequires: pkgconfig(gmock)
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
%if 0%{?gcov:1}
tar xf %{name}-gcov.tar -C %{buildroot}%{_datadir}/gcov/obj
%endif
+%check
+tests/tel-gtest
+%if 0%{?gcov:1}
+lcov -c --ignore-errors graph --no-external -b . -d . -o %{name}.info
+genhtml %{name}.info -o out --legend --show-details
+%endif
+
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%files unittests
%manifest %{name}.manifest
%{_bindir}/telephony-test
+%{_bindir}/%{name}/*gtest*
%license LICENSE.APLv2
%if 0%{?gcov:1}
for (i = 0; i < cp_count; i++) {
telephony_h tmp = malloc(sizeof(struct telephony_data));
if (tmp == NULL) {
- /* LCOV_EXCL_START */
int j;
ERR("Out of memory");
/* Need to be freed if allocated data is existing */
free(list->handle);
g_strfreev(cp_list);
return TELEPHONY_ERROR_OUT_OF_MEMORY;
- /* LCOV_EXCL_STOP */
}
tmp->evt_list = NULL;
tmp->tapi_h = tel_init(cp_list[i]);
if (tmp->tapi_h == NULL) {
- /* LCOV_EXCL_START */
int j;
ERR("tel_init() is failed");
/* Need to be freed if allocated data is existing */
free(list->handle);
g_strfreev(cp_list);
return TELEPHONY_ERROR_OPERATION_FAILED;
- /* LCOV_EXCL_STOP */
}
list->handle[i] = tmp;
}
LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
+ADD_DEFINITIONS("-DTEL_TEST")
-SET(TELE_TEST "telephony-test")
-
+SET(TEL_TEST "telephony-test")
FILE(GLOB TEST_SRCS *.c)
-ADD_EXECUTABLE(${TELE_TEST} ${TEST_SRCS})
-TARGET_LINK_LIBRARIES(${TELE_TEST} ${PROJECT_NAME})
-SET_TARGET_PROPERTIES(${TELE_TEST} PROPERTIES COMPILE_FLAGS "-fPIE")
-INSTALL(TARGETS ${TELE_TEST} DESTINATION ${BIN_INSTALL_DIR})
+ADD_EXECUTABLE(${TEL_TEST} ${TEST_SRCS})
+TARGET_LINK_LIBRARIES(${TEL_TEST} ${PROJECT_NAME})
+SET_TARGET_PROPERTIES(${TEL_TEST} PROPERTIES COMPILE_FLAGS "-fPIE")
+INSTALL(TARGETS ${TEL_TEST} DESTINATION ${BIN_INSTALL_DIR})
+
+pkg_check_modules(gtest_pkgs REQUIRED gmock)
+INCLUDE_DIRECTORIES(${gtest_pkgs_INCLUDE_DIRS})
+LINK_DIRECTORIES(${gtest_pkgs_LIBRARY_DIRS})
+
+SET(TEL_GTEST "tel-gtest")
+FILE(GLOB GTEST_SRCS *.cpp mocks/*.c ${CMAKE_SOURCE_DIR}/src/*.c)
+ADD_EXECUTABLE(${TEL_GTEST} ${GTEST_SRCS})
+TARGET_LINK_LIBRARIES(${TEL_GTEST} ${gtest_pkgs_LIBRARIES} ${pkgs_LIBRARIES})
+SET_TARGET_PROPERTIES(${TEL_GTEST} PROPERTIES
+ COMPILE_FLAGS "-fPIE"
+ #Never add any space for LINKFLAGS
+ LINK_FLAGS "-Wl,\
+--wrap=malloc,\
+--wrap=tel_get_cp_name_list,\
+--wrap=tel_init,\
+--wrap=tel_deinit,\
+--wrap=system_info_get_platform_bool")
+INSTALL(TARGETS ${TEL_GTEST} DESTINATION ${TEST_INSTALL_DIR})
--- /dev/null
+/*
+ * 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.
+ */
+#include <gtest/gtest.h>
+
+#include "telephony_common.h"
+
+extern "C" {
+#include "telephony_private.h"
+#include "mocks/telephony_malloc.h"
+#include "mocks/telephony_sysinfo.h"
+#include "mocks/telephony_tapi.h"
+}
+
+class TelCommonTest : public ::testing::Test {
+protected:
+ void SetUp() override
+ {
+ //Setting up Normal Codition
+ telephony_mock_sysinfo_set_up(true);
+ telephony_mock_tapi_cp_setup(1);
+ telephony_mock_tapi_init_setup(1);
+ }
+
+ void TearDown() override
+ {
+ telephony_mock_sysinfo_set_up(false);
+ telephony_mock_tapi_cp_setup(0);
+ telephony_mock_tapi_init_setup(0);
+ }
+};
+
+TEST_F(TelCommonTest, initP)
+{
+ int ret;
+ telephony_handle_list_s list;
+
+ ret = telephony_init(&list);
+ EXPECT_EQ(ret, TELEPHONY_ERROR_NONE);
+
+ ret = telephony_deinit(&list);
+ EXPECT_EQ(ret, TELEPHONY_ERROR_NONE);
+}
+
+TEST_F(TelCommonTest, initN)
+{
+ int ret;
+ telephony_handle_list_s list;
+
+ telephony_mock_tapi_init_setup(0);
+ ret = telephony_init(&list);
+ EXPECT_EQ(ret, TELEPHONY_ERROR_OPERATION_FAILED);
+
+ telephony_mock_malloc_set_up(sizeof(struct telephony_data), 0);
+ ret = telephony_init(&list);
+ EXPECT_EQ(ret, TELEPHONY_ERROR_OUT_OF_MEMORY);
+
+ telephony_mock_malloc_set_up(1 * sizeof(telephony_h), 0);
+ ret = telephony_init(&list);
+ EXPECT_EQ(ret, TELEPHONY_ERROR_OUT_OF_MEMORY);
+
+ telephony_mock_tapi_cp_setup(0);
+ ret = telephony_init(&list);
+ EXPECT_EQ(ret, TELEPHONY_ERROR_OPERATION_FAILED);
+
+ ret = telephony_init(NULL);
+ EXPECT_EQ(ret, TELEPHONY_ERROR_INVALID_PARAMETER);
+
+ telephony_mock_sysinfo_set_up(false);
+ ret = telephony_init(&list);
+ EXPECT_EQ(ret, TELEPHONY_ERROR_NOT_SUPPORTED);
+}
+
+int main(int argc, char **argv)
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
--- /dev/null
+/*
+ * 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.
+ */
+#include "telephony_malloc.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "telephony_private.h"
+
+static int telephony_mock_malloc_size;
+static int telephony_mock_malloc_result;
+extern void* __real_malloc(size_t size);
+
+void telephony_mock_malloc_set_up(size_t size, int result)
+{
+ telephony_mock_malloc_size = size;
+ telephony_mock_malloc_result = result;
+}
+
+void* __wrap_malloc(size_t size)
+{
+ if (size == telephony_mock_malloc_size) {
+ if (0 == telephony_mock_malloc_result)
+ return NULL;
+ }
+
+ return __real_malloc(size);
+}
+
--- /dev/null
+/*
+ * 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
+
+#include <stdlib.h>
+
+void telephony_mock_malloc_set_up(size_t size, int result);
--- /dev/null
+/*
+ * 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.
+ */
+#include "telephony_sysinfo.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <system_info.h>
+#include "telephony_private.h"
+
+static bool telephony_mock_sysinfo_result;
+extern int __real_system_info_get_platform_bool(const char *key, bool *value);
+
+void telephony_mock_sysinfo_set_up(bool value)
+{
+ telephony_mock_sysinfo_result = value;
+}
+
+API int __wrap_system_info_get_platform_bool(const char *key, bool *value)
+{
+ if (0 == strcmp(key, TELEPHONY_FEATURE)) {
+ *value = telephony_mock_sysinfo_result;
+ return SYSTEM_INFO_ERROR_NONE;
+ }
+
+ return __real_system_info_get_platform_bool(key, value);
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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
+
+#include <stdbool.h>
+
+void telephony_mock_sysinfo_set_up(bool value);
--- /dev/null
+/*
+ * 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.
+ */
+#include "telephony_tapi.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <tapi_common.h>
+#include "telephony_private.h"
+
+static int telephony_mock_tapi_cp_num;
+static int telephony_mock_tapi_init_result;
+
+void telephony_mock_tapi_cp_setup(int cp_num)
+{
+ telephony_mock_tapi_cp_num = cp_num;
+}
+
+char** __wrap_tel_get_cp_name_list()
+{
+ if (telephony_mock_tapi_cp_num) {
+ char **result = calloc(telephony_mock_tapi_cp_num + 1, sizeof(char*));
+ int i;
+ for (i = 0; i < telephony_mock_tapi_cp_num; i++) {
+ char buf[20];
+ snprintf(buf, sizeof(buf), "sprdmodem%d", i);
+ result[i] = strdup(buf);
+ }
+ return result;
+ } else {
+ return NULL;
+ }
+}
+
+void telephony_mock_tapi_init_setup(int result)
+{
+ telephony_mock_tapi_init_result = result;
+}
+
+TapiHandle* __wrap_tel_init(const char *cp_name)
+{
+ if (0 == telephony_mock_tapi_init_result)
+ return NULL;
+
+ return calloc(1, sizeof(TapiHandle));
+}
+
+int __wrap_tel_deinit(TapiHandle *handle)
+{
+ free(handle);
+ return TAPI_API_SUCCESS;
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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
+
+void telephony_mock_tapi_cp_setup(int cp_num);
+void telephony_mock_tapi_init_setup(int result);
\ No newline at end of file