Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- v2: fix a test failure with Windows XP
dlls/kernel32/tests/file.c | 82 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+)
diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c index 110082a9c4f..1f704337877 100644 --- a/dlls/kernel32/tests/file.c +++ b/dlls/kernel32/tests/file.c @@ -117,6 +117,13 @@ static void InitFunctionPointers(void) pFindFirstStreamW = (void *)GetProcAddress(hkernel32, "FindFirstStreamW"); }
+static void create_file( const char *path ) +{ + FILE *f = fopen( path, "wb" ); + fputs( path, f ); + fclose( f ); +} + static void test__hread( void ) { HFILE filehandle; @@ -5510,6 +5517,80 @@ static void test_SetFileTime(void) CloseHandle(hfile); }
+static void test_hard_link(void) +{ + char cwd[MAX_PATH], temp_dir[MAX_PATH], name_buffer[200], buffer[20]; + FILE_NAME_INFORMATION *name_info = (FILE_NAME_INFORMATION *)name_buffer; + IO_STATUS_BLOCK io; + NTSTATUS status; + HANDLE file; + DWORD size; + BOOL ret; + + GetCurrentDirectoryA( sizeof(cwd), cwd ); + GetTempPathA( sizeof(temp_dir), temp_dir ); + SetCurrentDirectoryA( temp_dir ); + + ret = CreateDirectoryA( "winetest_dir1", NULL ); + ok(ret, "failed to create directory, error %u\n", GetLastError()); + ret = CreateDirectoryA( "winetest_dir2", NULL ); + ok(ret, "failed to create directory, error %u\n", GetLastError()); + create_file( "winetest_file1" ); + create_file( "winetest_file2" ); + + ret = CreateHardLinkA( "winetest_file3", "winetest_file1", NULL ); + ok(ret, "got error %u\n", GetLastError()); + + file = CreateFileA( "winetest_file3", FILE_READ_DATA, 0, NULL, OPEN_EXISTING, 0, NULL ); + ok(file != INVALID_HANDLE_VALUE, "got error %u\n", GetLastError()); + + status = NtQueryInformationFile( file, &io, name_buffer, sizeof(name_buffer), FileNameInformation ); + ok(!status, "got status %#x\n", status); + ok(!wcsncmp(name_info->FileName + (name_info->FileNameLength / sizeof(WCHAR)) - wcslen(L"\winetest_file3"), + L"\winetest_file3", wcslen(L"\winetest_file3")), "got name %s\n", + debugstr_wn(name_info->FileName, name_info->FileNameLength / sizeof(WCHAR))); + + ret = ReadFile( file, buffer, sizeof(buffer), &size, NULL ); + ok(ret, "got error %u\n", GetLastError()); + ok(!memcmp( buffer, "winetest_file1", size ), "got file contents %s\n", debugstr_an( buffer, size )); + + CloseHandle( file ); + + ret = DeleteFileA( "winetest_file3" ); + ok(ret, "failed to delete file, error %u\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = CreateHardLinkA( "winetest_file2", "winetest_file1", NULL ); + ok(!ret, "expected failure\n"); + ok(GetLastError() == ERROR_ALREADY_EXISTS, "got error %u\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = CreateHardLinkA( "winetest_file3", "winetest_dir1", NULL ); + ok(!ret, "expected failure\n"); + ok(GetLastError() == ERROR_ACCESS_DENIED, "got error %u\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = CreateHardLinkA( "winetest_dir2", "winetest_dir1", NULL ); + ok(!ret, "expected failure\n"); + ok(GetLastError() == ERROR_ACCESS_DENIED + || GetLastError() == ERROR_ALREADY_EXISTS /* XP */, "got error %u\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = CreateHardLinkA( "winetest_dir1", "winetest_file1", NULL ); + ok(!ret, "expected failure\n"); + ok(GetLastError() == ERROR_ALREADY_EXISTS, "got error %u\n", GetLastError()); + + ret = RemoveDirectoryA( "winetest_dir1" ); + ok(ret, "failed to remove directory, error %u\n", GetLastError()); + ret = RemoveDirectoryA( "winetest_dir2" ); + ok(ret, "failed to remove directory, error %u\n", GetLastError()); + ret = DeleteFileA( "winetest_file1" ); + ok(ret, "failed to delete file, error %u\n", GetLastError()); + ret = DeleteFileA( "winetest_file2" ); + ok(ret, "failed to delete file, error %u\n", GetLastError()); + SetCurrentDirectoryA( cwd ); +} + START_TEST(file) { char temp_path[MAX_PATH]; @@ -5584,4 +5665,5 @@ START_TEST(file) test_find_file_stream(); test_SetFileTime(); test_ReOpenFile(); + test_hard_link(); }