Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / InterfaceRepo / Persistence_Test / Ptest.cpp
blob6cb797b60e03b6286872c2d45265dc3437b44892
1 // -*- C++ -*-
2 #include "Ptest.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/OS_NS_string.h"
6 Ptest::Ptest ()
7 : debug_ (0),
8 query_ (0)
12 Ptest::~Ptest ()
16 int
17 Ptest::init (int argc, ACE_TCHAR *argv[])
19 try
21 this->orb_ = CORBA::ORB_init (argc, argv);
23 int retval = this->parse_args (argc, argv);
25 if (retval != 0)
26 return retval;
28 CORBA::Object_var object =
29 this->orb_->resolve_initial_references ("InterfaceRepository");
31 if (CORBA::is_nil (object.in ()))
33 ACE_ERROR_RETURN ((
34 LM_ERROR,
35 "Null objref from resolve_initial_references\n"
36 ), -1);
39 this->repo_ =
40 CORBA::Repository::_narrow (object.in ());
42 if (CORBA::is_nil (this->repo_.in ()))
44 ACE_ERROR_RETURN ((LM_ERROR,
45 "CORBA::Repository::_narrow failed\n"),
46 -1);
49 catch (const CORBA::Exception& ex)
51 ex._tao_print_exception ("Ptest::init");
52 return -1;
55 return 0;
58 int
59 Ptest::shutdown ()
61 try
63 this->repo_ = CORBA::Repository::_nil ();
65 this->orb_->destroy ();
67 this->orb_ = CORBA::ORB::_nil ();
69 catch (const CORBA::Exception& ex)
71 ex._tao_print_exception ("Ptest::init");
72 return -1;
74 return 0;
77 int
78 Ptest::run ()
80 try
82 if (this->query_ == 1)
84 this->query ();
86 else
88 this->populate ();
91 catch (const CORBA::Exception& ex)
93 ex._tao_print_exception ("Ptest::run");
94 return -1;
97 return 0;
101 Ptest::parse_args (int argc,
102 ACE_TCHAR *argv[])
104 ACE_Get_Opt opts (argc, argv, ACE_TEXT("dq"));
105 int c;
107 while ((c = opts ()) != -1)
108 switch (c)
110 case 'd': // debug flag
111 this->debug_ = 1;
112 break;
113 case 'q': // query toggle
114 this->query_ = 1;
115 break;
116 case '?':
117 default:
118 ACE_ERROR_RETURN ((LM_ERROR,
119 "usage: %s"
120 " [-d]"
121 " [-q]"
122 "\n",
123 argv [0]),
124 -1);
127 return 0;
130 void
131 Ptest::populate ()
133 if (this->debug_)
135 ACE_DEBUG ((
136 LM_DEBUG,
137 ACE_TEXT ("\n============== POPULATE ==============\n\n")
141 CORBA::StructMemberSeq members (2);
142 members.length (2);
143 members[0].name = CORBA::string_dup ("long_mem");
144 members[0].type_def = this->repo_->get_primitive (CORBA::pk_long);
145 members[0].type = members[0].type_def->type ();
147 members[1].name = CORBA::string_dup ("array_mem");
148 members[1].type_def = this->repo_->create_array (5,
149 members[0].type_def.in ());
150 members[1].type = members[1].type_def->type ();
153 CORBA::StructDef_var svar = this->repo_->create_struct ("IDL:my_struct:1.0",
154 "my_struct",
155 "1.0",
156 members);
158 CORBA::EnumMemberSeq def_members (2);
159 def_members.length (2);
161 def_members[0] = CORBA::string_dup ("ZERO");
162 def_members[1] = CORBA::string_dup ("ONE");
164 CORBA::EnumDef_var e_def_var = svar->create_enum ("IDL:my_def_enum:1.0",
165 "my_enum",
166 "1.0",
167 def_members);
171 Ptest::query ()
173 if (this->debug_)
175 ACE_DEBUG ((
176 LM_DEBUG,
177 ACE_TEXT ("\n============== QUERY ==============\n\n")
181 const char *members[] =
183 "long_mem",
184 "array_mem",
185 "my_enum"
188 CORBA::ContainedSeq_var contents =
189 this->repo_->contents (CORBA::dk_all,
192 CORBA::ULong length = contents->length ();
194 if (length != 1)
196 ACE_ERROR_RETURN ((LM_ERROR,
197 ACE_TEXT ("ERROR: Repository::contents::length: %d")
198 ACE_TEXT (" while it's expected to be 1\n"),
199 length),
200 -1);
203 CORBA::ULong i = 0;
205 CORBA::StructDef_var svar =
206 CORBA::StructDef::_narrow (contents[i]);
208 if (CORBA::is_nil (svar.in ()))
210 ACE_ERROR_RETURN ((LM_ERROR,
211 ACE_TEXT ("ERROR: Struct from repo is nil\n")),
212 -1);
215 CORBA::StructMemberSeq_var out_members =
216 svar->members ();
218 length = out_members->length ();
220 if (length != 3)
222 ACE_ERROR_RETURN ((LM_ERROR,
223 ACE_TEXT ("ERROR: StructDef::members::length: %d")
224 ACE_TEXT (" while it's expected to be 3\n"),
225 length),
226 -1);
229 for (i = 0; i < length; ++i)
231 if (this->debug_)
233 ACE_DEBUG ((LM_DEBUG,
234 ACE_TEXT ("StructDef::members[%d]::name: %C\n"),
236 out_members[i].name.in ()));
239 if (i == length - 1)
241 if (ACE_OS::strcmp (out_members[i].name, "my_enum") != 0)
243 ACE_ERROR_RETURN ((LM_ERROR,
244 ACE_TEXT ("ERROR: Incorrect struct member\n")),
245 -1);
248 else
250 if (ACE_OS::strcmp (out_members[i].name, members[i]) != 0)
252 ACE_ERROR_RETURN ((LM_ERROR,
253 ACE_TEXT ("ERROR: Incorrect struct member\n")),
254 -1);
259 #if defined (ACE_NDEBUG)
260 // ACE_ASSERT macro expands to nothing, so...
261 ACE_UNUSED_ARG (members);
262 #endif /* ACE_NDEBUG */
264 svar->destroy ();
266 return 0;