Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_configuration_utils.cpp File Reference
#include <boost/test/included/unit_test.hpp>
#include <list>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <sysio/trace_api/configuration_utils.hpp>
#include <sysio/trace_api/test_common.hpp>
Include dependency graph for test_configuration_utils.cpp:

Go to the source code of this file.

Classes

struct  temp_file_fixture
 

Macros

#define BOOST_TEST_MODULE   trace_configuration_utils
 

Functions

 BOOST_AUTO_TEST_CASE (parse_kv_pairs_test)
 
 BOOST_FIXTURE_TEST_CASE (abi_def_from_file_test, temp_file_fixture)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   trace_configuration_utils

Definition at line 1 of file test_configuration_utils.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( parse_kv_pairs_test )

Definition at line 38 of file test_configuration_utils.cpp.

39 {
40 using spair = std::pair<std::string, std::string>;
41
42 // basic
43 BOOST_TEST( parse_kv_pairs("a=b") == spair("a", "b") );
44 BOOST_TEST( parse_kv_pairs("a==b") == spair("a", "=b") );
45 BOOST_TEST( parse_kv_pairs("a={}:\"=") == spair("a", "{}:\"=") );
46 BOOST_TEST( parse_kv_pairs("{}:\"=a") == spair("{}:\"", "a") );
47
48 // missing key not OK
49 BOOST_REQUIRE_THROW(parse_kv_pairs("=b"), chain::plugin_config_exception);
50
51 // missing value not OK
52 BOOST_REQUIRE_THROW(parse_kv_pairs("a="), chain::plugin_config_exception);
53
54 // missing = not OK
55 BOOST_REQUIRE_THROW(parse_kv_pairs("a"), chain::plugin_config_exception);
56
57 // emptynot OK
58 BOOST_REQUIRE_THROW(parse_kv_pairs(""), chain::plugin_config_exception);
59
60 }
std::pair< std::string, std::string > parse_kv_pairs(const std::string &input)
Here is the call graph for this function:

◆ BOOST_FIXTURE_TEST_CASE()

BOOST_FIXTURE_TEST_CASE ( abi_def_from_file_test ,
temp_file_fixture  )

Definition at line 62 of file test_configuration_utils.cpp.

63 {
64 auto data_dir = fc::path(bfs::temp_directory_path());
65 auto good_json = std::string("{\"version\" : \"test string please ignore\"}");
66 auto good_json_filename = create_temp_file(good_json);
67 auto relative_json_filename = bfs::path(good_json_filename).filename().generic_string();
68
69 auto good_abi = chain::abi_def();
70 good_abi.version = "test string please ignore";
71
72 auto bad_json = std::string("{{\"version\":oops\"}");
73 auto bad_json_filename = create_temp_file(bad_json);
74 auto bad_filename = (bfs::temp_directory_path() / bfs::unique_path()).generic_string();
75 auto directory_name = bfs::temp_directory_path().generic_string();
76
77 // good cases
78 BOOST_TEST( abi_def_from_file(good_json_filename, data_dir) == good_abi );
79 BOOST_TEST( abi_def_from_file(relative_json_filename, data_dir) == good_abi );
80
81 // bad cases
82 BOOST_REQUIRE_THROW( abi_def_from_file(bad_json_filename, data_dir), chain::json_parse_exception );
83 BOOST_REQUIRE_THROW( abi_def_from_file(bad_filename, data_dir), chain::plugin_config_exception );
84 BOOST_REQUIRE_THROW( abi_def_from_file(directory_name, data_dir), chain::plugin_config_exception );
85 }
wraps boost::filesystem::path to provide platform independent path manipulation.
chain::abi_def abi_def_from_file(const std::string &file_name, const fc::path &data_dir)
Here is the call graph for this function: