os/ossrv/stdcpp/tsrc/Boost_test/variant/src/test5.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 //-----------------------------------------------------------------------------
     2 // boost-libs variant/test/test5.cpp header file
     3 // See http://www.boost.org for updates, documentation, and revision history.
     4 //-----------------------------------------------------------------------------
     5 //
     6 // Copyright (c) 2003
     7 // Eric Friedman, Itay Maman
     8 //
     9 // Distributed under the Boost Software License, Version 1.0. (See
    10 // accompanying file LICENSE_1_0.txt or copy at
    11 // http://www.boost.org/LICENSE_1_0.txt)
    12 /*
    13  * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
    14 */
    15 
    16 #include "boost/test/minimal.hpp"
    17 #include "boost/variant.hpp"
    18 
    19 #include "jobs.h"
    20 
    21 #include <assert.h>
    22 #include <iostream>
    23 #include <string>
    24 #include <vector>
    25 #ifdef __SYMBIAN32__
    26 #include "std_log_result.h"
    27 #define LOG_FILENAME_LINE __FILE__, __LINE__
    28 #endif
    29 void run()
    30 {
    31    using std::string;
    32    using boost::variant;
    33    using boost::apply_visitor;
    34 
    35    typedef variant<int, float, unsigned short, unsigned char> t_var1;
    36    typedef variant<int, t_var1, unsigned short, unsigned char> t_var2;
    37    typedef variant<string, int, t_var2> t_var3;
    38 
    39    t_var1 v1;
    40    t_var2 v2;
    41    t_var2 v2_second;
    42    t_var3 v3;
    43 
    44    const char c0 = 'x';
    45    v1 = c0;
    46 
    47    //v2 and v3 are holding (aka: containing) a variant
    48    v2 = v1;
    49    v3 = v2;
    50 
    51    verify(v1, spec<int>());
    52    verify(v2, spec<t_var1>());
    53    verify(v3, spec<t_var2>());
    54 
    55 
    56    //
    57    // assignment from const char (Converted to int)
    58    //
    59    v2 = c0;
    60    v3 = c0;
    61 
    62    verify(v2, spec<int>());
    63    verify(v3, spec<int>());
    64 
    65 
    66    BOOST_CHECK(apply_visitor(sum_int(), v2) == c0);
    67    BOOST_CHECK(apply_visitor(sum_int(), v3) == c0);
    68 
    69    sum_int adder;
    70    apply_visitor(adder, v2);
    71    apply_visitor(adder, v3);
    72 
    73    BOOST_CHECK(adder.result() == 2*c0);
    74 
    75    //
    76    // A variant holding a variant
    77    //
    78    typedef variant<unsigned char, float> t_var4;
    79    typedef variant<string, t_var4> t_var5;
    80 
    81    t_var4 v4;
    82    t_var5 v5;
    83 
    84    v5 = 22.5f;
    85    verify(v5, spec<t_var4>(), "[V] [V] 22.5");
    86 }
    87 
    88 
    89 
    90 int test_main(int , char* [])
    91 {
    92 std_log(LOG_FILENAME_LINE,"[Test Case for test5]");
    93    run();
    94 #ifdef __SYMBIAN32__
    95    	testResultXml("test5");
    96 	close_log_file();
    97 #endif
    98    return 0;
    99 }
   100