1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/stdcpp/tsrc/Boost_test/variant/src/test1.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,157 @@
1.4 +//-----------------------------------------------------------------------------
1.5 +// boost-libs variant/test/test1.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 "class_a.h"
1.23 +#include "jobs.h"
1.24 +
1.25 +#include <iostream>
1.26 +#include <string>
1.27 +#include <vector>
1.28 +
1.29 +#ifdef __SYMBIAN32__
1.30 +#include "std_log_result.h"
1.31 +#define LOG_FILENAME_LINE __FILE__, __LINE__
1.32 +#endif
1.33 +
1.34 +void run()
1.35 +{
1.36 +
1.37 + using boost::apply_visitor;
1.38 + using boost::variant;
1.39 + using std::string;
1.40 + using std::vector;
1.41 +#ifndef __SYMBIAN32__
1.42 + using std::cout;
1.43 +#endif
1.44 + using std::endl;
1.45 +
1.46 + typedef variant< char*, string, short > t_var0;
1.47 + typedef variant< int, string, double > t_var1;
1.48 + typedef variant< short, const char* > t_var2;
1.49 + typedef variant< string, char > t_var3;
1.50 + typedef variant< unsigned short, const char* > t_var4;
1.51 + typedef variant< unsigned short, const char*, t_var2 > t_var5;
1.52 + typedef variant< unsigned short, const char*, t_var5 > t_var6;
1.53 + typedef variant< class_a, const void* > t_var7;
1.54 + typedef variant< t_var6, int > t_var8;
1.55 + typedef variant< t_var8, unsigned short > t_var9;
1.56 + typedef variant< char, unsigned char > t_var10;
1.57 + typedef variant< short, int, vector<int>, long> t_var11;
1.58 +
1.59 + t_var1 v1;
1.60 + t_var0 v0;
1.61 + t_var2 v2;
1.62 + t_var3 v3;
1.63 + t_var4 v4;
1.64 + t_var5 v5;
1.65 + t_var6 v6;
1.66 + t_var7 v7;
1.67 + t_var8 v8;
1.68 + t_var9 v9;
1.69 + t_var10 v10;
1.70 + t_var11 v11;
1.71 +
1.72 +
1.73 + //
1.74 + // Check assignment rules
1.75 + //
1.76 +
1.77 + v2 = 4;
1.78 + v4 = v2;
1.79 + verify(v4, spec<unsigned short>());
1.80 +
1.81 + v2 = "abc";
1.82 + v4 = v2;
1.83 + verify(v4, spec<const char*>(), "[V] abc");
1.84 +
1.85 + v5 = "def";
1.86 + verify(v5, spec<const char*>(), "[V] def");
1.87 +
1.88 + v5 = v2;
1.89 + verify(v5, spec<t_var2>(), "[V] [V] abc");
1.90 +
1.91 + v6 = 58;
1.92 + verify(v6, spec<unsigned short>(), "[V] 58");
1.93 +
1.94 + v6 = v5;
1.95 + verify(v6, spec<t_var5>(), "[V] [V] [V] abc");
1.96 +
1.97 + v8 = v2;
1.98 + verify(v8, spec<t_var6>(), "[V] [V] abc");
1.99 +
1.100 + v8 = v6;
1.101 + verify(v8, spec<t_var6>(), "[V] [V] [V] [V] abc");
1.102 +
1.103 + v7 = v2;
1.104 + verify(v7, spec<const void*>());
1.105 +
1.106 + v7 = 199;
1.107 + verify(v7, spec<class_a>(), "[V] class_a(199)");
1.108 +
1.109 + v2 = 200;
1.110 + v7 = v2;
1.111 + verify(v7, spec<class_a>(), "[V] class_a(200)");
1.112 +
1.113 +
1.114 +
1.115 + //
1.116 + // Check sizes of held values
1.117 + //
1.118 + total_sizeof ts;
1.119 +
1.120 + v1 = 5.9;
1.121 + apply_visitor(ts, v1);
1.122 +
1.123 + v1 = 'B';
1.124 + apply_visitor(ts, v1);
1.125 +
1.126 + v1 = 3.4f;
1.127 + apply_visitor(ts, v1);
1.128 +
1.129 + BOOST_CHECK(ts.result() == sizeof(int) + sizeof(double)*2);
1.130 +
1.131 + v11 = 5;
1.132 + string res_s = apply_visitor(int_printer(), v11);
1.133 + BOOST_CHECK(res_s == "5");
1.134 +
1.135 + //
1.136 + // A variant object holding an std::vector
1.137 + //
1.138 + vector<int> int_vec_1;
1.139 + int_vec_1.push_back(512);
1.140 + int_vec_1.push_back(256);
1.141 + int_vec_1.push_back(128);
1.142 + int_vec_1.push_back(64);
1.143 +
1.144 + v11 = int_vec_1;
1.145 + res_s = apply_visitor(int_printer(), v11);
1.146 + BOOST_CHECK(res_s == ",512,256,128,64");
1.147 +}
1.148 +
1.149 +
1.150 +
1.151 +int test_main(int , char* [])
1.152 +{
1.153 +std_log(LOG_FILENAME_LINE,"[Test Case for test1]");
1.154 + run();
1.155 +#ifdef __SYMBIAN32__
1.156 + testResultXml("test1");
1.157 + close_log_file();
1.158 +#endif
1.159 + return 0;
1.160 +}