Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: base/test/test_shortcut_win.cc

Issue 12286020: Replace FilePath with base::FilePath. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/test/test_file_util_win.cc ('k') | base/test/test_suite.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/test/test_shortcut_win.h" 5 #include "base/test/test_shortcut_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <shlobj.h> 8 #include <shlobj.h>
9 #include <propkey.h> 9 #include <propkey.h>
10 10
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/string16.h" 12 #include "base/string16.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "base/win/scoped_comptr.h" 14 #include "base/win/scoped_comptr.h"
15 #include "base/win/scoped_propvariant.h" 15 #include "base/win/scoped_propvariant.h"
16 #include "base/win/windows_version.h" 16 #include "base/win/windows_version.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace base { 19 namespace base {
20 namespace win { 20 namespace win {
21 21
22 namespace { 22 namespace {
23 23
24 // Validates |actual_path|'s LongPathName case-insensitively matches 24 // Validates |actual_path|'s LongPathName case-insensitively matches
25 // |expected_path|'s LongPathName. 25 // |expected_path|'s LongPathName.
26 void ValidatePathsAreEqual(const FilePath& expected_path, 26 void ValidatePathsAreEqual(const base::FilePath& expected_path,
27 const FilePath& actual_path) { 27 const base::FilePath& actual_path) {
28 wchar_t long_expected_path_chars[MAX_PATH] = {0}; 28 wchar_t long_expected_path_chars[MAX_PATH] = {0};
29 wchar_t long_actual_path_chars[MAX_PATH] = {0}; 29 wchar_t long_actual_path_chars[MAX_PATH] = {0};
30 30
31 // If |expected_path| is empty confirm immediately that |actual_path| is also 31 // If |expected_path| is empty confirm immediately that |actual_path| is also
32 // empty. 32 // empty.
33 if (expected_path.empty()) { 33 if (expected_path.empty()) {
34 EXPECT_TRUE(actual_path.empty()); 34 EXPECT_TRUE(actual_path.empty());
35 return; 35 return;
36 } 36 }
37 37
38 // Proceed with LongPathName matching which will also confirm the paths exist. 38 // Proceed with LongPathName matching which will also confirm the paths exist.
39 EXPECT_NE(0U, ::GetLongPathName( 39 EXPECT_NE(0U, ::GetLongPathName(
40 expected_path.value().c_str(), long_expected_path_chars, MAX_PATH)) 40 expected_path.value().c_str(), long_expected_path_chars, MAX_PATH))
41 << "Failed to get LongPathName of " << expected_path.value(); 41 << "Failed to get LongPathName of " << expected_path.value();
42 EXPECT_NE(0U, ::GetLongPathName( 42 EXPECT_NE(0U, ::GetLongPathName(
43 actual_path.value().c_str(), long_actual_path_chars, MAX_PATH)) 43 actual_path.value().c_str(), long_actual_path_chars, MAX_PATH))
44 << "Failed to get LongPathName of " << actual_path.value(); 44 << "Failed to get LongPathName of " << actual_path.value();
45 45
46 FilePath long_expected_path(long_expected_path_chars); 46 base::FilePath long_expected_path(long_expected_path_chars);
47 FilePath long_actual_path(long_actual_path_chars); 47 base::FilePath long_actual_path(long_actual_path_chars);
48 EXPECT_FALSE(long_expected_path.empty()); 48 EXPECT_FALSE(long_expected_path.empty());
49 EXPECT_FALSE(long_actual_path.empty()); 49 EXPECT_FALSE(long_actual_path.empty());
50 50
51 EXPECT_EQ(long_expected_path, long_actual_path); 51 EXPECT_EQ(long_expected_path, long_actual_path);
52 } 52 }
53 53
54 } // namespace 54 } // namespace
55 55
56 void ValidateShortcut(const FilePath& shortcut_path, 56 void ValidateShortcut(const base::FilePath& shortcut_path,
57 const ShortcutProperties& properties) { 57 const ShortcutProperties& properties) {
58 ScopedComPtr<IShellLink> i_shell_link; 58 ScopedComPtr<IShellLink> i_shell_link;
59 ScopedComPtr<IPersistFile> i_persist_file; 59 ScopedComPtr<IPersistFile> i_persist_file;
60 60
61 wchar_t read_target[MAX_PATH] = {0}; 61 wchar_t read_target[MAX_PATH] = {0};
62 wchar_t read_working_dir[MAX_PATH] = {0}; 62 wchar_t read_working_dir[MAX_PATH] = {0};
63 wchar_t read_arguments[MAX_PATH] = {0}; 63 wchar_t read_arguments[MAX_PATH] = {0};
64 wchar_t read_description[MAX_PATH] = {0}; 64 wchar_t read_description[MAX_PATH] = {0};
65 wchar_t read_icon[MAX_PATH] = {0}; 65 wchar_t read_icon[MAX_PATH] = {0};
66 int read_icon_index = 0; 66 int read_icon_index = 0;
(...skipping 13 matching lines...) Expand all
80 // Load the shortcut. 80 // Load the shortcut.
81 EXPECT_TRUE(SUCCEEDED(hr = i_persist_file->Load( 81 EXPECT_TRUE(SUCCEEDED(hr = i_persist_file->Load(
82 shortcut_path.value().c_str(), 0))) << "Failed to load shortcut at " 82 shortcut_path.value().c_str(), 0))) << "Failed to load shortcut at "
83 << shortcut_path.value(); 83 << shortcut_path.value();
84 if (FAILED(hr)) 84 if (FAILED(hr))
85 return; 85 return;
86 86
87 if (properties.options & ShortcutProperties::PROPERTIES_TARGET) { 87 if (properties.options & ShortcutProperties::PROPERTIES_TARGET) {
88 EXPECT_TRUE(SUCCEEDED( 88 EXPECT_TRUE(SUCCEEDED(
89 i_shell_link->GetPath(read_target, MAX_PATH, NULL, SLGP_SHORTPATH))); 89 i_shell_link->GetPath(read_target, MAX_PATH, NULL, SLGP_SHORTPATH)));
90 ValidatePathsAreEqual(properties.target, FilePath(read_target)); 90 ValidatePathsAreEqual(properties.target, base::FilePath(read_target));
91 } 91 }
92 92
93 if (properties.options & ShortcutProperties::PROPERTIES_WORKING_DIR) { 93 if (properties.options & ShortcutProperties::PROPERTIES_WORKING_DIR) {
94 EXPECT_TRUE(SUCCEEDED( 94 EXPECT_TRUE(SUCCEEDED(
95 i_shell_link->GetWorkingDirectory(read_working_dir, MAX_PATH))); 95 i_shell_link->GetWorkingDirectory(read_working_dir, MAX_PATH)));
96 ValidatePathsAreEqual(properties.working_dir, FilePath(read_working_dir)); 96 ValidatePathsAreEqual(properties.working_dir,
97 base::FilePath(read_working_dir));
97 } 98 }
98 99
99 if (properties.options & ShortcutProperties::PROPERTIES_ARGUMENTS) { 100 if (properties.options & ShortcutProperties::PROPERTIES_ARGUMENTS) {
100 EXPECT_TRUE(SUCCEEDED( 101 EXPECT_TRUE(SUCCEEDED(
101 i_shell_link->GetArguments(read_arguments, MAX_PATH))); 102 i_shell_link->GetArguments(read_arguments, MAX_PATH)));
102 EXPECT_EQ(properties.arguments, read_arguments); 103 EXPECT_EQ(properties.arguments, read_arguments);
103 } 104 }
104 105
105 if (properties.options & ShortcutProperties::PROPERTIES_DESCRIPTION) { 106 if (properties.options & ShortcutProperties::PROPERTIES_DESCRIPTION) {
106 EXPECT_TRUE(SUCCEEDED( 107 EXPECT_TRUE(SUCCEEDED(
107 i_shell_link->GetDescription(read_description, MAX_PATH))); 108 i_shell_link->GetDescription(read_description, MAX_PATH)));
108 EXPECT_EQ(properties.description, read_description); 109 EXPECT_EQ(properties.description, read_description);
109 } 110 }
110 111
111 if (properties.options & ShortcutProperties::PROPERTIES_ICON) { 112 if (properties.options & ShortcutProperties::PROPERTIES_ICON) {
112 EXPECT_TRUE(SUCCEEDED( 113 EXPECT_TRUE(SUCCEEDED(
113 i_shell_link->GetIconLocation(read_icon, MAX_PATH, &read_icon_index))); 114 i_shell_link->GetIconLocation(read_icon, MAX_PATH, &read_icon_index)));
114 ValidatePathsAreEqual(properties.icon, FilePath(read_icon)); 115 ValidatePathsAreEqual(properties.icon, base::FilePath(read_icon));
115 EXPECT_EQ(properties.icon_index, read_icon_index); 116 EXPECT_EQ(properties.icon_index, read_icon_index);
116 } 117 }
117 118
118 if (GetVersion() >= VERSION_WIN7) { 119 if (GetVersion() >= VERSION_WIN7) {
119 ScopedComPtr<IPropertyStore> property_store; 120 ScopedComPtr<IPropertyStore> property_store;
120 EXPECT_TRUE(SUCCEEDED(hr = property_store.QueryFrom(i_shell_link))); 121 EXPECT_TRUE(SUCCEEDED(hr = property_store.QueryFrom(i_shell_link)));
121 if (FAILED(hr)) 122 if (FAILED(hr))
122 return; 123 return;
123 124
124 if (properties.options & ShortcutProperties::PROPERTIES_APP_ID) { 125 if (properties.options & ShortcutProperties::PROPERTIES_APP_ID) {
(...skipping 26 matching lines...) Expand all
151 break; 152 break;
152 default: 153 default:
153 ADD_FAILURE() << "Unexpected variant type: " << pv_dual_mode.get().vt; 154 ADD_FAILURE() << "Unexpected variant type: " << pv_dual_mode.get().vt;
154 } 155 }
155 } 156 }
156 } 157 }
157 } 158 }
158 159
159 } // namespace win 160 } // namespace win
160 } // namespace base 161 } // namespace base
OLDNEW
« no previous file with comments | « base/test/test_file_util_win.cc ('k') | base/test/test_suite.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698