On 4/2/2011 10:51, Vincent Pelletier wrote:
> Add tests via FindFirstFileA.
> Fixes bug 22635.
> ---
> dlls/kernel32/tests/file.c | 119 ++++++++++++++++++++++++++++++++++++++++++++
> dlls/ntdll/path.c | 8 +++-
> 2 files changed, 126 insertions(+), 1 deletions(-)
>
> diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c
> index 4e8136a..dae8eee 100644
> --- a/dlls/kernel32/tests/file.c
> +++ b/dlls/kernel32/tests/file.c
> @@ -2164,6 +2164,125 @@ static void test_FindFirstFileA(void)
> err = GetLastError();
> ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should Fail\n", buffer2 );
> ok ( err == ERROR_PATH_NOT_FOUND, "Bad Error number %d\n", err );
> +
> + /* try FindFirstFileA on "test-dir" with forbidden chars */
> + CreateDirectoryA("test-dir", NULL);
> + _lclose(_lcreat("test-file", 0));
> +
> +#define FindFirstFileA_ok(value, caption, todo) { \
> + if(todo) { \
> + todo_wine ok(value, caption);\
> + } else { \
> + ok(value, caption);\
> + } \
> + }
> +
> +#define test_FindFirstFileA_with(x, y, todo) { \
> + handle = FindFirstFileA(x,&data);\
> + if (y) { \
> + FindFirstFileA_ok( \
> + handle != INVALID_HANDLE_VALUE, \
> + "FindFirstFile on "x" should succeed\n", \
> + todo);\
> + } else { \
> + FindFirstFileA_ok( \
> + handle == INVALID_HANDLE_VALUE, \
> + "FindFirstFile on "x" should fail\n", \
> + todo);\
> + } \
> + if (handle != INVALID_HANDLE_VALUE) \
> + ok( FindClose(handle) == TRUE, "Failed to close handle "x"\n"); \
> + }
> +
> + /* Disallowed chars being ignored: */
> + test_FindFirstFileA_with("test-dir/.", 1, 0);
> + test_FindFirstFileA_with("test-dir\\.", 1, 0);
> + test_FindFirstFileA_with("test-dir<.", 1, 0);
> + test_FindFirstFileA_with("test-dir< ", 1, 0);
> + test_FindFirstFileA_with("test-dir>.", 1, 0);
> + test_FindFirstFileA_with("test-dir> ", 1, 0);
> + test_FindFirstFileA_with("test-dir\".", 1, 0);
> + test_FindFirstFileA_with("test-dir\" ", 1, 0);
> + test_FindFirstFileA_with("test-dir/>", 1, 0);
> + test_FindFirstFileA_with("test-dir/<", 1, 0);
> + test_FindFirstFileA_with("test-dir/\"", 1, 0);
> + test_FindFirstFileA_with("test-dir<>", 1, 0);
> + test_FindFirstFileA_with("test-dir<<", 1, 0);
> + test_FindFirstFileA_with("test-dir<\"", 1, 0);
> + test_FindFirstFileA_with("test-dir>>", 1, 0);
> + test_FindFirstFileA_with("test-dir><", 1, 0);
> + test_FindFirstFileA_with("test-dir>\"", 1, 0);
> + test_FindFirstFileA_with("test-dir\">", 1, 0);
> + test_FindFirstFileA_with("test-dir\"<", 1, 0);
> + test_FindFirstFileA_with("test-dir\"\"", 1, 0);
> + test_FindFirstFileA_with("test-dir\\<", 1, 0);
> + test_FindFirstFileA_with("test-dir\\>", 1, 0);
> + test_FindFirstFileA_with("test-dir\\\"", 1, 0);
> + /* But space prevents forward& back slashes from being stripped */
> + test_FindFirstFileA_with("test-dir<", 0, 1);
> + test_FindFirstFileA_with("test-dir/ ", 0, 0);
> + test_FindFirstFileA_with("test-dir/ .", 0, 0);
> + test_FindFirstFileA_with("test-dir/. ", 0, 1);
> + test_FindFirstFileA_with("test-dir\\ ", 0, 0);
> + test_FindFirstFileA_with("test-dir\\ .", 0, 0);
> + test_FindFirstFileA_with("test-dir\\. ", 0, 1);
> + test_FindFirstFileA_with("test-dir/. ", 0, 1);
> + test_FindFirstFileA_with("test-dir\\. ", 0, 1);
> + /* But forward& back slashes are not tolerated on a file */
> + test_FindFirstFileA_with("test-file/>", 0, 1);
> + test_FindFirstFileA_with("test-file/<", 0, 1);
> + test_FindFirstFileA_with("test-file/\"", 0, 1);
> + test_FindFirstFileA_with("test-file<>", 1, 0);
> + test_FindFirstFileA_with("test-file<<", 1, 0);
> + test_FindFirstFileA_with("test-file<\"", 1, 0);
> + test_FindFirstFileA_with("test-file>>", 1, 0);
> + test_FindFirstFileA_with("test-file><", 1, 0);
> + test_FindFirstFileA_with("test-file>\"", 1, 0);
> + test_FindFirstFileA_with("test-file\">", 1, 0);
> + test_FindFirstFileA_with("test-file\"<", 1, 0);
> + test_FindFirstFileA_with("test-file\"\"", 1, 0);
> + test_FindFirstFileA_with("test-file\\<", 0, 1);
> + test_FindFirstFileA_with("test-file\\>", 0, 1);
> + test_FindFirstFileA_with("test-file\\\"", 0, 1);
> + /* Even when many */
> + test_FindFirstFileA_with("test-dir\"\"\"\"\"", 1, 0);
> + test_FindFirstFileA_with("test-dir<<<><><>\"\"\"\"<<<>", 1, 0);
> + /* But only in the end of path */
> + test_FindFirstFileA_with("test-/>dir", 0, 0);
> + test_FindFirstFileA_with("/>test-dir", 0, 0);
> + test_FindFirstFileA_with(">test-dir", 0, 0);
> + test_FindFirstFileA_with(">>test-dir", 0, 0);
> + test_FindFirstFileA_with(">test->dir", 0, 0);
> + test_FindFirstFileA_with("><test->dir", 0, 0);
> + test_FindFirstFileA_with("<test->dir", 0, 0);
> + test_FindFirstFileA_with("<\"test->dir", 0, 0);
> +
> + /* Slash after ignored chars is not ignored: */
> + test_FindFirstFileA_with("test-dir//", 0, 0);
> + test_FindFirstFileA_with("test-dir</", 0, 0);
> + test_FindFirstFileA_with("test-dir>/", 0, 0);
> + test_FindFirstFileA_with("test-dir\"/", 0, 0);
> + test_FindFirstFileA_with("test-dir\\", 0, 0);
> + test_FindFirstFileA_with("test-dir\\\\", 0, 0);
> + test_FindFirstFileA_with("test-dir\\/", 0, 0);
> + test_FindFirstFileA_with("test-dir/\\", 0, 0);
> +
> + /* Disalowed chars being preserved: */
> + test_FindFirstFileA_with("test-dir/:", 0, 0);
> + test_FindFirstFileA_with("test-dir/|", 0, 0);
> +
> + /* Slashes converted to backslashes */
> + test_FindFirstFileA_with("test-dir/", 0, 0);
> + test_FindFirstFileA_with("./test-dir", 1, 0);
> + test_FindFirstFileA_with("./test-dir/", 0, 0);
> + test_FindFirstFileA_with("test-dir\\", 0, 0);
> + test_FindFirstFileA_with(".\\test-dir", 1, 0);
> + test_FindFirstFileA_with(".\\test-dir\\", 0, 0);
> +
> +#undef test_FindFirstFileA_with
> +#undef FindFirstFileA_ok
> + DeleteFileA("test-file");
> + RemoveDirectoryA("test-dir");
> }
Please use table for test data and put your macro body in a loop.