Update contrib.
1 //-----------------------------------------------------------------------------
2 // boost-libs variant/test/test1.cpp header file
3 // See http://www.boost.org for updates, documentation, and revision history.
4 //-----------------------------------------------------------------------------
7 // Eric Friedman, Itay Maman
9 // Distributed under the Boost Software License, Version 1.0. (See
10 // accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
13 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
16 #include "boost/test/minimal.hpp"
17 #include "boost/variant.hpp"
27 #include "std_log_result.h"
28 #define LOG_FILENAME_LINE __FILE__, __LINE__
34 using boost::apply_visitor;
43 typedef variant< char*, string, short > t_var0;
44 typedef variant< int, string, double > t_var1;
45 typedef variant< short, const char* > t_var2;
46 typedef variant< string, char > t_var3;
47 typedef variant< unsigned short, const char* > t_var4;
48 typedef variant< unsigned short, const char*, t_var2 > t_var5;
49 typedef variant< unsigned short, const char*, t_var5 > t_var6;
50 typedef variant< class_a, const void* > t_var7;
51 typedef variant< t_var6, int > t_var8;
52 typedef variant< t_var8, unsigned short > t_var9;
53 typedef variant< char, unsigned char > t_var10;
54 typedef variant< short, int, vector<int>, long> t_var11;
71 // Check assignment rules
76 verify(v4, spec<unsigned short>());
80 verify(v4, spec<const char*>(), "[V] abc");
83 verify(v5, spec<const char*>(), "[V] def");
86 verify(v5, spec<t_var2>(), "[V] [V] abc");
89 verify(v6, spec<unsigned short>(), "[V] 58");
92 verify(v6, spec<t_var5>(), "[V] [V] [V] abc");
95 verify(v8, spec<t_var6>(), "[V] [V] abc");
98 verify(v8, spec<t_var6>(), "[V] [V] [V] [V] abc");
101 verify(v7, spec<const void*>());
104 verify(v7, spec<class_a>(), "[V] class_a(199)");
108 verify(v7, spec<class_a>(), "[V] class_a(200)");
113 // Check sizes of held values
118 apply_visitor(ts, v1);
121 apply_visitor(ts, v1);
124 apply_visitor(ts, v1);
126 BOOST_CHECK(ts.result() == sizeof(int) + sizeof(double)*2);
129 string res_s = apply_visitor(int_printer(), v11);
130 BOOST_CHECK(res_s == "5");
133 // A variant object holding an std::vector
135 vector<int> int_vec_1;
136 int_vec_1.push_back(512);
137 int_vec_1.push_back(256);
138 int_vec_1.push_back(128);
139 int_vec_1.push_back(64);
142 res_s = apply_visitor(int_printer(), v11);
143 BOOST_CHECK(res_s == ",512,256,128,64");
148 int test_main(int , char* [])
150 std_log(LOG_FILENAME_LINE,"[Test Case for test1]");
153 testResultXml("test1");