diff options
author | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-07-31 13:54:26 +0000 |
---|---|---|
committer | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-07-31 13:54:26 +0000 |
commit | 82fe2204351ba7f958c0df94bd34eed8a1356d77 (patch) | |
tree | 0e8bb54027d5ae57213b0b92b6c223dea247f9ee /tests/Service_Config_Test.cpp | |
parent | 3cacfbcbebb9c7e2489bfc12d89e92e798196790 (diff) | |
download | ATCD-82fe2204351ba7f958c0df94bd34eed8a1356d77.tar.gz |
added test of ACE_Service_Manager::at_exit ()
Diffstat (limited to 'tests/Service_Config_Test.cpp')
-rw-r--r-- | tests/Service_Config_Test.cpp | 66 |
1 files changed, 61 insertions, 5 deletions
diff --git a/tests/Service_Config_Test.cpp b/tests/Service_Config_Test.cpp index fd70532998a..f5630f2f7ad 100644 --- a/tests/Service_Config_Test.cpp +++ b/tests/Service_Config_Test.cpp @@ -4,28 +4,70 @@ // // = LIBRARY // tests -// +// // = FILENAME // Service_Config_Test.cpp // // = DESCRIPTION // This is a simple test to make sure the Service_Configurator is -// working correctly. +// working correctly. // // = AUTHOR // Doug Schmidt -// +// // ============================================================================ +#include "ace/Object_Manager.h" #include "ace/Service_Config.h" #include "test_config.h" +template <int NUMBER> +class mySingleton +{ +public: + static mySingleton *instance (); + static void cleanup (void *, void *); +private: + static mySingleton *instance_; + + mySingleton () { ACE_DEBUG ((LM_DEBUG, "mySingleton %d ctor\n", NUMBER)); } + // Can't use Log_Message here, yet, because it might already be deleted. + // It should work after ACE_Object_Manager starts using ::at_exit (). + ~mySingleton () { /* ACE_DEBUG ((LM_DEBUG, "mySingleton %d dtor\n", NUMBER)); */ } + + friend class friend_declaration_to_avoid_compiler_warning_with_private_ctor; +}; + +mySingleton<1> *mySingleton<1>::instance_ = 0; +mySingleton<2> *mySingleton<2>::instance_ = 0; +mySingleton<3> *mySingleton<3>::instance_ = 0; + +template <int NUMBER> +mySingleton<NUMBER> * +mySingleton<NUMBER>::instance () +{ + if (instance_ == 0) + { + ACE_NEW_RETURN (instance_, mySingleton, 0); + ACE_Object_Manager::at_exit (instance_, cleanup, 0); + } + + return instance_; +} + +template <int NUMBER> +void +mySingleton<NUMBER>::cleanup (void *object, void *) +{ + delete (mySingleton *) object; +} + static void run_test (int argc, char *argv[]) { // We need this scope to make sure ACE_Service_Config daemon; - + daemon.open (argc, argv); ACE_Time_Value tv (argc > 1 ? atoi (argv[1]) : 2); @@ -33,13 +75,27 @@ run_test (int argc, char *argv[]) ACE_ASSERT (ACE_Reactor::run_event_loop (tv) == 0); } -int +int main (int argc, char *argv[]) { ACE_START_TEST ("Service_Config_Test"); + mySingleton<1> &one = *mySingleton<1>::instance (); + mySingleton<2> &two = *mySingleton<2>::instance (); + mySingleton<3> &three = *mySingleton<3>::instance (); + if (&one == 0 || &two == 0 || &three == 0) + { + ACE_ERROR_RETURN ((LM_ERROR, "instance () allocate failed!\n"), 1); + } + run_test (argc, argv); ACE_END_TEST; return 0; } + +#if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) +template class mySingleton<1>; +template class mySingleton<2>; +template class mySingleton<3>; +#endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ |