Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / tests / OBV / Collocated / Forward / Client_Task.cpp
blobef1e47b367229d9f8c4124ef2c5b724a1ee9e91a
2 #include "Client_Task.h"
4 Client_Task::Client_Task (const ACE_TCHAR *ior,
5 CORBA::ORB_ptr corb,
6 ACE_Thread_Manager *thr_mgr)
7 : ACE_Task_Base (thr_mgr)
8 , input_ (ior)
9 , corb_ (CORBA::ORB::_duplicate (corb))
14 int
15 Client_Task::svc ()
17 int result = 0;
18 try
20 // All factories are kindly provided by
21 // compiler so we just to put everything in a right order.
23 // Create and register factory for BaseNode.
24 BaseNode_init *bn_factory = 0;
25 ACE_NEW_RETURN (bn_factory,
26 BaseNode_init,
27 1);
29 this->corb_->register_value_factory (bn_factory->tao_repository_id (),
30 bn_factory);
31 bn_factory->_remove_ref (); // release ownership
33 // Create and register factory for TreeController.
34 TreeController_init *tc_factory = 0;
35 ACE_NEW_RETURN (tc_factory,
36 TreeController_init,
37 1);
39 this->corb_->register_value_factory (tc_factory->tao_repository_id (),
40 tc_factory);
41 tc_factory->_remove_ref (); // release ownership
43 // Create and register factory for StringNode.
44 StringNode_init *sn_factory = 0;
45 ACE_NEW_RETURN (sn_factory,
46 StringNode_init,
47 1);
49 this->corb_->register_value_factory (sn_factory->tao_repository_id (),
50 sn_factory);
51 sn_factory->_remove_ref (); // release ownership
53 //Well, done with factories.
55 // Obtain reference to the object.
56 CORBA::Object_var tmp =
57 this->corb_->string_to_object(this->input_);
59 Test_var test = Test::_narrow(tmp.in ());
61 if (CORBA::is_nil (test.in ()))
63 ACE_ERROR_RETURN ((LM_DEBUG,
64 "Nil Test reference <%s>\n",
65 this->input_),
66 1);
69 // Now build simple graph (tree in our case).
71 TreeController_var tc;
72 ACE_NEW_RETURN (tc.inout (),
73 OBV_TreeController,
74 1);
76 // Create the root node.
78 StringNode_var sn;
79 ACE_NEW_RETURN (sn.inout (),
80 OBV_StringNode,
81 1);
82 sn->name ((const char*)("RootNode"));
83 tc->root (sn);
85 // Create the left leaf.
87 StringNode_var dummy;
88 ACE_NEW_RETURN (dummy.inout (),
89 OBV_StringNode,
90 1);
91 dummy->name ((const char*)("LeftNode"));
92 sn->left (dummy);
95 // Create the right leaf.
97 StringNode_var dummy;
98 ACE_NEW_RETURN (dummy.inout (),
99 OBV_StringNode,
101 dummy->name ((const char*)("RightNode"));
102 sn->right (dummy);
104 // dummy->right (sn); // ;-)
108 // Make copy
110 TreeController_var tc_copy;
111 ACE_NEW_RETURN (tc_copy.inout (),
112 OBV_TreeController,
115 // Create the root node.
117 StringNode_var sn;
118 ACE_NEW_RETURN (sn.inout (),
119 OBV_StringNode,
121 sn->name ((const char*)("RootNode"));
122 tc_copy->root (sn);
124 // Create the left leaf.
126 StringNode_var dummy;
127 ACE_NEW_RETURN (dummy.inout (),
128 OBV_StringNode,
130 dummy->name ((const char*)("LeftNode"));
131 sn->left (dummy);
134 // Create the right leaf.
136 StringNode_var dummy;
137 ACE_NEW_RETURN (dummy.inout (),
138 OBV_StringNode,
140 dummy->name ((const char*)("RightNode"));
141 sn->right (dummy);
143 // dummy->right (sn); // ;-)
147 if (!is_equal_tree (tc.in (), tc_copy.in ()))
149 ACE_ERROR ((LM_ERROR,
150 "ERROR: tc != tc_copy\n"));
151 result = 1;
154 TreeController_var tc_result =
155 test->reflect (tc.in ());
157 // The following two ifs will fail until bug 1390 is fixed.
158 if (is_equal_tree (tc.in (), tc_result.in ()))
160 ACE_ERROR ((LM_ERROR,
161 "ERROR: tc == tc_result\n"));
162 result = 1;
164 if (result == 0 && !is_equal_tree (tc.in (), tc_copy.in ()))
166 ACE_ERROR ((LM_ERROR,
167 "ERROR: tc != tc_copy\n"));
168 result = 1;
171 test->shutdown ();
173 ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - test finished\n"));
175 catch (const CORBA::Exception& ex)
177 ex._tao_print_exception ("Exception caught:");
178 return 1;
181 return result;
185 Client_Task::is_equal_tree (TreeController * tree1, TreeController * tree2)
187 return is_equal_node (tree1->root (), tree2->root ());
192 Client_Task::is_equal_node (BaseNode * node1, BaseNode * node2)
194 int ret_val = 0;
195 if (!(node1 || node2))
196 return 1;
197 if (node1 && node2)
199 StringNode * sn1 = StringNode::_downcast (node1);
200 StringNode * sn2 = StringNode::_downcast (node2);
201 if (sn1 && sn2)
202 if (!ACE_OS::strcmp (sn1->name (), sn2->name ()))
203 ret_val = 1;
204 if (!(sn1 || sn2))
205 ret_val = 1;
206 return (ret_val &&
207 is_equal_node (node1->left (), node2->left ()) &&
208 is_equal_node (node1->right (), node2->right ()));
211 return 0;
214 void
215 Client_Task::dump_node (BaseNode *bn, int indent)
217 if (bn == 0) return;
219 // This is ugly I know
220 int i = indent;
221 for (; i != 0; i--) ACE_DEBUG ((LM_DEBUG, " "));
223 StringNode *sn = StringNode::_downcast (bn);
224 if (sn != 0)
226 ACE_DEBUG ((LM_DEBUG, "%x <StringNode> %s\n",
228 sn->name ()));
230 else
232 ACE_DEBUG ((LM_DEBUG,
233 "%x <BaseNode>\n",
234 bn));
237 dump_node (bn->left (), indent + 1);
238 dump_node (bn->right (), indent + 1);
241 void
242 Client_Task::dump_tree (TreeController *tc)
244 ACE_DEBUG ((LM_DEBUG,
245 "(%P|%t) start tree dump <%x>\n",
246 tc));
248 dump_node (tc->root (), 1);
250 ACE_DEBUG ((LM_DEBUG,
251 "(%P|%t) end tree dump <%x>\n",
252 tc));