From 2a391eca5de745ed98bc7fdb2735963c7fc15815 Mon Sep 17 00:00:00 2001 From: Jaehyun Kim Date: Mon, 24 Apr 2023 19:38:19 +0900 Subject: [PATCH] Add gtest TCs for cache APIs [ 29s] [ RUN ] DownloadTest.SetCacheP [ 29s] [ OK ] DownloadTest.SetCacheP (0 ms) [ 29s] [ RUN ] DownloadTest.GetCacheN [ 29s] [ OK ] DownloadTest.GetCacheN (0 ms) [ 29s] [ RUN ] DownloadTest.GetCacheP [ 29s] [ OK ] DownloadTest.GetCacheP (0 ms) [ 29s] [ RUN ] DownloadTest.ResetCacheP [ 29s] [ OK ] DownloadTest.ResetCacheP (0 ms) [ 29s] [ RUN ] DownloadTest.GetCacheMaxSizeN [ 29s] [ OK ] DownloadTest.GetCacheMaxSizeN (0 ms) [ 29s] [ RUN ] DownloadTest.GetCacheMaxSizeP [ 29s] [ OK ] DownloadTest.GetCacheMaxSizeP (0 ms) [ 29s] [ RUN ] DownloadTest.SetCacheMaxSizeP [ 29s] [ OK ] DownloadTest.SetCacheMaxSizeP (0 ms) [ 29s] [ RUN ] DownloadTest.ResetAllCacheP [ 29s] [ OK ] DownloadTest.ResetAllCacheP (0 ms) [ 29s] [ RUN ] DownloadTest.GetCachePathN [ 29s] [ OK ] DownloadTest.GetCachePathN (0 ms) [ 29s] [ RUN ] DownloadTest.GetCachePathP [ 29s] [ OK ] DownloadTest.GetCachePathP (0 ms) [ 29s] [ RUN ] DownloadTest.SetCachePathP [ 29s] [ OK ] DownloadTest.SetCachePathP (0 ms) [ 29s] [ RUN ] DownloadTest.GetCacheLifecycleN [ 29s] [ OK ] DownloadTest.GetCacheLifecycleN (0 ms) [ 29s] [ RUN ] DownloadTest.GetCacheLifecycleP [ 29s] [ OK ] DownloadTest.GetCacheLifecycleP (0 ms) [ 29s] [ RUN ] DownloadTest.SetCacheLifecycleP [ 29s] [ OK ] DownloadTest.SetCacheLifecycleP (0 ms) Change-Id: I4fddf9a326a7dc7a0036a36ecc2ea51ff9aec39d Signed-off-by: Jaehyun Kim --- tests/mocks/dp-interface-mock.c | 50 ++++++++++++++++++++++++ tests/url-download-gtest-common.cpp | 77 +++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) diff --git a/tests/mocks/dp-interface-mock.c b/tests/mocks/dp-interface-mock.c index 75841f9..6387f61 100644 --- a/tests/mocks/dp-interface-mock.c +++ b/tests/mocks/dp-interface-mock.c @@ -269,3 +269,53 @@ EXPORT_API int dp_interface_set_verify_host(const int id, int enable) { return DOWNLOAD_ERROR_NONE; } + +EXPORT_API int dp_interface_set_cache(const int id, int enable) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_cache(const int id, int *enable) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_reset_cache(const int id) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_set_cache_max_size(const int id, const unsigned int size) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_cache_max_size(const int id, unsigned int *size) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_reset_all_cache(const int id) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_set_cache_path(const int id, const char *path) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_cache_path(const int id, char **path) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_set_cache_lifecycle(const int id, const unsigned int time) +{ + return DOWNLOAD_ERROR_NONE; +} + +EXPORT_API int dp_interface_get_cache_lifecycle(const int id, unsigned int *time) +{ + return DOWNLOAD_ERROR_NONE; +} diff --git a/tests/url-download-gtest-common.cpp b/tests/url-download-gtest-common.cpp index e3ed907..f45358e 100755 --- a/tests/url-download-gtest-common.cpp +++ b/tests/url-download-gtest-common.cpp @@ -17,6 +17,7 @@ #include #include "download.h" +#include "download_extension.h" extern "C" { #include "mocks/url-download-system-info.h" @@ -470,3 +471,79 @@ TEST_F(DownloadTest, SetTempFilePathP) EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_set_temp_file_path(did, (char *)"/tmp")); } + +TEST_F(DownloadTest, SetCacheP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_set_cache(did, true)); +} + +TEST_F(DownloadTest, GetCacheN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_get_cache(did, NULL)); +} + +TEST_F(DownloadTest, GetCacheP) +{ + bool cache_option; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_get_cache(did, &cache_option)); +} + +TEST_F(DownloadTest, ResetCacheP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_reset_cache()); +} + +TEST_F(DownloadTest, GetCacheMaxSizeN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_get_cache_max_size(NULL)); +} + +TEST_F(DownloadTest, GetCacheMaxSizeP) +{ + unsigned int size; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_get_cache_max_size(&size)); +} + +TEST_F(DownloadTest, SetCacheMaxSizeP) +{ + unsigned int size = 1000; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_set_cache_max_size(size)); +} + +TEST_F(DownloadTest, ResetAllCacheP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_reset_all_cache()); +} + +TEST_F(DownloadTest, GetCachePathN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_get_cache_path(NULL)); +} + +TEST_F(DownloadTest, GetCachePathP) +{ + char *name; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_get_cache_path(&name)); +} + +TEST_F(DownloadTest, SetCachePathP) +{ + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_set_cache_path((const char *)"/opt/usr/data/download_cache")); +} + +TEST_F(DownloadTest, GetCacheLifecycleN) +{ + EXPECT_EQ(DOWNLOAD_ERROR_INVALID_PARAMETER, download_get_cache_max_size(NULL)); +} + +TEST_F(DownloadTest, GetCacheLifecycleP) +{ + unsigned int time; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_get_cache_max_size(&time)); +} + +TEST_F(DownloadTest, SetCacheLifecycleP) +{ + unsigned int time = 172800; + EXPECT_EQ(DOWNLOAD_ERROR_NONE, download_set_cache_lifecycle(time)); +} -- 2.7.4