[PATCH 13/41] robocopy/tests: check if files are equal in source and destination
Florian Eder
others.meder at gmail.com
Mon Sep 6 09:54:50 CDT 2021
Checks if files are (correctly) overwritten if they already exist in the
destination folder, by checking whether the file size is equal in source
and destination
Signed-off-by: Florian Eder <others.meder at gmail.com>
---
programs/robocopy/tests/robocopy.c | 40 ++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/programs/robocopy/tests/robocopy.c b/programs/robocopy/tests/robocopy.c
index 433b65c587f..4bbf600e45a 100644
--- a/programs/robocopy/tests/robocopy.c
+++ b/programs/robocopy/tests/robocopy.c
@@ -172,8 +172,48 @@ static void check_folder_and_delete(const WCHAR *relative_path, BOOL should_exis
}
}
+static void check_files_equal(const WCHAR *relative_path_1, const WCHAR *relative_path_2, BOOL should_be_equal)
+{
+ WCHAR path_1[1024], path_2[1024];
+ HANDLE file_1, file_2;
+ LARGE_INTEGER size_1, size_2;
+ wcscpy(path_1, L"\\\\?\\");
+ GetTempPathW(ARRAY_SIZE(path_1) - 4, &(path_1[4]));
+ wcscpy(path_2, L"\\\\?\\");
+ GetTempPathW(ARRAY_SIZE(path_2) - 4, &(path_2[4]));
+ wcscat(path_1, relative_path_1);
+ wcscat(path_2, relative_path_2);
+ file_1 = CreateFileW(path_1, FILE_GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
+ file_2 = CreateFileW(path_2, FILE_GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
+ if (file_1 == INVALID_HANDLE_VALUE || file_2 == INVALID_HANDLE_VALUE)
+ {
+ ok(file_1 != INVALID_HANDLE_VALUE, "file \"%S\" does not exist, can't check equality with file \"%S\"\n", relative_path_1, relative_path_2);
+ ok(file_2 != INVALID_HANDLE_VALUE, "file \"%S\" does not exist, can't check equality with file \"%S\"\n", relative_path_2, relative_path_1);
+ CloseHandle(file_1);
+ CloseHandle(file_2);
+ return;
+ }
+ GetFileSizeEx(file_1, &size_1);
+ GetFileSizeEx(file_2, &size_2);
+ CloseHandle(file_1);
+ CloseHandle(file_2);
+ if (size_1.QuadPart == size_2.QuadPart)
+ {
+ ok(should_be_equal, "files \"%S\" and \"%S\" should be different, but are equal (size: %lld bytes)\n",
+ relative_path_1, relative_path_2, size_1.QuadPart);
+ }
+ else
+ {
+ ok(!should_be_equal, "files \"%S\" and \"%S\" should be equal, but are different (size: %lld bytes vs %lld bytes)\n",
+ relative_path_1, relative_path_2, size_1.QuadPart, size_2.QuadPart);
+ }
+}
+
static void check_basic_copy_test(void)
{
+ check_files_equal(L"robocopy_source\\fileA.a", L"robocopy_destination\\fileA.a", TRUE);
+ check_files_equal(L"robocopy_source\\fileB.b", L"robocopy_destination\\fileB.b", TRUE);
+
check_file_and_delete(L"robocopy_source\\fileA.a", TRUE);
check_file_and_delete(L"robocopy_source\\fileB.b", TRUE);
check_file_and_delete(L"robocopy_source\\folderA\\fileC.c", TRUE);
--
2.32.0
More information about the wine-devel
mailing list