Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Bug_4097_Regression / Bug_4097_Regression.cpp
blob579feca98c7081f5201bb98113399dbd84037d6c
1 #include "Bug_4097_RegressionS.h"
3 #include "tao/corba.h"
4 #include "tao/ORB.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"
14 namespace {
15 bool
16 checkResult (const CORBA::Any &any, const MultiLabelUnion &mlu)
18 bool error = false;
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 ()));
26 else
28 ACE_DEBUG ((LM_DEBUG, ". Extracted descriminant is WRONG (%d)\n", extracted->_d ()));
29 error = true;
31 if (extracted->mlu_char () == mlu.mlu_char ())
33 ACE_DEBUG ((LM_DEBUG, ". Extracted value is correct (%c)\n", extracted->mlu_char ()));
35 else
37 ACE_DEBUG ((LM_DEBUG, ". Extracted value is WRONG (%c)\n", extracted->mlu_char ()));
38 error = true;
41 else
43 ACE_DEBUG ((LM_DEBUG, ". DID NOT Extract from any (Test Failure)\n"));
44 error = true;
47 return error;
49 } // End of unnamed namespace
51 int
52 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
54 ACE_DEBUG ((LM_DEBUG, "Starting\n"));
55 try
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"));
71 MultiLabelUnion mlu;
72 mlu.mlu_char ('x');
73 CORBA::Any any;
74 any <<= mlu;
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);
81 if (!decoded.ptr ())
83 ACE_DEBUG ((LM_DEBUG, "No decoding\n"));
84 error = true;
86 else if (checkResult (decoded.in (), mlu))
88 error = true;
91 ACE_DEBUG ((LM_DEBUG, "Creating union using case 0\n"));
92 mlu.mlu_char ('y');
93 mlu._d (static_cast<CORBA::Long> (0)); // Note first case label for type.
94 any <<= mlu;
95 if (checkResult (any, mlu))
97 error = true;
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);
104 if (!decoded.ptr ())
106 ACE_DEBUG ((LM_DEBUG, "No decoding\n"));
107 error = true;
109 else if (checkResult (decoded.in (), mlu))
111 error = true;
114 ACE_DEBUG ((LM_DEBUG, "Creating union using case 1\n"));
115 mlu.mlu_char ('z');
116 mlu._d (static_cast<CORBA::Long> (1)); // Note second case label for same type as before
117 any <<= mlu;
118 if (checkResult (any, mlu))
120 error = true;
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);
127 if (!decoded.ptr ())
129 ACE_DEBUG ((LM_DEBUG, "No decoding\n"));
130 error = true;
132 else if (checkResult (decoded.in (), mlu))
134 error = true;
137 if (error)
139 ACE_DEBUG ((LM_DEBUG, "Test FAILED.\n"));
140 return 1;
143 catch (const CORBA::Exception &ex)
145 ex._tao_print_exception ("Test FAILED due to Exception:");
146 return 1;
148 catch (...)
150 ACE_DEBUG ((LM_DEBUG, "Test FAILED (UNKNOWN exception).\n"));
151 return 1;
154 ACE_DEBUG ((LM_DEBUG, "Test SUCCEEDED.\n"));
155 return 0;