Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / CSD_Strategy_Tests / TP_Common / AppHelper.cpp
blob084647b1edd0a13cb9348eefeb3751eab8ce0b18
1 #include "AppHelper.h"
3 void
4 AppHelper::ref_to_file(CORBA::ORB_ptr orb,
5 CORBA::Object_ptr obj,
6 const ACE_TCHAR* filename)
8 CORBA::String_var ior = orb->object_to_string(obj);
10 FILE* ior_file = ACE_OS::fopen(filename, ACE_TEXT("w"));
12 if (ior_file == 0)
14 ACE_ERROR((LM_ERROR,
15 "(%P|%t) Cannot open output file [%s] to write IOR.\n",
16 filename));
17 throw TestAppException();
20 ACE_OS::fprintf(ior_file, "%s", ior.in());
21 ACE_OS::fclose(ior_file);
25 PortableServer::POA_ptr
26 AppHelper::create_poa(const char* name,
27 PortableServer::POA_ptr root_poa,
28 PortableServer::POAManager_ptr mgr,
29 CORBA::PolicyList& policies)
31 PortableServer::POA_var child_poa = root_poa->create_POA(name,
32 mgr,
33 policies);
35 if (CORBA::is_nil(child_poa.in()))
37 ACE_ERROR((LM_ERROR,
38 "(%P|%t) Failed to create child POA: %s.\n", name));
39 throw TestAppException();
42 return child_poa._retn();
46 CORBA::Object_ptr
47 AppHelper::activate_servant(PortableServer::POA_ptr poa,
48 PortableServer::Servant servant)
50 // Activate the servant using the Child POA.
51 PortableServer::ObjectId_var oid
52 = poa->activate_object(servant);
54 CORBA::Object_var obj
55 = poa->servant_to_reference(servant);
57 if (CORBA::is_nil(obj.in()))
59 ACE_ERROR((LM_ERROR,
60 "(%P|%t) Failed to convert servant_to_ref.\n"));
61 throw TestAppException();
64 return obj._retn();
68 bool
69 AppHelper::validate_connection (CORBA::Object_ptr obj)
71 for (CORBA::ULong j = 0; j != 100; ++j)
73 try
75 #if (TAO_HAS_CORBA_MESSAGING == 1)
76 CORBA::PolicyList_var unused;
77 obj->_validate_connection (unused);
78 #else
79 obj->_is_a ("Not_An_IDL_Type");
80 #endif /* TAO_HAS_MESSAGING == 1 */
81 return true;
83 catch (const CORBA::Exception&)
88 return false;