mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Don't include unit test sources in code coverage (RIPD-1132):
Most files containing unit test code are moved to src/test. JTx and the test client code are not yet moved.
This commit is contained in:
240
src/test/json/Object_test.cpp
Normal file
240
src/test/json/Object_test.cpp
Normal file
@@ -0,0 +1,240 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/json/Object.h>
|
||||
#include <ripple/rpc/tests/TestOutputSuite.test.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
|
||||
namespace Json {
|
||||
|
||||
class JsonObject_test : public ripple::RPC::TestOutputSuite
|
||||
{
|
||||
void setup (std::string const& testName)
|
||||
{
|
||||
testcase (testName);
|
||||
output_.clear ();
|
||||
}
|
||||
|
||||
std::unique_ptr<WriterObject> writerObject_;
|
||||
|
||||
Object& makeRoot()
|
||||
{
|
||||
writerObject_ = std::make_unique<WriterObject> (
|
||||
stringWriterObject (output_));
|
||||
return **writerObject_;
|
||||
}
|
||||
|
||||
void expectResult (std::string const& expected)
|
||||
{
|
||||
writerObject_.reset();
|
||||
TestOutputSuite::expectResult (expected);
|
||||
}
|
||||
|
||||
public:
|
||||
void testTrivial ()
|
||||
{
|
||||
setup ("trivial");
|
||||
|
||||
{
|
||||
auto& root = makeRoot();
|
||||
(void) root;
|
||||
}
|
||||
expectResult ("{}");
|
||||
}
|
||||
|
||||
void testSimple ()
|
||||
{
|
||||
setup ("simple");
|
||||
{
|
||||
auto& root = makeRoot();
|
||||
root["hello"] = "world";
|
||||
root["skidoo"] = 23;
|
||||
root["awake"] = false;
|
||||
root["temperature"] = 98.6;
|
||||
}
|
||||
|
||||
expectResult (
|
||||
"{\"hello\":\"world\","
|
||||
"\"skidoo\":23,"
|
||||
"\"awake\":false,"
|
||||
"\"temperature\":98.6}");
|
||||
}
|
||||
|
||||
void testOneSub ()
|
||||
{
|
||||
setup ("oneSub");
|
||||
{
|
||||
auto& root = makeRoot();
|
||||
root.setArray ("ar");
|
||||
}
|
||||
expectResult ("{\"ar\":[]}");
|
||||
}
|
||||
|
||||
void testSubs ()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
{
|
||||
// Add an object with one entry.
|
||||
auto obj = root.setObject ("obj");
|
||||
obj["hello"] = "world";
|
||||
}
|
||||
|
||||
{
|
||||
// Add another object with two entries.
|
||||
Json::Value value;
|
||||
value["h"] = "w";
|
||||
value["f"] = false;
|
||||
root["obj2"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
// 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\"}}";
|
||||
writerObject_.reset();
|
||||
BEAST_EXPECT(output_ == case1 || output_ == case2);
|
||||
}
|
||||
|
||||
void testSubsShort ()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
// Add an object with one entry.
|
||||
root.setObject ("obj")["hello"] = "world";
|
||||
|
||||
{
|
||||
// Add another object with two entries.
|
||||
auto object = root.setObject ("obj2");
|
||||
object.set("h", "w");
|
||||
object.set("f", false);
|
||||
}
|
||||
}
|
||||
expectResult (
|
||||
"{\"ar\":[23,false,23.5],"
|
||||
"\"obj\":{\"hello\":\"world\"},"
|
||||
"\"obj2\":{\"h\":\"w\",\"f\":false}}");
|
||||
}
|
||||
|
||||
void testFailureObject()
|
||||
{
|
||||
{
|
||||
setup ("object failure assign");
|
||||
auto& root = makeRoot();
|
||||
auto obj = root.setObject ("o1");
|
||||
expectException ([&]() { root["fail"] = "complete"; });
|
||||
}
|
||||
{
|
||||
setup ("object failure object");
|
||||
auto& root = makeRoot();
|
||||
auto obj = root.setObject ("o1");
|
||||
expectException ([&] () { root.setObject ("o2"); });
|
||||
}
|
||||
{
|
||||
setup ("object failure Array");
|
||||
auto& root = makeRoot();
|
||||
auto obj = root.setArray ("o1");
|
||||
expectException ([&] () { root.setArray ("o2"); });
|
||||
}
|
||||
}
|
||||
|
||||
void testFailureArray()
|
||||
{
|
||||
{
|
||||
setup ("array failure append");
|
||||
auto& root = makeRoot();
|
||||
auto array = root.setArray ("array");
|
||||
auto subarray = array.appendArray ();
|
||||
auto fail = [&]() { array.append ("fail"); };
|
||||
expectException (fail);
|
||||
}
|
||||
{
|
||||
setup ("array failure appendArray");
|
||||
auto& root = makeRoot();
|
||||
auto array = root.setArray ("array");
|
||||
auto subarray = array.appendArray ();
|
||||
auto fail = [&]() { array.appendArray (); };
|
||||
expectException (fail);
|
||||
}
|
||||
{
|
||||
setup ("array failure appendObject");
|
||||
auto& root = makeRoot();
|
||||
auto array = root.setArray ("array");
|
||||
auto subarray = array.appendArray ();
|
||||
auto fail = [&]() { array.appendObject (); };
|
||||
expectException (fail);
|
||||
}
|
||||
}
|
||||
|
||||
void testKeyFailure ()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
setup ("repeating keys");
|
||||
auto& root = makeRoot();
|
||||
root.set ("foo", "bar");
|
||||
root.set ("baz", 0);
|
||||
auto fail = [&]() { root.set ("foo", "bar"); };
|
||||
expectException (fail);
|
||||
#endif
|
||||
}
|
||||
|
||||
void run () override
|
||||
{
|
||||
testTrivial ();
|
||||
testSimple ();
|
||||
|
||||
testOneSub ();
|
||||
testSubs ();
|
||||
testSubsShort ();
|
||||
|
||||
testFailureObject ();
|
||||
testFailureArray ();
|
||||
testKeyFailure ();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(JsonObject, ripple_basics, ripple);
|
||||
|
||||
} // Json
|
||||
64
src/test/json/Output_test.cpp
Normal file
64
src/test/json/Output_test.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/json/json_reader.h>
|
||||
#include <ripple/json/json_writer.h>
|
||||
#include <ripple/rpc/tests/TestOutputSuite.test.h>
|
||||
|
||||
namespace Json {
|
||||
|
||||
struct Output_test : ripple::RPC::TestOutputSuite
|
||||
{
|
||||
void runTest (std::string const& name, std::string const& valueDesc)
|
||||
{
|
||||
setup (name);
|
||||
Json::Value value;
|
||||
BEAST_EXPECT(Json::Reader().parse (valueDesc, value));
|
||||
auto out = stringOutput (output_);
|
||||
outputJson (value, out);
|
||||
|
||||
// Compare with the original version.
|
||||
auto expected = Json::FastWriter().write (value);
|
||||
expectResult (expected);
|
||||
expectResult (valueDesc);
|
||||
expectResult (jsonAsString (value));
|
||||
}
|
||||
|
||||
void runTest (std::string const& name)
|
||||
{
|
||||
runTest (name, name);
|
||||
}
|
||||
|
||||
void run () override
|
||||
{
|
||||
runTest ("empty dict", "{}");
|
||||
runTest ("empty array", "[]");
|
||||
runTest ("array", "[23,4.25,true,null,\"string\"]");
|
||||
runTest ("dict", "{\"hello\":\"world\"}");
|
||||
runTest ("array dict", "[{}]");
|
||||
runTest ("array array", "[[]]");
|
||||
runTest ("more complex",
|
||||
"{\"array\":[{\"12\":23},{},null,false,0.5]}");
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(Output, ripple_basics, ripple);
|
||||
|
||||
} // Json
|
||||
205
src/test/json/Writer_test.cpp
Normal file
205
src/test/json/Writer_test.cpp
Normal file
@@ -0,0 +1,205 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/json/json_writer.h>
|
||||
#include <ripple/json/Writer.h>
|
||||
#include <ripple/rpc/tests/TestOutputSuite.test.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
|
||||
namespace Json {
|
||||
|
||||
class JsonWriter_test : public ripple::RPC::TestOutputSuite
|
||||
{
|
||||
public:
|
||||
void testTrivial ()
|
||||
{
|
||||
setup ("trivial");
|
||||
BEAST_EXPECT(output_.empty ());
|
||||
expectResult("");
|
||||
}
|
||||
|
||||
void testNearTrivial ()
|
||||
{
|
||||
setup ("near trivial");
|
||||
BEAST_EXPECT(output_.empty ());
|
||||
writer_->output (0);
|
||||
expectResult("0");
|
||||
}
|
||||
|
||||
void testPrimitives ()
|
||||
{
|
||||
setup ("true");
|
||||
writer_->output (true);
|
||||
expectResult ("true");
|
||||
|
||||
setup ("false");
|
||||
writer_->output (false);
|
||||
expectResult ("false");
|
||||
|
||||
setup ("23");
|
||||
writer_->output (23);
|
||||
expectResult ("23");
|
||||
|
||||
setup ("23.0");
|
||||
writer_->output (23.0);
|
||||
expectResult ("23.0");
|
||||
|
||||
setup ("23.5");
|
||||
writer_->output (23.5);
|
||||
expectResult ("23.5");
|
||||
|
||||
setup ("a string");
|
||||
writer_->output ("a string");
|
||||
expectResult ("\"a string\"");
|
||||
|
||||
setup ("nullptr");
|
||||
writer_->output (nullptr);
|
||||
expectResult ("null");
|
||||
}
|
||||
|
||||
void testEmpty ()
|
||||
{
|
||||
setup ("empty array");
|
||||
writer_->startRoot (Writer::array);
|
||||
writer_->finish ();
|
||||
expectResult ("[]");
|
||||
|
||||
setup ("empty object");
|
||||
writer_->startRoot (Writer::object);
|
||||
writer_->finish ();
|
||||
expectResult ("{}");
|
||||
}
|
||||
|
||||
void testEscaping ()
|
||||
{
|
||||
setup ("backslash");
|
||||
writer_->output ("\\");
|
||||
expectResult ("\"\\\\\"");
|
||||
|
||||
setup ("quote");
|
||||
writer_->output ("\"");
|
||||
expectResult ("\"\\\"\"");
|
||||
|
||||
setup ("backslash and quote");
|
||||
writer_->output ("\\\"");
|
||||
expectResult ("\"\\\\\\\"\"");
|
||||
|
||||
setup ("escape embedded");
|
||||
writer_->output ("this contains a \\ in the middle of it.");
|
||||
expectResult ("\"this contains a \\\\ in the middle of it.\"");
|
||||
|
||||
setup ("remaining escapes");
|
||||
writer_->output ("\b\f\n\r\t");
|
||||
expectResult ("\"\\b\\f\\n\\r\\t\"");
|
||||
}
|
||||
|
||||
void testArray ()
|
||||
{
|
||||
setup ("empty array");
|
||||
writer_->startRoot (Writer::array);
|
||||
writer_->append (12);
|
||||
writer_->finish ();
|
||||
expectResult ("[12]");
|
||||
}
|
||||
|
||||
void testLongArray ()
|
||||
{
|
||||
setup ("long array");
|
||||
writer_->startRoot (Writer::array);
|
||||
writer_->append (12);
|
||||
writer_->append (true);
|
||||
writer_->append ("hello");
|
||||
writer_->finish ();
|
||||
expectResult ("[12,true,\"hello\"]");
|
||||
}
|
||||
|
||||
void testEmbeddedArraySimple ()
|
||||
{
|
||||
setup ("embedded array simple");
|
||||
writer_->startRoot (Writer::array);
|
||||
writer_->startAppend (Writer::array);
|
||||
writer_->finish ();
|
||||
writer_->finish ();
|
||||
expectResult ("[[]]");
|
||||
}
|
||||
|
||||
void testObject ()
|
||||
{
|
||||
setup ("object");
|
||||
writer_->startRoot (Writer::object);
|
||||
writer_->set ("hello", "world");
|
||||
writer_->finish ();
|
||||
|
||||
expectResult ("{\"hello\":\"world\"}");
|
||||
}
|
||||
|
||||
void testComplexObject ()
|
||||
{
|
||||
setup ("complex object");
|
||||
writer_->startRoot (Writer::object);
|
||||
|
||||
writer_->set ("hello", "world");
|
||||
writer_->startSet (Writer::array, "array");
|
||||
|
||||
writer_->append (true);
|
||||
writer_->append (12);
|
||||
writer_->startAppend (Writer::array);
|
||||
writer_->startAppend (Writer::object);
|
||||
writer_->set ("goodbye", "cruel world.");
|
||||
writer_->startSet (Writer::array, "subarray");
|
||||
writer_->append (23.5);
|
||||
writer_->finishAll ();
|
||||
|
||||
expectResult ("{\"hello\":\"world\",\"array\":[true,12,"
|
||||
"[{\"goodbye\":\"cruel world.\","
|
||||
"\"subarray\":[23.5]}]]}");
|
||||
}
|
||||
|
||||
void testJson ()
|
||||
{
|
||||
setup ("object");
|
||||
Json::Value value (Json::objectValue);
|
||||
value["foo"] = 23;
|
||||
writer_->startRoot (Writer::object);
|
||||
writer_->set ("hello", value);
|
||||
writer_->finish ();
|
||||
|
||||
expectResult ("{\"hello\":{\"foo\":23}}");
|
||||
}
|
||||
|
||||
void run () override
|
||||
{
|
||||
testTrivial ();
|
||||
testNearTrivial ();
|
||||
testPrimitives ();
|
||||
testEmpty ();
|
||||
testEscaping ();
|
||||
testArray ();
|
||||
testLongArray ();
|
||||
testEmbeddedArraySimple ();
|
||||
testObject ();
|
||||
testComplexObject ();
|
||||
testJson();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(JsonWriter, ripple_basics, ripple);
|
||||
|
||||
} // Json
|
||||
233
src/test/json/json_value_test.cpp
Normal file
233
src/test/json/json_value_test.cpp
Normal file
@@ -0,0 +1,233 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/json/json_value.h>
|
||||
#include <ripple/json/json_reader.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <ripple/beast/type_name.h>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
struct json_value_test : beast::unit_test::suite
|
||||
{
|
||||
void test_bool()
|
||||
{
|
||||
BEAST_EXPECT(! Json::Value());
|
||||
|
||||
BEAST_EXPECT(! Json::Value(""));
|
||||
|
||||
BEAST_EXPECT(bool (Json::Value("empty")));
|
||||
BEAST_EXPECT(bool (Json::Value(false)));
|
||||
BEAST_EXPECT(bool (Json::Value(true)));
|
||||
BEAST_EXPECT(bool (Json::Value(0)));
|
||||
BEAST_EXPECT(bool (Json::Value(1)));
|
||||
|
||||
Json::Value array (Json::arrayValue);
|
||||
BEAST_EXPECT(! array);
|
||||
array.append(0);
|
||||
BEAST_EXPECT(bool (array));
|
||||
|
||||
Json::Value object (Json::objectValue);
|
||||
BEAST_EXPECT(! object);
|
||||
object[""] = false;
|
||||
BEAST_EXPECT(bool (object));
|
||||
}
|
||||
|
||||
void test_bad_json ()
|
||||
{
|
||||
char const* s (
|
||||
"{\"method\":\"ledger\",\"params\":[{\"ledger_index\":1e300}]}"
|
||||
);
|
||||
|
||||
Json::Value j;
|
||||
Json::Reader r;
|
||||
|
||||
r.parse (s, j);
|
||||
pass ();
|
||||
}
|
||||
|
||||
void test_edge_cases ()
|
||||
{
|
||||
std::string json;
|
||||
|
||||
std::uint32_t max_uint = std::numeric_limits<std::uint32_t>::max ();
|
||||
std::int32_t max_int = std::numeric_limits<std::int32_t>::max ();
|
||||
std::int32_t min_int = std::numeric_limits<std::int32_t>::min ();
|
||||
|
||||
std::uint32_t a_uint = max_uint - 1978;
|
||||
std::int32_t a_large_int = max_int - 1978;
|
||||
std::int32_t a_small_int = min_int + 1978;
|
||||
|
||||
json = "{\"max_uint\":" + std::to_string (max_uint);
|
||||
json += ",\"max_int\":" + std::to_string (max_int);
|
||||
json += ",\"min_int\":" + std::to_string (min_int);
|
||||
json += ",\"a_uint\":" + std::to_string (a_uint);
|
||||
json += ",\"a_large_int\":" + std::to_string (a_large_int);
|
||||
json += ",\"a_small_int\":" + std::to_string (a_small_int);
|
||||
json += "}";
|
||||
|
||||
Json::Value j1;
|
||||
Json::Reader r1;
|
||||
|
||||
BEAST_EXPECT(r1.parse (json, j1));
|
||||
BEAST_EXPECT(j1["max_uint"].asUInt() == max_uint);
|
||||
BEAST_EXPECT(j1["max_int"].asInt() == max_int);
|
||||
BEAST_EXPECT(j1["min_int"].asInt() == min_int);
|
||||
BEAST_EXPECT(j1["a_uint"].asUInt() == a_uint);
|
||||
BEAST_EXPECT(j1["a_large_int"].asInt() == a_large_int);
|
||||
BEAST_EXPECT(j1["a_small_int"].asInt() == a_small_int);
|
||||
|
||||
json = "{\"overflow\":";
|
||||
json += std::to_string(std::uint64_t(max_uint) + 1);
|
||||
json += "}";
|
||||
|
||||
Json::Value j2;
|
||||
Json::Reader r2;
|
||||
|
||||
BEAST_EXPECT(!r2.parse (json, j2));
|
||||
|
||||
json = "{\"underflow\":";
|
||||
json += std::to_string(std::int64_t(min_int) - 1);
|
||||
json += "}";
|
||||
|
||||
Json::Value j3;
|
||||
Json::Reader r3;
|
||||
|
||||
BEAST_EXPECT(!r3.parse (json, j3));
|
||||
|
||||
pass ();
|
||||
}
|
||||
|
||||
void
|
||||
test_copy ()
|
||||
{
|
||||
Json::Value v1{2.5};
|
||||
BEAST_EXPECT(v1.isDouble ());
|
||||
BEAST_EXPECT(v1.asDouble () == 2.5);
|
||||
|
||||
Json::Value v2 = v1;
|
||||
BEAST_EXPECT(v1.isDouble ());
|
||||
BEAST_EXPECT(v1.asDouble () == 2.5);
|
||||
BEAST_EXPECT(v2.isDouble ());
|
||||
BEAST_EXPECT(v2.asDouble () == 2.5);
|
||||
BEAST_EXPECT(v1 == v2);
|
||||
|
||||
v1 = v2;
|
||||
BEAST_EXPECT(v1.isDouble ());
|
||||
BEAST_EXPECT(v1.asDouble () == 2.5);
|
||||
BEAST_EXPECT(v2.isDouble ());
|
||||
BEAST_EXPECT(v2.asDouble () == 2.5);
|
||||
BEAST_EXPECT(v1 == v2);
|
||||
|
||||
pass ();
|
||||
}
|
||||
|
||||
void
|
||||
test_move ()
|
||||
{
|
||||
Json::Value v1{2.5};
|
||||
BEAST_EXPECT(v1.isDouble ());
|
||||
BEAST_EXPECT(v1.asDouble () == 2.5);
|
||||
|
||||
Json::Value v2 = std::move(v1);
|
||||
BEAST_EXPECT(!v1);
|
||||
BEAST_EXPECT(v2.isDouble ());
|
||||
BEAST_EXPECT(v2.asDouble () == 2.5);
|
||||
BEAST_EXPECT(v1 != v2);
|
||||
|
||||
v1 = std::move(v2);
|
||||
BEAST_EXPECT(v1.isDouble ());
|
||||
BEAST_EXPECT(v1.asDouble () == 2.5);
|
||||
BEAST_EXPECT(! v2);
|
||||
BEAST_EXPECT(v1 != v2);
|
||||
|
||||
pass ();
|
||||
}
|
||||
|
||||
void
|
||||
test_comparisons()
|
||||
{
|
||||
Json::Value a, b;
|
||||
auto testEquals = [&] (std::string const& name) {
|
||||
BEAST_EXPECT(a == b);
|
||||
BEAST_EXPECT(a <= b);
|
||||
BEAST_EXPECT(a >= b);
|
||||
|
||||
BEAST_EXPECT(! (a != b));
|
||||
BEAST_EXPECT(! (a < b));
|
||||
BEAST_EXPECT(! (a > b));
|
||||
|
||||
BEAST_EXPECT(b == a);
|
||||
BEAST_EXPECT(b <= a);
|
||||
BEAST_EXPECT(b >= a);
|
||||
|
||||
BEAST_EXPECT(! (b != a));
|
||||
BEAST_EXPECT(! (b < a));
|
||||
BEAST_EXPECT(! (b > a));
|
||||
};
|
||||
|
||||
auto testGreaterThan = [&] (std::string const& name) {
|
||||
BEAST_EXPECT(! (a == b));
|
||||
BEAST_EXPECT(! (a <= b));
|
||||
BEAST_EXPECT(a >= b);
|
||||
|
||||
BEAST_EXPECT(a != b);
|
||||
BEAST_EXPECT(! (a < b));
|
||||
BEAST_EXPECT(a > b);
|
||||
|
||||
BEAST_EXPECT(! (b == a));
|
||||
BEAST_EXPECT(b <= a);
|
||||
BEAST_EXPECT(! (b >= a));
|
||||
|
||||
BEAST_EXPECT(b != a);
|
||||
BEAST_EXPECT(b < a);
|
||||
BEAST_EXPECT(! (b > a));
|
||||
};
|
||||
|
||||
a["a"] = Json::UInt (0);
|
||||
b["a"] = Json::Int (0);
|
||||
testEquals ("zero");
|
||||
|
||||
b["a"] = Json::Int (-1);
|
||||
testGreaterThan ("negative");
|
||||
|
||||
Json::Int big = std::numeric_limits<int>::max();
|
||||
Json::UInt bigger = big;
|
||||
bigger++;
|
||||
|
||||
a["a"] = bigger;
|
||||
b["a"] = big;
|
||||
testGreaterThan ("big");
|
||||
}
|
||||
|
||||
void run ()
|
||||
{
|
||||
test_bool ();
|
||||
test_bad_json ();
|
||||
test_edge_cases ();
|
||||
test_copy ();
|
||||
test_move ();
|
||||
test_comparisons ();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(json_value, json, ripple);
|
||||
|
||||
} // ripple
|
||||
Reference in New Issue
Block a user