diff --git a/confingure/prase_config.c b/confingure/prase_config.c index e2577fd..670dd28 100644 --- a/confingure/prase_config.c +++ b/confingure/prase_config.c @@ -22,6 +22,16 @@ static pthread_t g_monThreadId; static ZTP_CONFIG g_ztpInfo; static DEVICE_CONFIG g_devInfo; +PZTP_CONFIG get_ztp_configure(void) +{ + return &g_ztpInfo; +} + +PDEVICE_CONFIG get_device_configure(void) +{ + return &g_devInfo; +} + static void __init_dev_config(PDEVICE_CONFIG pCfg) { int i; diff --git a/include/ztp_config.h b/include/ztp_config.h index 8bea7af..d04ef61 100644 --- a/include/ztp_config.h +++ b/include/ztp_config.h @@ -90,4 +90,7 @@ double cfg_get_float_value(config_t *pCfg, const char *pTags, double defValue); int cfg_get_array_int_value(config_t *pCfg, const char *pTags, int *pArray, int *pMaxItem); int load_dev_config(const char *devId); + +PZTP_CONFIG get_ztp_configure(void); +PDEVICE_CONFIG get_device_configure(void); #endif //ZTP_CLIENT_ZTP_CONFIG_H diff --git a/unit_test/test/configure_test.cpp b/unit_test/test/configure_test.cpp new file mode 100644 index 0000000..a8b7575 --- /dev/null +++ b/unit_test/test/configure_test.cpp @@ -0,0 +1,49 @@ +// +// Created by xajhu on 2019/12/3 0003. +// +#include + +using namespace std; + +#include "gtest/gtest.h" + +extern "C" { +#include "err_code.h" +#include "ztp_config.h" +} + +TEST(config_file_test, ztpConfig) +{ + int ret = init_configure("../../ztp.conf"); + ASSERT_EQ(ERR_OK, ret); + + + PZTP_CONFIG pZtpCfg = get_ztp_configure(); + + + ASSERT_STREQ(pZtpCfg->svr_cfg.server_url, "cmhi.ztp.com"); + ASSERT_STREQ(pZtpCfg->dev_dir, "dev_confs"); + ASSERT_EQ(10082, pZtpCfg->svr_cfg.port); +} + +TEST(config_file_test, devConfig) +{ + int ret = init_configure("../../ztp.conf"); + ASSERT_EQ(ERR_OK, ret); + + ret = load_dev_config("ace08484843"); + ASSERT_EQ(ERR_OK, ret); + + PDEVICE_CONFIG pDevCfg = get_device_configure(); + + ASSERT_EQ(pDevCfg->port_cfg[0].port_type, WAN_PORT); + ASSERT_EQ(pDevCfg->port_cfg[0].port_protocol, DHCP_TYPE); + + ASSERT_EQ(pDevCfg->port_cfg[1].port_type, WAN_PORT); + ASSERT_EQ(pDevCfg->port_cfg[1].port_protocol, STATIC_TYPE); + + ASSERT_EQ(pDevCfg->lan_config.ip_type, IPV4_TYPE); + ASSERT_STREQ(pDevCfg->lan_config.ip_addr, "192.168.1.1"); + ASSERT_STREQ(pDevCfg->lan_config.netmask, "255.255.255.0"); +} + diff --git a/unit_test/test/restful_test.cpp b/unit_test/test/restful_test.cpp index b87820d..356cbca 100644 --- a/unit_test/test/restful_test.cpp +++ b/unit_test/test/restful_test.cpp @@ -25,7 +25,7 @@ TEST(ztp_auth, authorized_success) memset(buf, 0, 4096); ret = http_post_request(REQ_URL, JSON_REQ, (unsigned char *)buf, &size); - EXPECT_EQ(ERR_OK, ret); + ASSERT_EQ(ERR_OK, ret); ret = Json2Struct(buf, &pZTPRsp, JE_AUTH_ZTP, false);