📄 shlfileop.c
字号:
set_curr_dir_path(to, "test4.txt\0"); ok(!SHFileOperationA(&shfo), "Rename dir back");}/* tests the FO_COPY action */void test_copy(void){ SHFILEOPSTRUCTA shfo, shfo2; CHAR from[MAX_PATH]; CHAR to[MAX_PATH]; FILEOP_FLAGS tmp_flags; DWORD retval; shfo.hwnd = NULL; shfo.wFunc = FO_COPY; shfo.pFrom = from; shfo.pTo = to; shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI; shfo.hNameMappings = NULL; shfo.lpszProgressTitle = NULL; set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0"); set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0"); ok(SHFileOperationA(&shfo), "Can't copy many files"); ok(!file_exists(".\\test6.txt"), "The file is not copied - many files are " "specified as a target"); memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA)); shfo2.fFlags |= FOF_MULTIDESTFILES; set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0"); set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0"); ok(!SHFileOperationA(&shfo2), "Can't copy many files"); ok(file_exists(".\\test6.txt"), "The file is copied - many files are " "specified as a target"); DeleteFileA(".\\test6.txt"); DeleteFileA(".\\test7.txt"); RemoveDirectoryA(".\\test8.txt"); /* number of sources do not correspond to number of targets */ set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0"); set_curr_dir_path(to, "test6.txt\0test7.txt\0"); ok(SHFileOperationA(&shfo2), "Can't copy many files"); ok(!file_exists(".\\test6.txt"), "The file is not copied - many files are " "specified as a target"); set_curr_dir_path(from, "test1.txt\0"); set_curr_dir_path(to, "test4.txt\0"); ok(!SHFileOperationA(&shfo), "Prepare test to check how directories are copied recursively"); ok(file_exists(".\\test4.txt\\test1.txt"), "The file is copied"); set_curr_dir_path(from, "test?.txt\0"); set_curr_dir_path(to, "testdir2\0"); ok(!file_exists(".\\testdir2\\test1.txt"), "The file is not copied yet"); ok(!file_exists(".\\testdir2\\test4.txt"), "The directory is not copied yet"); ok(!SHFileOperationA(&shfo), "Files and directories are copied to directory "); ok(file_exists(".\\testdir2\\test1.txt"), "The file is copied"); ok(file_exists(".\\testdir2\\test4.txt"), "The directory is copied"); ok(file_exists(".\\testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is copied"); clean_after_shfo_tests(); init_shfo_tests(); shfo.fFlags |= FOF_FILESONLY; ok(!file_exists(".\\testdir2\\test1.txt"), "The file is not copied yet"); ok(!file_exists(".\\testdir2\\test4.txt"), "The directory is not copied yet"); ok(!SHFileOperationA(&shfo), "Files are copied to other directory "); ok(file_exists(".\\testdir2\\test1.txt"), "The file is copied"); ok(!file_exists(".\\testdir2\\test4.txt"), "The directory is copied"); clean_after_shfo_tests(); init_shfo_tests(); set_curr_dir_path(from, "test1.txt\0test2.txt\0"); ok(!file_exists(".\\testdir2\\test1.txt"), "The file is not copied yet"); ok(!file_exists(".\\testdir2\\test2.txt"), "The file is not copied yet"); ok(!SHFileOperationA(&shfo), "Files are copied to other directory "); ok(file_exists(".\\testdir2\\test1.txt"), "The file is copied"); ok(file_exists(".\\testdir2\\test2.txt"), "The file is copied"); clean_after_shfo_tests(); /* Copying multiple files with one not existing as source, fails the entire operation in Win98/ME/2K/XP, but not in 95/NT */ init_shfo_tests(); tmp_flags = shfo.fFlags; set_curr_dir_path(from, "test1.txt\0test10.txt\0test2.txt\0"); ok(!file_exists(".\\testdir2\\test1.txt"), "The file is not copied yet"); ok(!file_exists(".\\testdir2\\test2.txt"), "The file is not copied yet"); retval = SHFileOperationA(&shfo); if (!retval) /* Win 95/NT returns success but copies only the files up to the non-existent source */ ok(file_exists(".\\testdir2\\test1.txt"), "The file is not copied"); else { /* Win 98/ME/2K/XP fail the entire operation with return code 1026 if one source file does not exist */ ok(retval == 1026, "Files are copied to other directory "); ok(!file_exists(".\\testdir2\\test1.txt"), "The file is copied"); } ok(!file_exists(".\\testdir2\\test2.txt"), "The file is copied"); shfo.fFlags = tmp_flags;}/* tests the FO_MOVE action */void test_move(void){ SHFILEOPSTRUCTA shfo, shfo2; CHAR from[MAX_PATH]; CHAR to[MAX_PATH]; shfo.hwnd = NULL; shfo.wFunc = FO_MOVE; shfo.pFrom = from; shfo.pTo = to; shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI; shfo.hNameMappings = NULL; shfo.lpszProgressTitle = NULL; set_curr_dir_path(from, "test1.txt\0"); set_curr_dir_path(to, "test4.txt\0"); ok(!SHFileOperationA(&shfo), "Prepare test to check how directories are moved recursively"); ok(file_exists(".\\test4.txt\\test1.txt"), "The file is moved"); set_curr_dir_path(from, "test?.txt\0"); set_curr_dir_path(to, "testdir2\0"); ok(!file_exists(".\\testdir2\\test2.txt"), "The file is not moved yet"); ok(!file_exists(".\\testdir2\\test4.txt"), "The directory is not moved yet"); ok(!SHFileOperationA(&shfo), "Files and directories are moved to directory "); ok(file_exists(".\\testdir2\\test2.txt"), "The file is moved"); ok(file_exists(".\\testdir2\\test4.txt"), "The directory is moved"); ok(file_exists(".\\testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is moved"); clean_after_shfo_tests(); init_shfo_tests(); memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA)); shfo2.fFlags |= FOF_MULTIDESTFILES; set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0"); set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0"); ok(!SHFileOperationA(&shfo2), "Move many files"); ok(file_exists(".\\test6.txt"), "The file is moved - many files are " "specified as a target"); DeleteFileA(".\\test6.txt"); DeleteFileA(".\\test7.txt"); RemoveDirectoryA(".\\test8.txt"); init_shfo_tests(); /* number of sources do not correspond to number of targets */ set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0"); set_curr_dir_path(to, "test6.txt\0test7.txt\0"); ok(SHFileOperationA(&shfo2), "Can't move many files"); ok(!file_exists(".\\test6.txt"), "The file is not moved - many files are " "specified as a target"); init_shfo_tests(); set_curr_dir_path(from, "test3.txt\0"); set_curr_dir_path(to, "test4.txt\\test1.txt\0"); ok(!SHFileOperationA(&shfo), "File is moved moving to other directory"); ok(file_exists(".\\test4.txt\\test1.txt"), "The file is moved"); set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0"); set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0"); ok(SHFileOperationA(&shfo), "Can not move many files"); ok(file_exists(".\\test1.txt"), "The file is not moved. Many files are specified "); ok(file_exists(".\\test4.txt"), "The directory not is moved. Many files are specified "); set_curr_dir_path(from, "test1.txt\0"); set_curr_dir_path(to, "test6.txt\0"); ok(!SHFileOperationA(&shfo), "Move file"); ok(!file_exists(".\\test1.txt"), "The file is moved"); ok(file_exists(".\\test6.txt"), "The file is moved "); set_curr_dir_path(from, "test6.txt\0"); set_curr_dir_path(to, "test1.txt\0"); ok(!SHFileOperationA(&shfo), "Move file back"); set_curr_dir_path(from, "test4.txt\0"); set_curr_dir_path(to, "test6.txt\0"); ok(!SHFileOperationA(&shfo), "Move dir"); ok(!file_exists(".\\test4.txt"), "The dir is moved"); ok(file_exists(".\\test6.txt"), "The dir is moved "); set_curr_dir_path(from, "test6.txt\0"); set_curr_dir_path(to, "test4.txt\0"); ok(!SHFileOperationA(&shfo), "Move dir back");}START_TEST(shlfileop){ clean_after_shfo_tests(); init_shfo_tests(); test_delete(); clean_after_shfo_tests(); init_shfo_tests(); test_rename(); clean_after_shfo_tests(); init_shfo_tests(); test_copy(); clean_after_shfo_tests(); init_shfo_tests(); test_move(); clean_after_shfo_tests();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -