mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-06 12:27:09 +00:00
scrrun/tests: Introduce a test_file_contents helper.
This commit is contained in:
parent
cb254cb5f4
commit
7b44c6895f
|
@ -62,6 +62,32 @@ static inline void get_temp_path(const WCHAR *prefix, WCHAR *path)
|
||||||
DeleteFileW(path);
|
DeleteFileW(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define test_file_contents(a, b, c) _test_file_contents(a, b, c, __LINE__)
|
||||||
|
static void _test_file_contents(LPCWSTR pathW, DWORD expected_size, const void * expected_contents, int line)
|
||||||
|
{
|
||||||
|
HANDLE file;
|
||||||
|
BOOL ret;
|
||||||
|
DWORD actual_size;
|
||||||
|
|
||||||
|
file = CreateFileW(pathW, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
ok_(__FILE__,line) (file != INVALID_HANDLE_VALUE, "got %p\n", file);
|
||||||
|
|
||||||
|
actual_size = GetFileSize(file,NULL);
|
||||||
|
ok_(__FILE__,line) (actual_size == expected_size, "expected file %s size %ld, got %ld\n", wine_dbgstr_w(pathW), expected_size, actual_size);
|
||||||
|
|
||||||
|
if((expected_contents != NULL) && (actual_size > 0))
|
||||||
|
{
|
||||||
|
DWORD r;
|
||||||
|
void *actual_contents = malloc(actual_size);
|
||||||
|
ret = ReadFile(file, actual_contents, actual_size, &r, NULL);
|
||||||
|
ok_(__FILE__,line) (ret && r == actual_size, "Read %ld, got %d, error %ld.\n", r, ret, GetLastError());
|
||||||
|
ok_(__FILE__,line) (!memcmp(expected_contents, actual_contents, expected_size), "expected file %s contents %s, got %s\n", wine_dbgstr_w(pathW), wine_dbgstr_an(expected_contents,expected_size), wine_dbgstr_an(actual_contents,r));
|
||||||
|
free(actual_contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseHandle(file);
|
||||||
|
}
|
||||||
|
|
||||||
static IDrive *get_fixed_drive(void)
|
static IDrive *get_fixed_drive(void)
|
||||||
{
|
{
|
||||||
IDriveCollection *drives;
|
IDriveCollection *drives;
|
||||||
|
@ -1507,13 +1533,12 @@ static void get_temp_filepath(const WCHAR *filename, WCHAR *path, WCHAR *dir)
|
||||||
|
|
||||||
static void test_CreateTextFile(void)
|
static void test_CreateTextFile(void)
|
||||||
{
|
{
|
||||||
WCHAR pathW[MAX_PATH], dirW[MAX_PATH], buffW[10];
|
WCHAR pathW[MAX_PATH], dirW[MAX_PATH];
|
||||||
ITextStream *stream;
|
ITextStream *stream;
|
||||||
BSTR nameW, str;
|
BSTR nameW, str;
|
||||||
HANDLE file;
|
HANDLE file;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
DWORD r;
|
|
||||||
|
|
||||||
get_temp_filepath(testfileW, pathW, dirW);
|
get_temp_filepath(testfileW, pathW, dirW);
|
||||||
|
|
||||||
|
@ -1563,15 +1588,7 @@ static void test_CreateTextFile(void)
|
||||||
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
|
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
|
||||||
ITextStream_Release(stream);
|
ITextStream_Release(stream);
|
||||||
|
|
||||||
/* check contents */
|
test_file_contents(pathW,2,L"\ufeff");
|
||||||
file = CreateFileW(pathW, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
||||||
ok(file != INVALID_HANDLE_VALUE, "got %p\n", file);
|
|
||||||
r = 0;
|
|
||||||
ret = ReadFile(file, buffW, sizeof(buffW), &r, NULL);
|
|
||||||
ok(ret && r == 2, "Read %ld, got %d, error %ld.\n", r, ret, GetLastError());
|
|
||||||
|
|
||||||
ok( buffW[0] == 0xfeff, "got %04x\n", buffW[0] );
|
|
||||||
CloseHandle(file);
|
|
||||||
|
|
||||||
DeleteFileW(nameW);
|
DeleteFileW(nameW);
|
||||||
RemoveDirectoryW(dirW);
|
RemoveDirectoryW(dirW);
|
||||||
|
@ -1580,14 +1597,13 @@ static void test_CreateTextFile(void)
|
||||||
|
|
||||||
static void test_FolderCreateTextFile(void)
|
static void test_FolderCreateTextFile(void)
|
||||||
{
|
{
|
||||||
WCHAR pathW[MAX_PATH], dirW[MAX_PATH], buffW[10], buff2W[10];
|
WCHAR pathW[MAX_PATH], dirW[MAX_PATH];
|
||||||
ITextStream *stream;
|
ITextStream *stream;
|
||||||
BSTR nameW, str;
|
BSTR nameW, str;
|
||||||
HANDLE file;
|
HANDLE file;
|
||||||
IFolder *folder;
|
IFolder *folder;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
DWORD r;
|
|
||||||
|
|
||||||
get_temp_filepath(testfileW, pathW, dirW);
|
get_temp_filepath(testfileW, pathW, dirW);
|
||||||
nameW = SysAllocString(L"foo.txt");
|
nameW = SysAllocString(L"foo.txt");
|
||||||
|
@ -1640,18 +1656,7 @@ static void test_FolderCreateTextFile(void)
|
||||||
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
|
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
|
||||||
ITextStream_Release(stream);
|
ITextStream_Release(stream);
|
||||||
|
|
||||||
/* check contents */
|
test_file_contents(pathW,2,L"\ufeff");
|
||||||
file = CreateFileW(pathW, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
||||||
ok(file != INVALID_HANDLE_VALUE, "got %p\n", file);
|
|
||||||
r = 0;
|
|
||||||
ret = ReadFile(file, buffW, sizeof(buffW), &r, NULL);
|
|
||||||
ok(ret && r == 2, "Read %ld, got %d, error %ld.\n", r, ret, GetLastError());
|
|
||||||
buffW[r/sizeof(WCHAR)] = 0;
|
|
||||||
|
|
||||||
buff2W[0] = 0xfeff;
|
|
||||||
buff2W[1] = 0;
|
|
||||||
ok(!lstrcmpW(buff2W, buffW), "got %s, expected %s\n", wine_dbgstr_w(buffW), wine_dbgstr_w(buff2W));
|
|
||||||
CloseHandle(file);
|
|
||||||
|
|
||||||
DeleteFileW(pathW);
|
DeleteFileW(pathW);
|
||||||
RemoveDirectoryW(dirW);
|
RemoveDirectoryW(dirW);
|
||||||
|
@ -1661,11 +1666,10 @@ static void test_FolderCreateTextFile(void)
|
||||||
static void test_WriteLine(void)
|
static void test_WriteLine(void)
|
||||||
{
|
{
|
||||||
WCHAR pathW[MAX_PATH], dirW[MAX_PATH];
|
WCHAR pathW[MAX_PATH], dirW[MAX_PATH];
|
||||||
WCHAR buffW[MAX_PATH], buff2W[MAX_PATH];
|
WCHAR ExpectedW[MAX_PATH];
|
||||||
char buffA[MAX_PATH];
|
char ExpectedA[MAX_PATH];
|
||||||
ITextStream *stream;
|
ITextStream *stream;
|
||||||
DWORD r, len;
|
DWORD len;
|
||||||
HANDLE file;
|
|
||||||
BSTR nameW;
|
BSTR nameW;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
|
@ -1684,19 +1688,10 @@ static void test_WriteLine(void)
|
||||||
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
|
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
|
||||||
ITextStream_Release(stream);
|
ITextStream_Release(stream);
|
||||||
|
|
||||||
/* check contents */
|
len = WideCharToMultiByte(CP_ACP, 0, nameW, -1, ExpectedA, ARRAY_SIZE(ExpectedA)-2, NULL, NULL);
|
||||||
file = CreateFileW(pathW, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
ok(len > 0, "got %ld", len);
|
||||||
ok(file != INVALID_HANDLE_VALUE, "got %p\n", file);
|
lstrcatA(ExpectedA, "\r\n");
|
||||||
r = 0;
|
test_file_contents(pathW,lstrlenA(ExpectedA),ExpectedA);
|
||||||
ret = ReadFile(file, buffA, sizeof(buffA), &r, NULL);
|
|
||||||
ok(ret && r, "Read %ld, got %d, error %ld.\n", r, ret, GetLastError());
|
|
||||||
|
|
||||||
len = MultiByteToWideChar(CP_ACP, 0, buffA, r, buffW, ARRAY_SIZE(buffW));
|
|
||||||
buffW[len] = 0;
|
|
||||||
lstrcpyW(buff2W, nameW);
|
|
||||||
lstrcatW(buff2W, L"\r\n");
|
|
||||||
ok(!lstrcmpW(buff2W, buffW), "got %s, expected %s\n", wine_dbgstr_w(buffW), wine_dbgstr_w(buff2W));
|
|
||||||
CloseHandle(file);
|
|
||||||
DeleteFileW(nameW);
|
DeleteFileW(nameW);
|
||||||
|
|
||||||
/* same for unicode file */
|
/* same for unicode file */
|
||||||
|
@ -1707,20 +1702,10 @@ static void test_WriteLine(void)
|
||||||
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
|
ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
|
||||||
ITextStream_Release(stream);
|
ITextStream_Release(stream);
|
||||||
|
|
||||||
/* check contents */
|
lstrcpyW(ExpectedW, L"\ufeff");
|
||||||
file = CreateFileW(pathW, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
lstrcatW(ExpectedW, nameW);
|
||||||
ok(file != INVALID_HANDLE_VALUE, "got %p\n", file);
|
lstrcatW(ExpectedW, L"\r\n");
|
||||||
r = 0;
|
test_file_contents(pathW,lstrlenW(ExpectedW)*sizeof(WCHAR),ExpectedW);
|
||||||
ret = ReadFile(file, buffW, sizeof(buffW), &r, NULL);
|
|
||||||
ok(ret && r, "Read %ld, got %d, error %ld.\n", r, ret, GetLastError());
|
|
||||||
buffW[r/sizeof(WCHAR)] = 0;
|
|
||||||
|
|
||||||
buff2W[0] = 0xfeff;
|
|
||||||
buff2W[1] = 0;
|
|
||||||
lstrcatW(buff2W, nameW);
|
|
||||||
lstrcatW(buff2W, L"\r\n");
|
|
||||||
ok(!lstrcmpW(buff2W, buffW), "got %s, expected %s\n", wine_dbgstr_w(buffW), wine_dbgstr_w(buff2W));
|
|
||||||
CloseHandle(file);
|
|
||||||
DeleteFileW(nameW);
|
DeleteFileW(nameW);
|
||||||
|
|
||||||
RemoveDirectoryW(dirW);
|
RemoveDirectoryW(dirW);
|
||||||
|
|
Loading…
Reference in a new issue