---
mingw-w64-crt/testcases/t_findfirst.c | 53 +++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/mingw-w64-crt/testcases/t_findfirst.c
b/mingw-w64-crt/testcases/t_findfirst.c
index 52641e711c26..de88f6a19979 100644
--- a/mingw-w64-crt/testcases/t_findfirst.c
+++ b/mingw-w64-crt/testcases/t_findfirst.c
@@ -2,11 +2,62 @@
#include <stdlib.h>
#include <errno.h>
#include <string.h>
+#include <sys/stat.h>
#include <io.h>
#define A(x) x
#define W(x) L##x
+#define STRCMPAW(buf, str) (sizeof ((buf)[0]) == sizeof (wchar_t) ? wcscmp
((const void *)(buf), W(str)) : strcmp ((const void *)(buf), A(str)))
+
+#define CALL_STAT_TEST(d, F, STATDATA, STATFUNC, FINDFUNC) do { \
+ struct STATDATA st; \
+ int ret = STATFUNC ((const void *)d.name, &st); \
+ if (ret != 0) { \
+ fprintf (stderr, "Error: Function %s" F " failed: errno=%d (%s)\n",
#STATFUNC, d.name, errno, strerror (errno)); \
+ return 1; \
+ } \
+ if (STRCMPAW(d.name, "t_findfirst.log") == 0) { \
+ fprintf (stderr, "Skipping file t_findfirst.log as it is being changed
during the test\n"); \
+ } else { \
+ if (st.st_atime != d.time_access) { \
+ fprintf (stderr, "Error: " F ": %s st_atime (%I64d) differs from %s
time_access (%I64d)\n", d.name, #STATFUNC, (long long)st.st_atime, #FINDFUNC,
(long long)d.time_access); \
+ return 1; \
+ } \
+ if (st.st_ctime != d.time_write) { \
+ fprintf (stderr, "Error: " F ":%s st_ctime (%I64d) differs from %s
time_write (%I64d)\n", d.name, #STATFUNC, (long long)st.st_ctime, #FINDFUNC,
(long long)d.time_write); \
+ return 1; \
+ } \
+ /* st_size is always signed, d.size is unsigned for 32-bit calls and
signed for 64-bit calls, so following double cast normalize d.size to 64-bit
number */ \
+ if (st.st_size != (signed long long)(unsigned long long)d.size) { \
+ fprintf (stderr, "Error: " F ":%s st_size (%I64d) differs from %s size
(%I64d)\n", d.name, #STATFUNC, (long long)st.st_size, #FINDFUNC, (long
long)d.size); \
+ return 1; \
+ } \
+ } \
+} while (0)
+
+#define STAT_TEST(d, F, FINDFUNC) do { \
+ if (sizeof (d.name[0]) == sizeof (wchar_t)) { \
+ CALL_STAT_TEST (d, F, stat, wstat, FINDFUNC); \
+ CALL_STAT_TEST (d, F, stat64, wstat64, FINDFUNC); \
+ CALL_STAT_TEST (d, F, _stat, _wstat, FINDFUNC); \
+ CALL_STAT_TEST (d, F, _stati64, _wstati64, FINDFUNC); \
+ CALL_STAT_TEST (d, F, _stat32, _wstat32, FINDFUNC); \
+ CALL_STAT_TEST (d, F, _stat32i64, _wstat32i64, FINDFUNC); \
+ CALL_STAT_TEST (d, F, _stat64i32, _wstat64i32, FINDFUNC); \
+ CALL_STAT_TEST (d, F, _stat64, _wstat64, FINDFUNC); \
+ } else { \
+ CALL_STAT_TEST (d, F, stat, stat, FINDFUNC); \
+ CALL_STAT_TEST (d, F, stat64, stat64, FINDFUNC); \
+ CALL_STAT_TEST (d, F, _stat, _stat, FINDFUNC); \
+ CALL_STAT_TEST (d, F, _stati64, _stati64, FINDFUNC); \
+ CALL_STAT_TEST (d, F, _stat32, _stat32, FINDFUNC); \
+ CALL_STAT_TEST (d, F, _stat32i64, _stat32i64, FINDFUNC); \
+ CALL_STAT_TEST (d, F, _stat64i32, _stat64i32, FINDFUNC); \
+ CALL_STAT_TEST (d, F, _stat64, _stat64, FINDFUNC); \
+ } \
+} while (0)
+
#define DEFINE_TEST(T, F, NAME, FINDDATA, FINDFIRST, FINDNEXT) \
static int NAME(void) \
{ \
@@ -20,8 +71,10 @@ static int NAME(void) \
return 1; \
} \
printf (F "\n", d.name); \
+ STAT_TEST (d, F, FINDFIRST); \
while (FINDNEXT (handle, &d) == 0) { \
printf (F "\n", d.name); \
+ STAT_TEST (d, F, FINDNEXT); \
} \
if (errno != ENOENT) { \
fprintf (stderr, "Error: Function %s failed: errno=%d (%s)\n", #FINDNEXT,
errno, strerror (errno)); \
--
2.20.1
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public