OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "net/base/parse_number.h" | 5 #include "net/base/parse_number.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <sstream> | 8 #include <sstream> |
9 | 9 |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 // When testing ParseUint*() the |format| parameter is not applicable and | 119 // When testing ParseUint*() the |format| parameter is not applicable and |
120 // should be passed as NON_NEGATIVE. | 120 // should be passed as NON_NEGATIVE. |
121 template <typename T, typename ParseFunc> | 121 template <typename T, typename ParseFunc> |
122 void TestParseIntUsingFormat(ParseFunc func, ParseIntFormat format) { | 122 void TestParseIntUsingFormat(ParseFunc func, ParseIntFormat format) { |
123 // Test valid non-negative inputs | 123 // Test valid non-negative inputs |
124 for (const auto& test : kValidNonNegativeTests) { | 124 for (const auto& test : kValidNonNegativeTests) { |
125 ExpectParseIntSuccess<T>(func, test.input, format, test.expected_output); | 125 ExpectParseIntSuccess<T>(func, test.input, format, test.expected_output); |
126 } | 126 } |
127 | 127 |
128 // Test invalid inputs (invalid regardless of parsing format) | 128 // Test invalid inputs (invalid regardless of parsing format) |
129 for (const auto& input : kInvalidParseTests) { | 129 for (auto* input : kInvalidParseTests) { |
130 ExpectParseIntFailure<T>(func, input, format, ParseIntError::FAILED_PARSE); | 130 ExpectParseIntFailure<T>(func, input, format, ParseIntError::FAILED_PARSE); |
131 } | 131 } |
132 | 132 |
133 // Test valid negative inputs (constructed from the valid non-negative test | 133 // Test valid negative inputs (constructed from the valid non-negative test |
134 // cases). | 134 // cases). |
135 for (const auto& test : kValidNonNegativeTests) { | 135 for (const auto& test : kValidNonNegativeTests) { |
136 std::string negative_input = std::string("-") + test.input; | 136 std::string negative_input = std::string("-") + test.input; |
137 int expected_negative_output = -test.expected_output; | 137 int expected_negative_output = -test.expected_output; |
138 | 138 |
139 // The result depends on the format. | 139 // The result depends on the format. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 TEST(ParseNumberTest, ParseUint32) { | 242 TEST(ParseNumberTest, ParseUint32) { |
243 TestParseUint<uint32_t>(ParseUint32); | 243 TestParseUint<uint32_t>(ParseUint32); |
244 } | 244 } |
245 | 245 |
246 TEST(ParseNumberTest, ParseUint64) { | 246 TEST(ParseNumberTest, ParseUint64) { |
247 TestParseUint<uint64_t>(ParseUint64); | 247 TestParseUint<uint64_t>(ParseUint64); |
248 } | 248 } |
249 | 249 |
250 } // namespace | 250 } // namespace |
251 } // namespace net | 251 } // namespace net |
OLD | NEW |