• Home
  • Raw
  • Download

Lines Matching full:file

3 // found in the LICENSE file.
6 #include "base/files/file.h"
11 using base::File;
20 // Don't create a File at all. in TEST()
21 File file; in TEST() local
22 EXPECT_FALSE(file.IsValid()); in TEST()
23 EXPECT_EQ(base::File::FILE_ERROR_FAILED, file.error_details()); in TEST()
25 File file2(base::File::FILE_ERROR_TOO_MANY_OPENED); in TEST()
27 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, file2.error_details()); in TEST()
31 // Open a file that doesn't exist. in TEST()
32 File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ); in TEST() local
33 EXPECT_FALSE(file.IsValid()); in TEST()
34 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, file.error_details()); in TEST()
38 // Open or create a file. in TEST()
39 File file(file_path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ); in TEST() local
40 EXPECT_TRUE(file.IsValid()); in TEST()
41 EXPECT_TRUE(file.created()); in TEST()
42 EXPECT_EQ(base::File::FILE_OK, file.error_details()); in TEST()
46 // Open an existing file. in TEST()
47 File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ); in TEST() local
48 EXPECT_TRUE(file.IsValid()); in TEST()
49 EXPECT_FALSE(file.created()); in TEST()
50 EXPECT_EQ(base::File::FILE_OK, file.error_details()); in TEST()
52 // This time verify closing the file. in TEST()
53 file.Close(); in TEST()
54 EXPECT_FALSE(file.IsValid()); in TEST()
58 // Open an existing file through Initialize in TEST()
59 File file; in TEST() local
60 file.Initialize(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ); in TEST()
61 EXPECT_TRUE(file.IsValid()); in TEST()
62 EXPECT_FALSE(file.created()); in TEST()
63 EXPECT_EQ(base::File::FILE_OK, file.error_details()); in TEST()
65 // This time verify closing the file. in TEST()
66 file.Close(); in TEST()
67 EXPECT_FALSE(file.IsValid()); in TEST()
71 // Create a file that exists. in TEST()
72 File file(file_path, base::File::FLAG_CREATE | base::File::FLAG_READ); in TEST() local
73 EXPECT_FALSE(file.IsValid()); in TEST()
74 EXPECT_FALSE(file.created()); in TEST()
75 EXPECT_EQ(base::File::FILE_ERROR_EXISTS, file.error_details()); in TEST()
79 // Create or overwrite a file. in TEST()
80 File file(file_path, in TEST() local
81 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); in TEST()
82 EXPECT_TRUE(file.IsValid()); in TEST()
83 EXPECT_TRUE(file.created()); in TEST()
84 EXPECT_EQ(base::File::FILE_OK, file.error_details()); in TEST()
88 // Create a delete-on-close file. in TEST()
90 File file(file_path, in TEST() local
91 base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ | in TEST()
92 base::File::FLAG_DELETE_ON_CLOSE); in TEST()
93 EXPECT_TRUE(file.IsValid()); in TEST()
94 EXPECT_TRUE(file.created()); in TEST()
95 EXPECT_EQ(base::File::FILE_OK, file.error_details()); in TEST()
107 File file(file_path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_ASYNC); in TEST() local
108 EXPECT_TRUE(file.IsValid()); in TEST()
109 EXPECT_TRUE(file.async()); in TEST()
113 File file(file_path, base::File::FLAG_OPEN_ALWAYS); in TEST() local
114 EXPECT_TRUE(file.IsValid()); in TEST()
115 EXPECT_FALSE(file.async()); in TEST()
124 // Create a file. in TEST()
125 File file(file_path, in TEST() local
126 base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ | in TEST()
127 base::File::FLAG_SHARE_DELETE); in TEST()
128 EXPECT_TRUE(file.IsValid()); in TEST()
129 EXPECT_TRUE(file.created()); in TEST()
130 EXPECT_EQ(base::File::FILE_OK, file.error_details()); in TEST()
132 // Open an existing file and mark it as delete on close. in TEST()
133 File same_file(file_path, in TEST()
134 base::File::FLAG_OPEN | base::File::FLAG_DELETE_ON_CLOSE | in TEST()
135 base::File::FLAG_READ); in TEST()
136 EXPECT_TRUE(file.IsValid()); in TEST()
138 EXPECT_EQ(base::File::FILE_OK, same_file.error_details()); in TEST()
140 // Close both handles and check that the file is gone. in TEST()
141 file.Close(); in TEST()
150 File file(file_path, in TEST() local
151 base::File::FLAG_CREATE | base::File::FLAG_READ | in TEST()
152 base::File::FLAG_WRITE); in TEST()
153 ASSERT_TRUE(file.IsValid()); in TEST()
158 // Write 0 bytes to the file. in TEST()
159 int bytes_written = file.Write(0, data_to_write, 0); in TEST()
162 // Write "test" to the file. in TEST()
163 bytes_written = file.Write(0, data_to_write, kTestDataSize); in TEST()
168 int bytes_read = file.Read(kTestDataSize, data_read_1, kTestDataSize); in TEST()
171 // Read from somewhere in the middle of the file. in TEST()
173 bytes_read = file.Read(kPartialReadOffset, data_read_1, kTestDataSize); in TEST()
179 bytes_read = file.Read(0, data_read_1, 0); in TEST()
182 // Read the entire file. in TEST()
183 bytes_read = file.Read(0, data_read_1, kTestDataSize); in TEST()
189 bytes_read = file.ReadNoBestEffort(0, data_read_1, kTestDataSize); in TEST()
194 // Write past the end of the file. in TEST()
197 bytes_written = file.Write(kOffsetBeyondEndOfFile, in TEST()
201 // Make sure the file was extended. in TEST()
206 // Make sure the file was zero-padded. in TEST()
208 bytes_read = file.Read(0, data_read_2, static_cast<int>(file_size)); in TEST()
222 File file(file_path, base::File::FLAG_CREATE | base::File::FLAG_APPEND); in TEST() local
223 ASSERT_TRUE(file.IsValid()); in TEST()
228 // Write 0 bytes to the file. in TEST()
229 int bytes_written = file.Write(0, data_to_write, 0); in TEST()
232 // Write "test" to the file. in TEST()
233 bytes_written = file.Write(0, data_to_write, kTestDataSize); in TEST()
236 file.Close(); in TEST()
237 File file2(file_path, in TEST()
238 base::File::FLAG_OPEN | base::File::FLAG_READ | in TEST()
239 base::File::FLAG_APPEND); in TEST()
242 // Test passing the file around. in TEST()
243 file = file2.Pass(); in TEST()
245 ASSERT_TRUE(file.IsValid()); in TEST()
250 // Append "78" to the file. in TEST()
251 bytes_written = file.Write(0, append_data_to_write, kAppendDataSize); in TEST()
254 // Read the entire file. in TEST()
256 int bytes_read = file.Read(0, data_read_1, in TEST()
270 File file(file_path, in TEST() local
271 base::File::FLAG_CREATE | base::File::FLAG_READ | in TEST()
272 base::File::FLAG_WRITE); in TEST()
273 ASSERT_TRUE(file.IsValid()); in TEST()
274 EXPECT_EQ(0, file.GetLength()); in TEST()
276 // Write "test" to the file. in TEST()
279 int bytes_written = file.Write(0, data_to_write, kTestDataSize); in TEST()
282 // Extend the file. in TEST()
285 EXPECT_TRUE(file.SetLength(kExtendedFileLength)); in TEST()
286 EXPECT_EQ(kExtendedFileLength, file.GetLength()); in TEST()
290 // Make sure the file was zero-padded. in TEST()
292 int bytes_read = file.Read(0, data_read, static_cast<int>(file_size)); in TEST()
299 // Truncate the file. in TEST()
301 EXPECT_TRUE(file.SetLength(kTruncatedFileLength)); in TEST()
302 EXPECT_EQ(kTruncatedFileLength, file.GetLength()); in TEST()
306 // Make sure the file was truncated. in TEST()
307 bytes_read = file.Read(0, data_read, kTestDataSize); in TEST()
321 File file(temp_dir.path().AppendASCII("touch_get_info_file"), local
322 base::File::FLAG_CREATE | base::File::FLAG_WRITE |
323 base::File::FLAG_WRITE_ATTRIBUTES);
324 ASSERT_TRUE(file.IsValid());
326 // Get info for a newly created file.
327 base::File::Info info;
328 EXPECT_TRUE(file.GetInfo(&info));
341 // Write "test" to the file.
344 int bytes_written = file.Write(0, data, kTestDataSize);
356 EXPECT_TRUE(file.SetTimes(new_last_accessed, new_last_modified));
358 // Make sure the file info was updated accordingly.
359 EXPECT_TRUE(file.GetInfo(&info));
385 File file(file_path, local
386 base::File::FLAG_CREATE | base::File::FLAG_READ |
387 base::File::FLAG_WRITE);
388 EXPECT_TRUE(file.IsValid());
392 EXPECT_EQ(kDataSize, file.Write(0, kData, kDataSize));
394 EXPECT_EQ(0, file.Seek(base::File::FROM_BEGIN, 0));
398 EXPECT_EQ(first_chunk_size, file.ReadAtCurrentPos(buffer, first_chunk_size));
400 file.ReadAtCurrentPos(buffer + first_chunk_size,
409 File file(file_path, local
410 base::File::FLAG_CREATE | base::File::FLAG_READ |
411 base::File::FLAG_WRITE);
412 EXPECT_TRUE(file.IsValid());
418 EXPECT_EQ(first_chunk_size, file.WriteAtCurrentPos(kData, first_chunk_size));
420 file.WriteAtCurrentPos(kData + first_chunk_size,
424 EXPECT_EQ(kDataSize, file.Read(0, buffer, kDataSize));
435 base::File dir(
445 base::File::Info info;