-/* $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 <schwarze@openbsd.org>
+ * Copyright (c) 2017, 2022 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
/* Options for TESTFUNC(). */
#define TOPT_ERR (1 << 0)
-#define TOPT_STR (1 << 1)
/*
* Generate one test function for a specific interface.
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) \
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.
*/
#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