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

Side by Side Diff: util/numeric/in_range_cast_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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 EXPECT_EQ(-1, InRangeCast<int32_t>(-1, 1)); 49 EXPECT_EQ(-1, InRangeCast<int32_t>(-1, 1));
50 EXPECT_EQ(0x7fffffff, InRangeCast<int32_t>(0x7fffffff, 1)); 50 EXPECT_EQ(0x7fffffff, InRangeCast<int32_t>(0x7fffffff, 1));
51 EXPECT_EQ(0x7fffffff, InRangeCast<int32_t>(0x7fffffffu, 1)); 51 EXPECT_EQ(0x7fffffff, InRangeCast<int32_t>(0x7fffffffu, 1));
52 EXPECT_EQ(1, InRangeCast<int32_t>(0x80000000u, 1)); 52 EXPECT_EQ(1, InRangeCast<int32_t>(0x80000000u, 1));
53 EXPECT_EQ(1, InRangeCast<int32_t>(0xffffffffu, 1)); 53 EXPECT_EQ(1, InRangeCast<int32_t>(0xffffffffu, 1));
54 EXPECT_EQ(1, InRangeCast<int32_t>(INT64_C(0x80000000), 1)); 54 EXPECT_EQ(1, InRangeCast<int32_t>(INT64_C(0x80000000), 1));
55 EXPECT_EQ(1, InRangeCast<int32_t>(INT64_C(0xffffffff), 1)); 55 EXPECT_EQ(1, InRangeCast<int32_t>(INT64_C(0xffffffff), 1));
56 EXPECT_EQ(1, InRangeCast<int32_t>(INT64_C(0x100000000), 1)); 56 EXPECT_EQ(1, InRangeCast<int32_t>(INT64_C(0x100000000), 1));
57 EXPECT_EQ(kInt32Min, InRangeCast<int32_t>(kInt32Min, 1)); 57 EXPECT_EQ(kInt32Min, InRangeCast<int32_t>(kInt32Min, 1));
58 EXPECT_EQ(kInt32Min, 58 EXPECT_EQ(kInt32Min,
59 InRangeCast<int32_t>(static_cast<int64_t>(kInt32Min), 1)); 59 InRangeCast<int32_t>(implicit_cast<int64_t>(kInt32Min), 1));
60 EXPECT_EQ(1, InRangeCast<int32_t>(static_cast<int64_t>(kInt32Min) - 1, 1)); 60 EXPECT_EQ(1, InRangeCast<int32_t>(implicit_cast<int64_t>(kInt32Min) - 1, 1));
61 EXPECT_EQ(0, InRangeCast<int32_t>(0xffffffffu, 0)); 61 EXPECT_EQ(0, InRangeCast<int32_t>(0xffffffffu, 0));
62 EXPECT_EQ(-1, InRangeCast<int32_t>(0xffffffffu, -1)); 62 EXPECT_EQ(-1, InRangeCast<int32_t>(0xffffffffu, -1));
63 EXPECT_EQ(kInt32Min, InRangeCast<int32_t>(0xffffffffu, kInt32Min)); 63 EXPECT_EQ(kInt32Min, InRangeCast<int32_t>(0xffffffffu, kInt32Min));
64 EXPECT_EQ(0x7fffffff, InRangeCast<int32_t>(0xffffffffu, 0x7fffffff)); 64 EXPECT_EQ(0x7fffffff, InRangeCast<int32_t>(0xffffffffu, 0x7fffffff));
65 } 65 }
66 66
67 TEST(InRangeCast, Uint64) { 67 TEST(InRangeCast, Uint64) {
68 EXPECT_EQ(0u, InRangeCast<uint64_t>(0, 1)); 68 EXPECT_EQ(0u, InRangeCast<uint64_t>(0, 1));
69 EXPECT_EQ(1u, InRangeCast<uint64_t>(1, 1)); 69 EXPECT_EQ(1u, InRangeCast<uint64_t>(1, 1));
70 EXPECT_EQ(2u, InRangeCast<uint64_t>(2, 1)); 70 EXPECT_EQ(2u, InRangeCast<uint64_t>(2, 1));
(...skipping 26 matching lines...) Expand all
97 EXPECT_EQ(INT64_C(0x80000000), InRangeCast<int64_t>(INT64_C(0x80000000), 1)); 97 EXPECT_EQ(INT64_C(0x80000000), InRangeCast<int64_t>(INT64_C(0x80000000), 1));
98 EXPECT_EQ(INT64_C(0xffffffff), InRangeCast<int64_t>(INT64_C(0xffffffff), 1)); 98 EXPECT_EQ(INT64_C(0xffffffff), InRangeCast<int64_t>(INT64_C(0xffffffff), 1));
99 EXPECT_EQ(INT64_C(0x100000000), 99 EXPECT_EQ(INT64_C(0x100000000),
100 InRangeCast<int64_t>(INT64_C(0x100000000), 1)); 100 InRangeCast<int64_t>(INT64_C(0x100000000), 1));
101 EXPECT_EQ(INT64_C(0x7fffffffffffffff), 101 EXPECT_EQ(INT64_C(0x7fffffffffffffff),
102 InRangeCast<int64_t>(INT64_C(0x7fffffffffffffff), 1)); 102 InRangeCast<int64_t>(INT64_C(0x7fffffffffffffff), 1));
103 EXPECT_EQ(1, InRangeCast<int64_t>(UINT64_C(0x8000000000000000), 1)); 103 EXPECT_EQ(1, InRangeCast<int64_t>(UINT64_C(0x8000000000000000), 1));
104 EXPECT_EQ(1, InRangeCast<int64_t>(UINT64_C(0xffffffffffffffff), 1)); 104 EXPECT_EQ(1, InRangeCast<int64_t>(UINT64_C(0xffffffffffffffff), 1));
105 EXPECT_EQ(kInt32Min, InRangeCast<int64_t>(kInt32Min, 1)); 105 EXPECT_EQ(kInt32Min, InRangeCast<int64_t>(kInt32Min, 1));
106 EXPECT_EQ(kInt32Min, 106 EXPECT_EQ(kInt32Min,
107 InRangeCast<int64_t>(static_cast<int64_t>(kInt32Min), 1)); 107 InRangeCast<int64_t>(implicit_cast<int64_t>(kInt32Min), 1));
108 EXPECT_EQ(0, InRangeCast<int64_t>(UINT64_C(0xffffffffffffffff), 0)); 108 EXPECT_EQ(0, InRangeCast<int64_t>(UINT64_C(0xffffffffffffffff), 0));
109 EXPECT_EQ(-1, InRangeCast<int64_t>(UINT64_C(0xffffffffffffffff), -1)); 109 EXPECT_EQ(-1, InRangeCast<int64_t>(UINT64_C(0xffffffffffffffff), -1));
110 EXPECT_EQ(kInt64Min, 110 EXPECT_EQ(kInt64Min,
111 InRangeCast<int64_t>(UINT64_C(0xffffffffffffffff), kInt64Min)); 111 InRangeCast<int64_t>(UINT64_C(0xffffffffffffffff), kInt64Min));
112 EXPECT_EQ(INT64_C(0x7fffffffffffffff), 112 EXPECT_EQ(INT64_C(0x7fffffffffffffff),
113 InRangeCast<int64_t>(UINT64_C(0xffffffffffffffff), 113 InRangeCast<int64_t>(UINT64_C(0xffffffffffffffff),
114 INT64_C(0x7fffffffffffffff))); 114 INT64_C(0x7fffffffffffffff)));
115 } 115 }
116 116
117 } // namespace 117 } // namespace
118 } // namespace test 118 } // namespace test
119 } // namespace crashpad 119 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698