Exemple #1
0
/* The goal of this test is to check cases where more INT_MAX characters
   are output, in which case, it should be a failure, because like C's
   *printf functions, the return type is int and the returned value must
   be either the number of characters printed or a negative value. */
static void
check_long_string (void)
{
  /* this test is VERY expensive both in time (~1 min on core2 @ 2.40GHz) and
     in memory (~2.5 GB) */
  mpfr_t x;
  long large_prec = 2147483647;

  /* With a 32-bit (4GB) address space, a realloc failure has been noticed
     with a 2G precision (though allocating up to 4GB is possible):
       MPFR: Can't reallocate memory (old_size=4096 new_size=2147487744)
     The implementation might be improved to use less memory and avoid
     this problem. In the mean time, let's choose a smaller precision,
     but this will generally have the effect to disable the test. */
  if (sizeof (void *) == 4)
    large_prec /= 2;

  /* We assume that the precision won't be increased internally. */
  if (large_prec > MPFR_PREC_MAX)
    large_prec = MPFR_PREC_MAX;

  mpfr_init2 (x, large_prec);

  mpfr_set_ui (x, 1, MPFR_RNDN);
  mpfr_nextabove (x);

  if (large_prec >= INT_MAX - 512)
    {
      check_vprintf_failure ("%Rb %512d", x, 1);
      check_vprintf_failure ("%RA %RA %Ra %Ra %512d", x, x, x, x, 1);
    }

  mpfr_clear (x);
}
Exemple #2
0
static void
check_long_string (void)
{
  /* this test is VERY expensive both in time (~1 min on core2 @ 2.40GHz) and
     in memory (~2.5 GB) */
  mpfr_t x;

  mpfr_init2 (x, INT_MAX);

  mpfr_set_ui (x, 1, MPFR_RNDN);
  mpfr_nextabove (x);

  check_vprintf_failure ("%Rb", x);
  check_vprintf_failure ("%RA %RA %Ra %Ra", x, x, x, x);

  mpfr_clear (x);
}
Exemple #3
0
static void
check_invalid_format (void)
{
  int i = 0;

  /* format in disorder */
  check_vprintf_failure ("blah %l2.1d blah", i);
  check_vprintf_failure ("blah %2.1#d blah", i);

  /* incomplete format */
  check_vprintf_failure ("%", i);
  check_vprintf_failure ("% (missing conversion specifier)", i);
  check_vprintf_failure ("missing conversion specifier %h", i);
  check_vprintf_failure ("this should fail %.l because of missing conversion specifier "
                         "(or doubling %%)", i);
  check_vprintf_failure ("%L", i);
  check_vprintf_failure ("%hh. ", i);
  check_vprintf_failure ("blah %j.");
  check_vprintf_failure ("%ll blah");
  check_vprintf_failure ("blah%t blah");
  check_vprintf_failure ("%z ");
  check_vprintf_failure ("%F (missing conversion specifier)");
  check_vprintf_failure ("%Q (missing conversion specifier)");
  check_vprintf_failure ("%M (missing conversion specifier)");
  check_vprintf_failure ("%N (missing conversion specifier)");
  check_vprintf_failure ("%Z (missing conversion specifier)");
  check_vprintf_failure ("%R (missing conversion specifier)");
  check_vprintf_failure ("%R");
  check_vprintf_failure ("%P (missing conversion specifier)");

  /* conversion specifier with wrong length specifier */
  check_vprintf_failure ("%ha", i);
  check_vprintf_failure ("%hhe", i);
  check_vprintf_failure ("%jf", i);
  check_vprintf_failure ("%lg", i);
  check_vprintf_failure ("%tA", i);
  check_vprintf_failure ("%zE", i);
  check_vprintf_failure ("%Ld", i);
  check_vprintf_failure ("%Qf", i);
  check_vprintf_failure ("%MG", i);
  check_vprintf_failure ("%Na", i);
  check_vprintf_failure ("%ZE", i);
  check_vprintf_failure ("%PG", i);
  check_vprintf_failure ("%Fu", i);
  check_vprintf_failure ("%Rx", i);
}