1 // Copyright (c) 2016-2021 Antony Polukhin
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #include <boost/pfr/io.hpp>
7
8 #include <sstream>
9 #include <string>
10
11 #include <boost/core/lightweight_test.hpp>
12
13 template <class T>
test_write_read(const T & value)14 void test_write_read(const T& value) {
15 T result;
16 std::stringstream ss;
17 ss << boost::pfr::io(value);
18 ss >> boost::pfr::io(result);
19 BOOST_TEST_EQ(value.f0, result.f0);
20 BOOST_TEST_EQ(value.f1, result.f1);
21 BOOST_TEST_EQ(value.f2, result.f2);
22 BOOST_TEST_EQ(value.f3, result.f3);
23 BOOST_TEST_EQ(value.f4, result.f4);
24 }
25
26 template <class T>
to_string_test(const T & value,const char * ethalon)27 void to_string_test(const T& value, const char* ethalon) {
28 std::stringstream ss;
29 ss << boost::pfr::io(value);
30 BOOST_TEST_EQ(ss.str(), ethalon);
31 }
32
33 template <class T>
test_type(const T & value,const char * ethalon)34 void test_type(const T& value, const char* ethalon) {
35 test_write_read(value);
36 to_string_test(value, ethalon);
37 }
38
39
main()40 int main() {
41 #if !defined(_MSC_VER) /* TODO: remove after fixing strange errors https://ci.appveyor.com/project/apolukhin/magic-get/build/1.65.108-develop */
42 struct test4 {
43 int f0;
44 std::string f1;
45 char f2;
46 int f3;
47 std::string f4;
48 };
49 test_type(
50 test4{1, {"my o my"}, '3', 4, {"hello there!"} },
51 "{1, \"my o my\", 3, 4, \"hello there!\"}"
52 );
53
54 #if 0
55 // TODO:
56 std::string f1_referenced{"my O my"};
57 std::string f4_referenced{"Hello There!"};
58 struct test5 {
59 int f0;
60 const std::string& f1;
61 char f2;
62 int f3;
63 const std::string& f4;
64 };
65 to_string_test(
66 test5{1, f1_referenced, '3', 4, f4_referenced },
67 "{1, \"my o my\", 3, 4, \"hello there!\"}"
68 );
69 #endif
70 #endif
71
72 return boost::report_errors();
73 }
74
75
76