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

Side by Side Diff: chrome_elf/create_file/chrome_create_file_unittest.cc

Issue 603803002: Remove implicit HANDLE conversions from elf. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome_elf/create_file/chrome_create_file.h" 5 #include "chrome_elf/create_file/chrome_create_file.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include <bitset> 9 #include <bitset>
10 #include <string> 10 #include <string>
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 file_handle.Set(CreateFileNTDLL(path.value().c_str(), 235 file_handle.Set(CreateFileNTDLL(path.value().c_str(),
236 GENERIC_WRITE, 236 GENERIC_WRITE,
237 FILE_SHARE_READ, 237 FILE_SHARE_READ,
238 NULL, 238 NULL,
239 CREATE_ALWAYS, 239 CREATE_ALWAYS,
240 FILE_ATTRIBUTE_NORMAL | flag, 240 FILE_ATTRIBUTE_NORMAL | flag,
241 NULL)); 241 NULL));
242 } 242 }
243 243
244 244
245 EXPECT_FALSE(file_handle == INVALID_HANDLE_VALUE); 245 EXPECT_TRUE(file_handle.IsValid());
246 ::WriteFile(file_handle, kTestData, buffer_size, &bytes_written, NULL); 246 ::WriteFile(file_handle.Get(), kTestData, buffer_size, &bytes_written,
247 NULL);
247 EXPECT_EQ(buffer_size, bytes_written); 248 EXPECT_EQ(buffer_size, bytes_written);
248 } 249 }
249 250
250 void DoReadCheck(const base::FilePath& path, DWORD flag, bool is_system) { 251 void DoReadCheck(const base::FilePath& path, DWORD flag, bool is_system) {
251 base::win::ScopedHandle file_handle; 252 base::win::ScopedHandle file_handle;
252 const char kTestData[] = "0123456789"; 253 const char kTestData[] = "0123456789";
253 int buffer_size = sizeof(kTestData) - 1; 254 int buffer_size = sizeof(kTestData) - 1;
254 DWORD bytes_read; 255 DWORD bytes_read;
255 char read_buffer[10]; 256 char read_buffer[10];
256 257
257 if (is_system) { 258 if (is_system) {
258 file_handle.Set(::CreateFileW(path.value().c_str(), 259 file_handle.Set(::CreateFileW(path.value().c_str(),
259 GENERIC_READ, 260 GENERIC_READ,
260 0, 261 0,
261 NULL, 262 NULL,
262 OPEN_ALWAYS, 263 OPEN_ALWAYS,
263 FILE_ATTRIBUTE_NORMAL | flag, 264 FILE_ATTRIBUTE_NORMAL | flag,
264 NULL)); 265 NULL));
265 } else { 266 } else {
266 file_handle.Set(CreateFileNTDLL(path.value().c_str(), 267 file_handle.Set(CreateFileNTDLL(path.value().c_str(),
267 GENERIC_READ, 268 GENERIC_READ,
268 0, 269 0,
269 NULL, 270 NULL,
270 OPEN_ALWAYS, 271 OPEN_ALWAYS,
271 FILE_ATTRIBUTE_NORMAL | flag, 272 FILE_ATTRIBUTE_NORMAL | flag,
272 NULL)); 273 NULL));
273 } 274 }
274 275
275 EXPECT_FALSE(file_handle == INVALID_HANDLE_VALUE); 276 EXPECT_TRUE(file_handle.IsValid());
276 ::ReadFile(file_handle, read_buffer, buffer_size, &bytes_read, NULL); 277 ::ReadFile(file_handle.Get(), read_buffer, buffer_size, &bytes_read, NULL);
277 EXPECT_EQ(buffer_size, bytes_read); 278 EXPECT_EQ(buffer_size, bytes_read);
278 EXPECT_EQ(0, memcmp(kTestData, read_buffer, bytes_read)); 279 EXPECT_EQ(0, memcmp(kTestData, read_buffer, bytes_read));
279 } 280 }
280 281
281 void RunChecks(DWORD flag, bool check_reads) { 282 void RunChecks(DWORD flag, bool check_reads) {
282 // Make sure we can write to this file handle when called via the system. 283 // Make sure we can write to this file handle when called via the system.
283 base::FilePath junk_path_1 = temp_dir_.path().Append(L"junk_1.txt"); 284 base::FilePath junk_path_1 = temp_dir_.path().Append(L"junk_1.txt");
284 base::FilePath junk_path_2 = temp_dir_.path().Append(L"junk_2.txt"); 285 base::FilePath junk_path_2 = temp_dir_.path().Append(L"junk_2.txt");
285 DoWriteCheck(junk_path_1, flag, true); 286 DoWriteCheck(junk_path_1, flag, true);
286 DoWriteCheck(junk_path_2, flag, false); 287 DoWriteCheck(junk_path_2, flag, false);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 DoReadCheck(file_name, FILE_ATTRIBUTE_NORMAL, false); 400 DoReadCheck(file_name, FILE_ATTRIBUTE_NORMAL, false);
400 } 401 }
401 402
402 TEST_F(ChromeCreateFileTest, ReadWriteFromThunk) { 403 TEST_F(ChromeCreateFileTest, ReadWriteFromThunk) {
403 base::FilePath file_name = temp_dir_.path().Append(L"some_file.txt"); 404 base::FilePath file_name = temp_dir_.path().Append(L"some_file.txt");
404 DoWriteCheck(file_name, FILE_ATTRIBUTE_NORMAL, false); 405 DoWriteCheck(file_name, FILE_ATTRIBUTE_NORMAL, false);
405 DoReadCheck(file_name, FILE_ATTRIBUTE_NORMAL, false); 406 DoReadCheck(file_name, FILE_ATTRIBUTE_NORMAL, false);
406 } 407 }
407 408
408 } // namespace 409 } // namespace
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698