aboutsummaryrefslogtreecommitdiff
path: root/src/test/script_tests.cpp
diff options
context:
space:
mode:
authorCory Fields <cory-nospam-@coryfields.com>2013-09-10 15:18:09 -0400
committerCory Fields <cory-nospam-@coryfields.com>2013-09-16 12:53:11 -0400
commit152e51c7af2624831cc4796e06bf3b72787cc85f (patch)
treed943cbc4159b2e88f0ee68907edf51b9f673d6a8 /src/test/script_tests.cpp
parent08081e393b6d3249c19395f91537a7d824ec7333 (diff)
included-tests: generate binary data from test files for inclusion into test binaries
This change moves test data into the binaries rather than reading them from the disk at runtime. Advantages: - Tests become distributable - Cross-compile friendly. Build on one machine and execute in an arbitrary location on another. - Easier testing for backports. Users can verify that tests pass without having to track down corresponding test data. - More trustworthy test results and easier quality assurance as tests make fewer assumptions about their environment. - Tests could theoretically run at client/daemon startup and exit on failure. Disadvantages: - Required 'hexdump' build-dependency. This is a standard bsd tool that should be usable everywhere. It is likely already installed on all build-machines. - Tests can no longer be fudged after build by altering test-data.
Diffstat (limited to 'src/test/script_tests.cpp')
-rw-r--r--src/test/script_tests.cpp33
1 files changed, 8 insertions, 25 deletions
diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp
index 423a2ff185..dfa5529b87 100644
--- a/src/test/script_tests.cpp
+++ b/src/test/script_tests.cpp
@@ -14,6 +14,8 @@
#include "main.h"
#include "wallet.h"
+#include "data/script_invalid.json.h"
+#include "data/script_valid.json.h"
using namespace std;
using namespace json_spirit;
@@ -90,34 +92,15 @@ ParseScript(string s)
}
Array
-read_json(const std::string& filename)
+read_json(const std::string& jsondata)
{
- namespace fs = boost::filesystem;
- fs::path testFile = fs::current_path() / "data" / filename;
-
-#ifdef TEST_DATA_DIR
- if (!fs::exists(testFile))
- {
- testFile = fs::path(BOOST_PP_STRINGIZE(TEST_DATA_DIR)) / filename;
- }
-#endif
-
- ifstream ifs(testFile.string().c_str(), ifstream::in);
Value v;
- if (!read_stream(ifs, v))
- {
- if (ifs.fail())
- BOOST_ERROR("Cound not find/open " << filename);
- else
- BOOST_ERROR("JSON syntax error in " << filename);
- return Array();
- }
- if (v.type() != array_type)
+
+ if (!read_string(jsondata, v) || v.type() != array_type)
{
- BOOST_ERROR(filename << " does not contain a json array");
+ BOOST_ERROR("Parse error.");
return Array();
}
-
return v.get_array();
}
@@ -130,7 +113,7 @@ BOOST_AUTO_TEST_CASE(script_valid)
// Inner arrays are [ "scriptSig", "scriptPubKey" ]
// ... where scriptSig and scriptPubKey are stringified
// scripts.
- Array tests = read_json("script_valid.json");
+ Array tests = read_json(std::string(json_tests::script_valid, json_tests::script_valid + sizeof(json_tests::script_valid)));
BOOST_FOREACH(Value& tv, tests)
{
@@ -154,7 +137,7 @@ BOOST_AUTO_TEST_CASE(script_valid)
BOOST_AUTO_TEST_CASE(script_invalid)
{
// Scripts that should evaluate as invalid
- Array tests = read_json("script_invalid.json");
+ Array tests = read_json(std::string(json_tests::script_invalid, json_tests::script_invalid + sizeof(json_tests::script_invalid)));
BOOST_FOREACH(Value& tv, tests)
{