Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / Sequence_Unit_Tests / string_ut.cpp
blob0a1b2bff5586f0dd7eca26e015608fd93df9bad8
1 /**
2 * @file
4 * @brief Unit test for CORBA string
6 * @author Johnny Willemsen
7 */
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>
20 struct helper {};
22 template<>
23 struct helper<char>
25 static char const * empty() {
26 return "";
28 static char const * sample0() {
29 return "Hello";
31 static char const * sample1() {
32 return "World";
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;
45 template<>
46 struct helper<CORBA::WChar>
48 static CORBA::WChar const * empty() {
49 return L"";
51 static CORBA::WChar const * sample0() {
52 return L"Hello";
54 static CORBA::WChar const * sample1() {
55 return L"World";
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;
68 template<class charT>
69 struct Tester
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();
85 string_var xb (xe);
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,
98 shared_this));
101 static boost::shared_ptr<Tester> allocate()
103 boost::shared_ptr<Tester> ptr(new Tester);
104 ptr->self_ = ptr;
106 return ptr;
109 private:
110 Tester() {}
112 boost::weak_ptr<Tester> self_;
115 test_suite *
116 init_unit_test_suite(int, char*[])
118 test_suite * ts =
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);
129 return ts;