mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
Format first-party source according to .clang-format
This commit is contained in:
committed by
manojsdoshi
parent
65dfc5d19e
commit
50760c6935
@@ -17,50 +17,55 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <ripple/json/Object.h>
|
||||
#include <test/json/TestOutputSuite.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
|
||||
namespace Json {
|
||||
|
||||
class JsonObject_test : public ripple::test::TestOutputSuite
|
||||
{
|
||||
void setup (std::string const& testName)
|
||||
void
|
||||
setup(std::string const& testName)
|
||||
{
|
||||
testcase (testName);
|
||||
output_.clear ();
|
||||
testcase(testName);
|
||||
output_.clear();
|
||||
}
|
||||
|
||||
std::unique_ptr<WriterObject> writerObject_;
|
||||
|
||||
Object& makeRoot()
|
||||
Object&
|
||||
makeRoot()
|
||||
{
|
||||
writerObject_ = std::make_unique<WriterObject> (
|
||||
stringWriterObject (output_));
|
||||
writerObject_ =
|
||||
std::make_unique<WriterObject>(stringWriterObject(output_));
|
||||
return **writerObject_;
|
||||
}
|
||||
|
||||
void expectResult (std::string const& expected)
|
||||
void
|
||||
expectResult(std::string const& expected)
|
||||
{
|
||||
writerObject_.reset();
|
||||
TestOutputSuite::expectResult (expected);
|
||||
TestOutputSuite::expectResult(expected);
|
||||
}
|
||||
|
||||
public:
|
||||
void testTrivial ()
|
||||
void
|
||||
testTrivial()
|
||||
{
|
||||
setup ("trivial");
|
||||
setup("trivial");
|
||||
|
||||
{
|
||||
auto& root = makeRoot();
|
||||
(void) root;
|
||||
(void)root;
|
||||
}
|
||||
expectResult ("{}");
|
||||
expectResult("{}");
|
||||
}
|
||||
|
||||
void testSimple ()
|
||||
void
|
||||
testSimple()
|
||||
{
|
||||
setup ("simple");
|
||||
setup("simple");
|
||||
{
|
||||
auto& root = makeRoot();
|
||||
root["hello"] = "world";
|
||||
@@ -69,40 +74,42 @@ public:
|
||||
root["temperature"] = 98.6;
|
||||
}
|
||||
|
||||
expectResult (
|
||||
expectResult(
|
||||
"{\"hello\":\"world\","
|
||||
"\"skidoo\":23,"
|
||||
"\"awake\":false,"
|
||||
"\"temperature\":98.6}");
|
||||
}
|
||||
|
||||
void testOneSub ()
|
||||
void
|
||||
testOneSub()
|
||||
{
|
||||
setup ("oneSub");
|
||||
setup("oneSub");
|
||||
{
|
||||
auto& root = makeRoot();
|
||||
root.setArray ("ar");
|
||||
root.setArray("ar");
|
||||
}
|
||||
expectResult ("{\"ar\":[]}");
|
||||
expectResult("{\"ar\":[]}");
|
||||
}
|
||||
|
||||
void testSubs ()
|
||||
void
|
||||
testSubs()
|
||||
{
|
||||
setup ("subs");
|
||||
setup("subs");
|
||||
{
|
||||
auto& root = makeRoot();
|
||||
|
||||
{
|
||||
// Add an array with three entries.
|
||||
auto array = root.setArray ("ar");
|
||||
array.append (23);
|
||||
array.append (false);
|
||||
array.append (23.5);
|
||||
auto array = root.setArray("ar");
|
||||
array.append(23);
|
||||
array.append(false);
|
||||
array.append(23.5);
|
||||
}
|
||||
|
||||
{
|
||||
// Add an object with one entry.
|
||||
auto obj = root.setObject ("obj");
|
||||
auto obj = root.setObject("obj");
|
||||
obj["hello"] = "world";
|
||||
}
|
||||
|
||||
@@ -116,128 +123,135 @@ public:
|
||||
}
|
||||
|
||||
// Json::Value has an unstable order...
|
||||
auto case1 = "{\"ar\":[23,false,23.5],"
|
||||
"\"obj\":{\"hello\":\"world\"},"
|
||||
"\"obj2\":{\"h\":\"w\",\"f\":false}}";
|
||||
auto case2 = "{\"ar\":[23,false,23.5],"
|
||||
"\"obj\":{\"hello\":\"world\"},"
|
||||
"\"obj2\":{\"f\":false,\"h\":\"w\"}}";
|
||||
auto case1 =
|
||||
"{\"ar\":[23,false,23.5],"
|
||||
"\"obj\":{\"hello\":\"world\"},"
|
||||
"\"obj2\":{\"h\":\"w\",\"f\":false}}";
|
||||
auto case2 =
|
||||
"{\"ar\":[23,false,23.5],"
|
||||
"\"obj\":{\"hello\":\"world\"},"
|
||||
"\"obj2\":{\"f\":false,\"h\":\"w\"}}";
|
||||
writerObject_.reset();
|
||||
BEAST_EXPECT(output_ == case1 || output_ == case2);
|
||||
}
|
||||
|
||||
void testSubsShort ()
|
||||
void
|
||||
testSubsShort()
|
||||
{
|
||||
setup ("subsShort");
|
||||
setup("subsShort");
|
||||
|
||||
{
|
||||
auto& root = makeRoot();
|
||||
|
||||
{
|
||||
// Add an array with three entries.
|
||||
auto array = root.setArray ("ar");
|
||||
array.append (23);
|
||||
array.append (false);
|
||||
array.append (23.5);
|
||||
auto array = root.setArray("ar");
|
||||
array.append(23);
|
||||
array.append(false);
|
||||
array.append(23.5);
|
||||
}
|
||||
|
||||
// Add an object with one entry.
|
||||
root.setObject ("obj")["hello"] = "world";
|
||||
root.setObject("obj")["hello"] = "world";
|
||||
|
||||
{
|
||||
// Add another object with two entries.
|
||||
auto object = root.setObject ("obj2");
|
||||
auto object = root.setObject("obj2");
|
||||
object.set("h", "w");
|
||||
object.set("f", false);
|
||||
}
|
||||
}
|
||||
expectResult (
|
||||
expectResult(
|
||||
"{\"ar\":[23,false,23.5],"
|
||||
"\"obj\":{\"hello\":\"world\"},"
|
||||
"\"obj2\":{\"h\":\"w\",\"f\":false}}");
|
||||
}
|
||||
|
||||
void testFailureObject()
|
||||
void
|
||||
testFailureObject()
|
||||
{
|
||||
{
|
||||
setup ("object failure assign");
|
||||
setup("object failure assign");
|
||||
auto& root = makeRoot();
|
||||
auto obj = root.setObject ("o1");
|
||||
expectException ([&]() { root["fail"] = "complete"; });
|
||||
auto obj = root.setObject("o1");
|
||||
expectException([&]() { root["fail"] = "complete"; });
|
||||
}
|
||||
{
|
||||
setup ("object failure object");
|
||||
setup("object failure object");
|
||||
auto& root = makeRoot();
|
||||
auto obj = root.setObject ("o1");
|
||||
expectException ([&] () { root.setObject ("o2"); });
|
||||
auto obj = root.setObject("o1");
|
||||
expectException([&]() { root.setObject("o2"); });
|
||||
}
|
||||
{
|
||||
setup ("object failure Array");
|
||||
setup("object failure Array");
|
||||
auto& root = makeRoot();
|
||||
auto obj = root.setArray ("o1");
|
||||
expectException ([&] () { root.setArray ("o2"); });
|
||||
auto obj = root.setArray("o1");
|
||||
expectException([&]() { root.setArray("o2"); });
|
||||
}
|
||||
}
|
||||
|
||||
void testFailureArray()
|
||||
void
|
||||
testFailureArray()
|
||||
{
|
||||
{
|
||||
setup ("array failure append");
|
||||
setup("array failure append");
|
||||
auto& root = makeRoot();
|
||||
auto array = root.setArray ("array");
|
||||
auto subarray = array.appendArray ();
|
||||
auto fail = [&]() { array.append ("fail"); };
|
||||
expectException (fail);
|
||||
auto array = root.setArray("array");
|
||||
auto subarray = array.appendArray();
|
||||
auto fail = [&]() { array.append("fail"); };
|
||||
expectException(fail);
|
||||
}
|
||||
{
|
||||
setup ("array failure appendArray");
|
||||
setup("array failure appendArray");
|
||||
auto& root = makeRoot();
|
||||
auto array = root.setArray ("array");
|
||||
auto subarray = array.appendArray ();
|
||||
auto fail = [&]() { array.appendArray (); };
|
||||
expectException (fail);
|
||||
auto array = root.setArray("array");
|
||||
auto subarray = array.appendArray();
|
||||
auto fail = [&]() { array.appendArray(); };
|
||||
expectException(fail);
|
||||
}
|
||||
{
|
||||
setup ("array failure appendObject");
|
||||
setup("array failure appendObject");
|
||||
auto& root = makeRoot();
|
||||
auto array = root.setArray ("array");
|
||||
auto subarray = array.appendArray ();
|
||||
auto fail = [&]() { array.appendObject (); };
|
||||
expectException (fail);
|
||||
auto array = root.setArray("array");
|
||||
auto subarray = array.appendArray();
|
||||
auto fail = [&]() { array.appendObject(); };
|
||||
expectException(fail);
|
||||
}
|
||||
}
|
||||
|
||||
void testKeyFailure ()
|
||||
void
|
||||
testKeyFailure()
|
||||
{
|
||||
setup ("repeating keys");
|
||||
setup("repeating keys");
|
||||
auto& root = makeRoot();
|
||||
root.set ("foo", "bar");
|
||||
root.set ("baz", 0);
|
||||
root.set("foo", "bar");
|
||||
root.set("baz", 0);
|
||||
// setting key again throws in !NDEBUG builds
|
||||
auto set_again = [&]() { root.set ("foo", "bar"); };
|
||||
auto set_again = [&]() { root.set("foo", "bar"); };
|
||||
#ifdef NDEBUG
|
||||
set_again();
|
||||
pass();
|
||||
#else
|
||||
expectException (set_again);
|
||||
expectException(set_again);
|
||||
#endif
|
||||
}
|
||||
|
||||
void run () override
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testTrivial ();
|
||||
testSimple ();
|
||||
testTrivial();
|
||||
testSimple();
|
||||
|
||||
testOneSub ();
|
||||
testSubs ();
|
||||
testSubsShort ();
|
||||
testOneSub();
|
||||
testSubs();
|
||||
testSubsShort();
|
||||
|
||||
testFailureObject ();
|
||||
testFailureArray ();
|
||||
testKeyFailure ();
|
||||
testFailureObject();
|
||||
testFailureArray();
|
||||
testKeyFailure();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(JsonObject, ripple_basics, ripple);
|
||||
|
||||
} // Json
|
||||
} // namespace Json
|
||||
|
||||
Reference in New Issue
Block a user