From d32d08039ba77c4273d138f0a0203269c309c01e Mon Sep 17 00:00:00 2001 From: huangxin Date: Tue, 3 Dec 2019 14:17:33 +0800 Subject: [PATCH] =?UTF-8?q?Mod=20=20aaa-12=201.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E4=BF=A1=E6=81=AF=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=8E=A5=E5=8F=A3=E3=80=822.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E5=8D=95=E5=85=83=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=20RCA=EF=BC=9A=20SOL=EF=BC=9A=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BA=BA=EF=BC=9Ahuangxin=20=E6=A3=80=E8=A7=86=E4=BA=BA?= =?UTF-8?q?=EF=BC=9Ahuangxin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- confingure/prase_config.c | 10 +++++++ include/ztp_config.h | 3 ++ unit_test/test/configure_test.cpp | 49 +++++++++++++++++++++++++++++++ unit_test/test/restful_test.cpp | 2 +- 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 unit_test/test/configure_test.cpp 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);