54 lines
1.5 KiB
C++
54 lines
1.5 KiB
C++
//
|
|
// Created by xajhuang on 2023/2/23.
|
|
//
|
|
#include "doctest.h"
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
#include "json_schema/jsoncdaccord.h"
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
TEST_SUITE("Json schema validator functions") {
|
|
TEST_CASE("JSONCDAC VALIDATOR") {
|
|
const char *json =
|
|
"{\n"
|
|
" \"ver\": 3,\n"
|
|
" \"cryptoType\": 0,\n"
|
|
" \"timeStamp\": 1599187216753,\n"
|
|
" \"msgContent\": {\n"
|
|
" \"rangeSet\": [\n"
|
|
" {\n"
|
|
" \"dhcpRange\": \"192.168.30.50-192.168.30.60\",\n"
|
|
" \"netmask\": \"255.255.255.0\",\n"
|
|
" \"domainServer\": \"114.114.114.114, 8.8.8.8\",\n"
|
|
" \"gateway\": \"192.168.30.1\",\n"
|
|
" \"leaseTime\": 420\n"
|
|
" }\n"
|
|
" ]\n"
|
|
" }\n"
|
|
"}";
|
|
|
|
const char *sch =
|
|
"{\n"
|
|
"\t\"type\": \"object\",\n"
|
|
"\t\"properties\": {\n"
|
|
"\t\t\"ver\": {\n"
|
|
"\t\t\t\"type\": \"string\"\t\t\t\n"
|
|
"\t\t}\n"
|
|
"\t},\n"
|
|
"\t\"required\": [\n"
|
|
" \"ver\"\n"
|
|
" ]\n"
|
|
"}";
|
|
|
|
json_object *pJs = json_tokener_parse(json);
|
|
json_object *pSc = json_tokener_parse(sch);
|
|
|
|
CHECK_NE(pJs, nullptr);
|
|
CHECK_NE(pSc, nullptr);
|
|
int ret = jdac_validate(pJs, pSc);
|
|
CHECK_EQ(JDAC_ERR_VALID, ret);
|
|
}
|
|
} |