mirror of
https://gitlab.freedesktop.org/libbsd/libbsd.git
synced 2025-01-09 03:08:38 +01:00
test: Fix pipe_feed() to allow checking fprintf format strings
Warned-by: gcc -W
This commit is contained in:
parent
beafad2657
commit
1808d64b77
@ -75,7 +75,7 @@ test_fgetln_single(void)
|
|||||||
size_t len;
|
size_t len;
|
||||||
int i;
|
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++) {
|
for (i = 0; i < DATA_LINES; i++) {
|
||||||
char *str = fgetln(fp, &len);
|
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 = reallocarray(NULL, LINE_COUNT, sizeof(char *));
|
||||||
files[i].lines[0] = str;
|
files[i].lines[0] = str;
|
||||||
files[i].lines[1] = 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++) {
|
for (l = 0; l < LINE_COUNT; l++) {
|
||||||
@ -139,7 +139,7 @@ test_fgetwln_single(void)
|
|||||||
size_t len;
|
size_t len;
|
||||||
int i;
|
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++) {
|
for (i = 0; i < DATA_LINES; i++) {
|
||||||
wchar_t *wstr;
|
wchar_t *wstr;
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ test_fgetwln_multi(void)
|
|||||||
files[i].lines = reallocarray(NULL, LINE_COUNT, sizeof(char *));
|
files[i].lines = reallocarray(NULL, LINE_COUNT, sizeof(char *));
|
||||||
files[i].lines[0] = wstr;
|
files[i].lines[0] = wstr;
|
||||||
files[i].lines[1] = 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++) {
|
for (l = 0; l < LINE_COUNT; l++) {
|
||||||
|
@ -68,7 +68,7 @@ test_fparseln(const char **data_expect, int flags)
|
|||||||
FILE *fp;
|
FILE *fp;
|
||||||
size_t i, len, lineno = 0;
|
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++) {
|
for (i = 0; i < EXPECT_LINES; i++) {
|
||||||
char *str = fparseln(fp, &len, &lineno, NULL, flags);
|
char *str = fparseln(fp, &len, &lineno, NULL, flags);
|
||||||
|
|
||||||
|
@ -27,12 +27,13 @@
|
|||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <wchar.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "test-stream.h"
|
#include "test-stream.h"
|
||||||
|
|
||||||
FILE *
|
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;
|
FILE *fp;
|
||||||
int rc;
|
int rc;
|
||||||
@ -56,7 +57,10 @@ pipe_feed(const char *fmt, const void **buf, int buf_nmemb)
|
|||||||
assert(fp);
|
assert(fp);
|
||||||
|
|
||||||
for (line = 0; line < buf_nmemb; line++) {
|
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);
|
assert(rc >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,8 +29,13 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
enum pipe_data_mode {
|
||||||
|
PIPE_DATA_ASCII,
|
||||||
|
PIPE_DATA_WIDE,
|
||||||
|
};
|
||||||
|
|
||||||
FILE *
|
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
|
void
|
||||||
pipe_close(FILE *fp);
|
pipe_close(FILE *fp);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user