Blame stdio-common/tst-printfsz.c

Packit Service 82fcde
/* Based on code by Larry McVoy <lm@neteng.engr.sgi.com>.  */
Packit Service 82fcde
#include <printf.h>
Packit Service 82fcde
#include <stdio.h>
Packit Service 82fcde
#include <string.h>
Packit Service 82fcde
#include <libc-diag.h>
Packit Service 82fcde
Packit Service 82fcde
#define V       12345678.12345678
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
static int
Packit Service 82fcde
do_test (void)
Packit Service 82fcde
{
Packit Service 82fcde
  char buf[1024];
Packit Service 82fcde
  int result = 0;
Packit Service 82fcde
Packit Service 82fcde
  /* Testing printf_size_info requires using the deprecated
Packit Service 82fcde
     register_printf_function, resulting in warnings
Packit Service 82fcde
     "'register_printf_function' is deprecated".  */
Packit Service 82fcde
  DIAG_PUSH_NEEDS_COMMENT;
Packit Service 82fcde
  DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wdeprecated-declarations");
Packit Service 82fcde
  /* Register the printf handlers.  */
Packit Service 82fcde
  register_printf_function ('b', printf_size, printf_size_info);
Packit Service 82fcde
  register_printf_function ('B', printf_size, printf_size_info);
Packit Service 82fcde
  DIAG_POP_NEEDS_COMMENT;
Packit Service 82fcde
Packit Service 82fcde
  /* All of the formats here use the nonstandard extension specifier
Packit Service 82fcde
     just registered, so compiler checking will never grok them.  */
Packit Service 82fcde
  DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat");
Packit Service 82fcde
  DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat-extra-args");
Packit Service 82fcde
Packit Service 82fcde
  sprintf (buf, "%g %b %B %.0b %.0B %.1b %.1B %8.0b %08.0B",
Packit Service 82fcde
	   V, 1025., V, V, V, V, V, V, V, V);
Packit Service 82fcde
  fputs (buf, stdout);
Packit Service 82fcde
  if (strcmp (buf, "\
Packit Service 82fcde
1.23457e+07 1.001k 12.346M 12m 12M 11.8m 12.3M      12m 0000012M"))
Packit Service 82fcde
    {
Packit Service 82fcde
      result = 1;
Packit Service 82fcde
      fputs (" -> WRONG\n", stdout);
Packit Service 82fcde
    }
Packit Service 82fcde
  else
Packit Service 82fcde
    fputs (" -> OK\n", stdout);
Packit Service 82fcde
Packit Service 82fcde
  sprintf (buf, "%b|%B|%-20.2b|%-10.0b|%-10.8b|%-10.2B|",
Packit Service 82fcde
	   V, V, V, V, V, V, V, V, V, V, V);
Packit Service 82fcde
  fputs (buf, stdout);
Packit Service 82fcde
  if (strcmp (buf, "\
Packit Service 82fcde
11.774m|12.346M|11.77m              |12m       |11.77375614m|12.35M    |"))
Packit Service 82fcde
    {
Packit Service 82fcde
      result = 1;
Packit Service 82fcde
      fputs (" -> WRONG\n", stdout);
Packit Service 82fcde
    }
Packit Service 82fcde
  else
Packit Service 82fcde
    fputs (" -> OK\n", stdout);
Packit Service 82fcde
Packit Service 82fcde
  sprintf (buf, "%#.0B %*.0b %10.*b %*.*B %10.2B",
Packit Service 82fcde
	   V, 2, V, 2, V, 10, 2, V, V);
Packit Service 82fcde
  fputs (buf, stdout);
Packit Service 82fcde
  if (strcmp (buf, "12.M 12m     11.77m     12.35M     12.35M"))
Packit Service 82fcde
    {
Packit Service 82fcde
      result = 1;
Packit Service 82fcde
      fputs (" -> WRONG\n", stdout);
Packit Service 82fcde
    }
Packit Service 82fcde
  else
Packit Service 82fcde
    fputs (" -> OK\n", stdout);
Packit Service 82fcde
Packit Service 82fcde
  sprintf (buf, "%6B %6.1B %b %B %b %B",
Packit Service 82fcde
	   V, V, 1000.0, 1000.0, 1024.0, 1024.0);
Packit Service 82fcde
  fputs (buf, stdout);
Packit Service 82fcde
  if (strcmp (buf, "12.346M  12.3M 1000.000  1.000K 1.000k 1.024K"))
Packit Service 82fcde
    {
Packit Service 82fcde
      result = 1;
Packit Service 82fcde
      fputs (" -> WRONG\n", stdout);
Packit Service 82fcde
    }
Packit Service 82fcde
  else
Packit Service 82fcde
    fputs (" -> OK\n", stdout);
Packit Service 82fcde
Packit Service 82fcde
  return result;
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
#define TEST_FUNCTION do_test ()
Packit Service 82fcde
#include "../test-skeleton.c"