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

Side by Side Diff: util/stdlib/string_number_conversion_test.cc

Issue 807463004: win: avoid warnings in string_number_conversion_test.cc (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: . Created 6 years 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 | « no previous file | 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 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 {"0x10", true, 16}, 46 {"0x10", true, 16},
47 {"-0x10", true, -16}, 47 {"-0x10", true, -16},
48 {"+0x20", true, 32}, 48 {"+0x20", true, 32},
49 {"0xf", true, 15}, 49 {"0xf", true, 15},
50 {"0xg", false, 0}, 50 {"0xg", false, 0},
51 {"0x7fffffff", true, std::numeric_limits<int>::max()}, 51 {"0x7fffffff", true, std::numeric_limits<int>::max()},
52 {"0x7FfFfFfF", true, std::numeric_limits<int>::max()}, 52 {"0x7FfFfFfF", true, std::numeric_limits<int>::max()},
53 {"0x80000000", false, 0}, 53 {"0x80000000", false, 0},
54 {"0xFFFFFFFF", false, 0}, 54 {"0xFFFFFFFF", false, 0},
55 {"-0x7fffffff", true, -2147483647}, 55 {"-0x7fffffff", true, -2147483647},
56 {"-0x80000000", true, -2147483648}, 56 {"-0x80000000", true, std::numeric_limits<int>::min()},
57 {"-0x80000001", false, 0}, 57 {"-0x80000001", false, 0},
58 {"-0xffffffff", false, 0}, 58 {"-0xffffffff", false, 0},
59 {"0x100000000", false, 0}, 59 {"0x100000000", false, 0},
60 {"0xabcdef", true, 11259375}, 60 {"0xabcdef", true, 11259375},
61 {"010", true, 8}, 61 {"010", true, 8},
62 {"-010", true, -8}, 62 {"-010", true, -8},
63 {"+020", true, 16}, 63 {"+020", true, 16},
64 {"07", true, 7}, 64 {"07", true, 7},
65 {"08", false, 0}, 65 {"08", false, 0},
66 {" 0", false, 0}, 66 {" 0", false, 0},
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 if (valid) { 101 if (valid) {
102 EXPECT_EQ(kTestData[index].value, value) 102 EXPECT_EQ(kTestData[index].value, value)
103 << "index " << index << ", string " << kTestData[index].string; 103 << "index " << index << ", string " << kTestData[index].string;
104 } 104 }
105 } else { 105 } else {
106 EXPECT_FALSE(valid) << "index " << index << ", string " 106 EXPECT_FALSE(valid) << "index " << index << ", string "
107 << kTestData[index].string << ", value " << value; 107 << kTestData[index].string << ", value " << value;
108 } 108 }
109 } 109 }
110 110
111 // Ensure that embedded NUL characters are treated as bad input. 111 // Ensure that embedded NUL characters are treated as bad input. The string
112 const char input[] = "6\0006"; 112 // is split to avoid MSVC warning:
113 // "decimal digit terminates octal escape sequence".
114 const char input[] = "6\000" "6";
113 base::StringPiece input_string(input, arraysize(input) - 1); 115 base::StringPiece input_string(input, arraysize(input) - 1);
114 int output; 116 int output;
115 EXPECT_FALSE(StringToNumber(input_string, &output)); 117 EXPECT_FALSE(StringToNumber(input_string, &output));
116 118
117 // Ensure that a NUL is not required at the end of the string. 119 // Ensure that a NUL is not required at the end of the string.
118 EXPECT_TRUE(StringToNumber(base::StringPiece("66", 1), &output)); 120 EXPECT_TRUE(StringToNumber(base::StringPiece("66", 1), &output));
119 EXPECT_EQ(6, output); 121 EXPECT_EQ(6, output);
120 } 122 }
121 123
122 TEST(StringNumberConversion, StringToUnsignedInt) { 124 TEST(StringNumberConversion, StringToUnsignedInt) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 if (valid) { 199 if (valid) {
198 EXPECT_EQ(kTestData[index].value, value) 200 EXPECT_EQ(kTestData[index].value, value)
199 << "index " << index << ", string " << kTestData[index].string; 201 << "index " << index << ", string " << kTestData[index].string;
200 } 202 }
201 } else { 203 } else {
202 EXPECT_FALSE(valid) << "index " << index << ", string " 204 EXPECT_FALSE(valid) << "index " << index << ", string "
203 << kTestData[index].string << ", value " << value; 205 << kTestData[index].string << ", value " << value;
204 } 206 }
205 } 207 }
206 208
207 // Ensure that embedded NUL characters are treated as bad input. 209 // Ensure that embedded NUL characters are treated as bad input. The string
208 const char input[] = "6\0006"; 210 // is split to avoid MSVC warning:
211 // "decimal digit terminates octal escape sequence".
212 const char input[] = "6\000" "6";
209 base::StringPiece input_string(input, arraysize(input) - 1); 213 base::StringPiece input_string(input, arraysize(input) - 1);
210 unsigned int output; 214 unsigned int output;
211 EXPECT_FALSE(StringToNumber(input_string, &output)); 215 EXPECT_FALSE(StringToNumber(input_string, &output));
212 216
213 // Ensure that a NUL is not required at the end of the string. 217 // Ensure that a NUL is not required at the end of the string.
214 EXPECT_TRUE(StringToNumber(base::StringPiece("66", 1), &output)); 218 EXPECT_TRUE(StringToNumber(base::StringPiece("66", 1), &output));
215 EXPECT_EQ(6u, output); 219 EXPECT_EQ(6u, output);
216 } 220 }
217 221
218 } // namespace 222 } // namespace
219 } // namespace test 223 } // namespace test
220 } // namespace crashpad 224 } // namespace crashpad
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698