Example #1
0
void Test2()
{
  char tempstr[2048];
  int  n1, n2;

  /*
   * Set up for tests that will verify what was actually produced by log messages.
   * This is used to test log levels and to test the log_vnsprintf function.
   */
  SetComponentLogBuffer(COMPONENT_MAIN, tempstr);
  SetComponentLogBuffer(COMPONENT_INIT, tempstr);
  SetComponentLogLevel(COMPONENT_MAIN, NIV_EVENT);

  LogTest("------------------------------------------------------");
  LogTest("Test string/char formats");
  TestFormat("none");
  TestFormat("String: %s", "str");
  TestFormat("String: %12s", "str");
  TestFormat("String: %-12s", "str");
  TestFormat("String: %12s", "too long string");
  TestFormat("String: %-12s", "too long string");
  TestFormat("%c", (char) 65);
  // Not tested lc, ls, C, S

  LogTest("------------------------------------------------------");
  LogTest("Test integer formats");
  TestFormat("Integer: %d %d %i %i %u %s", 1, -1, 2, -2, 3, "extra");
  TestFormat("Octal and Hex: 0%o 0x%x 0x%X %s", 0123, 0xabcdef, 0xABCDEF, "extra");
  TestFormat("Field Length: %3d %s", 1, "extra");
  TestFormat("Variable Field Length: %*d %s", 5, 123, "extra");
  TestFormat("Alignment flags: %+d %+d %-5d %-5d %05d %05d % d % d %s", 2, -2, 333, -333, 444, -444, 5, -5, "extra");
  TestFormat("Two Flags: %-05d %-05d %0-5d %0-5d %s", 333, -333, 444, -444, "extra");
  TestFormat("Two Flags: %+ d %+ d % +d % +d %s", 333, -333, 444, -444, "extra");
  TestFormat("Two Flags: %-+5d %-+5d %+-5d %+-5d %s", 333, -333, 444, -444, "extra");
  TestFormat("Two Flags: %- 5d %- 5d % -5d % -5d %s", 333, -333, 444, -444, "extra");
  TestFormat("Two Flags: %+05d %+05d %0+5d %0+5d %s", 333, -333, 444, -444, "extra");
  TestFormat("Two Flags: % 05d % 05d %0 5d %0 5d %s", 333, -333, 444, -444, "extra");
  TestFormat("Use of # Flag: %#x %#3x %#05x %#-5x %-#5x %0#5x", 1, 2, 3, 4, 5, 6);
  TestFormat("Many Flags: %#-0 +#-0 +#-0 +5d", 4);
  TestFormat("Special Flags (may not be supported) %'d %Id %s", 12345, 67, "extra");

  LogTest("------------------------------------------------------");
  LogTest("Test floating point formats");
  TestFormat("%e %E %e %E %s", 1.1, 1.1, 1.1E10, 1.1E10, "extra");
  TestFormat("%f %F %f %F %s", 1.1, 1.1, 1.1E10, 1.1E10, "extra");
  TestFormat("%g %G %g %G %s", 1.1, 1.1, 1.1E10, 1.1E10, "extra");
  TestFormat("%a %A %a %A %s", 1.1, 1.1, 1.1E10, 1.1E10, "extra");
  TestFormat("%Le %LE %Le %LE %s", (long double) 1.1, (long double) 1.1, (long double) 1.1E10, (long double) 1.1E10, "extra");
  TestFormat("%Lf %LF %Lf %LF %s", (long double) 1.1, (long double) 1.1, (long double) 1.1E10, (long double) 1.1E10, "extra");
  TestFormat("%Lg %LG %Lg %LG %s", (long double) 1.1, (long double) 1.1, (long double) 1.1E10, (long double) 1.1E10, "extra");
  TestFormat("%La %LA %La %LA %s", (long double) 1.1, (long double) 1.1, (long double) 1.1E10, (long double) 1.1E10, "extra");
  TestFormat("%lle %llE %lle %llE %s", (long double) 1.1, (long double) 1.1, (long double) 1.1E10, (long double) 1.1E10, "extra");
  TestFormat("%llf %llF %llf %llf %s", (long double) 1.1, (long double) 1.1, (long double) 1.1E10, (long double) 1.1E10, "extra");
  TestFormat("%llg %llG %llg %llG %s", (long double) 1.1, (long double) 1.1, (long double) 1.1E10, (long double) 1.1E10, "extra");
  TestFormat("%lla %llA %lla %llA %s", (long double) 1.1, (long double) 1.1, (long double) 1.1E10, (long double) 1.1E10, "extra");
  TestFormat("Field Length: %8f %8.2f %8f %8.2f %s", 1.1, 1.1, 1.1E10, 1.1E3, "extra");
  TestFormat("Field Length: %08f %08.2f %08f %08.2f %s", 1.1, 1.1, 1.1E10, 1.1E3, "extra");
  TestFormat("Field Length: %-8f %-8.2f %-8f %-8.2f %s", 1.1, 1.1, 1.1E10, 1.1E3, "extra");
  TestFormat("Variable Field Length: %*.*f %*.2f %6.*f %s", 6, 2, 1.1, 6, 2.2, 2, 3.3, "extra");
  TestFormat("Negative:      %e %E %e %E %s    ", -1.1, -1.1, -1.1E10, -1.1E10, "extra");
  TestFormat("With '+' flag: %+e %+E %+e %+E %s", 1.1, 1.1, 1.1E10, 1.1E10, "extra");
  TestFormat("With ' ' flag: % e % E % e % E %s", 1.1, 1.1, 1.1E10, 1.1E10, "extra");
  TestFormat("With '#' flag: %#8.0e %8.0e %s", 1.0, 1.0, "extra");
  TestFormat("With '#' flag: %#g %g %#5g %#5g %5g %s", 1.0, 1.0, 2.0, 10.0, 2.0, "extra");

  LogTest("------------------------------------------------------");
  LogTest("Test some special formats");
  TestFormat("pointer: %p %s", &n1, "extra");
#if 0
// we can't support %n due to security considerations
  TestFormat("count: 12345678%n %s", &n1, "extra");
  snprintf(tempstr, 2048, "count: 12345678%n %s", &n1, "extra");
  log_snprintf(tempstr, 2048, "count: 12345678%n %s", &n2, "extra");
  if (n1 != n2)
    {
      LogTest("FAILURE: 12345678%%n produced %d expected %d", n2, n1);
      exit(1);
    }
  LogTest("SUCCESS: 12345678%%n produced %d", n2);
#endif
  errno = EIO;
  TestFormat("strerror: %m %64m %s", "extra");
  TestFormat("percent char: %% %s", "extra");

  LogTest("------------------------------------------------------");
  LogTest("Test integer size qualifier tags");
  TestFormat("%hhd %s", (char) 1, "extra");
  TestFormat("%hd %s", (short) 500, "extra");
  TestFormat("%lld %s", (long long) 12345678, "extra");
  TestFormat("%Ld %s", (long long) 12345678, "extra");
  TestFormat("%ld %s", (long) 12345, "extra");
  TestFormat("%qd %s", (long long) 12345678, "extra");
  TestFormat("%jd %s", (long long) 1, "extra");
  TestFormat("%td %s", (char *) &n1 - (char *) &n2, "extra");
  TestFormat("%zd %s", sizeof(int), "extra");

  /*
   * Ganesha can't properly support the $ parameter index tag, so don't bother testing, even if it does work
   * when the indices are in ascending order.
  TestFormat("%1$08x", 6);
  TestFormat("%3$llx %2$d %1d", 1, 2, (long long)0x12345678);
   */

  LogTest("------------------------------------------------------");
  LogTest("Ganesha specific tags");
  LogTest("\nTest %%b, %%B, %%h, %%H, %%y, and %%Y. These are odd tags:");
  LogTest("   %%b, %%B, %%h, and %%H each consume int1, str2, str3 even if not all are printed");
  LogTest("   %%y and %%Y each consume int1, str2, str3, int4, str5, str6 even if not all are printed");
  LogTest("   An extra string parameter is printed to demonstrate how the parameters are consumed");
  TestGaneshaFormat(TRUE,  "str2(1) (not part of %b)", "%b %s", 1, "str2", "str3", "(not part of %b)");
  TestGaneshaFormat(TRUE,  "str2(1) : 'str3' (not part of %B)", "%B %s", 1, "str2", "str3", "(not part of %B)");
  TestGaneshaFormat(TRUE,  "str2(1) (not part of %h)", "%h %s", 1, "str2", "str3", "(not part of %h)");
  TestGaneshaFormat(TRUE,  "str2(1) : 'str3' (not part of %H)", "%H %s", 1, "str2", "str3", "(not part of %H)");
  TestGaneshaFormat(TRUE,  "str2 str5(4) (not part of %y)", "%y %s", 1, "str2", "str3", 4, "str5", "str6", "(not part of %y)");
  TestGaneshaFormat(TRUE,  "str2(1) : 'str3' -> str5(4) : 'str6' (not part of %Y)", "%Y %s", 1, "str2", "str3", 4, "str5", "str6", "(not part of %Y)");
  LogTest("\nTest new tags for reporting errno values");
  TestGaneshaFormat(TRUE,  "EINVAL(22)", "%w", EINVAL);
  TestGaneshaFormat(TRUE,  "EINVAL(22) : 'Invalid argument'", "%W", EINVAL);
  LogTest("\nTest context sensitive tags");
  LogTest("%%K, %%V, and %%v go together, defaulting to ERR_SYS");
  LogTest("%%J, %%R, and %%r go together, defaulting to ERR_POSIX");
  TestGaneshaFormat(TRUE,  "ERR_SIGACTION(5) : 'sigaction impossible' EINVAL(22) : 'Invalid argument'", "%K%V %K%V", ERR_SYS, ERR_SIGACTION, ERR_POSIX, EINVAL);
  TestGaneshaFormat(TRUE,  "ERR_SIGACTION(5) EINVAL(22)", "%K%v %K%v", ERR_SYS, ERR_SIGACTION, ERR_POSIX, EINVAL);
  TestGaneshaFormat(TRUE,  "ERR_SIGACTION(5) : 'sigaction impossible' EINVAL(22) : 'Invalid argument'", "%J%R %J%R", ERR_SYS, ERR_SIGACTION, ERR_POSIX, EINVAL);
  TestGaneshaFormat(TRUE,  "ERR_SIGACTION(5) EINVAL(22)", "%J%r %J%r", ERR_SYS, ERR_SIGACTION, ERR_POSIX, EINVAL);
  TestGaneshaFormat(TRUE,  "ERR_SIGACTION(5) : 'sigaction impossible' EINVAL(22) : 'Invalid argument'", "%V %R", ERR_SIGACTION, EINVAL);
  TestGaneshaFormat(TRUE,  "ERR_SIGACTION(5) EINVAL(22)", "%v %r", ERR_SIGACTION, EINVAL);
  LogTest("Ganesha expects it's tags to just be two characters, for example %%b");
  TestGaneshaFormat(FALSE, "str2(1) (not part of %b)", "%5b %s", 1, "str2", "str3", "(not part of %b)");
}
void Test2()
{
  char tempstr[2048];
  int  n1, n2;

  /*
   * Set up for tests that will verify what was actually produced by log messages.
   * This is used to test log levels and to test the log_vnsprintf function.
   */
  SetComponentLogBuffer(COMPONENT_MAIN, tempstr);
  SetComponentLogBuffer(COMPONENT_INIT, tempstr);
  SetComponentLogLevel(COMPONENT_MAIN, NIV_EVENT);

  LogTest("------------------------------------------------------");
  LogTest("Test string/char formats");
  TestFormat("none");
  TestFormat("String: %s", "str");
  TestFormat("String: %12s", "str");
  TestFormat("String: %-12s", "str");
  TestFormat("String: %12s", "too long string");
  TestFormat("String: %-12s", "too long string");
  TestFormat("%c", (char) 65);
  // Not tested lc, ls, C, S

  LogTest("------------------------------------------------------");
  LogTest("Test integer formats");
  TestFormat("Integer: %d %d %i %i %u %s", 1, -1, 2, -2, 3, "extra");
  TestFormat("Octal and Hex: 0%o 0x%x 0x%X %s", 0123, 0xabcdef, 0xABCDEF, "extra");
  TestFormat("Field Length: %3d %s", 1, "extra");
  TestFormat("Variable Field Length: %*d %s", 5, 123, "extra");
  TestFormat("Alignment flags: %+d %+d %-5d %-5d %05d %05d % d % d %s", 2, -2, 333, -333, 444, -444, 5, -5, "extra");
  // TestFormat("Two Flags: %-05d %-05d %0-5d %0-5d %s", 333, -333, 444, -444, "extra");
  // TestFormat("Two Flags: %+ d %+ d % +d % +d %s", 333, -333, 444, -444, "extra");
  TestFormat("Two Flags: %-+5d %-+5d %+-5d %+-5d %s", 333, -333, 444, -444, "extra");
  TestFormat("Two Flags: %- 5d %- 5d % -5d % -5d %s", 333, -333, 444, -444, "extra");
  TestFormat("Two Flags: %+05d %+05d %0+5d %0+5d %s", 333, -333, 444, -444, "extra");
  TestFormat("Two Flags: % 05d % 05d %0 5d %0 5d %s", 333, -333, 444, -444, "extra");
  TestFormat("Use of # Flag: %#x %#3x %#05x %#-5x %-#5x %0#5x", 1, 2, 3, 4, 5, 6);
  // TestFormat("Many Flags: %#-0 +#-0 +#-0 +5d", 4);
  TestFormat("Special Flags (may not be supported) %'d %Id %s", 12345, 67, "extra");

  LogTest("------------------------------------------------------");
  LogTest("Test floating point formats");
  TestFormat("%e %E %e %E %s", 1.1, 1.1, 1.1E10, 1.1E10, "extra");
  TestFormat("%f %F %f %F %s", 1.1, 1.1, 1.1E10, 1.1E10, "extra");
  TestFormat("%g %G %g %G %s", 1.1, 1.1, 1.1E10, 1.1E10, "extra");
  TestFormat("%a %A %a %A %s", 1.1, 1.1, 1.1E10, 1.1E10, "extra");
  TestFormat("%Le %LE %Le %LE %s", (long double) 1.1, (long double) 1.1, (long double) 1.1E10, (long double) 1.1E10, "extra");
  TestFormat("%Lf %LF %Lf %LF %s", (long double) 1.1, (long double) 1.1, (long double) 1.1E10, (long double) 1.1E10, "extra");
  TestFormat("%Lg %LG %Lg %LG %s", (long double) 1.1, (long double) 1.1, (long double) 1.1E10, (long double) 1.1E10, "extra");
  TestFormat("%La %LA %La %LA %s", (long double) 1.1, (long double) 1.1, (long double) 1.1E10, (long double) 1.1E10, "extra");
  TestFormat("%lle %llE %lle %llE %s", (long double) 1.1, (long double) 1.1, (long double) 1.1E10, (long double) 1.1E10, "extra");
  TestFormat("%llf %llF %llf %llf %s", (long double) 1.1, (long double) 1.1, (long double) 1.1E10, (long double) 1.1E10, "extra");
  TestFormat("%llg %llG %llg %llG %s", (long double) 1.1, (long double) 1.1, (long double) 1.1E10, (long double) 1.1E10, "extra");
  TestFormat("%lla %llA %lla %llA %s", (long double) 1.1, (long double) 1.1, (long double) 1.1E10, (long double) 1.1E10, "extra");
  TestFormat("Field Length: %8f %8.2f %8f %8.2f %s", 1.1, 1.1, 1.1E10, 1.1E3, "extra");
  TestFormat("Field Length: %08f %08.2f %08f %08.2f %s", 1.1, 1.1, 1.1E10, 1.1E3, "extra");
  TestFormat("Field Length: %-8f %-8.2f %-8f %-8.2f %s", 1.1, 1.1, 1.1E10, 1.1E3, "extra");
  TestFormat("Variable Field Length: %*.*f %*.2f %6.*f %s", 6, 2, 1.1, 6, 2.2, 2, 3.3, "extra");
  TestFormat("Negative:      %e %E %e %E %s    ", -1.1, -1.1, -1.1E10, -1.1E10, "extra");
  TestFormat("With '+' flag: %+e %+E %+e %+E %s", 1.1, 1.1, 1.1E10, 1.1E10, "extra");
  TestFormat("With ' ' flag: % e % E % e % E %s", 1.1, 1.1, 1.1E10, 1.1E10, "extra");
  TestFormat("With '#' flag: %#8.0e %8.0e %s", 1.0, 1.0, "extra");
  TestFormat("With '#' flag: %#g %g %#5g %#5g %5g %s", 1.0, 1.0, 2.0, 10.0, 2.0, "extra");

  LogTest("------------------------------------------------------");
  LogTest("Test some special formats");
  TestFormat("pointer: %p %s", &n1, "extra");
#if 0
// we can't support %n due to security considerations
  TestFormat("count: 12345678%n %s", &n1, "extra");
  snprintf(tempstr, 2048, "count: 12345678%n %s", &n1, "extra");
  log_snprintf(tempstr, 2048, "count: 12345678%n %s", &n2, "extra");
  if (n1 != n2)
    {
      LogTest("FAILURE: 12345678%%n produced %d expected %d", n2, n1);
      exit(1);
    }
  LogTest("SUCCESS: 12345678%%n produced %d", n2);
#endif
  errno = EIO;
  TestFormat("strerror: %m %64m %s", "extra");
  TestFormat("percent char: %% %s", "extra");

  LogTest("------------------------------------------------------");
  LogTest("Test integer size qualifier tags");
  TestFormat("%hhd %s", (char) 1, "extra");
  TestFormat("%hd %s", (short) 500, "extra");
  TestFormat("%lld %s", (long long) 12345678, "extra");
  TestFormat("%Ld %s", (long long) 12345678, "extra");
  TestFormat("%ld %s", (long) 12345, "extra");
  TestFormat("%qd %s", (long long) 12345678, "extra");
  TestFormat("%jd %s", (long long) 1, "extra");
  TestFormat("%td %s", (char *) &n1 - (char *) &n2, "extra");
  TestFormat("%zd %s", sizeof(int), "extra");

  /*
   * Ganesha can't properly support the $ parameter index tag, so don't bother testing, even if it does work
   * when the indices are in ascending order.
  TestFormat("%1$08x", 6);
  TestFormat("%3$llx %2$d %1d", 1, 2, (long long)0x12345678);
   */

}
Example #3
0
/**
 *  Tests about Log streams and special printf functions.
 */
