Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Multiple / Collocation_Tester.cpp
bloba28e61db52bbed06986744b12d28218ae79193a7
1 #include "Collocation_Tester.h"
2 #include "ace/OS_NS_string.h"
4 const char *Quote::top = "Ciao";
5 const char *Quote::left = "Hola";
6 const char *Quote::right = "Hello";
7 const char *Quote::bottom = "Previet";
9 Collocation_Tester::Collocation_Tester (CORBA::Object_ptr object)
11 this->object_ = CORBA::Object::_duplicate (object);
14 Collocation_Tester::~Collocation_Tester ()
16 // No-Op.
19 int
20 Collocation_Tester::match_answer (const char *actual_answer,
21 const char *right_answer,
22 const char *method_name)
24 if (ACE_OS::strcmp (actual_answer, right_answer))
26 ACE_ERROR ((LM_DEBUG,
27 ACE_TEXT ("Call to <%C> returned the wrong value!\n"), method_name));
28 return 1;
30 else
32 ACE_DEBUG ((LM_DEBUG,
33 ACE_TEXT ("Call to <%C> returned with success: %C\n"), method_name, actual_answer));
34 return 0;
38 int
39 Collocation_Tester::test_top ()
41 ACE_DEBUG ((LM_DEBUG,
42 ACE_TEXT("\n------------------------<TOP>-------------------------------\n")));
43 int failure = 0;
44 int call_num = 1;
45 Multiple::Top_var top =
46 Multiple::Top::_narrow (this->object_.in ());
48 if (CORBA::is_nil (top.in ()))
50 ACE_ERROR ((LM_DEBUG,
51 ACE_TEXT ("Unable to Narrow to Multiple::Top\n")));
52 return 1;
55 ACE_DEBUG ((LM_DEBUG,
56 ACE_TEXT ("\n\nCalling all method supported by the Interface Top\n\n")));
58 CORBA::String_var msg = top->top_quote ();
60 failure += this->match_answer (Quote::top, msg.in (), "top_quote");
62 if (failure)
63 ACE_ERROR ((LM_DEBUG,
64 ACE_TEXT ("The test had %d/%d Failure\n"), failure, call_num));
66 ACE_DEBUG ((LM_DEBUG,
67 ACE_TEXT("\n------------------------<TOP>-------------------------------\n")));
69 return failure;
72 int
73 Collocation_Tester::test_right ()
75 ACE_DEBUG ((LM_DEBUG,
76 ACE_TEXT("\n------------------------<RIGHT>-------------------------------\n")));
77 int failure = 0;
78 int call_num = 2;
79 Multiple::Right_var right =
80 Multiple::Right::_narrow (this->object_.in ());
82 if (CORBA::is_nil (right.in ()))
84 ACE_ERROR ((LM_DEBUG,
85 ACE_TEXT ("Unable to Narrow to Multiple::Right\n")));
86 return 1;
89 ACE_DEBUG ((LM_DEBUG,
90 ACE_TEXT ("\n\nCalling all method supported by the Interface Right\n\n")));
92 CORBA::String_var msg = right->top_quote ();
94 failure += this->match_answer (Quote::top, msg.in (), "top_quote");
96 msg = right->right_quote ();
98 failure += this->match_answer (Quote::right, msg.in (), "right_quote");
100 if (failure)
101 ACE_ERROR ((LM_DEBUG,
102 ACE_TEXT ("The test had %d/%d Failure"), failure, call_num));
104 ACE_DEBUG ((LM_DEBUG,
105 ACE_TEXT("\n------------------------<RIGHT>-------------------------------\n")));
107 return failure;
112 Collocation_Tester::test_left ()
114 ACE_DEBUG ((LM_DEBUG,
115 ACE_TEXT("\n------------------------<LEFT>-------------------------------\n")));
116 int failure = 0;
117 int call_num = 2;
119 Multiple::Left_var left =
120 Multiple::Left::_narrow (this->object_.in ());
122 if (CORBA::is_nil (left.in ()))
124 ACE_ERROR ((LM_DEBUG,
125 ACE_TEXT ("Unable to Narrow to Multiple::Right\n")));
126 return 1;
129 ACE_DEBUG ((LM_DEBUG,
130 ACE_TEXT ("\n\nCalling all method supported by the Interface Left\n\n")));
132 CORBA::String_var msg = left->top_quote ();
134 failure += this->match_answer (Quote::top, msg.in (), "top_quote");
136 msg = left->left_quote ();
138 failure += this->match_answer (Quote::left, msg.in (), "left_quote");
140 if (failure)
141 ACE_ERROR ((LM_DEBUG,
142 ACE_TEXT ("The test had %d/%d Failure"), failure, call_num));
144 ACE_DEBUG ((LM_DEBUG,
145 ACE_TEXT("\n------------------------<LEFT>-------------------------------\n")));
147 return failure;
152 Collocation_Tester::test_bottom ()
154 ACE_DEBUG ((LM_DEBUG,
155 ACE_TEXT("\n-----------------------<BOTTOM>-------------------------------\n")));
156 int failure = 0;
157 int call_num = 4;
159 Multiple::Bottom_var bottom =
160 Multiple::Bottom::_narrow (this->object_.in ());
162 if (CORBA::is_nil (bottom.in ()))
164 ACE_ERROR ((LM_DEBUG,
165 ACE_TEXT ("Unable to Narrow to Multiple::Right\n")));
166 return 1;
169 ACE_DEBUG ((LM_DEBUG,
170 ACE_TEXT ("\n\nCalling all method supported by the Interface Bottom\n\n")));
172 CORBA::String_var msg = bottom->top_quote ();
174 failure += this->match_answer (Quote::top, msg.in (), "top_quote");
176 msg = bottom->left_quote ();
178 failure += this->match_answer (Quote::left, msg.in (), "left_quote");
180 msg = bottom->right_quote ();
182 failure += this->match_answer (Quote::right, msg.in (), "right_quote");
184 msg = bottom->bottom_quote ();
186 failure += this->match_answer (Quote::bottom, msg.in (), "bottom_quote");
188 if (failure)
189 ACE_ERROR ((LM_DEBUG,
190 ACE_TEXT ("The test had %d/%d Failure"), failure, call_num));
192 ACE_DEBUG ((LM_DEBUG,
193 ACE_TEXT("\n-----------------------<BOTTOM>-------------------------------\n")));
195 return failure;
198 void
199 Collocation_Tester::shutdown ()
201 Multiple::Top_var top =
202 Multiple::Top::_narrow (this->object_.in ());
204 if (CORBA::is_nil (top.in ()))
206 ACE_ERROR ((LM_DEBUG,
207 ACE_TEXT ("Unable to Narrow to Multiple::Top\n")));
208 return;
211 ACE_DEBUG ((LM_DEBUG,
212 ACE_TEXT ("\n\nCalling ShutDown on Top.\n\n")));
214 top->shutdown ();
217 void
218 Collocation_Tester::run ()
220 int failure_num = this->test_top ();
222 failure_num += this->test_left ();
224 failure_num += this->test_right ();
226 failure_num += this->test_bottom ();
228 if (failure_num)
229 ACE_ERROR ((LM_DEBUG,
230 ACE_TEXT ("\n\nThe Test failed in %d cases."), failure_num));
231 else
232 ACE_DEBUG ((LM_DEBUG,
233 ACE_TEXT ("\n\nThe Test Completed Successfully. Congratulations! ")));
235 this->shutdown ();