Commit 82c1888d authored by Lefebvre, Jordan's avatar Lefebvre, Jordan

Adding json parser failure/pass and benchmark tests.

parent 83f614eb
Pipeline #96067 failed with stages
in 77 minutes and 29 seconds
......@@ -214,7 +214,10 @@ class Timer
return seconds(mDuration).count();
}
}; // class Timer
bool running() const { return mRunning; };
};
// class Timer
} // namespace radix
#if RADIX_TIMING > 0
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
"A JSON payload should be an object or array, not a string."
\ No newline at end of file
["Unclosed array"
\ No newline at end of file
{unquoted_key: "keys must be quoted"}
\ No newline at end of file
["extra comma",]
\ No newline at end of file
["double extra comma",,]
\ No newline at end of file
[ , "<-- missing value"]
\ No newline at end of file
["Comma after the close"],
\ No newline at end of file
["Extra close"]]
\ No newline at end of file
{"Extra comma": true,}
\ No newline at end of file
{"Extra value after close": true} "misplaced quoted value"
\ No newline at end of file
{"Illegal expression": 1 + 2}
\ No newline at end of file
{"Illegal invocation": alert()}
\ No newline at end of file
{"Numbers cannot have leading zeroes": 013}
\ No newline at end of file
{"Numbers cannot be hex": 0x14}
\ No newline at end of file
["Illegal backslash escape: \x15"]
\ No newline at end of file
[\naked]
\ No newline at end of file
["Illegal backslash escape: \017"]
\ No newline at end of file
[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]
\ No newline at end of file
{"Missing colon" null}
\ No newline at end of file
{"Double colon":: null}
\ No newline at end of file
{"Comma instead of colon", null}
\ No newline at end of file
["Colon instead of comma": false]
\ No newline at end of file
["Bad value", truth]
\ No newline at end of file
['single quote']
\ No newline at end of file
[" tab character in string "]
\ No newline at end of file
["tab\ character\ in\ string\ "]
\ No newline at end of file
["line
break"]
\ No newline at end of file
["line\
break"]
\ No newline at end of file
[0e]
\ No newline at end of file
[0e+]
\ No newline at end of file
[0e+-1]
\ No newline at end of file
{"Comma instead if closing brace": true,
\ No newline at end of file
["mismatch"}
\ No newline at end of file
[
"JSON Test Pattern pass1",
{"object with 1 member":["array with 1 element"]},
{},
[],
-42,
true,
false,
null,
{
"integer": 1234567890,
"real": -9876.543210,
"e": 0.123456789e-12,
"E": 1.234567890E+34,
"": 23456789012E66,
"zero": 0,
"one": 1,
"space": " ",
"quote": "\"",
"backslash": "\\",
"controls": "\b\f\n\r\t",
"slash": "/ & \/",
"alpha": "abcdefghijklmnopqrstuvwyz",
"ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
"digit": "0123456789",
"0123456789": "digit",
"special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
"hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
"true": true,
"false": false,
"null": null,
"array":[ ],
"object":{ },
"address": "50 St. James Street",
"url": "http://www.JSON.org/",
"comment": "// /* <!-- --",
"# -- --> */": " ",
" s p a c e d " :[1,2 , 3
,
4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7],
"jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
"quotes": "&#34; \u0022 %22 0x22 034 &#x22;",
"\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
: "A key can be any string"
},
0.5 ,98.6
,
99.44
,
1066,
1e1,
0.1e1,
1e-1,
1e00,2e+00,2e-00
,"rosebud"]
\ No newline at end of file
[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
\ No newline at end of file
{
"JSON Test Pattern pass3": {
"The outermost value": "must be an object or array.",
"In this test": "It is an object."
}
}
[null]
\ No newline at end of file
[true]
\ No newline at end of file
[false]
\ No newline at end of file
[0]
\ No newline at end of file
["foo"]
\ No newline at end of file
[]
\ No newline at end of file
{}
\ No newline at end of file
[0,1]
\ No newline at end of file
{"foo":"bar"}
\ No newline at end of file
{"a":null,"foo":"bar"}
\ No newline at end of file
[-1]
\ No newline at end of file
[-2147483648]
\ No newline at end of file
[-1234567890123456789]
\ No newline at end of file
[-9223372036854775808]
\ No newline at end of file
[1]
\ No newline at end of file
[2147483647]
\ No newline at end of file
[4294967295]
\ No newline at end of file
[1234567890123456789]
\ No newline at end of file
[9223372036854775807]
\ No newline at end of file
[0.0]
\ No newline at end of file
[-0.0]
\ No newline at end of file
[1.2345]
\ No newline at end of file
[-1.2345]
\ No newline at end of file
[5e-324]
\ No newline at end of file
[2.225073858507201e-308]
\ No newline at end of file
[2.2250738585072014e-308]
\ No newline at end of file
[1.7976931348623157e308]
\ No newline at end of file
#include "gtest/gtest.h"
#include "radixbug/bug.hh"
#include "radixcore/json.hh"
#include "radixcore/system.hh"
......@@ -230,3 +231,108 @@ TEST(JSONParser, parse_from_stream)
EXPECT_EQ("string missing closing quote at line 1 column 5", errorMsg);
}
}
bool parse_and_test(const std::string& file)
{
std::cout << "PARSE_AND_TEST(" << file << ")" << std::endl;
Timer benchmark_timer;
JSONParser parser;
std::string filename =
to_native_path(dirname(__FILE__) + "/testfiles/" + file);
std::cout << "Test file: " << filename << std::endl;
bool benchmark = (file.substr(0, 4).compare("benc") == 0);
if (benchmark)
{
benchmark_timer.start();
}
bool success = parser.parse_from_file(filename);
if (benchmark) benchmark_timer.stop();
bool return_success = false;
// check if failure is expected
if (file.substr(0, 4).compare("fail") == 0)
{
return_success = !success;
}
if (!return_success)
{
// dump the json error
std::cout << parser.last_error() << std::endl;
}
if (benchmark)
{
std::cout << "Benchmark(" << file
<< ") timing: " << (benchmark_timer.duration() / 1e9)
<< " seconds" << std::endl;
}
return return_success;
}
TEST(JSONParser, JSONChecker)
{
// EXPECT_TRUE(parse_and_test("fail01_EXCLUDE.json"));
EXPECT_TRUE(parse_and_test("fail02.json"));
EXPECT_TRUE(parse_and_test("fail03.json"));
EXPECT_TRUE(parse_and_test("fail04.json"));
EXPECT_TRUE(parse_and_test("fail05.json"));
EXPECT_TRUE(parse_and_test("fail06.json"));
EXPECT_TRUE(parse_and_test("fail07.json"));
EXPECT_TRUE(parse_and_test("fail08.json"));
EXPECT_TRUE(parse_and_test("fail09.json"));
EXPECT_TRUE(parse_and_test("fail10.json"));
EXPECT_TRUE(parse_and_test("fail11.json"));
EXPECT_TRUE(parse_and_test("fail12.json"));
EXPECT_TRUE(parse_and_test("fail13.json"));
EXPECT_TRUE(parse_and_test("fail14.json"));
EXPECT_TRUE(parse_and_test("fail15.json"));
EXPECT_TRUE(parse_and_test("fail16.json"));
EXPECT_TRUE(parse_and_test("fail17.json"));
// EXPECT_TRUE(parse_and_test("fail18_EXCLUDE.json"));
EXPECT_TRUE(parse_and_test("fail19.json"));
EXPECT_TRUE(parse_and_test("fail20.json"));
EXPECT_TRUE(parse_and_test("fail21.json"));
EXPECT_TRUE(parse_and_test("fail22.json"));
EXPECT_TRUE(parse_and_test("fail23.json"));
EXPECT_TRUE(parse_and_test("fail24.json"));
EXPECT_TRUE(parse_and_test("fail25.json"));
EXPECT_TRUE(parse_and_test("fail26.json"));
EXPECT_TRUE(parse_and_test("fail27.json"));
EXPECT_TRUE(parse_and_test("fail28.json"));
EXPECT_TRUE(parse_and_test("fail29.json"));
EXPECT_TRUE(parse_and_test("fail30.json"));
EXPECT_TRUE(parse_and_test("fail31.json"));
EXPECT_TRUE(parse_and_test("fail32.json"));
EXPECT_TRUE(parse_and_test("fail33.json"));
EXPECT_TRUE(parse_and_test("pass01.json"));
EXPECT_TRUE(parse_and_test("pass02.json"));
EXPECT_TRUE(parse_and_test("pass03.json"));
// EXPECT_TRUE(parse_and_test("roundtrip01.json"));
// EXPECT_TRUE(parse_and_test("roundtrip02.json"));
// EXPECT_TRUE(parse_and_test("roundtrip03.json"));
// EXPECT_TRUE(parse_and_test("roundtrip04.json"));
// EXPECT_TRUE(parse_and_test("roundtrip05.json"));
// EXPECT_TRUE(parse_and_test("roundtrip06.json"));
// EXPECT_TRUE(parse_and_test("roundtrip07.json"));
// EXPECT_TRUE(parse_and_test("roundtrip08.json"));
// EXPECT_TRUE(parse_and_test("roundtrip09.json"));
// EXPECT_TRUE(parse_and_test("roundtrip10.json"));
// EXPECT_TRUE(parse_and_test("roundtrip11.json"));
// EXPECT_TRUE(parse_and_test("roundtrip12.json"));
// EXPECT_TRUE(parse_and_test("roundtrip13.json"));
// EXPECT_TRUE(parse_and_test("roundtrip14.json"));
// EXPECT_TRUE(parse_and_test("roundtrip15.json"));
// EXPECT_TRUE(parse_and_test("roundtrip16.json"));
// EXPECT_TRUE(parse_and_test("roundtrip17.json"));
// EXPECT_TRUE(parse_and_test("roundtrip18.json"));
// EXPECT_TRUE(parse_and_test("roundtrip19.json"));
// EXPECT_TRUE(parse_and_test("roundtrip20.json"));
// EXPECT_TRUE(parse_and_test("roundtrip21.json"));
// EXPECT_TRUE(parse_and_test("roundtrip22.json"));
// EXPECT_TRUE(parse_and_test("roundtrip23.json"));
// EXPECT_TRUE(parse_and_test("roundtrip24.json"));
// EXPECT_TRUE(parse_and_test("roundtrip25.json"));
// EXPECT_TRUE(parse_and_test("roundtrip26.json"));
// EXPECT_TRUE(parse_and_test("roundtrip27.json"));
EXPECT_TRUE(parse_and_test("benchmark_canada.json"));
EXPECT_TRUE(parse_and_test("benchmark_citm_catalog.json"));
EXPECT_TRUE(parse_and_test("benchmark_twitter.json"));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment