// // Created by xajhu on 2019/11/29 0029. // #include using namespace std; #include "gtest/gtest.h" extern "C" { #include "err_code.h" #include "json_interface.h" } TEST(json_test, encode) { int ret = 0; const char *pJson; AUTH_ZTH_REQ ztpReq; memset(&ztpReq, 0, sizeof(AUTH_ZTH_REQ)); ztpReq.pESN = (char *)"ace08484843"; pJson = Struct2Json(&ztpReq, JE_AUTH_ZTP, false, &ret); if(pJson) { free((void *)pJson); } ASSERT_EQ(ERR_OK, ret); } TEST(json_test, decode) { #define JSON_STR ("{\"code\":\"fBBx8Q\",\"ip\":\"172.28.73.38\",\"iptype\":\"1\",\"status\":\"SUCCESS\"}") int ret = 0; PAUTH_ZTH_RSP pZTPRsp; char *pJson = (char*)JSON_STR; ret = Json2Struct(pJson, &pZTPRsp, JE_AUTH_ZTP, false); if(pZTPRsp) { if(pZTPRsp->status) { free(pZTPRsp->status); } if(pZTPRsp->code) { free(pZTPRsp->code); } if(pZTPRsp->ip) { free(pZTPRsp->ip); } free(pZTPRsp); } ASSERT_EQ(0, ret); }