Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Bug_2918_Regression / client.cpp
blob7a4d6ed1b5e0117cdec272414d27caf4ad181316
1 #include "TestC.h"
2 #include "tao/IFR_Client/IFR_BaseC.h"
3 #include "tao/TypeCodeFactory/TypeCodeFactory_Loader.h"
4 #include "ace/Get_Opt.h"
6 #include <algorithm>
7 #include <functional>
9 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'k':
21 ior = get_opts.opt_arg ();
22 break;
24 case '?':
25 case 'h':
26 default:
27 ACE_ERROR_RETURN ((LM_ERROR,
28 "usage: %s "
29 "-k <ior> "
30 "\n",
31 argv [0]),
32 -1);
35 // Successful command line parsing.
36 return 0;
39 template<typename T> void dump (T *); // Forward declaration.
41 template<typename T>
42 void
43 perform_invocation (Test::Hello_ptr hello,
44 CORBA::Any const & the_any)
46 // Execute more than once to help verify that mutable repeated
47 // TypeCode state is managed correctly.
48 for (unsigned int n = 0; n < 2; ++n)
50 CORBA::Any_var my_any =
51 hello->get_any (the_any);
53 const T * my_foo = 0;
54 if (!(my_any.in () >>= my_foo))
55 throw Test::Demarshaling_From_Any_Failed ();
57 CORBA::TypeCode_var the_tc = the_any.type ();
58 CORBA::TypeCode_var my_tc = my_any->type ();
60 CORBA::Boolean const equal_tc =
61 the_tc->equal (my_tc.in ());
63 if (!equal_tc)
64 throw Test::Repeated_Type_In_Any_Test_Failed ();
66 CORBA::Boolean const equiv_tc =
67 the_tc->equivalent (my_tc.in ());
69 if (!equiv_tc)
70 throw Test::Repeated_Type_In_Any_Test_Failed ();
74 void
75 repeated_struct_test (CORBA::ORB_ptr /* orb */,
76 Test::Hello_ptr hello)
78 ACE_DEBUG ((LM_INFO,
79 "Executing repeated struct test\n"));
81 Test::FooStruct foo;
83 foo.Foo1 = 2;
84 foo.Foo2 = 37;
86 CORBA::Any the_any;
87 the_any <<= foo;
89 ::perform_invocation<Test::FooStruct> (hello, the_any);
92 /**
93 * @struct Caller
95 * @brief Test method invocation functor.
97 * Test method invocation functor.
99 template <typename T>
100 struct Caller : public std::function<void(T)>
102 /// Constructor.
103 Caller (CORBA::ORB_ptr o, Test::Hello_ptr h)
104 : orb (CORBA::ORB::_duplicate (o))
105 , hello (Test::Hello::_duplicate (h))
106 , success (true)
110 /// Function call operator overload.
111 void operator() (T f)
115 f (orb.in (),
116 hello.in ());
118 catch (const CORBA::Exception& ex)
120 ex._tao_print_exception ("Exception thrown:");
122 success = false;
126 CORBA::ORB_var orb;
127 Test::Hello_var hello;
128 bool success;
132 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
136 CORBA::ORB_var orb =
137 CORBA::ORB_init (argc, argv);
139 if (parse_args (argc, argv) != 0)
140 return 1;
142 CORBA::Object_var tmp =
143 orb->string_to_object(ior);
145 Test::Hello_var hello =
146 Test::Hello::_narrow(tmp.in ());
148 if (CORBA::is_nil (hello.in ()))
150 ACE_ERROR_RETURN ((LM_DEBUG,
151 "Nil Test::Hello reference <%s>\n",
152 ior),
156 typedef void (*test_func) (CORBA::ORB_ptr,
157 Test::Hello_ptr);
159 static test_func const tests[] =
161 repeated_struct_test
164 static size_t const test_count = sizeof (tests) / sizeof (test_func);
166 // Have some fun with the STL. :-)
167 Caller<test_func> c =
168 std::for_each (tests,
169 tests + test_count,
170 Caller<test_func> (orb.in (),
171 hello.in ()));
173 if (!c.success)
174 throw Test::Repeated_Type_In_Any_Test_Failed ();
176 hello->shutdown ();
178 orb->destroy ();
180 catch (const CORBA::Exception& ex)
182 ex._tao_print_exception ("Exception caught:");
183 return 1;
186 return 0;