4 * @brief Unit test for CORBA string
6 * @author Johnny Willemsen
8 #include "testing_string_traits.hpp"
9 #include "tao/CORBA_String.h"
11 #include "ace/OS_NS_string.h"
13 #include "test_macros.h"
15 using namespace TAO::details
;
17 using namespace boost::unit_test_framework
;
19 template<typename charT
>
25 static char const * empty() {
28 static char const * sample0() {
31 static char const * sample1() {
34 static char * dup_sample0() {
35 return string_traits
<char,true>::duplicate(sample0());
37 static char * dup_sample1() {
38 return string_traits
<char,true>::duplicate(sample1());
40 static bool equal(char const * lhs
, char const * rhs
) {
41 return ACE_OS::strcmp(lhs
, rhs
) == 0;
46 struct helper
<CORBA::WChar
>
48 static CORBA::WChar
const * empty() {
51 static CORBA::WChar
const * sample0() {
54 static CORBA::WChar
const * sample1() {
57 static CORBA::WChar
* dup_sample0() {
58 return string_traits
<CORBA::WChar
,true>::duplicate(sample0());
60 static CORBA::WChar
* dup_sample1() {
61 return string_traits
<CORBA::WChar
,true>::duplicate(sample1());
63 static bool equal(CORBA::WChar
const * lhs
, CORBA::WChar
const * rhs
) {
64 return ACE_OS::strcmp(lhs
, rhs
) == 0;
71 typedef string_traits
<charT
,true> tested_string_traits
;
72 typedef charT
* string_type
;
73 typedef charT
const * const_string_type
;
74 typedef typename
tested_string_traits::string_var string_var
;
75 typedef typename
tested_string_traits::string_mgr string_mgr
;
76 typedef typename
tested_string_traits::string_out string_out
;
78 void test_copy_constructor()
80 expected_calls
d(tested_string_traits::duplicate_calls
);
81 expected_calls
r(tested_string_traits::release_calls
);
84 string_var xe
= helper
<charT
>::dup_sample0();
88 BOOST_CHECK_MESSAGE(d
.expect(1), d
);
89 BOOST_CHECK_MESSAGE(r
.expect(1), r
);
92 void add_all(test_suite
* ts
)
94 boost::shared_ptr
<Tester
> shared_this(self_
);
96 ts
->add(BOOST_CLASS_TEST_CASE(
97 &Tester::test_copy_constructor
,
101 static boost::shared_ptr
<Tester
> allocate()
103 boost::shared_ptr
<Tester
> ptr(new Tester
);
112 boost::weak_ptr
<Tester
> self_
;
116 init_unit_test_suite(int, char*[])
119 BOOST_TEST_SUITE("string unit test");
121 boost::shared_ptr
<Tester
<char> > char_tester(
122 Tester
<char>::allocate());
123 char_tester
->add_all(ts
);
125 boost::shared_ptr
<Tester
<CORBA::WChar
> > wchar_tester(
126 Tester
<CORBA::WChar
>::allocate());
127 wchar_tester
->add_all(ts
);