summaryrefslogtreecommitdiff
path: root/ACE/tests/Log_Msg_Test.cpp
blob: 8317b58de96c876986340ffb865176d0a9d80b74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
// $Id$

// ============================================================================
//
// = LIBRARY
//    tests
//
// = FILENAME
//    Log_Msg_Test.cpp
//
// = DESCRIPTION
//     This program tests the <ACE_Log_Msg> class in various ways and
//     also illustrates many of the features of the <ACE_Log_Msg> For
//     instance, this program tests the <ACE_Log_Msg> abstraction wrt
//     writing to stderr and to a file.  It also tests writing to user
//     defined callback objects.
//
// = AUTHOR
//    Douglas C. Schmidt <schmidt@cs.wustl.edu>
//
// ============================================================================

#include "test_config.h"

// FUZZ: disable check_for_streams_include
#include "ace/streams.h"

#include "ace/FILE_Connector.h"
#include "ace/Auto_Ptr.h"
#include "ace/Log_Msg_Callback.h"
#include "ace/Log_Record.h"
#include "ace/OS_NS_fcntl.h"
#include "ace/OS_NS_string.h"
#include "ace/OS_NS_unistd.h"
#include "ace/OS_Memory.h"
#include "ace/OS_NS_sys_time.h"
#include "ace/OS_NS_time.h"
#include "ace/Time_Value.h"

ACE_RCSID(tests, Log_Msg_Test, "$Id$")

static void
cleanup (void)
{
  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("cleanup hook (%P)!\n")));
}

static void
cause_error (void)
{
  errno = EWOULDBLOCK;
  ACE_ERROR ((LM_DEBUG,
              ACE_TEXT ("would block\n")));
}

class Logger : public ACE_Log_Msg_Callback
{
public:
  Logger (bool be_recursive = true);
  // Constructor sets whether we're testing "recursive" callback
  // logging!

  void log (ACE_Log_Record &log_record);
  // Logging callback

  void verbose (bool be_verbose);

private:
  bool verbose_logging_;
  // Flag for testing verbose logging.

  bool recursive_;
  // Flag for testing recursive callback logging.
};

void
Logger::verbose (bool be_verbose)
{
  this->verbose_logging_ = be_verbose;
}

Logger::Logger (bool be_recursive)
  : recursive_ (be_recursive)
{
}

void
Logger::log (ACE_Log_Record &log_record)
{
  bool use_log_msg = false;
  if (this->recursive_)
    {
      this->recursive_ = false;
      use_log_msg = true;
    }

  if (!this->verbose_logging_)
    {
      if (use_log_msg)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("Logger::log->%s\n"),
                    log_record.msg_data ()));
#if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
      else
        *ace_file_stream::instance ()->output_file ()
          << "Recursive Logger callback = "
          << log_record.msg_data ()
          << endl;
#endif /* ACE_LACKS_IOSTREAM_TOTALLY */
    }
  else
    {
      ACE_TCHAR verbose_msg[ACE_Log_Record::MAXVERBOSELOGMSGLEN];
      int result = log_record.format_msg (ACE_LOG_MSG->local_host (),
                                          ACE_LOG_MSG->flags (),
                                          verbose_msg);
      if (result == 0)
        {
          if (use_log_msg)
            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("Logger::log->%s\n"),
                        verbose_msg));
#if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
          else
            *ace_file_stream::instance ()->output_file ()
              << "Recursive Logger callback = "
              << log_record.msg_data ()
              << endl;
#endif /* ACE_LACKS_IOSTREAM_TOTALLY */
        }
    }

  // Cleanup on the way out.
  if (use_log_msg)
    this->recursive_ = true;
}

