Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Sequence_Unit_Tests / object_reference_sequence_element_ut.cpp
blobe5467e6a70f593507f122f69ee289c98fdfa93c8
1 /**
2 * @file
4 * @brief Unit test for object_reference_sequence_element, this is the
5 * type returned by operator[] from a string sequence.
7 * @author Carlos O'Ryan
8 */
9 #include "testing_object_reference_traits.hpp"
10 #include "mock_reference.hpp"
12 #include "tao/Object_Reference_Sequence_Element_T.h"
13 #include "tao/SystemException.h"
15 #include "test_macros.h"
17 using namespace TAO_VERSIONED_NAMESPACE_NAME::TAO::details;
19 typedef object_reference_traits<mock_reference,mock_reference_var,true> tested_element_traits;
20 typedef object_reference_sequence_element<tested_element_traits> tested_element;
21 typedef mock_reference * reference_type;
22 typedef tested_element_traits::object_type_var reference_var;
24 int test_assignment_from_var_release_true()
26 expected_calls d(tested_element_traits::duplicate_calls);
27 expected_calls r(tested_element_traits::release_calls);
28 expected_calls md(mock_reference::duplicate_calls);
29 expected_calls mr(mock_reference::release_calls);
31 reference_type xe = mock_reference::allocate(1);
32 tested_element x(xe, true);
33 reference_var y(mock_reference::allocate(2));
35 FAIL_RETURN_IF_NOT(md.expect(0), md);
36 FAIL_RETURN_IF_NOT(mr.expect(0), mr);
38 x = y;
40 FAIL_RETURN_IF_NOT(d.expect(0), d);
41 FAIL_RETURN_IF_NOT(r.expect(1), r);
42 FAIL_RETURN_IF_NOT(md.expect(1), md);
43 FAIL_RETURN_IF_NOT(mr.expect(2), mr);
45 CHECK_EQUAL(2, x->id());
47 tested_element_traits::release(x);
48 FAIL_RETURN_IF_NOT(r.expect(1), r);
49 FAIL_RETURN_IF_NOT(mr.expect(1), mr);
52 FAIL_RETURN_IF_NOT(d.expect(0),d );
53 FAIL_RETURN_IF_NOT(r.expect(0),r );
54 FAIL_RETURN_IF_NOT(md.expect(0), md);
55 FAIL_RETURN_IF_NOT(mr.expect(1), mr);
57 return 0;
60 int test_assignment_from_var_release_false()
62 expected_calls d(tested_element_traits::duplicate_calls);
63 expected_calls r(tested_element_traits::release_calls);
64 expected_calls md(mock_reference::duplicate_calls);
65 expected_calls mr(mock_reference::release_calls);
67 reference_type xe = mock_reference::allocate(1);
68 reference_type oldxe = xe;
69 tested_element x(xe, false);
70 reference_var y(mock_reference::allocate(2));
72 FAIL_RETURN_IF_NOT(md.expect(0), md);
73 FAIL_RETURN_IF_NOT(mr.expect(0), mr);
75 x = y;
77 FAIL_RETURN_IF_NOT(d.expect(0), d );
78 FAIL_RETURN_IF_NOT(r.expect(0), r);
79 FAIL_RETURN_IF_NOT(md.expect(1), md);
80 FAIL_RETURN_IF_NOT(mr.expect(1), mr);
82 CHECK_EQUAL(2, x->id());
84 tested_element_traits::release(x);
85 tested_element_traits::release(oldxe);
86 FAIL_RETURN_IF_NOT(r.expect(2), r);
87 FAIL_RETURN_IF_NOT(mr.expect(2), mr);
90 FAIL_RETURN_IF_NOT(d.expect(0),d );
91 FAIL_RETURN_IF_NOT(r.expect(0), r);
92 FAIL_RETURN_IF_NOT(md.expect(0), md);
93 FAIL_RETURN_IF_NOT(mr.expect(1), mr);
94 return 0;
97 int test_assignment_from_var_throw()
99 expected_calls d(tested_element_traits::duplicate_calls);
100 expected_calls r(tested_element_traits::release_calls);
101 expected_calls md(mock_reference::duplicate_calls);
102 expected_calls mr(mock_reference::release_calls);
104 reference_type xe = mock_reference::allocate(1);
105 tested_element x(xe, true);
106 reference_var y(mock_reference::allocate(2));
108 FAIL_RETURN_IF_NOT(md.expect(0), md);
109 FAIL_RETURN_IF_NOT(mr.expect(0), mr);
111 mock_reference::duplicate_calls.failure_countdown(1);
113 CHECK_THROW(x = y, testing_exception);
115 FAIL_RETURN_IF_NOT(d.expect(0), d);
116 FAIL_RETURN_IF_NOT(r.expect(0), r);
117 FAIL_RETURN_IF_NOT(md.expect(1), md);
118 FAIL_RETURN_IF_NOT(mr.expect(0), mr);
120 CHECK_EQUAL(1, x->id());
121 CHECK_EQUAL(2, y->id());
123 tested_element_traits::release(x);
124 FAIL_RETURN_IF_NOT(r.expect(1), r);
125 FAIL_RETURN_IF_NOT(mr.expect(1), mr);
128 FAIL_RETURN_IF_NOT(d.expect(0), d);
129 FAIL_RETURN_IF_NOT(r.expect(0), r);
130 FAIL_RETURN_IF_NOT(md.expect(0), md);
131 FAIL_RETURN_IF_NOT(mr.expect(1), mr);
132 return 0;
135 int test_assignment_from_element_release_true()
137 expected_calls d(tested_element_traits::duplicate_calls);
138 expected_calls r(tested_element_traits::release_calls);
139 expected_calls md(mock_reference::duplicate_calls);
140 expected_calls mr(mock_reference::release_calls);
142 reference_type xe = mock_reference::allocate(1);
143 tested_element x(xe, true);
145 reference_type ye = mock_reference::allocate(2);
146 tested_element y(ye, true);
148 FAIL_RETURN_IF_NOT(d.expect(0), d);
149 FAIL_RETURN_IF_NOT(r.expect(0) ,r);
151 x = y;
153 FAIL_RETURN_IF_NOT(d.expect(1), d);
154 FAIL_RETURN_IF_NOT(r.expect(1), r);
155 FAIL_RETURN_IF_NOT(md.expect(1), md);
156 FAIL_RETURN_IF_NOT(mr.expect(2), mr);
158 CHECK_EQUAL(2, x->id());
160 tested_element_traits::release(xe);
161 tested_element_traits::release(ye);
162 FAIL_RETURN_IF_NOT(r.expect(2),r );
163 FAIL_RETURN_IF_NOT(mr.expect(2), mr);
166 FAIL_RETURN_IF_NOT(d.expect(0), d);
167 FAIL_RETURN_IF_NOT(r.expect(0), r);
168 FAIL_RETURN_IF_NOT(md.expect(0), md);
169 FAIL_RETURN_IF_NOT(mr.expect(0), mr);
170 return 0;
173 int test_assignment_from_element_release_false()
175 expected_calls d(tested_element_traits::duplicate_calls);
176 expected_calls r(tested_element_traits::release_calls);
177 expected_calls md(mock_reference::duplicate_calls);
178 expected_calls mr(mock_reference::release_calls);
180 reference_type xe = mock_reference::allocate(1);
181 reference_type oldxe = xe;
182 tested_element x(xe, false);
184 reference_type ye = mock_reference::allocate(2);
185 tested_element y(ye, true);
187 FAIL_RETURN_IF_NOT(d.expect(0), d);
188 FAIL_RETURN_IF_NOT(r.expect(0), r);
190 x = y;
192 FAIL_RETURN_IF_NOT(d.expect(1), d);
193 FAIL_RETURN_IF_NOT(r.expect(0), r);
194 FAIL_RETURN_IF_NOT(md.expect(1), md);
195 FAIL_RETURN_IF_NOT(mr.expect(1), mr);
197 CHECK_EQUAL(2, x->id());
199 tested_element_traits::release(xe);
200 tested_element_traits::release(oldxe);
201 tested_element_traits::release(ye);
202 FAIL_RETURN_IF_NOT(r.expect(3), r);
203 FAIL_RETURN_IF_NOT(mr.expect(3), mr);
206 FAIL_RETURN_IF_NOT(d.expect(0), d);
207 FAIL_RETURN_IF_NOT(r.expect(0), r);
208 FAIL_RETURN_IF_NOT(md.expect(0), md);
209 FAIL_RETURN_IF_NOT(mr.expect(0), mr);
210 return 0;
213 int test_assignment_from_reference_release_true()
215 expected_calls d(tested_element_traits::duplicate_calls);
216 expected_calls r(tested_element_traits::release_calls);
217 expected_calls md(mock_reference::duplicate_calls);
218 expected_calls mr(mock_reference::release_calls);
220 reference_type xe = mock_reference::allocate(1);
221 tested_element x(xe, true);
223 reference_type y = mock_reference::allocate(2);
225 FAIL_RETURN_IF_NOT(d.expect(0), d);
226 FAIL_RETURN_IF_NOT(r.expect(0), r);
228 x = y;
230 FAIL_RETURN_IF_NOT(d.expect(0), d);
231 FAIL_RETURN_IF_NOT(r.expect(1), r);
232 FAIL_RETURN_IF_NOT(md.expect(0), md);
233 FAIL_RETURN_IF_NOT(mr.expect(2), mr);
235 CHECK_EQUAL(2, x->id());
237 tested_element_traits::release(xe);
238 FAIL_RETURN_IF_NOT(r.expect(1), r);
239 FAIL_RETURN_IF_NOT(mr.expect(1), mr);
242 FAIL_RETURN_IF_NOT(d.expect(0), d);
243 FAIL_RETURN_IF_NOT(r.expect(0), r);
244 FAIL_RETURN_IF_NOT(md.expect(0), md);
245 FAIL_RETURN_IF_NOT(mr.expect(0), mr);
246 return 0;
249 int test_assignment_from_reference_release_false()
251 expected_calls d(tested_element_traits::duplicate_calls);
252 expected_calls r(tested_element_traits::release_calls);
253 expected_calls md(mock_reference::duplicate_calls);
254 expected_calls mr(mock_reference::release_calls);
256 reference_type xe = mock_reference::allocate(1);
257 reference_type oldxe = xe;
258 tested_element x(xe, false);
260 reference_type y = mock_reference::allocate(2);
262 FAIL_RETURN_IF_NOT(d.expect(0), d);
263 FAIL_RETURN_IF_NOT(r.expect(0), r);
265 x = y;
267 FAIL_RETURN_IF_NOT(d.expect(0), d);
268 FAIL_RETURN_IF_NOT(r.expect(0), r);
269 FAIL_RETURN_IF_NOT(md.expect(0), md);
270 FAIL_RETURN_IF_NOT(mr.expect(1), mr);
272 CHECK_EQUAL(2, x->id());
274 tested_element_traits::release(xe);
275 tested_element_traits::release(oldxe);
276 FAIL_RETURN_IF_NOT(r.expect(2), 2);
277 FAIL_RETURN_IF_NOT(mr.expect(2), mr);
280 FAIL_RETURN_IF_NOT(d.expect(0), d);
281 FAIL_RETURN_IF_NOT(r.expect(0), r);
282 FAIL_RETURN_IF_NOT(md.expect(0), md);
283 FAIL_RETURN_IF_NOT(mr.expect(0), mr);
284 return 0;
287 int ACE_TMAIN(int,ACE_TCHAR*[])
289 int status = 0;
292 status += test_assignment_from_var_release_true ();
293 status += test_assignment_from_var_release_false ();
294 status += test_assignment_from_var_throw ();
295 status += test_assignment_from_element_release_true ();
296 status += test_assignment_from_element_release_false ();
297 status += test_assignment_from_reference_release_true ();
298 status += test_assignment_from_reference_release_false ();
300 catch (const ::CORBA::Exception &ex)
302 ex._tao_print_exception("ERROR : unexpected CORBA exception caugth :");
303 ++status;
306 return status;