4 * @brief Unit test for string_sequence_element, this is the type
5 * returned by operator[] from a string sequence.
7 * @author Carlos O'Ryan
9 #include "testing_string_traits.hpp"
10 #include "tao/String_Sequence_Element_T.h"
11 #include "tao/String_Manager_T.h"
12 #include "tao/CORBA_String.h"
13 #include "tao/SystemException.h"
15 #include "ace/OS_NS_string.h"
17 #include "test_macros.h"
19 using namespace TAO_VERSIONED_NAMESPACE_NAME::TAO::details
;
22 template<typename charT
>
48 return string_traits
<char, true>::duplicate (sample0 ());
53 return string_traits
<char, true>::duplicate (sample1 ());
56 equal (char const *lhs
, char const *rhs
)
58 return ACE_OS::strcmp (lhs
, rhs
) == 0;
62 #if defined(ACE_HAS_WCHAR)
64 struct helper
<CORBA::WChar
>
66 static CORBA::WChar
const *
71 static CORBA::WChar
const *
76 static CORBA::WChar
const *
84 return string_traits
<CORBA::WChar
, true>::duplicate (sample0 ());
89 return string_traits
<CORBA::WChar
, true>::duplicate (sample1 ());
92 equal (CORBA::WChar
const *lhs
, CORBA::WChar
const *rhs
)
94 return ACE_OS::strcmp (lhs
, rhs
) == 0;
102 typedef string_traits
<charT
, true> tested_element_traits
;
103 typedef string_sequence_element
<tested_element_traits
> tested_element
;
104 typedef charT
*string_type
;
105 typedef charT
const *const_string_type
;
106 typedef typename
tested_element_traits::string_var string_var
;
107 typedef typename
tested_element_traits::string_mgr string_mgr
;
110 test_assignment_from_const_string ()
112 expected_calls
d (tested_element_traits::duplicate_calls
);
113 expected_calls
r (tested_element_traits::release_calls
);
116 string_type xe
= helper
<charT
>::dup_sample0 ();
117 const_string_type y
= helper
<charT
>::sample1 ();
121 tested_element
x(xe
, true);
122 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
123 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
127 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
128 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
131 helper
<charT
>::equal(helper
<charT
>::sample1(), xe
),
132 "Mismatch after assignment from const. expected="
133 << helper
<charT
>::sample0()
135 tested_element_traits::release (xe
);
136 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
138 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
139 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
144 test_assignment_from_element ()
146 expected_calls
d (tested_element_traits::duplicate_calls
);
147 expected_calls
r (tested_element_traits::release_calls
);
149 string_type xe
= helper
<charT
>::dup_sample0 ();
150 tested_element
x(xe
, true);
152 string_type ye
= helper
<charT
>::dup_sample1 ();
153 tested_element
y(ye
, true);
160 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
161 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
164 helper
<charT
>::equal(helper
<charT
>::sample1(), xe
),
165 "Mismatch after assignment from element. expected="
166 << helper
<charT
>::sample1()
169 tested_element_traits::release (xe
);
170 tested_element_traits::release (ye
);
171 FAIL_RETURN_IF_NOT(r
.expect(2), r
);
173 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
174 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
179 test_self_assignment ()
181 expected_calls
d (tested_element_traits::duplicate_calls
);
182 expected_calls
r (tested_element_traits::release_calls
);
184 string_type xe
= helper
<charT
>::dup_sample0 ();
186 tested_element
x(xe
, true);
193 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
194 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
197 helper
<charT
>::equal(helper
<charT
>::sample0(), xe
),
198 "Mismatch after self assignment. expected="
199 << helper
<charT
>::sample0()
202 tested_element_traits::release (xe
);
203 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
205 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
206 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
211 test_assignment_from_non_const_string ()
213 expected_calls
d (tested_element_traits::duplicate_calls
);
214 expected_calls
r (tested_element_traits::release_calls
);
218 tested_element
x(xe
, true);
221 tested_element_traits::duplicate (helper
<charT
>::sample0 ());
222 FAIL_RETURN_IF_NOT(d
.expect(1), d
);
223 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
227 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
228 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
231 helper
<charT
>::equal(helper
<charT
>::sample0(), xe
),
232 "Mismatch after assignment from non-const. expected="
233 << helper
<charT
>::sample0()
235 tested_element_traits::release (xe
);
236 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
238 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
239 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
244 test_copy_constructor ()
246 expected_calls
d (tested_element_traits::duplicate_calls
);
247 expected_calls
r (tested_element_traits::release_calls
);
251 tested_element_traits::duplicate (helper
<charT
>::sample0 ());
252 tested_element
x(xe
, true);
257 tested_element
y (x
);
259 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
260 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
263 helper
<charT
>::equal(helper
<charT
>::sample0(), y
),
264 "Mismatch after copy constructor. expected="
265 << helper
<charT
>::sample0()
268 tested_element_traits::release (xe
);
269 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
271 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
272 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
277 test_assignment_from_copy ()
279 expected_calls
d (tested_element_traits::duplicate_calls
);
280 expected_calls
r (tested_element_traits::release_calls
);
282 string_type xe
= helper
<charT
>::dup_sample0 ();
283 tested_element
x(xe
, true);
288 tested_element
y (x
);
292 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
295 helper
<charT
>::equal(helper
<charT
>::sample0(), xe
),
296 "Mismatch after assignment. expected="
297 << helper
<charT
>::sample0()
301 helper
<charT
>::equal(helper
<charT
>::sample0(), y
),
302 "Mismatch after assignment. expected="
303 << helper
<charT
>::sample0()
306 tested_element_traits::release (xe
);
307 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
309 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
310 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
315 test_assignment_from_var ()
317 expected_calls
d (tested_element_traits::duplicate_calls
);
318 expected_calls
r (tested_element_traits::release_calls
);
321 string_type xe
= helper
<charT
>::dup_sample1 ();
322 tested_element
x(xe
, true);
323 FAIL_RETURN_IF_NOT(d
.expect(1), d
);
325 string_var
y (helper
<charT
>::sample0());
327 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
328 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
332 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
335 helper
<charT
>::equal(helper
<charT
>::sample0(), xe
),
336 "Mismatch after assignment from var. expected="
337 << helper
<charT
>::sample0()
340 tested_element_traits::release (xe
);
341 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
343 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
344 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
349 test_assignment_from_mgr ()
351 expected_calls
d (tested_element_traits::duplicate_calls
);
352 expected_calls
r (tested_element_traits::release_calls
);
355 string_type xe
= helper
<charT
>::dup_sample1 ();
356 tested_element
x(xe
, true);
357 FAIL_RETURN_IF_NOT(d
.expect(1), d
);
360 y
= helper
<charT
>::sample0 ();
362 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
363 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
367 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
370 helper
<charT
>::equal(helper
<charT
>::sample0(), xe
),
371 "Mismatch after assignment from mgr. expected="
372 << helper
<charT
>::sample0()
375 tested_element_traits::release (xe
);
376 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
378 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
379 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
386 status
+= this->test_assignment_from_const_string ();
387 status
+= this->test_assignment_from_element ();
388 status
+= this->test_self_assignment ();
389 status
+= this->test_assignment_from_non_const_string ();
390 status
+= this->test_copy_constructor ();
391 status
+= this->test_assignment_from_copy ();
392 status
+= this->test_assignment_from_var ();
393 status
+= this->test_assignment_from_mgr ();
398 int ACE_TMAIN (int, ACE_TCHAR
*[])
404 Tester
<char> char_tester
;
405 status
+= char_tester
.test_all ();
406 Tester
<char> wchar_tester
;
407 status
+= wchar_tester
.test_all ();
409 catch (const ::CORBA::Exception
& ex
)
411 ex
._tao_print_exception("ERROR : unexpected CORBA exception caugth :");