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

Side by Side Diff: chrome/installer/util/work_item_list_unittest.cc

Issue 6090006: Regkey functions return error code instead of bool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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
OLDNEW
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 "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
(...skipping 10 matching lines...) Expand all
21 21
22 wchar_t test_root[] = L"ListList"; 22 wchar_t test_root[] = L"ListList";
23 wchar_t data_str[] = L"data_111"; 23 wchar_t data_str[] = L"data_111";
24 24
25 class WorkItemListTest : public testing::Test { 25 class WorkItemListTest : public testing::Test {
26 protected: 26 protected:
27 virtual void SetUp() { 27 virtual void SetUp() {
28 // Create a temporary key for testing 28 // Create a temporary key for testing
29 RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); 29 RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS);
30 key.DeleteKey(test_root); 30 key.DeleteKey(test_root);
31 ASSERT_FALSE(key.Open(HKEY_CURRENT_USER, test_root, KEY_READ)); 31 ASSERT_NE(ERROR_SUCCESS, key.Open(HKEY_CURRENT_USER, test_root, KEY_READ));
32 ASSERT_TRUE(key.Create(HKEY_CURRENT_USER, test_root, KEY_READ)); 32 ASSERT_EQ(ERROR_SUCCESS,
33 key.Create(HKEY_CURRENT_USER, test_root, KEY_READ));
33 34
34 // Create a temp directory for test. 35 // Create a temp directory for test.
35 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_)); 36 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_));
36 test_dir_ = test_dir_.AppendASCII("WorkItemListTest"); 37 test_dir_ = test_dir_.AppendASCII("WorkItemListTest");
37 file_util::Delete(test_dir_, true); 38 file_util::Delete(test_dir_, true);
38 ASSERT_FALSE(file_util::PathExists(test_dir_)); 39 ASSERT_FALSE(file_util::PathExists(test_dir_));
39 file_util::CreateDirectoryW(test_dir_); 40 file_util::CreateDirectoryW(test_dir_);
40 ASSERT_TRUE(file_util::PathExists(test_dir_)); 41 ASSERT_TRUE(file_util::PathExists(test_dir_));
41 } 42 }
42 43
43 virtual void TearDown() { 44 virtual void TearDown() {
44 logging::CloseLogFile(); 45 logging::CloseLogFile();
45 // Clean up test directory 46 // Clean up test directory
46 ASSERT_TRUE(file_util::Delete(test_dir_, true)); 47 ASSERT_TRUE(file_util::Delete(test_dir_, true));
47 ASSERT_FALSE(file_util::PathExists(test_dir_)); 48 ASSERT_FALSE(file_util::PathExists(test_dir_));
48 // Clean up the temporary key 49 // Clean up the temporary key
49 RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS); 50 RegKey key(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS);
50 ASSERT_TRUE(key.DeleteKey(test_root)); 51 ASSERT_EQ(ERROR_SUCCESS, key.DeleteKey(test_root));
51 } 52 }
52 53
53 FilePath test_dir_; 54 FilePath test_dir_;
54 }; 55 };
55 56
56 } // namespace 57 } // namespace
57 58
58 // Execute a WorkItem list successfully and then rollback. 59 // Execute a WorkItem list successfully and then rollback.
59 TEST_F(WorkItemListTest, ExecutionSuccess) { 60 TEST_F(WorkItemListTest, ExecutionSuccess) {
60 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); 61 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList());
(...skipping 20 matching lines...) Expand all
81 std::wstring data(data_str); 82 std::wstring data(data_str);
82 work_item.reset(reinterpret_cast<WorkItem*>( 83 work_item.reset(reinterpret_cast<WorkItem*>(
83 WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, key_to_create, 84 WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, key_to_create,
84 name, data, false))); 85 name, data, false)));
85 work_item_list->AddWorkItem(work_item.release()); 86 work_item_list->AddWorkItem(work_item.release());
86 87
87 EXPECT_TRUE(work_item_list->Do()); 88 EXPECT_TRUE(work_item_list->Do());
88 89
89 // Verify all WorkItems have been executed. 90 // Verify all WorkItems have been executed.
90 RegKey key; 91 RegKey key;
91 EXPECT_TRUE(key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); 92 EXPECT_EQ(ERROR_SUCCESS,
93 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ));
92 std::wstring read_out; 94 std::wstring read_out;
93 EXPECT_TRUE(key.ReadValue(name.c_str(), &read_out)); 95 EXPECT_EQ(ERROR_SUCCESS, key.ReadValue(name.c_str(), &read_out));
94 EXPECT_EQ(0, read_out.compare(data_str)); 96 EXPECT_EQ(0, read_out.compare(data_str));
95 key.Close(); 97 key.Close();
96 EXPECT_TRUE(file_util::PathExists(dir_to_create)); 98 EXPECT_TRUE(file_util::PathExists(dir_to_create));
97 99
98 work_item_list->Rollback(); 100 work_item_list->Rollback();
99 101
100 // Verify everything is rolled back. 102 // Verify everything is rolled back.
101 // The value must have been deleted first in roll back otherwise the key 103 // The value must have been deleted first in roll back otherwise the key
102 // can not be deleted. 104 // can not be deleted.
103 EXPECT_FALSE(key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); 105 EXPECT_NE(ERROR_SUCCESS,
106 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ));
104 EXPECT_FALSE(file_util::PathExists(top_dir_to_create)); 107 EXPECT_FALSE(file_util::PathExists(top_dir_to_create));
105 } 108 }
106 109
107 // Execute a WorkItem list. Fail in the middle. Rollback what has been done. 110 // Execute a WorkItem list. Fail in the middle. Rollback what has been done.
108 TEST_F(WorkItemListTest, ExecutionFailAndRollback) { 111 TEST_F(WorkItemListTest, ExecutionFailAndRollback) {
109 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); 112 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList());
110 scoped_ptr<WorkItem> work_item; 113 scoped_ptr<WorkItem> work_item;
111 114
112 FilePath top_dir_to_create(test_dir_); 115 FilePath top_dir_to_create(test_dir_);
113 top_dir_to_create = top_dir_to_create.AppendASCII("a"); 116 top_dir_to_create = top_dir_to_create.AppendASCII("a");
(...skipping 24 matching lines...) Expand all
138 // This one will not be executed because we will fail early. 141 // This one will not be executed because we will fail early.
139 work_item.reset(reinterpret_cast<WorkItem*>( 142 work_item.reset(reinterpret_cast<WorkItem*>(
140 WorkItem::CreateCreateRegKeyWorkItem(HKEY_CURRENT_USER, 143 WorkItem::CreateCreateRegKeyWorkItem(HKEY_CURRENT_USER,
141 not_created_key))); 144 not_created_key)));
142 work_item_list->AddWorkItem(work_item.release()); 145 work_item_list->AddWorkItem(work_item.release());
143 146
144 EXPECT_FALSE(work_item_list->Do()); 147 EXPECT_FALSE(work_item_list->Do());
145 148
146 // Verify the first 2 WorkItems have been executed. 149 // Verify the first 2 WorkItems have been executed.
147 RegKey key; 150 RegKey key;
148 EXPECT_TRUE(key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); 151 EXPECT_EQ(ERROR_SUCCESS,
152 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ));
149 key.Close(); 153 key.Close();
150 EXPECT_TRUE(file_util::PathExists(dir_to_create)); 154 EXPECT_TRUE(file_util::PathExists(dir_to_create));
151 // The last one should not be there. 155 // The last one should not be there.
152 EXPECT_FALSE(key.Open(HKEY_CURRENT_USER, not_created_key.c_str(), 156 EXPECT_NE(ERROR_SUCCESS,
153 KEY_READ)); 157 key.Open(HKEY_CURRENT_USER, not_created_key.c_str(), KEY_READ));
154 158
155 work_item_list->Rollback(); 159 work_item_list->Rollback();
156 160
157 // Verify everything is rolled back. 161 // Verify everything is rolled back.
158 EXPECT_FALSE(key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); 162 EXPECT_NE(ERROR_SUCCESS,
163 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ));
159 EXPECT_FALSE(file_util::PathExists(top_dir_to_create)); 164 EXPECT_FALSE(file_util::PathExists(top_dir_to_create));
160 } 165 }
161 166
162 TEST_F(WorkItemListTest, ConditionalExecutionSuccess) { 167 TEST_F(WorkItemListTest, ConditionalExecutionSuccess) {
163 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); 168 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList());
164 scoped_ptr<WorkItem> work_item; 169 scoped_ptr<WorkItem> work_item;
165 170
166 FilePath top_dir_to_create(test_dir_); 171 FilePath top_dir_to_create(test_dir_);
167 top_dir_to_create = top_dir_to_create.AppendASCII("a"); 172 top_dir_to_create = top_dir_to_create.AppendASCII("a");
168 FilePath dir_to_create(top_dir_to_create); 173 FilePath dir_to_create(top_dir_to_create);
(...skipping 20 matching lines...) Expand all
189 WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, key_to_create, 194 WorkItem::CreateSetRegValueWorkItem(HKEY_CURRENT_USER, key_to_create,
190 name, data, false))); 195 name, data, false)));
191 conditional_work_item_list->AddWorkItem(work_item.release()); 196 conditional_work_item_list->AddWorkItem(work_item.release());
192 197
193 work_item_list->AddWorkItem(conditional_work_item_list.release()); 198 work_item_list->AddWorkItem(conditional_work_item_list.release());
194 199
195 EXPECT_TRUE(work_item_list->Do()); 200 EXPECT_TRUE(work_item_list->Do());
196 201
197 // Verify all WorkItems have been executed. 202 // Verify all WorkItems have been executed.
198 RegKey key; 203 RegKey key;
199 EXPECT_TRUE(key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); 204 EXPECT_EQ(ERROR_SUCCESS,
205 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ));
200 std::wstring read_out; 206 std::wstring read_out;
201 EXPECT_TRUE(key.ReadValue(name.c_str(), &read_out)); 207 EXPECT_EQ(ERROR_SUCCESS, key.ReadValue(name.c_str(), &read_out));
202 EXPECT_EQ(0, read_out.compare(data_str)); 208 EXPECT_EQ(0, read_out.compare(data_str));
203 key.Close(); 209 key.Close();
204 EXPECT_TRUE(file_util::PathExists(dir_to_create)); 210 EXPECT_TRUE(file_util::PathExists(dir_to_create));
205 211
206 work_item_list->Rollback(); 212 work_item_list->Rollback();
207 213
208 // Verify everything is rolled back. 214 // Verify everything is rolled back.
209 // The value must have been deleted first in roll back otherwise the key 215 // The value must have been deleted first in roll back otherwise the key
210 // can not be deleted. 216 // can not be deleted.
211 EXPECT_FALSE(key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); 217 EXPECT_NE(ERROR_SUCCESS,
218 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ));
212 EXPECT_FALSE(file_util::PathExists(top_dir_to_create)); 219 EXPECT_FALSE(file_util::PathExists(top_dir_to_create));
213 } 220 }
214 221
215 TEST_F(WorkItemListTest, ConditionalExecutionConditionFailure) { 222 TEST_F(WorkItemListTest, ConditionalExecutionConditionFailure) {
216 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList()); 223 scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList());
217 scoped_ptr<WorkItem> work_item; 224 scoped_ptr<WorkItem> work_item;
218 225
219 FilePath top_dir_to_create(test_dir_); 226 FilePath top_dir_to_create(test_dir_);
220 top_dir_to_create = top_dir_to_create.AppendASCII("a"); 227 top_dir_to_create = top_dir_to_create.AppendASCII("a");
221 FilePath dir_to_create(top_dir_to_create); 228 FilePath dir_to_create(top_dir_to_create);
(...skipping 21 matching lines...) Expand all
243 name, data, false))); 250 name, data, false)));
244 conditional_work_item_list->AddWorkItem(work_item.release()); 251 conditional_work_item_list->AddWorkItem(work_item.release());
245 252
246 work_item_list->AddWorkItem(conditional_work_item_list.release()); 253 work_item_list->AddWorkItem(conditional_work_item_list.release());
247 254
248 EXPECT_TRUE(work_item_list->Do()); 255 EXPECT_TRUE(work_item_list->Do());
249 256
250 // Verify that the WorkItems added as part of the conditional list have NOT 257 // Verify that the WorkItems added as part of the conditional list have NOT
251 // been executed. 258 // been executed.
252 RegKey key; 259 RegKey key;
253 EXPECT_FALSE(key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); 260 EXPECT_NE(ERROR_SUCCESS,
261 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ));
254 std::wstring read_out; 262 std::wstring read_out;
255 EXPECT_FALSE(key.ReadValue(name.c_str(), &read_out)); 263 EXPECT_NE(ERROR_SUCCESS, key.ReadValue(name.c_str(), &read_out));
256 key.Close(); 264 key.Close();
257 265
258 // Verify that the other work item was executed. 266 // Verify that the other work item was executed.
259 EXPECT_TRUE(file_util::PathExists(dir_to_create)); 267 EXPECT_TRUE(file_util::PathExists(dir_to_create));
260 268
261 work_item_list->Rollback(); 269 work_item_list->Rollback();
262 270
263 // Verify everything is rolled back. 271 // Verify everything is rolled back.
264 // The value must have been deleted first in roll back otherwise the key 272 // The value must have been deleted first in roll back otherwise the key
265 // can not be deleted. 273 // can not be deleted.
266 EXPECT_FALSE(key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ)); 274 EXPECT_NE(ERROR_SUCCESS,
275 key.Open(HKEY_CURRENT_USER, key_to_create.c_str(), KEY_READ));
267 EXPECT_FALSE(file_util::PathExists(top_dir_to_create)); 276 EXPECT_FALSE(file_util::PathExists(top_dir_to_create));
268 } 277 }
269 278
270 279
OLDNEW
« no previous file with comments | « chrome/installer/util/work_item_list.cc ('k') | chrome/test/mini_installer_test/chrome_mini_installer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698