~ubuntu-branches/debian/sid/boost1.49/sid

« back to all changes in this revision

Viewing changes to libs/optional/test/optional_test_io.cpp

  • Committer: Package Import Robot
  • Author(s): Steve M. Robbins
  • Date: 2012-02-26 00:31:44 UTC
  • Revision ID: package-import@ubuntu.com-20120226003144-eaytp12cbf6ubpms
Tags: upstream-1.49.0
ImportĀ upstreamĀ versionĀ 1.49.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2003, Fernando Luis Cacciola Carballal.
 
2
//
 
3
// Use, modification, and distribution is subject to the Boost Software
 
4
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
 
5
// http://www.boost.org/LICENSE_1_0.txt)
 
6
//
 
7
// See http://www.boost.org/lib/optional for documentation.
 
8
//
 
9
// You are welcome to contact the author at:
 
10
//  fernando_cacciola@hotmail.com
 
11
//
 
12
#include<stdexcept>
 
13
#include<string>
 
14
#include<sstream>
 
15
 
 
16
#define BOOST_ENABLE_ASSERT_HANDLER
 
17
 
 
18
#include "boost/optional/optional.hpp"
 
19
#include "boost/optional/optional_io.hpp"
 
20
#include "boost/none.hpp"
 
21
 
 
22
#include "boost/test/minimal.hpp"
 
23
 
 
24
#ifdef ENABLE_TRACE
 
25
#define TRACE(msg) std::cout << msg << std::endl ;
 
26
#else
 
27
#define TRACE(msg)
 
28
#endif
 
29
 
 
30
namespace boost {
 
31
 
 
32
void assertion_failed (char const * expr, char const * func, char const * file, long )
 
33
{
 
34
  using std::string ;
 
35
  string msg =  string("Boost assertion failure for \"")
 
36
               + string(expr)
 
37
               + string("\" at file \"")
 
38
               + string(file)
 
39
               + string("\" function \"")
 
40
               + string(func)
 
41
               + string("\"") ;
 
42
 
 
43
  TRACE(msg);
 
44
 
 
45
  throw std::logic_error(msg);
 
46
}
 
47
 
 
48
}
 
49
 
 
50
using namespace std ;
 
51
using namespace boost ;
 
52
 
 
53
template<class Opt>
 
54
void test2( Opt o, Opt buff )
 
55
{
 
56
  stringstream s ;
 
57
 
 
58
  const int markv = 123 ;
 
59
  int mark = 0 ;
 
60
  
 
61
  s << o << " " << markv ;
 
62
  s >> buff >> mark ;
 
63
 
 
64
  BOOST_ASSERT( buff == o ) ;
 
65
  BOOST_ASSERT( mark == markv ) ;
 
66
}
 
67
 
 
68
 
 
69
template<class T>
 
70
void test( T v, T w )
 
71
{
 
72
  test2( make_optional(v), optional<T>  ());
 
73
  test2( make_optional(v), make_optional(w));
 
74
  test2( optional<T>  () , optional<T>  ());
 
75
  test2( optional<T>  () , make_optional(w));
 
76
}
 
77
 
 
78
int test_main( int, char* [] )
 
79
{
 
80
  try
 
81
  {
 
82
    test(1,2);
 
83
    test(string("hello"),string("buffer"));
 
84
  }
 
85
  catch ( ... )
 
86
  {
 
87
    BOOST_ERROR("Unexpected Exception caught!");
 
88
  }
 
89
 
 
90
  return 0;
 
91
}
 
92