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
;
20 CORBA::ULong
const MAXIMUM
= 32;
22 template<class value_type
>
25 typedef unbounded_value_allocation_traits
<value_type
,true> unbounded
;
26 typedef bounded_value_allocation_traits
<value_type
,MAXIMUM
,true> bounded
;
28 template<class aspect
>
31 expected_calls
c(aspect::allocbuf_calls
);
33 aspect::allocbuf_calls
.failure_countdown(2);
35 CHECK_NO_THROW(s
= aspect::allocbuf(4));
37 CHECK_THROW(s
= aspect::allocbuf(4), testing_exception
);
38 CHECK_NO_THROW(s
= aspect::allocbuf(4));
41 FAIL_RETURN_IF_NOT(c
.expect(3), c
);
45 template<class aspect
>
48 expected_calls
c(aspect::freebuf_calls
);
50 aspect::freebuf_calls
.failure_countdown(2);
51 value_type
* s
= aspect::allocbuf(4);
52 CHECK_NO_THROW(aspect::freebuf(s
));
53 s
= aspect::allocbuf(4);
54 CHECK_THROW(aspect::freebuf(s
), testing_exception
);
56 s
= aspect::allocbuf(4);
57 CHECK_NO_THROW(aspect::freebuf(s
));
59 FAIL_RETURN_IF_NOT(c
.expect(4), c
);
63 int test_default_buffer_allocation_value()
65 expected_calls
u(unbounded::default_buffer_allocation_calls
);
66 expected_calls
b(bounded::default_buffer_allocation_calls
);
68 value_type
* s
= unbounded::default_buffer_allocation();
69 FAIL_RETURN_IF_NOT(u
.expect(1), u
);
70 FAIL_RETURN_IF_NOT(b
.expect(0), b
);
71 CHECK_EQUAL(static_cast<value_type
*>(0), s
);
74 s
= bounded::default_buffer_allocation();
75 FAIL_RETURN_IF_NOT(u
.expect(0), u
);
76 FAIL_RETURN_IF_NOT(b
.expect(1), b
);
77 // default_buffer_allocation doesn't allocate a buffer for
78 // bounded sequences (see bug 3042).
79 CHECK_EQUAL(static_cast<value_type
*>(0), s
);
84 template<class aspect
>
85 int test_default_buffer_allocation()
87 expected_calls
c(aspect::default_buffer_allocation_calls
);
89 aspect::default_buffer_allocation_calls
.failure_countdown(2);
92 s
= aspect::default_buffer_allocation());
95 s
= aspect::default_buffer_allocation(), testing_exception
);
97 s
= aspect::default_buffer_allocation());
100 FAIL_RETURN_IF_NOT(c
.expect(3), c
);
104 int test_default_buffer_allocation_unbounded()
106 return test_default_buffer_allocation
<unbounded
>();
109 int test_default_buffer_allocation_bounded()
111 return test_default_buffer_allocation
<bounded
>();
114 int test_allocbuf_unbounded()
116 return test_allocbuf
<unbounded
>();
119 int test_allocbuf_bounded()
121 return test_allocbuf
<bounded
>();
124 int test_freebuf_unbounded()
126 return test_freebuf
<unbounded
>();
129 int test_freebuf_bounded()
131 return test_freebuf
<bounded
>();
137 status
+= this->test_default_buffer_allocation_value();
138 status
+= this->test_default_buffer_allocation_unbounded();
139 status
+= this->test_default_buffer_allocation_bounded();
140 status
+= this->test_allocbuf_unbounded();
141 status
+= this->test_allocbuf_bounded();
142 status
+= this->test_freebuf_unbounded();
143 status
+= this->test_freebuf_bounded();
149 struct Foo
{ int y
; };
151 int ACE_TMAIN(int,ACE_TCHAR
*[])
159 status
+= tester
.test_all ();
164 status
+= tester
.test_all ();
168 Tester
<char*> tester
;
169 status
+= tester
.test_all ();
172 catch (const ::CORBA::Exception
&ex
)
174 ex
._tao_print_exception("ERROR : unexpected CORBA exception caugth :");