int Test1(char *str, char *file)
{
  char tempstr[2048];
  int  i;

  SetComponentLogFile(COMPONENT_INIT, "STDOUT");
  LogAlways(COMPONENT_INIT, "%s", "Starting Log Tests");
  LogTest("My PID = %d", getpid());

  LogTest("------------------------------------------------------");

  LogTest("Test ERR_DUMMY");
  LogTest("A numerical error : error %%d = %%J%%R, in ERR_DUMMY_2 %%J%%R");
  log_snprintf(tempstr, sizeof(tempstr),
               "A numerical error : error %d = %J%R, in ERR_DUMMY_2 %J%R",
               ERR_SIGACTION, ERR_SYS, ERR_SIGACTION, ERR_DUMMY, ERR_DUMMY_2);
  LogTest("%s", tempstr);
  LogTest("A numerical error : error %d = %J%R, in ERR_DUMMY_1 %J%R",
          ERR_OPEN, ERR_SYS, ERR_OPEN, ERR_DUMMY, ERR_DUMMY_1);

  LogTest("------------------------------------------------------");
  LogTest("Test conversion of log levels between string and integer");
  for (i = NIV_NULL; i < NB_LOG_LEVEL; i++)
    {
      int j;
      if (strcmp(tabLogLevel[i].str, ReturnLevelInt(i)) != 0)
        {
          LogTest("FAILURE: Log level %d did not convert to %s, it converted to %s",
                  i, tabLogLevel[i].str, ReturnLevelInt(i));
          exit(1);
        }
      j = ReturnLevelAscii(tabLogLevel[i].str);
      if (j != i)
        {
          LogTest("FAILURE: Log level %s did not convert to %d, it converted to %d",
                  tabLogLevel[i].str, i, j);
          exit(1);
        }
    }

  LogTest("------------------------------------------------------");

  log_snprintf(tempstr, sizeof(tempstr), "Test log_snprintf");
  LogTest("%s", tempstr);
  LogTest("\nTesting LogError function");
  LogError(COMPONENT_CONFIG, ERR_SYS, ERR_MALLOC, EINVAL);
  LogTest("\nTesting possible environment variable");
  LogTest("COMPONENT_MEMCORRUPT debug level is %s",
          ReturnLevelInt(LogComponents[COMPONENT_MEMCORRUPT].comp_log_level));
  LogFullDebug(COMPONENT_MEMCORRUPT,
               "This should appear if environment is set properly");

  LogTest("------------------------------------------------------");
  LogTest("Send some messages to various files");
  SetComponentLogFile(COMPONENT_DISPATCH, "STDERR");
  LogEvent(COMPONENT_DISPATCH, "This should go to stderr");
  SetComponentLogFile(COMPONENT_DISPATCH, "STDOUT");
  LogEvent(COMPONENT_DISPATCH, "This should go to stdout");
  SetComponentLogFile(COMPONENT_DISPATCH, "SYSLOG");
  LogEvent(COMPONENT_DISPATCH, "This should go to syslog (verf = %s)", str);
  LogTest("About to set %s", file);
  SetComponentLogFile(COMPONENT_DISPATCH, file);
  LogTest("Got it set");
  LogEvent(COMPONENT_DISPATCH, "This should go to %s", file);

  /*
   * Set up for tests that will verify what was actually produced by log messages.
   * This is used to test log levels and to test the log_vnsprintf function.
   */
  SetComponentLogBuffer(COMPONENT_MAIN, tempstr);
  SetComponentLogBuffer(COMPONENT_INIT, tempstr);

#ifdef _SNMP_ADM_ACTIVE
  {
    snmp_adm_type_union param;
    int rc;
    strcpy(param.string, "FAILED");

    LogTest("------------------------------------------------------");
    LogTest("Test SNMP functions");
    SetLevelDebug(NIV_DEBUG);

    rc = getComponentLogLevel(&param, (void *)COMPONENT_ALL);
    LogTest("getComponentLogLevel(&param, (void *)COMPONENT_ALL) rc=%d result=%s",
            rc, param.string);
    if (rc != 0)
    {
      LogTest("FAILURE");
      exit(1);
    }
    strcpy(param.string, "NIV_EVENT");
    rc = setComponentLogLevel(&param, (void *)COMPONENT_MAIN);
    LogTest("setComponentLogLevel(&param, (void *)COMPONENT_MAIN) rc=%d", rc);
    if (rc != 0)
    {
      LogTest("FAILURE");
      exit(1);
    }
    TestAlways    (TRUE,  tempstr, COMPONENT_MAIN, "LogAlways (should print)");
    TestMajor     (TRUE,  tempstr, COMPONENT_MAIN, "LogMajor (should print)");
    TestCrit      (TRUE,  tempstr, COMPONENT_MAIN, "LogCrit (should print)");
    TestEvent     (TRUE,  tempstr, COMPONENT_MAIN, "LogEvent (should print)");
    TestDebug     (FALSE, tempstr, COMPONENT_MAIN, "LogDebug (shouldn't print)");
    TestFullDebug (FALSE, tempstr, COMPONENT_MAIN, "LogFullDebug (shouldn't print)");
    TestAlways    (TRUE,  tempstr, COMPONENT_INIT, "LogAlways (should print)");
    TestMajor     (TRUE,  tempstr, COMPONENT_INIT, "LogMajor (should print)");
    TestCrit      (TRUE,  tempstr, COMPONENT_INIT, "LogCrit (should print)");
    TestEvent     (TRUE,  tempstr, COMPONENT_INIT, "LogEvent (should print)");
    TestDebug     (TRUE,  tempstr, COMPONENT_INIT, "LogDebug (should print)");
    TestFullDebug (FALSE, tempstr, COMPONENT_INIT, "LogFullDebug (shouldn't print)");
  }
#endif /* _SNMP_ADM_ACTIVE */

  LogTest("------------------------------------------------------");
  LogTest("Test all levels of log filtering");
  SetComponentLogLevel(COMPONENT_MAIN, NIV_NULL);
  TestAlways    (TRUE,  tempstr, COMPONENT_MAIN, "LogAlways (should print)");
  TestMajor     (FALSE, tempstr, COMPONENT_MAIN, "LogMajor (shouldn't print)");
  TestCrit      (FALSE, tempstr, COMPONENT_MAIN, "LogCrit (shouldn't print)");
  TestEvent     (FALSE, tempstr, COMPONENT_MAIN, "LogEvent (shouldn't print)");
  TestDebug     (FALSE, tempstr, COMPONENT_MAIN, "LogDebug (shouldn't print)");
  TestFullDebug (FALSE, tempstr, COMPONENT_MAIN, "LogFullDebug (shouldn't print)");
  SetComponentLogLevel(COMPONENT_MAIN, NIV_MAJOR);
  TestAlways    (TRUE,  tempstr, COMPONENT_MAIN, "LogAlways (should print)");
  TestMajor     (TRUE,  tempstr, COMPONENT_MAIN, "LogMajor (should print)");
  TestCrit      (FALSE, tempstr, COMPONENT_MAIN, "LogCrit (shouldn't print)");
  TestEvent     (FALSE, tempstr, COMPONENT_MAIN, "LogEvent (shouldn't print)");
  TestDebug     (FALSE, tempstr, COMPONENT_MAIN, "LogDebug (shouldn't print)");
  TestFullDebug (FALSE, tempstr, COMPONENT_MAIN, "LogFullDebug (shouldn't print)");
  SetComponentLogLevel(COMPONENT_MAIN, NIV_CRIT);
  TestAlways    (TRUE,  tempstr, COMPONENT_MAIN, "LogAlways (should print)");
  TestMajor     (TRUE,  tempstr, COMPONENT_MAIN, "LogMajor (should print)");
  TestCrit      (TRUE,  tempstr, COMPONENT_MAIN, "LogCrit (should print)");
  TestEvent     (FALSE, tempstr, COMPONENT_MAIN, "LogEvent (shouldn't print)");
  TestDebug     (FALSE, tempstr, COMPONENT_MAIN, "LogDebug (shouldn't print)");
  TestFullDebug (FALSE, tempstr, COMPONENT_MAIN, "LogFullDebug (shouldn't print)");
  SetComponentLogLevel(COMPONENT_MAIN, NIV_EVENT);
  TestAlways    (TRUE,  tempstr, COMPONENT_MAIN, "LogAlways (should print)");
  TestMajor     (TRUE,  tempstr, COMPONENT_MAIN, "LogMajor (should print)");
  TestCrit      (TRUE,  tempstr, COMPONENT_MAIN, "LogCrit (should print)");
  TestEvent     (TRUE,  tempstr, COMPONENT_MAIN, "LogEvent (should print)");
  TestDebug     (FALSE, tempstr, COMPONENT_MAIN, "LogDebug (shouldn't print)");
  TestFullDebug (FALSE, tempstr, COMPONENT_MAIN, "LogFullDebug (shouldn't print)");
  SetComponentLogLevel(COMPONENT_MAIN, NIV_DEBUG);
  TestAlways    (TRUE,  tempstr, COMPONENT_MAIN, "LogAlways (should print)");
  TestMajor     (TRUE,  tempstr, COMPONENT_MAIN, "LogMajor (should print)");
  TestCrit      (TRUE,  tempstr, COMPONENT_MAIN, "LogCrit (should print)");
  TestEvent     (TRUE,  tempstr, COMPONENT_MAIN, "LogEvent (should print)");
  TestDebug     (TRUE,  tempstr, COMPONENT_MAIN, "LogDebug (should print)");
  TestFullDebug (FALSE, tempstr, COMPONENT_MAIN, "LogFullDebug (shouldn't print)");
  SetComponentLogLevel(COMPONENT_MAIN, NIV_FULL_DEBUG);
  TestAlways    (TRUE,  tempstr, COMPONENT_MAIN, "LogAlways (should print)");
  TestMajor     (TRUE,  tempstr, COMPONENT_MAIN, "LogMajor (should print)");
  TestCrit      (TRUE,  tempstr, COMPONENT_MAIN, "LogCrit (should print)");
  TestEvent     (TRUE,  tempstr, COMPONENT_MAIN, "LogEvent (should print)");
  TestDebug     (TRUE,  tempstr, COMPONENT_MAIN, "LogDebug (should print)");
  TestFullDebug (TRUE,  tempstr, COMPONENT_MAIN, "LogFullDebug (should print)");
}
/**
 *  Tests about Log streams and special printf functions.
 */
