From 0a5505f7854da2bb8250c2b63e33dd0ff366690e Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Wed, 2 Oct 2013 11:53:18 -0700 Subject: [PATCH] Add json parsing unit test --- Builds/VisualStudio2012/RippleD.vcxproj | 6 ++ .../VisualStudio2012/RippleD.vcxproj.filters | 3 + src/ripple/json/impl/Tests.cpp | 71 +++++++++++++++++++ src/ripple/json/ripple_json.cpp | 2 + 4 files changed, 82 insertions(+) create mode 100644 src/ripple/json/impl/Tests.cpp diff --git a/Builds/VisualStudio2012/RippleD.vcxproj b/Builds/VisualStudio2012/RippleD.vcxproj index d6c4fd5f1..9c148e7b5 100644 --- a/Builds/VisualStudio2012/RippleD.vcxproj +++ b/Builds/VisualStudio2012/RippleD.vcxproj @@ -65,6 +65,12 @@ true true + + true + true + true + true + true diff --git a/Builds/VisualStudio2012/RippleD.vcxproj.filters b/Builds/VisualStudio2012/RippleD.vcxproj.filters index 22216cf48..e955735d3 100644 --- a/Builds/VisualStudio2012/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2012/RippleD.vcxproj.filters @@ -1086,6 +1086,9 @@ [1] Ripple\peerfinder\impl + + [1] Ripple\json\impl + diff --git a/src/ripple/json/impl/Tests.cpp b/src/ripple/json/impl/Tests.cpp new file mode 100644 index 000000000..628fd7e16 --- /dev/null +++ b/src/ripple/json/impl/Tests.cpp @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +/* + 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. +*/ +//============================================================================== + +namespace ripple { +using namespace beast; + +class JsonCppTests : public UnitTest +{ +public: + void testSprintf () + { + beginTestCase ("sprintf"); + + char buffer [256]; + + double const value (1.0000000000000001e+300); + + sprintf (buffer, "%#f", value); + } + + void testBadJson () + { + beginTestCase ("bad input"); + + char const* s ( + "{\"method\":\"ledger\",\"params\":[{\"ledger_index\":1e300}]}" + ); + + Json::Value j; + Json::Reader r; + + if (! r.parse (s, j)) + { + pass (); + } + else + { + fail (); + } + } + + void runTest () + { + testSprintf(); + testBadJson (); + } + + JsonCppTests () : UnitTest ("JsonCpp", "ripple") + { + } +}; + +static JsonCppTests jsonCppTests; + +} diff --git a/src/ripple/json/ripple_json.cpp b/src/ripple/json/ripple_json.cpp index 90f1cd9be..e0abdb08f 100644 --- a/src/ripple/json/ripple_json.cpp +++ b/src/ripple/json/ripple_json.cpp @@ -45,3 +45,5 @@ #include "impl/json_reader.cpp" #include "impl/json_value.cpp" #include "impl/json_writer.cpp" + +#include "impl/Tests.cpp"