1 // The following is required to be able to access
2 // ace_svc_desc_TAO_*_Parser, below
3 #include "tao/CORBALOC_Parser.h"
4 #include "tao/CORBANAME_Parser.h"
7 #include "ace/Service_Config.h"
8 #include "ace/Intrusive_Auto_Ptr.h"
9 #include "ace/Dynamic_Service.h"
10 #include "Service_Configuration_Per_ORB.h"
13 testCompatibility (int , ACE_TCHAR
*[])
15 ACE_TRACE ("testCompatibility");
17 // This uses the same default ACE_Service_Repository
18 ACE_Intrusive_Auto_Ptr
<ACE_Service_Gestalt_Test
> glob (new ACE_Service_Gestalt_Test());
20 // Use the "old" interface
21 if (0 != ACE_Service_Config::process_directive
22 (ace_svc_desc_TAO_CORBANAME_Parser
))
23 ACE_ERROR_RETURN ((LM_DEBUG
, ACE_TEXT("Failed to process %s\n"), ace_svc_desc_TAO_CORBANAME_Parser
), -1);
25 if(0 != ACE_Service_Config::process_directive
26 (ace_svc_desc_TAO_CORBALOC_Parser
))
27 ACE_ERROR_RETURN ((LM_DEBUG
, ACE_TEXT("Failed to process %s\n"), ace_svc_desc_TAO_CORBALOC_Parser
), -1);
29 const ACE_TCHAR
* svcname
= 0;
32 // This uses the same default ACE_Service_Repository
33 ACE_Intrusive_Auto_Ptr
<ACE_Service_Gestalt_Test
> one (new ACE_Service_Gestalt_Test());
35 svcname
= ACE_TEXT ("CORBANAME_Parser");
37 ACE_Service_Object
* p20
= ACE_Dynamic_Service
<ACE_Service_Object
>::instance (one
.get (), svcname
);
39 ACE_ERROR_RETURN ((LM_DEBUG
,
40 ACE_TEXT("Expected %s locally, in one\n"), svcname
), -1);
42 svcname
= ACE_TEXT ("CORBALOC_Parser");
44 ACE_Service_Object
* p21
= ACE_Dynamic_Service
<ACE_Service_Object
>::instance (one
.get (), svcname
);
46 ACE_ERROR_RETURN ((LM_DEBUG
,
47 ACE_TEXT("Expected %s locally, in one\n"), svcname
), -1);
49 // Exiting this scope should fini all services in the glob ...
52 svcname
= ACE_TEXT ("CORBANAME_Parser");
54 ACE_Service_Object
* p20
= ACE_Dynamic_Service
<ACE_Service_Object
>::instance (glob
.get (), svcname
);
56 ACE_ERROR_RETURN ((LM_DEBUG
,
57 ACE_TEXT("Expected %s globally, too\n"), svcname
), -1);
59 svcname
= ACE_TEXT ("CORBALOC_Parser");
61 ACE_Service_Object
* p21
= ACE_Dynamic_Service
<ACE_Service_Object
>::instance (glob
.get (), svcname
);
63 ACE_ERROR_RETURN ((LM_DEBUG
,
64 ACE_TEXT("Expected %s globally, too\n"), svcname
), -1);
69 // @brief Test commandline processing
72 testCommandLineDirectives (int , ACE_TCHAR
*[])
74 ACE_TRACE ("testCommandLineDirectives");
77 if (new_argv
.add (ACE_TEXT ("-f")) == -1
78 || new_argv
.add (ACE_TEXT ("-S")) == -1
79 || new_argv
.add (ACE_TEXT ("d1")) == -1
80 || new_argv
.add (ACE_TEXT ("-S")) == -1
81 || new_argv
.add (ACE_TEXT ("d2")) == -1)
83 ACE_ERROR_RETURN ((LM_DEBUG
, ACE_TEXT("Unable to create an argv\n")), -1);
86 ACE_Service_Gestalt_Test
g(5);
87 if (g
.parse_args (new_argv
.argc (),
88 new_argv
.argv ()) == -1
91 ACE_ERROR_RETURN ((LM_DEBUG
, ACE_TEXT("Failed to parse the argv\n")), -1);
94 ACE_DEBUG ((LM_DEBUG
, "\tg.command_line_directives_count () -> %d\n",
95 g
.command_line_directives_count ()));
97 if (2 != g
.command_line_directives_count ())
98 ACE_ERROR_RETURN ((LM_DEBUG
,
99 ACE_TEXT("Expected %d, but found %d command line directives\n"),
101 g
.command_line_directives_count ()),
107 // @brief Test the helper components used to implement the temporary
108 // substitution of the repository currently used as "global" for the
109 // sake of registering static services, which are dependent on a dynamic
113 testTSSGestalt (int , ACE_TCHAR
*[])
115 ACE_TRACE ("testTSSGestalt");
117 ACE_Service_Gestalt_Test
one (10); // Localized ones go here
119 ACE_Intrusive_Auto_Ptr
<ACE_Service_Gestalt
> global_instance
= ACE_Service_Config::instance ();
122 if (global_instance
== &one
)
123 ACE_ERROR_RETURN ((LM_DEBUG
, ACE_TEXT("Invalid global gestalt\n")), -1);
126 // Make one be the ACE_Service_Config::instance () ...
127 ACE_Service_Config_Guard
temporary (&one
);
129 ACE_Intrusive_Auto_Ptr
<ACE_Service_Gestalt
> global_instance2
= ACE_Service_Config::instance ();
131 if (global_instance
== global_instance2
)
132 ACE_ERROR_RETURN ((LM_DEBUG
, ACE_TEXT("Expected to see a different global from before\n")), -1);
134 if (global_instance2
!= &one
)
135 ACE_ERROR_RETURN ((LM_DEBUG
, ACE_TEXT("Expected one to be the global gestalt instance\n")), -1);
137 // The guard is dead! Long live the global gestalt that was previously global!
140 if (global_instance
!= ACE_Service_Config::instance ())
141 ACE_ERROR_RETURN ((LM_DEBUG
, ACE_TEXT("Expected the original global gestalt\n")), -1);
143 if (global_instance
== &one
)
144 ACE_ERROR_RETURN ((LM_DEBUG
, ACE_TEXT("Found the wrong instance is still being global\n")), -1);
149 // @brief the main driver
152 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
155 testCompatibility (argc
, argv
)
156 && testCommandLineDirectives (argc
, argv
)
157 && testTSSGestalt(argc
, argv
);