Chromium Code Reviews| Index: base/test/test_shortcut_win.cc |
| diff --git a/base/test/test_shortcut_win.cc b/base/test/test_shortcut_win.cc |
| index b919e699e113d985bc9a36a5faa3825396e9260f..be1f07dc90e02d2a30c52a4573cc33c395fc4e55 100644 |
| --- a/base/test/test_shortcut_win.cc |
| +++ b/base/test/test_shortcut_win.cc |
| @@ -11,8 +11,10 @@ |
| #include "base/file_path.h" |
| #include "base/string16.h" |
| +#include "base/utf_string_conversions.h" |
| #include "base/win/scoped_comptr.h" |
| #include "base/win/windows_version.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| // propsys.lib is required for PropvariantTo*(). |
| #pragma comment(lib, "propsys.lib") |
| @@ -22,33 +24,45 @@ namespace win { |
| namespace { |
| -// Returns true if |actual_path|'s LongPathName case-insensitively matches |
| +// Validates |actual_path|'s LongPathName case-insensitively matches |
| // |expected_path|'s LongPathName. |
| -bool PathsAreEqual(const FilePath& expected_path, const FilePath& actual_path) { |
| +void ValidatePathsAreEqual(const FilePath& expected_path, |
| + const FilePath& actual_path) { |
| wchar_t long_expected_path_chars[MAX_PATH] = {0}; |
| wchar_t long_actual_path_chars[MAX_PATH] = {0}; |
| + // If |expected_path| is empty confirm immediately that |actual_path| is also |
| + // empty. Otherwise proceed with LongPathName matching which will also confirm |
| + // the paths exist. |
| + if (expected_path.empty()) { |
| + EXPECT_TRUE(actual_path.empty()); |
| + return; |
| + } |
| + |
| if (::GetLongPathName( |
| expected_path.value().c_str(), long_expected_path_chars, |
| MAX_PATH) == 0 || |
| ::GetLongPathName( |
| actual_path.value().c_str(), long_actual_path_chars, |
| MAX_PATH) == 0) { |
| - return false; |
| + GTEST_NONFATAL_FAILURE_("Failed to get LongPathNames."); |
| + return; |
| } |
| FilePath long_expected_path(long_expected_path_chars); |
| FilePath long_actual_path(long_actual_path_chars); |
| - if(long_expected_path.empty() || long_actual_path.empty()) |
| - return false; |
| + if(long_expected_path.empty() || long_actual_path.empty()) { |
| + GTEST_NONFATAL_FAILURE_("LongPathName unexpectingly empty."); |
| + return; |
| + } |
| - return long_expected_path == long_actual_path; |
| + EXPECT_EQ(long_expected_path, long_actual_path); |
| } |
| } // namespace |
| -VerifyShortcutStatus VerifyShortcut(const FilePath& shortcut_path, |
| - const ShortcutProperties& properties) { |
| +void ValidateShortcut(const FilePath& shortcut_path, |
| + const ShortcutProperties& properties) { |
| ScopedComPtr<IShellLink> i_shell_link; |
| ScopedComPtr<IPersistFile> i_persist_file; |
| @@ -63,47 +77,47 @@ VerifyShortcutStatus VerifyShortcut(const FilePath& shortcut_path, |
| if (FAILED(i_shell_link.CreateInstance(CLSID_ShellLink, NULL, |
| CLSCTX_INPROC_SERVER)) || |
| FAILED(i_persist_file.QueryFrom(i_shell_link))) { |
| - return VERIFY_SHORTCUT_FAILURE_UNEXPECTED; |
| + GTEST_NONFATAL_FAILURE_("Failed to initialize COM interfaces."); |
| + return; |
| } |
| // Load the shortcut. |
| - if (FAILED(i_persist_file->Load(shortcut_path.value().c_str(), 0))) |
| - return VERIFY_SHORTCUT_FAILURE_FILE_NOT_FOUND; |
| - |
| - if ((properties.options & ShortcutProperties::PROPERTIES_TARGET) && |
| - (FAILED(i_shell_link->GetPath( |
| - read_target, MAX_PATH, NULL, SLGP_SHORTPATH)) || |
| - !PathsAreEqual(properties.target, FilePath(read_target)))) { |
| - return VERIFY_SHORTCUT_FAILURE_TARGET; |
| + if (FAILED(i_persist_file->Load(shortcut_path.value().c_str(), 0))) { |
| + GTEST_NONFATAL_FAILURE_(("Failed to load shortcut at " + |
| + UTF16ToUTF8(shortcut_path.value())).c_str()); |
|
robertshield
2012/09/25 21:06:34
I don't see any other precedent in the code base f
gab
2012/09/25 22:10:00
Done all over the place as suggested. Only added l
|
| + return; |
| } |
| - if ((properties.options & ShortcutProperties::PROPERTIES_WORKING_DIR) && |
| - (FAILED(i_shell_link->GetWorkingDirectory(read_working_dir, MAX_PATH)) || |
| - FilePath(read_working_dir) != properties.working_dir)) { |
| - return VERIFY_SHORTCUT_FAILURE_WORKING_DIR; |
| + if (FAILED(i_shell_link->GetPath(read_target, MAX_PATH, NULL, |
| + SLGP_SHORTPATH)) || |
| + FAILED(i_shell_link->GetWorkingDirectory(read_working_dir, MAX_PATH)) || |
| + FAILED(i_shell_link->GetDescription(read_description, MAX_PATH)) || |
| + FAILED(i_shell_link->GetArguments(read_arguments, MAX_PATH)) || |
| + FAILED(i_shell_link->GetIconLocation(read_icon, MAX_PATH, |
| + &read_icon_index))) { |
| + GTEST_NONFATAL_FAILURE_(("Failed to read properties from shortcut at " + |
| + UTF16ToUTF8(shortcut_path.value())).c_str()); |
|
robertshield
2012/09/25 21:06:34
similar comment here, and in the other places in t
gab
2012/09/25 22:10:00
Done.
|
| + return; |
| } |
| - if ((properties.options & ShortcutProperties::PROPERTIES_ARGUMENTS) && |
| - (FAILED(i_shell_link->GetArguments(read_arguments, MAX_PATH)) || |
| - string16(read_arguments) != properties.arguments)) { |
| - return VERIFY_SHORTCUT_FAILURE_ARGUMENTS; |
| - } |
| + if (properties.options & ShortcutProperties::PROPERTIES_TARGET) |
| + ValidatePathsAreEqual(properties.target, FilePath(read_target)); |
| - if ((properties.options & ShortcutProperties::PROPERTIES_DESCRIPTION) && |
| - (FAILED(i_shell_link->GetDescription(read_description, MAX_PATH)) || |
| - string16(read_description) != properties.description)) { |
| - return VERIFY_SHORTCUT_FAILURE_DESCRIPTION; |
| - } |
| + if (properties.options & ShortcutProperties::PROPERTIES_WORKING_DIR) |
| + ValidatePathsAreEqual(properties.working_dir, FilePath(read_working_dir)); |
| - if ((properties.options & ShortcutProperties::PROPERTIES_ICON) && |
| - (FAILED(i_shell_link->GetIconLocation(read_icon, MAX_PATH, |
| - &read_icon_index)) || |
| - read_icon_index != properties.icon_index || |
| - !PathsAreEqual(properties.icon, FilePath(read_icon)))) { |
| - return VERIFY_SHORTCUT_FAILURE_ICON; |
| + if (properties.options & ShortcutProperties::PROPERTIES_ARGUMENTS) |
| + EXPECT_EQ(properties.arguments, read_arguments); |
| + |
| + if (properties.options & ShortcutProperties::PROPERTIES_DESCRIPTION) |
| + EXPECT_EQ(properties.description, read_description); |
| + |
| + if (properties.options & ShortcutProperties::PROPERTIES_ICON) { |
| + ValidatePathsAreEqual(properties.icon, FilePath(read_icon)); |
| + EXPECT_EQ(properties.icon_index, read_icon_index); |
| } |
| - if(GetVersion() >= VERSION_WIN7) { |
| + if (GetVersion() >= VERSION_WIN7) { |
| ScopedComPtr<IPropertyStore> property_store; |
| // Note that, as mentioned on MSDN at http://goo.gl/M8h9g, if a property is |
| // not set, GetValue will return S_OK and the PROPVARIANT will be set to |
| @@ -113,29 +127,29 @@ VerifyShortcutStatus VerifyShortcut(const FilePath& shortcut_path, |
| property_store->GetValue(PKEY_AppUserModel_ID, &pv_app_id) != S_OK || |
| property_store->GetValue(PKEY_AppUserModel_IsDualMode, |
| &pv_dual_mode) != S_OK) { |
| - return VERIFY_SHORTCUT_FAILURE_UNEXPECTED; |
| + GTEST_NONFATAL_FAILURE_(("Failed to read property store for shortcut at" + |
| + UTF16ToUTF8(shortcut_path.value())).c_str()); |
| + return; |
| } |
| - // Note, as mentioned on MSDN at http://goo.gl/hZ3sO, if |pv_app_id| is a |
| - // VT_EMPTY it is successfully converted to the empty string. |
| + // Note, as mentioned on MSDN at |
| + // http://msdn.microsoft.com/library/windows/desktop/bb776559.aspx, if |
| + // |pv_app_id| is a VT_EMPTY it is successfully converted to the empty |
| + // string as desired. |
| wchar_t read_app_id[MAX_PATH] = {0}; |
| PropVariantToString(pv_app_id, read_app_id, MAX_PATH); |
| - if((properties.options & ShortcutProperties::PROPERTIES_APP_ID) && |
| - string16(read_app_id) != properties.app_id) { |
| - return VERIFY_SHORTCUT_FAILURE_APP_ID; |
| - } |
| + if (properties.options & ShortcutProperties::PROPERTIES_APP_ID) |
| + EXPECT_EQ(properties.app_id, read_app_id); |
| - // Note, as mentioned on MSDN at http://goo.gl/9mBHB, if |pv_dual_mode| is a |
| - // VT_EMPTY it is successfully converted to false. |
| + // Note, as mentioned on MSDN at |
| + // http://msdn.microsoft.com/library/windows/desktop/bb776531.aspx, if |
| + // |pv_dual_mode| is a VT_EMPTY it is successfully converted to false as |
| + // desired. |
| BOOL read_dual_mode; |
| PropVariantToBoolean(pv_dual_mode, &read_dual_mode); |
| - if((properties.options & ShortcutProperties::PROPERTIES_DUAL_MODE) && |
| - static_cast<bool>(read_dual_mode) != properties.dual_mode) { |
| - return VERIFY_SHORTCUT_FAILURE_DUAL_MODE; |
| - } |
| + if (properties.options & ShortcutProperties::PROPERTIES_DUAL_MODE) |
| + EXPECT_EQ(properties.dual_mode, static_cast<bool>(read_dual_mode)); |
| } |
| - |
| - return VERIFY_SHORTCUT_SUCCESS; |
| } |
| } // namespace win |