test: Fix pipe_feed() to allow checking fprintf format strings

Warned-by: gcc -W
This commit is contained in:
Guillem Jover 2021-03-01 05:14:10 +01:00
parent beafad2657
commit 1808d64b77
4 changed files with 17 additions and 8 deletions

View 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++) {

View 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);

View File

@ -27,12 +27,13 @@
#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);
}

View File

@ -29,8 +29,13 @@
#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);