find/tests: Add tests for file based search.

Signed-off-by: Fabian Maurer <dark.shadow4@web.de>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Fabian Maurer 2020-01-28 21:41:00 +01:00 committed by Alexandre Julliard
parent 0ca19c3cfb
commit c74770c51b
1 changed files with 112 additions and 10 deletions

View File

@ -180,10 +180,44 @@ static void run_find_stdin_(const WCHAR *commandline, const BYTE *input, int inp
heap_free(child_output);
}
#define run_find_stdin_str(commandline, input, out_expected, exitcode_expected) \
run_find_stdin_str_(commandline, input, out_expected, exitcode_expected, __FILE__, __LINE__)
static void run_find_file_(const WCHAR *commandline, const BYTE *input, int input_len, const BYTE *out_expected, int out_expected_len, int exitcode_expected, const char *file, int line)
{
char path_temp_file[MAX_PATH];
char path_temp_dir[MAX_PATH];
HANDLE handle_file;
WCHAR commandline_new[MAX_PATH];
BYTE *out_expected_new;
char header[MAX_PATH];
int header_len;
static void run_find_stdin_str_(const char *commandline, const char *input, const char *out_expected, int exitcode_expected, const char *file, int line)
GetTempPathA(ARRAY_SIZE(path_temp_dir), path_temp_dir);
GetTempFileNameA(path_temp_dir, "", 0, path_temp_file);
handle_file = CreateFileA(path_temp_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
write_to_handle(handle_file, input, input_len);
CloseHandle(handle_file);
wsprintfW(commandline_new, L"%s %hs", commandline, path_temp_file);
CharUpperA(path_temp_file);
wsprintfA(header, "\r\n---------- %s\r\n", path_temp_file);
header_len = lstrlenA(header);
out_expected_new = heap_alloc(header_len + out_expected_len);
memcpy(out_expected_new, header, header_len);
memcpy(out_expected_new + header_len, out_expected, out_expected_len);
run_find_stdin_(commandline_new, (BYTE*)"", 0, out_expected_new, header_len + out_expected_len, exitcode_expected, file, line);
heap_free(out_expected_new);
DeleteFileA(path_temp_file);
}
#define run_find_stdin_str(commandline, input, out_expected, exitcode_expected) \
run_find_str_(commandline, input, out_expected, exitcode_expected, 0, __FILE__, __LINE__)
#define run_find_file_str(commandline, input, out_expected, exitcode_expected) \
run_find_str_(commandline, input, out_expected, exitcode_expected, 1, __FILE__, __LINE__)
static void run_find_str_(const char *commandline, const char *input, const char *out_expected, int exitcode_expected, BOOL is_file, const char *file, int line)
{
WCHAR *commandlineW;
int len_commandlineW;
@ -193,15 +227,20 @@ static void run_find_stdin_str_(const char *commandline, const char *input, cons
commandlineW = heap_alloc(len_commandlineW * sizeof(WCHAR));
MultiByteToWideChar(CP_UTF8, 0, commandline, -1, commandlineW, len_commandlineW);
run_find_stdin_(commandlineW, (BYTE *)input, lstrlenA(input), (BYTE *)out_expected, lstrlenA(out_expected), exitcode_expected, file, line);
if (is_file)
run_find_file_(commandlineW, (BYTE *)input, lstrlenA(input), (BYTE *)out_expected, lstrlenA(out_expected), exitcode_expected, file, line);
else
run_find_stdin_(commandlineW, (BYTE *)input, lstrlenA(input), (BYTE *)out_expected, lstrlenA(out_expected), exitcode_expected, file, line);
heap_free(commandlineW);
}
#define run_find_stdin_unicode(input, out_expected, exitcode_expected) \
run_find_stdin_unicode_(input, sizeof(input), out_expected, sizeof(out_expected), exitcode_expected, __FILE__, __LINE__)
run_find_unicode_(input, sizeof(input), out_expected, sizeof(out_expected), exitcode_expected, 0, __FILE__, __LINE__)
static void run_find_stdin_unicode_(const BYTE *input, int input_len, const BYTE *out_expected, int out_expected_len, int exitcode_expected, const char *file, int line)
#define run_find_file_unicode(input, out_expected, exitcode_expected) \
run_find_unicode_(input, sizeof(input), out_expected, sizeof(out_expected), exitcode_expected, 1, __FILE__, __LINE__)
static void run_find_unicode_(const BYTE *input, int input_len, const BYTE *out_expected, int out_expected_len, int exitcode_expected, BOOL is_file, const char *file, int line)
{
/* Need "test" as char and quoted wchar */
static const WCHAR wstr_quoted_test[] = { '"','t', 'e', 's', 't','"',0 };
@ -219,7 +258,10 @@ static void run_find_stdin_unicode_(const BYTE *input, int input_len, const BYTE
exitcode_expected = 1;
}
run_find_stdin_(wstr_quoted_test, input, input_len, out_expected_mangled, out_expected_mangled_len, exitcode_expected, file, line);
if (is_file)
run_find_file_(wstr_quoted_test, input, input_len, out_expected_mangled, out_expected_mangled_len, exitcode_expected, file, line);
else
run_find_stdin_(wstr_quoted_test, input, input_len, out_expected_mangled, out_expected_mangled_len, exitcode_expected, file, line);
}
static void test_errors(void)
@ -230,6 +272,8 @@ static void test_errors(void)
todo_wine /* Quotes are not properly passed into wine yet */
run_find_stdin_str("\"test", "", "FIND: Parameter format not correct\r\n", 2);
run_find_stdin_str("\"test\" /XYZ", "", "FIND: Invalid switch\r\n", 2);
todo_wine
run_find_stdin_str("\"test\" C:\\doesnotexist.dat", "", "File not found - C:\\DOESNOTEXIST.DAT\r\n", 1);
}
static void test_singleline_without_switches(void)
@ -272,7 +316,7 @@ static const BYTE str_rus_utf8_nobom[] = { 0xD0,0xBF,0xD1,0x
static const BYTE str_en_utf8_bom[] = { 0xEF,0xBB,0xBF,'e','n','t','e','s','t','\r','\n' };
static const BYTE str_en_utf8_nobom[] = { 'e','n','t','e','s','t','\r','\n' };
static void test_unicode_support(void)
static void test_unicode_support_stdin(void)
{
/* Test unicode support on STDIN
* Those depend on the active codepage - e.g. 932 (japanese) behaves different from 1252 (latin)
@ -302,6 +346,62 @@ static void test_unicode_support(void)
run_find_stdin_unicode(str_jap_utf16le_bom, str_jap_utf16le_bom, 0);
}
static void test_file_search(void)
{
todo_wine
run_find_file_str("\"\"", "test", "", 1);
todo_wine
run_find_file_str("\"test\"", "", "", 1);
todo_wine
run_find_file_str("\"test\"", "test", "test\r\n", 0);
todo_wine
run_find_file_str("\"test\"", "test2", "test2\r\n", 0);
todo_wine
run_find_file_str("\"test\"", "test\r2", "test\r2\r\n", 0);
todo_wine
run_find_file_str("\"test2\"", "test", "", 1);
todo_wine
run_find_file_str("\"test\"", "test\nother\ntest2\ntest3", "test\r\ntest2\r\ntest3\r\n", 0);
}
static void test_unicode_support_file(void)
{
/* Test unicode support on files */
/* Test UTF-8 BOM */
todo_wine
run_find_file_unicode(str_en_utf8_nobom, str_en_utf8_nobom, 0);
todo_wine
run_find_file_unicode(str_en_utf8_bom, str_en_utf8_bom, 0);
/* Test russian characters */
todo_wine
run_find_file_unicode(str_rus_utf8_bom, str_rus_utf8_bom, 0);
todo_wine
run_find_file_unicode(str_rus_utf8_nobom, str_rus_utf8_nobom, 0);
/* Test japanese characters */
todo_wine
run_find_file_unicode(str_jap_utf8_nobom, str_jap_utf8_nobom, 0);
todo_wine
run_find_file_unicode(str_jap_utf8_bom, str_jap_utf8_bom, 0);
todo_wine
run_find_file_unicode(str_jap_shiftjis, str_jap_shiftjis, 0);
/* Test unsupported encodings */
todo_wine
run_find_file_unicode(str_jap_utf16le_nobom, str_empty, 1);
todo_wine
run_find_file_unicode(str_jap_utf16be_bom, str_empty, 1);
todo_wine
run_find_file_unicode(str_jap_utf16be_nobom, str_empty, 1);
/* Test utf16le */
todo_wine
run_find_file_unicode(str_jap_utf16le_bom, str_jap_utf16le_bom, 0);
}
START_TEST(find)
{
if (PRIMARYLANGID(GetUserDefaultUILanguage()) != LANG_ENGLISH)
@ -314,5 +414,7 @@ START_TEST(find)
}
test_singleline_without_switches();
test_multiline();
test_unicode_support();
test_unicode_support_stdin();
test_file_search();
test_unicode_support_file();
}