Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / OBV / Any / client.cpp
blob4aa7180c268d57b07d6f492e6c0f68528a5025cb
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
37 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - test started.\n"));
39 CORBA::ORB_var orb =
40 CORBA::ORB_init (argc, argv);
42 if (parse_args (argc, argv) != 0)
43 return 1;
45 // Create and register factories.
47 OBV_AnyTest::VA_init *va_factory = 0;
48 ACE_NEW_RETURN (va_factory,
49 OBV_AnyTest::VA_init,
50 1); // supplied by mapping
52 orb->register_value_factory (va_factory->tao_repository_id (),
53 va_factory);
54 va_factory->_remove_ref (); // release ownership
57 OBV_AnyTest::VB_init *vb_factory = 0;
58 ACE_NEW_RETURN (vb_factory,
59 OBV_AnyTest::VB_init,
60 1); // supplied by mapping
62 orb->register_value_factory (vb_factory->tao_repository_id (),
63 vb_factory);
64 vb_factory->_remove_ref (); // release ownership
66 // Do local test
68 OBV_AnyTest::VA_var va1, va2;
69 ACE_NEW_RETURN (va1.inout (), OBV_OBV_AnyTest::VA, 1);
70 ACE_NEW_RETURN (va2.inout (), OBV_OBV_AnyTest::VA, 1);
72 const CORBA::ULong magic = 3145;
74 va1->id (magic);
75 va2->id (magic);
77 CORBA::Any a1, a2;
79 // Test both copying and non-copying version of operator<<=
80 a1 <<= va1.in ();
82 OBV_AnyTest::VA *pva = va2._retn();
83 a2 <<= &pva;
85 OBV_AnyTest::VA* dst = 0;
87 if (!(a1 >>= dst) || dst->id () != magic)
89 ACE_ERROR_RETURN ((LM_DEBUG,
90 "(%P|%t) client - test failed.\n"),
91 1);
94 if (!(a2 >>= dst) || dst->id () != magic)
96 ACE_ERROR_RETURN ((LM_DEBUG,
97 "(%P|%t) client - test failed.\n"),
98 1);
102 // It should be possible to extract to a base type
103 OBV_AnyTest::VB_var vb1;
104 ACE_NEW_RETURN (vb1.inout (), OBV_OBV_AnyTest::VB, 1);
105 vb1->id (magic);
107 a1 <<= vb1.in ();
108 CORBA::ValueBase_var target;
109 if (!(a1 >>= CORBA::Any::to_value(target.out())))
111 ACE_ERROR_RETURN ((LM_DEBUG,
112 "(%P|%t) client - base extraction test failed.\n"),
115 dst = OBV_AnyTest::VA::_downcast(target.in());
116 if (dst == 0 || dst->id() != magic)
118 ACE_ERROR_RETURN ((LM_DEBUG,
119 "(%P|%t) client - base extraction test failed.\n"),
124 // Now do remote test
126 CORBA::Object_var tmp =
127 orb->string_to_object(ior);
129 OBV_AnyTest::Test_var test =
130 OBV_AnyTest::Test::_narrow(tmp.in ());
132 if (CORBA::is_nil (test.in ()))
134 ACE_ERROR_RETURN ((LM_DEBUG,
135 "Nil OBV_AnyTest::Test reference <%s>\n",
136 ior),
141 // STEP 1.
142 CORBA::Any_var result = test->get_something (
145 if (!(result.inout () >>= dst) || dst->id () != magic)
147 ACE_ERROR_RETURN ((LM_DEBUG,
148 "(%P|%t) client - test 1 failed.\n"),
152 // STEP 2.
153 OBV_AnyTest::VB* dst_vb = 0;
154 result = test->get_something (
157 if (!(result.inout () >>= dst_vb) || dst_vb->id () != magic)
159 ACE_ERROR_RETURN ((LM_DEBUG,
160 "(%P|%t) client - test 2 failed.\n"),
164 // STEP 3. A sanity check demonstrating base-type pointer to
165 // derived type allowed.
166 OBV_AnyTest::VA_var dst_va = test->get_vb();
167 if (dst_va->id () != magic)
169 ACE_ERROR_RETURN ((LM_DEBUG,
170 "(%P|%t) client - test 3 failed.\n"),
174 #if !defined (TAO_HAS_OPTIMIZED_VALUETYPE_MARSHALING)
175 // @@ There's still a problem here with the optimized valuetype
176 // marshaling and passing values through anys. The problem is
177 // that while the Any in fact contains all of the required type
178 // information, there is no way to share that with the
179 // ValueBase::_tao_unmarshal_pre() which needs the type info in
180 // order to select the appropriate value factory.
182 // STEP 4. get a VB, but extract to a VA*.
183 result = test->get_something (
186 if (!(result.inout () >>= CORBA::Any::to_value(target.out())))
188 ACE_ERROR_RETURN ((LM_DEBUG,
189 "(%P|%t) client - test 4 extraction failed.\n"),
192 dst_va = OBV_AnyTest::VA::_downcast(target._retn());
193 if (dst_va == 0 || dst_va->id() != magic)
195 ACE_ERROR_RETURN ((LM_DEBUG,
196 "(%P|%t) client - test 4 failed.\n"),
199 #endif /* TAO_HAS_OPTIMIZED_VALUETYPE_MARSHALING */
201 test->shutdown ();
203 orb->destroy ();
205 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - test finished.\n"));
207 catch (const CORBA::Exception& ex)
209 ex._tao_print_exception ("Exception caught in client:");
210 return 1;
213 return 0;