!6 using glibc library functions for unit test
Merge pull request !6 from JingWoo/master
This commit is contained in:
commit
8faaf7a519
@ -24,5 +24,5 @@ target_include_directories(${EXE} PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils
|
||||
${CMAKE_BINARY_DIR}/json
|
||||
)
|
||||
set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,calloc -Wl,--wrap,memcpy_s")
|
||||
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lsecurec -lz)
|
||||
set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,calloc")
|
||||
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lz)
|
||||
|
||||
@ -16,7 +16,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <climits>
|
||||
#include <securec.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include "mock.h"
|
||||
#include "utils_array.h"
|
||||
@ -25,10 +24,6 @@
|
||||
extern "C" {
|
||||
DECLARE_WRAPPER(calloc, void *, (size_t nmemb, size_t size));
|
||||
DEFINE_WRAPPER(calloc, void *, (size_t nmemb, size_t size), (nmemb, size));
|
||||
|
||||
DECLARE_WRAPPER(memcpy_s, errno_t, (void* dest, size_t destMax, const void* src, size_t count));
|
||||
DEFINE_WRAPPER(memcpy_s, errno_t, (void* dest, size_t destMax, const void* src, size_t count),
|
||||
(dest, destMax, src, count));
|
||||
}
|
||||
|
||||
TEST(utils_array, test_util_array_len)
|
||||
@ -158,17 +153,6 @@ TEST(utils_array, test_util_grow_array)
|
||||
util_free_array(array);
|
||||
array = nullptr;
|
||||
capacity = 0;
|
||||
|
||||
capacity = 1;
|
||||
array = (char **)util_common_calloc_s(capacity * sizeof(char *));
|
||||
ASSERT_NE(array, nullptr);
|
||||
MOCK_SET(memcpy_s, EINVAL);
|
||||
ret = util_grow_array(&array, &capacity, 1, 1);
|
||||
ASSERT_NE(ret, 0);
|
||||
MOCK_CLEAR(memcpy_s);
|
||||
util_free_array(array);
|
||||
array = nullptr;
|
||||
capacity = 0;
|
||||
}
|
||||
|
||||
TEST(utils_array, test_util_array_append)
|
||||
@ -219,17 +203,4 @@ TEST(utils_array, test_util_array_append)
|
||||
MOCK_CLEAR(calloc);
|
||||
util_free_array(array);
|
||||
array = nullptr;
|
||||
|
||||
array_three = (char **)util_common_calloc_s(4 * sizeof(char *));
|
||||
ASSERT_NE(array_three, nullptr);
|
||||
array_three[0] = util_strdup_s("test1");
|
||||
array_three[1] = util_strdup_s("test2");
|
||||
array_three[2] = util_strdup_s("test3");
|
||||
array_three[3] = nullptr;
|
||||
MOCK_SET(memcpy_s, EINVAL);
|
||||
ret = util_array_append(&array_three, "123");
|
||||
ASSERT_NE(ret, 0);
|
||||
MOCK_CLEAR(memcpy_s);
|
||||
util_free_array(array_three);
|
||||
array_three = nullptr;
|
||||
}
|
||||
|
||||
@ -24,4 +24,4 @@ target_include_directories(${EXE} PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/cutils
|
||||
${CMAKE_BINARY_DIR}/json
|
||||
)
|
||||
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lsecurec -lz)
|
||||
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lz)
|
||||
|
||||
@ -16,7 +16,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <climits>
|
||||
#include <securec.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include "mock.h"
|
||||
#include "utils_convert.h"
|
||||
|
||||
@ -25,4 +25,4 @@ target_include_directories(${EXE} PUBLIC
|
||||
${CMAKE_BINARY_DIR}/json
|
||||
)
|
||||
set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,util_strdup_s -Wl,--wrap,calloc -Wl,--wrap,strcat_s")
|
||||
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lsecurec -lz)
|
||||
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lz)
|
||||
|
||||
@ -15,7 +15,6 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <securec.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include "mock.h"
|
||||
#include "utils_string.h"
|
||||
@ -26,26 +25,6 @@ extern "C" {
|
||||
|
||||
DECLARE_WRAPPER(calloc, void *, (size_t nmemb, size_t size));
|
||||
DEFINE_WRAPPER(calloc, void *, (size_t nmemb, size_t size), (nmemb, size));
|
||||
|
||||
DECLARE_WRAPPER_V(strcat_s, errno_t, (char *strDest, size_t destMax, const char *strSrc));
|
||||
DEFINE_WRAPPER_V(strcat_s, errno_t, (char *strDest, size_t destMax, const char *strSrc),
|
||||
(strDest, destMax, strSrc));
|
||||
}
|
||||
|
||||
static int g_strcat_s_cnt = 0;
|
||||
|
||||
static errno_t strcat_s_fail(char *strDest, size_t destMax, const char *strSrc)
|
||||
{
|
||||
return (errno_t)EINVAL;
|
||||
}
|
||||
|
||||
static errno_t strcat_s_second_fail(char *strDest, size_t destMax, const char *strSrc)
|
||||
{
|
||||
g_strcat_s_cnt++;
|
||||
if (g_strcat_s_cnt == 1) {
|
||||
return __real_strcat_s(strDest, destMax, strSrc);
|
||||
}
|
||||
return (errno_t)EINVAL;
|
||||
}
|
||||
|
||||
TEST(utils_string_llt, test_strings_count)
|
||||
@ -681,22 +660,6 @@ TEST(utils_string_llt, test_util_string_join)
|
||||
|
||||
result = util_string_join(nullptr, array_long, array_long_len);
|
||||
ASSERT_STREQ(result, nullptr);
|
||||
|
||||
MOCK_SET_V(strcat_s, strcat_s_fail);
|
||||
result = util_string_join(" ", array_short, array_short_len);
|
||||
ASSERT_STREQ(result, nullptr);
|
||||
MOCK_CLEAR(strcat_s);
|
||||
|
||||
MOCK_SET_V(strcat_s, strcat_s_fail);
|
||||
result = util_string_join(" ", array_long, array_long_len);
|
||||
ASSERT_STREQ(result, nullptr);
|
||||
MOCK_CLEAR(strcat_s);
|
||||
|
||||
g_strcat_s_cnt = 0;
|
||||
MOCK_SET_V(strcat_s, strcat_s_second_fail);
|
||||
result = util_string_join(" ", array_long, array_long_len);
|
||||
ASSERT_STREQ(result, nullptr);
|
||||
MOCK_CLEAR(strcat_s);
|
||||
}
|
||||
|
||||
TEST(utils_string_llt, test_util_string_append)
|
||||
@ -742,17 +705,6 @@ TEST(utils_string_llt, test_util_string_append)
|
||||
result = util_string_append("abc", "123");
|
||||
ASSERT_STREQ(result, nullptr);
|
||||
MOCK_CLEAR(calloc);
|
||||
|
||||
MOCK_SET_V(strcat_s, strcat_s_fail);
|
||||
result = util_string_append("abc", "123");
|
||||
ASSERT_STREQ(result, nullptr);
|
||||
MOCK_CLEAR(strcat_s);
|
||||
|
||||
g_strcat_s_cnt = 0;
|
||||
MOCK_SET_V(strcat_s, strcat_s_second_fail);
|
||||
result = util_string_append("abc", "123");
|
||||
ASSERT_STREQ(result, nullptr);
|
||||
MOCK_CLEAR(strcat_s);
|
||||
}
|
||||
|
||||
TEST(utils_string_llt, test_dup_array_of_strings)
|
||||
|
||||
@ -57,4 +57,4 @@ target_include_directories(${EXE} PUBLIC
|
||||
)
|
||||
|
||||
set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,util_common_calloc_s -Wl,--wrap,util_smart_calloc_s -Wl,--wrap,merge_env")
|
||||
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lsecurec -lz)
|
||||
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lz)
|
||||
|
||||
@ -15,7 +15,6 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <securec.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include "mock.h"
|
||||
#include "oci_runtime_spec.h"
|
||||
|
||||
@ -24,4 +24,4 @@ target_include_directories(${EXE} PUBLIC
|
||||
${CMAKE_BINARY_DIR}/json
|
||||
)
|
||||
set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,getcwd -Wl,--wrap,readlink")
|
||||
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lsecurec -lz)
|
||||
target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} -lyajl -lz)
|
||||
|
||||
@ -16,7 +16,6 @@
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <securec.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include "mock.h"
|
||||
#include "utils.h"
|
||||
@ -36,13 +35,16 @@ extern "C" {
|
||||
|
||||
static char *getcwd_specify(char *str, size_t size)
|
||||
{
|
||||
const char *dst = "/home";
|
||||
if (str == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (strcpy_s(str, size, "/home") != EOK) {
|
||||
if (size <= strlen(dst)) {
|
||||
return nullptr;
|
||||
}
|
||||
(void)strcpy(str, dst);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
@ -74,9 +76,10 @@ static ssize_t readlink_specify(const char *path, char *buf, size_t bufsize)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strcpy_s(buf, bufsize, linkpath) != EOK) {
|
||||
if (bufsize <= linkpath_length) {
|
||||
return -1;
|
||||
}
|
||||
(void)strcpy(buf, linkpath);
|
||||
|
||||
if (linkpath_length > bufsize) {
|
||||
return bufsize;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user