Get rid of ACE_Auto_Array_Ptr
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_2285_Regression / client2.cpp
blob0be4100e289a4fe178f96a01bef60eea2bd4aef7
1 #include "TestC.h"
2 #include "ace/Get_Opt.h"
3 #include "tao/IORManipulation/IORManip_Loader.h"
4 // Ensure that the PI library is linked in when building statically
5 #include "tao/PI/PI.h"
6 #include "orbsvcs/FaultTolerance/FT_ClientService_Activate.h"
7 #include "orbsvcs/FaultTolerance/FT_IOGR_Property.h"
8 #include "ace/Auto_Ptr.h"
11 //const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
12 TAO_IOP::TAO_IOR_Manipulation_var iorm = 0;
13 CORBA::ULong number_of_servers = 0;
15 int
16 parse_args (int argc, ACE_TCHAR *argv[])
18 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:n:"));
19 int c;
21 while ((c = get_opts ()) != -1)
22 switch (c)
24 case 'k':
25 break;
26 case 'n':
27 number_of_servers = ACE_OS::atoi (get_opts.opt_arg ());
28 break;
29 case '?':
30 default:
31 ACE_ERROR_RETURN ((LM_ERROR,
32 "usage: %s "
33 "-k <ior> "
34 "\n",
35 argv [0]),
36 -1);
38 // Indicates successful parsing of the command line
39 return 0;
42 CORBA::Object_ptr
43 make_iogr (const char* domain_id, CORBA::ULongLong group_id, CORBA::ULong group_version, Test::Hello_var *refs)
45 FT::TagFTGroupTaggedComponent ft_tag_component;
46 // Create the list
47 TAO_IOP::TAO_IOR_Manipulation::IORList iors (number_of_servers);
48 iors.length(number_of_servers);
49 for (CORBA::ULong i = 0; i < number_of_servers; ++i)
51 iors [i] = CORBA::Object::_duplicate (refs[i].in ());
54 CORBA::Object_var new_ref =
55 iorm->merge_iors (iors);
57 // Property values
59 // Major and Minor revision numbers
60 ft_tag_component.component_version.major = (CORBA::Octet) 1;
61 ft_tag_component.component_version.minor = (CORBA::Octet) 0;
63 // Domain id
64 //const char *id = "iogr_testing";
65 ft_tag_component.group_domain_id = domain_id;
67 // Object group id
68 ft_tag_component.object_group_id = group_id;
70 // Version
71 ft_tag_component.object_group_ref_version = group_version;
73 // Construct the IOGR Property class
74 TAO_FT_IOGR_Property iogr_prop (ft_tag_component);
76 // Set the property
77 CORBA::Boolean retval = iorm->set_property (&iogr_prop,
78 new_ref.in ());
80 // Set the primary
81 // See we are setting the second ior as the primary
82 if (retval != 0)
84 retval = iorm->set_primary (&iogr_prop,
85 refs[0].in (),
86 new_ref.in ());
89 return new_ref._retn ();
92 int
93 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
95 CORBA::Boolean result = 0;
96 try
98 CORBA::ORB_var orb =
99 CORBA::ORB_init (argc, argv);
101 if (parse_args (argc, argv) != 0)
102 return 1;
104 // Get a ref to the IORManipulation object
105 CORBA::Object_var IORM =
106 orb->resolve_initial_references (TAO_OBJID_IORMANIPULATION,
109 // Narrow
110 iorm =
111 TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM.in());
113 Test::Hello_var *servers = 0;
114 ACE_NEW_RETURN (servers,
115 Test::Hello_var [number_of_servers],
116 -1);
117 std::unique_ptr<Test::Hello_var[]> owner (servers);
119 for (CORBA::ULong i = 0; i < number_of_servers; ++ i)
121 char buf[4]; // if you run more than 10000 servers then you need your head looking at
122 const char *number = ACE_OS::itoa ((int) i, buf, 10);
123 ACE_CString ior_file ("file://n");
124 const char *ior = ((ior_file += number) += ".ior").c_str ();
126 CORBA::Object_var tmp =
127 orb->string_to_object(ior);
129 servers[i] =
130 Test::Hello::_narrow(tmp.in ());
132 if (CORBA::is_nil (servers[i].in ()))
134 ACE_ERROR_RETURN ((LM_DEBUG,
135 "Test failed - Not regression - Unexpected Nil Test::Hello reference <%s>\n",
136 ior),
141 CORBA::Object_var iogr = make_iogr ("Domain_1", 1, 1, servers);
143 Test::Hello_var hello_iogr = Test::Hello::_narrow(iogr.in ());
145 CORBA::ULong last_server = 0;
149 last_server = hello_iogr->drop_down_dead ();
150 // If the call 'succeeds' the server has identified a regression.
151 result = 1;
152 ACE_DEBUG ((LM_ERROR, "Error: REGRESSION identified by server %u. Test Failed !!\n", last_server));
154 catch (const CORBA::COMM_FAILURE&)
156 // We can't use the word exception for fear of upsetting the build log parser
157 ACE_DEBUG ((LM_DEBUG, "Client caught one of those things that is normally used to indicate a problem ("
158 "although it doesn't in this case) and which we cannot name because the autobuild "
159 "script will think we have a problem if we do mention the word. No problem !\n"));
162 for (CORBA::ULong j = last_server; j < number_of_servers; ++j)
166 servers[j]->shutdown ();
168 catch (...)
170 // Well we tried...
174 orb->destroy ();
176 catch (const CORBA::Exception& ex)
178 ex._tao_print_exception (
179 "Test failed (Not regression) because unexpected exception caught:");
180 return 1;
183 if (result)
185 ACE_DEBUG ((LM_ERROR, "Error: REGRESSION identified!!!\n"));
187 else
189 ACE_DEBUG ((LM_DEBUG, "Test passed !!!\n"));
191 return result;