MCPcopy Create free account
hub / github.com/Icinga/icinga2 / BOOST_AUTO_TEST_CASE

Function BOOST_AUTO_TEST_CASE

test/base-json.cpp:24–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22BOOST_AUTO_TEST_SUITE(base_json)
23
24BOOST_AUTO_TEST_CASE(encode)
25{
26 int emptyGenCounter = 0;
27 std::vector<int> empty;
28 std::vector<int> vec{1, 2, 3};
29 auto generate = [](int count) -> Value { return Value(count); };
30
31 Dictionary::Ptr input (new Dictionary({
32 { "array", new Array({ new Namespace() }) },
33 { "false", false },
34 // Use double max value to test JSON encoding of large numbers and trigger boost numeric_cast exceptions
35 { "max_double", std::numeric_limits<double>::max() },
36 // Test the largest uint64_t value that has an exact double representation (2^64-2048).
37 { "max_int_in_double", std::nextafter(std::pow(2, 64), 0.0) },
38 { "float", -1.25f },
39 { "float_without_fraction", 23.0f },
40 { "fx", new Function("<test>", []() {}) },
41 { "int", -42 },
42 { "null", Value() },
43 { "string", "LF\nTAB\tAUml\xC3\xA4Ill\xC3" },
44 { "true", true },
45 { "uint", 23u },
46 { "generator", new ValueGenerator{vec, generate} },
47 {
48 "empty_generator",
49 new ValueGenerator{
50 empty,
51 [&emptyGenCounter](int) -> Value {
52 emptyGenCounter++;
53 return Empty;
54 }
55 }
56 },
57 }));
58
59 String output (R"EOF({
60 "array": [
61 {}
62 ],
63 "empty_generator": [],
64 "false": false,
65 "float": -1.25,
66 "float_without_fraction": 23,
67 "fx": "Object of type 'Function'",
68 "generator": [
69 1,
70 2,
71 3
72 ],
73 "int": -42,
74 "max_double": 1.7976931348623157e+308,
75 "max_int_in_double": 18446744073709549568,
76 "null": null,
77 "string": "LF\nTAB\tAUml\u00e4Ill\ufffd",
78 "true": true,
79 "uint": 23
80}
81)EOF");

Callers

nothing calls this directly

Calls 15

MakeNestedJsonArrayFunction · 0.85
MakeNestedJsonObjectFunction · 0.85
TestJsonStackSizeFunction · 0.85
GetKeysMethod · 0.80
IsBooleanMethod · 0.80
IsNumberMethod · 0.80
IsStringMethod · 0.80
ValueClass · 0.50
SetMethod · 0.45
GetMethod · 0.45
GetLengthMethod · 0.45

Tested by

no test coverage detected