| 16 | #endif |
| 17 | |
| 18 | static 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()); |
no test coverage detected
searching dependent graphs…