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
;
23 template<typename charT
>
49 return string_traits
<char, true>::duplicate (sample0 ());
54 return string_traits
<char, true>::duplicate (sample1 ());
57 equal (char const *lhs
, char const *rhs
)
59 return ACE_OS::strcmp (lhs
, rhs
) == 0;
63 #if defined(ACE_HAS_WCHAR)
65 struct helper
<CORBA::WChar
>
67 static CORBA::WChar
const *
72 static CORBA::WChar
const *
77 static CORBA::WChar
const *
85 return string_traits
<CORBA::WChar
, true>::duplicate (sample0 ());
90 return string_traits
<CORBA::WChar
, true>::duplicate (sample1 ());
93 equal (CORBA::WChar
const *lhs
, CORBA::WChar
const *rhs
)
95 return ACE_OS::strcmp (lhs
, rhs
) == 0;
100 template<class charT
>
103 typedef string_traits
<charT
, true> tested_element_traits
;
104 typedef string_sequence_element
<tested_element_traits
> tested_element
;
105 typedef charT
*string_type
;
106 typedef charT
const *const_string_type
;
107 typedef typename
tested_element_traits::string_var string_var
;
108 typedef typename
tested_element_traits::string_mgr string_mgr
;
111 test_assignment_from_const_string ()
113 expected_calls
d (tested_element_traits::duplicate_calls
);
114 expected_calls
r (tested_element_traits::release_calls
);
117 string_type xe
= helper
<charT
>::dup_sample0 ();
118 const_string_type y
= helper
<charT
>::sample1 ();
122 tested_element
x(xe
, true);
123 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
124 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
128 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
129 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
132 helper
<charT
>::equal(helper
<charT
>::sample1(), xe
),
133 "Mismatch after assignment from const. expected="
134 << helper
<charT
>::sample0()
136 tested_element_traits::release (xe
);
137 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
139 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
140 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
145 test_assignment_from_element ()
147 expected_calls
d (tested_element_traits::duplicate_calls
);
148 expected_calls
r (tested_element_traits::release_calls
);
150 string_type xe
= helper
<charT
>::dup_sample0 ();
151 tested_element
x(xe
, true);
153 string_type ye
= helper
<charT
>::dup_sample1 ();
154 tested_element
y(ye
, true);
161 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
162 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
165 helper
<charT
>::equal(helper
<charT
>::sample1(), xe
),
166 "Mismatch after assignment from element. expected="
167 << helper
<charT
>::sample1()
170 tested_element_traits::release (xe
);
171 tested_element_traits::release (ye
);
172 FAIL_RETURN_IF_NOT(r
.expect(2), r
);
174 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
175 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
180 test_self_assignment ()
182 expected_calls
d (tested_element_traits::duplicate_calls
);
183 expected_calls
r (tested_element_traits::release_calls
);
185 string_type xe
= helper
<charT
>::dup_sample0 ();
187 tested_element
x(xe
, true);
194 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
195 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
198 helper
<charT
>::equal(helper
<charT
>::sample0(), xe
),
199 "Mismatch after self assignment. expected="
200 << helper
<charT
>::sample0()
203 tested_element_traits::release (xe
);
204 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
206 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
207 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
212 test_assignment_from_non_const_string ()
214 expected_calls
d (tested_element_traits::duplicate_calls
);
215 expected_calls
r (tested_element_traits::release_calls
);
219 tested_element
x(xe
, true);
222 tested_element_traits::duplicate (helper
<charT
>::sample0 ());
223 FAIL_RETURN_IF_NOT(d
.expect(1), d
);
224 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
228 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
229 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
232 helper
<charT
>::equal(helper
<charT
>::sample0(), xe
),
233 "Mismatch after assignment from non-const. expected="
234 << helper
<charT
>::sample0()
236 tested_element_traits::release (xe
);
237 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
239 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
240 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
245 test_copy_constructor ()
247 expected_calls
d (tested_element_traits::duplicate_calls
);
248 expected_calls
r (tested_element_traits::release_calls
);
252 tested_element_traits::duplicate (helper
<charT
>::sample0 ());
253 tested_element
x(xe
, true);
258 tested_element
y (x
);
260 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
261 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
264 helper
<charT
>::equal(helper
<charT
>::sample0(), y
),
265 "Mismatch after copy constructor. expected="
266 << helper
<charT
>::sample0()
269 tested_element_traits::release (xe
);
270 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
272 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
273 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
278 test_assignment_from_copy ()
280 expected_calls
d (tested_element_traits::duplicate_calls
);
281 expected_calls
r (tested_element_traits::release_calls
);
283 string_type xe
= helper
<charT
>::dup_sample0 ();
284 tested_element
x(xe
, true);
289 tested_element
y (x
);
293 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
296 helper
<charT
>::equal(helper
<charT
>::sample0(), xe
),
297 "Mismatch after assignment. expected="
298 << helper
<charT
>::sample0()
302 helper
<charT
>::equal(helper
<charT
>::sample0(), y
),
303 "Mismatch after assignment. expected="
304 << helper
<charT
>::sample0()
307 tested_element_traits::release (xe
);
308 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
310 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
311 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
316 test_assignment_from_var ()
318 expected_calls
d (tested_element_traits::duplicate_calls
);
319 expected_calls
r (tested_element_traits::release_calls
);
322 string_type xe
= helper
<charT
>::dup_sample1 ();
323 tested_element
x(xe
, true);
324 FAIL_RETURN_IF_NOT(d
.expect(1), d
);
326 string_var
y (helper
<charT
>::sample0());
328 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
329 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
333 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
336 helper
<charT
>::equal(helper
<charT
>::sample0(), xe
),
337 "Mismatch after assignment from var. expected="
338 << helper
<charT
>::sample0()
341 tested_element_traits::release (xe
);
342 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
344 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
345 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
350 test_assignment_from_mgr ()
352 expected_calls
d (tested_element_traits::duplicate_calls
);
353 expected_calls
r (tested_element_traits::release_calls
);
356 string_type xe
= helper
<charT
>::dup_sample1 ();
357 tested_element
x(xe
, true);
358 FAIL_RETURN_IF_NOT(d
.expect(1), d
);
361 y
= helper
<charT
>::sample0 ();
363 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
364 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
368 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
371 helper
<charT
>::equal(helper
<charT
>::sample0(), xe
),
372 "Mismatch after assignment from mgr. expected="
373 << helper
<charT
>::sample0()
376 tested_element_traits::release (xe
);
377 FAIL_RETURN_IF_NOT(r
.expect(1), r
);
379 FAIL_RETURN_IF_NOT(d
.expect(0), d
);
380 FAIL_RETURN_IF_NOT(r
.expect(0), r
);
387 status
+= this->test_assignment_from_const_string ();
388 status
+= this->test_assignment_from_element ();
389 status
+= this->test_self_assignment ();
390 status
+= this->test_assignment_from_non_const_string ();
391 status
+= this->test_copy_constructor ();
392 status
+= this->test_assignment_from_copy ();
393 status
+= this->test_assignment_from_var ();
394 status
+= this->test_assignment_from_mgr ();
399 int ACE_TMAIN (int, ACE_TCHAR
*[])
405 Tester
<char> char_tester
;
406 status
+= char_tester
.test_all ();
407 Tester
<char> wchar_tester
;
408 status
+= wchar_tester
.test_all ();
410 catch (const ::CORBA::Exception
& ex
)
412 ex
._tao_print_exception("ERROR : unexpected CORBA exception caugth :");