diff options
author | Brian Dessent <brian@dessent.net> | 2008-03-09 04:10:10 +0000 |
---|---|---|
committer | Brian Dessent <brian@dessent.net> | 2008-03-09 04:10:10 +0000 |
commit | 59fb00ae07d9cfbfac3735f541149bed2c7625cb (patch) | |
tree | de577bf100b29e165aaddd3c7a2076b422feb7f7 /winsup/utils/testsuite.cc | |
parent | 68d2dd03a33cfa5c0feff6ce5618062a6ea3b613 (diff) | |
download | cygnal-59fb00ae07d9cfbfac3735f541149bed2c7625cb.tar.gz cygnal-59fb00ae07d9cfbfac3735f541149bed2c7625cb.tar.bz2 cygnal-59fb00ae07d9cfbfac3735f541149bed2c7625cb.zip |
* Makefile.in: Add a 'check' target that builds and runs
testsuite.exe from path-testsuite.o and testsuite.o.
* path.cc: Include testsuite.h.
(struct mnt): Change to a mnt_t typedef and don't define
mount_table when TESTSUITE is defined.
(find2): Don't include when TESTSUITE is defined to avoid warning.
(get_cygdrive0): Ditto.
(get_cygdrive): Ditto.
(read_mounts): Provide empty implementation when TESTSUITE is
defined.
(vconcat): Use the isslash macro.
(unconvert_slashes): New helper to convert to backslashses.
(rel_vconcat): Handle relative paths more gracefully.
(cygpath): Skip a leading "./" sequence. Avoid double-slashes.
Normalize final output to backslashes and remove redundant path
sequences.
* testsuite.cc: New file implementing testsuite driver.
* testsuite.h: New header implementing harness mount table and
series of tests.
Diffstat (limited to 'winsup/utils/testsuite.cc')
-rw-r--r-- | winsup/utils/testsuite.cc | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/winsup/utils/testsuite.cc b/winsup/utils/testsuite.cc new file mode 100644 index 000000000..b87f85cf8 --- /dev/null +++ b/winsup/utils/testsuite.cc @@ -0,0 +1,89 @@ +/* testsuite.cc + + Copyright 2008 Red Hat, Inc. + +This file is part of Cygwin. + +This software is a copyrighted work licensed under the terms of the +Cygwin license. Please consult the file "CYGWIN_LICENSE" for +details. */ + +/* This file implements a driver for performing tests on the file/path + translation code in path.cc. This file is meant to be generic, all + test harness data is in testsuite.h. */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#define TESTSUITE +#include "testsuite.h" + +typedef struct + { + const char *cwd; /* in win32 form, as if by GetCurrentDirectory */ + const char *posix; /* input */ + const char *win32; /* expected output */ + } test_t; + +#define TESTSUITE_TESTS +#include "testsuite.h" +#undef TESTSUITE_TESTS + +static int curtest; + +/* A replacement for the w32api GetCurrentDirectory() that returns + the cwd that the current test specifies. */ +DWORD +testsuite_getcwd (DWORD nBufferLength, LPSTR lpBuffer) +{ + unsigned len = strlen (testsuite_tests[curtest].cwd) + 1; + + /* If the test specified NO_CWD, then it means we should not have + needed the CWD for that test as the test was for an absolute path, + and so if we see that here return 0, simulating a + GetCurrentDirectory() error. */ + if (strcmp (testsuite_tests[curtest].cwd, NO_CWD) == 0) + return 0; + + if (nBufferLength >= len) + { + strcpy (lpBuffer, testsuite_tests[curtest].cwd); + return len - 1; + } + return len; +} + +extern char *cygpath (const char *s, ...); + +int +main (int argc, char **argv) +{ + int numpass = 0; + + for (test_t &t = testsuite_tests[curtest]; t.posix; t = testsuite_tests[++curtest]) + { + char *result = cygpath (t.posix, NULL); + bool pass = (strcmp (result, t.win32) == 0); + + if (pass) + { + numpass++; + printf ("test %03d: PASS cwd=%-18s input=%-22s expected+actual=%s\n", + curtest, t.cwd, t.posix, result); + } + else + { + printf ("test %03d: FAIL cwd=%-18s input=%-29s expected=%-25s actual=%s\n", + curtest, t.cwd, t.posix, t.win32, result); + } + } + printf ("\n" + "total tests: %d\n" + "pass : %d (%.1f%%)\n" + "fail : %d (%.1f%%)\n", + curtest, numpass, ((float)numpass)/curtest * 100.0F, curtest - numpass, + ((float)curtest - numpass)/curtest * 100.0F); + return (numpass < curtest ? 1 : 0); +} |