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.
This commit is contained in:
@@ -2,20 +2,21 @@
|
||||
#include "json/json_spirit_reader_template.h"
|
||||
#include "json/json_spirit_writer_template.h"
|
||||
#include "json/json_spirit_utils.h"
|
||||
#include "data/base58_encode_decode.json.h"
|
||||
#include "data/base58_keys_invalid.json.h"
|
||||
#include "data/base58_keys_valid.json.h"
|
||||
|
||||
#include "base58.h"
|
||||
#include "util.h"
|
||||
|
||||
using namespace json_spirit;
|
||||
extern Array read_json(const std::string& filename);
|
||||
extern Array read_json(const std::string& jsondata);
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(base58_tests)
|
||||
|
||||
// Goal: test low-level base58 encoding functionality
|
||||
BOOST_AUTO_TEST_CASE(base58_EncodeBase58)
|
||||
{
|
||||
Array tests = read_json("base58_encode_decode.json");
|
||||
|
||||
Array tests = read_json(std::string(json_tests::base58_encode_decode, json_tests::base58_encode_decode + sizeof(json_tests::base58_encode_decode)));
|
||||
BOOST_FOREACH(Value& tv, tests)
|
||||
{
|
||||
Array test = tv.get_array();
|
||||
@@ -36,7 +37,7 @@ BOOST_AUTO_TEST_CASE(base58_EncodeBase58)
|
||||
// Goal: test low-level base58 decoding functionality
|
||||
BOOST_AUTO_TEST_CASE(base58_DecodeBase58)
|
||||
{
|
||||
Array tests = read_json("base58_encode_decode.json");
|
||||
Array tests = read_json(std::string(json_tests::base58_encode_decode, json_tests::base58_encode_decode + sizeof(json_tests::base58_encode_decode)));
|
||||
std::vector<unsigned char> result;
|
||||
|
||||
BOOST_FOREACH(Value& tv, tests)
|
||||
@@ -104,7 +105,7 @@ public:
|
||||
// Goal: check that parsed keys match test payload
|
||||
BOOST_AUTO_TEST_CASE(base58_keys_valid_parse)
|
||||
{
|
||||
Array tests = read_json("base58_keys_valid.json");
|
||||
Array tests = read_json(std::string(json_tests::base58_keys_valid, json_tests::base58_keys_valid + sizeof(json_tests::base58_keys_valid)));
|
||||
std::vector<unsigned char> result;
|
||||
CBitcoinSecret secret;
|
||||
CBitcoinAddress addr;
|
||||
@@ -163,7 +164,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_parse)
|
||||
// Goal: check that generated keys match test vectors
|
||||
BOOST_AUTO_TEST_CASE(base58_keys_valid_gen)
|
||||
{
|
||||
Array tests = read_json("base58_keys_valid.json");
|
||||
Array tests = read_json(std::string(json_tests::base58_keys_valid, json_tests::base58_keys_valid + sizeof(json_tests::base58_keys_valid)));
|
||||
std::vector<unsigned char> result;
|
||||
BOOST_FOREACH(Value& tv, tests)
|
||||
{
|
||||
@@ -231,7 +232,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_gen)
|
||||
// Goal: check that base58 parsing code is robust against a variety of corrupted data
|
||||
BOOST_AUTO_TEST_CASE(base58_keys_invalid)
|
||||
{
|
||||
Array tests = read_json("base58_keys_invalid.json"); // Negative testcases
|
||||
Array tests = read_json(std::string(json_tests::base58_keys_invalid, json_tests::base58_keys_invalid + sizeof(json_tests::base58_keys_invalid))); // Negative testcases
|
||||
std::vector<unsigned char> result;
|
||||
CBitcoinSecret secret;
|
||||
CBitcoinAddress addr;
|
||||
|
||||
Reference in New Issue
Block a user