More tests update
[ACE_TAO.git] / TAO / tests / OBV / Any / client.cpp
blob4727efe5d5befd3573fde416cd4b94111d35f5e1
1 #include "AnyC.h"
2 #include "ace/Get_Opt.h"
4 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
6 int
7 parse_args (int argc, ACE_TCHAR *argv[])
9 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
10 int c;
12 while ((c = get_opts ()) != -1)
13 switch (c)
15 case 'k':
16 ior = get_opts.optarg;
17 break;
19 case '?':
20 default:
21 ACE_ERROR_RETURN ((LM_ERROR,
22 "usage: %s "
23 "-k <ior> "
24 "\n",
25 argv [0]),
26 -1);
28 // Indicates successful parsing of the command line
29 return 0;
32 int
33 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
35 try
38 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - test started.\n"));
40 CORBA::ORB_var orb =
41 CORBA::ORB_init (argc, argv);
43 if (parse_args (argc, argv) != 0)
44 return 1;
46 // Create and register factories.
48 OBV_AnyTest::VA_init *va_factory = 0;
49 ACE_NEW_RETURN (va_factory,
50 OBV_AnyTest::VA_init,
51 1); // supplied by mapping
53 orb->register_value_factory (va_factory->tao_repository_id (),
54 va_factory);
55 va_factory->_remove_ref (); // release ownership
58 OBV_AnyTest::VB_init *vb_factory = 0;
59 ACE_NEW_RETURN (vb_factory,
60 OBV_AnyTest::VB_init,
61 1); // supplied by mapping
63 orb->register_value_factory (vb_factory->tao_repository_id (),
64 vb_factory);
65 vb_factory->_remove_ref (); // release ownership
67 // Do local test
69 OBV_AnyTest::VA_var va1, va2;
70 ACE_NEW_RETURN (va1.inout (), OBV_OBV_AnyTest::VA, 1);
71 ACE_NEW_RETURN (va2.inout (), OBV_OBV_AnyTest::VA, 1);
73 const CORBA::ULong magic = 3145;
75 va1->id (magic);
76 va2->id (magic);
78 CORBA::Any a1, a2;
80 // Test both copying and non-copying version of operator<<=
81 a1 <<= va1.in ();
83 OBV_AnyTest::VA *pva = va2._retn();
84 a2 <<= &pva;
86 OBV_AnyTest::VA* dst = 0;
88 if (!(a1 >>= dst) || dst->id () != magic)
90 ACE_ERROR_RETURN ((LM_DEBUG,
91 "(%P|%t) client - test failed.\n"),
92 1);
95 if (!(a2 >>= dst) || dst->id () != magic)
97 ACE_ERROR_RETURN ((LM_DEBUG,
98 "(%P|%t) client - test failed.\n"),
99 1);
103 // It should be possible to extract to a base type
104 OBV_AnyTest::VB_var vb1;
105 ACE_NEW_RETURN (vb1.inout (), OBV_OBV_AnyTest::VB, 1);
106 vb1->id (magic);
108 a1 <<= vb1.in ();
109 CORBA::ValueBase_var target;
110 if (!(a1 >>= CORBA::Any::to_value(target.out())))
112 ACE_ERROR_RETURN ((LM_DEBUG,
113 "(%P|%t) client - base extraction test failed.\n"),
116 dst = OBV_AnyTest::VA::_downcast(target.in());
117 if (dst == 0 || dst->id() != magic)
119 ACE_ERROR_RETURN ((LM_DEBUG,
120 "(%P|%t) client - base extraction test failed.\n"),
125 // Now do remote test
127 CORBA::Object_var tmp =
128 orb->string_to_object(ior);
130 OBV_AnyTest::Test_var test =
131 OBV_AnyTest::Test::_narrow(tmp.in ());
133 if (CORBA::is_nil (test.in ()))
135 ACE_ERROR_RETURN ((LM_DEBUG,
136 "Nil OBV_AnyTest::Test reference <%s>\n",
137 ior),
142 // STEP 1.
143 CORBA::Any_var result = test->get_something (
146 if (!(result.inout () >>= dst) || dst->id () != magic)
148 ACE_ERROR_RETURN ((LM_DEBUG,
149 "(%P|%t) client - test 1 failed.\n"),
153 // STEP 2.
154 OBV_AnyTest::VB* dst_vb = 0;
155 result = test->get_something (
158 if (!(result.inout () >>= dst_vb) || dst_vb->id () != magic)
160 ACE_ERROR_RETURN ((LM_DEBUG,
161 "(%P|%t) client - test 2 failed.\n"),
165 // STEP 3. A sanity check demonstrating base-type pointer to
166 // derived type allowed.
167 OBV_AnyTest::VA_var dst_va = test->get_vb();
168 if (dst_va->id () != magic)
170 ACE_ERROR_RETURN ((LM_DEBUG,
171 "(%P|%t) client - test 3 failed.\n"),
175 #if !defined (TAO_HAS_OPTIMIZED_VALUETYPE_MARSHALING)
176 // @@ There's still a problem here with the optimized valuetype
177 // marshaling and passing values through anys. The problem is
178 // that while the Any in fact contains all of the required type
179 // information, there is no way to share that with the
180 // ValueBase::_tao_unmarshal_pre() which needs the type info in
181 // order to select the appropriate value factory.
183 // STEP 4. get a VB, but extract to a VA*.
184 result = test->get_something (
187 if (!(result.inout () >>= CORBA::Any::to_value(target.out())))
189 ACE_ERROR_RETURN ((LM_DEBUG,
190 "(%P|%t) client - test 4 extraction failed.\n"),
193 dst_va = OBV_AnyTest::VA::_downcast(target._retn());
194 if (dst_va == 0 || dst_va->id() != magic)
196 ACE_ERROR_RETURN ((LM_DEBUG,
197 "(%P|%t) client - test 4 failed.\n"),
200 #endif /* TAO_HAS_OPTIMIZED_VALUETYPE_MARSHALING */
202 test->shutdown ();
204 orb->destroy ();
206 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - test finished.\n"));
208 catch (const CORBA::Exception& ex)
210 ex._tao_print_exception ("Exception caught in client:");
211 return 1;
214 return 0;