| 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..f84c0d06412df8fd35c01612b651dfdeeb069da6 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,40 @@ 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 (::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;
|
| + // If |expected_path| is empty confirm immediately that |actual_path| is also
|
| + // empty.
|
| + if (expected_path.empty()) {
|
| + EXPECT_TRUE(actual_path.empty());
|
| + return;
|
| }
|
|
|
| + // Proceed with LongPathName matching which will also confirm the paths exist.
|
| + EXPECT_NE(0U, ::GetLongPathName(
|
| + expected_path.value().c_str(), long_expected_path_chars, MAX_PATH))
|
| + << "Failed to get LongPathName of " << expected_path.value();
|
| + EXPECT_NE(0U, ::GetLongPathName(
|
| + actual_path.value().c_str(), long_actual_path_chars, MAX_PATH))
|
| + << "Failed to get LongPathName of " << actual_path.value();
|
| +
|
| 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;
|
| + EXPECT_FALSE(long_expected_path.empty());
|
| + EXPECT_FALSE(long_actual_path.empty());
|
|
|
| - 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;
|
|
|
| @@ -59,83 +68,87 @@ VerifyShortcutStatus VerifyShortcut(const FilePath& shortcut_path,
|
| wchar_t read_icon[MAX_PATH] = {0};
|
| int read_icon_index = 0;
|
|
|
| + HRESULT hr;
|
| +
|
| // Initialize the shell interfaces.
|
| - 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;
|
| - }
|
| + EXPECT_TRUE(SUCCEEDED(hr = i_shell_link.CreateInstance(
|
| + CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER)));
|
| + if (FAILED(hr))
|
| + return;
|
| +
|
| + EXPECT_TRUE(SUCCEEDED(hr = i_persist_file.QueryFrom(i_shell_link)));
|
| + if (FAILED(hr))
|
| + 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;
|
| + EXPECT_TRUE(SUCCEEDED(hr = i_persist_file->Load(
|
| + shortcut_path.value().c_str(), 0))) << "Failed to load shortcut at "
|
| + << shortcut_path.value();
|
| + if (FAILED(hr))
|
| + return;
|
| +
|
| + if (properties.options & ShortcutProperties::PROPERTIES_TARGET) {
|
| + EXPECT_TRUE(SUCCEEDED(
|
| + i_shell_link->GetPath(read_target, MAX_PATH, NULL, SLGP_SHORTPATH)));
|
| + ValidatePathsAreEqual(properties.target, FilePath(read_target));
|
| }
|
|
|
| - 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 (properties.options & ShortcutProperties::PROPERTIES_WORKING_DIR) {
|
| + EXPECT_TRUE(SUCCEEDED(
|
| + i_shell_link->GetWorkingDirectory(read_working_dir, MAX_PATH)));
|
| + ValidatePathsAreEqual(properties.working_dir, FilePath(read_working_dir));
|
| }
|
|
|
| - 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_ARGUMENTS) {
|
| + EXPECT_TRUE(SUCCEEDED(
|
| + i_shell_link->GetArguments(read_arguments, MAX_PATH)));
|
| + EXPECT_EQ(properties.arguments, read_arguments);
|
| }
|
|
|
| - 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_DESCRIPTION) {
|
| + EXPECT_TRUE(SUCCEEDED(
|
| + i_shell_link->GetDescription(read_description, MAX_PATH)));
|
| + EXPECT_EQ(properties.description, read_description);
|
| }
|
|
|
| - 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_ICON) {
|
| + EXPECT_TRUE(SUCCEEDED(
|
| + i_shell_link->GetIconLocation(read_icon, MAX_PATH, &read_icon_index)));
|
| + 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
|
| // VT_EMPTY.
|
| PROPVARIANT pv_app_id, pv_dual_mode;
|
| - if (FAILED(property_store.QueryFrom(i_shell_link)) ||
|
| - 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;
|
| - }
|
| -
|
| - // 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.
|
| + EXPECT_TRUE(SUCCEEDED(hr = property_store.QueryFrom(i_shell_link)));
|
| + if (FAILED(hr))
|
| + return;
|
| + EXPECT_EQ(S_OK, property_store->GetValue(PKEY_AppUserModel_ID, &pv_app_id));
|
| + EXPECT_EQ(S_OK, property_store->GetValue(PKEY_AppUserModel_IsDualMode,
|
| + &pv_dual_mode));
|
| +
|
| + // 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
|
|
|