diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2015-10-01 16:23:59 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2015-10-01 16:36:15 +0200 |
commit | f297042cae572753e6c25d25caf92091e88b76df (patch) | |
tree | 59a0827f7d3500f1b145e4f5653f1f8b94c1e037 /src/univalue/test/unitester.cpp | |
parent | 17d0e638b66b9dd51370335c9b0a7039de3f81fa (diff) | |
parent | 95acf3cc6d90d9406030ce897efdee8be0550a53 (diff) | |
download | bitcoin-f297042cae572753e6c25d25caf92091e88b76df.tar.xz |
Merge pull request #6637
95acf3c remove $(@F) and subdirs from univalue make (Jonas Schnelli)
9623e93 [Univalue] add univalue over subtree (Jonas Schnelli)
2f9f082 Squashed 'src/univalue/' content from commit 87d9045 (Jonas Schnelli)
0917306 remove univalue, prepare for subtree (Jonas Schnelli)
Diffstat (limited to 'src/univalue/test/unitester.cpp')
-rw-r--r-- | src/univalue/test/unitester.cpp | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/src/univalue/test/unitester.cpp b/src/univalue/test/unitester.cpp new file mode 100644 index 0000000000..835556e031 --- /dev/null +++ b/src/univalue/test/unitester.cpp @@ -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; +} + |