summaryrefslogtreecommitdiff
path: root/contrib/utility/Test/ExH/Compound/compound.cpp
blob: d3319f5d7dc1fba0a78ae9b6592001bbcb25f99a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// file      : Test/ExH/Compound/compound.cpp
// author    : Boris Kolpackov <boris@kolpackov.net>
// copyright : Copyright (c) 2002-2003 Boris Kolpackov
// license   : http://kolpackov.net/license.html

#include "Utility/ExH/Compound.hpp"

#include <string>

using namespace Utility::ExH;

struct E {};

void postcondition (bool p) throw (E)
{
  if (!p) throw E ();
}

class Base
{
protected:
  Base () throw ()
  {
  }

  void
  init (char const* description) throw ()
  {
    str_ = description;
  }

  char const*
  what () const throw ()
  {
    return str_.c_str ();
  }

public:
  std::string str_;
};

class A_ {};
typedef
Compound<A_, Base>
A;

struct StringHolder
{
  StringHolder (char const* s)
      : str_ (s)
  {
  }

  operator std::string () const
  {
    return str_;
  }

  std::string str_;
};


int main ()
{
  try
  {
    // Compound (char const*)
    //
    {
      A a ("hello");

      postcondition (a.str_ == "hello");
    }

    // Compound (T const&)
    //
    {
      StringHolder a ("hello");
      A b (a);

      postcondition (b.str_ == "hello");
    }

    // Compound (Compound const&)
    //
    {
      A a ("hello");
      A b (a);

      postcondition (b.str_ == "hello");
    }

    // ~Compound ()
    //

    // operator= (Compound const&)
    //
    {
      A a ("hello");
      A b ("foo");
      b = a;

      postcondition (b.str_ == "hello");
    }

    // Compound ()
    //

  }
  catch (...)
  {
    return -1;
  }
}
//$Id$