Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Bug_3919_Regression / client.cpp
blob83e67ab411b6e30205334aaef5bb353b33f86e44
1 #include "Test2C.h"
2 #include "tao/IFR_Client/IFR_BaseC.h"
3 #include "tao/TypeCodeFactory/TypeCodeFactory_Loader.h"
5 #include "ace/Get_Opt.h"
7 #include <algorithm>
8 #include <functional>
10 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
16 int c;
18 while ((c = get_opts ()) != -1)
19 switch (c)
21 case 'k':
22 ior = get_opts.opt_arg ();
23 break;
25 case '?':
26 case 'h':
27 default:
28 ACE_ERROR_RETURN ((LM_ERROR,
29 "usage: %s "
30 "-k <ior> "
31 "\n",
32 argv [0]),
33 -1);
36 // Successful command line parsing.
37 return 0;
40 template<typename T> void dump (T *); // Forward declaration.
42 template<typename T>
43 void
44 perform_invocation (Test::Hello_ptr hello,
45 CORBA::Any const & the_any)
47 // Execute more than once to help verify that mutable recursive
48 // TypeCode state is managed correctly.
49 for (unsigned int n = 0; n < 2; ++n)
51 CORBA::Any_var my_any =
52 hello->get_any (the_any);
54 const T * my_foo = 0;
55 if (!(my_any.in () >>= my_foo))
56 throw Test::Demarshaling_From_Any_Failed ();
58 CORBA::TypeCode_var the_tc = the_any.type ();
59 CORBA::TypeCode_var my_tc = my_any->type ();
61 CORBA::Boolean const equal_tc =
62 the_tc->equal (my_tc.in ());
64 if (!equal_tc)
65 throw Test::Recursive_Type_In_Any_Test_Failed ();
67 CORBA::Boolean const equiv_tc =
68 the_tc->equivalent (my_tc.in ());
70 if (!equiv_tc)
71 throw Test::Recursive_Type_In_Any_Test_Failed ();
75 void
76 recursive_typecode_test (CORBA::ORB_ptr /* orb */,
77 Test::Hello_ptr hello)
79 ACE_DEBUG ((LM_INFO,
80 "Executing recursive typecode test\n"));
82 CORBA::Any the_any;
84 Test::MyAttRefSequence test;
86 Test::MyAttRef attr;
87 attr.attRefName="attr";
88 attr.attRefValue.attrValue("value");
89 attr.attRefQualifier="atrQ1";
91 Test::MyAttRef attr2;
92 attr2.attRefName="attr2";
93 attr2.attRefValue.attrValue("value2");
94 attr2.attRefQualifier="atrQ2";
96 Test::MyAttRef comp;
97 comp.attRefName="comp1";
98 comp.attRefQualifier="compQ";
100 Test::MyAttRef::MyAttRefValue::_compValue_seq compSeq(1);
101 compSeq.length(1);
102 compSeq[0]=attr2;
103 comp.attRefValue.compValue(compSeq);
105 Test::MyAttRef inti;
106 inti.attRefName="intval";
107 inti.attRefValue.intValue(0xAFFEAFFE);
109 test.length(3);
110 test[0] = comp;
111 test[1] = inti;
112 test[2] = attr;
114 the_any <<= test;
116 ::perform_invocation<Test::MyAttRefSequence> (hello, the_any);
119 void
120 nested_recursive_typecode_test (CORBA::ORB_ptr /* orb */,
121 Test::Hello_ptr hello)
123 ACE_DEBUG ((LM_INFO,
124 "Executing nested recursive typecode test\n"));
126 CORBA::Any the_any;
128 Test2::MyAttRefSeqStruct test;
130 Test::MyAttRef attr;
131 attr.attRefName="attr";
132 attr.attRefValue.attrValue("value");
133 attr.attRefQualifier="atrQ1";
135 Test::MyAttRef attr2;
136 attr2.attRefName="attr2";
137 attr2.attRefValue.attrValue("value2");
138 attr2.attRefQualifier="atrQ2";
140 Test::MyAttRef comp;
141 comp.attRefName="comp1";
142 comp.attRefQualifier="compQ";
144 Test::MyAttRef::MyAttRefValue::_compValue_seq compSeq(1);
145 compSeq.length(1);
146 compSeq[0]=attr2;
147 comp.attRefValue.compValue(compSeq);
149 Test::MyAttRef inti;
150 inti.attRefName="intval";
151 inti.attRefValue.intValue(0xAFFEAFFE);
153 test.attRefSeq.length(3);
154 test.attRefSeq[0] = comp;
155 test.attRefSeq[1] = inti;
156 test.attRefSeq[2] = attr;
158 the_any <<= test;
160 ::perform_invocation<Test2::MyAttRefSeqStruct> (hello, the_any);
164 * @struct Caller
166 * @brief Test method invocation functor.
168 * Test method invocation functor.
170 template <typename T>
171 struct Caller : public std::function<void(T)>
173 /// Constructor.
174 Caller (CORBA::ORB_ptr o, Test::Hello_ptr h)
175 : orb (CORBA::ORB::_duplicate (o))
176 , hello (Test::Hello::_duplicate (h))
177 , success (true)
181 /// Function call operator overload.
182 void operator() (T f)
186 f (orb.in (),
187 hello.in ());
189 catch (const CORBA::Exception& ex)
191 ex._tao_print_exception ("Exception thrown:");
193 success = false;
197 CORBA::ORB_var orb;
198 Test::Hello_var hello;
199 bool success;
203 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
207 CORBA::ORB_var orb =
208 CORBA::ORB_init (argc, argv);
210 if (parse_args (argc, argv) != 0)
211 return 1;
213 CORBA::Object_var tmp =
214 orb->string_to_object(ior);
216 Test::Hello_var hello =
217 Test::Hello::_narrow(tmp.in ());
219 if (CORBA::is_nil (hello.in ()))
221 ACE_ERROR_RETURN ((LM_DEBUG,
222 "Nil Test::Hello reference <%s>\n",
223 ior),
227 typedef void (*test_func) (CORBA::ORB_ptr,
228 Test::Hello_ptr);
230 static test_func const tests[] =
232 recursive_typecode_test,
233 nested_recursive_typecode_test
236 static size_t const test_count = sizeof (tests) / sizeof (test_func);
238 // Have some fun with the STL. :-)
239 Caller<test_func> c =
240 std::for_each (tests,
241 tests + test_count,
242 Caller<test_func> (orb.in (),
243 hello.in ()));
245 if (!c.success)
246 throw Test::Recursive_Type_In_Any_Test_Failed ();
248 hello->shutdown ();
250 orb->destroy ();
252 catch (const CORBA::Exception& ex)
254 ex._tao_print_exception ("Exception caught:");
255 return 1;
258 return 0;