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

Side by Side Diff: net/base/parse_number_unittest.cc

Issue 1829873002: Add base/parse_number.h to generalize number parsing done in //net. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more tests Created 4 years, 9 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
« no previous file with comments | « net/base/parse_number.cc ('k') | net/base/sdch_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 const struct {
14 const char* input;
15 int output;
16 } kTests[] = {
17 {"0", 0}, {"00000", 0}, {"003", 3}, {"003", 3}, {"1234566", 1234566},
18 {"987", 987}, {"010", 10},
19 };
20
21 for (const auto& test : kTests) {
22 int result;
23 ASSERT_TRUE(ParseNonNegativeDecimalInt(test.input, &result))
24 << "Failed to parse: " << test.input;
25 EXPECT_EQ(result, test.output) << "Failed to parse: " << test.input;
26 }
27 }
28
29 TEST(ParseNumberTest, IntInvalidInputs) {
30 const char* kTests[] = {
31 "",
32 "-23",
33 "+42",
34 " 123",
35 "123 ",
36 "123\n",
37 "0xFF",
38 "0x11",
39 "x11",
40 "F11",
41 "AF",
42 "0AF",
43 "0.0",
44 "13.",
45 "13,000",
46 "13.000",
47 "13/5",
48 "9999999999999999999999999999999999999999999999999999999999999999",
49 "Inf",
50 "NaN",
51 "null",
52 "dog",
53 };
54
55 for (const auto& input : kTests) {
56 int result = 0xDEAD;
57 ASSERT_FALSE(ParseNonNegativeDecimalInt(input, &result))
58 << "Succeeded to parse: " << input;
59 EXPECT_EQ(0xDEAD, result) << "Modified output for failed parsing";
60 }
61 }
62
63 TEST(ParseNumberTest, IntInvalidInputsContainsNul) {
64 int result = 0xDEAD;
65 ASSERT_FALSE(
66 ParseNonNegativeDecimalInt(base::StringPiece("123\0", 4), &result));
67 EXPECT_EQ(0xDEAD, result);
68 }
69
70 } // namespace
71 } // namespace net
OLDNEW
« no previous file with comments | « net/base/parse_number.cc ('k') | net/base/sdch_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698