Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / Sequence_Unit_Tests / unbounded_sequence_cdr_ut.cpp
blob4f078ff5a51368bf3a0217efb8a5d5746c0c89e4
1 /**
2 * @file
4 * @brief Unit test for unbounded sequences of object references.
6 * @author Carlos O'Ryan
7 */
8 #include "testing_object_reference_traits.hpp"
9 #include "tao/Object_Reference_Traits_T.h"
10 #include "testing_allocation_traits.hpp"
11 #include "testing_range_checking.hpp"
13 #include "mock_reference.hpp"
15 #include "tao/Unbounded_Value_Sequence_T.h"
16 #include "tao/Unbounded_Octet_Sequence_T.h"
17 #include "tao/Unbounded_Object_Reference_Sequence_T.h"
18 #include "tao/Unbounded_Basic_String_Sequence_T.h"
19 #include "tao/Unbounded_BD_String_Sequence_T.h"
20 #include "tao/Unbounded_Sequence_CDR_T.h"
21 #include "tao/CDR.h"
23 #include "test_macros.h"
26 using namespace TAO_VERSIONED_NAMESPACE_NAME::TAO;
28 typedef unbounded_object_reference_sequence<mock_reference, mock_reference_var> tested_sequence;
30 CORBA::Boolean operator<< (TAO_OutputCDR &strm, const tested_sequence &sequence)
32 return TAO::marshal_sequence(strm, sequence);
35 CORBA::Boolean operator>> (TAO_InputCDR &strm, tested_sequence &sequence)
37 return TAO::demarshal_sequence(strm, sequence);
40 struct Tester
42 typedef tested_sequence::value_type value_type;
43 typedef tested_sequence::const_value_type const_value_type;
45 typedef tested_sequence::element_traits tested_element_traits;
46 typedef tested_sequence::allocation_traits tested_allocation_traits;
47 typedef TAO::details::range_checking<value_type,true> range;
49 value_type * alloc_and_init_buffer()
51 value_type * buf = tested_sequence::allocbuf(8);
52 buf[0] = mock_reference::allocate(1);
53 buf[1] = mock_reference::allocate(4);
54 buf[2] = mock_reference::allocate(9);
55 buf[3] = mock_reference::allocate(16);
57 return buf;
60 int check_values(tested_sequence const & a)
62 CHECK_EQUAL( 1, a[0]->id());
63 CHECK_EQUAL( 4, a[1]->id());
64 CHECK_EQUAL( 9, a[2]->id());
65 CHECK_EQUAL(16, a[3]->id());
66 return 0;
69 int test_stream()
71 value_type * buffer = alloc_and_init_buffer();
73 expected_calls s(mock_reference::marshal_calls);
75 tested_sequence a;
76 a.replace(8, 4, buffer, false);
78 CHECK_EQUAL(CORBA::ULong(8), a.maximum());
79 CHECK_EQUAL(CORBA::ULong(4), a.length());
80 CHECK_EQUAL(buffer, a.get_buffer());
81 CHECK_EQUAL(false, a.release());
82 check_values(a);
84 TAO_OutputCDR stream;
85 stream << a;
86 FAIL_RETURN_IF_NOT(s.expect(4), s);
88 tested_sequence::freebuf(buffer);
89 return 0;
93 int ACE_TMAIN(int,ACE_TCHAR*[])
95 int status = 0;
97 try
99 Tester x;
100 status += x.test_stream ();
102 catch (const ::CORBA::Exception &ex)
104 ex._tao_print_exception("ERROR : unexpected CORBA exception caugth :");
105 ++status;
107 return status;