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

Side by Side Diff: base/safe_numerics_unittest.cc

Issue 12051089: fix checked_numeric_cast comments (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « base/safe_numerics.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « base/safe_numerics.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698