3 Copyright 2008 Red Hat, Inc.
5 This file is part of Cygwin.
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
11 /* This file implements a driver for performing tests on the file/path
12 translation code in path.cc. This file is meant to be generic, all
13 test harness data is in testsuite.h. */
18 #define WIN32_LEAN_AND_MEAN
21 #include "testsuite.h"
25 const char *cwd; /* in win32 form, as if by GetCurrentDirectory */
26 const char *posix; /* input */
27 const char *win32; /* expected output */
30 #define TESTSUITE_TESTS
31 #include "testsuite.h"
32 #undef TESTSUITE_TESTS
36 /* A replacement for the w32api GetCurrentDirectory() that returns
37 the cwd that the current test specifies. */
39 testsuite_getcwd (DWORD nBufferLength, LPSTR lpBuffer)
41 unsigned len = strlen (testsuite_tests[curtest].cwd) + 1;
43 /* If the test specified NO_CWD, then it means we should not have
44 needed the CWD for that test as the test was for an absolute path,
45 and so if we see that here return 0, simulating a
46 GetCurrentDirectory() error. */
47 if (strcmp (testsuite_tests[curtest].cwd, NO_CWD) == 0)
50 if (nBufferLength >= len)
52 strcpy (lpBuffer, testsuite_tests[curtest].cwd);
58 extern char *cygpath (const char *s, ...);
61 main (int argc, char **argv)
65 for (test_t &t = testsuite_tests[curtest]; t.posix; t = testsuite_tests[++curtest])
67 char *result = cygpath (t.posix, NULL);
68 bool pass = (strcmp (result, t.win32) == 0);
73 printf ("test %03d: PASS cwd=%-18s input=%-22s expected+actual=%s\n",
74 curtest, t.cwd, t.posix, result);
78 printf ("test %03d: FAIL cwd=%-18s input=%-29s expected=%-25s actual=%s\n",
79 curtest, t.cwd, t.posix, t.win32, result);
84 "pass : %d (%.1f%%)\n"
85 "fail : %d (%.1f%%)\n",
86 curtest, numpass, ((float)numpass)/curtest * 100.0F, curtest - numpass,
87 ((float)curtest - numpass)/curtest * 100.0F);
88 return (numpass < curtest ? 1 : 0);