Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / Bug_3552_Regression / check.cpp
blobd6b205dd0de6f01e89ae7466fde47ad996f6db60
1 #include "tao/CodecFactory/CodecFactory.h"
2 #include "structC.h"
4 int
5 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
7 int result = 1; // Failed until changed.
9 try
11 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
13 // Obtain the reference to the CodecFactory.
14 CORBA::Object_var
15 obj = orb->resolve_initial_references ("CodecFactory");
16 IOP::CodecFactory_var
17 codec_factory = IOP::CodecFactory::_narrow (obj.in ());
19 // Obtain the codec from the factory.
20 // Set up a structure that contains information necessary to
21 // create a GIOP 1.2 CDR encapsulation Codec.
22 IOP::Encoding encoding;
23 encoding.format = IOP::ENCODING_CDR_ENCAPS;
24 encoding.major_version = 1;
25 encoding.minor_version = 2;
26 IOP::Codec_var
27 codec = codec_factory->create_codec (encoding);
29 // Create the CDR we want to check
30 CORBA::Octet mixedEndianCDR[]= {
31 // Starts off BigEndian
32 0x00, // BigEndian mark
33 0x1a, 0x87, 0x00, // 3 bytes padding
34 0x00, 0x00, 0x00, 0x0f, // Typecode = tk_struct
35 0x00, 0x00, 0x00, 0x4c, // Length of embedded encapsulation
36 // Has an embedded LittleEndian bit
37 0x01, // LittleEndian mark
38 0x1a, 0x87, 0x00, // 3 bytes padding
39 0x17, 0x00, 0x00, 0x00, // Length of ID string
40 0x49, 0x44, 0x4c, 0x3a, 0x54, 0x65, 0x73, 0x74, // "IDL:Test"
41 0x2f, 0x74, 0x68, 0x65, 0x53, 0x74, 0x72, 0x75, // "/theStru"
42 0x63, 0x74, 0x3a, 0x31, 0x2e, 0x30, 0x00, // "ct:1.0" + Null
43 0x00, // 1 byte Padding
44 0x0a, 0x00, 0x00, 0x00, // Length of simple name
45 0x74, 0x68, 0x65, 0x53, 0x74, 0x72, 0x75, 0x63, // "theStruc"
46 0x74, 0x00, // "t" + Null
47 0x00, 0x00, // 2 bytes padding
48 0x01, 0x00, 0x00, 0x00, // Has One member
49 0x0a, 0x00, 0x00, 0x00, // Length of member name
50 0x74, 0x68, 0x65, 0x53, 0x74, 0x72, 0x69, 0x6e, // "theStrin"
51 0x67, 0x00, // "g" + Null
52 0x00, 0x00, // 2 bytes padding
53 0x12, 0x00, 0x00, 0x00, // member typecode = tk_string
54 0x00, 0x00, 0x00, 0x00, // Of Variable length
55 // Should now return back to outer scope BigEndian
56 0x00, 0x00, 0x00, 0x06, // (Length of value)
57 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x00 // "Hello" + Null
59 const unsigned int
60 mixedEndianCDRLength= sizeof (mixedEndianCDR) / sizeof (mixedEndianCDR[0]);
62 // We actually need this to be a sequence of octets (Don't delete them on destruction)
63 CORBA::OctetSeq
64 OctSeq (mixedEndianCDRLength, mixedEndianCDRLength, mixedEndianCDR, 0);
66 // Now try and decode this message
67 CORBA::Any_var
68 decodedData = codec->decode (OctSeq);
69 // And extract the actual struct (still owned by the any)
70 const Test::theStruct *myStruct = 0;
71 if (decodedData.in () >>= myStruct)
73 if (!strcmp (myStruct->theString, "Hello"))
75 result = 0; // Success!
77 else
79 ACE_DEBUG ((LM_DEBUG,
80 "ERROR: Unexpected string=\"%C\" (should be \"Hello\")\n",
81 myStruct->theString.in ()));
84 else
86 ACE_DEBUG ((LM_DEBUG, "ERROR: Didn't decode the Struct\n"));
89 catch (const CORBA::Exception& ex)
91 ex._tao_print_exception ("Caught:");
94 if (result)
95 ACE_DEBUG ((LM_DEBUG, "Mixed Endian CDR decoding is NOT working\nTest Failed!\n"));
96 else
97 ACE_DEBUG ((LM_DEBUG, "Mixed Endian CDR decoding is working\nTest Passed!\n"));
98 return result;