os/ossrv/stdcpp/tsrc/Boost_test/variant/src/test1.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
//-----------------------------------------------------------------------------
sl@0
     2
// boost-libs variant/test/test1.cpp header file
sl@0
     3
// See http://www.boost.org for updates, documentation, and revision history.
sl@0
     4
//-----------------------------------------------------------------------------
sl@0
     5
//
sl@0
     6
// Copyright (c) 2003
sl@0
     7
// Eric Friedman, Itay Maman
sl@0
     8
//
sl@0
     9
// Distributed under the Boost Software License, Version 1.0. (See
sl@0
    10
// accompanying file LICENSE_1_0.txt or copy at
sl@0
    11
// http://www.boost.org/LICENSE_1_0.txt)
sl@0
    12
/*
sl@0
    13
 * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
sl@0
    14
*/
sl@0
    15
sl@0
    16
#include "boost/test/minimal.hpp"
sl@0
    17
#include "boost/variant.hpp"
sl@0
    18
sl@0
    19
#include "class_a.h"
sl@0
    20
#include "jobs.h"
sl@0
    21
sl@0
    22
#include <iostream>
sl@0
    23
#include <string>
sl@0
    24
#include <vector>
sl@0
    25
sl@0
    26
#ifdef __SYMBIAN32__
sl@0
    27
#include "std_log_result.h"
sl@0
    28
#define LOG_FILENAME_LINE __FILE__, __LINE__
sl@0
    29
#endif
sl@0
    30
sl@0
    31
void run()
sl@0
    32
{
sl@0
    33
sl@0
    34
   using boost::apply_visitor;
sl@0
    35
   using boost::variant;
sl@0
    36
   using std::string;
sl@0
    37
   using std::vector;
sl@0
    38
#ifndef __SYMBIAN32__
sl@0
    39
   using std::cout;
sl@0
    40
#endif   
sl@0
    41
   using std::endl;
sl@0
    42
sl@0
    43
   typedef variant< char*, string, short > t_var0;
sl@0
    44
   typedef variant< int, string, double > t_var1;
sl@0
    45
   typedef variant< short, const char* > t_var2;
sl@0
    46
   typedef variant< string, char > t_var3;   
sl@0
    47
   typedef variant< unsigned short, const char* > t_var4;
sl@0
    48
   typedef variant< unsigned short, const char*, t_var2 > t_var5;
sl@0
    49
   typedef variant< unsigned short, const char*, t_var5 > t_var6;
sl@0
    50
   typedef variant< class_a, const void* > t_var7;
sl@0
    51
   typedef variant< t_var6, int > t_var8;
sl@0
    52
   typedef variant< t_var8, unsigned short > t_var9;
sl@0
    53
   typedef variant< char, unsigned char > t_var10;
sl@0
    54
   typedef variant< short, int, vector<int>, long> t_var11;
sl@0
    55
sl@0
    56
   t_var1 v1;
sl@0
    57
   t_var0 v0;
sl@0
    58
   t_var2 v2;
sl@0
    59
   t_var3 v3;
sl@0
    60
   t_var4 v4;
sl@0
    61
   t_var5 v5;
sl@0
    62
   t_var6 v6;
sl@0
    63
   t_var7 v7;
sl@0
    64
   t_var8 v8;
sl@0
    65
   t_var9 v9;
sl@0
    66
   t_var10 v10;
sl@0
    67
   t_var11 v11;
sl@0
    68
sl@0
    69
sl@0
    70
   //
sl@0
    71
   // Check assignment rules 
sl@0
    72
   //
sl@0
    73
sl@0
    74
   v2 = 4;
sl@0
    75
   v4 = v2;
sl@0
    76
   verify(v4, spec<unsigned short>());
sl@0
    77
sl@0
    78
   v2 = "abc";
sl@0
    79
   v4 = v2;
sl@0
    80
   verify(v4, spec<const char*>(), "[V] abc");
sl@0
    81
sl@0
    82
   v5 = "def";
sl@0
    83
   verify(v5, spec<const char*>(), "[V] def");
sl@0
    84
sl@0
    85
   v5 = v2;
sl@0
    86
   verify(v5, spec<t_var2>(), "[V] [V] abc");
sl@0
    87
sl@0
    88
   v6 = 58;
sl@0
    89
   verify(v6, spec<unsigned short>(), "[V] 58");
sl@0
    90
sl@0
    91
   v6 = v5;
sl@0
    92
   verify(v6, spec<t_var5>(), "[V] [V] [V] abc");
sl@0
    93
sl@0
    94
   v8 = v2;
sl@0
    95
   verify(v8, spec<t_var6>(), "[V] [V] abc");
sl@0
    96
sl@0
    97
   v8 = v6;
sl@0
    98
   verify(v8, spec<t_var6>(), "[V] [V] [V] [V] abc");
sl@0
    99
sl@0
   100
   v7 = v2;
sl@0
   101
   verify(v7, spec<const void*>());
sl@0
   102
sl@0
   103
   v7 = 199;
sl@0
   104
   verify(v7, spec<class_a>(), "[V] class_a(199)");
sl@0
   105
sl@0
   106
   v2 = 200;
sl@0
   107
   v7 = v2;
sl@0
   108
   verify(v7, spec<class_a>(), "[V] class_a(200)");
sl@0
   109
sl@0
   110
sl@0
   111
sl@0
   112
   //
sl@0
   113
   // Check sizes of held values
sl@0
   114
   //
sl@0
   115
   total_sizeof ts;
sl@0
   116
sl@0
   117
   v1 = 5.9;
sl@0
   118
   apply_visitor(ts, v1);
sl@0
   119
sl@0
   120
   v1 = 'B';
sl@0
   121
   apply_visitor(ts, v1);
sl@0
   122
sl@0
   123
   v1 = 3.4f;
sl@0
   124
   apply_visitor(ts, v1);
sl@0
   125
sl@0
   126
   BOOST_CHECK(ts.result() == sizeof(int) + sizeof(double)*2);
sl@0
   127
sl@0
   128
   v11 = 5;
sl@0
   129
   string res_s = apply_visitor(int_printer(), v11);
sl@0
   130
   BOOST_CHECK(res_s == "5");
sl@0
   131
sl@0
   132
   //
sl@0
   133
   // A variant object holding an std::vector 
sl@0
   134
   //
sl@0
   135
   vector<int> int_vec_1;
sl@0
   136
   int_vec_1.push_back(512);
sl@0
   137
   int_vec_1.push_back(256);
sl@0
   138
   int_vec_1.push_back(128);
sl@0
   139
   int_vec_1.push_back(64);
sl@0
   140
sl@0
   141
   v11 = int_vec_1;
sl@0
   142
   res_s = apply_visitor(int_printer(), v11);
sl@0
   143
   BOOST_CHECK(res_s == ",512,256,128,64");
sl@0
   144
}
sl@0
   145
sl@0
   146
sl@0
   147
sl@0
   148
int test_main(int , char* [])
sl@0
   149
{
sl@0
   150
std_log(LOG_FILENAME_LINE,"[Test Case for test1]");
sl@0
   151
   run();
sl@0
   152
#ifdef __SYMBIAN32__
sl@0
   153
   	testResultXml("test1");
sl@0
   154
	close_log_file();
sl@0
   155
#endif
sl@0
   156
   return 0;
sl@0
   157
}