summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/Bug_1630_Regression/testclient.cpp
blob: c7443b34692f5c29eb4c151739007c4831f71053 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
//
// $Id$
//

#include "tao/IFR_Client/IFR_BasicC.h"
#include "tao/IFR_Client/IFR_Client_Adapter_Impl.h"
#include "tao/AnyTypeCode/NVList.h"
#include "tao/ORB.h"
#include "ace/OS_NS_string.h"

int main (int argc, char* argv[])
{
  try
   {
      int failed = 0;

      ACE_DEBUG((LM_DEBUG, "Start of Client\n"));
      // Initialise ORB.
      //
      CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

      // Find the Interface Repository.
      //
      ACE_DEBUG((LM_DEBUG, ". Find IFR\n"));
      CORBA::Object_var ifr_obj =
        orb->resolve_initial_references( "InterfaceRepository");

      ACE_DEBUG((LM_DEBUG, ". Narrow IFR\n"));
      CORBA::Repository_var ifr = CORBA::Repository::_narrow( ifr_obj.in());

      if( CORBA::is_nil( ifr.in() ) )
      {
         ACE_DEBUG((LM_DEBUG, "Nil IFR reference\n"));
         return 1;
      }

      ACE_DEBUG((LM_DEBUG, ". Construct interface\n"));
      // Add an interface to the repository.
      //
      CORBA::InterfaceDefSeq baseInterfaces(1) ;
      baseInterfaces.length(0) ;
      CORBA::InterfaceDef_var interface =
         ifr->create_interface( "IDL:interface865:1.0",
                                "interface865",
                                "1.0",
                                baseInterfaces) ;

      // Add an operation to the interface.
      // First get some useful things.
      //
      ACE_DEBUG((LM_DEBUG, ". Get primitive (void)\n"));
      CORBA::PrimitiveDef_var voidPrimitive =
         ifr->get_primitive( CORBA::pk_void) ;
      ACE_DEBUG((LM_DEBUG, ". Get primitive (char)\n"));
      CORBA::PrimitiveDef_var charPrimitive =
         ifr->get_primitive( CORBA::pk_char) ;
      ACE_DEBUG((LM_DEBUG, ". Get primitive (long)\n"));
      CORBA::PrimitiveDef_var longPrimitive =
         ifr->get_primitive( CORBA::pk_long) ;
      ACE_DEBUG((LM_DEBUG, ". Get primitive (short)\n"));
      CORBA::PrimitiveDef_var shortPrimitive =
         ifr->get_primitive( CORBA::pk_short) ;

      ACE_DEBUG((LM_DEBUG, ". create 3 parameters\n"));
      // The operation has three parameters...
      //
      CORBA::ULong numParams = 3 ;
      CORBA::ParDescriptionSeq parameters( numParams ) ;
      parameters.length( numParams ) ;

      // ... which are: in char p1...
      //
      parameters[0].name = CORBA::string_dup("p1") ;
      parameters[0].type_def =
         CORBA::PrimitiveDef::_duplicate( charPrimitive.in() ) ;
      parameters[0].type = charPrimitive->type() ;
      parameters[0].mode = CORBA::PARAM_IN ;

      // ...out long p2...
      //
      parameters[1].name = CORBA::string_dup("p2") ;
      parameters[1].type_def =
         CORBA::PrimitiveDef::_duplicate( longPrimitive.in() ) ;
      parameters[1].type = longPrimitive->type() ;
      parameters[1].mode = CORBA::PARAM_OUT ;

      // ...and inout short p3
      //
      parameters[2].name = CORBA::string_dup("p3") ;
      parameters[2].type_def =
         CORBA::PrimitiveDef::_duplicate( shortPrimitive.in() ) ;
      parameters[2].type = shortPrimitive->type() ;
      parameters[2].mode = CORBA::PARAM_INOUT ;

      // ...and no exceptions...
      //
      ACE_DEBUG((LM_DEBUG, ". create 0 excepts\n"));
      CORBA::ExceptionDefSeq exceptions( 1 ) ;
      exceptions.length( 0 ) ;

      // ...and no context ids
      //
      ACE_DEBUG((LM_DEBUG, ". create 0 cids\n"));
      CORBA::ContextIdSeq contextIds( 1 ) ;
      contextIds.length( 0 ) ;

      // Create the operation, called "f".
      //
      ACE_DEBUG((LM_DEBUG, ". create_operation\n"));
      CORBA::OperationDef_var operation =
         interface->create_operation( "IDL:interface865/f:1.0",
                                      "f",
                                      "1.0",
                                      voidPrimitive.in(),
                                      CORBA::OP_NORMAL,
                                      parameters,
                                      exceptions,
                                      contextIds) ;



      // Create operation list.
      //
      CORBA::NVList_var opList ;

      ACE_DEBUG((LM_DEBUG, "About to call create_operation_list\n"));
      orb->create_operation_list(operation.in (),
		                 opList.out()) ;

      ACE_DEBUG((LM_DEBUG, "Call to create_operation_list succeeded\n"));
      CORBA::ULong count = opList->count() ;

      if( count != numParams )
      {
         ACE_DEBUG((LM_DEBUG, "Test failed - wrong number of elements n list\n")) ;
         failed = 1 ;
      }

      CORBA::NamedValue_ptr nv = opList->item( 0 ) ;
      if(ACE_OS::strcmp( nv->name(), "p1") != 0 )
      {
         ACE_DEBUG((LM_DEBUG, "Test failed: param 1 wrong name\n"));
         failed = 1 ;
      }

      CORBA::Boolean const eq_char =
        nv->value()->type()->equal (CORBA::_tc_char);

      if( !eq_char  )
      {
         ACE_DEBUG((LM_DEBUG, "Test failed: param 1 wrong type\n"));
         failed = 1 ;
      }
      if( nv->flags() != CORBA::ARG_IN )
      {
         ACE_DEBUG((LM_DEBUG, "Test failed: param 1 wrong mode\n"));
         failed = 1 ;
      }

      nv = opList->item( 1 ) ;
      if(ACE_OS::strcmp( nv->name(), "p2") != 0 )
      {
         ACE_DEBUG((LM_DEBUG, "Test failed: param 2 wrong name\n"));
         failed = 1 ;
      }

      CORBA::Boolean const eq_long =
        nv->value()->type()->equal (CORBA::_tc_long);

      if( !eq_long  )
      {
         ACE_DEBUG((LM_DEBUG, "Test failed: param 2 wrong type\n"));
         failed = 1 ;
      }
      if( nv->flags() != CORBA::ARG_OUT )
      {
         ACE_DEBUG((LM_DEBUG, "Test failed: param 2 wrong mode\n"));
         failed = 1 ;
      }

      nv = opList->item( 2 ) ;
      if(ACE_OS::strcmp( nv->name(), "p3") != 0 )
      {
         ACE_DEBUG((LM_DEBUG, "Test failed: param 3 wrong name\n"));
         failed = 1 ;
      }

      CORBA::Boolean const eq_short =
        nv->value()->type()->equal (CORBA::_tc_short);

      if( !eq_short  )
      {
         ACE_DEBUG((LM_DEBUG, "Test failed: param 3 wrong type\n"));
         failed = 1 ;
      }
      if( nv->flags() != CORBA::ARG_INOUT )
      {
         ACE_DEBUG((LM_DEBUG, "Test failed: param 3 wrong mode\n"));
         failed = 1 ;
      }

      // opList->free();
      //operation->destroy();

      // Finally destroy the interface.
      //
      interface->destroy() ;

      //orb->destroy();

      if( failed == 1 )
      {
         return 1 ;
      }
      ACE_DEBUG((LM_DEBUG, ". seems OK\n"));
   }
   catch (const CORBA::Exception& ex)
   {
      ex._tao_print_exception ("Exception - test failed:\n");
      return 1;
   }
   catch (...)
   {
     ACE_DEBUG((LM_DEBUG, "An unknown exception occured - test failed\n"));
     return 1;
   }


   return 0 ;
}