4 * @brief Unit test for unbounded sequences of value types (integers,
7 * @author Carlos O'Ryan
9 #include "testing_allocation_traits.hpp"
10 #include "testing_range_checking.hpp"
12 #include "tao/Unbounded_Value_Sequence_T.h"
14 #include "value_sequence_tester.hpp"
16 #include "test_macros.h"
19 using namespace TAO_VERSIONED_NAMESPACE_NAME::TAO
;
21 typedef unbounded_value_sequence
<int> tested_sequence
;
22 typedef tested_sequence::element_traits tested_element_traits
;
23 typedef tested_sequence::allocation_traits tested_allocation_traits
;
24 typedef details::range_checking
<int,true> range
;
28 typedef tested_sequence::value_type value_type
;
30 int test_copy_constructor_from_ulong()
32 expected_calls
a(tested_allocation_traits::allocbuf_calls
);
33 expected_calls
f(tested_allocation_traits::freebuf_calls
);
35 tested_sequence
x(16);
36 FAIL_RETURN_IF_NOT(a
.expect(1), a
);
39 CHECK_EQUAL(CORBA::ULong(16), x
.maximum());
40 CHECK_EQUAL(CORBA::ULong(8), x
.length());
41 CHECK_EQUAL(true, x
.release());
44 FAIL_RETURN_IF_NOT(a
.expect(1), a
);
45 CHECK_EQUAL(CORBA::ULong(16), y
.maximum());
46 CHECK_EQUAL(CORBA::ULong(8), y
.length());
47 CHECK_EQUAL(true, y
.release());
49 FAIL_RETURN_IF_NOT(f
.expect(2), f
);
53 int test_assignment_from_ulong()
55 expected_calls
a(tested_allocation_traits::allocbuf_calls
);
56 expected_calls
f(tested_allocation_traits::freebuf_calls
);
58 tested_sequence
x(16);
60 FAIL_RETURN_IF_NOT(a
.expect(1), a
);
61 CHECK_EQUAL(CORBA::ULong(16), x
.maximum());
62 CHECK_EQUAL(CORBA::ULong(8), x
.length());
63 CHECK_EQUAL(true, x
.release());
66 FAIL_RETURN_IF_NOT(a
.expect(0), a
);
69 FAIL_RETURN_IF_NOT(a
.expect(1), a
);
70 FAIL_RETURN_IF_NOT(f
.expect(0), f
);
71 CHECK_EQUAL(CORBA::ULong(16), y
.maximum());
72 CHECK_EQUAL(CORBA::ULong(8), y
.length());
73 CHECK_EQUAL(true, y
.release());
75 FAIL_RETURN_IF_NOT(f
.expect(2), f
);
79 int test_ulong_constructor()
81 expected_calls
a(tested_allocation_traits::allocbuf_calls
);
82 expected_calls
f(tested_allocation_traits::freebuf_calls
);
84 tested_sequence
x(16);
86 CHECK_EQUAL(CORBA::ULong(16), x
.maximum());
87 CHECK_EQUAL(CORBA::ULong(0), x
.length());
88 CHECK_EQUAL(true, x
.release());
90 FAIL_RETURN_IF_NOT(a
.expect(1), a
);
91 FAIL_RETURN_IF_NOT(f
.expect(1), f
);
95 int test_exception_in_ulong_constructor()
97 expected_calls
a(tested_allocation_traits::allocbuf_calls
);
98 expected_calls
f(tested_allocation_traits::freebuf_calls
);
100 tested_allocation_traits::allocbuf_calls
.failure_countdown(1);
101 CHECK_THROW(tested_sequence
x(16), testing_exception
);
102 FAIL_RETURN_IF_NOT(a
.expect(1), a
);
104 FAIL_RETURN_IF_NOT(f
.expect(0), f
);
108 int test_set_length_less_than_maximum()
110 expected_calls
a(tested_allocation_traits::allocbuf_calls
);
111 expected_calls
f(tested_allocation_traits::freebuf_calls
);
113 tested_sequence
x(16);
116 CHECK_EQUAL(CORBA::ULong(16), x
.maximum());
117 CHECK_EQUAL(CORBA::ULong(8), x
.length());
118 CHECK_EQUAL(true, x
.release());
120 FAIL_RETURN_IF_NOT(a
.expect(1), a
);
121 FAIL_RETURN_IF_NOT(f
.expect(1), f
);
125 int test_set_length_more_than_maximum()
127 expected_calls
a(tested_allocation_traits::allocbuf_calls
);
128 expected_calls
f(tested_allocation_traits::freebuf_calls
);
130 tested_sequence
x(16);
131 FAIL_RETURN_IF_NOT(a
.expect(1), a
);
134 FAIL_RETURN_IF_NOT(a
.expect(1), a
);
135 FAIL_RETURN_IF_NOT(f
.expect(1), f
);
137 CHECK_EQUAL(CORBA::ULong(32), x
.maximum());
138 CHECK_EQUAL(CORBA::ULong(32), x
.length());
139 CHECK_EQUAL(true, x
.release());
141 FAIL_RETURN_IF_NOT(f
.expect(1), f
);
145 int test_exception_in_set_length()
147 expected_calls
f(tested_allocation_traits::freebuf_calls
);
151 expected_calls
a(tested_allocation_traits::allocbuf_calls
);
152 tested_allocation_traits::allocbuf_calls
.failure_countdown(1);
153 CHECK_THROW(x
.length(8), testing_exception
);
154 FAIL_RETURN_IF_NOT(a
.expect(1), a
);
156 FAIL_RETURN_IF_NOT(f
.expect(0), f
);
160 value_type
* alloc_and_init_buffer()
162 value_type
* buf
= tested_sequence::allocbuf(8);
163 buf
[0] = 1; buf
[1] = 4; buf
[2] = 9; buf
[3] = 16;
168 int test_regression_2201 ()
170 value_type
* buffer
= alloc_and_init_buffer();
172 expected_calls
a(tested_allocation_traits::allocbuf_calls
);
173 expected_calls
f(tested_allocation_traits::freebuf_calls
);
175 tested_sequence
x(8, 4, buffer
, true);
176 CHECK_EQUAL(CORBA::ULong(8), x
.maximum());
177 CHECK_EQUAL(CORBA::ULong(4), x
.length());
178 CHECK_EQUAL(buffer
, x
.get_buffer());
179 CHECK_EQUAL(int( 1), x
[0]);
180 CHECK_EQUAL(int( 4), x
[1]);
181 CHECK_EQUAL(int( 9), x
[2]);
182 CHECK_EQUAL(int(16), x
[3]);
183 CHECK_EQUAL(true, x
.release());
185 CHECK_EQUAL(CORBA::ULong(3), x
.length());
187 CHECK_EQUAL(CORBA::ULong(4), x
.length());
188 CHECK_EQUAL(int(0), x
[3]);
190 FAIL_RETURN_IF_NOT(a
.expect(0), a
);
191 FAIL_RETURN_IF_NOT(f
.expect(1), f
);
195 int test_buffer_constructor_default()
197 value_type
* buffer
= alloc_and_init_buffer();
199 expected_calls
a(tested_allocation_traits::allocbuf_calls
);
200 expected_calls
f(tested_allocation_traits::freebuf_calls
);
202 tested_sequence
a(8, 4, buffer
);
203 CHECK_EQUAL(CORBA::ULong(8), a
.maximum());
204 CHECK_EQUAL(CORBA::ULong(4), a
.length());
205 CHECK_EQUAL(buffer
, a
.get_buffer());
206 CHECK_EQUAL(int( 1), a
[0]);
207 CHECK_EQUAL(int( 4), a
[1]);
208 CHECK_EQUAL(int( 9), a
[2]);
209 CHECK_EQUAL(int(16), a
[3]);
210 CHECK_EQUAL(false, a
.release());
212 FAIL_RETURN_IF_NOT(a
.expect(0), a
);
213 FAIL_RETURN_IF_NOT(f
.expect(0), f
);
214 tested_sequence::freebuf(buffer
);
218 int test_buffer_constructor_false()
220 value_type
* buffer
= alloc_and_init_buffer();
221 expected_calls
a(tested_allocation_traits::allocbuf_calls
);
222 expected_calls
f(tested_allocation_traits::freebuf_calls
);
224 tested_sequence
a(8, 4, buffer
, false);
225 CHECK_EQUAL(CORBA::ULong(8), a
.maximum());
226 CHECK_EQUAL(CORBA::ULong(4), a
.length());
227 CHECK_EQUAL(buffer
, a
.get_buffer());
228 CHECK_EQUAL(int( 1), a
[0]);
229 CHECK_EQUAL(int( 4), a
[1]);
230 CHECK_EQUAL(int( 9), a
[2]);
231 CHECK_EQUAL(int(16), a
[3]);
232 CHECK_EQUAL(false, a
.release());
234 FAIL_RETURN_IF_NOT(a
.expect(0), a
);
235 FAIL_RETURN_IF_NOT(f
.expect(0), f
);
236 tested_sequence::freebuf(buffer
);
240 int test_buffer_constructor_true()
242 value_type
* buffer
= alloc_and_init_buffer();
243 expected_calls
a(tested_allocation_traits::allocbuf_calls
);
244 expected_calls
f(tested_allocation_traits::freebuf_calls
);
246 tested_sequence
a(8, 4, buffer
, true);
247 CHECK_EQUAL(CORBA::ULong(8), a
.maximum());
248 CHECK_EQUAL(CORBA::ULong(4), a
.length());
249 CHECK_EQUAL(buffer
, a
.get_buffer());
250 CHECK_EQUAL(int( 1), a
[0]);
251 CHECK_EQUAL(int( 4), a
[1]);
252 CHECK_EQUAL(int( 9), a
[2]);
253 CHECK_EQUAL(int(16), a
[3]);
254 CHECK_EQUAL(true, a
.release());
256 FAIL_RETURN_IF_NOT(a
.expect(0), a
);
257 FAIL_RETURN_IF_NOT(f
.expect(1), f
);
261 int test_replace_default()
263 value_type
* buffer
= alloc_and_init_buffer();
265 expected_calls
c(tested_allocation_traits::allocbuf_calls
);
266 expected_calls
f(tested_allocation_traits::freebuf_calls
);
269 a
.replace(8, 4, buffer
);
270 FAIL_RETURN_IF_NOT(c
.expect(0), c
);
271 FAIL_RETURN_IF_NOT(f
.expect(0), f
);
273 CHECK_EQUAL(CORBA::ULong(8), a
.maximum());
274 CHECK_EQUAL(CORBA::ULong(4), a
.length());
275 CHECK_EQUAL(buffer
, a
.get_buffer());
276 CHECK_EQUAL(int( 1), a
[0]);
277 CHECK_EQUAL(int( 4), a
[1]);
278 CHECK_EQUAL(int( 9), a
[2]);
279 CHECK_EQUAL(int(16), a
[3]);
280 CHECK_EQUAL(false, a
.release());
282 FAIL_RETURN_IF_NOT(c
.expect(0), c
);
283 FAIL_RETURN_IF_NOT(f
.expect(0), f
);
284 tested_sequence::freebuf(buffer
);
288 int test_replace_false()
290 value_type
* buffer
= alloc_and_init_buffer();
291 expected_calls
c(tested_allocation_traits::allocbuf_calls
);
292 expected_calls
f(tested_allocation_traits::freebuf_calls
);
296 a
.replace(8, 4, buffer
, false);
297 FAIL_RETURN_IF_NOT(c
.expect(0), c
);
298 FAIL_RETURN_IF_NOT(f
.expect(0), f
);
300 CHECK_EQUAL(CORBA::ULong(8), a
.maximum());
301 CHECK_EQUAL(CORBA::ULong(4), a
.length());
302 CHECK_EQUAL(buffer
, a
.get_buffer());
303 CHECK_EQUAL(int( 1), a
[0]);
304 CHECK_EQUAL(int( 4), a
[1]);
305 CHECK_EQUAL(int( 9), a
[2]);
306 CHECK_EQUAL(int(16), a
[3]);
307 CHECK_EQUAL(false, a
.release());
309 FAIL_RETURN_IF_NOT(c
.expect(0), c
);
310 FAIL_RETURN_IF_NOT(f
.expect(0), f
);
311 tested_sequence::freebuf(buffer
);
315 int test_replace_true()
317 value_type
* buffer
= alloc_and_init_buffer();
318 expected_calls
c(tested_allocation_traits::allocbuf_calls
);
319 expected_calls
f(tested_allocation_traits::freebuf_calls
);
323 a
.replace(8, 4, buffer
, true);
324 FAIL_RETURN_IF_NOT(c
.expect(0), c
);
325 FAIL_RETURN_IF_NOT(f
.expect(0), f
);
327 CHECK_EQUAL(CORBA::ULong(8), a
.maximum());
328 CHECK_EQUAL(CORBA::ULong(4), a
.length());
329 CHECK_EQUAL(buffer
, a
.get_buffer());
330 CHECK_EQUAL(int( 1), a
[0]);
331 CHECK_EQUAL(int( 4), a
[1]);
332 CHECK_EQUAL(int( 9), a
[2]);
333 CHECK_EQUAL(int(16), a
[3]);
334 CHECK_EQUAL(true, a
.release());
336 FAIL_RETURN_IF_NOT(c
.expect(0), c
);
337 FAIL_RETURN_IF_NOT(f
.expect(1), f
);
341 int test_get_buffer_default()
343 value_type
* buffer
= alloc_and_init_buffer();
344 tested_sequence
a(8, 4, buffer
, true);
345 CHECK_EQUAL(a
.get_buffer(), buffer
);
349 int test_get_buffer_false()
351 value_type
* buffer
= alloc_and_init_buffer();
352 tested_sequence
a(8, 4, buffer
, true);
353 CHECK_EQUAL(a
.get_buffer(), buffer
);
357 int test_get_buffer_true_with_release_false()
359 value_type
* buffer
= alloc_and_init_buffer();
360 tested_sequence
a(8, 4, buffer
, false);
361 CHECK(0 == a
.get_buffer(true));
362 tested_sequence::freebuf(buffer
);
366 int test_get_buffer_true_with_release_true()
368 value_type
* buffer
= alloc_and_init_buffer();
369 expected_calls
c(tested_allocation_traits::allocbuf_calls
);
370 expected_calls
f(tested_allocation_traits::freebuf_calls
);
372 tested_sequence
a(8, 4, buffer
, true);
373 CHECK_EQUAL(buffer
, a
.get_buffer(true));
375 tested_sequence
const & b
= a
;
376 CHECK_EQUAL(0UL, b
.maximum());
377 CHECK_EQUAL(0UL, b
.length());
378 CHECK(0 != b
.get_buffer());
379 CHECK_EQUAL(true, b
.release());
381 FAIL_RETURN_IF_NOT(c
.expect(1), c
);
383 CHECK(buffer
!= b
.get_buffer());
385 FAIL_RETURN_IF_NOT(c
.expect(0), c
);
386 FAIL_RETURN_IF_NOT(f
.expect(1), f
);
387 tested_sequence::freebuf(buffer
);
394 status
+= this->test_ulong_constructor();
395 status
+= this->test_copy_constructor_from_ulong();
396 status
+= this->test_assignment_from_ulong();
397 status
+= this->test_exception_in_ulong_constructor();
398 status
+= this->test_set_length_less_than_maximum();
399 status
+= this->test_set_length_more_than_maximum();
400 status
+= this->test_exception_in_set_length();
401 status
+= this->test_regression_2201 ();
402 status
+= this->test_buffer_constructor_default();
403 status
+= this->test_buffer_constructor_false();
404 status
+= this->test_buffer_constructor_true();
405 status
+= this->test_replace_default();
406 status
+= this->test_replace_false();
407 status
+= this->test_replace_true();
408 status
+= this->test_get_buffer_false();
409 status
+= this->test_get_buffer_true_with_release_false();
410 status
+= this->test_get_buffer_true_with_release_true();
416 int ACE_TMAIN(int,ACE_TCHAR
*[])
422 status
+= tester
.test_all ();
424 typedef value_sequence_tester
<tested_sequence
,tested_allocation_traits
> common
;
426 status
+= tester2
.test_all ();
428 catch (const ::CORBA::Exception
&ex
)
430 ex
._tao_print_exception("ERROR : unexpected CORBA exception caugth :");