Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_1630_Regression / testclient.cpp
blob402016611d7c003d0a0749d0636c210e540b72ae
2 #include "tao/IFR_Client/IFR_BasicC.h"
3 #include "tao/IFR_Client/IFR_Client_Adapter_Impl.h"
4 #include "tao/AnyTypeCode/NVList.h"
5 #include "tao/ORB.h"
6 #include "ace/OS_NS_string.h"
8 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
10 try
12 int failed = 0;
14 ACE_DEBUG((LM_DEBUG, "Start of Client\n"));
15 // Initialise ORB.
17 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
19 // Find the Interface Repository.
21 ACE_DEBUG((LM_DEBUG, ". Find IFR\n"));
22 CORBA::Object_var ifr_obj =
23 orb->resolve_initial_references( "InterfaceRepository");
25 ACE_DEBUG((LM_DEBUG, ". Narrow IFR\n"));
26 CORBA::Repository_var ifr = CORBA::Repository::_narrow( ifr_obj.in());
28 if( CORBA::is_nil( ifr.in() ) )
30 ACE_DEBUG((LM_DEBUG, "Nil IFR reference\n"));
31 return 1;
34 ACE_DEBUG((LM_DEBUG, ". Construct interface\n"));
35 // Add an interface to the repository.
37 CORBA::InterfaceDefSeq baseInterfaces(1) ;
38 baseInterfaces.length(0) ;
39 CORBA::InterfaceDef_var intface =
40 ifr->create_interface( "IDL:interface865:1.0",
41 "interface865",
42 "1.0",
43 baseInterfaces) ;
45 // Add an operation to the interface.
46 // First get some useful things.
48 ACE_DEBUG((LM_DEBUG, ". Get primitive (void)\n"));
49 CORBA::PrimitiveDef_var voidPrimitive =
50 ifr->get_primitive( CORBA::pk_void) ;
51 ACE_DEBUG((LM_DEBUG, ". Get primitive (char)\n"));
52 CORBA::PrimitiveDef_var charPrimitive =
53 ifr->get_primitive( CORBA::pk_char) ;
54 ACE_DEBUG((LM_DEBUG, ". Get primitive (long)\n"));
55 CORBA::PrimitiveDef_var longPrimitive =
56 ifr->get_primitive( CORBA::pk_long) ;
57 ACE_DEBUG((LM_DEBUG, ". Get primitive (short)\n"));
58 CORBA::PrimitiveDef_var shortPrimitive =
59 ifr->get_primitive( CORBA::pk_short) ;
61 ACE_DEBUG((LM_DEBUG, ". create 3 parameters\n"));
62 // The operation has three parameters...
64 CORBA::ULong numParams = 3 ;
65 CORBA::ParDescriptionSeq parameters( numParams ) ;
66 parameters.length( numParams ) ;
68 // ... which are: in char p1...
70 parameters[0].name = CORBA::string_dup("p1") ;
71 parameters[0].type_def =
72 CORBA::PrimitiveDef::_duplicate( charPrimitive.in() ) ;
73 parameters[0].type = charPrimitive->type() ;
74 parameters[0].mode = CORBA::PARAM_IN ;
76 // ...out long p2...
78 parameters[1].name = CORBA::string_dup("p2") ;
79 parameters[1].type_def =
80 CORBA::PrimitiveDef::_duplicate( longPrimitive.in() ) ;
81 parameters[1].type = longPrimitive->type() ;
82 parameters[1].mode = CORBA::PARAM_OUT ;
84 // ...and inout short p3
86 parameters[2].name = CORBA::string_dup("p3") ;
87 parameters[2].type_def =
88 CORBA::PrimitiveDef::_duplicate( shortPrimitive.in() ) ;
89 parameters[2].type = shortPrimitive->type() ;
90 parameters[2].mode = CORBA::PARAM_INOUT ;
92 // ...and no exceptions...
94 ACE_DEBUG((LM_DEBUG, ". create 0 excepts\n"));
95 CORBA::ExceptionDefSeq exceptions( 1 ) ;
96 exceptions.length( 0 ) ;
98 // ...and no context ids
100 ACE_DEBUG((LM_DEBUG, ". create 0 cids\n"));
101 CORBA::ContextIdSeq contextIds( 1 ) ;
102 contextIds.length( 0 ) ;
104 // Create the operation, called "f".
106 ACE_DEBUG((LM_DEBUG, ". create_operation\n"));
107 CORBA::OperationDef_var operation =
108 intface->create_operation( "IDL:interface865/f:1.0",
109 "f",
110 "1.0",
111 voidPrimitive.in(),
112 CORBA::OP_NORMAL,
113 parameters,
114 exceptions,
115 contextIds) ;
119 // Create operation list.
121 CORBA::NVList_var opList ;
123 ACE_DEBUG((LM_DEBUG, "About to call create_operation_list\n"));
124 orb->create_operation_list(operation.in (),
125 opList.out()) ;
127 ACE_DEBUG((LM_DEBUG, "Call to create_operation_list succeeded\n"));
128 CORBA::ULong count = opList->count() ;
130 if( count != numParams )
132 ACE_DEBUG((LM_DEBUG, "Test failed - wrong number of elements n list\n")) ;
133 failed = 1 ;
136 CORBA::NamedValue_ptr nv = opList->item( 0 ) ;
137 if(ACE_OS::strcmp( nv->name(), "p1") != 0 )
139 ACE_DEBUG((LM_DEBUG, "Test failed: param 1 wrong name\n"));
140 failed = 1 ;
143 CORBA::Boolean const eq_char =
144 nv->value()->type()->equal (CORBA::_tc_char);
146 if( !eq_char )
148 ACE_DEBUG((LM_DEBUG, "Test failed: param 1 wrong type\n"));
149 failed = 1 ;
151 if( nv->flags() != CORBA::ARG_IN )
153 ACE_DEBUG((LM_DEBUG, "Test failed: param 1 wrong mode\n"));
154 failed = 1 ;
157 nv = opList->item( 1 ) ;
158 if(ACE_OS::strcmp( nv->name(), "p2") != 0 )
160 ACE_DEBUG((LM_DEBUG, "Test failed: param 2 wrong name\n"));
161 failed = 1 ;
164 CORBA::Boolean const eq_long =
165 nv->value()->type()->equal (CORBA::_tc_long);
167 if( !eq_long )
169 ACE_DEBUG((LM_DEBUG, "Test failed: param 2 wrong type\n"));
170 failed = 1 ;
172 if( nv->flags() != CORBA::ARG_OUT )
174 ACE_DEBUG((LM_DEBUG, "Test failed: param 2 wrong mode\n"));
175 failed = 1 ;
178 nv = opList->item( 2 ) ;
179 if(ACE_OS::strcmp( nv->name(), "p3") != 0 )
181 ACE_DEBUG((LM_DEBUG, "Test failed: param 3 wrong name\n"));
182 failed = 1 ;
185 CORBA::Boolean const eq_short =
186 nv->value()->type()->equal (CORBA::_tc_short);
188 if( !eq_short )
190 ACE_DEBUG((LM_DEBUG, "Test failed: param 3 wrong type\n"));
191 failed = 1 ;
193 if( nv->flags() != CORBA::ARG_INOUT )
195 ACE_DEBUG((LM_DEBUG, "Test failed: param 3 wrong mode\n"));
196 failed = 1 ;
199 // opList->free();
200 //operation->destroy();
202 // Finally destroy the interface.
204 intface->destroy() ;
206 //orb->destroy();
208 if( failed == 1 )
210 return 1 ;
212 ACE_DEBUG((LM_DEBUG, ". seems OK\n"));
214 catch (const CORBA::Exception& ex)
216 ex._tao_print_exception ("Exception - test failed:\n");
217 return 1;
219 catch (...)
221 ACE_DEBUG((LM_DEBUG, "An unknown exception occurred - test failed\n"));
222 return 1;
226 return 0 ;