Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Bug_2844_Regression / client.cpp
blob7021b6ff0d991554c216300215d9840def0c39c6
1 #include "TestC.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 nested_recursive_struct_test (CORBA::ORB_ptr /* orb */,
77 Test::Hello_ptr hello)
79 ACE_DEBUG ((LM_INFO,
80 "Executing nested recursive struct test\n"));
82 CORBA::Any the_any;
84 Test::NestedRecursiveStruct5 foo5;
86 the_any <<= foo5;
88 ::perform_invocation<Test::NestedRecursiveStruct5> (hello, the_any);
91 /**
92 * @struct Caller
94 * @brief Test method invocation functor.
96 * Test method invocation functor.
98 template <typename T>
99 struct Caller : public std::function<void(T)>
101 /// Constructor.
102 Caller (CORBA::ORB_ptr o, Test::Hello_ptr h)
103 : orb (CORBA::ORB::_duplicate (o))
104 , hello (Test::Hello::_duplicate (h))
105 , success (true)
109 /// Function call operator overload.
110 void operator() (T f)
114 f (orb.in (),
115 hello.in ());
117 catch (const CORBA::Exception& ex)
119 ex._tao_print_exception ("Exception thrown:");
121 success = false;
125 CORBA::ORB_var orb;
126 Test::Hello_var hello;
127 bool success;
131 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
135 CORBA::ORB_var orb =
136 CORBA::ORB_init (argc, argv);
138 if (parse_args (argc, argv) != 0)
139 return 1;
141 CORBA::Object_var tmp =
142 orb->string_to_object(ior);
144 Test::Hello_var hello =
145 Test::Hello::_narrow(tmp.in ());
147 if (CORBA::is_nil (hello.in ()))
149 ACE_ERROR_RETURN ((LM_DEBUG,
150 "Nil Test::Hello reference <%s>\n",
151 ior),
155 typedef void (*test_func) (CORBA::ORB_ptr,
156 Test::Hello_ptr);
158 static test_func const tests[] =
160 nested_recursive_struct_test
163 static size_t const test_count = sizeof (tests) / sizeof (test_func);
165 // Have some fun with the STL. :-)
166 Caller<test_func> c =
167 std::for_each (tests,
168 tests + test_count,
169 Caller<test_func> (orb.in (),
170 hello.in ()));
172 if (!c.success)
173 throw Test::Recursive_Type_In_Any_Test_Failed ();
175 hello->shutdown ();
177 orb->destroy ();
179 catch (const CORBA::Exception& ex)
181 ex._tao_print_exception ("Exception caught:");
182 return 1;
185 return 0;