🧪 test: 增加gtest

This commit is contained in:
“pengxuanzheng”
2022-03-02 07:53:16 +00:00
parent 9d688a9e9e
commit e7f4277894
17 changed files with 280 additions and 219 deletions

View File

@@ -7,8 +7,20 @@ variables:
TESTING_VERSION_BUILD: 0 TESTING_VERSION_BUILD: 0
stages: stages:
- analysis
- test
- build - build
run_cppcheck:
stage: analysis
script:
- mkdir build || true
- cd build
- cmake3 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
- cppcheck --project=compile_commands.json --enable=all --error-exitcode=1 --suppress=unusedFunction --suppress=missingInclude --suppress=uselessAssignmentPtrArg --suppress=unmatchedSuppression
tags:
- share
.build_by_travis: .build_by_travis:
before_script: before_script:
- mkdir -p $BUILD_PADDING_PREFIX/$CI_PROJECT_NAMESPACE/ - mkdir -p $BUILD_PADDING_PREFIX/$CI_PROJECT_NAMESPACE/
@@ -22,6 +34,18 @@ stages:
tags: tags:
- share - share
# run_test:
# stage: test
# extends: .build_by_travis
# variables:
# HOS_MOCK: "ON"
# HOS_MESA_LOG: "OFF"
# script:
# - yum makecache
# - ./ci/travis.sh
# - cd build
# - ctest --verbose
branch_build_debug: branch_build_debug:
stage: build stage: build
extends: .build_by_travis extends: .build_by_travis

View File

@@ -15,9 +15,28 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall ")
set(CMAKE_INSTALL_PREFIX /opt/MESA) set(CMAKE_INSTALL_PREFIX /opt/MESA)
set(SUPPORT_INSTALL_PREFIX /usr/local/lib64) set(SUPPORT_INSTALL_PREFIX /usr/local/lib64)
find_program(CMAKE_CXX_CPPCHECK NAMES cppcheck)
if (CMAKE_CXX_CPPCHECK)
list(
APPEND CMAKE_CXX_CPPCHECK
"--enable=all"
"--error-exitcode=0"
"--suppress=unusedFunction"
"--suppress=missingInclude"
"--suppress=uselessAssignmentPtrArg"
"--suppress=unmatchedSuppression"
)
set(CMAKE_C_CPPCHECK ${CMAKE_CXX_CPPCHECK})
else()
message(FATAL_ERROR "Could not find the program cppcheck.")
endif()
add_subdirectory(support) add_subdirectory(support)
add_subdirectory(src) add_subdirectory(src)
enable_testing()
add_subdirectory(gtest)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/src/libhos-client-cpp.so DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT LIBRARIES) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/src/libhos-client-cpp.so DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT LIBRARIES)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/hos_client.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include COMPONENT HEADER) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/hos_client.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include COMPONENT HEADER)
#install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/hos.conf DESTINATION /etc/ld.so.conf.d COMPONENT PROFILE) #install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/hos.conf DESTINATION /etc/ld.so.conf.d COMPONENT PROFILE)

View File

@@ -44,6 +44,7 @@ cmake3 -DCMAKE_CXX_FLAGS=$CXX_FLAGS \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \ -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \ -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \
-DENABLE_DEVEL=$ENABLE_DEVEL_SWITCH \ -DENABLE_DEVEL=$ENABLE_DEVEL_SWITCH \
-DHOS_MOCK=$HOS_MOCK \
.. ..
make make
@@ -57,8 +58,9 @@ if [ -n "${UPLOAD}" ]; then
python3 rpm_upload_tools.py ${PULP3_REPO_NAME} ${PULP3_DIST_NAME} *.rpm python3 rpm_upload_tools.py ${PULP3_REPO_NAME} ${PULP3_DIST_NAME} *.rpm
fi fi
#if [ -n "${UPLOAD_SYMBOL_FILES}" ]; then if [ -n "${UPLOAD_SYMBOL_FILES}" ]; then
# rpm -i tfe*debuginfo*.rpm rpm -i $SYMBOL_TARGE*debuginfo*.rpm
# cp /usr/lib/debug/opt/tsg/tfe/bin/tfe.debug /tmp/tfe.debuginfo.${CI_COMMIT_SHORT_SHA} _symbol_file=`find /usr/lib/debug/ -name "$SYMBOL_TARGET*.so*.debug"`
# sentry-cli upload-dif -t elf /tmp/tfe.debuginfo.${CI_COMMIT_SHORT_SHA} cp $_symbol_file ${_symbol_file}info.${CI_COMMIT_SHORT_SHA}
#fi sentry-cli upload-dif -t elf ${_symbol_file}info.${CI_COMMIT_SHORT_SHA}
fi

View File

@@ -5,6 +5,9 @@ aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} SRCS)
include_directories("/opt/MESA/include") include_directories("/opt/MESA/include")
include_directories("/opt/MESA/include/MESA") include_directories("/opt/MESA/include/MESA")
link_directories("/opt/MESA/lib") link_directories("/opt/MESA/lib")
link_directories("${CMAKE_BINARY_DIR}/support/GoogleTest/include/")
link_directories("${CMAKE_BINARY_DIR}/src/")
link_directories("${CMAKE_BINARY_DIR}/support/GoogleTest/lib/")
#link_libraries(hos-client-cpp gtest gtest_main pthread) #link_libraries(hos-client-cpp gtest gtest_main pthread)
# coverage # coverage
@@ -14,7 +17,12 @@ SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-cove
add_definitions(-g -W -Wall -std=c++11) add_definitions(-g -W -Wall -std=c++11)
#add_executable(gtest_hos_client gtest_hos_init_instance.cpp gtest_hos_get_instance.cpp gtest_hos_close_fd.cpp gtest_hos_open_fd.cpp) #add_executable(gtest_hos_client gtest_hos_init_instance.cpp gtest_hos_get_instance.cpp gtest_hos_close_fd.cpp gtest_hos_open_fd.cpp)
#add_executable(gtest_hos_client CheckHosClient.cpp gtest_hos_close_fd.cpp) #add_executable(gtest_hos_client CheckHosClient.cpp gtest_hos_init_instance.cpp)
add_executable(gtest_hos_client ${SRCS}) add_executable(gtest_hos_client ${SRCS})
add_dependencies(gtest_hos_client ${lib_name}_shared gtest)
target_link_libraries(gtest_hos_client hos-client-cpp gtest gtest_main pthread) target_link_libraries(gtest_hos_client hos-client-cpp gtest gtest_main pthread)
add_test(NAME SOFT_LINK COMMAND sh -c "ln -sf ${CMAKE_CURRENT_SOURCE_DIR}/conf ${CMAKE_BINARY_DIR}/conf")
add_test(NAME MKDIR COMMAND sh -c "cd ${CMAKE_CURRENT_BINARY_DIR} && mkdir log")
add_test(NAME HOS_TEST COMMAND gtest_hos_client)

View File

