-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonUnitTest.cpp
More file actions
49 lines (48 loc) · 1.46 KB
/
jsonUnitTest.cpp
File metadata and controls
49 lines (48 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "json.h"
void dummyFunc(JSON & val)
{
val["HAPPY"] = "customer";
}
JSON getAJSON()
{
return JSON(1);
}
void populate(JSON & rhs)
{
JSON data;
data["id"] = 15;
data["secondID"] = getAJSON();
data["name"](false);
dummyFunc(data);
data["person"][0]["name"] = "Benny";
data["person"][0]["id"] = 3294;
data["person"][1]["name"] = "Cunpu";
data["person"][1]["id"] = 321312;
rhs = data;
}
int main()
{
JSON data;
populate(data);
int ID = (int)data["id"];
assert(((int)data["id"]) == ID);
assert(((string)data["person"][0]["name"]) == "Benny");
assert(((int)data["secondID"]) == 1);
std::cout << data.json_encode() << std::endl;
JSON decoded;
JSONDecode(data.json_encode(), decoded);
std::cout << decoded.json_encode() << std::endl;
std::string test_data = "{ \"glossary\": { \"title\": \"example glossary\","
"\"GlossDiv\": { \"title\": \"S\", \"GlossList\": { \"GlossEntry\": {"
"\"ID\": \"SGML\",\"SortAs\": \"SGML\","
"\"GlossTerm\": \"Standard Generalized Markup Language\","
"\"Acronym\": \"SGML\",\"Abbrev\": \"ISO 8879:1986\","
"\"GlossDef\": {\"para\": \"A meta-markup language, "
"used to create markup languages such as DocBook.\","
"\"GlossSeeAlso\": [\"GML\", \"XML\"]},\"GlossSee\": \"markup\""
"} } } } }";
JSON decoded2;
JSONDecode(test_data, decoded2);
std::cout << decoded2.json_encode() << std::endl;
return 0;
}