parent
fbe5ddc560
commit
60eda95739
|
@ -1,5 +1,10 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR)
|
||||
INCLUDE(depend/system_libs.cmake)
|
||||
|
||||
LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/depend)
|
||||
IF (BUILD_TESTING)
|
||||
INCLUDE(doctest_framework)
|
||||
ENDIF ()
|
||||
INCLUDE(system_libs)
|
||||
|
||||
SET(VCPE_VERSION "1.0.1")
|
||||
PROJECT(vCPE VERSION "${VCPE_VERSION}")
|
||||
|
@ -9,7 +14,7 @@ OPTION(USED_LWIP "PPPoE of LWIP support for vCPE" OFF)
|
|||
OPTION(USED_OPENDHCPD "DHCP server for vCPE" OFF)
|
||||
OPTION(USED_OPENDHCPDDNS "DHCP And DNS server for vCPE" OFF)
|
||||
OPTION(USED_USER_VNI "Support pass user vni id from console command line" OFF)
|
||||
option(BUILD_TESTING "Enable tests" OFF)
|
||||
OPTION(BUILD_TESTING "Enable tests" OFF)
|
||||
|
||||
# 数据库开关
|
||||
OPTION(USED_REDIS "Add redis database support for vCPE" OFF)
|
||||
|
@ -113,6 +118,5 @@ ADD_SUBDIRECTORY(srcs/libs)
|
|||
ADD_SUBDIRECTORY(srcs/httpserver)
|
||||
|
||||
IF (BUILD_TESTING)
|
||||
ADD_SUBDIRECTORY(test)
|
||||
ADD_SUBDIRECTORY(srcs/libs/unit_test)
|
||||
ADD_SUBDIRECTORY(unit_test)
|
||||
ENDIF ()
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,18 @@
|
|||
CMAKE_MINIMUM_REQUIRED(VERSION 3.14 FATAL_ERROR)
|
||||
INCLUDE(FetchContent)
|
||||
|
||||
IF (BUILD_TESTING)
|
||||
FETCHCONTENT_DECLARE(doctest_framework
|
||||
URL file://${CMAKE_SOURCE_DIR}/depend/doctest-2.4.9.tar.gz
|
||||
URL_MD5 a7948b5ec1f69de6f84c7d7487aaf79b)
|
||||
FETCHCONTENT_MAKEAVAILABLE(doctest_framework)
|
||||
|
||||
FETCHCONTENT_GETPROPERTIES(doctest_framework)
|
||||
IF (NOT doctest_framework_POPULATED)
|
||||
FETCHCONTENT_POPULATE(doctest_framework)
|
||||
ADD_SUBDIRECTORY(${doctest_framework_SOURCE_DIR})
|
||||
ENDIF ()
|
||||
|
||||
INCLUDE_DIRECTORIES(${doctest_framework_SOURCE_DIR}/doctest)
|
||||
LIST(APPEND CMAKE_MODULE_PATH ${doctest_framework_SOURCE_DIR}/scripts/cmake)
|
||||
ENDIF ()
|
|
@ -68,9 +68,9 @@ ADD_CUSTOM_COMMAND(TARGET ${PROJECT_TARGET}
|
|||
COMMENT "!!!!!! Notice: Automatic upgreade configuration files after build project."
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/config/"
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/log/"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${PROJECT_SOURCE_DIR}/../config/zlog.conf" "${CMAKE_CURRENT_BINARY_DIR}/config/"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${PROJECT_SOURCE_DIR}/../config/vcpe.cfg" "${CMAKE_CURRENT_BINARY_DIR}/config/"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${PROJECT_SOURCE_DIR}/../config/banner.txt" "${CMAKE_CURRENT_BINARY_DIR}/config/")
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/config/zlog.conf" "${CMAKE_CURRENT_BINARY_DIR}/config/"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/config/vcpe.cfg" "${CMAKE_CURRENT_BINARY_DIR}/config/"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_SOURCE_DIR}/config/banner.txt" "${CMAKE_CURRENT_BINARY_DIR}/config/")
|
||||
|
||||
SET(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install/")
|
||||
INSTALL(FILES ../config/vcpe.cfg ../config/vcpe@.service ../config/banner.txt ../config/zlog.conf
|
||||
|
|
|
@ -83,9 +83,6 @@ typedef enum {
|
|||
CONFIG_ITEM_ID_MAX
|
||||
} CONFIG_ITEM_ID;
|
||||
|
||||
const char *get_cur_process_dir();
|
||||
const char *get_cur_process_name();
|
||||
|
||||
const char *config_get_ssl_ca_path();
|
||||
const char *cfg_get_config_directory();
|
||||
int cfg_get_banner_enable();
|
||||
|
|
|
@ -44,6 +44,8 @@ extern "C" {
|
|||
|
||||
#define DEBUG_CODE_LINE() (dzlog_debug("\n"))
|
||||
|
||||
const char *get_cur_process_dir();
|
||||
const char *get_cur_process_name();
|
||||
int file_exists(const char *pPath);
|
||||
const char *basename_v2(const char *path);
|
||||
int dirname_v2(const char *path, char *dir);
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
typedef unsigned char uuid_t[16];
|
||||
#define UUID_BYTES (16)
|
||||
typedef unsigned char uuid_t[UUID_BYTES];
|
||||
|
||||
#define uuid_generate(out) uuid_generate_random(out)
|
||||
|
||||
|
|
|
@ -94,8 +94,8 @@ char *bin2hex(char *p, const unsigned char *cp, unsigned int count) {
|
|||
while (count) {
|
||||
unsigned char c = *cp++;
|
||||
/* put lowercase hex digits */
|
||||
*p++ = (char)(0x20 | hex_asc[c >> 4]);
|
||||
*p++ = (char)(0x20 | hex_asc[c & 0xf]);
|
||||
*p++ = (char)(0x20 | hex_asc[c >> 4]);
|
||||
*p++ = (char)(0x20 | hex_asc[c & 0xf]);
|
||||
count--;
|
||||
}
|
||||
|
||||
|
@ -245,7 +245,11 @@ int get_nic_info(const char *pName,
|
|||
}
|
||||
|
||||
const char *get_cur_process_name() {
|
||||
static char g_exeName[1024];
|
||||
static char g_exeName[1024] = {0};
|
||||
|
||||
if (strlen(g_exeName) > 0) {
|
||||
return basename_v2(g_exeName);
|
||||
}
|
||||
|
||||
memset(g_exeName, 0, 1024);
|
||||
if (readlink("/proc/self/exe", g_exeName, 1023) <= 0) {
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
PROJECT(libcommon_utest)
|
||||
|
||||
INCLUDE_DIRECTORIES(./ ../include ../../include ../../../test)
|
||||
|
||||
AUX_SOURCE_DIRECTORY(misc UTEST_SRC)
|
||||
|
||||
ADD_EXECUTABLE(${PROJECT_NAME} ${UTEST_SRC})
|
||||
TARGET_LINK_LIBRARIES(${PROJECT_NAME} common)
|
|
@ -1,29 +0,0 @@
|
|||
//
|
||||
// Created by xajhuang on 2023/1/31.
|
||||
//
|
||||
// provides main(); this line is required in only one .cpp file
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "doctest.h"
|
||||
|
||||
#include "uuid.h"
|
||||
|
||||
TEST_SUITE("Miscellaneous functions") {
|
||||
TEST_CASE("UUID test") {
|
||||
uuid_t msgId;
|
||||
char strMsgId[64];
|
||||
|
||||
memset(msgId, 0, sizeof(msgId));
|
||||
memset(strMsgId, 0, 64);
|
||||
|
||||
uuid_generate_random(msgId);
|
||||
|
||||
for (int i = 0; i < sizeof(msgId); i++) {
|
||||
CHECK_NE(msgId[0], 0);
|
||||
}
|
||||
|
||||
uuid_unparse(msgId, strMsgId);
|
||||
CHECK_EQ(strlen(strMsgId), 36);
|
||||
|
||||
INFO("Random UUID: ", strMsgId);
|
||||
}
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
PROJECT(vcpe_utest)
|
||||
|
||||
INCLUDE_DIRECTORIES(./ ../srcs/include ../srcs/libs/include)
|
7019
test/doctest.h
7019
test/doctest.h
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,15 @@
|
|||
PROJECT(libcommon_utest)
|
||||
|
||||
INCLUDE_DIRECTORIES(. ${CMAKE_SOURCE_DIR}/srcs/include ${CMAKE_SOURCE_DIR}/srcs/libs/include)
|
||||
|
||||
AUX_SOURCE_DIRECTORY(misc UTEST_SRC)
|
||||
|
||||
ADD_DEFINITIONS(-DPROJECT_NAME="${PROJECT_NAME}")
|
||||
|
||||
ADD_EXECUTABLE(${PROJECT_NAME} ${UTEST_SRC})
|
||||
|
||||
TARGET_LINK_LIBRARIES(${PROJECT_NAME} common)
|
||||
|
||||
#INCLUDE(CTest)
|
||||
#INCLUDE(doctest)
|
||||
#doctest_discover_tests(${PROJECT_NAME})
|
|
@ -0,0 +1,13 @@
|
|||
//
|
||||
// Created by xajhuang on 2023/2/1.
|
||||
//
|
||||
#include "doctest.h"
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
TEST_SUITE("Miscellaneous functions") {
|
||||
TEST_CASE("GetProcessName") {
|
||||
const char *processName = get_cur_process_name();
|
||||
CHECK_EQ(doctest::String(processName), PROJECT_NAME);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
//
|
||||
// Created by xajhuang on 2023/1/31.
|
||||
//
|
||||
// provides main(); this line is required in only one .cpp file
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "doctest.h"
|
||||
|
||||
#include "uuid.h"
|
||||
|
||||
TEST_SUITE("Miscellaneous functions") {
|
||||
TEST_CASE("UUID TEST") {
|
||||
int i;
|
||||
uuid_t msgId;
|
||||
memset(msgId, 0, sizeof(msgId));
|
||||
uuid_generate_random(msgId);
|
||||
|
||||
SUBCASE("Generate UUID") {
|
||||
unsigned int sum = 0;
|
||||
for (i = 0; i < UUID_BYTES; i++) {
|
||||
sum += msgId[i];
|
||||
}
|
||||
REQUIRE_NE(sum, 0);
|
||||
}
|
||||
|
||||
SUBCASE("UUID String") {
|
||||
char strMsgId[64];
|
||||
memset(strMsgId, 0, 64);
|
||||
|
||||
uuid_unparse(msgId, strMsgId);
|
||||
REQUIRE_MESSAGE((strlen(strMsgId) == 36), "UUID:", strMsgId);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue