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

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

Issue 913223008: Add FileReaderInterface::ReadExactly() and FileSeekerInterface::SeekSet() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 10 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/file_writer.h ('k') | util/util.gyp » ('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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 EXPECT_EQ(4, string_file.Seek(0, SEEK_CUR)); 110 EXPECT_EQ(4, string_file.Seek(0, SEEK_CUR));
111 string_file.SetString(kString3); 111 string_file.SetString(kString3);
112 EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR)); 112 EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
113 EXPECT_EQ(4, string_file.Read(buf, 4)); 113 EXPECT_EQ(4, string_file.Read(buf, 4));
114 EXPECT_STREQ("our ", buf); 114 EXPECT_STREQ("our ", buf);
115 EXPECT_EQ(static_cast<FileOffset>(strlen(kString3)), 115 EXPECT_EQ(static_cast<FileOffset>(strlen(kString3)),
116 string_file.Seek(0, SEEK_END)); 116 string_file.Seek(0, SEEK_END));
117 EXPECT_EQ(kString3, string_file.string()); 117 EXPECT_EQ(kString3, string_file.string());
118 } 118 }
119 119
120 TEST(StringFile, ReadExactly) {
121 StringFile string_file;
122 string_file.SetString("1234567");
123 char buf[4] = "***";
124 EXPECT_TRUE(string_file.ReadExactly(buf, 3));
125 EXPECT_STREQ("123", buf);
126 EXPECT_TRUE(string_file.ReadExactly(buf, 3));
127 EXPECT_STREQ("456", buf);
128 EXPECT_FALSE(string_file.ReadExactly(buf, 3));
129 }
130
120 TEST(StringFile, Reset) { 131 TEST(StringFile, Reset) {
121 StringFile string_file; 132 StringFile string_file;
122 133
123 EXPECT_TRUE(string_file.Write("abc", 3)); 134 EXPECT_TRUE(string_file.Write("abc", 3));
124 EXPECT_EQ(3u, string_file.string().size()); 135 EXPECT_EQ(3u, string_file.string().size());
125 EXPECT_EQ("abc", string_file.string()); 136 EXPECT_EQ("abc", string_file.string());
126 EXPECT_EQ(3, string_file.Seek(0, SEEK_CUR)); 137 EXPECT_EQ(3, string_file.Seek(0, SEEK_CUR));
127 char buf[10] = "*********"; 138 char buf[10] = "*********";
128 EXPECT_EQ(0, string_file.Seek(0, SEEK_SET)); 139 EXPECT_EQ(0, string_file.Seek(0, SEEK_SET));
129 EXPECT_EQ(3, string_file.Read(&buf, 10)); 140 EXPECT_EQ(3, string_file.Read(&buf, 10));
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 469
459 EXPECT_EQ(kMaxOffset, string_file.Seek(kMaxOffset, SEEK_SET)); 470 EXPECT_EQ(kMaxOffset, string_file.Seek(kMaxOffset, SEEK_SET));
460 EXPECT_EQ(kMaxOffset, string_file.Seek(0, SEEK_CUR)); 471 EXPECT_EQ(kMaxOffset, string_file.Seek(0, SEEK_CUR));
461 EXPECT_LT(string_file.Seek(1, SEEK_CUR), 0); 472 EXPECT_LT(string_file.Seek(1, SEEK_CUR), 0);
462 473
463 EXPECT_EQ(1, string_file.Seek(1, SEEK_SET)); 474 EXPECT_EQ(1, string_file.Seek(1, SEEK_SET));
464 EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR)); 475 EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
465 EXPECT_LT(string_file.Seek(kMaxOffset, SEEK_CUR), 0); 476 EXPECT_LT(string_file.Seek(kMaxOffset, SEEK_CUR), 0);
466 } 477 }
467 478
479 TEST(StringFile, SeekSet) {
480 StringFile string_file;
481 EXPECT_TRUE(string_file.SeekSet(1));
482 EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
483 EXPECT_TRUE(string_file.SeekSet(0));
484 EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
485 EXPECT_TRUE(string_file.SeekSet(10));
486 EXPECT_EQ(10, string_file.Seek(0, SEEK_CUR));
487 EXPECT_FALSE(string_file.SeekSet(-1));
488 EXPECT_EQ(10, string_file.Seek(0, SEEK_CUR));
489 EXPECT_FALSE(string_file.SeekSet(std::numeric_limits<ssize_t>::min()));
490 EXPECT_EQ(10, string_file.Seek(0, SEEK_CUR));
491 EXPECT_FALSE(string_file.SeekSet(std::numeric_limits<FileOffset>::min()));
492 EXPECT_EQ(10, string_file.Seek(0, SEEK_CUR));
493 }
494
468 } // namespace 495 } // namespace
469 } // namespace test 496 } // namespace test
470 } // namespace crashpad 497 } // namespace crashpad
OLDNEW
« no previous file with comments | « util/file/file_writer.h ('k') | util/util.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698