diff options
author | schwarze <> | 2022-07-25 15:29:21 +0000 |
---|---|---|
committer | schwarze <> | 2022-07-25 15:29:21 +0000 |
commit | 20aea8136defb6b04d2ebae31195a55bf10ae314 (patch) | |
tree | 70a2f07a1ad7fe8315e16be8c2d2035bad3e7b00 /src | |
parent | 70819cc930595b9f8df020a494d2a24efa52c16d (diff) | |
download | openbsd-20aea8136defb6b04d2ebae31195a55bf10ae314.tar.gz openbsd-20aea8136defb6b04d2ebae31195a55bf10ae314.tar.bz2 openbsd-20aea8136defb6b04d2ebae31195a55bf10ae314.zip |
Separate the macro for generating string test functions
for the macro generating test functions for other data types.
This makes sense because both are sufficiently different.
It also avoids a large number of false positive compiler warnings
that guenther@ reported.
OK guenther@
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libc/locale/uselocale/uselocale.c | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/src/regress/lib/libc/locale/uselocale/uselocale.c b/src/regress/lib/libc/locale/uselocale/uselocale.c index f07a16ad65..eb0a0025a9 100644 --- a/src/regress/lib/libc/locale/uselocale/uselocale.c +++ b/src/regress/lib/libc/locale/uselocale/uselocale.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* $OpenBSD: uselocale.c,v 1.6 2022/04/03 16:52:50 anton Exp $ */ | 1 | /* $OpenBSD: uselocale.c,v 1.7 2022/07/25 15:29:21 schwarze Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> | 3 | * Copyright (c) 2017, 2022 Ingo Schwarze <schwarze@openbsd.org> |
4 | * | 4 | * |
5 | * Permission to use, copy, modify, and distribute this software for any | 5 | * Permission to use, copy, modify, and distribute this software for any |
6 | * purpose with or without fee is hereby granted, provided that the above | 6 | * purpose with or without fee is hereby granted, provided that the above |
@@ -38,7 +38,6 @@ | |||
38 | 38 | ||
39 | /* Options for TESTFUNC(). */ | 39 | /* Options for TESTFUNC(). */ |
40 | #define TOPT_ERR (1 << 0) | 40 | #define TOPT_ERR (1 << 0) |
41 | #define TOPT_STR (1 << 1) | ||
42 | 41 | ||
43 | /* | 42 | /* |
44 | * Generate one test function for a specific interface. | 43 | * Generate one test function for a specific interface. |
@@ -62,14 +61,7 @@ _test_##Fn(int line, int ee, Ft er, FUNCPARA) \ | |||
62 | Ft ar; \ | 61 | Ft ar; \ |
63 | errno = 0; \ | 62 | errno = 0; \ |
64 | ar = Fn(FUNCARGS); \ | 63 | ar = Fn(FUNCARGS); \ |
65 | if (Op & TOPT_STR) { \ | 64 | if (ar != er) \ |
66 | if (er == (Ft)NULL) \ | ||
67 | er = (Ft)"NULL"; \ | ||
68 | if (ar == (Ft)NULL) \ | ||
69 | ar = (Ft)"NULL"; \ | ||
70 | } \ | ||
71 | if (Op & TOPT_STR ? strcmp((const char *)er, (const char *)ar) \ | ||
72 | : ar != er) \ | ||
73 | errx(1, "[%d] %s(" Af ")=" Rf " [exp: " Rf "]", \ | 65 | errx(1, "[%d] %s(" Af ")=" Rf " [exp: " Rf "]", \ |
74 | line, #Fn, FUNCARGS, ar, er); \ | 66 | line, #Fn, FUNCARGS, ar, er); \ |
75 | if (Op & TOPT_ERR && errno != ee) \ | 67 | if (Op & TOPT_ERR && errno != ee) \ |
@@ -77,6 +69,22 @@ _test_##Fn(int line, int ee, Ft er, FUNCPARA) \ | |||
77 | line, #Fn, FUNCARGS, errno, ee); \ | 69 | line, #Fn, FUNCARGS, errno, ee); \ |
78 | } | 70 | } |
79 | 71 | ||
72 | #define STRTESTFUNC(Fn, Af) \ | ||
73 | static void \ | ||
74 | _test_##Fn(int line, int ee, const char *er, FUNCPARA) \ | ||
75 | { \ | ||
76 | const char *ar; \ | ||
77 | errno = 0; \ | ||
78 | ar = Fn(FUNCARGS); \ | ||
79 | if (er == NULL) \ | ||
80 | er = "NULL"; \ | ||
81 | if (ar == NULL) \ | ||
82 | ar = "NULL"; \ | ||
83 | if (strcmp((const char *)er, (const char *)ar) != 0) \ | ||
84 | errx(1, "[%d] %s(" Af ")=%s [exp: %s]", \ | ||
85 | line, #Fn, FUNCARGS, ar, er); \ | ||
86 | } | ||
87 | |||
80 | /* | 88 | /* |
81 | * Test functions for all tested interfaces. | 89 | * Test functions for all tested interfaces. |
82 | */ | 90 | */ |
@@ -91,15 +99,15 @@ TESTFUNC(uselocale, locale_t, "%p", "%p", TOPT_ERR) | |||
91 | 99 | ||
92 | #define FUNCPARA int category, char *locname | 100 | #define FUNCPARA int category, char *locname |
93 | #define FUNCARGS category, locname | 101 | #define FUNCARGS category, locname |
94 | TESTFUNC(setlocale, const char *, "%d, %s", "%s", TOPT_STR) | 102 | STRTESTFUNC(setlocale, "%d, %s") |
95 | 103 | ||
96 | #define FUNCPARA nl_item item | 104 | #define FUNCPARA nl_item item |
97 | #define FUNCARGS item | 105 | #define FUNCARGS item |
98 | TESTFUNC(nl_langinfo, const char *, "%ld", "%s", TOPT_STR) | 106 | STRTESTFUNC(nl_langinfo, "%ld") |
99 | 107 | ||
100 | #define FUNCPARA nl_item item, locale_t locale | 108 | #define FUNCPARA nl_item item, locale_t locale |
101 | #define FUNCARGS item, locale | 109 | #define FUNCARGS item, locale |
102 | TESTFUNC(nl_langinfo_l, const char *, "%ld, %p", "%s", TOPT_STR) | 110 | STRTESTFUNC(nl_langinfo_l, "%ld, %p") |
103 | 111 | ||
104 | #define FUNCPARA int c | 112 | #define FUNCPARA int c |
105 | #define FUNCARGS c | 113 | #define FUNCARGS c |