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

Side by Side Diff: base/files/file_unittest.cc

Issue 394313002: Add support for loading pak files from arbitrary file regions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Win implementation Created 6 years, 5 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
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/file_util.h" 5 #include "base/file_util.h"
6 #include "base/files/file.h" 6 #include "base/files/file.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 265
266 TEST(FileTest, Length) { 266 TEST(FileTest, Length) {
267 base::ScopedTempDir temp_dir; 267 base::ScopedTempDir temp_dir;
268 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 268 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
269 FilePath file_path = temp_dir.path().AppendASCII("truncate_file"); 269 FilePath file_path = temp_dir.path().AppendASCII("truncate_file");
270 File file(file_path, 270 File file(file_path,
271 base::File::FLAG_CREATE | base::File::FLAG_READ | 271 base::File::FLAG_CREATE | base::File::FLAG_READ |
272 base::File::FLAG_WRITE); 272 base::File::FLAG_WRITE);
273 ASSERT_TRUE(file.IsValid()); 273 ASSERT_TRUE(file.IsValid());
274 EXPECT_EQ(0, file.GetLength()); 274 EXPECT_EQ(0, file.GetLength());
275 EXPECT_EQ(0, base::File::Region(file).offset);
276 EXPECT_EQ(0, base::File::Region(file).size);
275 277
276 // Write "test" to the file. 278 // Write "test" to the file.
277 char data_to_write[] = "test"; 279 char data_to_write[] = "test";
278 int kTestDataSize = 4; 280 int kTestDataSize = 4;
279 int bytes_written = file.Write(0, data_to_write, kTestDataSize); 281 int bytes_written = file.Write(0, data_to_write, kTestDataSize);
280 EXPECT_EQ(kTestDataSize, bytes_written); 282 EXPECT_EQ(kTestDataSize, bytes_written);
281 283
282 // Extend the file. 284 // Extend the file.
283 const int kExtendedFileLength = 10; 285 const int kExtendedFileLength = 10;
284 int64 file_size = 0; 286 int64 file_size = 0;
285 EXPECT_TRUE(file.SetLength(kExtendedFileLength)); 287 EXPECT_TRUE(file.SetLength(kExtendedFileLength));
286 EXPECT_EQ(kExtendedFileLength, file.GetLength()); 288 EXPECT_EQ(kExtendedFileLength, file.GetLength());
287 EXPECT_TRUE(GetFileSize(file_path, &file_size)); 289 EXPECT_TRUE(GetFileSize(file_path, &file_size));
288 EXPECT_EQ(kExtendedFileLength, file_size); 290 EXPECT_EQ(kExtendedFileLength, file_size);
291 EXPECT_EQ(0, base::File::Region(file).offset);
292 EXPECT_EQ(kExtendedFileLength, base::File::Region(file).size);
289 293
290 // Make sure the file was zero-padded. 294 // Make sure the file was zero-padded.
291 char data_read[32]; 295 char data_read[32];
292 int bytes_read = file.Read(0, data_read, static_cast<int>(file_size)); 296 int bytes_read = file.Read(0, data_read, static_cast<int>(file_size));
293 EXPECT_EQ(file_size, bytes_read); 297 EXPECT_EQ(file_size, bytes_read);
294 for (int i = 0; i < kTestDataSize; i++) 298 for (int i = 0; i < kTestDataSize; i++)
295 EXPECT_EQ(data_to_write[i], data_read[i]); 299 EXPECT_EQ(data_to_write[i], data_read[i]);
296 for (int i = kTestDataSize; i < file_size; i++) 300 for (int i = kTestDataSize; i < file_size; i++)
297 EXPECT_EQ(0, data_read[i]); 301 EXPECT_EQ(0, data_read[i]);
298 302
299 // Truncate the file. 303 // Truncate the file.
300 const int kTruncatedFileLength = 2; 304 const int kTruncatedFileLength = 2;
301 EXPECT_TRUE(file.SetLength(kTruncatedFileLength)); 305 EXPECT_TRUE(file.SetLength(kTruncatedFileLength));
302 EXPECT_EQ(kTruncatedFileLength, file.GetLength()); 306 EXPECT_EQ(kTruncatedFileLength, file.GetLength());
303 EXPECT_TRUE(GetFileSize(file_path, &file_size)); 307 EXPECT_TRUE(GetFileSize(file_path, &file_size));
304 EXPECT_EQ(kTruncatedFileLength, file_size); 308 EXPECT_EQ(kTruncatedFileLength, file_size);
309 EXPECT_EQ(0, base::File::Region(file).offset);
310 EXPECT_EQ(kTruncatedFileLength, base::File::Region(file).size);
305 311
306 // Make sure the file was truncated. 312 // Make sure the file was truncated.
307 bytes_read = file.Read(0, data_read, kTestDataSize); 313 bytes_read = file.Read(0, data_read, kTestDataSize);
308 EXPECT_EQ(file_size, bytes_read); 314 EXPECT_EQ(file_size, bytes_read);
309 for (int i = 0; i < file_size; i++) 315 for (int i = 0; i < file_size; i++)
310 EXPECT_EQ(data_to_write[i], data_read[i]); 316 EXPECT_EQ(data_to_write[i], data_read[i]);
311 } 317 }
312 318
313 // Flakily fails: http://crbug.com/86494 319 // Flakily fails: http://crbug.com/86494
314 #if defined(OS_ANDROID) 320 #if defined(OS_ANDROID)
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 NULL)); 465 NULL));
460 ASSERT_TRUE(dir.IsValid()); 466 ASSERT_TRUE(dir.IsValid());
461 467
462 base::File::Info info; 468 base::File::Info info;
463 EXPECT_TRUE(dir.GetInfo(&info)); 469 EXPECT_TRUE(dir.GetInfo(&info));
464 EXPECT_TRUE(info.is_directory); 470 EXPECT_TRUE(info.is_directory);
465 EXPECT_FALSE(info.is_symbolic_link); 471 EXPECT_FALSE(info.is_symbolic_link);
466 EXPECT_EQ(0, info.size); 472 EXPECT_EQ(0, info.size);
467 } 473 }
468 #endif // defined(OS_WIN) 474 #endif // defined(OS_WIN)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698