diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2013-02-14 15:34:32 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2013-05-07 09:41:05 +1000 |
commit | 5ea21560dd071ea4ab87430000d087fd5fe1f092 (patch) | |
tree | 2bac3b8720d344998f2a5d111a116ee669609dc9 /test | |
parent | d3d4af5f9e505d444b6c82c6ea238206433fd24b (diff) |
os: support pnprintf length modifiers for integers
Mainly for %ld, smaller than int is propagated anyway, and %lld isn't really
used.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/signal-logging.c | 78 |
1 files changed, 69 insertions, 9 deletions
diff --git a/test/signal-logging.c b/test/signal-logging.c index e0eb81006..9038cf81f 100644 --- a/test/signal-logging.c +++ b/test/signal-logging.c @@ -158,6 +158,8 @@ static void logging_format(void) char buf[1024]; int i; unsigned int ui; + long li; + unsigned long lui; FILE *f; char read_buf[2048]; char *logmsg; @@ -207,6 +209,14 @@ static void logging_format(void) LogMessageVerbSigSafe(X_ERROR, -1, "\n"); fseek(f, 0, SEEK_END); +#warning Ignore compiler warning below "unknown conversion type character". This is intentional. + /* %hld is bogus */ + LogMessageVerbSigSafe(X_ERROR, -1, "%hld\n", 4); + read_log_msg(logmsg); + assert(strstr(logmsg, "BUG") != NULL); + LogMessageVerbSigSafe(X_ERROR, -1, "\n"); + fseek(f, 0, SEEK_END); + /* number substitution */ ui = 0; do { @@ -215,12 +225,47 @@ static void logging_format(void) LogMessageVerbSigSafe(X_ERROR, -1, "%u\n", ui); read_log_msg(logmsg); assert(strcmp(logmsg, expected) == 0); + + sprintf(expected, "(EE) %x\n", ui); + LogMessageVerbSigSafe(X_ERROR, -1, "%x\n", ui); + read_log_msg(logmsg); + assert(strcmp(logmsg, expected) == 0); + if (ui == 0) ui = 1; else ui <<= 1; } while(ui); + lui = 0; + do { + char expected[30]; + sprintf(expected, "(EE) %lu\n", lui); + LogMessageVerbSigSafe(X_ERROR, -1, "%lu\n", lui); + read_log_msg(logmsg); + + sprintf(expected, "(EE) %lld\n", (unsigned long long)ui); + LogMessageVerbSigSafe(X_ERROR, -1, "%lld\n", (unsigned long long)ui); + read_log_msg(logmsg); + assert(strcmp(logmsg, expected) == 0); + + sprintf(expected, "(EE) %lx\n", lui); + printf("%s\n", expected); + LogMessageVerbSigSafe(X_ERROR, -1, "%lx\n", lui); + read_log_msg(logmsg); + assert(strcmp(logmsg, expected) == 0); + + sprintf(expected, "(EE) %llx\n", (unsigned long long)ui); + LogMessageVerbSigSafe(X_ERROR, -1, "%llx\n", (unsigned long long)ui); + read_log_msg(logmsg); + assert(strcmp(logmsg, expected) == 0); + + if (lui == 0) + lui = 1; + else + lui <<= 1; + } while(lui); + /* signed number substitution */ i = 0; do { @@ -230,7 +275,6 @@ static void logging_format(void) read_log_msg(logmsg); assert(strcmp(logmsg, expected) == 0); - sprintf(expected, "(EE) %d\n", i | INT_MIN); LogMessageVerbSigSafe(X_ERROR, -1, "%d\n", i | INT_MIN); read_log_msg(logmsg); @@ -242,19 +286,35 @@ static void logging_format(void) i <<= 1; } while(i > INT_MIN); - /* hex number substitution */ - ui = 0; + li = 0; do { char expected[30]; - sprintf(expected, "(EE) %x\n", ui); - LogMessageVerbSigSafe(X_ERROR, -1, "%x\n", ui); + sprintf(expected, "(EE) %ld\n", li); + LogMessageVerbSigSafe(X_ERROR, -1, "%ld\n", li); read_log_msg(logmsg); assert(strcmp(logmsg, expected) == 0); - if (ui == 0) - ui = 1; + + sprintf(expected, "(EE) %ld\n", li | LONG_MIN); + LogMessageVerbSigSafe(X_ERROR, -1, "%ld\n", li | LONG_MIN); + read_log_msg(logmsg); + assert(strcmp(logmsg, expected) == 0); + + sprintf(expected, "(EE) %lld\n", (long long)li); + LogMessageVerbSigSafe(X_ERROR, -1, "%lld\n", (long long)li); + read_log_msg(logmsg); + assert(strcmp(logmsg, expected) == 0); + + sprintf(expected, "(EE) %lld\n", (long long)(li | LONG_MIN)); + LogMessageVerbSigSafe(X_ERROR, -1, "%lld\n", (long long)(li | LONG_MIN)); + read_log_msg(logmsg); + assert(strcmp(logmsg, expected) == 0); + + if (li == 0) + li = 1; else - ui <<= 1; - } while(ui); + li <<= 1; + } while(li > LONG_MIN); + /* pointer substitution */ /* we print a null-pointer differently to printf */ |