MCPcopy Create free account
hub / github.com/acl-dev/acl / test

Function test

lib_acl_cpp/samples/json/json5/json.cpp:18–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16#endif
17
18static void test(bool once)
19{
20 acl::json json;
21
22 if (once)
23 json.update(default_data);
24 else
25 {
26 const char* s = default_data;
27 char buf[2];
28
29 while (*s)
30 {
31 buf[0] = *s;
32 buf[1] = 0;
33 json.update(buf);
34 s++;
35 }
36 }
37
38 printf("-------------------------------------------------\r\n");
39 printf(">>>%s(%d)->source data: %s\r\n",
40 __FUNCTION__, __LINE__, default_data);
41 printf("-------------------------------------------------\r\n");
42 printf(">>>%s(%d)->build json: %s\r\n",
43 __FUNCTION__, __LINE__, json.to_string().c_str());
44 printf("-------------------------------------------------\r\n");
45 if (json.to_string() == default_data)
46 printf("%s(%d): build json OK!\r\n", __FUNCTION__, __LINE__);
47 else
48 {
49 printf(">>>src:\r\n%s\r\n>>>dst:\r\n%s\r\n",
50 default_data, json.to_string().c_str());
51 printf("%s(%d): build json ERROR!\r\n", __FUNCTION__, __LINE__);
52 exit (1);
53 }
54 printf("-------------------------------------------------\r\n");
55
56 const char* tags;
57 tags = "DataValue/RemoteLoginRemind";
58 //tags = "DataValue";
59 printf(">>>%s(%d)->tags: %s\r\n", __FUNCTION__, __LINE__, tags);
60
61 const std::vector<acl::json_node*>& nodes = json.getElementsByTags(tags);
62 if (nodes.empty())
63 {
64 printf(">>>%s(%d)->NOT FOUND(tags: %s)\r\n",
65 __FUNCTION__, __LINE__, tags);
66 return;
67 }
68
69 acl::json_node* first = nodes[0];
70 acl_assert(first);
71
72 printf(">>>node(tags: %s, tag: %s, text: %s, left: %d) to string:\r\n%s\r\n",
73 tags, first->tag_name() ? first->tag_name() : "null",
74 first->get_text() ? first->get_text() : "null",
75 first->get_json_node()->left_ch, first->to_string().c_str());

Callers 1

mainFunction · 0.70

Calls 13

acl_vstring_allocFunction · 0.85
acl_json_node_buildFunction · 0.85
acl_vstring_freeFunction · 0.85
get_textMethod · 0.80
get_json_nodeMethod · 0.80
get_objMethod · 0.80
updateMethod · 0.45
c_strMethod · 0.45
to_stringMethod · 0.45
emptyMethod · 0.45
tag_nameMethod · 0.45
first_nodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…