]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
test: Fix pipe_feed() to allow checking fprintf format strings
authorGuillem Jover <guillem@hadrons.org>
Mon, 1 Mar 2021 04:14:10 +0000 (05:14 +0100)
committerGuillem Jover <guillem@hadrons.org>
Sat, 27 Nov 2021 04:06:14 +0000 (05:06 +0100)
Warned-by: gcc -W
test/fgetln.c
test/fparseln.c
test/test-stream.c
test/test-stream.h

index d08fb3b5194619277224db1abd00ff4251a373b7..2eafa8466126813cc8eaf33bc922f51ee147a364 100644 (file)
@@ -75,7 +75,7 @@ test_fgetln_single(void)
        size_t len;
        int i;
 
-       fp = pipe_feed("%s", (const void **)data_ascii, DATA_LINES);
+       fp = pipe_feed(PIPE_DATA_ASCII, (const void **)data_ascii, DATA_LINES);
        for (i = 0; i < DATA_LINES; i++) {
                char *str = fgetln(fp, &len);
 
@@ -102,7 +102,7 @@ test_fgetln_multi(void)
                files[i].lines = reallocarray(NULL, LINE_COUNT, sizeof(char *));
                files[i].lines[0] = str;
                files[i].lines[1] = str;
-               files[i].fp = pipe_feed("%s", files[i].lines, LINE_COUNT);
+               files[i].fp = pipe_feed(PIPE_DATA_ASCII, files[i].lines, LINE_COUNT);
        }
 
        for (l = 0; l < LINE_COUNT; l++) {
@@ -139,7 +139,7 @@ test_fgetwln_single(void)
        size_t len;
        int i;
 
-       fp = pipe_feed("%ls", (const void **)data_wide, DATA_LINES);
+       fp = pipe_feed(PIPE_DATA_WIDE, (const void **)data_wide, DATA_LINES);
        for (i = 0; i < DATA_LINES; i++) {
                wchar_t *wstr;
 
@@ -168,7 +168,7 @@ test_fgetwln_multi(void)
                files[i].lines = reallocarray(NULL, LINE_COUNT, sizeof(char *));
                files[i].lines[0] = wstr;
                files[i].lines[1] = wstr;
-               files[i].fp = pipe_feed("%ls", files[i].lines, LINE_COUNT);
+               files[i].fp = pipe_feed(PIPE_DATA_WIDE, files[i].lines, LINE_COUNT);
        }
 
        for (l = 0; l < LINE_COUNT; l++) {
index daff6bd78463256d95a80258cb9ded8a22311e0c..5d7898d00f6024f0e64f2e363ffeb9430db17853 100644 (file)
@@ -68,7 +68,7 @@ test_fparseln(const char **data_expect, int flags)
        FILE *fp;
        size_t i, len, lineno = 0;
 
-       fp = pipe_feed("%s", (const void **)data_test, TEST_LINES);
+       fp = pipe_feed(PIPE_DATA_ASCII, (const void **)data_test, TEST_LINES);
        for (i = 0; i < EXPECT_LINES; i++) {
                char *str = fparseln(fp, &len, &lineno, NULL, flags);
 
index 849f419846c950e0450b6fb62fc1043bb95699af..0bbb6414c857af65c74dd76e69315c5018ce74c9 100644 (file)
 #include <sys/wait.h>
 #include <assert.h>
 #include <unistd.h>
+#include <wchar.h>
 #include <stdio.h>
 
 #include "test-stream.h"
 
 FILE *
-pipe_feed(const char *fmt, const void **buf, int buf_nmemb)
+pipe_feed(enum pipe_data_mode mode, const void **buf, int buf_nmemb)
 {
        FILE *fp;
        int rc;
@@ -56,7 +57,10 @@ pipe_feed(const char *fmt, const void **buf, int buf_nmemb)
                assert(fp);
 
                for (line = 0; line < buf_nmemb; line++) {
-                       rc = fprintf(fp, fmt, buf[line]);
+                       if (mode == PIPE_DATA_ASCII)
+                               rc = fprintf(fp, "%s", (const char *)buf[line]);
+                       else
+                               rc = fprintf(fp, "%ls", (const wchar_t *)buf[line]);
                        assert(rc >= 0);
                }
 
index cee4e60101dfdbbca76c7d63c4cbc32d007a9762..8caf3fcd65500440fc597f2cfde25acc4b3e78e8 100644 (file)
 
 #include <stdio.h>
 
+enum pipe_data_mode {
+       PIPE_DATA_ASCII,
+       PIPE_DATA_WIDE,
+};
+
 FILE *
-pipe_feed(const char *fmt, const void **buf, int buf_nmemb);
+pipe_feed(enum pipe_data_mode mode, const void **buf, int buf_nmemb);
 void
 pipe_close(FILE *fp);