sl@0: //----------------------------------------------------------------------------- sl@0: // boost-libs variant/test/test2.cpp header file sl@0: // See http://www.boost.org for updates, documentation, and revision history. sl@0: //----------------------------------------------------------------------------- sl@0: // sl@0: // Copyright (c) 2003 sl@0: // Eric Friedman, Itay Maman sl@0: // sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: /* sl@0: * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved. sl@0: */ sl@0: sl@0: #include "boost/config.hpp" sl@0: #include "boost/test/minimal.hpp" sl@0: #include "boost/variant.hpp" sl@0: sl@0: #include "jobs.h" sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #ifdef __SYMBIAN32__ sl@0: #include "std_log_result.h" sl@0: #define LOG_FILENAME_LINE __FILE__, __LINE__ sl@0: #endif sl@0: using boost::apply_visitor; sl@0: sl@0: struct short_string sl@0: { sl@0: BOOST_STATIC_CONSTANT(size_t, e_limit = 101); sl@0: sl@0: short_string() : len_(0) sl@0: { sl@0: buffer_[0] = '\0'; sl@0: } sl@0: sl@0: short_string(const char* src) sl@0: { sl@0: #ifndef BOOST_NO_STDC_NAMESPACE sl@0: using std::strlen; sl@0: #endif // BOOST_NO_STDC_NAMESPACE sl@0: sl@0: size_t e_limit = this->e_limit; // avoid warnings on some compilers sl@0: size_t src_len = strlen(src); sl@0: sl@0: len_ = (std::min)(src_len, e_limit-1); sl@0: std::copy(src, src + len_, buffer_); sl@0: buffer_[len_] = '\0'; sl@0: } sl@0: sl@0: short_string(const short_string& other) : len_(other.len_) sl@0: { sl@0: std::copy(other.buffer_, other.buffer_ + e_limit, buffer_); sl@0: } sl@0: sl@0: void swap(short_string& other) sl@0: { sl@0: char temp[e_limit]; sl@0: sl@0: std::copy(buffer_, buffer_ + e_limit, temp); sl@0: std::copy(other.buffer_, other.buffer_ + e_limit, buffer_); sl@0: std::copy(temp, temp + e_limit, other.buffer_); sl@0: sl@0: std::swap(len_, other.len_); sl@0: } sl@0: sl@0: short_string& operator=(const short_string& rhs) sl@0: { sl@0: short_string temp(rhs); sl@0: swap(temp); sl@0: sl@0: return *this; sl@0: } sl@0: sl@0: operator const char*() const sl@0: { sl@0: return buffer_; sl@0: } sl@0: sl@0: sl@0: private: sl@0: char buffer_[e_limit]; sl@0: size_t len_; sl@0: }; //short_string sl@0: sl@0: sl@0: std::ostream& operator<<(std::ostream& out, const short_string& s) sl@0: { sl@0: out << static_cast(s); sl@0: return out; sl@0: } sl@0: sl@0: sl@0: sl@0: void run() sl@0: { sl@0: using boost::variant; sl@0: sl@0: variant v0; sl@0: variant v1; sl@0: variant v2; sl@0: sl@0: // sl@0: // Default construction sl@0: // sl@0: verify(v0, spec()); sl@0: verify(v1, spec()); sl@0: verify(v2, spec()); sl@0: sl@0: // sl@0: // Implicit conversion to bounded type sl@0: // sl@0: v1 = "I am v1"; sl@0: verify(v1, spec(), "[V] I am v1"); sl@0: sl@0: v2 = "I am v2"; sl@0: verify(v2, spec(), "[V] I am v2"); sl@0: sl@0: // sl@0: // Variant-to-variant assignment sl@0: // sl@0: sl@0: v0 = v1; sl@0: verify(v0, spec(), "[V] I am v1"); sl@0: sl@0: v1 = v0; sl@0: verify(v1, spec(), "[V] I am v1"); sl@0: sl@0: const int n0 = 88; sl@0: v1 = n0; sl@0: v0 = v1; sl@0: sl@0: // sl@0: // Implicit conversion to bounded type sl@0: // sl@0: verify(v0, spec(), "[V] 88"); sl@0: verify(v1, spec(), "[V] X"); sl@0: } sl@0: sl@0: sl@0: int test_main(int , char* []) sl@0: { sl@0: std_log(LOG_FILENAME_LINE,"[Test Case for test2]"); sl@0: run(); sl@0: #ifdef __SYMBIAN32__ sl@0: testResultXml("test2"); sl@0: close_log_file(); sl@0: #endif sl@0: return 0; sl@0: } sl@0: