Exemple #1
0
static int
do_test (void)
{
  init_invalid_status ();

  TEST ("test",      NULL,   "%s",      "test");
  TEST ("test-test", NULL,   "%s-test", "test");
  TEST ("test",      "test", "%s",      "test");
  TEST ("test-test", "test", "%s-test", "test");

  TEST ("test%",      NULL,   "%s%%",      "test");
  TEST ("test%-test", NULL,   "%s%%-test", "test");
  TEST ("test%",      "test", "%s%%",      "test");
  TEST ("test%-test", "test", "%s%%-test", "test");

  TEST ("0000007b",      NULL,   "%x",      123);
  TEST ("0000007b-test", NULL,   "%x-test", 123);
  TEST ("0000007b",      "test", "%x",      123);
  TEST ("0000007b-test", "test", "%x-test", 123);

#define TEST_LONG(es, objn, fmt, ...)				\
  ({								\
     if (sizeof (int) == sizeof (long int))			\
       TEST (es, objn, fmt, __VA_ARGS__);			\
     else							\
       TEST ("ffffffff" es, objn, fmt, __VA_ARGS__);		\
   })

  TEST_LONG ("fffffffd",      NULL,   "%lx",      (long int)~2ul);
  TEST_LONG ("fffffffd-test", NULL,   "%lx-test", (long int)~2ul);
  TEST_LONG ("fffffffd",      "test", "%lx",      (long int)~2ul);
  TEST_LONG ("fffffffd-test", "test", "%lx-test", (long int)~2ul);

  TEST_LONG ("fffffffe",      NULL,   "%zx",      (size_t)~1ul);
  TEST_LONG ("fffffffe-test", NULL,   "%zx-test", (size_t)~1ul);
  TEST_LONG ("fffffffe",      "test", "%zx",      (size_t)~1ul);
  TEST_LONG ("fffffffe-test", "test", "%zx-test", (size_t)~1ul);

  struct support_capture_subprocess result;
  result = support_capture_subprocess (do_test_invalid_conversion, NULL);
  support_capture_subprocess_check (&result, "dl-exception",
				    invalid_status, sc_allow_stderr);
  TEST_COMPARE_STRING (result.err.buffer,
		       "Fatal error: invalid format in exception string\n");

  return 0;
}
void
test_long (CharT*, Traits*,
           const char *cname,
           const char *tname)
{
    info (cname, tname, "long");

    test_extractor ((CharT*)0, (Traits*)0, (long*)0,
                    cname, tname, "long", "%li");

#define TEST_LONG(ss, fl, is, ex, ee, es, ne, fw, iv, ev)   \
    TEST (long, "%li", ss, fl, is, ex, ee, es, ne, fw, iv, ev)

    LocaleData locale_data = { 0, -1, -1, 0, 0, 0 };
    locale_data.whitespace = "";

#if 2 == _RWSTD_LONG_SIZE
    const long lmax = +32767L;
    const long lmin = -lmax - 1;

    TEST_LONG ("-32768",  -1, -1, -1, 0, _e_, 6, 0,  1, lmin);
    TEST_LONG ("-32769",  -1, -1, -1, 0, _ef, 6, 0,  1, lmin);
    TEST_LONG ("-99999",  -1, -1, -1, 0, _ef, 6, 0,  1, lmin);

    TEST_LONG ("+32767",  -1, -1, -1, 0, _e_, 6, 0,  1, lmax);
    TEST_LONG ("+32768",  -1, -1, -1, 0, _ef, 6, 0,  1, lmax);
    TEST_LONG ("+99999",  -1, -1, -1, 0, _ef, 6, 0,  1, lmax);
#elif 4 == _RWSTD_LONG_SIZE
    const long lmax = +2147483647L;
    const long lmin = -lmax - 1;

    TEST_LONG ("-2147483648", -1, -1, -1, 0, _e_, 11, 0, -1, lmin);
    TEST_LONG ("-2147483649", -1, -1, -1, 0, _ef, 11, 0, -1, lmin);
    TEST_LONG ("-9999999999", -1, -1, -1, 0, _ef, 11, 0, -1, lmin);

    TEST_LONG ("+2147483647", -1, -1, -1, 0, _e_, 11, 0, -1, lmax);
    TEST_LONG ("+2147483648", -1, -1, -1, 0, _ef, 11, 0, -1, lmax);
    TEST_LONG ("99999999999", -1, -1, -1, 0, _ef, 11, 0, -1, lmax);
#elif 8 == _RWSTD_LONG_SIZE
    const long lmax = +9223372036854775807L;
    const long lmin = -lmax - 1;

    TEST_LONG ("-9223372036854775808", -1, -1, -1, 0, _e_, 20, 0, -1, lmin);
    TEST_LONG ("-9223372036854775809", -1, -1, -1, 0, _ef, 20, 0, -1, lmin);
    TEST_LONG ("-9999999999999999999", -1, -1, -1, 0, _ef, 20, 0, -1, lmin);

    TEST_LONG ("+9223372036854775807", -1, -1, -1, 0, _e_, 20, 0, -1, lmax);
    TEST_LONG ("+9223372036854775808", -1, -1, -1, 0, _ef, 20, 0, -1, lmax);
    TEST_LONG ("99999999999999999999", -1, -1, -1, 0, _ef, 20, 0, -1, lmax);
#endif   // _RWSTD_LONG_SIZE

}