Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / Bug_3941_Regression / test.cpp
blob661c3bc07caa00884309d12a7ab010bfc14a5bfb
1 #include "testC.h"
3 int
4 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
6 try
8 CORBA::ORB_var orb =
9 CORBA::ORB_init (argc, argv);
11 test::event0_init *ev0_fac = 0;
12 ACE_NEW_RETURN (ev0_fac,
13 test::event0_init,
14 -1);
15 CORBA::ValueFactoryBase_var ev0_fac_owner (ev0_fac);
17 test::event1_init *ev1_fac = 0;
18 ACE_NEW_RETURN (ev1_fac,
19 test::event1_init,
20 -1);
21 CORBA::ValueFactoryBase_var ev1_fac_owner (ev1_fac);
23 orb->register_value_factory (ev0_fac->tao_repository_id (), ev0_fac);
24 orb->register_value_factory (ev1_fac->tao_repository_id (), ev1_fac);
26 test::event0_var ev0;
27 ACE_NEW_RETURN (ev0,
28 OBV_test::event0,
29 -1);
30 ev0->message ("one");
32 // write ev0 to CDR
33 TAO_OutputCDR cdr ((size_t) 0, // size
34 (int) ACE_CDR_BYTE_ORDER,
35 (ACE_Allocator *) 0, // buffer_allocator
36 (ACE_Allocator *) 0, // data_block_allocator
37 (ACE_Allocator *) 0, // message_block_allocator
38 0, // memcpy_tradeoff
40 1);
41 cdr.reset ();
43 if (!(cdr << ev0.in ()))
45 ACE_ERROR_RETURN ((LM_DEBUG,
46 "ERROR: cdr << ev0\n"),
47 -1);
50 // convert cdr into safe_octet_seq
51 CORBA::OctetSeq safe_octet_seq (cdr.total_length ());
52 safe_octet_seq.length (cdr.total_length ());
54 CORBA::Octet *buffer = safe_octet_seq.get_buffer ();
55 for (ACE_Message_Block const *i = cdr.begin ();
56 i != 0;
57 i = i->cont ())
59 CORBA::ULong len = i->length ();
60 ACE_OS::memcpy (buffer, i->rd_ptr (), (size_t) len);
61 buffer += len;
64 // Use TAO_InputCDR for unmarshalling
65 buffer = safe_octet_seq.get_buffer ();
66 size_t char_len = safe_octet_seq.length () * sizeof (CORBA::Octet);
67 TAO_InputCDR input ((char const*) buffer,
68 char_len,
69 ACE_CDR_BYTE_ORDER,
70 TAO_DEF_GIOP_MAJOR,
71 TAO_DEF_GIOP_MINOR,
72 orb->orb_core ());
74 // Read ev1 from CDR, this should fail (we actually encoded a ev0),
75 // but *NOT* leak memory.
76 test::event1_var ev1;
77 if (input >> ev1.out ())
79 ACE_ERROR_RETURN ((LM_DEBUG,
80 "ERROR: unmarshal shouldn't work\n"),
81 -1);
84 ACE_DEBUG ((LM_DEBUG,
85 "Test passed.\n"));
87 orb->destroy ();
89 catch (const CORBA::Exception& ex)
91 ex._tao_print_exception (
92 "Caught exception in server:");
93 return 1;
96 return 0;