1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/stdcpp/tsrc/Boost_test/variant/src/test5.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,100 @@
1.4 +//-----------------------------------------------------------------------------
1.5 +// boost-libs variant/test/test5.cpp header file
1.6 +// See http://www.boost.org for updates, documentation, and revision history.
1.7 +//-----------------------------------------------------------------------------
1.8 +//
1.9 +// Copyright (c) 2003
1.10 +// Eric Friedman, Itay Maman
1.11 +//
1.12 +// Distributed under the Boost Software License, Version 1.0. (See
1.13 +// accompanying file LICENSE_1_0.txt or copy at
1.14 +// http://www.boost.org/LICENSE_1_0.txt)
1.15 +/*
1.16 + * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
1.17 +*/
1.18 +
1.19 +#include "boost/test/minimal.hpp"
1.20 +#include "boost/variant.hpp"
1.21 +
1.22 +#include "jobs.h"
1.23 +
1.24 +#include <assert.h>
1.25 +#include <iostream>
1.26 +#include <string>
1.27 +#include <vector>
1.28 +#ifdef __SYMBIAN32__
1.29 +#include "std_log_result.h"
1.30 +#define LOG_FILENAME_LINE __FILE__, __LINE__
1.31 +#endif
1.32 +void run()
1.33 +{
1.34 + using std::string;
1.35 + using boost::variant;
1.36 + using boost::apply_visitor;
1.37 +
1.38 + typedef variant<int, float, unsigned short, unsigned char> t_var1;
1.39 + typedef variant<int, t_var1, unsigned short, unsigned char> t_var2;
1.40 + typedef variant<string, int, t_var2> t_var3;
1.41 +
1.42 + t_var1 v1;
1.43 + t_var2 v2;
1.44 + t_var2 v2_second;
1.45 + t_var3 v3;
1.46 +
1.47 + const char c0 = 'x';
1.48 + v1 = c0;
1.49 +
1.50 + //v2 and v3 are holding (aka: containing) a variant
1.51 + v2 = v1;
1.52 + v3 = v2;
1.53 +
1.54 + verify(v1, spec<int>());
1.55 + verify(v2, spec<t_var1>());
1.56 + verify(v3, spec<t_var2>());
1.57 +
1.58 +
1.59 + //
1.60 + // assignment from const char (Converted to int)
1.61 + //
1.62 + v2 = c0;
1.63 + v3 = c0;
1.64 +
1.65 + verify(v2, spec<int>());
1.66 + verify(v3, spec<int>());
1.67 +
1.68 +
1.69 + BOOST_CHECK(apply_visitor(sum_int(), v2) == c0);
1.70 + BOOST_CHECK(apply_visitor(sum_int(), v3) == c0);
1.71 +
1.72 + sum_int adder;
1.73 + apply_visitor(adder, v2);
1.74 + apply_visitor(adder, v3);
1.75 +
1.76 + BOOST_CHECK(adder.result() == 2*c0);
1.77 +
1.78 + //
1.79 + // A variant holding a variant
1.80 + //
1.81 + typedef variant<unsigned char, float> t_var4;
1.82 + typedef variant<string, t_var4> t_var5;
1.83 +
1.84 + t_var4 v4;
1.85 + t_var5 v5;
1.86 +
1.87 + v5 = 22.5f;
1.88 + verify(v5, spec<t_var4>(), "[V] [V] 22.5");
1.89 +}
1.90 +
1.91 +
1.92 +
1.93 +int test_main(int , char* [])
1.94 +{
1.95 +std_log(LOG_FILENAME_LINE,"[Test Case for test5]");
1.96 + run();
1.97 +#ifdef __SYMBIAN32__
1.98 + testResultXml("test5");
1.99 + close_log_file();
1.100 +#endif
1.101 + return 0;
1.102 +}
1.103 +