void Test1(char *str, char *file)
{
  char tempstr[2048];
  int  i;

  SetComponentLogFile(COMPONENT_INIT, "STDOUT");
  LogAlways(COMPONENT_INIT, "%s", "Starting Log Tests");
  LogTest("My PID = %d", getpid());

  LogTest("------------------------------------------------------");
  LogTest("Test conversion of log levels between string and integer");
  for (i = NIV_NULL; i < NB_LOG_LEVEL; i++)
    {
      int j;
      if (strcmp(tabLogLevel[i].str, ReturnLevelInt(i)) != 0)
        {
          LogTest("FAILURE: Log level %d did not convert to %s, it converted to %s",
                  i, tabLogLevel[i].str, ReturnLevelInt(i));
          exit(1);
        }
      j = ReturnLevelAscii(tabLogLevel[i].str);
      if (j != i)
        {
          LogTest("FAILURE: Log level %s did not convert to %d, it converted to %d",
                  tabLogLevel[i].str, i, j);
          exit(1);
        }
    }

  LogTest("------------------------------------------------------");

  log_snprintf(tempstr, sizeof(tempstr), "Test log_snprintf");
  LogTest("%s", tempstr);
  LogTest("\nTesting possible environment variable");
  LogTest("COMPONENT_MEMCORRUPT debug level is %s",
          ReturnLevelInt(LogComponents[COMPONENT_MEMCORRUPT].comp_log_level));
  LogFullDebug(COMPONENT_MEMCORRUPT,
               "This should appear if environment is set properly");

  LogTest("------------------------------------------------------");
  LogTest("Send some messages to various files");
  SetComponentLogFile(COMPONENT_DISPATCH, "STDERR");
  LogEvent(COMPONENT_DISPATCH, "This should go to stderr");
  SetComponentLogFile(COMPONENT_DISPATCH, "STDOUT");
  LogEvent(COMPONENT_DISPATCH, "This should go to stdout");
  SetComponentLogFile(COMPONENT_DISPATCH, "SYSLOG");
  LogEvent(COMPONENT_DISPATCH, "This should go to syslog (verf = %s)", str);
  LogTest("About to set %s", file);
  SetComponentLogFile(COMPONENT_DISPATCH, file);
  LogTest("Got it set");
  LogEvent(COMPONENT_DISPATCH, "This should go to %s", file);

  /*
   * Set up for tests that will verify what was actually produced by log messages.
   * This is used to test log levels and to test the log_vnsprintf function.
   */
  SetComponentLogBuffer(COMPONENT_MAIN, tempstr);
  SetComponentLogBuffer(COMPONENT_INIT, tempstr);

  LogTest("------------------------------------------------------");
  LogTest("Test all levels of log filtering");
  SetComponentLogLevel(COMPONENT_MAIN, NIV_NULL);
  TestAlways    (true,  tempstr, COMPONENT_MAIN, "LogAlways (should print)");
  TestMajor     (false, tempstr, COMPONENT_MAIN, "LogMajor (shouldn't print)");
  TestCrit      (false, tempstr, COMPONENT_MAIN, "LogCrit (shouldn't print)");
  TestEvent     (false, tempstr, COMPONENT_MAIN, "LogEvent (shouldn't print)");
  TestDebug     (false, tempstr, COMPONENT_MAIN, "LogDebug (shouldn't print)");
  TestFullDebug (false, tempstr, COMPONENT_MAIN, "LogFullDebug (shouldn't print)");
  SetComponentLogLevel(COMPONENT_MAIN, NIV_MAJOR);
  TestAlways    (true,  tempstr, COMPONENT_MAIN, "LogAlways (should print)");
  TestMajor     (true,  tempstr, COMPONENT_MAIN, "LogMajor (should print)");
  TestCrit      (false, tempstr, COMPONENT_MAIN, "LogCrit (shouldn't print)");
  TestEvent     (false, tempstr, COMPONENT_MAIN, "LogEvent (shouldn't print)");
  TestDebug     (false, tempstr, COMPONENT_MAIN, "LogDebug (shouldn't print)");
  TestFullDebug (false, tempstr, COMPONENT_MAIN, "LogFullDebug (shouldn't print)");
  SetComponentLogLevel(COMPONENT_MAIN, NIV_CRIT);
  TestAlways    (true,  tempstr, COMPONENT_MAIN, "LogAlways (should print)");
  TestMajor     (true,  tempstr, COMPONENT_MAIN, "LogMajor (should print)");
  TestCrit      (true,  tempstr, COMPONENT_MAIN, "LogCrit (should print)");
  TestEvent     (false, tempstr, COMPONENT_MAIN, "LogEvent (shouldn't print)");
  TestDebug     (false, tempstr, COMPONENT_MAIN, "LogDebug (shouldn't print)");
  TestFullDebug (false, tempstr, COMPONENT_MAIN, "LogFullDebug (shouldn't print)");
  SetComponentLogLevel(COMPONENT_MAIN, NIV_EVENT);
  TestAlways    (true,  tempstr, COMPONENT_MAIN, "LogAlways (should print)");
  TestMajor     (true,  tempstr, COMPONENT_MAIN, "LogMajor (should print)");
  TestCrit      (true,  tempstr, COMPONENT_MAIN, "LogCrit (should print)");
  TestEvent     (true,  tempstr, COMPONENT_MAIN, "LogEvent (should print)");
  TestDebug     (false, tempstr, COMPONENT_MAIN, "LogDebug (shouldn't print)");
  TestFullDebug (false, tempstr, COMPONENT_MAIN, "LogFullDebug (shouldn't print)");
  SetComponentLogLevel(COMPONENT_MAIN, NIV_DEBUG);
  TestAlways    (true,  tempstr, COMPONENT_MAIN, "LogAlways (should print)");
  TestMajor     (true,  tempstr, COMPONENT_MAIN, "LogMajor (should print)");
  TestCrit      (true,  tempstr, COMPONENT_MAIN, "LogCrit (should print)");
  TestEvent     (true,  tempstr, COMPONENT_MAIN, "LogEvent (should print)");
  TestDebug     (true,  tempstr, COMPONENT_MAIN, "LogDebug (should print)");
  TestFullDebug (false, tempstr, COMPONENT_MAIN, "LogFullDebug (shouldn't print)");
  SetComponentLogLevel(COMPONENT_MAIN, NIV_FULL_DEBUG);
  TestAlways    (true,  tempstr, COMPONENT_MAIN, "LogAlways (should print)");
  TestMajor     (true,  tempstr, COMPONENT_MAIN, "LogMajor (should print)");
  TestCrit      (true,  tempstr, COMPONENT_MAIN, "LogCrit (should print)");
  TestEvent     (true,  tempstr, COMPONENT_MAIN, "LogEvent (should print)");
  TestDebug     (true,  tempstr, COMPONENT_MAIN, "LogDebug (should print)");
  TestFullDebug (true,  tempstr, COMPONENT_MAIN, "LogFullDebug (should print)");
}