20#include <test/json/TestOutputSuite.h>
22#include <xrpl/beast/unit_test.h>
23#include <xrpl/json/Object.h>
50 TestOutputSuite::expectResult(expected);
72 root[
"hello"] =
"world";
74 root[
"awake"] =
false;
75 root[
"temperature"] = 98.6;
79 "{\"hello\":\"world\","
82 "\"temperature\":98.6}");
105 auto array = root.setArray(
"ar");
113 auto obj = root.setObject(
"obj");
114 obj[
"hello"] =
"world";
122 root[
"obj2"] = value;
128 "{\"ar\":[23,false,23.5],"
129 "\"obj\":{\"hello\":\"world\"},"
130 "\"obj2\":{\"h\":\"w\",\"f\":false}}";
132 "{\"ar\":[23,false,23.5],"
133 "\"obj\":{\"hello\":\"world\"},"
134 "\"obj2\":{\"f\":false,\"h\":\"w\"}}";
149 auto array = root.setArray(
"ar");
156 root.setObject(
"obj")[
"hello"] =
"world";
160 auto object = root.setObject(
"obj2");
161 object.set(
"h",
"w");
162 object.set(
"f",
false);
166 "{\"ar\":[23,false,23.5],"
167 "\"obj\":{\"hello\":\"world\"},"
168 "\"obj2\":{\"h\":\"w\",\"f\":false}}");
175 setup(
"object failure assign");
177 auto obj = root.setObject(
"o1");
181 setup(
"object failure object");
183 auto obj = root.setObject(
"o1");
187 setup(
"object failure Array");
189 auto obj = root.setArray(
"o1");
198 setup(
"array failure append");
200 auto array = root.setArray(
"array");
201 auto subarray = array.appendArray();
202 auto fail = [&]() { array.append(
"fail"); };
206 setup(
"array failure appendArray");
208 auto array = root.setArray(
"array");
209 auto subarray = array.appendArray();
210 auto fail = [&]() { array.appendArray(); };
214 setup(
"array failure appendObject");
216 auto array = root.setArray(
"array");
217 auto subarray = array.appendArray();
218 auto fail = [&]() { array.appendObject(); };
226 setup(
"repeating keys");
228 root.set(
"foo",
"bar");
231 auto set_again = [&]() { root.set(
"foo",
"bar"); };
256BEAST_DEFINE_TESTSUITE(JsonObject, json,
ripple);
void setup(std::string const &testName)
void expectResult(std::string const &expected)
std::unique_ptr< WriterObject > writerObject_
void run() override
Runs the suite.
Represents a JSON object being written to a Writer.
void pass()
Record a successful test condition.
testcase_t testcase
Memberspace for declaring test cases.
void fail(String const &reason, char const *file, int line)
Record a failure.
bool expectException(Functor f, std::string const &message="")
JSON (JavaScript Object Notation).
WriterObject stringWriterObject(std::string &)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.