Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Bug_2669_Regression / client.cpp
blobef9002835a6ca447f62907edc08f62a6094846a0
2 //=============================================================================
3 //=============================================================================
6 #include "ace/Get_Opt.h"
7 #include "ace/Task.h"
8 #include "ace/OS_NS_string.h"
10 #include "ChildS.h"
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT(""));
16 int c;
18 while ((c = get_opts ()) != -1)
19 switch (c)
21 case '?':
22 default:
23 ACE_ERROR_RETURN ((LM_ERROR,
24 "usage: %s "
25 "\n",
26 argv [0]),
27 -1);
29 // Indicates successful parsing of the command line
30 return 0;
33 class ChildHandler : public POA_ChildModule::AMI_ChildInterfaceHandler
35 public:
36 ChildHandler () = default;
37 ~ChildHandler () = default;
40 class NonRelatedChildHandler : public POA_AMI_ChildInterfaceHandler
42 public:
43 NonRelatedChildHandler () = default;
44 ~NonRelatedChildHandler () = default;
47 int
48 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
50 int result = 0;
53 try
55 CORBA::ORB_var orb =
56 CORBA::ORB_init (argc, argv);
58 CORBA::Object_var object_var =
59 orb->resolve_initial_references ("RootPOA");
61 PortableServer::POA_var poa_var =
62 PortableServer::POA::_narrow (object_var.in ());
64 PortableServer::POAManager_var poa_manager_var =
65 poa_var->the_POAManager ();
67 poa_manager_var->activate ();
69 if (parse_args (argc, argv) != 0)
70 return 1;
72 // Create two handlers
73 ChildHandler child_handler;
74 NonRelatedChildHandler non_related_child_handler;
76 PortableServer::ObjectId_var id =
77 poa_var->activate_object (&child_handler);
79 CORBA::Object_var object = poa_var->id_to_reference (id.in ());
81 ChildModule::AMI_ChildInterfaceHandler_var the_child_handler_var =
82 ChildModule::AMI_ChildInterfaceHandler::_narrow (object.in ());
84 const char * expectedid = "IDL:child.pragma.prefix/ChildModule/AMI_ChildInterfaceHandler:1.0";
85 if (ACE_OS::strcmp (the_child_handler_var->_interface_repository_id (), expectedid) != 0)
87 ACE_ERROR ((LM_ERROR, "Error: REGRESSION - ChildModule::repository id is "
88 "incorrectly generated, received %s\n",
89 the_child_handler_var->_interface_repository_id ()));
90 result = 1;
93 // This handler has no relationship with the above in IDL.
94 id = poa_var->activate_object (&non_related_child_handler);
96 object = poa_var->id_to_reference (id.in ());
98 AMI_ChildInterfaceHandler_var the_non_related_child_handler_var =
99 AMI_ChildInterfaceHandler::_narrow (object.in ());
101 // Check that both handler objects narrow successfully to their parent
102 // handler types...
103 ParentModule::AMI_ParentInterfaceHandler_var the_parent_handler_var =
104 ParentModule::AMI_ParentInterfaceHandler::_narrow (the_child_handler_var.in ());
106 if (CORBA::is_nil (the_parent_handler_var.in ()))
108 ACE_ERROR ((LM_ERROR, "Error: REGRESSION - Cannot narrow ChildModule::ChildInterface "
109 "reply handler to its parent handler type.\n"));
110 result = 1;
113 AMI_ParentInterfaceHandler_var the_non_related_parent_handler_var =
114 AMI_ParentInterfaceHandler::_narrow (the_non_related_child_handler_var.in ());
116 if (CORBA::is_nil (the_non_related_parent_handler_var.in ()))
118 ACE_ERROR ((LM_ERROR, "Error: REGRESSION - Cannot narrow ChildInterface "
119 "reply handler to its parent handler type.\n"));
120 result = 1;
123 // Check that both handler objects *won't* narrow to each other's parent
124 // handler types...
125 the_parent_handler_var =
126 ParentModule::AMI_ParentInterfaceHandler::_narrow (the_non_related_child_handler_var.in ());
128 if (! CORBA::is_nil (the_parent_handler_var.in ()))
130 ACE_ERROR ((LM_ERROR, "Error: REGRESSION - ChildModule::ChildInterface reply handler "
131 "narrows to unrelated type.\n"));
132 result = 1;
135 the_non_related_parent_handler_var =
136 AMI_ParentInterfaceHandler::_narrow (the_child_handler_var.in ());
138 if (! CORBA::is_nil (the_non_related_parent_handler_var.in ()))
140 ACE_ERROR ((LM_ERROR, "Error: REGRESSION - ChildModule::ChildInterface reply handler "
141 "narrows to unrelated type.\n"));
142 result = 1;
145 poa_var->destroy (1,0);
147 orb->destroy ();
149 catch (const CORBA::Exception& ex)
151 ex._tao_print_exception ("Caught exception:");
152 return 1;
155 return result;