@@ -2,22 +2,22 @@
void CheckStructHosConfigT(hos_config_t *actual, hos_config_t *expect) void CheckStructHosConfigT(hos_config_t *actual, hos_config_t *expect)
{ {
EXPECT_STREQ(actual->accesskeyid, expect->accesskeyid); ASSERT_STREQ(actual->accesskeyid, expect->accesskeyid);
EXPECT_STREQ(actual->secretkey, expect->secretkey); ASSERT_STREQ(actual->secretkey, expect->secretkey);
EXPECT_STREQ(actual->log_path, expect->log_path); ASSERT_STREQ(actual->log_path, expect->log_path);
EXPECT_EQ(actual->log_level, expect->log_level); ASSERT_EQ(actual->log_level, expect->log_level);
EXPECT_EQ(actual->pool_thread_size, expect->pool_thread_size); ASSERT_EQ(actual->pool_thread_size, expect->pool_thread_size);
EXPECT_EQ(actual->cache_count, expect->cache_count); ASSERT_EQ(actual->cache_count, expect->cache_count);
EXPECT_EQ(actual->cache_size, expect->cache_size); ASSERT_EQ(actual->cache_size, expect->cache_size);
EXPECT_EQ(actual->fs2_fmt, expect->fs2_fmt); ASSERT_EQ(actual->fs2_fmt, expect->fs2_fmt);
EXPECT_STREQ(actual->fs2_ip, expect->fs2_ip); ASSERT_STREQ(actual->fs2_ip, expect->fs2_ip);
EXPECT_STREQ(actual->fs2_path, expect->fs2_path); ASSERT_STREQ(actual->fs2_path, expect->fs2_path);
EXPECT_EQ(actual->fs2_port, expect->fs2_port); ASSERT_EQ(actual->fs2_port, expect->fs2_port);
EXPECT_STREQ(actual->ip, expect->ip); ASSERT_STREQ(actual->ip, expect->ip);
EXPECT_EQ(actual->port, expect->port); ASSERT_EQ(actual->port, expect->port);
EXPECT_EQ(actual->thread_num, expect->thread_num); ASSERT_EQ(actual->thread_num, expect->thread_num);
EXPECT_EQ(actual->max_request_context, expect->max_request_context); ASSERT_EQ(actual->max_request_context, expect->max_request_context);
EXPECT_EQ(actual->max_request_num, expect->max_request_num); ASSERT_EQ(actual->max_request_num, expect->max_request_num);
} }
void CheckStructFs2DataInfo(data_info_t *actual, data_info_t *expect, int thread_num) void CheckStructFs2DataInfo(data_info_t *actual, data_info_t *expect, int thread_num)
@@ -28,59 +28,59 @@ void CheckStructFs2DataInfo(data_info_t *actual, data_info_t *expect, int thread
{ {
if (actual->cache) if (actual->cache)
{ {
EXPECT_EQ(actual->cache[i], expect->cache[i]); ASSERT_EQ(actual->cache[i], expect->cache[i]);
} }
if (actual->rx_bytes) if (actual->rx_bytes)
{ {
EXPECT_EQ(actual->rx_bytes[i], expect->rx_bytes[i]); ASSERT_EQ(actual->rx_bytes[i], expect->rx_bytes[i]);
} }
if (actual->rx_pkts) if (actual->rx_pkts)
{ {
EXPECT_EQ(actual->rx_pkts[i], expect->rx_pkts[i]); ASSERT_EQ(actual->rx_pkts[i], expect->rx_pkts[i]);
} }
if (actual->tx_bytes) if (actual->tx_bytes)
{ {
EXPECT_EQ(actual->tx_bytes[i], expect->tx_bytes[i]); ASSERT_EQ(actual->tx_bytes[i], expect->tx_bytes[i]);
} }
if (actual->tx_pkts) if (actual->tx_pkts)
{ {
EXPECT_EQ(actual->tx_pkts[i], expect->tx_pkts[i]); ASSERT_EQ(actual->tx_pkts[i], expect->tx_pkts[i]);
} }
if (actual->tx_failed_bytes) if (actual->tx_failed_bytes)
{ {
EXPECT_EQ(actual->tx_failed_bytes[i], expect->tx_failed_bytes[i]); ASSERT_EQ(actual->tx_failed_bytes[i], expect->tx_failed_bytes[i]);
} }
if (actual->tx_failed_pkts) if (actual->tx_failed_pkts)
{ {
EXPECT_EQ(actual->tx_failed_pkts[i], expect->tx_failed_pkts[i]); ASSERT_EQ(actual->tx_failed_pkts[i], expect->tx_failed_pkts[i]);
} }
} }
} }
void CheckStructHosFunc(hos_func_thread_t *actual, hos_func_thread_t *expect, int thread_num) void CheckStructHosFunc(hos_func_thread_t *actual, hos_func_thread_t *expect, int thread_num)
{ {
//EXPECT_EQ(actual->fd_thread, expect->fd_thread); //ASSERT_EQ(actual->fd_thread, expect->fd_thread);
EXPECT_EQ(actual->fd_thread_status, expect->fd_thread_status); ASSERT_EQ(actual->fd_thread_status, expect->fd_thread_status);
if (actual->fs2_info.reserved != NULL) if (actual->fs2_info.reserved != NULL)
{ {
CheckStructFs2DataInfo((data_info_t *)actual->fs2_info.reserved, CheckStructFs2DataInfo((data_info_t *)actual->fs2_info.reserved,
(data_info_t *)expect->fs2_info.reserved, thread_num); (data_info_t *)expect->fs2_info.reserved, thread_num);
} }
EXPECT_EQ(actual->fs2_status, expect->fs2_status); ASSERT_EQ(actual->fs2_status, expect->fs2_status);
//EXPECT_EQ(actual->fs2_thread, expect->fs2_thread); //ASSERT_EQ(actual->fs2_thread, expect->fs2_thread);
} }
void CheckStructGHosHandle(hos_client_handle_t *actual, hos_client_handle_t *expect) void CheckStructGHosHandle(hos_client_handle_t *actual, hos_client_handle_t *expect)
{ {
//EXPECT_STREQ(actual->buckets.c_str(), expect->buckets.c_str()); //ASSERT_STREQ(actual->buckets.c_str(), expect->buckets.c_str());
int bucketNum = actual->buckets.size() > expect->buckets.size() ? expect->buckets.size() : actual->buckets.size(); int bucketNum = actual->buckets.size() > expect->buckets.size() ? expect->buckets.size() : actual->buckets.size();
for (int i = 0; i < bucketNum; i++) for (int i = 0; i < bucketNum; i++)
{ {
EXPECT_STREQ(actual->buckets.at(i).GetName().c_str(), expect->buckets.at(i).GetName().c_str()); ASSERT_STREQ(actual->buckets.at(i).GetName().c_str(), expect->buckets.at(i).GetName().c_str());
} }
EXPECT_EQ(actual->count, expect->count); ASSERT_EQ(actual->count, expect->count);
//EXPECT_TRUE(actual->log != NULL); //ASSERT_TRUE(actual->log != NULL);
//EXPECT_TRUE(actual->S3Client != NULL); //ASSERT_TRUE(actual->S3Client != NULL);
CheckStructHosConfigT(&actual->hos_config, &expect->hos_config); CheckStructHosConfigT(&actual->hos_config, &expect->hos_config);
CheckStructHosFunc(&actual->hos_func, &expect->hos_func, actual->hos_config.thread_num); CheckStructHosFunc(&actual->hos_func, &expect->hos_func, actual->hos_config.thread_num);
} }
@@ -89,28 +89,28 @@ void CheckStructGHosFdContext(hos_fd_context_t *actual, hos_fd_context_t *expect
{ {
if (actual == NULL || expect == NULL) if (actual == NULL || expect == NULL)
{ {
EXPECT_TRUE(actual == expect); ASSERT_TRUE(actual == expect);
} }
else else
{ {
EXPECT_STREQ(actual->bucket, expect->bucket); ASSERT_STREQ(actual->bucket, expect->bucket);
//EXPECT_TRUE(actual->cache == NULL); //ASSERT_TRUE(actual->cache == NULL);
EXPECT_EQ(actual->cache_count, expect->cache_count); ASSERT_EQ(actual->cache_count, expect->cache_count);
EXPECT_EQ(actual->cache_rest, expect->cache_rest); ASSERT_EQ(actual->cache_rest, expect->cache_rest);
EXPECT_EQ(actual->callback, expect->callback); ASSERT_EQ(actual->callback, expect->callback);
EXPECT_EQ(actual->fd_status, expect->fd_status); ASSERT_EQ(actual->fd_status, expect->fd_status);
EXPECT_EQ(actual->mode, expect->mode); ASSERT_EQ(actual->mode, expect->mode);
EXPECT_STREQ(actual->object, expect->object); ASSERT_STREQ(actual->object, expect->object);
EXPECT_EQ(actual->position, expect->position); ASSERT_EQ(actual->position, expect->position);
EXPECT_EQ(actual->recive_cnt, expect->recive_cnt); ASSERT_EQ(actual->recive_cnt, expect->recive_cnt);
EXPECT_EQ(actual->userdata, expect->userdata); ASSERT_EQ(actual->userdata, expect->userdata);
} }
} }
void CheckHosInstance(hos_instance actual, hos_instance expect) void CheckHosInstance(hos_instance actual, hos_instance expect)
{ {
EXPECT_EQ(actual->status, expect->status); ASSERT_EQ(actual->status, expect->status);
EXPECT_EQ(actual->error_code, expect->error_code); ASSERT_EQ(actual->error_code, expect->error_code);
EXPECT_STREQ(actual->error_message, expect->error_message); ASSERT_STREQ(actual->error_message, expect->error_message);
EXPECT_STREQ(actual->hos_url_prefix, expect->hos_url_prefix); ASSERT_STREQ(actual->hos_url_prefix, expect->hos_url_prefix);
} }

1
gtest/conf/conf Symbolic link
View File

@@ -0,0 +1 @@
/root/project/hos_client_cpp_module/gtest/conf

View File

@@ -51,9 +51,10 @@ static void gtest_hos_instance_init(hos_instance instance)
static void gtest_hos_fd_init(hos_fd_context_t *fd_info) static void gtest_hos_fd_init(hos_fd_context_t *fd_info)
{ {
memset(fd_info, 0, sizeof(hos_fd_context_t)); fd_info->mode = 0;
fd_info->bucket = (char *)HOS_BUCKET; fd_info->bucket = (char *)HOS_BUCKET;
fd_info->object = (char *)"object"; fd_info->object = (char *)"object";
fd_info->cache = NULL;
fd_info->cache_count = 10; fd_info->cache_count = 10;
fd_info->cache_rest = g_hos_handle.hos_config.cache_size; fd_info->cache_rest = g_hos_handle.hos_config.cache_size;
fd_info->callback = NULL; fd_info->callback = NULL;
@@ -62,6 +63,10 @@ static void gtest_hos_fd_init(hos_fd_context_t *fd_info)
fd_info->position = 0; fd_info->position = 0;
fd_info->recive_cnt = 0; fd_info->recive_cnt = 0;
fd_info->userdata = NULL; fd_info->userdata = NULL;
fd_info->reslut = false;
fd_info->error = NULL;
fd_info->errorcode = 0;
fd_info->thread_id = 0;
} }
TEST(hos_close_fd, normal) TEST(hos_close_fd, normal)
@@ -72,25 +77,26 @@ TEST(hos_close_fd, normal)
int thread_num = 2; int thread_num = 2;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", thread_num); hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", thread_num);
ASSERT_NE(hos_instance, nullptr);
gtest_hos_instance_init(&expect_hos_instance); gtest_hos_instance_init(&expect_hos_instance);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
gtest_hos_handle_init(&expect_hos_handle, thread_num); gtest_hos_handle_init(&expect_hos_handle, thread_num);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd = 0; size_t fd = 0;
int err = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, &fd); hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, &fd);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info); gtest_hos_fd_init(&expect_fd_info);
CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info); CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info);
int ret = hos_close_fd(fd); int ret = hos_close_fd(fd);
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance(); ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = INSTANCE_UNINIT_STATE; expect_hos_instance.status = INSTANCE_UNINIT_STATE;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
@@ -123,7 +129,7 @@ TEST(hos_close_fd, paramer_error)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd = 0; size_t fd = 0;
int err = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, &fd); hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, &fd);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info); gtest_hos_fd_init(&expect_fd_info);
@@ -131,12 +137,12 @@ TEST(hos_close_fd, paramer_error)
((hos_fd_context_t *)fd)->thread_id = thread_num + 1; ((hos_fd_context_t *)fd)->thread_id = thread_num + 1;
int ret = hos_close_fd(fd); int ret = hos_close_fd(fd);
EXPECT_EQ(ret, HOS_PARAMETER_ERROR); ASSERT_EQ(ret, HOS_PARAMETER_ERROR);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance(); ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = INSTANCE_UNINIT_STATE; expect_hos_instance.status = INSTANCE_UNINIT_STATE;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
@@ -157,7 +163,7 @@ TEST(hos_close_fd, paramer_error)
TEST(hos_close_fd, not_init_instance) TEST(hos_close_fd, not_init_instance)
{ {
int ret = hos_close_fd(1); int ret = hos_close_fd(1);
EXPECT_EQ(ret, HOS_INSTANCE_NOT_INIT); ASSERT_EQ(ret, HOS_INSTANCE_NOT_INIT);
} }
#if 0 #if 0
@@ -175,12 +181,12 @@ TEST(hos_close_fd, fd_not_exits)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_close_fd(7, 0); int ret = hos_close_fd(7, 0);
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance(); ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = INSTANCE_UNINIT_STATE; expect_hos_instance.status = INSTANCE_UNINIT_STATE;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);

