Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/base/parse_number.h" | |
| 6 | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | |
| 8 | |
| 9 namespace net { | |
| 10 namespace { | |
| 11 | |
| 12 TEST(ParseNumberTest, IntValidInputs) { | |
| 13 struct { | |
| 14 const char* input; | |
| 15 int output; | |
| 16 } tests[] = { | |
|
mmenke
2016/03/23 19:32:28
+const
tests -> kTests
| |
| 17 {"0", 0}, {"00000", 0}, {"003", 3}, {"003", 3}, {"1234566", 1234566}, | |
|
mmenke
2016/03/23 19:32:28
You have no test that we can handle digits in decr
eroman
2016/03/23 19:50:30
Done
| |
| 18 }; | |
| 19 | |
| 20 for (const auto& test : tests) { | |
| 21 int result; | |
| 22 ASSERT_TRUE(ParseNonNegativeDecimalInt(test.input, &result)) | |
| 23 << "Failed to parse: " << test.input; | |
| 24 EXPECT_EQ(result, test.output) << "Failed to parse: " << test.input; | |
| 25 } | |
| 26 } | |
| 27 | |
| 28 TEST(ParseNumberTest, IntInvalidInputs) { | |
| 29 const char* tests[] = { | |
| 30 "", | |
| 31 "-23", | |
| 32 "+42", | |
| 33 " 123", | |
| 34 "123 ", | |
| 35 "123\n", | |
| 36 "0xFF", | |
|
mmenke
2016/03/23 19:32:28
0x11? Just checking hex value with non-hex chars.
eroman
2016/03/23 19:50:30
Good idea. Done.
| |
| 37 "AF", | |
| 38 "0AF", | |
| 39 "0.0", | |
| 40 "13.", | |
| 41 "13,000", | |
| 42 "13.000", | |
| 43 "13/5", | |
| 44 "9999999999999999999999999999999999999999999999999999999999999999", | |
| 45 "Inf", | |
| 46 "NaN", | |
| 47 "null", | |
| 48 "dog", | |
| 49 }; | |
| 50 | |
| 51 for (const auto& input : tests) { | |
| 52 int result = 0xDEAD; | |
| 53 ASSERT_FALSE(ParseNonNegativeDecimalInt(input, &result)) | |
| 54 << "Succeeded to parse: " << input; | |
| 55 EXPECT_EQ(0xDEAD, result) << "Modified output for failed parsing"; | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 TEST(ParseNumberTest, IntInvalidInputsContainsNul) { | |
| 60 int result = 0xDEAD; | |
| 61 ASSERT_FALSE( | |
| 62 ParseNonNegativeDecimalInt(base::StringPiece("123\0", 4), &result)); | |
| 63 EXPECT_EQ(0xDEAD, result); | |
| 64 } | |
| 65 | |
| 66 } // namespace | |
| 67 } // namespace net | |
| OLD | NEW |