os/ossrv/stdcpp/tsrc/Boost_test/variant/src/test5.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
//-----------------------------------------------------------------------------
sl@0
     2
// boost-libs variant/test/test5.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 "jobs.h"
sl@0
    20
sl@0
    21
#include <assert.h>
sl@0
    22
#include <iostream>
sl@0
    23
#include <string>
sl@0
    24
#include <vector>
sl@0
    25
#ifdef __SYMBIAN32__
sl@0
    26
#include "std_log_result.h"
sl@0
    27
#define LOG_FILENAME_LINE __FILE__, __LINE__
sl@0
    28
#endif
sl@0
    29
void run()
sl@0
    30
{
sl@0
    31
   using std::string;
sl@0
    32
   using boost::variant;
sl@0
    33
   using boost::apply_visitor;
sl@0
    34
sl@0
    35
   typedef variant<int, float, unsigned short, unsigned char> t_var1;
sl@0
    36
   typedef variant<int, t_var1, unsigned short, unsigned char> t_var2;
sl@0
    37
   typedef variant<string, int, t_var2> t_var3;
sl@0
    38
sl@0
    39
   t_var1 v1;
sl@0
    40
   t_var2 v2;
sl@0
    41
   t_var2 v2_second;
sl@0
    42
   t_var3 v3;
sl@0
    43
sl@0
    44
   const char c0 = 'x';
sl@0
    45
   v1 = c0;
sl@0
    46
sl@0
    47
   //v2 and v3 are holding (aka: containing) a variant
sl@0
    48
   v2 = v1;
sl@0
    49
   v3 = v2;
sl@0
    50
sl@0
    51
   verify(v1, spec<int>());
sl@0
    52
   verify(v2, spec<t_var1>());
sl@0
    53
   verify(v3, spec<t_var2>());
sl@0
    54
sl@0
    55
sl@0
    56
   //
sl@0
    57
   // assignment from const char (Converted to int)
sl@0
    58
   //
sl@0
    59
   v2 = c0;
sl@0
    60
   v3 = c0;
sl@0
    61
sl@0
    62
   verify(v2, spec<int>());
sl@0
    63
   verify(v3, spec<int>());
sl@0
    64
sl@0
    65
sl@0
    66
   BOOST_CHECK(apply_visitor(sum_int(), v2) == c0);
sl@0
    67
   BOOST_CHECK(apply_visitor(sum_int(), v3) == c0);
sl@0
    68
sl@0
    69
   sum_int adder;
sl@0
    70
   apply_visitor(adder, v2);
sl@0
    71
   apply_visitor(adder, v3);
sl@0
    72
sl@0
    73
   BOOST_CHECK(adder.result() == 2*c0);
sl@0
    74
sl@0
    75
   //
sl@0
    76
   // A variant holding a variant
sl@0
    77
   //
sl@0
    78
   typedef variant<unsigned char, float> t_var4;
sl@0
    79
   typedef variant<string, t_var4> t_var5;
sl@0
    80
sl@0
    81
   t_var4 v4;
sl@0
    82
   t_var5 v5;
sl@0
    83
sl@0
    84
   v5 = 22.5f;
sl@0
    85
   verify(v5, spec<t_var4>(), "[V] [V] 22.5");
sl@0
    86
}
sl@0
    87
sl@0
    88
sl@0
    89
sl@0
    90
int test_main(int , char* [])
sl@0
    91
{
sl@0
    92
std_log(LOG_FILENAME_LINE,"[Test Case for test5]");
sl@0
    93
   run();
sl@0
    94
#ifdef __SYMBIAN32__
sl@0
    95
   	testResultXml("test5");
sl@0
    96
	close_log_file();
sl@0
    97
#endif
sl@0
    98
   return 0;
sl@0
    99
}
sl@0
   100