Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / ACE / tests / Log_Msg_Test.cpp
blob3bc006c0113868d41dcaadd8bbf6553e6c94032c
1 //=============================================================================
2 /**
3 * @file Log_Msg_Test.cpp
5 * This program tests the <ACE_Log_Msg> class in various ways and
6 * also illustrates many of the features of the <ACE_Log_Msg> For
7 * instance, this program tests the <ACE_Log_Msg> abstraction wrt
8 * writing to stderr and to a file. It also tests writing to user
9 * defined callback objects.
11 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
13 //=============================================================================
16 #include "test_config.h"
18 // FUZZ: disable check_for_streams_include
19 #include "ace/streams.h"
21 #include "ace/FILE_Connector.h"
22 #include "ace/Auto_Ptr.h"
23 #include "ace/Log_Msg_Callback.h"
24 #include "ace/Log_Record.h"
25 #include "ace/OS_NS_fcntl.h"
26 #include "ace/OS_NS_string.h"
27 #include "ace/OS_NS_unistd.h"
28 #include "ace/OS_Memory.h"
29 #include "ace/OS_NS_sys_time.h"
30 #include "ace/OS_NS_time.h"
31 #include "ace/Time_Value.h"
32 #include "ace/Thread.h"
34 static void
35 cleanup (void)
37 ACE_DEBUG ((LM_INFO,
38 ACE_TEXT ("cleanup hook (%P)!\n")));
41 static void
42 cause_error (void)
44 errno = EWOULDBLOCK;
45 ACE_ERROR ((LM_DEBUG,
46 ACE_TEXT ("would block\n")));
49 class Logger : public ACE_Log_Msg_Callback
51 public:
52 /// Constructor sets whether we're testing "recursive" callback
53 /// logging!
54 Logger (bool be_recursive = true);
56 /// Logging callback
57 void log (ACE_Log_Record &log_record);
59 void verbose (bool be_verbose);
61 private:
62 /// Flag for testing verbose logging.
63 bool verbose_logging_;
65 /// Flag for testing recursive callback logging.
66 bool recursive_;
69 void
70 Logger::verbose (bool be_verbose)
72 this->verbose_logging_ = be_verbose;
75 Logger::Logger (bool be_recursive)
76 : recursive_ (be_recursive)
80 void
81 Logger::log (ACE_Log_Record &log_record)
83 bool use_log_msg = false;
84 if (this->recursive_)
86 this->recursive_ = false;
87 use_log_msg = true;
90 if (!this->verbose_logging_)
92 if (use_log_msg)
93 ACE_DEBUG ((LM_DEBUG,
94 ACE_TEXT ("Logger::log->%s\n"),
95 log_record.msg_data ()));
96 else
97 #ifdef ACE_LACKS_IOSTREAM_TOTALLY
98 ACE_OS::fprintf (ace_file_stream::instance ()->output_file (),
99 "Recursive Logger callback = %s\n",
100 ACE_TEXT_ALWAYS_CHAR (log_record.msg_data ()));
101 #else
102 *ace_file_stream::instance ()->output_file ()
103 << "Recursive Logger callback = "
104 << log_record.msg_data ()
105 << endl;
106 #endif /* ACE_LACKS_IOSTREAM_TOTALLY */
108 else
110 ACE_TCHAR verbose_msg[ACE_Log_Record::MAXVERBOSELOGMSGLEN];
111 int result = log_record.format_msg (ACE_LOG_MSG->local_host (),
112 ACE_LOG_MSG->flags (),
113 verbose_msg,
114 ACE_Log_Record::MAXVERBOSELOGMSGLEN);
115 if (result == 0)
117 if (use_log_msg)
118 ACE_DEBUG ((LM_DEBUG,
119 ACE_TEXT ("Logger::log->%s\n"),
120 verbose_msg));
121 else
122 #ifdef ACE_LACKS_IOSTREAM_TOTALLY
123 ACE_OS::fprintf (ace_file_stream::instance ()->output_file (),
124 "Recursive Logger callback = %s\n",
125 ACE_TEXT_ALWAYS_CHAR (log_record.msg_data ()));
126 #else
127 *ace_file_stream::instance ()->output_file ()
128 << "Recursive Logger callback = "
129 << log_record.msg_data ()
130 << endl;
131 #endif /* ACE_LACKS_IOSTREAM_TOTALLY */
135 // Cleanup on the way out.
136 if (use_log_msg)
137 this->recursive_ = true;
140 static void
141 test_callbacks (void)
143 // This message should show up in stderr.
144 ACE_DEBUG ((LM_DEBUG,
145 ACE_TEXT ("(%t) first message\n")));
147 ACE_LOG_MSG->clr_flags (ACE_Log_Msg::OSTREAM);
149 // This message should not show up anywhere.
150 ACE_DEBUG ((LM_DEBUG,
151 ACE_TEXT ("(%t) second message\n")));
153 ACE_LOG_MSG->set_flags (ACE_Log_Msg::MSG_CALLBACK);
155 // This message should not show up anywhere since no callback object
156 // has been specified.
157 ACE_DEBUG ((LM_DEBUG,
158 ACE_TEXT ("(%t) third message\n")));
160 // Create a callback object and make it "verbose".
161 Logger logger;
162 logger.verbose (1);
164 // Set the callback object.
165 ACE_LOG_MSG->msg_callback (&logger);
167 // This message should show up via the Logger callback.
168 ACE_DEBUG ((LM_DEBUG,
169 ACE_TEXT ("(%t) forth message\n")));
171 ACE_LOG_MSG->set_flags (ACE_Log_Msg::VERBOSE_LITE);
173 // This message should show up via the Logger callback (somewhat
174 // verbosely).
175 ACE_DEBUG ((LM_DEBUG,
176 ACE_TEXT ("(%t) fifth message\n")));
178 ACE_LOG_MSG->set_flags (ACE_Log_Msg::VERBOSE);
180 // This message should show up via the Logger callback (really
181 // verbosely).
182 ACE_DEBUG ((LM_DEBUG,
183 ACE_TEXT ("(%t) sixth message\n")));
185 logger.verbose (0);
187 // This message should show up via the Logger callback (not
188 // verbosely).
189 ACE_DEBUG ((LM_DEBUG,
190 ACE_TEXT ("(%t) seventh message\n")));
192 ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
194 // This message should show up in stderr and the Logger callback.
195 // The one from the Logger callback will not be verbose, but the one
196 // from stderr should be verbose.
197 ACE_DEBUG ((LM_DEBUG,
198 ACE_TEXT ("(%t) eighth message\n")));
199 ACE_LOG_MSG->msg_callback (0);
202 static void
203 test_log_msg_features (const ACE_TCHAR *program)
205 // Note that the default behavior is to log to STDERR...
207 int counter = 1 ;
209 if (ACE_LOG_MSG->open (program) == -1)
210 ACE_ERROR ((LM_ERROR,
211 ACE_TEXT ("cannot open logger!!!\n")));
213 cause_error ();
215 // Check to see what happened.
216 if (ACE_LOG_MSG->op_status () == -1
217 && ACE_LOG_MSG->errnum () == EWOULDBLOCK)
218 ACE_DEBUG ((LM_DEBUG,
219 ACE_TEXT ("op_status and errnum work!\n")));
220 else
221 ACE_ERROR ((LM_ERROR,
222 ACE_TEXT ("op_status and errnum failed!\n")));
224 const char *badname = "badname";
226 // We use the DEBUG messages instead of error messages. This is to
227 // help the scripts. If we print out error messages the scripts
228 // start catching them as errors.
229 if (ACE_OS::open (badname,
230 O_RDONLY) == ACE_INVALID_HANDLE)
231 ACE_DEBUG ((LM_DEBUG,
232 ACE_TEXT ("%n: (%x), can't open %C%r\n"),
233 10000,
234 badname,
235 cleanup));
237 // Try a log operation that would overflow the logging buffer if not
238 // properly guarded.
239 ACE_TCHAR big[ACE_Log_Record::MAXLOGMSGLEN + 1];
240 size_t i = 0;
241 static const ACE_TCHAR alphabet[] = ACE_TEXT ("abcdefghijklmnopqrstuvwxyz");
242 size_t j = ACE_OS::strlen (alphabet);
243 while (i < ACE_Log_Record::MAXLOGMSGLEN)
245 size_t const index = i++;
246 big[index] = alphabet[i % j];
248 big[ACE_Log_Record::MAXLOGMSGLEN] = ACE_TEXT ('\0');
249 ACE_DEBUG ((LM_INFO, ACE_TEXT ("This is too big:%l %s\n"), big));
251 ACE_HEX_DUMP((LM_INFO, (const char*)big, ACE_Log_Record::MAXLOGMSGLEN ));
253 // Exercise many different combinations of OSTREAM.
255 double f = 3.1416 * counter++;
256 int n = 10000;
258 ACE_DEBUG ((LM_INFO,
259 ACE_TEXT ("%10f, %*s%s = %d\n"),
262 ACE_TEXT (""),
263 ACE_TEXT ("hello"),
264 n));
266 ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
267 ACE_LOG_MSG->msg_ostream (ace_file_stream::instance ()->output_file ());
269 f = 3.1416 * counter;
270 n = 10000 * counter++;
272 ACE_DEBUG ((LM_INFO,
273 ACE_TEXT ("%10f, %*s%s = %d\n"),
276 ACE_TEXT (""),
277 ACE_TEXT ("world"),
278 n));
280 ACE_LOG_MSG->clr_flags (ACE_Log_Msg::OSTREAM);
282 // The next two messages shouldn't print.
284 f = 3.1416 * counter;
285 n = 10000 * counter++;
287 ACE_DEBUG ((LM_INFO,
288 ACE_TEXT ("%10f, %*s%s = %d\n"),
291 ACE_TEXT (""),
292 ACE_TEXT ("world"),
293 n));
295 f = 3.1416 * counter;
296 n = 10000 * counter++;
298 ACE_DEBUG ((LM_INFO,
299 ACE_TEXT ("%10f, %*s%s = %d\n"),
302 ACE_TEXT (""),
303 ACE_TEXT ("world"),
304 n));
306 ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
308 f = 3.1416 * counter;
309 n = 10000 * counter++;
311 ACE_DEBUG ((LM_INFO,
312 ACE_TEXT ("%10f, %*s%s = %d\n"),
315 ACE_TEXT (""),
316 ACE_TEXT ("world"),
317 n));
319 static int array[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048};
321 // Print out the binary bytes of the array in hex form.
322 ACE_LOG_MSG->log_hexdump (LM_DEBUG,
323 (char *) array,
324 sizeof array);
326 // Disable the LM_DEBUG and LM_INFO messages.
327 u_long priority_mask =
328 ACE_LOG_MSG->priority_mask (ACE_Log_Msg::PROCESS);
329 ACE_CLR_BITS (priority_mask,
330 LM_DEBUG | LM_INFO);
331 ACE_LOG_MSG->priority_mask (priority_mask,
332 ACE_Log_Msg::PROCESS);
334 ACE_DEBUG ((LM_INFO,
335 ACE_TEXT ("This LM_INFO message should not print!\n")));
336 ACE_DEBUG ((LM_DEBUG,
337 ACE_TEXT ("This LM_DEBUG message should not print!\n")));
339 ACE_SET_BITS (priority_mask,
340 LM_INFO);
341 ACE_LOG_MSG->priority_mask (priority_mask,
342 ACE_Log_Msg::PROCESS);
344 ACE_DEBUG ((LM_INFO,
345 ACE_TEXT ("This LM_INFO message should print!\n")));
346 ACE_DEBUG ((LM_DEBUG,
347 ACE_TEXT ("This LM_DEBUG message should not print!\n")));
349 ACE_CLR_BITS (priority_mask, LM_INFO);
350 ACE_LOG_MSG->priority_mask (priority_mask,
351 ACE_Log_Msg::PROCESS);
353 ACE_DEBUG ((LM_INFO,
354 ACE_TEXT ("This LM_INFO message should not print!\n")));
355 ACE_DEBUG ((LM_DEBUG,
356 ACE_TEXT ("This LM_DEBUG message should not print!\n")));
359 // For testing how many log records has been output
360 class Log_Count : public ACE_Log_Msg_Callback
362 int count_;
363 public:
364 /// logging!
365 Log_Count () : count_(0)
369 /// Logging callback
370 void log (ACE_Log_Record &)
372 ++count_;
375 int count() const
377 return count_;
381 static int
382 test_acelib_category()
384 int failed = 0;
386 Log_Count counter;
388 ACE_LOG_MSG->msg_callback (&counter);
390 // Disable the LM_DEBUG and LM_INFO messages.
391 u_long priority_mask =
392 ACE_LOG_MSG->priority_mask (ACE_Log_Msg::PROCESS);
393 ACE_CLR_BITS (priority_mask,
394 LM_DEBUG | LM_INFO);
395 ACE_Log_Category::ace_lib().priority_mask (priority_mask);
397 ACELIB_DEBUG ((LM_INFO,
398 ACE_TEXT ("This LM_INFO message should not print!\n")));
399 ACELIB_DEBUG ((LM_DEBUG,
400 ACE_TEXT ("This LM_DEBUG message should not print!\n")));
402 if (counter.count() != 0)
404 ++failed;
407 ACE_DEBUG ((LM_INFO,
408 ACE_TEXT ("This LM_INFO message should print!\n")));
409 ACE_DEBUG ((LM_DEBUG,
410 ACE_TEXT ("This LM_DEBUG message should print!\n")));
412 if (counter.count() != 2)
414 ++failed;
417 ACE_SET_BITS (priority_mask,
418 LM_INFO);
419 ACE_Log_Category::ace_lib().priority_mask (priority_mask);
421 ACELIB_DEBUG ((LM_INFO,
422 ACE_TEXT ("This LM_INFO message should print!\n")));
424 if (counter.count() != 3)
426 ++failed;
429 ACELIB_DEBUG ((LM_DEBUG,
430 ACE_TEXT ("This LM_DEBUG message should not print!\n")));
432 if (counter.count() != 3)
434 ++failed;
437 ACE_CLR_BITS (priority_mask, LM_INFO);
438 ACE_Log_Category::ace_lib().priority_mask (priority_mask);
440 ACELIB_DEBUG ((LM_INFO,
441 ACE_TEXT ("This LM_INFO message should not print!\n")));
442 ACELIB_DEBUG ((LM_DEBUG,
443 ACE_TEXT ("This LM_DEBUG message should not print!\n")));
445 if (counter.count() != 3)
447 ++failed;
451 if (failed == 0) {
452 ACE_DEBUG((LM_DEBUG, "All ace lib category log passed\n"));
454 else {
455 ACE_ERROR((LM_ERROR, "Some ace lib category log failed\n"));
457 ACE_LOG_MSG->msg_callback (0);
458 return failed;
461 static int
462 test_ostream (void)
464 // This message should show up in the log file.
465 ACE_DEBUG ((LM_DEBUG,
466 ACE_TEXT ("first message\n")));
468 ACE_LOG_MSG->clr_flags (ACE_Log_Msg::OSTREAM);
470 // This message should not show up anywhere.
471 ACE_DEBUG ((LM_DEBUG,
472 ACE_TEXT ("second message\n")));
474 ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
476 #if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
477 // Create a persistent store.
478 const ACE_TCHAR *filename = ACE_TEXT ("output");
479 ofstream myostream (ACE_TEXT_ALWAYS_CHAR (filename), ios::out | ios::trunc);
481 // Check for errors.
482 if (myostream.bad ())
483 return -1;
485 OFSTREAM *old_stream = ace_file_stream::instance ()->output_file ();
486 // Set the ostream.
487 ACE_LOG_MSG->msg_ostream (&myostream);
489 // This message should show up in the ostream.
490 ACE_DEBUG ((LM_DEBUG,
491 ACE_TEXT ("fourth message\n")));
492 // Set the ostream back to the test's log file.
493 ACE_LOG_MSG->msg_ostream (old_stream);
494 // Now close the ostream file and check its contents.
495 myostream.close ();
497 ACE_FILE_Connector connector;
498 ACE_FILE_IO file;
499 ACE_FILE_Addr file_addr (filename);
501 // Open up the file.
502 if (connector.connect (file, file_addr) == -1)
504 ACE_ERROR_RETURN ((LM_ERROR,
505 ACE_TEXT ("connect failed for %p\n"),
506 filename),
510 #if !defined (ACE_VXWORKS) && !defined (ACE_HAS_PHARLAP) || (defined(ACE_VXWORKS) && (ACE_VXWORKS > 0x690))
511 # define TEST_CAN_UNLINK_IN_ADVANCE
512 #endif
514 #if defined (TEST_CAN_UNLINK_IN_ADVANCE)
515 // Unlink this file right away so that it is automatically removed
516 // when the process exits.Ignore error returns in case this operation
517 // is not supported.
518 ACE_OS::unlink(filename);
519 #endif
521 ACE_FILE_Info info;
522 if (file.get_info (info) == -1)
524 ACE_ERROR_RETURN ((LM_ERROR,
525 ACE_TEXT ("get_info failed on %p\n"),
526 filename),
527 -1);
530 // Allocate the input buffer
531 char *buffer = 0;
532 ACE_NEW_RETURN (buffer,
533 char[info.size_ + 1],
534 -1);
535 // Make sure <buffer> is released automagically.
536 ACE_Auto_Basic_Array_Ptr<char> b (buffer);
538 // Read the file into the buffer.
539 ssize_t size = file.recv (buffer,
540 info.size_);
541 if (size != info.size_)
543 ACE_ERROR_RETURN ((LM_ERROR,
544 ACE_TEXT ("Read %d bytes, rather than expected %d bytes\n"),
545 size,
546 info.size_),
547 -1);
549 // Make sure to NUL-terminate this turkey!
550 buffer[size] = '\0';
553 ACE_DEBUG ((LM_DEBUG,
554 ACE_TEXT ("%C"),
555 buffer));
557 #if !defined (TEST_CAN_UNLINK_IN_ADVANCE)
558 file.close ();
559 if (file.unlink () == -1)
560 ACE_ERROR_RETURN ((LM_ERROR,
561 ACE_TEXT ("unlink failed for %p\n"),
562 file_addr.get_path_name ()),
564 #endif
566 #endif /* ACE_LACKS_IOSTREAM_TOTALLY */
568 // This message should show up in stderr and the ostream (without
569 // ACE_LACKS_IOSTREAM_TOTALLY).
570 ACE_DEBUG ((LM_DEBUG,
571 ACE_TEXT ("fifth message\n")));
573 return 0;
577 // For testing the format specifiers, a class is defined as a callback
578 // mechanism. It will get the formatted messages and check them for
579 // correctness. The test_format_specs() function will set the first
580 // few characters to say which test is being run, and the Log_Spec_Verify
581 // class will use that to decide how to verify the results.
583 class Log_Spec_Verify : public ACE_Log_Msg_Callback
585 public:
586 Log_Spec_Verify (bool be_recursive = true) : fail_ (0), tests_ (0), recursive_ (be_recursive) {};
588 /// Logging callback
589 void log (ACE_Log_Record &log_record);
591 int result ();
593 private:
594 /// Count how many tests failed.
595 int fail_;
597 /// Count how many tests we run
598 int tests_;
600 bool recursive_;
603 void
604 Log_Spec_Verify::log (ACE_Log_Record &log_record)
606 bool use_log_msg = false;
607 if (this->recursive_)
609 this->recursive_ = false;
610 use_log_msg = true;
613 if (!use_log_msg)
615 #if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
616 *ace_file_stream::instance ()->output_file ()
617 << "Logger callback = "
618 << log_record.msg_data ()
619 << endl;
620 #endif /* ACE_LACKS_IOSTREAM_TOTALLY */
622 else
624 const ACE_TCHAR *b = log_record.msg_data ();
625 const ACE_TCHAR *expect = 0;
627 ++this->tests_;
629 if (ACE_OS::strncmp (b, ACE_TEXT ("l1:"), 3) == 0)
631 expect = ACE_TEXT ("42");
632 b += 3;
634 else if (ACE_OS::strncmp (b, ACE_TEXT ("l2:"), 3) == 0)
636 expect = ACE_TEXT (" 42");
637 b += 3;
639 else if (ACE_OS::strncmp (b, ACE_TEXT ("l3N1:"), 4) == 0)
641 expect = ACE_TEXT ("0042,Log_Msg");
642 b += 5;
644 else if (ACE_OS::strncmp (b, ACE_TEXT ("l4:"), 3) == 0)
646 b += 3;
647 // Check if we have a string, exact length could vary
648 if (b != log_record.msg_data () && ACE_OS::strlen (b) < 15)
650 ACE_ERROR ((LM_ERROR, ACE_TEXT ("ERROR: Test %s failed; expected %d\n"),
651 log_record.msg_data (), ACE_OS::strlen (b)));
652 ++this->fail_;
655 else if (ACE_OS::strncmp (b, ACE_TEXT ("l5:"), 3) == 0)
657 b += 3;
658 switch (log_record.type())
660 case (LM_SHUTDOWN): expect = ACE_TEXT("S"); break;
661 case (LM_TRACE): expect = ACE_TEXT("T"); break;
662 case (LM_DEBUG): expect = ACE_TEXT("D"); break;
663 case (LM_INFO): expect = ACE_TEXT("I"); break;
664 case (LM_NOTICE): expect = ACE_TEXT("N"); break;
665 case (LM_WARNING): expect = ACE_TEXT("W"); break;
666 case (LM_STARTUP): expect = ACE_TEXT("U"); break;
667 case (LM_ERROR): expect = ACE_TEXT("E"); break;
668 case (LM_CRITICAL): expect = ACE_TEXT("C"); break;
669 case (LM_ALERT): expect = ACE_TEXT("A"); break;
670 case (LM_EMERGENCY): expect = ACE_TEXT("!"); break;
671 default: expect = ACE_TEXT("?"); break;
674 else if (ACE_OS::strncmp (b, ACE_TEXT ("l6:"), 3) == 0)
676 // After a l6 there shouldn't be a space
677 b += 1;
678 if (b != log_record.msg_data () && ACE_OS::strncmp (b, ACE_TEXT (" "), 1) == 0)
680 ACE_ERROR ((LM_ERROR, ACE_TEXT ("ERROR: Test %s failed; expected no space before the time\n"),
681 log_record.msg_data ()));
682 ++this->fail_;
685 else
687 ACE_ERROR ((LM_ERROR,
688 ACE_TEXT ("Log_Spec_Verify, unrecognized test: %s\n"),
689 b));
690 ++this->fail_;
693 if (b != log_record.msg_data () && expect && ACE_OS::strcmp (b, expect) != 0)
695 ACE_ERROR ((LM_ERROR, ACE_TEXT ("ERROR: Test %s failed; expected %s\n"),
696 log_record.msg_data (), expect));
697 ++this->fail_;
701 // Cleanup on the way out.
702 if (use_log_msg)
703 this->recursive_ = true;
707 Log_Spec_Verify::result (void)
709 if (this->fail_ == 0)
710 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("All logging specifier tests passed.\n")));
711 else
712 ACE_ERROR ((LM_ERROR, ACE_TEXT ("%d logging specifier tests failed!\n"),
713 this->fail_));
715 if (this->tests_ != 19)
717 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Expected number of tests run is %d, not 19!\n"),
718 this->tests_));
719 ++this->fail_;
721 return this->fail_;
724 static int
725 test_format_specs (void)
727 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l1:%l\n")));
728 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l2:%5l\n")));
729 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l3N1:%0*l,%.7N\n"), 4));
730 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%*ISTART INDENTING %{\n"), 4));
731 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%IONE%{\n")));
732 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%ITWO%{\n")));
733 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%ITHREE%*Iwp == 1\n"), 1));
734 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%}%ITWO\n")));
735 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%}%IONE\n")));
736 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%}%IENDINDENTING\n")));
737 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%W\n"), ACE_TEXT_WIDE ("My string test\n")));
738 ACE_WCHAR_T *nill_string = 0;
739 char* char_nill_string = 0;
740 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%W\n"), nill_string));
741 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s\n"), nill_string));
742 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%C\n"), char_nill_string));
743 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%m %p\n"), nill_string));
744 errno = ENOENT;
745 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%m %p\n"), ACE_TEXT("perror")));
746 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%S\n"), SIGINT));
747 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%S\n"), ACE_NSIG));
748 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("thread id %t\n")));
750 Log_Spec_Verify verifier;
752 ACE_LOG_MSG->msg_callback (&verifier);
753 ACE_LOG_MSG->clr_flags (ACE_Log_Msg::VERBOSE_LITE);
754 ACE_LOG_MSG->clr_flags (ACE_Log_Msg::VERBOSE);
755 ACE_LOG_MSG->linenum (42);
756 ACE_LOG_MSG->file ("Log_Msg_Test.cpp");
758 #ifdef ACE_LACKS_VA_FUNCTIONS
759 #define LOG_ARGS
760 #else
761 #define LOG_ARGS(X) X
762 #endif
764 ACE_LOG_MSG->log LOG_ARGS ((LM_DEBUG, ACE_TEXT ("l1:%l")));
765 ACE_LOG_MSG->log LOG_ARGS ((LM_DEBUG, ACE_TEXT ("l2:%5l")));
766 ACE_LOG_MSG->log LOG_ARGS ((LM_DEBUG, ACE_TEXT ("l3N1:%0*l,%.7N"), 4));
767 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l4:%T")));
769 ACE_LOG_MSG->priority_mask (LM_SHUTDOWN |
770 LM_TRACE |
771 LM_DEBUG |
772 LM_INFO |
773 LM_NOTICE |
774 LM_WARNING |
775 LM_STARTUP |
776 LM_ERROR |
777 LM_CRITICAL |
778 LM_ALERT |
779 LM_EMERGENCY,
780 ACE_Log_Msg::PROCESS);
781 ACE_DEBUG ((LM_SHUTDOWN, ACE_TEXT ("l5:%.1M")));
782 ACE_DEBUG ((LM_TRACE, ACE_TEXT ("l5:%.1M")));
783 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l5:%.1M")));
784 ACE_DEBUG ((LM_INFO, ACE_TEXT ("l5:%.1M")));
785 ACE_DEBUG ((LM_NOTICE, ACE_TEXT ("l5:%.1M")));
786 ACE_DEBUG ((LM_WARNING, ACE_TEXT ("l5:%.1M")));
787 ACE_DEBUG ((LM_STARTUP, ACE_TEXT ("l5:%.1M")));
788 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("l5:%.1M")));
789 ACE_DEBUG ((LM_CRITICAL, ACE_TEXT ("l5:%.1M")));
790 ACE_DEBUG ((LM_ALERT, ACE_TEXT ("l5:%.1M")));
791 ACE_DEBUG ((LM_EMERGENCY, ACE_TEXT ("l5:%.1M")));
793 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l6:%D\n")));
794 ACE_Time_Value tv = ACE_OS::gettimeofday ();
795 tv += ACE_Time_Value (25*60*60); // + 25 hours
796 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l6:%#D\n"), &tv));
798 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l6:%T\n")));
799 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l6:%#T\n"), &tv));
801 ACE_LOG_MSG->msg_ostream (ace_file_stream::instance ()->output_file ());
802 ACE_LOG_MSG->msg_callback (0);
803 ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
804 ACE_LOG_MSG->set_flags (ACE_Log_Msg::VERBOSE_LITE);
806 return verifier.result ();
809 // Main function.
812 run_main (int argc, ACE_TCHAR *argv[])
814 ACE_START_TEST (ACE_TEXT ("Log_Msg_Test"));
816 int status = 0;
818 ACE_DEBUG ((LM_DEBUG,
819 ACE_TEXT ("**** running ostream test\n")));
821 // Test the <ACE_Log_Msg> abstraction wrt writing to stderr and to a
822 // file.
823 test_ostream ();
825 ACE_DEBUG ((LM_DEBUG,
826 ACE_TEXT ("%M **** running callback test\n")));
828 // Test the <ACE_Log_Msg> callback mechanism.
829 test_callbacks ();
831 ACE_DEBUG ((LM_DEBUG,
832 ACE_TEXT ("**** running features test\n")));
834 // Test various features of the <ACE_Log_Msg>.
835 test_log_msg_features ((argc > 0 ? argv[0] : ACE_TEXT ("program")));
837 // Test the format specifiers
839 // Restore this mask so diags and the shutdown message will print correctly!
840 ACE_LOG_MSG->priority_mask (ACE_LOG_MSG->priority_mask () | LM_DEBUG | LM_ERROR,
841 ACE_Log_Msg::PROCESS);
843 ACE_DEBUG ((LM_DEBUG,
844 ACE_TEXT ("**** running format specifiers test\n")));
846 if (status += test_format_specs ())
848 ACE_ERROR ((LM_ERROR, ACE_TEXT ("logging specifier tests failed!\n")));
849 status = 1;
852 status += test_acelib_category();
854 ACE_END_TEST;
855 return status;