| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <windows.h> | 5 #include <windows.h> |
| 6 | 6 |
| 7 #include <fstream> | 7 #include <fstream> |
| 8 #include <iostream> | 8 #include <iostream> |
| 9 | 9 |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 wchar_t text_content_1[] = L"Gooooooooooooooooooooogle"; | 72 wchar_t text_content_1[] = L"Gooooooooooooooooooooogle"; |
| 73 wchar_t text_content_2[] = L"Overwrite Me"; | 73 wchar_t text_content_2[] = L"Overwrite Me"; |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 // Move one directory from source to destination when destination does not | 76 // Move one directory from source to destination when destination does not |
| 77 // exist. | 77 // exist. |
| 78 TEST_F(MoveTreeWorkItemTest, MoveDirectory) { | 78 TEST_F(MoveTreeWorkItemTest, MoveDirectory) { |
| 79 // Create two level deep source dir | 79 // Create two level deep source dir |
| 80 FilePath from_dir1(test_dir_); | 80 FilePath from_dir1(test_dir_); |
| 81 from_dir1 = from_dir1.AppendASCII("From_Dir1"); | 81 from_dir1 = from_dir1.AppendASCII("From_Dir1"); |
| 82 CreateDirectory(from_dir1.value().c_str(), NULL); | 82 file_util::CreateDirectory(from_dir1); |
| 83 ASSERT_TRUE(file_util::PathExists(from_dir1)); | 83 ASSERT_TRUE(file_util::PathExists(from_dir1)); |
| 84 | 84 |
| 85 FilePath from_dir2(from_dir1); | 85 FilePath from_dir2(from_dir1); |
| 86 from_dir2 = from_dir2.AppendASCII("From_Dir2"); | 86 from_dir2 = from_dir2.AppendASCII("From_Dir2"); |
| 87 CreateDirectory(from_dir2.value().c_str(), NULL); | 87 file_util::CreateDirectory(from_dir2); |
| 88 ASSERT_TRUE(file_util::PathExists(from_dir2)); | 88 ASSERT_TRUE(file_util::PathExists(from_dir2)); |
| 89 | 89 |
| 90 FilePath from_file(from_dir2); | 90 FilePath from_file(from_dir2); |
| 91 from_file = from_file.AppendASCII("From_File"); | 91 from_file = from_file.AppendASCII("From_File"); |
| 92 CreateTextFile(from_file.value(), text_content_1); | 92 CreateTextFile(from_file.value(), text_content_1); |
| 93 ASSERT_TRUE(file_util::PathExists(from_file)); | 93 ASSERT_TRUE(file_util::PathExists(from_file)); |
| 94 | 94 |
| 95 // Generate destination path | 95 // Generate destination path |
| 96 FilePath to_dir(test_dir_); | 96 FilePath to_dir(test_dir_); |
| 97 to_dir = to_dir.AppendASCII("To_Dir"); | 97 to_dir = to_dir.AppendASCII("To_Dir"); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 119 EXPECT_TRUE(file_util::PathExists(from_file)); | 119 EXPECT_TRUE(file_util::PathExists(from_file)); |
| 120 EXPECT_FALSE(file_util::PathExists(to_dir)); | 120 EXPECT_FALSE(file_util::PathExists(to_dir)); |
| 121 } | 121 } |
| 122 | 122 |
| 123 // Move one directory from source to destination when destination already | 123 // Move one directory from source to destination when destination already |
| 124 // exists. | 124 // exists. |
| 125 TEST_F(MoveTreeWorkItemTest, MoveDirectoryDestExists) { | 125 TEST_F(MoveTreeWorkItemTest, MoveDirectoryDestExists) { |
| 126 // Create two level deep source dir | 126 // Create two level deep source dir |
| 127 FilePath from_dir1(test_dir_); | 127 FilePath from_dir1(test_dir_); |
| 128 from_dir1 = from_dir1.AppendASCII("From_Dir1"); | 128 from_dir1 = from_dir1.AppendASCII("From_Dir1"); |
| 129 CreateDirectory(from_dir1.value().c_str(), NULL); | 129 file_util::CreateDirectory(from_dir1); |
| 130 ASSERT_TRUE(file_util::PathExists(from_dir1)); | 130 ASSERT_TRUE(file_util::PathExists(from_dir1)); |
| 131 | 131 |
| 132 FilePath from_dir2(from_dir1); | 132 FilePath from_dir2(from_dir1); |
| 133 from_dir2 = from_dir2.AppendASCII("From_Dir2"); | 133 from_dir2 = from_dir2.AppendASCII("From_Dir2"); |
| 134 CreateDirectory(from_dir2.value().c_str(), NULL); | 134 file_util::CreateDirectory(from_dir2); |
| 135 ASSERT_TRUE(file_util::PathExists(from_dir2)); | 135 ASSERT_TRUE(file_util::PathExists(from_dir2)); |
| 136 | 136 |
| 137 FilePath from_file(from_dir2); | 137 FilePath from_file(from_dir2); |
| 138 from_file = from_file.AppendASCII("From_File"); | 138 from_file = from_file.AppendASCII("From_File"); |
| 139 CreateTextFile(from_file.value(), text_content_1); | 139 CreateTextFile(from_file.value(), text_content_1); |
| 140 ASSERT_TRUE(file_util::PathExists(from_file)); | 140 ASSERT_TRUE(file_util::PathExists(from_file)); |
| 141 | 141 |
| 142 // Create destination path | 142 // Create destination path |
| 143 FilePath to_dir(test_dir_); | 143 FilePath to_dir(test_dir_); |
| 144 to_dir = to_dir.AppendASCII("To_Dir"); | 144 to_dir = to_dir.AppendASCII("To_Dir"); |
| 145 CreateDirectory(to_dir.value().c_str(), NULL); | 145 file_util::CreateDirectory(to_dir); |
| 146 ASSERT_TRUE(file_util::PathExists(to_dir)); | 146 ASSERT_TRUE(file_util::PathExists(to_dir)); |
| 147 | 147 |
| 148 FilePath orig_to_file(to_dir); | 148 FilePath orig_to_file(to_dir); |
| 149 orig_to_file = orig_to_file.AppendASCII("To_File"); | 149 orig_to_file = orig_to_file.AppendASCII("To_File"); |
| 150 CreateTextFile(orig_to_file.value(), text_content_2); | 150 CreateTextFile(orig_to_file.value(), text_content_2); |
| 151 ASSERT_TRUE(file_util::PathExists(orig_to_file)); | 151 ASSERT_TRUE(file_util::PathExists(orig_to_file)); |
| 152 | 152 |
| 153 FilePath new_to_file(to_dir); | 153 FilePath new_to_file(to_dir); |
| 154 new_to_file = new_to_file.AppendASCII("From_Dir2"); | 154 new_to_file = new_to_file.AppendASCII("From_Dir2"); |
| 155 new_to_file = new_to_file.AppendASCII("From_File"); | 155 new_to_file = new_to_file.AppendASCII("From_File"); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 177 text_content_2)); | 177 text_content_2)); |
| 178 EXPECT_EQ(0, ReadTextFile(from_file.ToWStringHack()).compare(text_content_1)); | 178 EXPECT_EQ(0, ReadTextFile(from_file.ToWStringHack()).compare(text_content_1)); |
| 179 } | 179 } |
| 180 | 180 |
| 181 // Move one file from source to destination when destination does not | 181 // Move one file from source to destination when destination does not |
| 182 // exist. | 182 // exist. |
| 183 TEST_F(MoveTreeWorkItemTest, MoveAFile) { | 183 TEST_F(MoveTreeWorkItemTest, MoveAFile) { |
| 184 // Create a file inside source dir | 184 // Create a file inside source dir |
| 185 FilePath from_dir(test_dir_); | 185 FilePath from_dir(test_dir_); |
| 186 from_dir = from_dir.AppendASCII("From_Dir"); | 186 from_dir = from_dir.AppendASCII("From_Dir"); |
| 187 CreateDirectory(from_dir.value().c_str(), NULL); | 187 file_util::CreateDirectory(from_dir); |
| 188 ASSERT_TRUE(file_util::PathExists(from_dir)); | 188 ASSERT_TRUE(file_util::PathExists(from_dir)); |
| 189 | 189 |
| 190 FilePath from_file(from_dir); | 190 FilePath from_file(from_dir); |
| 191 from_file = from_file.AppendASCII("From_File"); | 191 from_file = from_file.AppendASCII("From_File"); |
| 192 CreateTextFile(from_file.value(), text_content_1); | 192 CreateTextFile(from_file.value(), text_content_1); |
| 193 ASSERT_TRUE(file_util::PathExists(from_file)); | 193 ASSERT_TRUE(file_util::PathExists(from_file)); |
| 194 | 194 |
| 195 // Generate destination file name | 195 // Generate destination file name |
| 196 FilePath to_file(test_dir_); | 196 FilePath to_file(test_dir_); |
| 197 to_file = to_file.AppendASCII("To_File"); | 197 to_file = to_file.AppendASCII("To_File"); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 216 EXPECT_FALSE(file_util::PathExists(to_file)); | 216 EXPECT_FALSE(file_util::PathExists(to_file)); |
| 217 EXPECT_EQ(0, ReadTextFile(from_file.value()).compare(text_content_1)); | 217 EXPECT_EQ(0, ReadTextFile(from_file.value()).compare(text_content_1)); |
| 218 } | 218 } |
| 219 | 219 |
| 220 // Move one file from source to destination when destination already | 220 // Move one file from source to destination when destination already |
| 221 // exists. | 221 // exists. |
| 222 TEST_F(MoveTreeWorkItemTest, MoveFileDestExists) { | 222 TEST_F(MoveTreeWorkItemTest, MoveFileDestExists) { |
| 223 // Create a file inside source dir | 223 // Create a file inside source dir |
| 224 FilePath from_dir(test_dir_); | 224 FilePath from_dir(test_dir_); |
| 225 from_dir = from_dir.AppendASCII("From_Dir"); | 225 from_dir = from_dir.AppendASCII("From_Dir"); |
| 226 CreateDirectory(from_dir.value().c_str(), NULL); | 226 file_util::CreateDirectory(from_dir); |
| 227 ASSERT_TRUE(file_util::PathExists(from_dir)); | 227 ASSERT_TRUE(file_util::PathExists(from_dir)); |
| 228 | 228 |
| 229 FilePath from_file(from_dir); | 229 FilePath from_file(from_dir); |
| 230 from_file = from_file.AppendASCII("From_File"); | 230 from_file = from_file.AppendASCII("From_File"); |
| 231 CreateTextFile(from_file.value(), text_content_1); | 231 CreateTextFile(from_file.value(), text_content_1); |
| 232 ASSERT_TRUE(file_util::PathExists(from_file)); | 232 ASSERT_TRUE(file_util::PathExists(from_file)); |
| 233 | 233 |
| 234 // Create destination path | 234 // Create destination path |
| 235 FilePath to_dir(test_dir_); | 235 FilePath to_dir(test_dir_); |
| 236 to_dir = to_dir.AppendASCII("To_Dir"); | 236 to_dir = to_dir.AppendASCII("To_Dir"); |
| 237 CreateDirectory(to_dir.value().c_str(), NULL); | 237 file_util::CreateDirectory(to_dir); |
| 238 ASSERT_TRUE(file_util::PathExists(to_dir)); | 238 ASSERT_TRUE(file_util::PathExists(to_dir)); |
| 239 | 239 |
| 240 FilePath to_file(to_dir); | 240 FilePath to_file(to_dir); |
| 241 to_file = to_file.AppendASCII("To_File"); | 241 to_file = to_file.AppendASCII("To_File"); |
| 242 CreateTextFile(to_file.value(), text_content_2); | 242 CreateTextFile(to_file.value(), text_content_2); |
| 243 ASSERT_TRUE(file_util::PathExists(to_file)); | 243 ASSERT_TRUE(file_util::PathExists(to_file)); |
| 244 | 244 |
| 245 // test Do() | 245 // test Do() |
| 246 scoped_ptr<MoveTreeWorkItem> work_item(WorkItem::CreateMoveTreeWorkItem( | 246 scoped_ptr<MoveTreeWorkItem> work_item(WorkItem::CreateMoveTreeWorkItem( |
| 247 from_file.ToWStringHack(), to_dir.ToWStringHack(), | 247 from_file.ToWStringHack(), to_dir.ToWStringHack(), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 262 EXPECT_TRUE(file_util::PathExists(to_dir)); | 262 EXPECT_TRUE(file_util::PathExists(to_dir)); |
| 263 EXPECT_EQ(0, ReadTextFile(to_file.value()).compare(text_content_2)); | 263 EXPECT_EQ(0, ReadTextFile(to_file.value()).compare(text_content_2)); |
| 264 } | 264 } |
| 265 | 265 |
| 266 // Move one file from source to destination when destination already | 266 // Move one file from source to destination when destination already |
| 267 // exists and is in use. | 267 // exists and is in use. |
| 268 TEST_F(MoveTreeWorkItemTest, MoveFileDestInUse) { | 268 TEST_F(MoveTreeWorkItemTest, MoveFileDestInUse) { |
| 269 // Create a file inside source dir | 269 // Create a file inside source dir |
| 270 FilePath from_dir(test_dir_); | 270 FilePath from_dir(test_dir_); |
| 271 from_dir = from_dir.AppendASCII("From_Dir"); | 271 from_dir = from_dir.AppendASCII("From_Dir"); |
| 272 CreateDirectory(from_dir.value().c_str(), NULL); | 272 file_util::CreateDirectory(from_dir); |
| 273 ASSERT_TRUE(file_util::PathExists(from_dir)); | 273 ASSERT_TRUE(file_util::PathExists(from_dir)); |
| 274 | 274 |
| 275 FilePath from_file(from_dir); | 275 FilePath from_file(from_dir); |
| 276 from_file = from_file.AppendASCII("From_File"); | 276 from_file = from_file.AppendASCII("From_File"); |
| 277 CreateTextFile(from_file.value(), text_content_1); | 277 CreateTextFile(from_file.value(), text_content_1); |
| 278 ASSERT_TRUE(file_util::PathExists(from_file)); | 278 ASSERT_TRUE(file_util::PathExists(from_file)); |
| 279 | 279 |
| 280 // Create an executable in destination path by copying ourself to it. | 280 // Create an executable in destination path by copying ourself to it. |
| 281 FilePath to_dir(test_dir_); | 281 FilePath to_dir(test_dir_); |
| 282 to_dir = to_dir.AppendASCII("To_Dir"); | 282 to_dir = to_dir.AppendASCII("To_Dir"); |
| 283 CreateDirectory(to_dir.value().c_str(), NULL); | 283 file_util::CreateDirectory(to_dir); |
| 284 ASSERT_TRUE(file_util::PathExists(to_dir)); | 284 ASSERT_TRUE(file_util::PathExists(to_dir)); |
| 285 | 285 |
| 286 wchar_t exe_full_path_str[MAX_PATH]; | 286 wchar_t exe_full_path_str[MAX_PATH]; |
| 287 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); | 287 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); |
| 288 FilePath exe_full_path(exe_full_path_str); | 288 FilePath exe_full_path(exe_full_path_str); |
| 289 FilePath to_file(to_dir); | 289 FilePath to_file(to_dir); |
| 290 to_file = to_file.AppendASCII("To_File"); | 290 to_file = to_file.AppendASCII("To_File"); |
| 291 file_util::CopyFile(exe_full_path, to_file); | 291 file_util::CopyFile(exe_full_path, to_file); |
| 292 ASSERT_TRUE(file_util::PathExists(to_file)); | 292 ASSERT_TRUE(file_util::PathExists(to_file)); |
| 293 | 293 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 323 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0); | 323 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0); |
| 324 CloseHandle(pi.hProcess); | 324 CloseHandle(pi.hProcess); |
| 325 CloseHandle(pi.hThread); | 325 CloseHandle(pi.hThread); |
| 326 } | 326 } |
| 327 | 327 |
| 328 // Move one file that is in use to destination. | 328 // Move one file that is in use to destination. |
| 329 TEST_F(MoveTreeWorkItemTest, MoveFileInUse) { | 329 TEST_F(MoveTreeWorkItemTest, MoveFileInUse) { |
| 330 // Create an executable for source by copying ourself to a new source dir. | 330 // Create an executable for source by copying ourself to a new source dir. |
| 331 FilePath from_dir(test_dir_); | 331 FilePath from_dir(test_dir_); |
| 332 from_dir = from_dir.AppendASCII("From_Dir"); | 332 from_dir = from_dir.AppendASCII("From_Dir"); |
| 333 CreateDirectory(from_dir.value().c_str(), NULL); | 333 file_util::CreateDirectory(from_dir); |
| 334 ASSERT_TRUE(file_util::PathExists(from_dir)); | 334 ASSERT_TRUE(file_util::PathExists(from_dir)); |
| 335 | 335 |
| 336 wchar_t exe_full_path_str[MAX_PATH]; | 336 wchar_t exe_full_path_str[MAX_PATH]; |
| 337 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); | 337 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); |
| 338 FilePath exe_full_path(exe_full_path_str); | 338 FilePath exe_full_path(exe_full_path_str); |
| 339 FilePath from_file(from_dir); | 339 FilePath from_file(from_dir); |
| 340 from_file = from_file.AppendASCII("From_File"); | 340 from_file = from_file.AppendASCII("From_File"); |
| 341 file_util::CopyFile(exe_full_path, from_file); | 341 file_util::CopyFile(exe_full_path, from_file); |
| 342 ASSERT_TRUE(file_util::PathExists(from_file)); | 342 ASSERT_TRUE(file_util::PathExists(from_file)); |
| 343 | 343 |
| 344 // Create a destination source dir and generate destination file name. | 344 // Create a destination source dir and generate destination file name. |
| 345 FilePath to_dir(test_dir_); | 345 FilePath to_dir(test_dir_); |
| 346 to_dir = to_dir.AppendASCII("To_Dir"); | 346 to_dir = to_dir.AppendASCII("To_Dir"); |
| 347 CreateDirectory(to_dir.value().c_str(), NULL); | 347 file_util::CreateDirectory(to_dir); |
| 348 ASSERT_TRUE(file_util::PathExists(to_dir)); | 348 ASSERT_TRUE(file_util::PathExists(to_dir)); |
| 349 | 349 |
| 350 FilePath to_file(to_dir); | 350 FilePath to_file(to_dir); |
| 351 to_file = to_file.AppendASCII("To_File"); | 351 to_file = to_file.AppendASCII("To_File"); |
| 352 CreateTextFile(to_file.value(), text_content_1); | 352 CreateTextFile(to_file.value(), text_content_1); |
| 353 ASSERT_TRUE(file_util::PathExists(to_file)); | 353 ASSERT_TRUE(file_util::PathExists(to_file)); |
| 354 | 354 |
| 355 // Run the executable in source path | 355 // Run the executable in source path |
| 356 STARTUPINFOW si = {sizeof(si)}; | 356 STARTUPINFOW si = {sizeof(si)}; |
| 357 PROCESS_INFORMATION pi = {0}; | 357 PROCESS_INFORMATION pi = {0}; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 385 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, to_file)); | 385 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, to_file)); |
| 386 | 386 |
| 387 // test rollback() | 387 // test rollback() |
| 388 work_item->Rollback(); | 388 work_item->Rollback(); |
| 389 | 389 |
| 390 EXPECT_TRUE(file_util::PathExists(from_dir)); | 390 EXPECT_TRUE(file_util::PathExists(from_dir)); |
| 391 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, from_file)); | 391 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, from_file)); |
| 392 EXPECT_TRUE(file_util::PathExists(to_dir)); | 392 EXPECT_TRUE(file_util::PathExists(to_dir)); |
| 393 EXPECT_EQ(0, ReadTextFile(to_file.value()).compare(text_content_1)); | 393 EXPECT_EQ(0, ReadTextFile(to_file.value()).compare(text_content_1)); |
| 394 } | 394 } |
| OLD | NEW |