Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / tests / Log_Msg_Test.cpp
blob579dddd1e8c6d857c8005f2befcbada199ffaf55
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 //=============================================================================
15 #include "test_config.h"
17 // FUZZ: disable check_for_streams_include
18 #include "ace/streams.h"
20 #include "ace/FILE_Connector.h"
21 #include <memory>
22 #include "ace/Log_Msg_Callback.h"
23 #include "ace/Log_Record.h"
24 #include "ace/OS_NS_fcntl.h"
25 #include "ace/OS_NS_string.h"
26 #include "ace/OS_NS_unistd.h"
27 #include "ace/OS_Memory.h"
28 #include "ace/OS_NS_sys_time.h"
29 #include "ace/OS_NS_time.h"
30 #include "ace/Time_Value.h"
31 #include "ace/Thread.h"
33 static void
34 cleanup ()
36 ACE_DEBUG ((LM_INFO,
37 ACE_TEXT ("cleanup hook (%P)!\n")));
40 static void
41 cause_error ()
43 errno = EWOULDBLOCK;
44 ACE_ERROR ((LM_DEBUG,
45 ACE_TEXT ("would block\n")));
48 class Logger : public ACE_Log_Msg_Callback
50 public:
51 /// Constructor sets whether we're testing "recursive" callback
52 /// logging!
53 Logger (bool be_recursive = true);
55 /// Logging callback
56 void log (ACE_Log_Record &log_record) override;
58 void verbose (bool be_verbose);
60 private:
61 /// Flag for testing verbose logging.
62 bool verbose_logging_;
64 /// Flag for testing recursive callback logging.
65 bool recursive_;
68 void
69 Logger::verbose (bool be_verbose)
71 this->verbose_logging_ = be_verbose;
74 Logger::Logger (bool be_recursive)
75 : recursive_ (be_recursive)
79 void
80 Logger::log (ACE_Log_Record &log_record)
82 bool use_log_msg = false;
83 if (this->recursive_)
85 this->recursive_ = false;
86 use_log_msg = true;
89 if (!this->verbose_logging_)
91 if (use_log_msg)
92 ACE_DEBUG ((LM_DEBUG,
93 ACE_TEXT ("Logger::log->%s\n"),
94 log_record.msg_data ()));
95 else
96 #ifdef ACE_LACKS_IOSTREAM_TOTALLY
97 ACE_OS::fprintf (ace_file_stream::instance ()->output_file (),
98 "Recursive Logger callback = %s\n",
99 ACE_TEXT_ALWAYS_CHAR (log_record.msg_data ()));
100 #else
101 *ace_file_stream::instance ()->output_file ()
102 << "Recursive Logger callback = "
103 << log_record.msg_data ()
104 << endl;
105 #endif /* ACE_LACKS_IOSTREAM_TOTALLY */
107 else
109 ACE_TCHAR verbose_msg[ACE_Log_Record::MAXVERBOSELOGMSGLEN];
110 int result = log_record.format_msg (ACE_LOG_MSG->local_host (),
111 ACE_LOG_MSG->flags (),
112 verbose_msg,
113 ACE_Log_Record::MAXVERBOSELOGMSGLEN);
114 if (result == 0)
116 if (use_log_msg)
117 ACE_DEBUG ((LM_DEBUG,
118 ACE_TEXT ("Logger::log->%s\n"),
119 verbose_msg));
120 else
121 #ifdef ACE_LACKS_IOSTREAM_TOTALLY
122 ACE_OS::fprintf (ace_file_stream::instance ()->output_file (),
123 "Recursive Logger callback = %s\n",
124 ACE_TEXT_ALWAYS_CHAR (log_record.msg_data ()));
125 #else
126 *ace_file_stream::instance ()->output_file ()
127 << "Recursive Logger callback = "
128 << log_record.msg_data ()
129 << endl;
130 #endif /* ACE_LACKS_IOSTREAM_TOTALLY */
134 // Cleanup on the way out.
135 if (use_log_msg)
136 this->recursive_ = true;
139 static void
140 test_callbacks ()
142 // This message should show up in stderr.
143 ACE_DEBUG ((LM_DEBUG,
144 ACE_TEXT ("(%t) first message\n")));
146 ACE_LOG_MSG->clr_flags (ACE_Log_Msg::OSTREAM);
148 // This message should not show up anywhere.
149 ACE_DEBUG ((LM_DEBUG,
150 ACE_TEXT ("(%t) second message\n")));
152 ACE_LOG_MSG->set_flags (ACE_Log_Msg::MSG_CALLBACK);
154 // This message should not show up anywhere since no callback object
155 // has been specified.
156 ACE_DEBUG ((LM_DEBUG,
157 ACE_TEXT ("(%t) third message\n")));
159 // Create a callback object and make it "verbose".
160 Logger logger;
161 logger.verbose (1);
163 // Set the callback object.
164 ACE_LOG_MSG->msg_callback (&logger);
166 // This message should show up via the Logger callback.
167 ACE_DEBUG ((LM_DEBUG,
168 ACE_TEXT ("(%t) forth message\n")));
170 ACE_LOG_MSG->set_flags (ACE_Log_Msg::VERBOSE_LITE);
172 // This message should show up via the Logger callback (somewhat
173 // verbosely).
174 ACE_DEBUG ((LM_DEBUG,
175 ACE_TEXT ("(%t) fifth message\n")));
177 ACE_LOG_MSG->set_flags (ACE_Log_Msg::VERBOSE);
179 // This message should show up via the Logger callback (really
180 // verbosely).
181 ACE_DEBUG ((LM_DEBUG,
182 ACE_TEXT ("(%t) sixth message\n")));
184 logger.verbose (0);
186 // This message should show up via the Logger callback (not
187 // verbosely).
188 ACE_DEBUG ((LM_DEBUG,
189 ACE_TEXT ("(%t) seventh message\n")));
191 ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
193 // This message should show up in stderr and the Logger callback.
194 // The one from the Logger callback will not be verbose, but the one
195 // from stderr should be verbose.
196 ACE_DEBUG ((LM_DEBUG,
197 ACE_TEXT ("(%t) eighth message\n")));
198 ACE_LOG_MSG->msg_callback (0);
201 static void
202 test_log_msg_features (const ACE_TCHAR *program)
204 // Note that the default behavior is to log to STDERR...
206 int counter = 1 ;
208 if (ACE_LOG_MSG->open (program) == -1)
209 ACE_ERROR ((LM_ERROR,
210 ACE_TEXT ("cannot open logger!!!\n")));
212 cause_error ();
214 // Check to see what happened.
215 if (ACE_LOG_MSG->op_status () == -1
216 && ACE_LOG_MSG->errnum () == EWOULDBLOCK)
217 ACE_DEBUG ((LM_DEBUG,
218 ACE_TEXT ("op_status and errnum work!\n")));
219 else
220 ACE_ERROR ((LM_ERROR,
221 ACE_TEXT ("op_status and errnum failed!\n")));
223 const char *badname = "badname";
225 // We use the DEBUG messages instead of error messages. This is to
226 // help the scripts. If we print out error messages the scripts
227 // start catching them as errors.
228 if (ACE_OS::open (badname,
229 O_RDONLY) == ACE_INVALID_HANDLE)
230 ACE_DEBUG ((LM_DEBUG,
231 ACE_TEXT ("%n: (%x), can't open %C%r\n"),
232 10000,
233 badname,
234 cleanup));
236 // Try a log operation that would overflow the logging buffer if not
237 // properly guarded.
238 ACE_TCHAR big[ACE_Log_Record::MAXLOGMSGLEN + 1];
239 size_t i = 0;
240 static const ACE_TCHAR alphabet[] = ACE_TEXT ("abcdefghijklmnopqrstuvwxyz");
241 size_t j = ACE_OS::strlen (alphabet);
242 while (i < ACE_Log_Record::MAXLOGMSGLEN)
244 size_t const index = i++;
245 big[index] = alphabet[i % j];
247 big[ACE_Log_Record::MAXLOGMSGLEN] = ACE_TEXT ('\0');
248 ACE_DEBUG ((LM_INFO, ACE_TEXT ("This is too big:%l %s\n"), big));
250 ACE_HEX_DUMP((LM_INFO, (const char*)big, ACE_Log_Record::MAXLOGMSGLEN ));
252 // Exercise many different combinations of OSTREAM.
254 double f = 3.1416 * counter++;
255 int n = 10000;
257 ACE_DEBUG ((LM_INFO,
258 ACE_TEXT ("%10f, %*s%s = %d\n"),
261 ACE_TEXT (""),
262 ACE_TEXT ("hello"),
263 n));
265 ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
266 ACE_LOG_MSG->msg_ostream (ace_file_stream::instance ()->output_file ());
268 f = 3.1416 * counter;
269 n = 10000 * counter++;
271 ACE_DEBUG ((LM_INFO,
272 ACE_TEXT ("%10f, %*s%s = %d\n"),
275 ACE_TEXT (""),
276 ACE_TEXT ("world"),
277 n));
279 ACE_LOG_MSG->clr_flags (ACE_Log_Msg::OSTREAM);
281 // The next two messages shouldn't print.
283 f = 3.1416 * counter;
284 n = 10000 * counter++;
286 ACE_DEBUG ((LM_INFO,
287 ACE_TEXT ("%10f, %*s%s = %d\n"),
290 ACE_TEXT (""),
291 ACE_TEXT ("world"),
292 n));
294 f = 3.1416 * counter;
295 n = 10000 * counter++;
297 ACE_DEBUG ((LM_INFO,
298 ACE_TEXT ("%10f, %*s%s = %d\n"),
301 ACE_TEXT (""),
302 ACE_TEXT ("world"),
303 n));
305 ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
307 f = 3.1416 * counter;
308 n = 10000 * counter++;
310 ACE_DEBUG ((LM_INFO,
311 ACE_TEXT ("%10f, %*s%s = %d\n"),
314 ACE_TEXT (""),
315 ACE_TEXT ("world"),
316 n));
318 static int array[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048};
320 // Print out the binary bytes of the array in hex form.
321 ACE_LOG_MSG->log_hexdump (LM_DEBUG,
322 (char *) array,
323 sizeof array);
325 // Disable the LM_DEBUG and LM_INFO messages.
326 u_long priority_mask =
327 ACE_LOG_MSG->priority_mask (ACE_Log_Msg::PROCESS);
328 ACE_CLR_BITS (priority_mask,
329 LM_DEBUG | LM_INFO);
330 ACE_LOG_MSG->priority_mask (priority_mask,
331 ACE_Log_Msg::PROCESS);
333 ACE_DEBUG ((LM_INFO,
334 ACE_TEXT ("This LM_INFO message should not print!\n")));
335 ACE_DEBUG ((LM_DEBUG,
336 ACE_TEXT ("This LM_DEBUG message should not print!\n")));
338 ACE_SET_BITS (priority_mask,
339 LM_INFO);
340 ACE_LOG_MSG->priority_mask (priority_mask,
341 ACE_Log_Msg::PROCESS);
343 ACE_DEBUG ((LM_INFO,
344 ACE_TEXT ("This LM_INFO message should print!\n")));
345 ACE_DEBUG ((LM_DEBUG,
346 ACE_TEXT ("This LM_DEBUG message should not print!\n")));
348 ACE_CLR_BITS (priority_mask, LM_INFO);
349 ACE_LOG_MSG->priority_mask (priority_mask,
350 ACE_Log_Msg::PROCESS);
352 ACE_DEBUG ((LM_INFO,
353 ACE_TEXT ("This LM_INFO message should not print!\n")));
354 ACE_DEBUG ((LM_DEBUG,
355 ACE_TEXT ("This LM_DEBUG message should not print!\n")));
358 // For testing how many log records has been output
359 class Log_Count : public ACE_Log_Msg_Callback
361 int count_;
362 public:
363 /// logging!
364 Log_Count () : count_(0)
368 /// Logging callback
369 void log (ACE_Log_Record &) override
371 ++count_;
374 int count() const
376 return count_;
380 static int
381 test_acelib_category()
383 int failed = 0;
385 Log_Count counter;
387 ACE_LOG_MSG->msg_callback (&counter);
389 // Disable the LM_DEBUG and LM_INFO messages.
390 u_long priority_mask =
391 ACE_LOG_MSG->priority_mask (ACE_Log_Msg::PROCESS);
392 ACE_CLR_BITS (priority_mask,
393 LM_DEBUG | LM_INFO);
394 ACE_Log_Category::ace_lib().priority_mask (priority_mask);
396 ACELIB_DEBUG ((LM_INFO,
397 ACE_TEXT ("This LM_INFO message should not print!\n")));
398 ACELIB_DEBUG ((LM_DEBUG,
399 ACE_TEXT ("This LM_DEBUG message should not print!\n")));
401 if (counter.count() != 0)
403 ++failed;
406 ACE_DEBUG ((LM_INFO,
407 ACE_TEXT ("This LM_INFO message should print!\n")));
408 ACE_DEBUG ((LM_DEBUG,
409 ACE_TEXT ("This LM_DEBUG message should print!\n")));
411 if (counter.count() != 2)
413 ++failed;
416 ACE_SET_BITS (priority_mask,
417 LM_INFO);
418 ACE_Log_Category::ace_lib().priority_mask (priority_mask);
420 ACELIB_DEBUG ((LM_INFO,
421 ACE_TEXT ("This LM_INFO message should print!\n")));
423 if (counter.count() != 3)
425 ++failed;
428 ACELIB_DEBUG ((LM_DEBUG,
429 ACE_TEXT ("This LM_DEBUG message should not print!\n")));
431 if (counter.count() != 3)
433 ++failed;
436 ACE_CLR_BITS (priority_mask, LM_INFO);
437 ACE_Log_Category::ace_lib().priority_mask (priority_mask);
439 ACELIB_DEBUG ((LM_INFO,
440 ACE_TEXT ("This LM_INFO message should not print!\n")));
441 ACELIB_DEBUG ((LM_DEBUG,
442 ACE_TEXT ("This LM_DEBUG message should not print!\n")));
444 if (counter.count() != 3)
446 ++failed;
450 if (failed == 0) {
451 ACE_DEBUG((LM_DEBUG, "All ace lib category log passed\n"));
453 else {
454 ACE_ERROR((LM_ERROR, "Some ace lib category log failed\n"));
456 ACE_LOG_MSG->msg_callback (0);
457 return failed;
460 static int
461 test_ostream ()
463 // This message should show up in the log file.
464 ACE_DEBUG ((LM_DEBUG,
465 ACE_TEXT ("first message\n")));
467 ACE_LOG_MSG->clr_flags (ACE_Log_Msg::OSTREAM);
469 // This message should not show up anywhere.
470 ACE_DEBUG ((LM_DEBUG,
471 ACE_TEXT ("second message\n")));
473 ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
475 #if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
476 // Create a persistent store.
477 const ACE_TCHAR *filename = ACE_TEXT ("output");
478 ofstream myostream (ACE_TEXT_ALWAYS_CHAR (filename), ios::out | ios::trunc);
480 // Check for errors.
481 if (myostream.bad ())
482 return -1;
484 OFSTREAM *old_stream = ace_file_stream::instance ()->output_file ();
485 // Set the ostream.
486 ACE_LOG_MSG->msg_ostream (&myostream);
488 // This message should show up in the ostream.
489 ACE_DEBUG ((LM_DEBUG,
490 ACE_TEXT ("fourth message\n")));
491 // Set the ostream back to the test's log file.
492 ACE_LOG_MSG->msg_ostream (old_stream);
493 // Now close the ostream file and check its contents.
494 myostream.close ();
496 ACE_FILE_Connector connector;
497 ACE_FILE_IO file;
498 ACE_FILE_Addr file_addr (filename);
500 // Open up the file.
501 if (connector.connect (file, file_addr) == -1)
503 ACE_ERROR_RETURN ((LM_ERROR,
504 ACE_TEXT ("connect failed for %p\n"),
505 filename),
509 #if !defined (ACE_VXWORKS) || (defined(ACE_VXWORKS) && (ACE_VXWORKS > 0x690))
510 # define TEST_CAN_UNLINK_IN_ADVANCE
511 #endif
513 #if defined (TEST_CAN_UNLINK_IN_ADVANCE)
514 // Unlink this file right away so that it is automatically removed
515 // when the process exits.Ignore error returns in case this operation
516 // is not supported.
517 ACE_OS::unlink(filename);
518 #endif
520 ACE_FILE_Info info;
521 if (file.get_info (info) == -1)
523 ACE_ERROR_RETURN ((LM_ERROR,
524 ACE_TEXT ("get_info failed on %p\n"),
525 filename),
526 -1);
529 // Allocate the input buffer
530 char *buffer = 0;
531 ACE_NEW_RETURN (buffer,
532 char[info.size_ + 1],
533 -1);
534 // Make sure <buffer> is released automagically.
535 std::unique_ptr<char[]> b (buffer);
537 // Read the file into the buffer.
538 ssize_t size = file.recv (buffer,
539 info.size_);
540 if (size != info.size_)
542 ACE_ERROR_RETURN ((LM_ERROR,
543 ACE_TEXT ("Read %d bytes, rather than expected %d bytes\n"),
544 size,
545 info.size_),
546 -1);
548 // Make sure to NUL-terminate this turkey!
549 buffer[size] = '\0';
552 ACE_DEBUG ((LM_DEBUG,
553 ACE_TEXT ("%C"),
554 buffer));
556 #if !defined (TEST_CAN_UNLINK_IN_ADVANCE)
557 file.close ();
558 if (file.unlink () == -1)
559 ACE_ERROR_RETURN ((LM_ERROR,
560 ACE_TEXT ("unlink failed for %p\n"),
561 file_addr.get_path_name ()),
563 #endif
565 #endif /* ACE_LACKS_IOSTREAM_TOTALLY */
567 // This message should show up in stderr and the ostream (without
568 // ACE_LACKS_IOSTREAM_TOTALLY).
569 ACE_DEBUG ((LM_DEBUG,
570 ACE_TEXT ("fifth message\n")));
572 return 0;
576 // For testing the format specifiers, a class is defined as a callback
577 // mechanism. It will get the formatted messages and check them for
578 // correctness. The test_format_specs() function will set the first
579 // few characters to say which test is being run, and the Log_Spec_Verify
580 // class will use that to decide how to verify the results.
582 class Log_Spec_Verify : public ACE_Log_Msg_Callback
584 public:
585 Log_Spec_Verify (bool be_recursive = true) : fail_ (0), tests_ (0), recursive_ (be_recursive) {};
587 /// Logging callback
588 void log (ACE_Log_Record &log_record) override;
590 int result ();
592 private:
593 /// Count how many tests failed.
594 int fail_;
596 /// Count how many tests we run
597 int tests_;
599 bool recursive_;
602 void
603 Log_Spec_Verify::log (ACE_Log_Record &log_record)
605 bool use_log_msg = false;
606 if (this->recursive_)
608 this->recursive_ = false;
609 use_log_msg = true;
612 if (!use_log_msg)
614 #if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
615 *ace_file_stream::instance ()->output_file ()
616 << "Logger callback = "
617 << log_record.msg_data ()
618 << endl;
619 #endif /* ACE_LACKS_IOSTREAM_TOTALLY */
621 else
623 const ACE_TCHAR *b = log_record.msg_data ();
624 const ACE_TCHAR *expect = 0;
626 ++this->tests_;
628 if (ACE_OS::strncmp (b, ACE_TEXT ("l1:"), 3) == 0)
630 expect = ACE_TEXT ("42");
631 b += 3;
633 else if (ACE_OS::strncmp (b, ACE_TEXT ("l2:"), 3) == 0)
635 expect = ACE_TEXT (" 42");
636 b += 3;
638 else if (ACE_OS::strncmp (b, ACE_TEXT ("l3N1:"), 4) == 0)
640 expect = ACE_TEXT ("0042,Log_Msg");
641 b += 5;
643 else if (ACE_OS::strncmp (b, ACE_TEXT ("l4:"), 3) == 0)
645 b += 3;
646 // Check if we have a string, exact length could vary
647 if (b != log_record.msg_data () && ACE_OS::strlen (b) < 15)
649 ACE_ERROR ((LM_ERROR, ACE_TEXT ("ERROR: Test %s failed; expected %d\n"),
650 log_record.msg_data (), ACE_OS::strlen (b)));
651 ++this->fail_;
654 else if (ACE_OS::strncmp (b, ACE_TEXT ("l5:"), 3) == 0)
656 b += 3;
657 switch (log_record.type())
659 case (LM_SHUTDOWN): expect = ACE_TEXT("S"); break;
660 case (LM_TRACE): expect = ACE_TEXT("T"); break;
661 case (LM_DEBUG): expect = ACE_TEXT("D"); break;
662 case (LM_INFO): expect = ACE_TEXT("I"); break;
663 case (LM_NOTICE): expect = ACE_TEXT("N"); break;
664 case (LM_WARNING): expect = ACE_TEXT("W"); break;
665 case (LM_STARTUP): expect = ACE_TEXT("U"); break;
666 case (LM_ERROR): expect = ACE_TEXT("E"); break;
667 case (LM_CRITICAL): expect = ACE_TEXT("C"); break;
668 case (LM_ALERT): expect = ACE_TEXT("A"); break;
669 case (LM_EMERGENCY): expect = ACE_TEXT("!"); break;
670 default: expect = ACE_TEXT("?"); break;
673 else if (ACE_OS::strncmp (b, ACE_TEXT ("l6:"), 3) == 0)
675 // After a l6 there shouldn't be a space
676 b += 1;
677 if (b != log_record.msg_data () && ACE_OS::strncmp (b, ACE_TEXT (" "), 1) == 0)
679 ACE_ERROR ((LM_ERROR, ACE_TEXT ("ERROR: Test %s failed; expected no space before the time\n"),
680 log_record.msg_data ()));
681 ++this->fail_;
684 else
686 ACE_ERROR ((LM_ERROR,
687 ACE_TEXT ("Log_Spec_Verify, unrecognized test: %s\n"),
688 b));
689 ++this->fail_;
692 if (b != log_record.msg_data () && expect && ACE_OS::strcmp (b, expect) != 0)
694 ACE_ERROR ((LM_ERROR, ACE_TEXT ("ERROR: Test %s failed; expected %s\n"),
695 log_record.msg_data (), expect));
696 ++this->fail_;
700 // Cleanup on the way out.
701 if (use_log_msg)
702 this->recursive_ = true;
706 Log_Spec_Verify::result ()
708 if (this->fail_ == 0)
709 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("All logging specifier tests passed.\n")));
710 else
711 ACE_ERROR ((LM_ERROR, ACE_TEXT ("%d logging specifier tests failed!\n"),
712 this->fail_));
714 if (this->tests_ != 19)
716 ACE_ERROR ((LM_ERROR, ACE_TEXT ("Expected number of tests run is %d, not 19!\n"),
717 this->tests_));
718 ++this->fail_;
720 return this->fail_;
723 static int
724 test_format_specs ()
726 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l1:%l\n")));
727 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l2:%5l\n")));
728 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l3N1:%0*l,%.7N\n"), 4));
729 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%*ISTART INDENTING %{\n"), 4));
730 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%IONE%{\n")));
731 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%ITWO%{\n")));
732 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%ITHREE%*Iwp == 1\n"), 1));
733 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%}%ITWO\n")));
734 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%}%IONE\n")));
735 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%}%IENDINDENTING\n")));
736 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%W\n"), ACE_TEXT_WIDE ("My string test\n")));
737 ACE_WCHAR_T *nill_string = 0;
738 char* char_nill_string = 0;
739 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%W\n"), nill_string));
740 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s\n"), nill_string));
741 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%C\n"), char_nill_string));
742 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%m %p\n"), nill_string));
743 errno = ENOENT;
744 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%m %p\n"), ACE_TEXT("perror")));
745 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%S\n"), SIGINT));
746 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%S\n"), ACE_NSIG));
747 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("thread id %t\n")));
749 Log_Spec_Verify verifier;
751 ACE_LOG_MSG->msg_callback (&verifier);
752 ACE_LOG_MSG->clr_flags (ACE_Log_Msg::VERBOSE_LITE);
753 ACE_LOG_MSG->clr_flags (ACE_Log_Msg::VERBOSE);
754 ACE_LOG_MSG->linenum (42);
755 ACE_LOG_MSG->file ("Log_Msg_Test.cpp");
757 #ifdef ACE_LACKS_VA_FUNCTIONS
758 #define LOG_ARGS
759 #else
760 #define LOG_ARGS(X) X
761 #endif
763 ACE_LOG_MSG->log LOG_ARGS ((LM_DEBUG, ACE_TEXT ("l1:%l")));
764 ACE_LOG_MSG->log LOG_ARGS ((LM_DEBUG, ACE_TEXT ("l2:%5l")));
765 ACE_LOG_MSG->log LOG_ARGS ((LM_DEBUG, ACE_TEXT ("l3N1:%0*l,%.7N"), 4));
766 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l4:%T")));
768 ACE_LOG_MSG->priority_mask (LM_SHUTDOWN |
769 LM_TRACE |
770 LM_DEBUG |
771 LM_INFO |
772 LM_NOTICE |
773 LM_WARNING |
774 LM_STARTUP |
775 LM_ERROR |
776 LM_CRITICAL |
777 LM_ALERT |
778 LM_EMERGENCY,
779 ACE_Log_Msg::PROCESS);
780 ACE_DEBUG ((LM_SHUTDOWN, ACE_TEXT ("l5:%.1M")));
781 ACE_DEBUG ((LM_TRACE, ACE_TEXT ("l5:%.1M")));
782 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l5:%.1M")));
783 ACE_DEBUG ((LM_INFO, ACE_TEXT ("l5:%.1M")));
784 ACE_DEBUG ((LM_NOTICE, ACE_TEXT ("l5:%.1M")));
785 ACE_DEBUG ((LM_WARNING, ACE_TEXT ("l5:%.1M")));
786 ACE_DEBUG ((LM_STARTUP, ACE_TEXT ("l5:%.1M")));
787 ACE_DEBUG ((LM_ERROR, ACE_TEXT ("l5:%.1M")));
788 ACE_DEBUG ((LM_CRITICAL, ACE_TEXT ("l5:%.1M")));
789 ACE_DEBUG ((LM_ALERT, ACE_TEXT ("l5:%.1M")));
790 ACE_DEBUG ((LM_EMERGENCY, ACE_TEXT ("l5:%.1M")));
792 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l6:%D\n")));
793 ACE_Time_Value tv = ACE_OS::gettimeofday ();
794 tv += ACE_Time_Value (25*60*60); // + 25 hours
795 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l6:%#D\n"), &tv));
797 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l6:%T\n")));
798 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l6:%#T\n"), &tv));
800 ACE_LOG_MSG->msg_ostream (ace_file_stream::instance ()->output_file ());
801 ACE_LOG_MSG->msg_callback (0);
802 ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
803 ACE_LOG_MSG->set_flags (ACE_Log_Msg::VERBOSE_LITE);
805 return verifier.result ();
808 // Main function.
811 run_main (int argc, ACE_TCHAR *argv[])
813 ACE_START_TEST (ACE_TEXT ("Log_Msg_Test"));
815 int status = 0;
817 ACE_DEBUG ((LM_DEBUG,
818 ACE_TEXT ("**** running ostream test\n")));
820 // Test the <ACE_Log_Msg> abstraction wrt writing to stderr and to a
821 // file.
822 test_ostream ();
824 ACE_DEBUG ((LM_DEBUG,
825 ACE_TEXT ("%M **** running callback test\n")));
827 // Test the <ACE_Log_Msg> callback mechanism.
828 test_callbacks ();
830 ACE_DEBUG ((LM_DEBUG,
831 ACE_TEXT ("**** running features test\n")));
833 // Test various features of the <ACE_Log_Msg>.
834 test_log_msg_features ((argc > 0 ? argv[0] : ACE_TEXT ("program")));
836 // Test the format specifiers
838 // Restore this mask so diags and the shutdown message will print correctly!
839 ACE_LOG_MSG->priority_mask (ACE_LOG_MSG->priority_mask () | LM_DEBUG | LM_ERROR,
840 ACE_Log_Msg::PROCESS);
842 ACE_DEBUG ((LM_DEBUG,
843 ACE_TEXT ("**** running format specifiers test\n")));
845 if (status += test_format_specs ())
847 ACE_ERROR ((LM_ERROR, ACE_TEXT ("logging specifier tests failed!\n")));
848 status = 1;
851 status += test_acelib_category();
853 ACE_END_TEST;
854 return status;