summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2013-02-14 15:34:32 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2013-05-14 16:37:26 +1000
commitb606767f20c566e24704502eae682eacb41f450e (patch)
treea9dadb8b5727f701c9d9272d7f99cf671404e064 /test
parent00b8d11dafdbd1214695e0b54c6c2184ece6aa4d (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> (cherry picked from commit 5ea21560dd071ea4ab87430000d087fd5fe1f092)
Diffstat (limited to 'test')
-rw-r--r--test/signal-logging.c78
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 */