diff options
author | Steve Huston <shuston@riverace.com> | 2006-08-29 21:22:39 +0000 |
---|---|---|
committer | Steve Huston <shuston@riverace.com> | 2006-08-29 21:22:39 +0000 |
commit | 0a72e0ea4019b89480a4d695e496870fdc34d51a (patch) | |
tree | 6e31530ace126a2a5dc6535f7714689e9e27f7ed | |
parent | ab2ae407f6e6a9c3c1442b7791268b5b31b1a579 (diff) | |
download | ATCD-0a72e0ea4019b89480a4d695e496870fdc34d51a.tar.gz |
ChangeLogTag:Tue Aug 29 21:17:26 UTC 2006 Steve Huston <shuston@riverace.com>
-rw-r--r-- | ACE/ChangeLog | 7 | ||||
-rw-r--r-- | ACE/tests/Service_Config_DLL.cpp | 43 | ||||
-rw-r--r-- | ACE/tests/Service_Config_DLL.h | 23 | ||||
-rw-r--r-- | ACE/tests/Service_Config_Test.cpp | 51 |
4 files changed, 121 insertions, 3 deletions
diff --git a/ACE/ChangeLog b/ACE/ChangeLog index 97518315dd8..970f4962495 100644 --- a/ACE/ChangeLog +++ b/ACE/ChangeLog @@ -1,3 +1,10 @@ +Tue Aug 29 21:17:26 UTC 2006 Steve Huston <shuston@riverace.com> + + * tests/Service_Config_DLL.{h cpp}: + * tests/Service_Config_Test.cpp: Added a test for ACE_Service_Config's + behavior when a dynamic service's init() hook returns -1 (failure). + This was precipitated by Bugzilla #2648. + Tue Aug 29 18:07:39 UTC 2006 Ossama Othman <ossama_othman at symantec dot com> * examples/IPC_SAP/SSL_SAP/SSL_SAP.mpc: diff --git a/ACE/tests/Service_Config_DLL.cpp b/ACE/tests/Service_Config_DLL.cpp index abe2f5aab7f..feada5ff2d1 100644 --- a/ACE/tests/Service_Config_DLL.cpp +++ b/ACE/tests/Service_Config_DLL.cpp @@ -229,3 +229,46 @@ ACE_STATIC_SVC_DEFINE (Test_Object_2_More, // Same factory is used for all service descriptors defined above. ACE_FACTORY_DEFINE (Service_Config_DLL, Service_Config_DLL) + +/* +** Simple service which will refuse to load/initialize correctly. +** The main program should do: +** 1. Try to load this service (which should fail) +** 2. Try to look up this service and call its info() hook; if info() +** can be called, the test has failed. +** Similarly, if fini() is called later, something is very wrong. +*/ + +/// Initializes object when dynamic linking occurs. +int +Refuses_Init::init (int, ACE_TCHAR *[]) +{ + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Refuses_Init::init - refusing to init\n"))); + return -1; +} + +/// Terminates object when dynamic unlinking occurs. +int +Refuses_Init::fini (void) +{ + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Refuses_Init::fini should not be called!\n"))); + return 0; +} + +/// Returns information on a service object. +int +Refuses_Init::info (ACE_TCHAR **info_string, size_t length) const +{ + ACE_TCHAR const *msg = + ACE_TEXT ("Refuses_Init service, shouldn't be here!\n"); + if (*info_string == 0) + *info_string = ACE::strnew (msg); + else + ACE_OS::strncpy (*info_string, msg, length); + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Refuses_Init::info() called - shouldn't be\n"))); + return ACE_OS::strlen (*info_string); +} + +ACE_FACTORY_DEFINE (Service_Config_DLL, Refuses_Init) diff --git a/ACE/tests/Service_Config_DLL.h b/ACE/tests/Service_Config_DLL.h index 1d0c194d2fa..7eebe0e6364 100644 --- a/ACE/tests/Service_Config_DLL.h +++ b/ACE/tests/Service_Config_DLL.h @@ -21,6 +21,7 @@ # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ +#include "ace/Service_Object.h" #include "ace/Task.h" /** @@ -60,8 +61,30 @@ private: }; +/** + * @class Refuses_Init + * + * @brief The Refuses_Init service simply tests for proper operation + * when a service's init() hook returns -1. + */ +class Service_Config_DLL_Export Refuses_Init : public ACE_Service_Object +{ +public: + // Constructor; required for factory function. + Refuses_Init () {} + + /// Initializes object when dynamic linking occurs. + virtual int init (int argc, ACE_TCHAR *argv[]); + + /// Terminates object when dynamic unlinking occurs. + virtual int fini (void); + + /// Returns information on a service object. + virtual int info (ACE_TCHAR **info_string, size_t length = 0) const; +}; ACE_FACTORY_DECLARE (Service_Config_DLL, Service_Config_DLL) +ACE_FACTORY_DECLARE (Service_Config_DLL, Refuses_Init) #include /**/ "ace/post.h" diff --git a/ACE/tests/Service_Config_Test.cpp b/ACE/tests/Service_Config_Test.cpp index c18970173be..2caaed3ea7f 100644 --- a/ACE/tests/Service_Config_Test.cpp +++ b/ACE/tests/Service_Config_Test.cpp @@ -20,6 +20,9 @@ #include "ace/Log_Msg.h" #include "ace/Object_Manager.h" #include "ace/Service_Config.h" +#include "ace/Service_Object.h" +#include "ace/Service_Repository.h" +#include "ace/Service_Types.h" #include "ace/Reactor.h" #include "ace/Thread_Manager.h" #include "ace/ARGV.h" @@ -118,6 +121,47 @@ Test_Singleton::~Test_Singleton (void) } void +testFailedServiceInit (int argc, ACE_TCHAR *argv[]) +{ + static const ACE_TCHAR *refuse_svc = +#if (ACE_USES_CLASSIC_SVC_CONF == 1) + ACE_TEXT ("dynamic Refuses_Svc Service_Object * ") + ACE_TEXT (" Service_Config_DLL:_make_Refuses_Init() \"\"") +#else + ACE_TEXT ("<dynamic id=\"Refuses_Svc\" type=\"Service_Object\">") + ACE_TEXT (" <initializer init=\"_make_Refuses_Init\" path=\"Service_Config_DLL\" params=\"\"/>") + ACE_TEXT ("</dynamic>") +#endif /* (ACE_USES_CLASSIC_SVC_CONF == 1) */ + ; + + int error_count = 0; + if ((error_count = ACE_Service_Config::process_directive (refuse_svc)) != 1) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Failed init test should have returned 1; ") + ACE_TEXT ("returned %d instead\n"), + error_count)); + } + + // Try to find the service; it should not be there. + ACE_Service_Type const *svcp; + if (-1 != ACE_Service_Repository::instance ()->find (ACE_TEXT ("Refuses_Svc"), + &svcp)) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Found service repo entry for Refuses_Svc\n"))); + ACE_Service_Type_Impl const *svc_impl = svcp->type (); + ACE_TCHAR msg[1024]; + ACE_TCHAR *msgp = msg; + if (svc_impl->info (&msgp, sizeof (msg) / sizeof (ACE_TCHAR)) > 0) + ACE_ERROR ((LM_ERROR, ACE_TEXT ("Refuses_Svc said: %s\n"), msg)); + } + else + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Repo reports no Refuses_Svc; correct.\n"))); +} + +void testLoadingServiceConfFile (int argc, ACE_TCHAR *argv[]) { ACE_ARGV new_argv; @@ -232,7 +276,7 @@ testLimits (int , ACE_TCHAR *[]) // @brief ?? void -testOrderlyInstantialtion (int , ACE_TCHAR *[]) +testOrderlyInstantiation (int , ACE_TCHAR *[]) { for (u_int i = 0; i < VARIETIES; ++i) { @@ -252,8 +296,9 @@ run_main (int argc, ACE_TCHAR *argv[]) { ACE_START_TEST (ACE_TEXT ("Service_Config_Test")); - testOrderlyInstantialtion (argc, argv); - testLoadingServiceConfFile (argc, argv); + testOrderlyInstantiation (argc, argv); + testFailedServiceInit (argc, argv); + testLoadingServiceConfFile (argc, argv); testLimits (argc, argv); ACE_END_TEST; |