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

Function test

lib_acl_cpp/samples/json/json0/json.cpp:12–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10using namespace std;
11
12static void test(void)
13{
14 static const char* data = \
15 "{ 'menu name': {\r\n"
16 " 'id:file': 'file',\r\n"
17 " 'value': 'File',\r\n"
18 " 'popup': {\r\n"
19 " 'menuitem1': [\r\n"
20 " {'value': 'New1', 'onclick': 'CreateNewDoc()'},\r\n"
21 " {'value': 'Open1', 'onclick': 'OpenDoc()'},\r\n"
22 " {'value': 'Close1', 'onclick': 'CloseDoc()'}\r\n"
23 " ],\r\n"
24 " 'menuname': 'hello world',\r\n"
25 " 'inner': { 'value' : 'new ', 'value' : 'open' },\r\n"
26 " 'menuitem2': [\r\n"
27 " {'value': 'New2', 'onclick': 'CreateNewDoc()'},\r\n"
28 " {'value': 'Open2', 'onclick': 'OpenDoc()'},\r\n"
29 " {'value': 'Close2', 'onclick': 'CloseDoc()'},\r\n"
30 " {{'value': 'Help2', 'onclick': 'Help()'}}"
31 " ]\r\n"
32 " }\r\n"
33 " }\r\n,"
34 " 'help': 'hello world!',\r\n"
35 " 'menuitem2': [\r\n"
36 " {'value': 'New3', 'onclick': 'CreateNewDoc()'},\r\n"
37 " {'value': 'Open3', 'onclick': 'OpenDoc()'},\r\n"
38 " {'value': 'Close3', 'onclick': 'CloseDoc()'},\r\n"
39 " [{'value': 'Save3', 'onclick': 'SaveDoc()'}]"
40 " ]\r\n"
41 "}\r\n";
42 acl::json json;
43
44 json.update(data);
45 const vector<acl::json_node*>& elements = json.getElementsByTagName("value");
46
47 if (!elements.empty())
48 {
49 vector<acl::json_node*>::const_iterator cit = elements.begin();
50 for (; cit != elements.end(); ++cit)
51 {
52 acl::json_node *node = *cit;
53 printf("tagname: %s, text: %s\n",
54 node->tag_name() ? node->tag_name() : "",
55 node->get_text() ? node->get_text() : "");
56 }
57 }
58
59 //const vector<acl::json_node*>& menuitem1 = json.getElementsByTagName("menuitem1");
60 const vector<acl::json_node*>& menuitem1 =
61 json.getElementsByTags("menu name/popup/menuitem1");
62 if (!menuitem1.empty())
63 {
64 vector<acl::json_node*>::const_iterator cit = menuitem1.begin();
65 for (; cit != menuitem1.end(); ++cit)
66 {
67 acl::json_node* node = (*cit)->first_child();
68 printf("tag: %s\r\n", (*cit)->tag_name());
69 while (node)

Callers 1

mainFunction · 0.70

Calls 15

beginMethod · 0.80
get_textMethod · 0.80
get_parentMethod · 0.80
build_jsonMethod · 0.80
updateMethod · 0.45
emptyMethod · 0.45
endMethod · 0.45
tag_nameMethod · 0.45
first_childMethod · 0.45
next_childMethod · 0.45
resetMethod · 0.45
create_nodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…