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

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

Issue 1549853002: Switch to standard integer types in base/files/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 5 years 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 | « base/files/file_tracing.cc ('k') | base/files/file_util.h » ('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/files/file.h" 5 #include "base/files/file.h"
6 6
7 #include <stdint.h>
8
7 #include <utility> 9 #include <utility>
8 10
9 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
11 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "build/build_config.h"
12 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
13 16
14 using base::File; 17 using base::File;
15 using base::FilePath; 18 using base::FilePath;
16 19
17 TEST(FileTest, Create) { 20 TEST(FileTest, Create) {
18 base::ScopedTempDir temp_dir; 21 base::ScopedTempDir temp_dir;
19 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 22 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
20 FilePath file_path = temp_dir.path().AppendASCII("create_file_1"); 23 FilePath file_path = temp_dir.path().AppendASCII("create_file_1");
21 24
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 EXPECT_EQ(data_to_write[i], data_read_1[i]); 198 EXPECT_EQ(data_to_write[i], data_read_1[i]);
196 199
197 // Write past the end of the file. 200 // Write past the end of the file.
198 const int kOffsetBeyondEndOfFile = 10; 201 const int kOffsetBeyondEndOfFile = 10;
199 const int kPartialWriteLength = 2; 202 const int kPartialWriteLength = 2;
200 bytes_written = file.Write(kOffsetBeyondEndOfFile, 203 bytes_written = file.Write(kOffsetBeyondEndOfFile,
201 data_to_write, kPartialWriteLength); 204 data_to_write, kPartialWriteLength);
202 EXPECT_EQ(kPartialWriteLength, bytes_written); 205 EXPECT_EQ(kPartialWriteLength, bytes_written);
203 206
204 // Make sure the file was extended. 207 // Make sure the file was extended.
205 int64 file_size = 0; 208 int64_t file_size = 0;
206 EXPECT_TRUE(GetFileSize(file_path, &file_size)); 209 EXPECT_TRUE(GetFileSize(file_path, &file_size));
207 EXPECT_EQ(kOffsetBeyondEndOfFile + kPartialWriteLength, file_size); 210 EXPECT_EQ(kOffsetBeyondEndOfFile + kPartialWriteLength, file_size);
208 211
209 // Make sure the file was zero-padded. 212 // Make sure the file was zero-padded.
210 char data_read_2[32]; 213 char data_read_2[32];
211 bytes_read = file.Read(0, data_read_2, static_cast<int>(file_size)); 214 bytes_read = file.Read(0, data_read_2, static_cast<int>(file_size));
212 EXPECT_EQ(file_size, bytes_read); 215 EXPECT_EQ(file_size, bytes_read);
213 for (int i = 0; i < kTestDataSize; i++) 216 for (int i = 0; i < kTestDataSize; i++)
214 EXPECT_EQ(data_to_write[i], data_read_2[i]); 217 EXPECT_EQ(data_to_write[i], data_read_2[i]);
215 for (int i = kTestDataSize; i < kOffsetBeyondEndOfFile; i++) 218 for (int i = kTestDataSize; i < kOffsetBeyondEndOfFile; i++)
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 EXPECT_EQ(0, file.GetLength()); 280 EXPECT_EQ(0, file.GetLength());
278 281
279 // Write "test" to the file. 282 // Write "test" to the file.
280 char data_to_write[] = "test"; 283 char data_to_write[] = "test";
281 int kTestDataSize = 4; 284 int kTestDataSize = 4;
282 int bytes_written = file.Write(0, data_to_write, kTestDataSize); 285 int bytes_written = file.Write(0, data_to_write, kTestDataSize);
283 EXPECT_EQ(kTestDataSize, bytes_written); 286 EXPECT_EQ(kTestDataSize, bytes_written);
284 287
285 // Extend the file. 288 // Extend the file.
286 const int kExtendedFileLength = 10; 289 const int kExtendedFileLength = 10;
287 int64 file_size = 0; 290 int64_t file_size = 0;
288 EXPECT_TRUE(file.SetLength(kExtendedFileLength)); 291 EXPECT_TRUE(file.SetLength(kExtendedFileLength));
289 EXPECT_EQ(kExtendedFileLength, file.GetLength()); 292 EXPECT_EQ(kExtendedFileLength, file.GetLength());
290 EXPECT_TRUE(GetFileSize(file_path, &file_size)); 293 EXPECT_TRUE(GetFileSize(file_path, &file_size));
291 EXPECT_EQ(kExtendedFileLength, file_size); 294 EXPECT_EQ(kExtendedFileLength, file_size);
292 295
293 // Make sure the file was zero-padded. 296 // Make sure the file was zero-padded.
294 char data_read[32]; 297 char data_read[32];
295 int bytes_read = file.Read(0, data_read, static_cast<int>(file_size)); 298 int bytes_read = file.Read(0, data_read, static_cast<int>(file_size));
296 EXPECT_EQ(file_size, bytes_read); 299 EXPECT_EQ(file_size, bytes_read);
297 for (int i = 0; i < kTestDataSize; i++) 300 for (int i = 0; i < kTestDataSize; i++)
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 433
431 TEST(FileTest, Seek) { 434 TEST(FileTest, Seek) {
432 base::ScopedTempDir temp_dir; 435 base::ScopedTempDir temp_dir;
433 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 436 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
434 FilePath file_path = temp_dir.path().AppendASCII("seek_file"); 437 FilePath file_path = temp_dir.path().AppendASCII("seek_file");
435 File file(file_path, 438 File file(file_path,
436 base::File::FLAG_CREATE | base::File::FLAG_READ | 439 base::File::FLAG_CREATE | base::File::FLAG_READ |
437 base::File::FLAG_WRITE); 440 base::File::FLAG_WRITE);
438 ASSERT_TRUE(file.IsValid()); 441 ASSERT_TRUE(file.IsValid());
439 442
440 const int64 kOffset = 10; 443 const int64_t kOffset = 10;
441 EXPECT_EQ(kOffset, file.Seek(base::File::FROM_BEGIN, kOffset)); 444 EXPECT_EQ(kOffset, file.Seek(base::File::FROM_BEGIN, kOffset));
442 EXPECT_EQ(2 * kOffset, file.Seek(base::File::FROM_CURRENT, kOffset)); 445 EXPECT_EQ(2 * kOffset, file.Seek(base::File::FROM_CURRENT, kOffset));
443 EXPECT_EQ(kOffset, file.Seek(base::File::FROM_CURRENT, -kOffset)); 446 EXPECT_EQ(kOffset, file.Seek(base::File::FROM_CURRENT, -kOffset));
444 EXPECT_TRUE(file.SetLength(kOffset * 2)); 447 EXPECT_TRUE(file.SetLength(kOffset * 2));
445 EXPECT_EQ(kOffset, file.Seek(base::File::FROM_END, -kOffset)); 448 EXPECT_EQ(kOffset, file.Seek(base::File::FROM_END, -kOffset));
446 } 449 }
447 450
448 TEST(FileTest, Duplicate) { 451 TEST(FileTest, Duplicate) {
449 base::ScopedTempDir temp_dir; 452 base::ScopedTempDir temp_dir;
450 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 453 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 NULL)); 508 NULL));
506 ASSERT_TRUE(dir.IsValid()); 509 ASSERT_TRUE(dir.IsValid());
507 510
508 base::File::Info info; 511 base::File::Info info;
509 EXPECT_TRUE(dir.GetInfo(&info)); 512 EXPECT_TRUE(dir.GetInfo(&info));
510 EXPECT_TRUE(info.is_directory); 513 EXPECT_TRUE(info.is_directory);
511 EXPECT_FALSE(info.is_symbolic_link); 514 EXPECT_FALSE(info.is_symbolic_link);
512 EXPECT_EQ(0, info.size); 515 EXPECT_EQ(0, info.size);
513 } 516 }
514 #endif // defined(OS_WIN) 517 #endif // defined(OS_WIN)
OLDNEW
« no previous file with comments | « base/files/file_tracing.cc ('k') | base/files/file_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698