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

Side by Side Diff: util/file/string_file_test.cc

Issue 1416493006: Change file op |ssize_t|s to FileOperationResult (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: fixes Created 5 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 | « util/file/string_file.cc ('k') | util/net/http_body.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 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 EXPECT_TRUE(string_file.string().empty()); 190 EXPECT_TRUE(string_file.string().empty());
191 EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR)); 191 EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
192 } 192 }
193 193
194 TEST(StringFile, WriteInvalid) { 194 TEST(StringFile, WriteInvalid) {
195 StringFile string_file; 195 StringFile string_file;
196 196
197 EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR)); 197 EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
198 198
199 EXPECT_FALSE(string_file.Write( 199 EXPECT_FALSE(string_file.Write(
200 "", implicit_cast<size_t>(std::numeric_limits<ssize_t>::max()) + 1)); 200 "",
201 implicit_cast<size_t>(std::numeric_limits<FileOperationResult>::max()) +
202 1));
201 EXPECT_TRUE(string_file.string().empty()); 203 EXPECT_TRUE(string_file.string().empty());
202 EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR)); 204 EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
203 205
204 EXPECT_TRUE(string_file.Write("a", 1)); 206 EXPECT_TRUE(string_file.Write("a", 1));
205 EXPECT_FALSE(string_file.Write( 207 EXPECT_FALSE(string_file.Write(
206 "", implicit_cast<size_t>(std::numeric_limits<ssize_t>::max()))); 208 "",
209 implicit_cast<size_t>(std::numeric_limits<FileOperationResult>::max())));
207 EXPECT_EQ(1u, string_file.string().size()); 210 EXPECT_EQ(1u, string_file.string().size());
208 EXPECT_EQ("a", string_file.string()); 211 EXPECT_EQ("a", string_file.string());
209 EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR)); 212 EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
210 } 213 }
211 214
212 TEST(StringFile, WriteIoVec) { 215 TEST(StringFile, WriteIoVec) {
213 StringFile string_file; 216 StringFile string_file;
214 217
215 std::vector<WritableIoVec> iovecs; 218 std::vector<WritableIoVec> iovecs;
216 WritableIoVec iov; 219 WritableIoVec iov;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 StringFile string_file; 286 StringFile string_file;
284 287
285 std::vector<WritableIoVec> iovecs; 288 std::vector<WritableIoVec> iovecs;
286 EXPECT_FALSE(string_file.WriteIoVec(&iovecs)); 289 EXPECT_FALSE(string_file.WriteIoVec(&iovecs));
287 EXPECT_TRUE(string_file.string().empty()); 290 EXPECT_TRUE(string_file.string().empty());
288 EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR)); 291 EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
289 292
290 WritableIoVec iov; 293 WritableIoVec iov;
291 EXPECT_EQ(1, string_file.Seek(1, SEEK_CUR)); 294 EXPECT_EQ(1, string_file.Seek(1, SEEK_CUR));
292 iov.iov_base = "a"; 295 iov.iov_base = "a";
293 iov.iov_len = std::numeric_limits<ssize_t>::max(); 296 iov.iov_len = std::numeric_limits<FileOperationResult>::max();
294 iovecs.push_back(iov); 297 iovecs.push_back(iov);
295 EXPECT_FALSE(string_file.WriteIoVec(&iovecs)); 298 EXPECT_FALSE(string_file.WriteIoVec(&iovecs));
296 EXPECT_TRUE(string_file.string().empty()); 299 EXPECT_TRUE(string_file.string().empty());
297 EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR)); 300 EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
298 301
299 iovecs.clear(); 302 iovecs.clear();
300 iov.iov_base = "a"; 303 iov.iov_base = "a";
301 iov.iov_len = 1; 304 iov.iov_len = 1;
302 iovecs.push_back(iov); 305 iovecs.push_back(iov);
303 iov.iov_len = std::numeric_limits<ssize_t>::max() - 1; 306 iov.iov_len = std::numeric_limits<FileOperationResult>::max() - 1;
304 iovecs.push_back(iov); 307 iovecs.push_back(iov);
305 EXPECT_FALSE(string_file.WriteIoVec(&iovecs)); 308 EXPECT_FALSE(string_file.WriteIoVec(&iovecs));
306 EXPECT_TRUE(string_file.string().empty()); 309 EXPECT_TRUE(string_file.string().empty());
307 EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR)); 310 EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
308 } 311 }
309 312
310 TEST(StringFile, Seek) { 313 TEST(StringFile, Seek) {
311 StringFile string_file; 314 StringFile string_file;
312 315
313 EXPECT_TRUE(string_file.Write("abcd", 4)); 316 EXPECT_TRUE(string_file.Write("abcd", 4));
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 } 445 }
443 446
444 TEST(StringFile, SeekInvalid) { 447 TEST(StringFile, SeekInvalid) {
445 StringFile string_file; 448 StringFile string_file;
446 449
447 EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR)); 450 EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
448 EXPECT_EQ(1, string_file.Seek(1, SEEK_SET)); 451 EXPECT_EQ(1, string_file.Seek(1, SEEK_SET));
449 EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR)); 452 EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
450 EXPECT_LT(string_file.Seek(-1, SEEK_SET), 0); 453 EXPECT_LT(string_file.Seek(-1, SEEK_SET), 0);
451 EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR)); 454 EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
452 EXPECT_LT(string_file.Seek(std::numeric_limits<ssize_t>::min(), SEEK_SET), 0); 455 EXPECT_LT(string_file.Seek(std::numeric_limits<FileOperationResult>::min(),
456 SEEK_SET),
457 0);
453 EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR)); 458 EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
454 EXPECT_LT(string_file.Seek(std::numeric_limits<FileOffset>::min(), SEEK_SET), 459 EXPECT_LT(string_file.Seek(std::numeric_limits<FileOffset>::min(), SEEK_SET),
455 0); 460 0);
456 EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR)); 461 EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
457 EXPECT_TRUE(string_file.string().empty()); 462 EXPECT_TRUE(string_file.string().empty());
458 463
459 static_assert(SEEK_SET != 3 && SEEK_CUR != 3 && SEEK_END != 3, 464 static_assert(SEEK_SET != 3 && SEEK_CUR != 3 && SEEK_END != 3,
460 "3 must be invalid for whence"); 465 "3 must be invalid for whence");
461 EXPECT_LT(string_file.Seek(0, 3), 0); 466 EXPECT_LT(string_file.Seek(0, 3), 0);
462 467
(...skipping 17 matching lines...) Expand all
480 TEST(StringFile, SeekSet) { 485 TEST(StringFile, SeekSet) {
481 StringFile string_file; 486 StringFile string_file;
482 EXPECT_TRUE(string_file.SeekSet(1)); 487 EXPECT_TRUE(string_file.SeekSet(1));
483 EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR)); 488 EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
484 EXPECT_TRUE(string_file.SeekSet(0)); 489 EXPECT_TRUE(string_file.SeekSet(0));
485 EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR)); 490 EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
486 EXPECT_TRUE(string_file.SeekSet(10)); 491 EXPECT_TRUE(string_file.SeekSet(10));
487 EXPECT_EQ(10, string_file.Seek(0, SEEK_CUR)); 492 EXPECT_EQ(10, string_file.Seek(0, SEEK_CUR));
488 EXPECT_FALSE(string_file.SeekSet(-1)); 493 EXPECT_FALSE(string_file.SeekSet(-1));
489 EXPECT_EQ(10, string_file.Seek(0, SEEK_CUR)); 494 EXPECT_EQ(10, string_file.Seek(0, SEEK_CUR));
490 EXPECT_FALSE(string_file.SeekSet(std::numeric_limits<ssize_t>::min())); 495 EXPECT_FALSE(
496 string_file.SeekSet(std::numeric_limits<FileOperationResult>::min()));
491 EXPECT_EQ(10, string_file.Seek(0, SEEK_CUR)); 497 EXPECT_EQ(10, string_file.Seek(0, SEEK_CUR));
492 EXPECT_FALSE(string_file.SeekSet(std::numeric_limits<FileOffset>::min())); 498 EXPECT_FALSE(string_file.SeekSet(std::numeric_limits<FileOffset>::min()));
493 EXPECT_EQ(10, string_file.Seek(0, SEEK_CUR)); 499 EXPECT_EQ(10, string_file.Seek(0, SEEK_CUR));
494 } 500 }
495 501
496 } // namespace 502 } // namespace
497 } // namespace test 503 } // namespace test
498 } // namespace crashpad 504 } // namespace crashpad
OLDNEW
« no previous file with comments | « util/file/string_file.cc ('k') | util/net/http_body.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698