More tests update
[ACE_TAO.git] / TAO / tests / Sequence_Unit_Tests / testing_allocation_traits_ut.cpp
blob51fe07bb2130df4cb93f1c1f40befc93a61db02d
1 /**
2 * @file
4 * @brief Unit test for the testing_allocation_traits.
6 * @author Carlos O'Ryan
7 */
8 #include "testing_allocation_traits.hpp"
9 #include "test_macros.h"
11 #include "tao/SystemException.h"
13 #define CHECK_NO_THROW(statement) \
14 try { statement; } catch(...) { \
15 return 1; }
17 using namespace TAO_VERSIONED_NAMESPACE_NAME::TAO::details;
21 CORBA::ULong const MAXIMUM = 32;
23 template<class value_type>
24 struct Tester
26 typedef unbounded_value_allocation_traits<value_type,true> unbounded;
27 typedef bounded_value_allocation_traits<value_type,MAXIMUM,true> bounded;
29 template<class aspect>
30 int test_allocbuf()
32 expected_calls c(aspect::allocbuf_calls);
34 aspect::allocbuf_calls.failure_countdown(2);
35 value_type * s = 0;
36 CHECK_NO_THROW(s = aspect::allocbuf(4));
37 aspect::freebuf(s);
38 CHECK_THROW(s = aspect::allocbuf(4), testing_exception);
39 CHECK_NO_THROW(s = aspect::allocbuf(4));
40 aspect::freebuf(s);
42 FAIL_RETURN_IF_NOT(c.expect(3), c);
43 return 0;
46 template<class aspect>
47 int test_freebuf()
49 expected_calls c(aspect::freebuf_calls);
51 aspect::freebuf_calls.failure_countdown(2);
52 value_type * s = aspect::allocbuf(4);
53 CHECK_NO_THROW(aspect::freebuf(s));
54 s = aspect::allocbuf(4);
55 CHECK_THROW(aspect::freebuf(s), testing_exception);
56 aspect::freebuf(s);
57 s = aspect::allocbuf(4);
58 CHECK_NO_THROW(aspect::freebuf(s));
60 FAIL_RETURN_IF_NOT(c.expect(4), c);
61 return 0;
64 int test_default_buffer_allocation_value()
66 expected_calls u(unbounded::default_buffer_allocation_calls);
67 expected_calls b(bounded::default_buffer_allocation_calls);
69 value_type * s = unbounded::default_buffer_allocation();
70 FAIL_RETURN_IF_NOT(u.expect(1), u);
71 FAIL_RETURN_IF_NOT(b.expect(0), b);
72 CHECK_EQUAL(static_cast<value_type*>(0), s);
73 bounded::freebuf(s);
75 s = bounded::default_buffer_allocation();
76 FAIL_RETURN_IF_NOT(u.expect(0), u);
77 FAIL_RETURN_IF_NOT(b.expect(1), b);
78 // default_buffer_allocation doesn't allocate a buffer for
79 // bounded sequences (see bug 3042).
80 CHECK_EQUAL(static_cast<value_type*>(0), s);
81 bounded::freebuf(s);
82 return 0;
85 template<class aspect>
86 int test_default_buffer_allocation()
88 expected_calls c(aspect::default_buffer_allocation_calls);
90 aspect::default_buffer_allocation_calls.failure_countdown(2);
91 value_type * s = 0;
92 CHECK_NO_THROW(
93 s = aspect::default_buffer_allocation());
94 aspect::freebuf(s);
95 CHECK_THROW(
96 s = aspect::default_buffer_allocation(), testing_exception);
97 CHECK_NO_THROW(
98 s = aspect::default_buffer_allocation());
99 aspect::freebuf(s);
101 FAIL_RETURN_IF_NOT(c.expect(3), c);
102 return 0;
105 int test_default_buffer_allocation_unbounded()
107 return test_default_buffer_allocation<unbounded>();
110 int test_default_buffer_allocation_bounded()
112 return test_default_buffer_allocation<bounded>();
115 int test_allocbuf_unbounded()
117 return test_allocbuf<unbounded>();
120 int test_allocbuf_bounded()
122 return test_allocbuf<bounded>();
125 int test_freebuf_unbounded()
127 return test_freebuf<unbounded>();
130 int test_freebuf_bounded()
132 return test_freebuf<bounded>();
135 int test_all()
137 int status = 0;
138 status += this->test_default_buffer_allocation_value();
139 status += this->test_default_buffer_allocation_unbounded();
140 status += this->test_default_buffer_allocation_bounded();
141 status += this->test_allocbuf_unbounded();
142 status += this->test_allocbuf_bounded();
143 status += this->test_freebuf_unbounded();
144 status += this->test_freebuf_bounded();
145 return status;
147 Tester() {}
150 struct Foo { int y; };
152 int ACE_TMAIN(int,ACE_TCHAR*[])
154 int status = 0;
159 Tester<int> tester;
160 status += tester.test_all ();
164 Tester<Foo> tester;
165 status += tester.test_all ();
169 Tester<char*> tester;
170 status += tester.test_all ();
173 catch (const ::CORBA::Exception &ex)
175 ex._tao_print_exception("ERROR : unexpected CORBA exception caugth :");
176 ++status;
179 return status;