From 60875c3b8d4e3a3b9291e9e17f1e38c9a71077fe Mon Sep 17 00:00:00 2001 From: schwarze Date: Mon, 25 Jul 2022 15:29:21 +0000 Subject: [PATCH] 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@ --- regress/lib/libc/locale/uselocale/uselocale.c | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/regress/lib/libc/locale/uselocale/uselocale.c b/regress/lib/libc/locale/uselocale/uselocale.c index f07a16ad651..eb0a0025a93 100644 --- a/regress/lib/libc/locale/uselocale/uselocale.c +++ b/regress/lib/libc/locale/uselocale/uselocale.c @@ -1,6 +1,6 @@ -/* $OpenBSD: uselocale.c,v 1.6 2022/04/03 16:52:50 anton Exp $ */ +/* $OpenBSD: uselocale.c,v 1.7 2022/07/25 15:29:21 schwarze Exp $ */ /* - * Copyright (c) 2017 Ingo Schwarze + * Copyright (c) 2017, 2022 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -38,7 +38,6 @@ /* Options for TESTFUNC(). */ #define TOPT_ERR (1 << 0) -#define TOPT_STR (1 << 1) /* * Generate one test function for a specific interface. @@ -62,14 +61,7 @@ _test_##Fn(int line, int ee, Ft er, FUNCPARA) \ Ft ar; \ errno = 0; \ ar = Fn(FUNCARGS); \ - if (Op & TOPT_STR) { \ - if (er == (Ft)NULL) \ - er = (Ft)"NULL"; \ - if (ar == (Ft)NULL) \ - ar = (Ft)"NULL"; \ - } \ - if (Op & TOPT_STR ? strcmp((const char *)er, (const char *)ar) \ - : ar != er) \ + if (ar != er) \ errx(1, "[%d] %s(" Af ")=" Rf " [exp: " Rf "]", \ line, #Fn, FUNCARGS, ar, er); \ if (Op & TOPT_ERR && errno != ee) \ @@ -77,6 +69,22 @@ _test_##Fn(int line, int ee, Ft er, FUNCPARA) \ line, #Fn, FUNCARGS, errno, ee); \ } +#define STRTESTFUNC(Fn, Af) \ +static void \ +_test_##Fn(int line, int ee, const char *er, FUNCPARA) \ +{ \ + const char *ar; \ + errno = 0; \ + ar = Fn(FUNCARGS); \ + if (er == NULL) \ + er = "NULL"; \ + if (ar == NULL) \ + ar = "NULL"; \ + if (strcmp((const char *)er, (const char *)ar) != 0) \ + errx(1, "[%d] %s(" Af ")=%s [exp: %s]", \ + line, #Fn, FUNCARGS, ar, er); \ +} + /* * Test functions for all tested interfaces. */ @@ -91,15 +99,15 @@ TESTFUNC(uselocale, locale_t, "%p", "%p", TOPT_ERR) #define FUNCPARA int category, char *locname #define FUNCARGS category, locname -TESTFUNC(setlocale, const char *, "%d, %s", "%s", TOPT_STR) +STRTESTFUNC(setlocale, "%d, %s") #define FUNCPARA nl_item item #define FUNCARGS item -TESTFUNC(nl_langinfo, const char *, "%ld", "%s", TOPT_STR) +STRTESTFUNC(nl_langinfo, "%ld") #define FUNCPARA nl_item item, locale_t locale #define FUNCARGS item, locale -TESTFUNC(nl_langinfo_l, const char *, "%ld, %p", "%s", TOPT_STR) +STRTESTFUNC(nl_langinfo_l, "%ld, %p") #define FUNCPARA int c #define FUNCARGS c -- 2.20.1