sl@0: //----------------------------------------------------------------------------- sl@0: // boost-libs variant/test/test5.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 "jobs.h" sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #ifdef __SYMBIAN32__ sl@0: #include "std_log_result.h" sl@0: #define LOG_FILENAME_LINE __FILE__, __LINE__ sl@0: #endif sl@0: void run() sl@0: { sl@0: using std::string; sl@0: using boost::variant; sl@0: using boost::apply_visitor; sl@0: sl@0: typedef variant t_var1; sl@0: typedef variant t_var2; sl@0: typedef variant t_var3; sl@0: sl@0: t_var1 v1; sl@0: t_var2 v2; sl@0: t_var2 v2_second; sl@0: t_var3 v3; sl@0: sl@0: const char c0 = 'x'; sl@0: v1 = c0; sl@0: sl@0: //v2 and v3 are holding (aka: containing) a variant sl@0: v2 = v1; sl@0: v3 = v2; sl@0: sl@0: verify(v1, spec()); sl@0: verify(v2, spec()); sl@0: verify(v3, spec()); sl@0: sl@0: sl@0: // sl@0: // assignment from const char (Converted to int) sl@0: // sl@0: v2 = c0; sl@0: v3 = c0; sl@0: sl@0: verify(v2, spec()); sl@0: verify(v3, spec()); sl@0: sl@0: sl@0: BOOST_CHECK(apply_visitor(sum_int(), v2) == c0); sl@0: BOOST_CHECK(apply_visitor(sum_int(), v3) == c0); sl@0: sl@0: sum_int adder; sl@0: apply_visitor(adder, v2); sl@0: apply_visitor(adder, v3); sl@0: sl@0: BOOST_CHECK(adder.result() == 2*c0); sl@0: sl@0: // sl@0: // A variant holding a variant sl@0: // sl@0: typedef variant t_var4; sl@0: typedef variant t_var5; sl@0: sl@0: t_var4 v4; sl@0: t_var5 v5; sl@0: sl@0: v5 = 22.5f; sl@0: verify(v5, spec(), "[V] [V] 22.5"); 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 test5]"); sl@0: run(); sl@0: #ifdef __SYMBIAN32__ sl@0: testResultXml("test5"); sl@0: close_log_file(); sl@0: #endif sl@0: return 0; sl@0: } sl@0: