Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_static_variant.cpp File Reference
#include <boost/test/included/unit_test.hpp>
#include <fc/exception/exception.hpp>
#include <fc/static_variant.hpp>
#include <fc/variant.hpp>
Include dependency graph for test_static_variant.cpp:

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   static_variant
 

Functions

 BOOST_AUTO_TEST_CASE (to_from_fc_variant)
 
 BOOST_AUTO_TEST_CASE (get)
 
 BOOST_AUTO_TEST_CASE (static_variant_from_index)
 
 BOOST_AUTO_TEST_CASE (static_variant_get_index)
 

Macro Definition Documentation

◆ BOOST_TEST_MODULE

#define BOOST_TEST_MODULE   static_variant

Definition at line 1 of file test_static_variant.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/4]

BOOST_AUTO_TEST_CASE ( get )

Definition at line 22 of file test_static_variant.cpp.

23 {
24 using variant_type = std::variant<int32_t, bool, std::string>;
25
26 auto v1 = variant_type{std::string{"hello world"}};
27 BOOST_CHECK_EXCEPTION(std::get<int32_t>(v1), std::bad_variant_access, [](const auto& e) { return true; });
28 auto result1 = std::get<std::string>(v1);
29 BOOST_REQUIRE(result1 == std::string{"hello world"});
30
31 const auto v2 = variant_type{std::string{"hello world"}};
32 BOOST_CHECK_EXCEPTION(std::get<int32_t>(v2), std::bad_variant_access, [](const auto& e) { return true; });
33 const auto result2 = std::get<std::string>(v2);
34 BOOST_REQUIRE(result2 == std::string{"hello world"});
35 }

◆ BOOST_AUTO_TEST_CASE() [2/4]

BOOST_AUTO_TEST_CASE ( static_variant_from_index )

Definition at line 37 of file test_static_variant.cpp.

38 {
39 using variant_type = std::variant<int32_t, bool, std::string>;
40 auto v = variant_type{};
41
42 BOOST_CHECK_EXCEPTION(fc::from_index(v, 3), fc::assert_exception, [](const auto& e) { return e.code() == fc::assert_exception_code; });
43
44 fc::from_index(v, 2);
45 BOOST_REQUIRE(std::string{} == std::get<std::string>(v));
46 }
@ assert_exception_code
Definition exception.hpp:30
void from_index(variant &v, int index)
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/4]

BOOST_AUTO_TEST_CASE ( static_variant_get_index )

Definition at line 48 of file test_static_variant.cpp.

49 {
50 using variant_type = std::variant<int32_t, bool, std::string>;
51 BOOST_REQUIRE((fc::get_index<variant_type, int32_t>() == 0));
52 BOOST_REQUIRE((fc::get_index<variant_type, bool>() == 1));
53 BOOST_REQUIRE((fc::get_index<variant_type, std::string>() == 2));
54 BOOST_REQUIRE((fc::get_index<variant_type, double>() == std::variant_size_v<variant_type>)); // Isn't a type contained in variant.
55 }
constexpr std::size_t get_index()
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/4]

BOOST_AUTO_TEST_CASE ( to_from_fc_variant )

Definition at line 8 of file test_static_variant.cpp.

9 {
10 using variant_type = std::variant<int32_t, bool>;
11 auto std_variant_1 = variant_type{false};
12 auto fc_variant = fc::variant{};
13
14 fc::to_variant(std_variant_1, fc_variant);
15
16 auto std_variant_2 = variant_type{};
17 fc::from_variant(fc_variant, std_variant_2);
18
19 BOOST_REQUIRE(std_variant_1 == std_variant_2);
20 }
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
void from_variant(const fc::variant &v, sysio::chain::chain_id_type &cid)
void to_variant(const sysio::chain::shared_public_key &var, fc::variant &vo)
Definition authority.cpp:4
Here is the call graph for this function: