os/ossrv/stdcpp/tsrc/Boost_test/variant/src/test2.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/stdcpp/tsrc/Boost_test/variant/src/test2.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,155 @@
     1.4 +//-----------------------------------------------------------------------------
     1.5 +// boost-libs variant/test/test2.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/config.hpp"
    1.20 +#include "boost/test/minimal.hpp"
    1.21 +#include "boost/variant.hpp"
    1.22 +
    1.23 +#include "jobs.h"
    1.24 +
    1.25 +#include <cassert>
    1.26 +#include <iostream>
    1.27 +#include <algorithm>
    1.28 +#include <cstring>
    1.29 +#ifdef __SYMBIAN32__
    1.30 +#include "std_log_result.h"
    1.31 +#define LOG_FILENAME_LINE __FILE__, __LINE__
    1.32 +#endif
    1.33 +using boost::apply_visitor;
    1.34 +
    1.35 +struct short_string
    1.36 +{
    1.37 +   BOOST_STATIC_CONSTANT(size_t, e_limit = 101);
    1.38 +
    1.39 +   short_string() : len_(0) 
    1.40 +   { 
    1.41 +      buffer_[0] = '\0';
    1.42 +   }
    1.43 +
    1.44 +   short_string(const char* src) 
    1.45 +   {
    1.46 +#ifndef BOOST_NO_STDC_NAMESPACE
    1.47 +      using std::strlen;
    1.48 +#endif // BOOST_NO_STDC_NAMESPACE
    1.49 +
    1.50 +      size_t e_limit = this->e_limit; // avoid warnings on some compilers
    1.51 +      size_t src_len = strlen(src);
    1.52 +      
    1.53 +      len_ = (std::min)(src_len, e_limit-1);
    1.54 +      std::copy(src, src + len_, buffer_);
    1.55 +      buffer_[len_] = '\0';
    1.56 +   }
    1.57 +
    1.58 +   short_string(const short_string& other) : len_(other.len_)
    1.59 +   {
    1.60 +      std::copy(other.buffer_, other.buffer_ + e_limit, buffer_);
    1.61 +   }
    1.62 +
    1.63 +   void swap(short_string& other)
    1.64 +   {
    1.65 +      char temp[e_limit];
    1.66 +
    1.67 +      std::copy(buffer_, buffer_ + e_limit, temp);
    1.68 +      std::copy(other.buffer_, other.buffer_ + e_limit, buffer_);
    1.69 +      std::copy(temp, temp + e_limit, other.buffer_);
    1.70 +
    1.71 +      std::swap(len_, other.len_);
    1.72 +   }
    1.73 +
    1.74 +   short_string& operator=(const short_string& rhs)
    1.75 +   {
    1.76 +      short_string temp(rhs);
    1.77 +      swap(temp);
    1.78 +
    1.79 +      return *this;
    1.80 +   }
    1.81 +
    1.82 +   operator const char*() const
    1.83 +   {
    1.84 +      return buffer_;
    1.85 +   }
    1.86 +
    1.87 +
    1.88 +private:
    1.89 +   char buffer_[e_limit];
    1.90 +   size_t len_;
    1.91 +}; //short_string
    1.92 +
    1.93 +
    1.94 +std::ostream& operator<<(std::ostream& out, const short_string& s)
    1.95 +{
    1.96 +   out << static_cast<const char*>(s);
    1.97 +   return out;
    1.98 +}
    1.99 +
   1.100 +
   1.101 +
   1.102 +void run()
   1.103 +{   
   1.104 +   using boost::variant;
   1.105 +
   1.106 +   variant<short, short_string> v0;
   1.107 +   variant<char, const char*> v1;
   1.108 +   variant<short_string, char > v2;
   1.109 +
   1.110 +   //
   1.111 +   // Default construction
   1.112 +   //
   1.113 +   verify(v0, spec<short>());
   1.114 +   verify(v1, spec<char>());
   1.115 +   verify(v2, spec<short_string>());
   1.116 +
   1.117 +   //
   1.118 +   // Implicit conversion to bounded type
   1.119 +   //
   1.120 +   v1 = "I am v1";
   1.121 +   verify(v1, spec<const char*>(), "[V] I am v1");
   1.122 +
   1.123 +   v2 = "I am v2";
   1.124 +   verify(v2, spec<short_string>(), "[V] I am v2");
   1.125 +
   1.126 +   //
   1.127 +   // Variant-to-variant assignment
   1.128 +   //
   1.129 +
   1.130 +   v0 = v1;
   1.131 +   verify(v0, spec<short_string>(), "[V] I am v1");
   1.132 +
   1.133 +   v1 = v0;
   1.134 +   verify(v1, spec<const char*>(), "[V] I am v1");
   1.135 +
   1.136 +   const int n0 = 88;
   1.137 +   v1 = n0;
   1.138 +   v0 = v1;
   1.139 +
   1.140 +   //
   1.141 +   // Implicit conversion to bounded type
   1.142 +   //
   1.143 +   verify(v0, spec<short>(), "[V] 88");
   1.144 +   verify(v1, spec<char>(), "[V] X");
   1.145 +}
   1.146 +
   1.147 +
   1.148 +int test_main(int , char* [])
   1.149 +{
   1.150 +std_log(LOG_FILENAME_LINE,"[Test Case for test2]");
   1.151 +   run();
   1.152 + #ifdef __SYMBIAN32__
   1.153 +   	testResultXml("test2");
   1.154 +	close_log_file();
   1.155 +#endif
   1.156 +   return 0;
   1.157 +}
   1.158 +