From 661dfee1fffe6fff4649447c9a19c80efa8729ef Mon Sep 17 00:00:00 2001 From: Seonah Moon Date: Fri, 7 May 2021 16:41:57 +0900 Subject: [PATCH] Add gtests for coverage [ 23s] Overall coverage rate: [ 23s] lines......: 97.3% (653 of 671 lines) [ 23s] functions..: 96.6% (172 of 178 functions) Change-Id: Ic2889f8de4765e699e4fa35c79ca83990f1868e4 --- CMakeLists.txt | 33 +-- packaging/capi-web-url-download.spec | 24 +- tests/CMakeLists.txt | 29 ++ tests/mocks/dp-interface-mock.c | 271 +++++++++++++++++++ tests/mocks/url-download-system-info.c | 37 +++ tests/mocks/url-download-system-info.h | 21 ++ tests/url-download-gtest-common.cpp | 472 +++++++++++++++++++++++++++++++++ tests/url-download-gtest-main.cpp | 23 ++ tests/url-download-gtest-product.cpp | 62 +++++ 9 files changed, 933 insertions(+), 39 deletions(-) create mode 100755 tests/CMakeLists.txt create mode 100644 tests/mocks/dp-interface-mock.c create mode 100644 tests/mocks/url-download-system-info.c create mode 100644 tests/mocks/url-download-system-info.h create mode 100755 tests/url-download-gtest-common.cpp create mode 100755 tests/url-download-gtest-main.cpp create mode 100755 tests/url-download-gtest-product.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7459acd..5917c64 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,33 +67,6 @@ CONFIGURE_FILE( ) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) -IF(UNIX) - -ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution) -ADD_CUSTOM_COMMAND( - DEPENDS clean - COMMENT "distribution clean" - COMMAND find - ARGS . - -not -name config.cmake -and \( - -name tester.c -or - -name Testing -or - -name CMakeFiles -or - -name cmake.depends -or - -name cmake.check_depends -or - -name CMakeCache.txt -or - -name cmake.check_cache -or - -name *.cmake -or - -name Makefile -or - -name core -or - -name core.* -or - -name gmon.out -or - -name install_manifest.txt -or - -name *.pc -or - -name *~ \) - | grep -v TC | xargs rm -rf - TARGET distclean - VERBATIM -) - -ENDIF(UNIX) +IF(BUILD_GTESTS) + ADD_SUBDIRECTORY(tests) +ENDIF(BUILD_GTESTS) diff --git a/packaging/capi-web-url-download.spec b/packaging/capi-web-url-download.spec index b80306f..d406f65 100755 --- a/packaging/capi-web-url-download.spec +++ b/packaging/capi-web-url-download.spec @@ -11,9 +11,11 @@ BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(download-provider-interface) BuildRequires: pkgconfig(capi-system-info) +BuildRequires: pkgconfig(gmock) BuildRequires: cmake %if 0%{?gcov:1} BuildRequires: lcov +BuildRequires: tar %endif %description @@ -46,21 +48,25 @@ export FFLAGS+=" -fprofile-arcs -ftest-coverage" export LDFLAGS+=" -lgcov" %endif -%cmake . - +%cmake -DBUILD_GTESTS=%{?gcov:1}%{!?gcov:0} \ + . make %{?jobs:-j%jobs} +%install +%make_install + %if 0%{?gcov:1} -mkdir -p gcov-obj -find . -name '*.gcno' -exec cp '{}' gcov-obj ';' +find .. -name '*.gcno' | tar cf %{name}-gcov.tar -T - +install -d -m 755 %{buildroot}%{_datadir}/gcov/obj +tar xf %{name}-gcov.tar -C %{buildroot}%{_datadir}/gcov/obj %endif -%install -rm -rf %{buildroot} -%make_install +%check %if 0%{?gcov:1} -mkdir -p %{buildroot}%{_datadir}/gcov/obj -install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:tests +tests/url-download-gtest +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 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100755 index 0000000..b81949b --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,29 @@ +SET(DOWNLOAD_GTEST "url-download-gtest") + +SET(DP_INTERFACE_MOCK "dp-interface-mock") +SET(DP_INTERFACE_MOCK_SRCS mocks/dp-interface-mock.c) +SET(DP_INTERFACE_MOCK_CFLAGS "${CMAKE_C_FLAGS}" ) +ADD_LIBRARY(${DP_INTERFACE_MOCK} SHARED ${DP_INTERFACE_MOCK_SRCS}) +SET_TARGET_PROPERTIES(${DP_INTERFACE_MOCK} PROPERTIES + COMPILE_FLAGS ${DP_INTERFACE_MOCK_CFLAGS} +) + +pkg_check_modules(gtest_pkgs REQUIRED gmock glib-2.0) +INCLUDE_DIRECTORIES(${gtest_pkgs_INCLUDE_DIRS}) +LINK_DIRECTORIES(${gtest_pkgs_LIBRARY_DIRS}) + +pkg_check_modules(capi_pkgs REQUIRED dlog capi-base-common capi-appfw-application capi-system-info) +INCLUDE_DIRECTORIES(${capi_pkgs_INCLUDE_DIRS}) +LINK_DIRECTORIES(${capi_pkgs_LIBRARY_DIRS}) + +SET(DOWNLOAD_GTEST "url-download-gtest") +FILE(GLOB GTEST_SRCS *.cpp mocks/url-download-*.c ${CMAKE_SOURCE_DIR}/src/*.c) +ADD_EXECUTABLE(${DOWNLOAD_GTEST} ${GTEST_SRCS}) +TARGET_LINK_LIBRARIES(${DOWNLOAD_GTEST} + ${gtest_pkgs_LIBRARIES} + ${capi_pkgs_LIBRARIES} + ${DP_INTERFACE_MOCK}) +SET_TARGET_PROPERTIES(${DOWNLOAD_GTEST} PROPERTIES + COMPILE_FLAGS "-fPIE" + LINK_FLAGS "-Wl,\ +--wrap=system_info_get_platform_bool") diff --git a/tests/mocks/dp-interface-mock.c b/tests/mocks/dp-interface-mock.c new file mode 100644 index 0000000..75841f9 --- /dev/null +++ b/tests/mocks/dp-interface-mock.c @@ -0,0 +1,271 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef EXPORT_API +#define EXPORT_API __attribute__((visibility("default"))) +#endif + +#define DOWNLOAD_ERROR_NONE 0 + +typedef void (*dp_interface_state_changed_cb) (int id, int state, void *user_data); +typedef void (*dp_interface_progress_cb) (int id, unsigned long long received, void *user_data); + +EXPORT_API int dp_interface_set_state_changed_cb + (const int id, dp_interface_state_changed_cb callback, void *user_data) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_unset_state_changed_cb(int id) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_set_progress_cb + (const int id, dp_interface_progress_cb callback, void *user_data) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_unset_progress_cb(const int id) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_create(int *id) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_destroy(const int id) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_start(const int id) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_pause(const int id) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_cancel(const int id) +{ + return DOWNLOAD_ERROR_NONE; +} + + +EXPORT_API int dp_interface_set_url(const int id, const char *url) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_set_proxy(const int id, const char *proxy) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_set_destination(const int id, const char *path) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_set_file_name(const int id, const char *file_name) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_set_network_type(const int id, int net_type) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_set_network_bonding(const int id, int enable) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_set_auto_download(const int id, int enable) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_url(const int id, char **url) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_proxy(const int id, char **proxy) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_network_type(const int id, int *net_type) +{ + *net_type = 1; + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_network_bonding(const int id, int *enable) +{ + *enable = 1; + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_destination(const int id, char **path) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_file_name(const int id, char **file_name) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_downloaded_file_path(const int id, char **path) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_mime_type(const int id, char **mime_type) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_auto_download(const int id, int *enable) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_state(const int id, int *state) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_temp_path(const int id, char **temp_path) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_content_name(const int id, char **content_name) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_content_size(const int id, unsigned long long *content_size) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_error(const int id, int *error) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_http_status(const int id, int *http_status) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_etag(const int id, char **etag) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_set_temp_file_path(const int id, const char *path) +{ + return DOWNLOAD_ERROR_NONE; +} + + +EXPORT_API int dp_interface_add_http_header_field(const int id, const char *field, const char *value) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_http_header_field(const int id, const char *field, char **value) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_http_header_field_list(const int id, char ***fields, int *length) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_remove_http_header_field(const int id, const char *field) +{ + return DOWNLOAD_ERROR_NONE; +} + + +EXPORT_API int dp_interface_set_notification_bundle(const int id, const int type, void *bundle_param) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_notification_bundle(const int id, const int type, void **bundle_param) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_set_notification_service_handle(const int id, const int type, void *handle) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_notification_service_handle(const int id, const int type, void **handle) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_set_notification_title(const int id, const char *title) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_notification_title(const int id, char **title) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_set_notification_description(const int id, const char *description) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_notification_description(const int id, char **description) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_set_notification_type(const int id, int type) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_notification_type(const int id, int *type) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_set_verify_host(const int id, int enable) +{ + return DOWNLOAD_ERROR_NONE; +} diff --git a/tests/mocks/url-download-system-info.c b/tests/mocks/url-download-system-info.c new file mode 100644 index 0000000..c6d61e5 --- /dev/null +++ b/tests/mocks/url-download-system-info.c @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2021 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 "url-download-system-info.h" + +#include +#include +#include +#include + +#define DOWNLOAD_FEATURE "tizen.org/feature/download" + +static bool url_download_mock_sysinfo_result; + +void url_download_mock_set_sysinfo_result(bool value) +{ + url_download_mock_sysinfo_result = value; +} + +int __wrap_system_info_get_platform_bool(const char *key, bool *value) +{ + *value = url_download_mock_sysinfo_result; + return SYSTEM_INFO_ERROR_NONE; +} diff --git a/tests/mocks/url-download-system-info.h b/tests/mocks/url-download-system-info.h new file mode 100644 index 0000000..599799e --- /dev/null +++ b/tests/mocks/url-download-system-info.h @@ -0,0 +1,21 @@ +/* +* Copyright (c) 2021 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 + +void url_download_mock_set_sysinfo_result(bool value); diff --git a/tests/url-download-gtest-common.cpp b/tests/url-download-gtest-common.cpp new file mode 100755 index 0000000..e3ed907 --- /dev/null +++ b/tests/url-download-gtest-common.cpp @@ -0,0 +1,472 @@ +/* +* Copyright (c) 2021 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 + +#include "download.h" + +extern "C" { +#include "mocks/url-download-system-info.h" +} + +class DownloadTest: public ::testing::Test { + protected: + int did; //download id + + void SetUp() override + { + url_download_mock_set_sysinfo_result(true); + download_create(&did); + } + + void TearDown() override + { + download_destroy(did); + url_download_mock_set_sysinfo_result(false); + } +}; + +static void __state_changed_cb(int id, download_state_e state, void *user_data) +{ +} + +static void __progress_cb(int id, unsigned long long received, void *user_data) +{ +} + +TEST_F(DownloadTest, CreateN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_create(NULL)); +} + +TEST_F(DownloadTest, CreateP) +{ + int id; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_create(&id)); +} + +TEST_F(DownloadTest, DestroyP) +{ + int id; + download_create(&id); + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_destroy(id)); +} + +TEST_F(DownloadTest, StartP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_start(did)); +} + +TEST_F(DownloadTest, PauseP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_pause(did)); +} + +TEST_F(DownloadTest, CancelP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_cancel(did)); +} + +TEST_F(DownloadTest, SetUrlN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_set_url(did, NULL)); +} + +TEST_F(DownloadTest, SetUrlP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_set_url(did, "https://www.tizen.org")); +} + +TEST_F(DownloadTest, GetUrlN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_get_url(did, NULL)); +} + +TEST_F(DownloadTest, GetUrlP) +{ + char *url = NULL; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_get_url(did, &url)); +} + +TEST_F(DownloadTest, SetNetworkTypeP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_set_network_type(did, + DOWNLOAD_NETWORK_DATA_NETWORK)); + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_set_network_type(did, + DOWNLOAD_NETWORK_WIFI)); + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_set_network_type(did, + DOWNLOAD_NETWORK_WIFI_DIRECT)); + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_set_network_type(did, + DOWNLOAD_NETWORK_ALL)); +} + +TEST_F(DownloadTest, GetNetworkTypeN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_get_network_type(did, NULL)); +} + +TEST_F(DownloadTest, GetNetworkTypeP) +{ + download_network_type_e type; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_get_network_type(did, &type)); +} + +TEST_F(DownloadTest, SetDestinationN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_set_destination(did, NULL)); +} + +TEST_F(DownloadTest, SetDestinationP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_set_destination(did, "/tmp")); +} + +TEST_F(DownloadTest, GetDestinationN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_get_destination(did, NULL)); +} + +TEST_F(DownloadTest, GetDestinationP) +{ + char *dest; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_get_destination(did, &dest)); +} + +TEST_F(DownloadTest, SetFileNameN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_set_file_name(did, NULL)); +} + +TEST_F(DownloadTest, SetFileNameP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_set_file_name(did, "test-file")); +} + +TEST_F(DownloadTest, GetFileNameN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_get_file_name(did, NULL)); +} + +TEST_F(DownloadTest, GetFileNameP) +{ + char *name; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_get_file_name(did, &name)); +} + +TEST_F(DownloadTest, GetDownloadedFilePathN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_get_downloaded_file_path(did, NULL)); +} + +TEST_F(DownloadTest, GetDownloadedFilePathP) +{ + char *path; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_get_downloaded_file_path(did, &path)); +} + +TEST_F(DownloadTest, AddHttpHeaderFieldN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, + download_add_http_header_field(did, NULL, "value")); + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, + download_add_http_header_field(did, "field", NULL)); +} + +TEST_F(DownloadTest, AddHttpHeaderFieldP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, + download_add_http_header_field(did, "field", "value")); +} + +TEST_F(DownloadTest, GetHttpHeaderFieldN) +{ + char *val; + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, + download_get_http_header_field(did, "Content-Length", NULL)); + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, + download_get_http_header_field(did, NULL, &val)); +} + +TEST_F(DownloadTest, GetHttpHeaderFieldP) +{ + char *val; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, + download_get_http_header_field(did, "Content-Length", &val)); +} + +TEST_F(DownloadTest, GetHttpHeaderFieldListN) +{ + char **field; + int len; + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, + download_get_http_header_field_list(did, &field, NULL)); + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, + download_get_http_header_field_list(did, NULL, &len)); +} + +TEST_F(DownloadTest, GetHttpHeaderFieldListP) +{ + char **field; + int len; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, + download_get_http_header_field_list(did, &field, &len)); +} + +TEST_F(DownloadTest, RemoveHttpHeaderFieldN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, + download_remove_http_header_field(did, NULL)); +} + +TEST_F(DownloadTest, RemoveHttpHeaderFieldP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, + download_remove_http_header_field(did, "Content-Length")); +} + +TEST_F(DownloadTest, SetStateChangedCbP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, + download_set_state_changed_cb(did, __state_changed_cb, NULL)); +} + +TEST_F(DownloadTest, UnsetStateChangedCbP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, + download_unset_state_changed_cb(did)); +} + +TEST_F(DownloadTest, SetProgressCbP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, + download_set_progress_cb(did, __progress_cb, NULL)); +} + +TEST_F(DownloadTest, UnsetProgressCbP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, + download_unset_progress_cb(did)); +} + +TEST_F(DownloadTest, GetStateN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_get_state(did, NULL)); +} + +TEST_F(DownloadTest, GetStateP) +{ + download_state_e state; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_get_state(did, &state)); +} + +TEST_F(DownloadTest, GetTempPathN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_get_temp_path(did, NULL)); +} + +TEST_F(DownloadTest, GetTempPathP) +{ + char *path; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_get_temp_path(did, &path)); +} + +TEST_F(DownloadTest, GetContentNameN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_get_content_name(did, NULL)); +} + +TEST_F(DownloadTest, GetContentNameP) +{ + char *name; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_get_content_name(did, &name)); +} + +TEST_F(DownloadTest, GetContentSizeN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_get_content_size(did, NULL)); +} + +TEST_F(DownloadTest, GetContentSizeP) +{ + unsigned long long size; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_get_content_size(did, &size)); +} + +TEST_F(DownloadTest, GetMimeTypeN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_get_mime_type(did, NULL)); +} + +TEST_F(DownloadTest, GetMimeTypeP) +{ + char *type; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_get_mime_type(did, &type)); +} + +TEST_F(DownloadTest, SetAutoDownloadP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_set_auto_download(did, true)); +} + +TEST_F(DownloadTest, GetAutoDownloadN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_get_auto_download(did, NULL)); +} + +TEST_F(DownloadTest, GetAutoDownloadP) +{ + bool auto_download; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_get_auto_download(did, &auto_download)); +} + +TEST_F(DownloadTest, GetErrorN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_get_error(did, NULL)); +} + +TEST_F(DownloadTest, GetErrorP) +{ + download_error_e error; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_get_error(did, &error)); +} + +TEST_F(DownloadTest, GetHttpStatusN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_get_http_status(did, NULL)); +} + +TEST_F(DownloadTest, GetHttpStatusP) +{ + int status; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_get_http_status(did, &status)); +} + +TEST_F(DownloadTest, SetNotificationAppControlN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, + download_set_notification_app_control(did, + DOWNLOAD_NOTIFICATION_APP_CONTROL_TYPE_COMPLETE, NULL)); +} + +TEST_F(DownloadTest, SetNotificationAppControlP) +{ + app_control_h app = (app_control_h)calloc(1, sizeof(int)); + EXPECT_EQ(DOWNLOAD_ERROR_NONE, + download_set_notification_app_control(did, + DOWNLOAD_NOTIFICATION_APP_CONTROL_TYPE_COMPLETE, app)); + free(app); +} + +TEST_F(DownloadTest, GetNotificationAppControlN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, + download_get_notification_app_control(did, + DOWNLOAD_NOTIFICATION_APP_CONTROL_TYPE_COMPLETE, NULL)); +} + +TEST_F(DownloadTest, GetNotificationAppControlP) +{ + app_control_h app; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, + download_get_notification_app_control(did, + DOWNLOAD_NOTIFICATION_APP_CONTROL_TYPE_COMPLETE, &app)); +} + +TEST_F(DownloadTest, SetNotificationTitleN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_set_notification_title(did, NULL)); +} + +TEST_F(DownloadTest, SetNotificationTitleP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_set_notification_title(did, "title")); +} + +TEST_F(DownloadTest, GetNotificationTitleN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_get_notification_title(did, NULL)); +} + +TEST_F(DownloadTest, GetNotificationTitleP) +{ + char *title; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_get_notification_title(did, &title)); +} + +TEST_F(DownloadTest, SetNotificationDescriptionN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, + download_set_notification_description(did, NULL)); +} + +TEST_F(DownloadTest, SetNotificationDescriptionP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, + download_set_notification_description(did, "description")); +} + +TEST_F(DownloadTest, GetNotificationDescriptionN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, + download_get_notification_description(did, NULL)); +} + +TEST_F(DownloadTest, GetNotificationDescriptionP) +{ + char *description; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, + download_get_notification_description(did, &description)); +} + +TEST_F(DownloadTest, SetNotificationTypeP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, + download_set_notification_type(did, DOWNLOAD_NOTIFICATION_TYPE_COMPLETE_ONLY)); +} + +TEST_F(DownloadTest, GetNotificationTypeN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_get_notification_type(did, NULL)); +} + +TEST_F(DownloadTest, GetNotificationTypeP) +{ + download_notification_type_e type; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_get_notification_type(did, &type)); +} + +TEST_F(DownloadTest, GetEtagN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_get_etag(did, NULL)); +} + +TEST_F(DownloadTest, GetEtagP) +{ + char *etag; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_get_etag(did, &etag)); +} + +TEST_F(DownloadTest, SetTempFilePathN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, + download_set_temp_file_path(did, NULL)); +} + +TEST_F(DownloadTest, SetTempFilePathP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, + download_set_temp_file_path(did, (char *)"/tmp")); +} diff --git a/tests/url-download-gtest-main.cpp b/tests/url-download-gtest-main.cpp new file mode 100755 index 0000000..4f45cb4 --- /dev/null +++ b/tests/url-download-gtest-main.cpp @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2021 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 + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/tests/url-download-gtest-product.cpp b/tests/url-download-gtest-product.cpp new file mode 100755 index 0000000..d11939c --- /dev/null +++ b/tests/url-download-gtest-product.cpp @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2021 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 + +#include "download.h" +#include "download_product.h" + +extern "C" { +#include "mocks/url-download-system-info.h" +} + +class DownloadProductTest: public ::testing::Test { + protected: + int did; //download id + + void SetUp() override + { + url_download_mock_set_sysinfo_result(true); + download_create(&did); + } + + void TearDown() override + { + download_destroy(did); + url_download_mock_set_sysinfo_result(false); + } +}; + +TEST_F(DownloadProductTest, SetNetworkBondingP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_set_network_bonding(did, true)); +} + +TEST_F(DownloadProductTest, GetNetworkBondingN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_get_network_bonding(did, NULL)); +} + +TEST_F(DownloadProductTest, GetNetworkBondingP) +{ + bool bonding; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_get_network_bonding(did, &bonding)); +} + +TEST_F(DownloadProductTest, SetVerifyHostP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_set_verify_host(did, true)); +} -- 2.7.4