4 * @brief Unit test for the testing_allocation_traits.
6 * @author Carlos O'Ryan
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(...) { \
17 using namespace TAO_VERSIONED_NAMESPACE_NAME::TAO::details
;
21 CORBA::ULong
const MAXIMUM
= 32;
23 template<class value_type
>
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
>
32 expected_calls
c(aspect::allocbuf_calls
);
34 aspect::allocbuf_calls
.failure_countdown(2);
36 CHECK_NO_THROW(s
= aspect::allocbuf(4));
38 CHECK_THROW(s
= aspect::allocbuf(4), testing_exception
);
39 CHECK_NO_THROW(s
= aspect::allocbuf(4));
42 FAIL_RETURN_IF_NOT(c
.expect(3), c
);
46 template<class aspect
>
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
);
57 s
= aspect::allocbuf(4);
58 CHECK_NO_THROW(aspect::freebuf(s
));
60 FAIL_RETURN_IF_NOT(c
.expect(4), c
);
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
);
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
);
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);
93 s
= aspect::default_buffer_allocation());
96 s
= aspect::default_buffer_allocation(), testing_exception
);
98 s
= aspect::default_buffer_allocation());
101 FAIL_RETURN_IF_NOT(c
.expect(3), c
);
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
>();
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();
150 struct Foo
{ int y
; };
152 int ACE_TMAIN(int,ACE_TCHAR
*[])
160 status
+= tester
.test_all ();
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 :");