| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include <shlobj.h> | 6 #include <shlobj.h> |
| 7 | 7 |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 const wchar_t* test_name; | 104 const wchar_t* test_name; |
| 105 const wchar_t* str; | 105 const wchar_t* str; |
| 106 DWORD length; | 106 DWORD length; |
| 107 size_t count; | 107 size_t count; |
| 108 } tests[] = { | 108 } tests[] = { |
| 109 { L"basic", L"foo\0bar\0fee\0bee\0boo\0bong\0\0", 26 * sizeof(wchar_t), 3 }, | 109 { L"basic", L"foo\0bar\0fee\0bee\0boo\0bong\0\0", 26 * sizeof(wchar_t), 3 }, |
| 110 { L"empty", L"\0\0", 2 * sizeof(wchar_t), 1 }, | 110 { L"empty", L"\0\0", 2 * sizeof(wchar_t), 1 }, |
| 111 { L"deletes", L"foo\0\0bar\0\0bizz\0\0", 16 * sizeof(wchar_t), 3 }, | 111 { L"deletes", L"foo\0\0bar\0\0bizz\0\0", 16 * sizeof(wchar_t), 3 }, |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 for (int i = 0; i < arraysize(tests); i++) { | 114 for (size_t i = 0; i < arraysize(tests); i++) { |
| 115 std::vector<PendingMove> string_list; | 115 std::vector<PendingMove> string_list; |
| 116 EXPECT_TRUE(SUCCEEDED( | 116 EXPECT_TRUE(SUCCEEDED( |
| 117 MultiSZBytesToStringArray(reinterpret_cast<const char*>(tests[i].str), | 117 MultiSZBytesToStringArray(reinterpret_cast<const char*>(tests[i].str), |
| 118 tests[i].length, | 118 tests[i].length, |
| 119 &string_list))) | 119 &string_list))) |
| 120 << tests[i].test_name; | 120 << tests[i].test_name; |
| 121 EXPECT_EQ(tests[i].count, string_list.size()) << tests[i].test_name; | 121 EXPECT_EQ(tests[i].count, string_list.size()) << tests[i].test_name; |
| 122 std::vector<char> buffer; | 122 std::vector<char> buffer; |
| 123 buffer.resize(WStringPairListSize(string_list)); | 123 buffer.resize(WStringPairListSize(string_list)); |
| 124 StringArrayToMultiSZBytes(string_list, &buffer); | 124 StringArrayToMultiSZBytes(string_list, &buffer); |
| 125 EXPECT_TRUE(CompareBuffers(const_cast<const char*>(&buffer[0]), | 125 EXPECT_TRUE(CompareBuffers(const_cast<const char*>(&buffer[0]), |
| 126 reinterpret_cast<const char*>(tests[i].str), | 126 reinterpret_cast<const char*>(tests[i].str), |
| 127 tests[i].length)) | 127 tests[i].length)) |
| 128 << tests[i].test_name; | 128 << tests[i].test_name; |
| 129 } | 129 } |
| 130 | 130 |
| 131 StringTest failures[] = { | 131 StringTest failures[] = { |
| 132 {L"malformed", reinterpret_cast<const wchar_t*>("oddnumb\0\0"), 9, 1}, | 132 {L"malformed", reinterpret_cast<const wchar_t*>("oddnumb\0\0"), 9, 1}, |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 for (int i = 0; i < arraysize(failures); i++) { | 135 for (size_t i = 0; i < arraysize(failures); i++) { |
| 136 std::vector<PendingMove> string_list; | 136 std::vector<PendingMove> string_list; |
| 137 EXPECT_FALSE(SUCCEEDED(MultiSZBytesToStringArray( | 137 EXPECT_FALSE(SUCCEEDED(MultiSZBytesToStringArray( |
| 138 reinterpret_cast<const char*>(failures[i].str), | 138 reinterpret_cast<const char*>(failures[i].str), |
| 139 failures[i].length, | 139 failures[i].length, |
| 140 &string_list))) | 140 &string_list))) |
| 141 << failures[i].test_name; | 141 << failures[i].test_name; |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 | 145 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 164 std::vector<PendingMove>::const_iterator iter(pending_moves.begin()); | 164 std::vector<PendingMove>::const_iterator iter(pending_moves.begin()); |
| 165 for (; iter != pending_moves.end(); iter++) { | 165 for (; iter != pending_moves.end(); iter++) { |
| 166 base::FilePath move_path(iter->first); | 166 base::FilePath move_path(iter->first); |
| 167 if (MatchPendingDeletePath(short_temp_file, move_path)) | 167 if (MatchPendingDeletePath(short_temp_file, move_path)) |
| 168 break; | 168 break; |
| 169 } | 169 } |
| 170 | 170 |
| 171 // Check that each of the deletes we expect are there in order. | 171 // Check that each of the deletes we expect are there in order. |
| 172 base::FilePath expected_paths[] = | 172 base::FilePath expected_paths[] = |
| 173 { temp_file_, temp_subdir_file_, temp_subdir_, temp_dir_ }; | 173 { temp_file_, temp_subdir_file_, temp_subdir_, temp_dir_ }; |
| 174 for (int i = 0; i < arraysize(expected_paths); ++i) { | 174 for (size_t i = 0; i < arraysize(expected_paths); ++i) { |
| 175 EXPECT_FALSE(iter == pending_moves.end()); | 175 EXPECT_FALSE(iter == pending_moves.end()); |
| 176 if (iter != pending_moves.end()) { | 176 if (iter != pending_moves.end()) { |
| 177 base::FilePath short_path_name(GetShortPathName(expected_paths[i])); | 177 base::FilePath short_path_name(GetShortPathName(expected_paths[i])); |
| 178 base::FilePath move_path(iter->first); | 178 base::FilePath move_path(iter->first); |
| 179 EXPECT_TRUE(MatchPendingDeletePath(short_path_name, move_path)); | 179 EXPECT_TRUE(MatchPendingDeletePath(short_path_name, move_path)); |
| 180 ++iter; | 180 ++iter; |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 | 183 |
| 184 // Test that we can remove the pending deletes. | 184 // Test that we can remove the pending deletes. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 std::vector<PendingMove>::const_iterator iter(pending_moves.begin()); | 218 std::vector<PendingMove>::const_iterator iter(pending_moves.begin()); |
| 219 for (; iter != pending_moves.end(); iter++) { | 219 for (; iter != pending_moves.end(); iter++) { |
| 220 base::FilePath move_path(iter->first); | 220 base::FilePath move_path(iter->first); |
| 221 if (MatchPendingDeletePath(short_temp_file, move_path)) | 221 if (MatchPendingDeletePath(short_temp_file, move_path)) |
| 222 break; | 222 break; |
| 223 } | 223 } |
| 224 | 224 |
| 225 // Check that each of the deletes we expect are there in order. | 225 // Check that each of the deletes we expect are there in order. |
| 226 base::FilePath expected_paths[] = | 226 base::FilePath expected_paths[] = |
| 227 { temp_file_, temp_subdir_file_, temp_subdir_, temp_dir_ }; | 227 { temp_file_, temp_subdir_file_, temp_subdir_, temp_dir_ }; |
| 228 for (int i = 0; i < arraysize(expected_paths); ++i) { | 228 for (size_t i = 0; i < arraysize(expected_paths); ++i) { |
| 229 EXPECT_FALSE(iter == pending_moves.end()); | 229 EXPECT_FALSE(iter == pending_moves.end()); |
| 230 if (iter != pending_moves.end()) { | 230 if (iter != pending_moves.end()) { |
| 231 base::FilePath short_path_name(GetShortPathName(expected_paths[i])); | 231 base::FilePath short_path_name(GetShortPathName(expected_paths[i])); |
| 232 base::FilePath move_path(iter->first); | 232 base::FilePath move_path(iter->first); |
| 233 EXPECT_TRUE(MatchPendingDeletePath(short_path_name, move_path)); | 233 EXPECT_TRUE(MatchPendingDeletePath(short_path_name, move_path)); |
| 234 ++iter; | 234 ++iter; |
| 235 } | 235 } |
| 236 } | 236 } |
| 237 | 237 |
| 238 // Delete the temporary directory. | 238 // Delete the temporary directory. |
| 239 base::DeleteFile(temp_dir_, true); | 239 base::DeleteFile(temp_dir_, true); |
| 240 | 240 |
| 241 // Test that we can remove the pending deletes. | 241 // Test that we can remove the pending deletes. |
| 242 EXPECT_TRUE(RemoveFromMovesPendingReboot(temp_dir_)); | 242 EXPECT_TRUE(RemoveFromMovesPendingReboot(temp_dir_)); |
| 243 HRESULT hr = GetPendingMovesValue(&pending_moves); | 243 HRESULT hr = GetPendingMovesValue(&pending_moves); |
| 244 EXPECT_TRUE(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)); | 244 EXPECT_TRUE(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)); |
| 245 | 245 |
| 246 EXPECT_EQ(initial_pending_moves_size, pending_moves.size()); | 246 EXPECT_EQ(initial_pending_moves_size, pending_moves.size()); |
| 247 | 247 |
| 248 std::vector<PendingMove>::const_iterator check_iter(pending_moves.begin()); | 248 std::vector<PendingMove>::const_iterator check_iter(pending_moves.begin()); |
| 249 for (; check_iter != pending_moves.end(); ++check_iter) { | 249 for (; check_iter != pending_moves.end(); ++check_iter) { |
| 250 base::FilePath move_path(check_iter->first); | 250 base::FilePath move_path(check_iter->first); |
| 251 EXPECT_FALSE(MatchPendingDeletePath(short_temp_file, move_path)); | 251 EXPECT_FALSE(MatchPendingDeletePath(short_temp_file, move_path)); |
| 252 } | 252 } |
| 253 } | 253 } |
| 254 | 254 |
| OLD | NEW |