View File

@@ -75,7 +75,7 @@ TEST(hos_get_instance, normal)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_shutdown_instance(); int ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = 0; expect_hos_instance.status = 0;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);

View File

@@ -67,7 +67,7 @@ TEST(hos_init_instance, normal)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_shutdown_instance(); int ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
memset(&expect_hos_instance, 0, sizeof(expect_hos_instance)); memset(&expect_hos_instance, 0, sizeof(expect_hos_instance));
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
@@ -92,7 +92,7 @@ TEST(hos_init_instance, param_error)
ASSERT_EQ(hos_instance, nullptr); ASSERT_EQ(hos_instance, nullptr);
expect_hos_instance.status = INSTANCE_UNINIT_STATE; expect_hos_instance.status = INSTANCE_UNINIT_STATE;
expect_hos_instance.error_code = HOS_PARAMETER_ERROR; expect_hos_instance.error_code = HOS_PARAMETER_ERROR;
const char *err_msg = "param error:conf_path:(null), module:hos_default_conf, thread_num:1"; const char *err_msg = "param error:conf_path:NULL, module:hos_default_conf, thread_num:1";
memcpy(expect_hos_instance.error_message, err_msg, strlen(err_msg)+1); memcpy(expect_hos_instance.error_message, err_msg, strlen(err_msg)+1);
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(&g_hos_instance, &expect_hos_instance); CheckHosInstance(&g_hos_instance, &expect_hos_instance);
@@ -129,7 +129,7 @@ TEST(hos_init_instance, server_conn_failed)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_shutdown_instance(); int ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
memset(&expect_hos_instance, 0, sizeof(expect_hos_instance)); memset(&expect_hos_instance, 0, sizeof(expect_hos_instance));
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);

View File

@@ -51,9 +51,10 @@ static void gtest_hos_instance_init(hos_instance instance)
static void gtest_hos_fd_init(hos_fd_context_t *fd_info) static void gtest_hos_fd_init(hos_fd_context_t *fd_info)
{ {
memset(fd_info, 0, sizeof(hos_fd_context_t)); fd_info->mode = 0;
fd_info->bucket = (char *)HOS_BUCKET; fd_info->bucket = (char *)HOS_BUCKET;
fd_info->object = (char *)"object"; fd_info->object = (char *)"object";
fd_info->cache = NULL;
fd_info->cache_count = 10; fd_info->cache_count = 10;
fd_info->cache_rest = g_hos_handle.hos_config.cache_size; fd_info->cache_rest = g_hos_handle.hos_config.cache_size;
fd_info->callback = NULL; fd_info->callback = NULL;
@@ -62,6 +63,10 @@ static void gtest_hos_fd_init(hos_fd_context_t *fd_info)
fd_info->position = 0; fd_info->position = 0;
fd_info->recive_cnt = 0; fd_info->recive_cnt = 0;
fd_info->userdata = NULL; fd_info->userdata = NULL;
fd_info->reslut = false;
fd_info->error = NULL;
fd_info->errorcode = 0;
fd_info->thread_id = 0;
} }
TEST(hos_open_fd, normal) TEST(hos_open_fd, normal)
@@ -78,31 +83,31 @@ TEST(hos_open_fd, normal)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd = 0; size_t fd = 0;
int err = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, &fd); hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, &fd);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[0]); gtest_hos_fd_init(&expect_fd_info[0]);
CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info[0]); CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info[0]);
size_t fd1 = 0; size_t fd1 = 0;
err = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 1, &fd1); hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 1, &fd1);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[1]); gtest_hos_fd_init(&expect_fd_info[1]);
CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]); CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
int ret = hos_close_fd(fd); int ret = hos_close_fd(fd);
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_close_fd(fd1); ret = hos_close_fd(fd1);
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance(); ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = 0; expect_hos_instance.status = 0;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
@@ -133,12 +138,12 @@ TEST(hos_open_fd, paramer_error)
size_t fd = 0; size_t fd = 0;
int err = hos_open_fd(NULL, "object", NULL, NULL, 0, &fd); int err = hos_open_fd(NULL, "object", NULL, NULL, 0, &fd);
EXPECT_EQ(err, HOS_PARAMETER_ERROR); ASSERT_EQ(err, HOS_PARAMETER_ERROR);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_shutdown_instance(); int ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = 0; expect_hos_instance.status = 0;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
@@ -169,12 +174,12 @@ TEST(hos_open_fd, over_threadnums)
size_t fd = 0; size_t fd = 0;
int err = hos_open_fd(HOS_CONF, "object", NULL, NULL, 3, &fd); int err = hos_open_fd(HOS_CONF, "object", NULL, NULL, 3, &fd);
EXPECT_EQ(err, HOS_PARAMETER_ERROR); ASSERT_EQ(err, HOS_PARAMETER_ERROR);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_shutdown_instance(); int ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = 0; expect_hos_instance.status = 0;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
@@ -196,5 +201,5 @@ TEST(hos_open_fd, not_init_instance)
{ {
size_t fd = 0; size_t fd = 0;
int err = hos_open_fd(HOS_CONF, "object", NULL, NULL, 0, &fd); int err = hos_open_fd(HOS_CONF, "object", NULL, NULL, 0, &fd);
EXPECT_EQ(err, HOS_INSTANCE_NOT_ENABLE); ASSERT_EQ(err, HOS_INSTANCE_NOT_ENABLE);
} }

View File

@@ -59,7 +59,6 @@ TEST(hos_shutdown_instance, normal)
{ {
hos_instance_s expect_hos_instance; hos_instance_s expect_hos_instance;
hos_client_handle_t expect_hos_handle; hos_client_handle_t expect_hos_handle;
hos_fd_context_t expect_fd_info;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1); hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1);
gtest_hos_instance_init(&expect_hos_instance); gtest_hos_instance_init(&expect_hos_instance);
@@ -68,7 +67,7 @@ TEST(hos_shutdown_instance, normal)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_shutdown_instance(); int ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = 0; expect_hos_instance.status = 0;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
@@ -89,14 +88,13 @@ TEST(hos_shutdown_instance, normal)
TEST(hos_shutdown_instance, no_init) TEST(hos_shutdown_instance, no_init)
{ {
int ret = hos_shutdown_instance(); int ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_INSTANCE_NOT_INIT); ASSERT_EQ(ret, HOS_INSTANCE_NOT_INIT);
} }
TEST(hos_shutdown_instance, shutdown_more) TEST(hos_shutdown_instance, shutdown_more)
{ {
hos_instance_s expect_hos_instance; hos_instance_s expect_hos_instance;
hos_client_handle_t expect_hos_handle; hos_client_handle_t expect_hos_handle;
hos_fd_context_t expect_fd_info;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1); hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 1);
gtest_hos_instance_init(&expect_hos_instance); gtest_hos_instance_init(&expect_hos_instance);
@@ -105,7 +103,7 @@ TEST(hos_shutdown_instance, shutdown_more)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_shutdown_instance(); int ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = 0; expect_hos_instance.status = 0;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
@@ -123,7 +121,7 @@ TEST(hos_shutdown_instance, shutdown_more)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance(); ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_INSTANCE_NOT_INIT); ASSERT_EQ(ret, HOS_INSTANCE_NOT_INIT);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
} }

View File

@@ -53,29 +53,28 @@ static void gtest_hos_instance_init(hos_instance instance)
static void hos_callback(bool result, const char *bucket, const char *object, const char *error, size_t errorcode, void *userdata) static void hos_callback(bool result, const char *bucket, const char *object, const char *error, size_t errorcode, void *userdata)
{ {
SUCCEED(); SUCCEED();
EXPECT_EQ(result, true); ASSERT_EQ(result, true);
EXPECT_STREQ(bucket, HOS_BUCKET); ASSERT_STREQ(bucket, HOS_BUCKET);
EXPECT_STREQ(object, (char *)userdata); ASSERT_STREQ(object, (char *)userdata);
EXPECT_STREQ(error, NULL); ASSERT_STREQ(error, NULL);
EXPECT_EQ(error, nullptr); ASSERT_EQ(error, nullptr);
EXPECT_EQ(errorcode, 0); ASSERT_EQ(errorcode, 0);
} }
static void hos_bucket_not_exits_cb(bool result, const char *bucket, const char *object, const char *error, size_t errorcode, void *userdata) static void hos_bucket_not_exits_cb(bool result, const char *bucket, const char *object, const char *error, size_t errorcode, void *userdata)
{ {
SUCCEED(); SUCCEED();
EXPECT_EQ(result, false); ASSERT_EQ(result, false);
EXPECT_STREQ(bucket, "bucket_not_exits"); ASSERT_STREQ(bucket, "bucket_not_exits");
EXPECT_STREQ(object, (char *)userdata); ASSERT_STREQ(object, (char *)userdata);
EXPECT_STREQ(error, "The specified bucket does not exist."); ASSERT_STREQ(error, "The specified bucket does not exist.");
EXPECT_EQ(errorcode, NO_SUCH_BUCKET); ASSERT_EQ(errorcode, NO_SUCH_BUCKET);
} }
TEST(hos_upload_buff, normal) TEST(hos_upload_buff, normal)
{ {
hos_instance_s expect_hos_instance; hos_instance_s expect_hos_instance;
hos_client_handle_t expect_hos_handle; hos_client_handle_t expect_hos_handle;
hos_fd_context_t expect_fd_info;
data_info_t *data_info = NULL; data_info_t *data_info = NULL;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2); hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2);
@@ -86,7 +85,7 @@ TEST(hos_upload_buff, normal)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_upload_buf(HOS_BUCKET, "object", HOS_BUFF, strlen(HOS_BUFF), hos_callback, (void *)"object", 0); int ret = hos_upload_buf(HOS_BUCKET, "object", HOS_BUFF, strlen(HOS_BUFF), hos_callback, (void *)"object", 0);
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->rx_bytes[0] += strlen(HOS_BUFF); data_info->rx_bytes[0] += strlen(HOS_BUFF);
data_info->rx_pkts[0] += 1; data_info->rx_pkts[0] += 1;
data_info->tx_bytes[0] += strlen(HOS_BUFF); data_info->tx_bytes[0] += strlen(HOS_BUFF);
@@ -95,7 +94,7 @@ TEST(hos_upload_buff, normal)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance(); ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = 0; expect_hos_instance.status = 0;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
@@ -116,7 +115,6 @@ TEST(hos_upload_buff, bucket_not_exits)
{ {
hos_instance_s expect_hos_instance; hos_instance_s expect_hos_instance;
hos_client_handle_t expect_hos_handle; hos_client_handle_t expect_hos_handle;
hos_fd_context_t expect_fd_info;
data_info_t *data_info = NULL; data_info_t *data_info = NULL;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2); hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2);
@@ -127,7 +125,7 @@ TEST(hos_upload_buff, bucket_not_exits)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_upload_buf("bucket_not_exits", "object", HOS_BUFF, strlen(HOS_BUFF), hos_bucket_not_exits_cb, (void *)"object", 0); int ret = hos_upload_buf("bucket_not_exits", "object", HOS_BUFF, strlen(HOS_BUFF), hos_bucket_not_exits_cb, (void *)"object", 0);
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->rx_bytes[0] += strlen(HOS_BUFF); data_info->rx_bytes[0] += strlen(HOS_BUFF);
data_info->rx_pkts[0] += 1; data_info->rx_pkts[0] += 1;
data_info->tx_failed_bytes[0] += strlen(HOS_BUFF); data_info->tx_failed_bytes[0] += strlen(HOS_BUFF);
@@ -136,7 +134,7 @@ TEST(hos_upload_buff, bucket_not_exits)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance(); ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = 0; expect_hos_instance.status = 0;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
@@ -157,7 +155,6 @@ TEST(hos_upload_buff, param_error)
{ {
hos_instance_s expect_hos_instance; hos_instance_s expect_hos_instance;
hos_client_handle_t expect_hos_handle; hos_client_handle_t expect_hos_handle;
hos_fd_context_t expect_fd_info;
data_info_t *data_info = NULL; data_info_t *data_info = NULL;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2); hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2);
@@ -168,12 +165,12 @@ TEST(hos_upload_buff, param_error)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_upload_buf(NULL, "object", HOS_BUFF, strlen(HOS_BUFF), hos_callback, (void *)"object", 0); int ret = hos_upload_buf(NULL, "object", HOS_BUFF, strlen(HOS_BUFF), hos_callback, (void *)"object", 0);
EXPECT_EQ(ret, HOS_PARAMETER_ERROR); ASSERT_EQ(ret, HOS_PARAMETER_ERROR);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance(); ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = 0; expect_hos_instance.status = 0;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
@@ -193,5 +190,5 @@ TEST(hos_upload_buff, param_error)
TEST(hos_upload_buff, not_init_instance) TEST(hos_upload_buff, not_init_instance)
{ {
int ret = hos_upload_buf(HOS_BUCKET, "object", HOS_BUFF, strlen(HOS_BUFF), hos_callback, (void *)"object", 0); int ret = hos_upload_buf(HOS_BUCKET, "object", HOS_BUFF, strlen(HOS_BUFF), hos_callback, (void *)"object", 0);
EXPECT_EQ(ret, HOS_INSTANCE_NOT_ENABLE); ASSERT_EQ(ret, HOS_INSTANCE_NOT_ENABLE);
} }

