]> sourceware.org Git - newlib-cygwin.git/blob - winsup/utils/testsuite.cc
Cygwin: Fix remaining warnings building path testsuite
[newlib-cygwin.git] / winsup / utils / testsuite.cc
1 /* testsuite.cc
2
3 This file is part of Cygwin.
4
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
7 details. */
8
9 /* This file implements a driver for performing tests on the file/path
10 translation code in path.cc. This file is meant to be generic, all
11 test harness data is in testsuite.h. */
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <unistd.h>
16 #define WIN32_LEAN_AND_MEAN
17 #include <windows.h>
18 #ifndef TESTSUITE
19 #define TESTSUITE
20 #endif
21 #include "testsuite.h"
22
23 typedef struct
24 {
25 const char *cwd; /* in win32 form, as if by GetCurrentDirectory */
26 const char *posix; /* input */
27 const char *win32; /* expected output */
28 } test_t;
29
30 #define TESTSUITE_TESTS
31 #include "testsuite.h"
32 #undef TESTSUITE_TESTS
33
34 static int curtest;
35
36 /* A replacement for the w32api GetCurrentDirectory() that returns
37 the cwd that the current test specifies. */
38 DWORD
39 testsuite_getcwd (DWORD nBufferLength, LPSTR lpBuffer)
40 {
41 unsigned len = strlen (testsuite_tests[curtest].cwd) + 1;
42
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)
48 return 0;
49
50 if (nBufferLength >= len)
51 {
52 strcpy (lpBuffer, testsuite_tests[curtest].cwd);
53 return len - 1;
54 }
55 return len;
56 }
57
58 extern char *cygpath (const char *s, ...);
59
60 int
61 main (int argc, char **argv)
62 {
63 int numpass = 0;
64
65 for (test_t &t = testsuite_tests[curtest]; t.posix; t = testsuite_tests[++curtest])
66 {
67 char *result = cygpath (t.posix, NULL);
68 bool pass = (strcmp (result, t.win32) == 0);
69
70 if (pass)
71 {
72 numpass++;
73 printf ("test %03d: PASS cwd=%-18s input=%-22s expected+actual=%s\n",
74 curtest, t.cwd, t.posix, result);
75 }
76 else
77 {
78 printf ("test %03d: FAIL cwd=%-18s input=%-29s expected=%-25s actual=%s\n",
79 curtest, t.cwd, t.posix, t.win32, result);
80 }
81 }
82 printf ("\n"
83 "total tests: %d\n"
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);
89 }
This page took 0.043695 seconds and 6 git commands to generate.