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

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

Issue 700383007: Use implicit_cast<> instead of static_cast<> whenever possible (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 1 month 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 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 EXPECT_TRUE(writer.string().empty()); 94 EXPECT_TRUE(writer.string().empty());
95 EXPECT_EQ(0, writer.Seek(0, SEEK_CUR)); 95 EXPECT_EQ(0, writer.Seek(0, SEEK_CUR));
96 } 96 }
97 97
98 TEST(StringFileWriter, WriteInvalid) { 98 TEST(StringFileWriter, WriteInvalid) {
99 StringFileWriter writer; 99 StringFileWriter writer;
100 100
101 EXPECT_EQ(0, writer.Seek(0, SEEK_CUR)); 101 EXPECT_EQ(0, writer.Seek(0, SEEK_CUR));
102 102
103 EXPECT_FALSE(writer.Write( 103 EXPECT_FALSE(writer.Write(
104 "", static_cast<size_t>(std::numeric_limits<ssize_t>::max()) + 1)); 104 "", implicit_cast<size_t>(std::numeric_limits<ssize_t>::max()) + 1));
105 EXPECT_TRUE(writer.string().empty()); 105 EXPECT_TRUE(writer.string().empty());
106 EXPECT_EQ(0, writer.Seek(0, SEEK_CUR)); 106 EXPECT_EQ(0, writer.Seek(0, SEEK_CUR));
107 107
108 EXPECT_TRUE(writer.Write("a", 1)); 108 EXPECT_TRUE(writer.Write("a", 1));
109 EXPECT_FALSE(writer.Write( 109 EXPECT_FALSE(writer.Write(
110 "", static_cast<size_t>(std::numeric_limits<ssize_t>::max()))); 110 "", implicit_cast<size_t>(std::numeric_limits<ssize_t>::max())));
111 EXPECT_EQ(1u, writer.string().size()); 111 EXPECT_EQ(1u, writer.string().size());
112 EXPECT_EQ("a", writer.string()); 112 EXPECT_EQ("a", writer.string());
113 EXPECT_EQ(1, writer.Seek(0, SEEK_CUR)); 113 EXPECT_EQ(1, writer.Seek(0, SEEK_CUR));
114 } 114 }
115 115
116 TEST(StringFileWriter, WriteIoVec) { 116 TEST(StringFileWriter, WriteIoVec) {
117 StringFileWriter writer; 117 StringFileWriter writer;
118 118
119 std::vector<WritableIoVec> iovecs; 119 std::vector<WritableIoVec> iovecs;
120 WritableIoVec iov; 120 WritableIoVec iov;
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 356
357 static_assert(SEEK_SET != 3 && SEEK_CUR != 3 && SEEK_END != 3, 357 static_assert(SEEK_SET != 3 && SEEK_CUR != 3 && SEEK_END != 3,
358 "3 must be invalid for whence"); 358 "3 must be invalid for whence");
359 EXPECT_LT(writer.Seek(0, 3), 0); 359 EXPECT_LT(writer.Seek(0, 3), 0);
360 360
361 writer.Reset(); 361 writer.Reset();
362 EXPECT_EQ(0, writer.Seek(0, SEEK_CUR)); 362 EXPECT_EQ(0, writer.Seek(0, SEEK_CUR));
363 EXPECT_TRUE(writer.string().empty()); 363 EXPECT_TRUE(writer.string().empty());
364 364
365 const off_t kMaxOffset = 365 const off_t kMaxOffset =
366 std::min(static_cast<uint64_t>(std::numeric_limits<off_t>::max()), 366 std::min(implicit_cast<uint64_t>(std::numeric_limits<off_t>::max()),
367 static_cast<uint64_t>(std::numeric_limits<size_t>::max())); 367 implicit_cast<uint64_t>(std::numeric_limits<size_t>::max()));
368 368
369 EXPECT_EQ(kMaxOffset, writer.Seek(kMaxOffset, SEEK_SET)); 369 EXPECT_EQ(kMaxOffset, writer.Seek(kMaxOffset, SEEK_SET));
370 EXPECT_EQ(kMaxOffset, writer.Seek(0, SEEK_CUR)); 370 EXPECT_EQ(kMaxOffset, writer.Seek(0, SEEK_CUR));
371 EXPECT_LT(writer.Seek(1, SEEK_CUR), 0); 371 EXPECT_LT(writer.Seek(1, SEEK_CUR), 0);
372 372
373 EXPECT_EQ(1, writer.Seek(1, SEEK_SET)); 373 EXPECT_EQ(1, writer.Seek(1, SEEK_SET));
374 EXPECT_EQ(1, writer.Seek(0, SEEK_CUR)); 374 EXPECT_EQ(1, writer.Seek(0, SEEK_CUR));
375 EXPECT_LT(writer.Seek(kMaxOffset, SEEK_CUR), 0); 375 EXPECT_LT(writer.Seek(kMaxOffset, SEEK_CUR), 0);
376 } 376 }
377 377
378 } // namespace 378 } // namespace
379 } // namespace test 379 } // namespace test
380 } // namespace crashpad 380 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698