static void
test_callbacks (void)
{
  // This message should show up in stderr.
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t) first message\n")));

  ACE_LOG_MSG->clr_flags (ACE_Log_Msg::OSTREAM);

  // This message should not show up anywhere.
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t) second message\n")));

  ACE_LOG_MSG->set_flags (ACE_Log_Msg::MSG_CALLBACK);

  // This message should not show up anywhere since no callback object
  // has been specified.
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t) third message\n")));

  // Create a callback object and make it "verbose".
  Logger logger;
  logger.verbose (1);

  // Set the callback object.
  ACE_LOG_MSG->msg_callback (&logger);

  // This message should show up via the Logger callback.
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t) forth message\n")));

  ACE_LOG_MSG->set_flags (ACE_Log_Msg::VERBOSE_LITE);

  // This message should show up via the Logger callback (somewhat
  // verbosely).
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t) fifth message\n")));

  ACE_LOG_MSG->set_flags (ACE_Log_Msg::VERBOSE);

  // This message should show up via the Logger callback (really
  // verbosely).
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t) sixth message\n")));

  logger.verbose (0);

  // This message should show up via the Logger callback (not
  // verbosely).
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t) seventh message\n")));

  ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);

  // This message should show up in stderr and the Logger callback.
  // The one from the Logger callback will not be verbose, but the one
  // from stderr should be verbose.
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%t) eighth message\n")));
  ACE_LOG_MSG->msg_callback (0);
}

static void
test_log_msg_features (const ACE_TCHAR *program)
{
  // Note that the default behavior is to log to STDERR...

  int counter = 1 ;

  if (ACE_LOG_MSG->open (program) == -1)
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("cannot open logger!!!\n")));

  cause_error ();

  // Check to see what happened.
  if (ACE_LOG_MSG->op_status () == -1
      && ACE_LOG_MSG->errnum () == EWOULDBLOCK)
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("op_status and errnum work!\n")));
  else
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("op_status and errnum failed!\n")));

  const char *badname = "badname";

  // We use the DEBUG messages instead of error messages. This is to
  // help the scripts. If we print out error messages the scripts
  // start catching them as errors.
  if (ACE_OS::open (badname,
                    O_RDONLY) == ACE_INVALID_HANDLE)
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("%n: (%x), can't open %C%r\n"),
                10000,
                badname,
                cleanup));

  // Try a log operation that would overflow the logging buffer if not
  // properly guarded.
  ACE_TCHAR big[ACE_Log_Record::MAXLOGMSGLEN + 1];
  size_t i = 0;
  static const ACE_TCHAR alphabet[] = ACE_TEXT ("abcdefghijklmnopqrstuvwxyz");
  size_t j = ACE_OS::strlen (alphabet);
  while (i < ACE_Log_Record::MAXLOGMSGLEN)
    {
      size_t const index = i++;
      big[index] = alphabet[i % j];
    }
  big[ACE_Log_Record::MAXLOGMSGLEN] = ACE_TEXT ('\0');
  ACE_DEBUG ((LM_INFO, ACE_TEXT ("This is too big: %s\n"), big));

  // Exercise many different combinations of OSTREAM.

  double f = 3.1416 * counter++;
  int n = 10000;

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("%10f, %*s%s = %d\n"),
              f,
              8,
              ACE_TEXT (""),
              ACE_TEXT ("hello"),
              n));

  ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
  ACE_LOG_MSG->msg_ostream (ace_file_stream::instance ()->output_file ());

  f = 3.1416 * counter;
  n = 10000 * counter++;

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("%10f, %*s%s = %d\n"),
              f,
              8,
              ACE_TEXT (""),
              ACE_TEXT ("world"),
              n));

  ACE_LOG_MSG->clr_flags (ACE_Log_Msg::OSTREAM);

  // The next two messages shouldn't print.

  f = 3.1416 * counter;
  n = 10000 * counter++;

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("%10f, %*s%s = %d\n"),
              f,
              8,
              ACE_TEXT (""),
              ACE_TEXT ("world"),
              n));

  f = 3.1416 * counter;
  n = 10000 * counter++;

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("%10f, %*s%s = %d\n"),
              f,
              8,
              ACE_TEXT (""),
              ACE_TEXT ("world"),
              n));

  ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);

  f = 3.1416 * counter;
  n = 10000 * counter++;

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("%10f, %*s%s = %d\n"),
              f,
              8,
              ACE_TEXT (""),
              ACE_TEXT ("world"),
              n));

  static int array[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048};

  // Print out the binary bytes of the array in hex form.
  ACE_LOG_MSG->log_hexdump (LM_DEBUG,
                            (char *) array,
                            sizeof array);

  // Disable the LM_DEBUG and LM_INFO messages.
  u_long priority_mask =
    ACE_LOG_MSG->priority_mask (ACE_Log_Msg::PROCESS);
  ACE_CLR_BITS (priority_mask,
                LM_DEBUG | LM_INFO);
  ACE_LOG_MSG->priority_mask (priority_mask,
                              ACE_Log_Msg::PROCESS);

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("This LM_INFO message should not print!\n")));
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("This LM_DEBUG message should not print!\n")));

  ACE_SET_BITS (priority_mask,
                LM_INFO);
  ACE_LOG_MSG->priority_mask (priority_mask,
                              ACE_Log_Msg::PROCESS);

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("This LM_INFO message should print!\n")));
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("This LM_DEBUG message should not print!\n")));

  ACE_CLR_BITS (priority_mask, LM_INFO);
  ACE_LOG_MSG->priority_mask (priority_mask,
                              ACE_Log_Msg::PROCESS);

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("This LM_INFO message should not print!\n")));
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("This LM_DEBUG message should not print!\n")));
}

static int
test_ostream (void)
{
  // This message should show up in the log file.
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("first message\n")));

  ACE_LOG_MSG->clr_flags (ACE_Log_Msg::OSTREAM);

  // This message should not show up anywhere.
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("second message\n")));

  ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);

#if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
  // Create a persistent store.
  const ACE_TCHAR *filename = ACE_TEXT ("output");
  ofstream myostream (ACE_TEXT_ALWAYS_CHAR (filename), ios::out | ios::trunc);

  // Check for errors.
  if (myostream.bad ())
    return -1;

  OFSTREAM *old_stream = ace_file_stream::instance ()->output_file ();
  // Set the ostream.
  ACE_LOG_MSG->msg_ostream (&myostream);

  // This message should show up in the ostream.
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("fourth message\n")));
  // Set the ostream back to the test's log file.
  ACE_LOG_MSG->msg_ostream (old_stream);
  // Now close the ostream file and check its contents.
  myostream.close ();

  ACE_FILE_Connector connector;
  ACE_FILE_IO file;
  ACE_FILE_Addr file_addr (filename);

  // Open up the file.
  if (connector.connect (file, file_addr) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("connect failed for %p\n"),
                         filename),
                        1);
    }

#if !defined (ACE_VXWORKS) && !defined (ACE_HAS_PHARLAP) || (defined(ACE_VXWORKS) && (ACE_VXWORKS > 0x680))
# define TEST_CAN_UNLINK_IN_ADVANCE
#endif

#if defined (TEST_CAN_UNLINK_IN_ADVANCE)
  // Unlink this file right away so that it is automatically removed
  // when the process exits.Ignore error returns in case this operation
  // is not supported.
  ACE_OS::unlink(filename);
#endif

  ACE_FILE_Info info;
  if (file.get_info (info) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("get_info failed on %p\n"),
                         filename),
                        -1);
    }

  // Allocate the input buffer
  char *buffer = 0;
  ACE_NEW_RETURN (buffer,
                  char[info.size_ + 1],
                  -1);
  // Make sure <buffer> is released automagically.
  ACE_Auto_Basic_Array_Ptr<char> b (buffer);

  // Read the file into the buffer.
  ssize_t size = file.recv (buffer,
                            info.size_);
  if (size != info.size_)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("Read %d bytes, rather than expected %d bytes\n"),
                         size,
                         info.size_),
                        -1);
    }
  // Make sure to NUL-terminate this turkey!
  buffer[size] = '\0';


  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("%C"),
              buffer));

#if !defined (TEST_CAN_UNLINK_IN_ADVANCE)
  file.close ();
  if (file.unlink () == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("unlink failed for %p\n"),
                       file_addr.get_path_name ()),
                       1);
#endif

#endif /* ACE_LACKS_IOSTREAM_TOTALLY */

  // This message should show up in stderr and the ostream (without
  // ACE_LACKS_IOSTREAM_TOTALLY).
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("fifth message\n")));

  return 0;
}


// For testing the format specifiers, a class is defined as a callback
// mechanism. It will get the formatted messages and check them for
// correctness. The test_format_specs() function will set the first
// few characters to say which test is being run, and the Log_Spec_Verify
// class will use that to decide how to verify the results.

class Log_Spec_Verify : public ACE_Log_Msg_Callback
{
public:
  Log_Spec_Verify (bool be_recursive = true) : fail_ (0), tests_ (0), recursive_ (be_recursive) {};

  void log (ACE_Log_Record &log_record);
  // Logging callback

  int  result ();

private:
  int fail_;
  // Count how many tests failed.

