mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
Squashed 'src/univalue/' content from commit 87d9045
git-subtree-dir: src/univalue git-subtree-split: 87d90455ff5e87dedc304353aa23ace47ffb6c1c
This commit is contained in:
7
test/.gitignore
vendored
Normal file
7
test/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
unitester
|
||||
|
||||
*.log
|
||||
*.trs
|
||||
|
||||
.libs
|
||||
1
test/fail1.json
Normal file
1
test/fail1.json
Normal file
@@ -0,0 +1 @@
|
||||
"A JSON payload should be an object or array, not a string."
|
||||
1
test/fail10.json
Normal file
1
test/fail10.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Extra value after close": true} "misplaced quoted value"
|
||||
1
test/fail11.json
Normal file
1
test/fail11.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Illegal expression": 1 + 2}
|
||||
1
test/fail12.json
Normal file
1
test/fail12.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Illegal invocation": alert()}
|
||||
1
test/fail13.json
Normal file
1
test/fail13.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Numbers cannot have leading zeroes": 013}
|
||||
1
test/fail14.json
Normal file
1
test/fail14.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Numbers cannot be hex": 0x14}
|
||||
1
test/fail15.json
Normal file
1
test/fail15.json
Normal file
@@ -0,0 +1 @@
|
||||
["Illegal backslash escape: \x15"]
|
||||
1
test/fail16.json
Normal file
1
test/fail16.json
Normal file
@@ -0,0 +1 @@
|
||||
[\naked]
|
||||
1
test/fail17.json
Normal file
1
test/fail17.json
Normal file
@@ -0,0 +1 @@
|
||||
["Illegal backslash escape: \017"]
|
||||
1
test/fail18.json
Normal file
1
test/fail18.json
Normal file
@@ -0,0 +1 @@
|
||||
[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]
|
||||
1
test/fail19.json
Normal file
1
test/fail19.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Missing colon" null}
|
||||
1
test/fail2.json
Normal file
1
test/fail2.json
Normal file
@@ -0,0 +1 @@
|
||||
["Unclosed array"
|
||||
1
test/fail20.json
Normal file
1
test/fail20.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Double colon":: null}
|
||||
1
test/fail21.json
Normal file
1
test/fail21.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Comma instead of colon", null}
|
||||
1
test/fail22.json
Normal file
1
test/fail22.json
Normal file
@@ -0,0 +1 @@
|
||||
["Colon instead of comma": false]
|
||||
1
test/fail23.json
Normal file
1
test/fail23.json
Normal file
@@ -0,0 +1 @@
|
||||
["Bad value", truth]
|
||||
1
test/fail24.json
Normal file
1
test/fail24.json
Normal file
@@ -0,0 +1 @@
|
||||
['single quote']
|
||||
1
test/fail25.json
Normal file
1
test/fail25.json
Normal file
@@ -0,0 +1 @@
|
||||
[" tab character in string "]
|
||||
1
test/fail26.json
Normal file
1
test/fail26.json
Normal file
@@ -0,0 +1 @@
|
||||
["tab\ character\ in\ string\ "]
|
||||
2
test/fail27.json
Normal file
2
test/fail27.json
Normal file
@@ -0,0 +1,2 @@
|
||||
["line
|
||||
break"]
|
||||
2
test/fail28.json
Normal file
2
test/fail28.json
Normal file
@@ -0,0 +1,2 @@
|
||||
["line\
|
||||
break"]
|
||||
1
test/fail29.json
Normal file
1
test/fail29.json
Normal file
@@ -0,0 +1 @@
|
||||
[0e]
|
||||
1
test/fail3.json
Normal file
1
test/fail3.json
Normal file
@@ -0,0 +1 @@
|
||||
{unquoted_key: "keys must be quoted"}
|
||||
1
test/fail30.json
Normal file
1
test/fail30.json
Normal file
@@ -0,0 +1 @@
|
||||
[0e+]
|
||||
1
test/fail31.json
Normal file
1
test/fail31.json
Normal file
@@ -0,0 +1 @@
|
||||
[0e+-1]
|
||||
1
test/fail32.json
Normal file
1
test/fail32.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Comma instead if closing brace": true,
|
||||
1
test/fail33.json
Normal file
1
test/fail33.json
Normal file
@@ -0,0 +1 @@
|
||||
["mismatch"}
|
||||
1
test/fail34.json
Normal file
1
test/fail34.json
Normal file
@@ -0,0 +1 @@
|
||||
{} garbage
|
||||
1
test/fail4.json
Normal file
1
test/fail4.json
Normal file
@@ -0,0 +1 @@
|
||||
["extra comma",]
|
||||
1
test/fail5.json
Normal file
1
test/fail5.json
Normal file
@@ -0,0 +1 @@
|
||||
["double extra comma",,]
|
||||
1
test/fail6.json
Normal file
1
test/fail6.json
Normal file
@@ -0,0 +1 @@
|
||||
[ , "<-- missing value"]
|
||||
1
test/fail7.json
Normal file
1
test/fail7.json
Normal file
@@ -0,0 +1 @@
|
||||
["Comma after the close"],
|
||||
1
test/fail8.json
Normal file
1
test/fail8.json
Normal file
@@ -0,0 +1 @@
|
||||
["Extra close"]]
|
||||
1
test/fail9.json
Normal file
1
test/fail9.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Extra comma": true,}
|
||||
58
test/pass1.json
Normal file
58
test/pass1.json
Normal file
@@ -0,0 +1,58 @@
|
||||
[
|
||||
"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": "" \u0022 %22 0x22 034 "",
|
||||
"\/\\\"\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"]
|
||||
1
test/pass2.json
Normal file
1
test/pass2.json
Normal file
@@ -0,0 +1 @@
|
||||
[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
|
||||
6
test/pass3.json
Normal file
6
test/pass3.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"JSON Test Pattern pass3": {
|
||||
"The outermost value": "must be an object or array.",
|
||||
"In this test": "It is an object."
|
||||
}
|
||||
}
|
||||
115
test/unitester.cpp
Normal file
115
test/unitester.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
// Copyright 2014 BitPay Inc.
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include "univalue.h"
|
||||
|
||||
#ifndef JSON_TEST_SRC
|
||||
#error JSON_TEST_SRC must point to test source directory
|
||||
#endif
|
||||
|
||||
#ifndef ARRAY_SIZE
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
string srcdir(JSON_TEST_SRC);
|
||||
|
||||
static void runtest(string filename, const string& jdata)
|
||||
{
|
||||
fprintf(stderr, "test %s\n", filename.c_str());
|
||||
|
||||
string prefix = filename.substr(0, 4);
|
||||
|
||||
bool wantPass = (prefix == "pass");
|
||||
bool wantFail = (prefix == "fail");
|
||||
assert(wantPass || wantFail);
|
||||
|
||||
UniValue val;
|
||||
bool testResult = val.read(jdata);
|
||||
|
||||
if (wantPass) {
|
||||
assert(testResult == true);
|
||||
} else {
|
||||
assert(testResult == false);
|
||||
}
|
||||
}
|
||||
|
||||
static void runtest_file(const char *filename_)
|
||||
{
|
||||
string basename(filename_);
|
||||
string filename = srcdir + "/" + basename;
|
||||
FILE *f = fopen(filename.c_str(), "r");
|
||||
assert(f != NULL);
|
||||
|
||||
string jdata;
|
||||
|
||||
char buf[4096];
|
||||
while (!feof(f)) {
|
||||
int bread = fread(buf, 1, sizeof(buf), f);
|
||||
assert(!ferror(f));
|
||||
|
||||
string s(buf, bread);
|
||||
jdata += s;
|
||||
}
|
||||
|
||||
assert(!ferror(f));
|
||||
fclose(f);
|
||||
|
||||
runtest(basename, jdata);
|
||||
}
|
||||
|
||||
static const char *filenames[] = {
|
||||
"fail10.json",
|
||||
"fail11.json",
|
||||
"fail12.json",
|
||||
"fail13.json",
|
||||
"fail14.json",
|
||||
"fail15.json",
|
||||
"fail16.json",
|
||||
"fail17.json",
|
||||
//"fail18.json", // investigate
|
||||
"fail19.json",
|
||||
"fail1.json",
|
||||
"fail20.json",
|
||||
"fail21.json",
|
||||
"fail22.json",
|
||||
"fail23.json",
|
||||
"fail24.json",
|
||||
"fail25.json",
|
||||
"fail26.json",
|
||||
"fail27.json",
|
||||
"fail28.json",
|
||||
"fail29.json",
|
||||
"fail2.json",
|
||||
"fail30.json",
|
||||
"fail31.json",
|
||||
"fail32.json",
|
||||
"fail33.json",
|
||||
"fail34.json",
|
||||
"fail3.json",
|
||||
"fail4.json", // extra comma
|
||||
"fail5.json",
|
||||
"fail6.json",
|
||||
"fail7.json",
|
||||
"fail8.json",
|
||||
"fail9.json", // extra comma
|
||||
"pass1.json",
|
||||
"pass2.json",
|
||||
"pass3.json",
|
||||
};
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
for (unsigned int fidx = 0; fidx < ARRAY_SIZE(filenames); fidx++) {
|
||||
runtest_file(filenames[fidx]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user