OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <gtest/gtest.h> | 5 #include <gtest/gtest.h> |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/safe_numerics.h" | 10 #include "base/safe_numerics.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 EXPECT_TRUE(IsValidNumericCast<unsigned int>(size_t_large)); | 123 EXPECT_TRUE(IsValidNumericCast<unsigned int>(size_t_large)); |
124 EXPECT_TRUE(IsValidNumericCast<long long>(size_t_large)); | 124 EXPECT_TRUE(IsValidNumericCast<long long>(size_t_large)); |
125 EXPECT_TRUE(IsValidNumericCast<unsigned long long>(size_t_large)); | 125 EXPECT_TRUE(IsValidNumericCast<unsigned long long>(size_t_large)); |
126 | 126 |
127 // Various edge cases. | 127 // Various edge cases. |
128 EXPECT_TRUE(IsValidNumericCast<int>(static_cast<short>(SHRT_MIN))); | 128 EXPECT_TRUE(IsValidNumericCast<int>(static_cast<short>(SHRT_MIN))); |
129 EXPECT_FALSE( | 129 EXPECT_FALSE( |
130 IsValidNumericCast<unsigned short>(static_cast<short>(SHRT_MIN))); | 130 IsValidNumericCast<unsigned short>(static_cast<short>(SHRT_MIN))); |
131 EXPECT_FALSE(IsValidNumericCast<unsigned short>(SHRT_MIN)); | 131 EXPECT_FALSE(IsValidNumericCast<unsigned short>(SHRT_MIN)); |
132 | 132 |
133 // Confirm that numeric_cast<> actually compiles. | 133 // Confirm that checked_numeric_cast<> actually compiles. |
134 std::vector<int> v; | 134 std::vector<int> v; |
135 unsigned int checked_size = | 135 unsigned int checked_size = |
136 base::checked_numeric_cast<unsigned int>(v.size()); | 136 base::checked_numeric_cast<unsigned int>(v.size()); |
137 EXPECT_EQ(0u, checked_size); | 137 EXPECT_EQ(0u, checked_size); |
138 | 138 |
139 #ifdef RUN_EXHAUSTIVE_TEST | 139 #ifdef RUN_EXHAUSTIVE_TEST |
140 ExhaustiveCheckFrom<short>(); | 140 ExhaustiveCheckFrom<short>(); |
141 ExhaustiveCheckFrom<unsigned short>(); | 141 ExhaustiveCheckFrom<unsigned short>(); |
142 ExhaustiveCheckFrom<int>(); | 142 ExhaustiveCheckFrom<int>(); |
143 ExhaustiveCheckFrom<unsigned int>(); | 143 ExhaustiveCheckFrom<unsigned int>(); |
144 ExhaustiveCheckFrom<long long>(); | 144 ExhaustiveCheckFrom<long long>(); |
145 ExhaustiveCheckFrom<unsigned long long>(); | 145 ExhaustiveCheckFrom<unsigned long long>(); |
146 ExhaustiveCheckFrom<size_t>(); | 146 ExhaustiveCheckFrom<size_t>(); |
147 #endif | 147 #endif |
148 } | 148 } |
149 | 149 |
150 } // namespace internal | 150 } // namespace internal |
151 } // namespace base | 151 } // namespace base |
OLD | NEW |