1 #include "Bug_4097_RegressionS.h"
5 #include "tao/Object.h"
6 #include "tao/Object_T.h"
7 #include "tao/ORB_Core.h"
8 #include "tao/CodecFactory/CodecFactory.h"
10 #include "ace/Log_Msg.h"
11 #include "ace/OS_NS_string.h"
12 #include "tao/AnyTypeCode/Any.h"
16 checkResult (const CORBA::Any
&any
, const MultiLabelUnion
&mlu
)
19 const MultiLabelUnion
*extracted
= 0;
20 if (any
>>= extracted
)
22 if (extracted
->_d () == mlu
._d ())
24 ACE_DEBUG ((LM_DEBUG
, ". Extracted descriminant is correct (%d)\n", extracted
->_d ()));
28 ACE_DEBUG ((LM_DEBUG
, ". Extracted descriminant is WRONG (%d)\n", extracted
->_d ()));
31 if (extracted
->mlu_char () == mlu
.mlu_char ())
33 ACE_DEBUG ((LM_DEBUG
, ". Extracted value is correct (%c)\n", extracted
->mlu_char ()));
37 ACE_DEBUG ((LM_DEBUG
, ". Extracted value is WRONG (%c)\n", extracted
->mlu_char ()));
43 ACE_DEBUG ((LM_DEBUG
, ". DID NOT Extract from any (Test Failure)\n"));
49 } // End of unnamed namespace
52 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
54 ACE_DEBUG ((LM_DEBUG
, "Starting\n"));
57 CORBA::ORB_var
orb (CORBA::ORB_init (argc
, argv
));
59 CORBA::Object_var
obj (orb
->resolve_initial_references ("CodecFactory"));
60 IOP::CodecFactory_var
codecFactory (IOP::CodecFactory::_narrow (obj
.in ()));
62 IOP::Encoding cdr_encoding
;
63 cdr_encoding
.format
= IOP::ENCODING_CDR_ENCAPS
;
64 cdr_encoding
.major_version
= 1;
65 cdr_encoding
.minor_version
= 2;
66 IOP::Codec_var
codec (codecFactory
->create_codec (cdr_encoding
));
68 // Test starts here with first case
70 ACE_DEBUG ((LM_DEBUG
, "Creating union using default descriminant of mlu_char type\n"));
75 bool error
= checkResult (any
, mlu
);
77 ACE_DEBUG ((LM_DEBUG
, "Encode->Decode any with union using default descriminant of mlu_char type\n"));
78 CORBA::OctetSeq_var
messageInCDR (codec
->encode (any
));
79 ACE_DEBUG ((LM_DEBUG
, ". Size of encoding is %d\n", messageInCDR
->length ()));
80 CORBA::Any_var decoded
= codec
->decode (messageInCDR
);
83 ACE_DEBUG ((LM_DEBUG
, "No decoding\n"));
86 else if (checkResult (decoded
.in (), mlu
))
91 ACE_DEBUG ((LM_DEBUG
, "Creating union using case 0\n"));
93 mlu
._d (static_cast<CORBA::Long
> (0)); // Note first case label for type.
95 if (checkResult (any
, mlu
))
100 ACE_DEBUG ((LM_DEBUG
, "Encode->Decode any with union using case 0\n"));
101 messageInCDR
= codec
->encode (any
);
102 ACE_DEBUG ((LM_DEBUG
, ". Size of encoding is %d\n", messageInCDR
->length ()));
103 decoded
= codec
->decode (messageInCDR
);
106 ACE_DEBUG ((LM_DEBUG
, "No decoding\n"));
109 else if (checkResult (decoded
.in (), mlu
))
114 ACE_DEBUG ((LM_DEBUG
, "Creating union using case 1\n"));
116 mlu
._d (static_cast<CORBA::Long
> (1)); // Note second case label for same type as before
118 if (checkResult (any
, mlu
))
123 ACE_DEBUG ((LM_DEBUG
, "Encode->Decode any with union using case 1\n"));
124 messageInCDR
= codec
->encode (any
);
125 ACE_DEBUG ((LM_DEBUG
, ". Size of encoding is %d\n", messageInCDR
->length ()));
126 decoded
= codec
->decode (messageInCDR
);
129 ACE_DEBUG ((LM_DEBUG
, "No decoding\n"));
132 else if (checkResult (decoded
.in (), mlu
))
139 ACE_DEBUG ((LM_DEBUG
, "Test FAILED.\n"));
143 catch (const CORBA::Exception
&ex
)
145 ex
._tao_print_exception ("Test FAILED due to Exception:");
150 ACE_DEBUG ((LM_DEBUG
, "Test FAILED (UNKNOWN exception).\n"));
154 ACE_DEBUG ((LM_DEBUG
, "Test SUCCEEDED.\n"));