  int tests_;
  // Count how many tests we run

  bool recursive_;
};

void
Log_Spec_Verify::log (ACE_Log_Record &log_record)
{
  bool use_log_msg = false;
  if (this->recursive_)
    {
      this->recursive_ = false;
      use_log_msg = true;
    }

  if (!use_log_msg)
    {
#if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
      *ace_file_stream::instance ()->output_file ()
        << "Logger callback = "
        << log_record.msg_data ()
        << endl;
#endif /* ACE_LACKS_IOSTREAM_TOTALLY */
    }
  else
    {
      const ACE_TCHAR *b = log_record.msg_data ();
      const ACE_TCHAR *expect = 0;

      ++this->tests_;

      if (ACE_OS::strncmp (b, ACE_TEXT ("l1:"), 3) == 0)
        {
          expect = ACE_TEXT ("42");
          b += 3;
        }
      else if (ACE_OS::strncmp (b, ACE_TEXT ("l2:"), 3) == 0)
        {
          expect = ACE_TEXT ("   42");
          b += 3;
        }
      else if (ACE_OS::strncmp (b, ACE_TEXT ("l3N1:"), 4) == 0)
        {
          expect = ACE_TEXT ("0042,Log_Msg");
          b += 5;
        }
      else if (ACE_OS::strncmp (b, ACE_TEXT ("l4:"), 3) == 0)
        {
          b += 3;
          // Check if we have a string, exact length could vary
          if (b != log_record.msg_data () && ACE_OS::strlen (b) < 15)
            {
              ACE_ERROR ((LM_ERROR, ACE_TEXT ("Test %s failed; expected %d\n"),
                          log_record.msg_data (), ACE_OS::strlen (b)));
              ++this->fail_;
            }
        }
        else if (ACE_OS::strncmp (b, ACE_TEXT ("l5:"), 3) == 0)
        {
          b += 3;          
          switch (log_record.type())
          {
            case (LM_SHUTDOWN): expect = ACE_TEXT("S"); break;
            case (LM_TRACE): expect = ACE_TEXT("T"); break;
            case (LM_DEBUG): expect = ACE_TEXT("D"); break;
            case (LM_INFO): expect = ACE_TEXT("I"); break;
            case (LM_NOTICE): expect = ACE_TEXT("N"); break;
            case (LM_WARNING): expect = ACE_TEXT("W"); break;
            case (LM_STARTUP): expect = ACE_TEXT("U"); break;
            case (LM_ERROR): expect = ACE_TEXT("E"); break;
            case (LM_CRITICAL): expect = ACE_TEXT("C"); break;
            case (LM_ALERT): expect = ACE_TEXT("A"); break;
            case (LM_EMERGENCY): expect = ACE_TEXT("!"); break;
            default: expect = ACE_TEXT("?"); break;
          }
          
        }
      else
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("Log_Spec_Verify, unrecognized test: %s\n"),
                      b));
          ++this->fail_;
        }

      if (b != log_record.msg_data () && expect && ACE_OS::strcmp (b, expect) != 0)
        {
          ACE_ERROR ((LM_ERROR, ACE_TEXT ("Test %s failed; expected %s\n"),
                      log_record.msg_data (), expect));
          ++this->fail_;
        }
    }

  // Cleanup on the way out.
  if (use_log_msg)
    this->recursive_ = true;
}

int
Log_Spec_Verify::result (void)
{
  if (this->fail_ == 0)
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("All logging specifier tests passed.\n")));
  else
    ACE_ERROR ((LM_ERROR, ACE_TEXT ("%d logging specifier tests failed!\n"),
                this->fail_));

  if (this->tests_ != 15)
  {
    ACE_ERROR ((LM_ERROR, ACE_TEXT ("Expected number of tests run is %d, not 15!\n"),
                this->tests_));
    ++this->fail_;
  }
  return this->fail_;
}

