sl@0: //----------------------------------------------------------------------------- sl@0: // boost-libs variant/test/test1.cpp header file sl@0: // See http://www.boost.org for updates, documentation, and revision history. sl@0: //----------------------------------------------------------------------------- sl@0: // sl@0: // Copyright (c) 2003 sl@0: // Eric Friedman, Itay Maman sl@0: // sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: /* sl@0: * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved. sl@0: */ sl@0: sl@0: #include "boost/test/minimal.hpp" sl@0: #include "boost/variant.hpp" sl@0: sl@0: #include "class_a.h" sl@0: #include "jobs.h" sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #ifdef __SYMBIAN32__ sl@0: #include "std_log_result.h" sl@0: #define LOG_FILENAME_LINE __FILE__, __LINE__ sl@0: #endif sl@0: sl@0: void run() sl@0: { sl@0: sl@0: using boost::apply_visitor; sl@0: using boost::variant; sl@0: using std::string; sl@0: using std::vector; sl@0: #ifndef __SYMBIAN32__ sl@0: using std::cout; sl@0: #endif sl@0: using std::endl; sl@0: sl@0: typedef variant< char*, string, short > t_var0; sl@0: typedef variant< int, string, double > t_var1; sl@0: typedef variant< short, const char* > t_var2; sl@0: typedef variant< string, char > t_var3; sl@0: typedef variant< unsigned short, const char* > t_var4; sl@0: typedef variant< unsigned short, const char*, t_var2 > t_var5; sl@0: typedef variant< unsigned short, const char*, t_var5 > t_var6; sl@0: typedef variant< class_a, const void* > t_var7; sl@0: typedef variant< t_var6, int > t_var8; sl@0: typedef variant< t_var8, unsigned short > t_var9; sl@0: typedef variant< char, unsigned char > t_var10; sl@0: typedef variant< short, int, vector, long> t_var11; sl@0: sl@0: t_var1 v1; sl@0: t_var0 v0; sl@0: t_var2 v2; sl@0: t_var3 v3; sl@0: t_var4 v4; sl@0: t_var5 v5; sl@0: t_var6 v6; sl@0: t_var7 v7; sl@0: t_var8 v8; sl@0: t_var9 v9; sl@0: t_var10 v10; sl@0: t_var11 v11; sl@0: sl@0: sl@0: // sl@0: // Check assignment rules sl@0: // sl@0: sl@0: v2 = 4; sl@0: v4 = v2; sl@0: verify(v4, spec()); sl@0: sl@0: v2 = "abc"; sl@0: v4 = v2; sl@0: verify(v4, spec(), "[V] abc"); sl@0: sl@0: v5 = "def"; sl@0: verify(v5, spec(), "[V] def"); sl@0: sl@0: v5 = v2; sl@0: verify(v5, spec(), "[V] [V] abc"); sl@0: sl@0: v6 = 58; sl@0: verify(v6, spec(), "[V] 58"); sl@0: sl@0: v6 = v5; sl@0: verify(v6, spec(), "[V] [V] [V] abc"); sl@0: sl@0: v8 = v2; sl@0: verify(v8, spec(), "[V] [V] abc"); sl@0: sl@0: v8 = v6; sl@0: verify(v8, spec(), "[V] [V] [V] [V] abc"); sl@0: sl@0: v7 = v2; sl@0: verify(v7, spec()); sl@0: sl@0: v7 = 199; sl@0: verify(v7, spec(), "[V] class_a(199)"); sl@0: sl@0: v2 = 200; sl@0: v7 = v2; sl@0: verify(v7, spec(), "[V] class_a(200)"); sl@0: sl@0: sl@0: sl@0: // sl@0: // Check sizes of held values sl@0: // sl@0: total_sizeof ts; sl@0: sl@0: v1 = 5.9; sl@0: apply_visitor(ts, v1); sl@0: sl@0: v1 = 'B'; sl@0: apply_visitor(ts, v1); sl@0: sl@0: v1 = 3.4f; sl@0: apply_visitor(ts, v1); sl@0: sl@0: BOOST_CHECK(ts.result() == sizeof(int) + sizeof(double)*2); sl@0: sl@0: v11 = 5; sl@0: string res_s = apply_visitor(int_printer(), v11); sl@0: BOOST_CHECK(res_s == "5"); sl@0: sl@0: // sl@0: // A variant object holding an std::vector sl@0: // sl@0: vector int_vec_1; sl@0: int_vec_1.push_back(512); sl@0: int_vec_1.push_back(256); sl@0: int_vec_1.push_back(128); sl@0: int_vec_1.push_back(64); sl@0: sl@0: v11 = int_vec_1; sl@0: res_s = apply_visitor(int_printer(), v11); sl@0: BOOST_CHECK(res_s == ",512,256,128,64"); sl@0: } sl@0: sl@0: sl@0: sl@0: int test_main(int , char* []) sl@0: { sl@0: std_log(LOG_FILENAME_LINE,"[Test Case for test1]"); sl@0: run(); sl@0: #ifdef __SYMBIAN32__ sl@0: testResultXml("test1"); sl@0: close_log_file(); sl@0: #endif sl@0: return 0; sl@0: }