View File

@@ -53,29 +53,28 @@ static void gtest_hos_instance_init(hos_instance instance)
static void hos_callback(bool result, const char *bucket, const char *object, const char *error, size_t errorcode, void *userdata) static void hos_callback(bool result, const char *bucket, const char *object, const char *error, size_t errorcode, void *userdata)
{ {
SUCCEED(); SUCCEED();
EXPECT_EQ(result, true); ASSERT_EQ(result, true);
EXPECT_STREQ(bucket, HOS_BUCKET); ASSERT_STREQ(bucket, HOS_BUCKET);
EXPECT_STREQ(object, (char *)userdata); ASSERT_STREQ(object, (char *)userdata);
EXPECT_STREQ(error, NULL); ASSERT_STREQ(error, NULL);
EXPECT_EQ(error, nullptr); ASSERT_EQ(error, nullptr);
EXPECT_EQ(errorcode, 0); ASSERT_EQ(errorcode, 0);
} }
static void hos_bucket_not_exits_cb(bool result, const char *bucket, const char *object, const char *error, size_t errorcode, void *userdata) static void hos_bucket_not_exits_cb(bool result, const char *bucket, const char *object, const char *error, size_t errorcode, void *userdata)
{ {
SUCCEED(); SUCCEED();
EXPECT_EQ(result, false); ASSERT_EQ(result, false);
EXPECT_STREQ(bucket, HOS_CONF); ASSERT_STREQ(bucket, HOS_CONF);
EXPECT_STREQ(object, (char *)userdata); ASSERT_STREQ(object, (char *)userdata);
EXPECT_STREQ(error, "The specified bucket does not exist."); ASSERT_STREQ(error, "The specified bucket does not exist.");
EXPECT_EQ(errorcode, NO_SUCH_BUCKET); ASSERT_EQ(errorcode, NO_SUCH_BUCKET);
} }
TEST(hos_upload_file, normal) TEST(hos_upload_file, normal)
{ {
hos_instance_s expect_hos_instance; hos_instance_s expect_hos_instance;
hos_client_handle_t expect_hos_handle; hos_client_handle_t expect_hos_handle;
hos_fd_context_t expect_fd_info;
data_info_t *data_info = NULL; data_info_t *data_info = NULL;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2); hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2);
@@ -86,7 +85,7 @@ TEST(hos_upload_file, normal)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_upload_file(HOS_BUCKET, HOS_BUFF, hos_callback, (void *)HOS_BUFF, 0); int ret = hos_upload_file(HOS_BUCKET, HOS_BUFF, hos_callback, (void *)HOS_BUFF, 0);
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
struct stat buffer; struct stat buffer;
stat(HOS_BUFF, &buffer); stat(HOS_BUFF, &buffer);
data_info->rx_bytes[0] += buffer.st_size; data_info->rx_bytes[0] += buffer.st_size;
@@ -97,7 +96,7 @@ TEST(hos_upload_file, normal)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance(); ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = 0; expect_hos_instance.status = 0;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
@@ -118,7 +117,6 @@ TEST(hos_upload_file, param_error)
{ {
hos_instance_s expect_hos_instance; hos_instance_s expect_hos_instance;
hos_client_handle_t expect_hos_handle; hos_client_handle_t expect_hos_handle;
hos_fd_context_t expect_fd_info;
data_info_t *data_info = NULL; data_info_t *data_info = NULL;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2); hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2);
@@ -129,12 +127,12 @@ TEST(hos_upload_file, param_error)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_upload_file(NULL, "object", hos_callback, (void *)"object", 0); int ret = hos_upload_file(NULL, "object", hos_callback, (void *)"object", 0);
EXPECT_EQ(ret, HOS_PARAMETER_ERROR); ASSERT_EQ(ret, HOS_PARAMETER_ERROR);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance(); ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = 0; expect_hos_instance.status = 0;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
@@ -155,7 +153,6 @@ TEST(hos_upload_file, file_not_exits)
{ {
hos_instance_s expect_hos_instance; hos_instance_s expect_hos_instance;
hos_client_handle_t expect_hos_handle; hos_client_handle_t expect_hos_handle;
hos_fd_context_t expect_fd_info;
data_info_t *data_info = NULL; data_info_t *data_info = NULL;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2); hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2);
@@ -166,12 +163,12 @@ TEST(hos_upload_file, file_not_exits)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_upload_file(HOS_BUCKET, "file_not_exits", hos_callback, (void *)"object", 0); int ret = hos_upload_file(HOS_BUCKET, "file_not_exits", hos_callback, (void *)"object", 0);
EXPECT_EQ(ret, HOS_FILE_NOT_EXIST); ASSERT_EQ(ret, HOS_FILE_NOT_EXIST);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance(); ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = 0; expect_hos_instance.status = 0;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
@@ -191,14 +188,13 @@ TEST(hos_upload_file, file_not_exits)
TEST(hos_upload_file, not_init_instance) TEST(hos_upload_file, not_init_instance)
{ {
int ret = hos_upload_file(HOS_BUCKET, HOS_BUFF, hos_callback, (void *)"object", 0); int ret = hos_upload_file(HOS_BUCKET, HOS_BUFF, hos_callback, (void *)"object", 0);
EXPECT_EQ(ret, HOS_INSTANCE_NOT_ENABLE); ASSERT_EQ(ret, HOS_INSTANCE_NOT_ENABLE);
} }
TEST(hos_upload_file, bucket_not_exits) TEST(hos_upload_file, bucket_not_exits)
{ {
hos_instance_s expect_hos_instance; hos_instance_s expect_hos_instance;
hos_client_handle_t expect_hos_handle; hos_client_handle_t expect_hos_handle;
hos_fd_context_t expect_fd_info;
data_info_t *data_info = NULL; data_info_t *data_info = NULL;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2); hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_default_conf", 2);
@@ -209,7 +205,7 @@ TEST(hos_upload_file, bucket_not_exits)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_upload_file(HOS_CONF, HOS_CONF, hos_bucket_not_exits_cb, (void *)HOS_CONF, 0); int ret = hos_upload_file(HOS_CONF, HOS_CONF, hos_bucket_not_exits_cb, (void *)HOS_CONF, 0);
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
struct stat buffer; struct stat buffer;
stat(HOS_CONF, &buffer); stat(HOS_CONF, &buffer);
data_info->rx_bytes[0] += buffer.st_size; data_info->rx_bytes[0] += buffer.st_size;
@@ -220,7 +216,7 @@ TEST(hos_upload_file, bucket_not_exits)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance(); ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = 0; expect_hos_instance.status = 0;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);

View File

