diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 2001-08-26 16:58:56 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 2001-08-26 16:58:56 +0000 |
commit | c99d526e5563849d2b6436b00a09b87b8433d591 (patch) | |
tree | 4e90f2b6e2e69b8b2afbc0883e5841f8c2efc064 /tests/Logging_Strategy_Test.cpp | |
parent | fde7cc35d48aed9734500f1d5185632e0e44b0b8 (diff) | |
download | ATCD-c99d526e5563849d2b6436b00a09b87b8433d591.tar.gz |
ChangeLogTag:Sun Aug 26 08:13:12 2001 Douglas C. Schmidt <schmidt@macarena.cs.wustl.edu>
Diffstat (limited to 'tests/Logging_Strategy_Test.cpp')
-rw-r--r-- | tests/Logging_Strategy_Test.cpp | 158 |
1 files changed, 102 insertions, 56 deletions
diff --git a/tests/Logging_Strategy_Test.cpp b/tests/Logging_Strategy_Test.cpp index 5b94a84d4af..f2cd54cc5f7 100644 --- a/tests/Logging_Strategy_Test.cpp +++ b/tests/Logging_Strategy_Test.cpp @@ -9,17 +9,24 @@ // Logging_Strategy_Test.cpp // // = DESCRIPTION -// This program tests the <ACE_Logging_Strategy> class in various ways -// and also illustrates many of the features of the <ACE_Log_Msg>. -// The test works as follows: +// This program tests the <ACE_Logging_Strategy> class in various +// ways and also illustrates many of the features of the +// <ACE_Log_Msg>. The test works as follows: // -Load the inserted arguments; -// -Remove existent log_files with the file_name specified by the user; -// -Generate 1000 messages to create the DEBUG statements to be stored in -// the files; -// -Counts the created log_files and if it was specified a maximum number -// of log_files, compare and verify if they are the same. +// -Remove existent log_files with the file_name specified by the +// user; +// -Generate 1000 messages to create the DEBUG statements to be +// stored in the files; +// -Counts the created log_files and if it was specified a maximum +// number of log_files, compare and verify if they are the same. // -Verify the order of the files with the order argument. // +// When Dlls are used, we utilize the dynamic service +// configuration mechanism to activate the logging strategy. This +// is not a must though, and you may activate the logging strategy +// as described in the non-DLL section below under DLL +// environments as well. +// // = AUTHOR // Orlando Ribeiro <oribeiro@inescporto.pt> // @@ -28,10 +35,18 @@ #include "ace/OS.h" #include "ace/Service_Config.h" #include "ace/Thread_Manager.h" -#include <ace/Get_Opt.h> + +#if defined (ACE_AS_STATIC_LIBS) || \ + (!defined (ACE_WIN32) && !defined (ACE_HAS_SVR4_DYNAMIC_LINKING) && \ + !defined (__hpux)) +#include "ace/Logging_Strategy.cpp" +#endif + +#include "ace/Auto_Ptr.cpp" +#include "ace/Get_Opt.h" #include "test_config.h" -ACE_RCSID(tests, Logging_Strategy_Test, "Logging_Strategy_Test.cpp,v 1.00 2001/02/19 05:17:39 oribeiro Exp") +ACE_RCSID(tests, Logging_Strategy_Test, "$Id$") #if !defined (ACE_LACKS_PRAGMA_ONCE) #pragma once @@ -71,11 +86,13 @@ static int max_num_files = 0; static int interval_time = 0; static int order_state = 0; static int num_files = 0; +static int wipeout_logfile = 0; void run_reactor (void *) { - ACE_Reactor::instance ()->owner (ACE_Thread_Manager::instance ()->thr_self ()); + ACE_Reactor::instance ()->owner + (ACE_Thread_Manager::instance ()->thr_self ()); ACE_Reactor::instance ()->run_event_loop (); } @@ -147,12 +164,14 @@ count_files (void) { if (max_num_files != num_files) ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("Creating files...Failed! Imput value=%d, Checked value=%d"), + ACE_TEXT ("Creating files...Failed!") + ACE_TEXT (" Input value=%d, Checked value=%d"), max_num_files, num_files)); else ACE_DEBUG ((LM_DEBUG, - ACE_TEXT (" Creating files...OK! Imput value=%d, Checked value=%d"), + ACE_TEXT (" Creating files...OK!") + ACE_TEXT (" Input value=%d, Checked value=%d"), max_num_files, num_files)); } @@ -206,7 +225,8 @@ order (void) if (num_files == 1) get_statistic (file_name); ACE_DEBUG ((LM_DEBUG, - ACE_TEXT (" Ordering...OK! - Only %d file (s) was (were) generated"), + ACE_TEXT (" Ordering...OK! - ") + ACE_TEXT (" Only %d file (s) was (were) generated"), num_files)); } else @@ -240,7 +260,8 @@ order (void) if ((tm_bk_1 < tm_bk_2) && order_state) { ACE_DEBUG ((LM_DEBUG, - ACE_TEXT (" %s (newest) ; %s (oldest)\n"), + ACE_TEXT (" %s (newest);") + ACE_TEXT ("%s (oldest)\n"), backup_2, backup_1)); ACE_DEBUG ((LM_DEBUG, @@ -248,7 +269,8 @@ order (void) } else ACE_DEBUG ((LM_DEBUG, - ACE_TEXT (" Ordering...FAILED! - The files are disorderly"))); + ACE_TEXT (" Ordering...FAILED!") + ACE_TEXT ("- The files are disorderly"))); } } @@ -278,12 +300,11 @@ remove_files (void) test = ACE_OS::unlink (backup); if (test != 0) error = 1; - } while (error != 1); ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("-< removing existent files finished... \n\n"))); + ACE_TEXT ("-< removing existing files...\n\n"))); } static int @@ -291,7 +312,7 @@ parse_args (int argc, ACE_TCHAR *argv[]) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Specifications:\n"))); - ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("s:i:m:f:n:o")); + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("s:i:m:f:N:ow")); int c; while ((c = get_opt ()) != EOF) @@ -320,7 +341,7 @@ parse_args (int argc, ACE_TCHAR *argv[]) ACE_TEXT ("Modes: %s\n"), get_opt.optarg)); break; - case 'n': + case 'N': max_num_files = ACE_OS::atoi (get_opt.optarg); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Maximum files number: %d\n"), @@ -331,17 +352,27 @@ parse_args (int argc, ACE_TCHAR *argv[]) ACE_TEXT ("Ordering files activated\n"))); order_state = 1; break; + case 'w': + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Wipeout logfile activated\n"))); + wipeout_logfile = 1; + break; default: - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("usage: [-s]<file_name>") - ACE_TEXT ("[-i]<sample_interval> [-m]<max_size> [-f]<msg_flags> [-n]<num_files> [-o]\n") - ACE_TEXT ("\t-s: Specify the name of the log files.\n") - ACE_TEXT ("\t-i: Define the sample interval in secs.\n") - ACE_TEXT ("\t-m: Define the max size for the log_files in KB.\n") - ACE_TEXT ("\t-f: Indicates the Log_Msg flags.\n") - ACE_TEXT ("\t-n: Define the maximum number of log_files.\n") - ACE_TEXT ("\t-o: If activated puts the log_files ordered.\n")), - -1); + ACE_ERROR_RETURN + ((LM_ERROR, + ACE_TEXT ("usage: [-s]<file_name>") + ACE_TEXT ("[-i]<sample_interval> ") + ACE_TEXT ("[-m]<max_size> [-f]<msg_flags> ") + ACE_TEXT ("[-n]<num_files> [-o]\n") + ACE_TEXT ("\t-s: Specify the name of the log files.\n") + ACE_TEXT ("\t-i: Define the sample interval in secs.\n") + ACE_TEXT ("\t-m: Define the max size for the log_files in KB.\n") + ACE_TEXT ("\t-f: Indicates the Log_Msg flags.\n") + ACE_TEXT ("\t-N: Define the maximum number of log_files.\n") + ACE_TEXT ("\t-o: If activated puts the log_files ordered.\n"), + ACE_TEXT ("\t-w: If activated cause the logfile to be wiped out,") + ACE_TEXT (" both on startup and on reconfigure.\n")), + -1); /* NOTREACHED */ break; } @@ -354,13 +385,6 @@ int main (int argc, ACE_TCHAR *argv []) { ACE_START_TEST (ACE_TEXT ("Logging_Strategy_Test")); - // Protection against this test being run on platforms not supporting Dlls. -#if defined (ACE_WIN32) || defined (ACE_HAS_SVR4_DYNAMIC_LINKING) || \ - defined (__hpux) - - // Implement the dynamic entries via main arguments - ACE_LOG_MSG->open (argv[0]); - ACE_TCHAR *l_argv[4]; if (argc > 1) @@ -373,7 +397,8 @@ int main (int argc, ACE_TCHAR *argv []) else { l_argv[0] = argv[0]; - l_argv[1] = (ACE_TCHAR *) ACE_TEXT ("-slog/Logging_Strategy_Test.log"); + l_argv[1] = + (ACE_TCHAR *) ACE_TEXT ("-slog/Logging_Strategy_Test.log"); l_argv[2] = (ACE_TCHAR *) ACE_TEXT ("-o"); l_argv[3] = 0; @@ -385,9 +410,28 @@ int main (int argc, ACE_TCHAR *argv []) argc = 3; } + // Remove the existent files + remove_files (); + + // This is necessary only if the provided logfile name is the same + // as the default name. If so, nothing will be written as the + // previous ofstream is closed only at the end (ACE_END_TEST) + ACE_CLOSE_TEST_LOG; + + // When Dlls are used, we utilize the dynamic service configuration + // mechanism to activate the logging strategy. This is not a must + // though, and you may activate the logging strategy as described in + // the non-DLL section below under DLL environments as well. + +#if !defined (ACE_AS_STATIC_LIBS) && \ + (defined (ACE_WIN32) || defined (ACE_HAS_SVR4_DYNAMIC_LINKING) || \ + defined (__hpux)) + // Platform support DLLs, and not configured to link statically ACE_TCHAR arg_str[250]; ACE_OS::sprintf (arg_str, - ACE_TEXT ("dynamic Logger Service_Object *ACE:_make_ACE_Logging_Strategy() \"")); + ACE_TEXT ("dynamic Logger Service_Object ") + ACE_TEXT ("*ACE:_make_ACE_Logging_Strategy()") + ACE_TEXT ("\"")); for (int i = 1; i < argc; i++) { @@ -399,18 +443,32 @@ int main (int argc, ACE_TCHAR *argv []) if (ACE_Service_Config::process_directive (arg_str) == -1) ACE_ERROR_RETURN ((LM_ERROR, - "Error opening _make_ACE_Log_Strategy object.\n"), + "Error opening _make_ACE_Log_Strategy.\n"), 1); +#else // Platform doesn't support DLLs, or configured to link + // statically + ACE_Logging_Strategy logging_strategy; + char ls_argc = argc - 1; + auto_ptr<ACE_TCHAR *> ls_argv (new ACE_TCHAR *[ls_argc]); + + for (char c = 0; c < ls_argc; c++) + (ls_argv.get ())[c] = argv[c+1]; + + if (logging_strategy.init (ls_argc, ls_argv.get ()) == -1) + ACE_ERROR_RETURN + ((LM_ERROR, + "Error initializing the ACE_Logging_Strategy.\n"), + 1); +#endif /* !ACE_AS_STATIC_LIBS && (ACE_WIN32 || + ACE_HAS_SVR4_DYNAMIC_LINKING || __hpux) */ // launch a new Thread - if (ACE_Thread_Manager::instance ()->spawn (ACE_THR_FUNC (run_reactor)) < 0) + if (ACE_Thread_Manager::instance ()->spawn + (ACE_THR_FUNC (run_reactor)) < 0) ACE_ERROR_RETURN ((LM_ERROR, "Spawning Reactor.\n"), 1); - // Remove the existent files - remove_files (); - // Function to print the message print_till_death (); @@ -425,18 +483,6 @@ int main (int argc, ACE_TCHAR *argv []) "Error ending reactor.\n"), 1); -#else - ACE_ERROR ((LM_INFO, - ACE_TEXT ("DLLs not supported on this platform\n"))); - - ACE_UNUSED_ARG (argc); - ACE_UNUSED_ARG (argv); - ACE_UNUSED_ARG (print_till_death); - ACE_UNUSED_ARG (order); - ACE_UNUSED_ARG (remove_files); - ACE_UNUSED_ARG (parse_args); -#endif /* ACE_WIN32 || ACE_HAS_SVR4_DYNAMIC_LINKING || __hpux */ - ACE_END_TEST; return 0; } |