static int
test_format_specs (void)
{
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l1:%l\n")));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l2:%5l\n")));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l3N1:%0*l,%.7N\n"), 4));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%*ISTART INDENTING %{\n"), 4));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%IONE%{\n")));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%ITWO%{\n")));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%ITHREE\n")));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%}%ITWO\n")));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%}%IONE\n")));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%}%IENDINDENTING\n")));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%W\n"), ACE_TEXT_WIDE ("My string test\n")));
  ACE_TCHAR* nill_string = 0;
  char* char_nill_string = 0;
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%W\n"), nill_string));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%s\n"), nill_string));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%C\n"), char_nill_string));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%m %p\n"), nill_string));
  errno = ENOENT;
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%m %p\n"), ACE_TEXT("perror")));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%S\n"), SIGINT));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%S\n"), ACE_NSIG));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%D\n")));
  ACE_Time_Value tv = ACE_OS::gettimeofday ();
  tv += ACE_Time_Value (25*60*60); // + 25 hours
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%#D\n"), &tv));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%T\n")));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%#T\n"), &tv));

  Log_Spec_Verify  verifier;

  ACE_LOG_MSG->msg_callback (&verifier);
  ACE_LOG_MSG->clr_flags (ACE_Log_Msg::VERBOSE_LITE);
  ACE_LOG_MSG->clr_flags (ACE_Log_Msg::VERBOSE);
  ACE_LOG_MSG->linenum (42);
  ACE_LOG_MSG->file ("Log_Msg_Test.cpp");

  ACE_LOG_MSG->log (LM_DEBUG, ACE_TEXT ("l1:%l"));
  ACE_LOG_MSG->log (LM_DEBUG, ACE_TEXT ("l2:%5l"));
  ACE_LOG_MSG->log (LM_DEBUG, ACE_TEXT ("l3N1:%0*l,%.7N"), 4);
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l4:%T")));  

  ACE_LOG_MSG->priority_mask (LM_SHUTDOWN | 
                              LM_TRACE | 
                              LM_DEBUG | 
                              LM_INFO | 
                              LM_NOTICE | 
                              LM_WARNING | 
                              LM_STARTUP | 
                              LM_ERROR | 
                              LM_CRITICAL | 
                              LM_ALERT | 
                              LM_EMERGENCY,
                              ACE_Log_Msg::PROCESS);
  ACE_DEBUG ((LM_SHUTDOWN, ACE_TEXT ("l5:%.1M")));  
  ACE_DEBUG ((LM_TRACE, ACE_TEXT ("l5:%.1M")));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("l5:%.1M")));
  ACE_DEBUG ((LM_INFO, ACE_TEXT ("l5:%.1M")));
  ACE_DEBUG ((LM_NOTICE, ACE_TEXT ("l5:%.1M")));
  ACE_DEBUG ((LM_WARNING, ACE_TEXT ("l5:%.1M")));
  ACE_DEBUG ((LM_STARTUP, ACE_TEXT ("l5:%.1M")));
  ACE_DEBUG ((LM_ERROR, ACE_TEXT ("l5:%.1M")));
  ACE_DEBUG ((LM_CRITICAL, ACE_TEXT ("l5:%.1M")));
  ACE_DEBUG ((LM_ALERT, ACE_TEXT ("l5:%.1M")));
  ACE_DEBUG ((LM_EMERGENCY, ACE_TEXT ("l5:%.1M")));
  
  ACE_LOG_MSG->msg_ostream (ace_file_stream::instance ()->output_file ());
  ACE_LOG_MSG->msg_callback (0);
  ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
  ACE_LOG_MSG->set_flags (ACE_Log_Msg::VERBOSE_LITE);

  return verifier.result ();
}

// Main function.

int
run_main (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("Log_Msg_Test"));

  int status = 0;

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("**** running ostream test\n")));

  // Test the <ACE_Log_Msg> abstraction wrt writing to stderr and to a
  // file.
  test_ostream ();

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("%M **** running callback test\n")));

  // Test the <ACE_Log_Msg> callback mechanism.
  test_callbacks ();

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("**** running features test\n")));

  // Test various features of the <ACE_Log_Msg>.
  test_log_msg_features ((argc > 0 ? argv[0] : ACE_TEXT ("program")));

  // Test the format specifiers

  // Restore this mask so diags and the shutdown message will print correctly!
  ACE_LOG_MSG->priority_mask (ACE_LOG_MSG->priority_mask () | LM_DEBUG | LM_ERROR,
                              ACE_Log_Msg::PROCESS);

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("**** running format specifiers test\n")));

  if (status += test_format_specs ())
    {
      ACE_ERROR ((LM_ERROR, ACE_TEXT ("logging specifier tests failed!\n")));
      status = 1;
    }

  ACE_END_TEST;
  return status;
}