@@ -53,9 +53,10 @@ static void gtest_hos_instance_init(hos_instance instance)
static void gtest_hos_fd_init(hos_fd_context_t *fd_info) static void gtest_hos_fd_init(hos_fd_context_t *fd_info)
{ {
memset(fd_info, 0, sizeof(hos_fd_context_t)); fd_info->mode = 0;
fd_info->bucket = (char *)HOS_BUCKET; fd_info->bucket = (char *)HOS_BUCKET;
fd_info->object = (char *)"object"; fd_info->object = (char *)"object";
fd_info->cache = NULL;
fd_info->cache_count = 10; fd_info->cache_count = 10;
fd_info->cache_rest = g_hos_handle.hos_config.cache_size; fd_info->cache_rest = g_hos_handle.hos_config.cache_size;
fd_info->callback = NULL; fd_info->callback = NULL;
@@ -64,46 +65,50 @@ static void gtest_hos_fd_init(hos_fd_context_t *fd_info)
fd_info->position = 0; fd_info->position = 0;
fd_info->recive_cnt = 0; fd_info->recive_cnt = 0;
fd_info->userdata = NULL; fd_info->userdata = NULL;
fd_info->reslut = false;
fd_info->error = NULL;
fd_info->errorcode = 0;
fd_info->thread_id = 0;
} }
static void hos_callback(bool result, const char *bucket, const char *object, const char *error, size_t errorcode, void *userdata) static void hos_callback(bool result, const char *bucket, const char *object, const char *error, size_t errorcode, void *userdata)
{ {
SUCCEED(); SUCCEED();
EXPECT_EQ(result, true); ASSERT_EQ(result, true);
EXPECT_STREQ(bucket, HOS_BUCKET); ASSERT_STREQ(bucket, HOS_BUCKET);
EXPECT_STREQ(object, (char *)userdata); ASSERT_STREQ(object, (char *)userdata);
EXPECT_STREQ(error, NULL); ASSERT_STREQ(error, NULL);
EXPECT_EQ(errorcode, 0); ASSERT_EQ(errorcode, 0);
} }
static void hos_write_buff_cb(bool result, const char *bucket, const char *object, const char *error, size_t errorcode, void *userdata) static void hos_write_buff_cb(bool result, const char *bucket, const char *object, const char *error, size_t errorcode, void *userdata)
{ {
SUCCEED(); SUCCEED();
EXPECT_EQ(result, true); ASSERT_EQ(result, true);
EXPECT_STREQ(bucket, HOS_BUCKET); ASSERT_STREQ(bucket, HOS_BUCKET);
EXPECT_STREQ(object, (char *)userdata); ASSERT_STREQ(object, (char *)userdata);
EXPECT_STREQ(error, NULL); ASSERT_STREQ(error, NULL);
EXPECT_EQ(errorcode, 0); ASSERT_EQ(errorcode, 0);
} }
static void hos_write_append_cb(bool result, const char *bucket, const char *object, const char *error, size_t errorcode, void *userdata) static void hos_write_append_cb(bool result, const char *bucket, const char *object, const char *error, size_t errorcode, void *userdata)
{ {
SUCCEED(); SUCCEED();
EXPECT_EQ(result, true); ASSERT_EQ(result, true);
EXPECT_STREQ(bucket, HOS_BUCKET); ASSERT_STREQ(bucket, HOS_BUCKET);
EXPECT_STREQ(object, (char *)userdata); ASSERT_STREQ(object, (char *)userdata);
EXPECT_STREQ(error, NULL); ASSERT_STREQ(error, NULL);
EXPECT_EQ(errorcode, 0); ASSERT_EQ(errorcode, 0);
} }
static void hos_bucket_not_exits_cb(bool result, const char *bucket, const char *object, const char *error, size_t errorcode, void *userdata) static void hos_bucket_not_exits_cb(bool result, const char *bucket, const char *object, const char *error, size_t errorcode, void *userdata)
{ {
SUCCEED(); SUCCEED();
EXPECT_EQ(result, false); ASSERT_EQ(result, false);
EXPECT_STREQ(bucket, "bucket_not_exits"); ASSERT_STREQ(bucket, "bucket_not_exits");
EXPECT_STREQ(object, (char *)userdata); ASSERT_STREQ(object, (char *)userdata);
EXPECT_STREQ(error, "The specified bucket does not exist."); ASSERT_STREQ(error, "The specified bucket does not exist.");
EXPECT_EQ(errorcode, NO_SUCH_BUCKET); ASSERT_EQ(errorcode, NO_SUCH_BUCKET);
} }
TEST(hos_write, normal) TEST(hos_write, normal)
@@ -122,7 +127,7 @@ TEST(hos_write, normal)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd = 0; size_t fd = 0;
int err = hos_open_fd(HOS_BUCKET, "object_buff", hos_write_buff_cb, (void *)"object_buff", 0, &fd); hos_open_fd(HOS_BUCKET, "object_buff", hos_write_buff_cb, (void *)"object_buff", 0, &fd);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[0]); gtest_hos_fd_init(&expect_fd_info[0]);
@@ -132,7 +137,7 @@ TEST(hos_write, normal)
CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info[0]); CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info[0]);
int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF)); int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF));
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_fd_info[0].fd_status = 2; expect_fd_info[0].fd_status = 2;
data_info->rx_bytes[0] += strlen(HOS_BUFF); data_info->rx_bytes[0] += strlen(HOS_BUFF);
data_info->rx_pkts[0] +=1; data_info->rx_pkts[0] +=1;
@@ -142,7 +147,7 @@ TEST(hos_write, normal)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd1 = 0; size_t fd1 = 0;
err = hos_open_fd(HOS_BUCKET, "object_append", hos_write_append_cb, (void *)"object_append", 1, &fd1); hos_open_fd(HOS_BUCKET, "object_append", hos_write_append_cb, (void *)"object_append", 1, &fd1);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[1]); gtest_hos_fd_init(&expect_fd_info[1]);
@@ -152,7 +157,7 @@ TEST(hos_write, normal)
CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]); CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF)); ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF));
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->rx_bytes[1] += strlen(HOS_BUFF); data_info->rx_bytes[1] += strlen(HOS_BUFF);
data_info->rx_pkts[1] +=1; data_info->rx_pkts[1] +=1;
data_info->cache[1] += strlen(HOS_BUFF); data_info->cache[1] += strlen(HOS_BUFF);
@@ -161,10 +166,10 @@ TEST(hos_write, normal)
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF); expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
expect_fd_info[1].cache_count--; expect_fd_info[1].cache_count--;
CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]); CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
EXPECT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL); ASSERT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF)); ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF));
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->rx_bytes[1] += strlen(HOS_BUFF); data_info->rx_bytes[1] += strlen(HOS_BUFF);
data_info->rx_pkts[1] +=1; data_info->rx_pkts[1] +=1;
data_info->cache[1] += strlen(HOS_BUFF); data_info->cache[1] += strlen(HOS_BUFF);
@@ -173,18 +178,18 @@ TEST(hos_write, normal)
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF); expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
expect_fd_info[1].cache_count--; expect_fd_info[1].cache_count--;
CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]); CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
EXPECT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL); ASSERT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL);
ret = hos_close_fd(fd); ret = hos_close_fd(fd);
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->tx_bytes[0] += data_info->cache[0]; data_info->tx_bytes[0] += data_info->cache[0];
data_info->tx_pkts[0] += 1; data_info->tx_pkts[0] += 1;
data_info->cache[0] = 0; data_info->cache[0] = 0;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_close_fd(fd1); ret = hos_close_fd(fd1);
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->tx_bytes[1] += data_info->cache[1]; data_info->tx_bytes[1] += data_info->cache[1];
data_info->tx_pkts[1] += 1; data_info->tx_pkts[1] += 1;
data_info->cache[1] = 0; data_info->cache[1] = 0;
@@ -192,7 +197,7 @@ TEST(hos_write, normal)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance(); ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = 0; expect_hos_instance.status = 0;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
@@ -225,7 +230,7 @@ TEST(hos_write, bucket_not_exits)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd = 0; size_t fd = 0;
int err = hos_open_fd("bucket_not_exits", "object_buff", hos_bucket_not_exits_cb, (void *)"object_buff", 0, &fd); hos_open_fd("bucket_not_exits", "object_buff", hos_bucket_not_exits_cb, (void *)"object_buff", 0, &fd);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[0]); gtest_hos_fd_init(&expect_fd_info[0]);
@@ -236,7 +241,7 @@ TEST(hos_write, bucket_not_exits)
CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info[0]); CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info[0]);
int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF)); int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF));
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->rx_bytes[0] = strlen(HOS_BUFF); data_info->rx_bytes[0] = strlen(HOS_BUFF);
data_info->rx_pkts[0] += 1; data_info->rx_pkts[0] += 1;
data_info->cache[0] = strlen(HOS_BUFF); data_info->cache[0] = strlen(HOS_BUFF);
@@ -244,7 +249,7 @@ TEST(hos_write, bucket_not_exits)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd1 = 0; size_t fd1 = 0;
err = hos_open_fd("bucket_not_exits", "object_append", hos_bucket_not_exits_cb, (void *)"object_append", 1, &fd1); hos_open_fd("bucket_not_exits", "object_append", hos_bucket_not_exits_cb, (void *)"object_append", 1, &fd1);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[1]); gtest_hos_fd_init(&expect_fd_info[1]);
@@ -255,7 +260,7 @@ TEST(hos_write, bucket_not_exits)
CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]); CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF)); ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF));
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->cache[1] += strlen(HOS_BUFF); data_info->cache[1] += strlen(HOS_BUFF);
data_info->rx_bytes[1] += strlen(HOS_BUFF); data_info->rx_bytes[1] += strlen(HOS_BUFF);
data_info->rx_pkts[1] += 1; data_info->rx_pkts[1] += 1;
@@ -264,10 +269,10 @@ TEST(hos_write, bucket_not_exits)
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF); expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
expect_fd_info[1].cache_count--; expect_fd_info[1].cache_count--;
CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]); CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
EXPECT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL); ASSERT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF)); ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF));
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->cache[1] += strlen(HOS_BUFF); data_info->cache[1] += strlen(HOS_BUFF);
data_info->rx_bytes[1] += strlen(HOS_BUFF); data_info->rx_bytes[1] += strlen(HOS_BUFF);
data_info->rx_pkts[1] += 1; data_info->rx_pkts[1] += 1;
@@ -276,17 +281,17 @@ TEST(hos_write, bucket_not_exits)
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF); expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
expect_fd_info[1].cache_count--; expect_fd_info[1].cache_count--;
CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]); CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
EXPECT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL); ASSERT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL);
ret = hos_close_fd(fd); ret = hos_close_fd(fd);
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->tx_failed_bytes[0] += data_info->cache[0]; data_info->tx_failed_bytes[0] += data_info->cache[0];
data_info->tx_failed_pkts[0] += 1; data_info->tx_failed_pkts[0] += 1;
data_info->cache[0] = 0; data_info->cache[0] = 0;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_close_fd(fd1); ret = hos_close_fd(fd1);
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->tx_failed_bytes[1] += data_info->cache[1]; data_info->tx_failed_bytes[1] += data_info->cache[1];
data_info->tx_failed_pkts[1] += 1; data_info->tx_failed_pkts[1] += 1;
data_info->cache[1] = 0; data_info->cache[1] = 0;
@@ -294,7 +299,7 @@ TEST(hos_write, bucket_not_exits)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance(); ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = 0; expect_hos_instance.status = 0;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
@@ -328,7 +333,7 @@ TEST(hos_write, sync_mode)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd = 0; size_t fd = 0;
int err = hos_open_fd(HOS_BUCKET, "object_buff", NULL, NULL, 0, &fd); hos_open_fd(HOS_BUCKET, "object_buff", NULL, NULL, 0, &fd);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[0]); gtest_hos_fd_init(&expect_fd_info[0]);
@@ -336,7 +341,7 @@ TEST(hos_write, sync_mode)
CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info[0]); CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info[0]);
int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF)); int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF));
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->rx_bytes[0] += strlen(HOS_BUFF); data_info->rx_bytes[0] += strlen(HOS_BUFF);
data_info->rx_pkts[0] += 1; data_info->rx_pkts[0] += 1;
data_info->cache[0] += strlen(HOS_BUFF); data_info->cache[0] += strlen(HOS_BUFF);
@@ -344,7 +349,7 @@ TEST(hos_write, sync_mode)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd1 = 0; size_t fd1 = 0;
err = hos_open_fd(HOS_BUCKET, "object_append", NULL, NULL, 1, &fd1); hos_open_fd(HOS_BUCKET, "object_append", NULL, NULL, 1, &fd1);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[1]); gtest_hos_fd_init(&expect_fd_info[1]);
@@ -352,7 +357,7 @@ TEST(hos_write, sync_mode)
CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]); CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF)); ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF));
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->rx_bytes[1] += strlen(HOS_BUFF); data_info->rx_bytes[1] += strlen(HOS_BUFF);
data_info->rx_pkts[1] += 1; data_info->rx_pkts[1] += 1;
data_info->cache[1] += strlen(HOS_BUFF); data_info->cache[1] += strlen(HOS_BUFF);
@@ -361,10 +366,10 @@ TEST(hos_write, sync_mode)
expect_fd_info[1].cache_count--; expect_fd_info[1].cache_count--;
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF); expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]); CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
EXPECT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL); ASSERT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF)); ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF));
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->rx_bytes[1] += strlen(HOS_BUFF); data_info->rx_bytes[1] += strlen(HOS_BUFF);
data_info->rx_pkts[1] += 1; data_info->rx_pkts[1] += 1;
data_info->cache[1] += strlen(HOS_BUFF); data_info->cache[1] += strlen(HOS_BUFF);
@@ -373,17 +378,17 @@ TEST(hos_write, sync_mode)
expect_fd_info[1].cache_count--; expect_fd_info[1].cache_count--;
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF); expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]); CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
EXPECT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL); ASSERT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL);
ret = hos_close_fd(fd); ret = hos_close_fd(fd);
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->tx_bytes[0] += data_info->cache[0]; data_info->tx_bytes[0] += data_info->cache[0];
data_info->tx_pkts[0] += 1; data_info->tx_pkts[0] += 1;
data_info->cache[0] = 0; data_info->cache[0] = 0;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_close_fd(fd1); ret = hos_close_fd(fd1);
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->tx_bytes[1] += data_info->cache[1]; data_info->tx_bytes[1] += data_info->cache[1];
data_info->tx_pkts[1] += 1; data_info->tx_pkts[1] += 1;
data_info->cache[1] = 0; data_info->cache[1] = 0;
@@ -391,7 +396,7 @@ TEST(hos_write, sync_mode)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance(); ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = 0; expect_hos_instance.status = 0;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
@@ -425,7 +430,7 @@ TEST(hos_write, sync_mode_bucket_not_exits)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd = 0; size_t fd = 0;
int err = hos_open_fd(HOS_CONF, "object_buff", NULL, NULL, 0, &fd); hos_open_fd(HOS_CONF, "object_buff", NULL, NULL, 0, &fd);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[0]); gtest_hos_fd_init(&expect_fd_info[0]);
@@ -434,7 +439,7 @@ TEST(hos_write, sync_mode_bucket_not_exits)
CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info[0]); CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info[0]);
int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF)); int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF));
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_fd_info[0].fd_status = 2; expect_fd_info[0].fd_status = 2;
data_info->rx_bytes[0] += strlen(HOS_BUFF); data_info->rx_bytes[0] += strlen(HOS_BUFF);
data_info->rx_pkts[0] += 1; data_info->rx_pkts[0] += 1;
@@ -443,7 +448,7 @@ TEST(hos_write, sync_mode_bucket_not_exits)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd1 = 0; size_t fd1 = 0;
err = hos_open_fd(HOS_CONF, "object_append", NULL, NULL, 1, &fd1); hos_open_fd(HOS_CONF, "object_append", NULL, NULL, 1, &fd1);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[1]); gtest_hos_fd_init(&expect_fd_info[1]);
@@ -452,7 +457,7 @@ TEST(hos_write, sync_mode_bucket_not_exits)
CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]); CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF)); ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF));
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->rx_bytes[1] += strlen(HOS_BUFF); data_info->rx_bytes[1] += strlen(HOS_BUFF);
data_info->rx_pkts[1] += 1; data_info->rx_pkts[1] += 1;
data_info->cache[1] += strlen(HOS_BUFF); data_info->cache[1] += strlen(HOS_BUFF);
@@ -461,10 +466,10 @@ TEST(hos_write, sync_mode_bucket_not_exits)
expect_fd_info[1].cache_count--; expect_fd_info[1].cache_count--;
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF); expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]); CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
EXPECT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL); ASSERT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL);
ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF)); ret = hos_write(fd1, HOS_BUFF, strlen(HOS_BUFF));
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->rx_bytes[1] += strlen(HOS_BUFF); data_info->rx_bytes[1] += strlen(HOS_BUFF);
data_info->rx_pkts[1] += 1; data_info->rx_pkts[1] += 1;
data_info->cache[1] += strlen(HOS_BUFF); data_info->cache[1] += strlen(HOS_BUFF);
@@ -473,17 +478,17 @@ TEST(hos_write, sync_mode_bucket_not_exits)
expect_fd_info[1].cache_count--; expect_fd_info[1].cache_count--;
expect_fd_info[1].cache_rest -= strlen(HOS_BUFF); expect_fd_info[1].cache_rest -= strlen(HOS_BUFF);
CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]); CheckStructGHosFdContext((hos_fd_context_t *)fd1, &expect_fd_info[1]);
EXPECT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL); ASSERT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL);
ret = hos_close_fd(fd); ret = hos_close_fd(fd);
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->tx_failed_bytes[0] += data_info->cache[0]; data_info->tx_failed_bytes[0] += data_info->cache[0];
data_info->tx_failed_pkts[0] += 1; data_info->tx_failed_pkts[0] += 1;
data_info->cache[0] = 0; data_info->cache[0] = 0;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_close_fd(fd1); ret = hos_close_fd(fd1);
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->tx_failed_bytes[1] += data_info->cache[1]; data_info->tx_failed_bytes[1] += data_info->cache[1];
data_info->tx_failed_pkts[1] += 1; data_info->tx_failed_pkts[1] += 1;
data_info->cache[1] = 0; data_info->cache[1] = 0;
@@ -491,7 +496,7 @@ TEST(hos_write, sync_mode_bucket_not_exits)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance(); ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = 0; expect_hos_instance.status = 0;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
@@ -522,7 +527,7 @@ TEST(hos_write, paramer_error)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd = 0; size_t fd = 0;
int err = hos_open_fd(HOS_BUCKET, "object_buff", hos_callback, NULL, 0, &fd); hos_open_fd(HOS_BUCKET, "object_buff", hos_callback, NULL, 0, &fd);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info); gtest_hos_fd_init(&expect_fd_info);
@@ -531,12 +536,12 @@ TEST(hos_write, paramer_error)
CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info); CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info);
int ret = hos_write(fd, NULL, strlen(HOS_BUFF)); int ret = hos_write(fd, NULL, strlen(HOS_BUFF));
EXPECT_EQ(ret, HOS_PARAMETER_ERROR); ASSERT_EQ(ret, HOS_PARAMETER_ERROR);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance(); ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = 0; expect_hos_instance.status = 0;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
@@ -569,12 +574,12 @@ TEST(hos_write, fd_not_find)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
int ret = hos_write(3, HOS_BUFF, strlen(HOS_CONF), 0); int ret = hos_write(3, HOS_BUFF, strlen(HOS_CONF), 0);
EXPECT_EQ(ret, HOS_HASH_NOT_FIND); ASSERT_EQ(ret, HOS_HASH_NOT_FIND);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance(); ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = 0; expect_hos_instance.status = 0;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
@@ -607,7 +612,7 @@ TEST(hos_write, over_threadnums)
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd = 0; size_t fd = 0;
int err = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, &fd); hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, &fd);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info); gtest_hos_fd_init(&expect_fd_info);
@@ -615,12 +620,12 @@ TEST(hos_write, over_threadnums)
CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info); CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info);
int ret = hos_write(fd, NULL, strlen(HOS_CONF)); int ret = hos_write(fd, NULL, strlen(HOS_CONF));
EXPECT_EQ(ret, HOS_PARAMETER_ERROR); ASSERT_EQ(ret, HOS_PARAMETER_ERROR);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance(); ret = hos_shutdown_instance();
EXPECT_EQ(ret, HOS_CLIENT_OK); ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = 0; expect_hos_instance.status = 0;
expect_hos_instance.hos_url_prefix = NULL; expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
@@ -641,7 +646,7 @@ TEST(hos_write, over_threadnums)
TEST(hos_write, not_init_instance) TEST(hos_write, not_init_instance)
{ {
int ret = hos_write(3, HOS_BUFF, strlen(HOS_CONF)); int ret = hos_write(3, HOS_BUFF, strlen(HOS_CONF));
EXPECT_EQ(ret, HOS_INSTANCE_NOT_ENABLE); ASSERT_EQ(ret, HOS_INSTANCE_NOT_ENABLE);
} }
static void read_file(char *path, char **content, int *len) static void read_file(char *path, char **content, int *len)
@@ -675,7 +680,6 @@ static void *hos_function(void *ptr)
hos_fd_context_t expect_fd_info[32][20]; hos_fd_context_t expect_fd_info[32][20];
int thread_num = 32; int thread_num = 32;
data_info_t *data_info = NULL; data_info_t *data_info = NULL;
int err = 0;
{ {
hos_instance = hos_get_instance(); hos_instance = hos_get_instance();
@@ -693,8 +697,8 @@ static void *hos_function(void *ptr)
for (i = 0; i < HOS_FD_NUMS_LOCAL; i++) for (i = 0; i < HOS_FD_NUMS_LOCAL; i++)
{ {
snprintf(object[i], 1024, "object_%lu_%d", thread_id, i); snprintf(object[i], 1024, "object_%zu_%d", thread_id, i);
err = hos_open_fd(HOS_BUCKET, object[i], hos_callback, object[i], 0, &fd[i]); int err = hos_open_fd(HOS_BUCKET, object[i], hos_callback, object[i], 0, &fd[i]);
EXPECT_EQ(err, i + 1); EXPECT_EQ(err, i + 1);
CheckHosInstance(hos_instance, &expect_hos_instance); CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);

View File

@@ -20,22 +20,6 @@ if (HOS_MESA_LOG)
add_definitions(-DHOS_MESA_LOG) add_definitions(-DHOS_MESA_LOG)
endif() endif()
find_program(CMAKE_CXX_CPPCHECK NAMES cppcheck)
if (CMAKE_CXX_CPPCHECK)
list(
APPEND CMAKE_CXX_CPPCHECK
"--enable=all"
"--error-exitcode=1"
"--suppress=unusedFunction"
"--suppress=missingInclude"
"--suppress=uselessAssignmentPtrArg"
"--suppress=unmatchedSuppression"
)
set(CMAKE_C_CPPCHECK ${CMAKE_CXX_CPPCHECK})
else()
message(FATAL_ERROR "Could not find the program cppcheck.")
endif()
file(GLOB HOS_SRC file(GLOB HOS_SRC
${HOS_SOURCE} ${HOS_SOURCE}
${HOS_HEADERS} ${HOS_HEADERS}

View File

@@ -22,3 +22,20 @@ ExternalProject_Add(aws-sdk-cpp-master
add_dependencies(aws-sdk-cpp-master-static aws-sdk-cpp-master) add_dependencies(aws-sdk-cpp-master-static aws-sdk-cpp-master)
set_property(TARGET aws-sdk-cpp-master-static PROPERTY IMPORTED_LOCATION ${SUPPORT_INSTALL_PREFIX}) set_property(TARGET aws-sdk-cpp-master-static PROPERTY IMPORTED_LOCATION ${SUPPORT_INSTALL_PREFIX})
#### GoogleTest
ExternalProject_Add(GoogleTest
PREFIX GoogleTest
URL ${CMAKE_CURRENT_SOURCE_DIR}/googletest-release-1.8.0.tar.gz
URL_MD5 16877098823401d1bf2ed7891d7dce36
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DBUILD_SHARED_LIBS=ON)
ExternalProject_Get_Property(GoogleTest INSTALL_DIR)
file(MAKE_DIRECTORY ${INSTALL_DIR}/include)
add_library(gtest SHARED IMPORTED GLOBAL)
add_dependencies(gtest GoogleTest)
set_property(TARGET gtest PROPERTY IMPORTED_LOCATION ${INSTALL_DIR}/lib/libgtest.so)
#set_property(TARGET gtest PROPERTY IMPORTED_LOCATION ${INSTALL_DIR}/lib/libgtest_main.so)
set_property(TARGET gtest PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include)
set_property(TARGET gtest PROPERTY INTERFACE_LINK_LIBRARIES pthread)

Binary file not shown.