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

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

Issue 2555353002: Update Crashpad to 32981a3ee9d7c2769fb27afa038fe2e194cfa329 (Closed)
Patch Set: fix readme Created 4 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
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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 const char input[] = "6\000" "6"; 214 const char input[] = "6\000" "6";
215 base::StringPiece input_string(input, arraysize(input) - 1); 215 base::StringPiece input_string(input, arraysize(input) - 1);
216 unsigned int output; 216 unsigned int output;
217 EXPECT_FALSE(StringToNumber(input_string, &output)); 217 EXPECT_FALSE(StringToNumber(input_string, &output));
218 218
219 // Ensure that a NUL is not required at the end of the string. 219 // Ensure that a NUL is not required at the end of the string.
220 EXPECT_TRUE(StringToNumber(base::StringPiece("66", 1), &output)); 220 EXPECT_TRUE(StringToNumber(base::StringPiece("66", 1), &output));
221 EXPECT_EQ(6u, output); 221 EXPECT_EQ(6u, output);
222 } 222 }
223 223
224 TEST(StringNumberConversion, StringToInt64) {
225 const struct {
226 const char* string;
227 bool valid;
228 int64_t value;
229 } kTestData[] = {
230 {"", false, 0},
231 {"0", true, 0},
232 {"1", true, 1},
233 {"2147483647", true, 2147483647},
234 {"2147483648", true, 2147483648},
235 {"4294967295", true, 4294967295},
236 {"4294967296", true, 4294967296},
237 {"9223372036854775807", true, std::numeric_limits<int64_t>::max()},
238 {"9223372036854775808", false, 0},
239 {"18446744073709551615", false, 0},
240 {"18446744073709551616", false, 0},
241 {"-1", true, -1},
242 {"-2147483648", true, INT64_C(-2147483648)},
243 {"-2147483649", true, INT64_C(-2147483649)},
244 {"-9223372036854775808", true, std::numeric_limits<int64_t>::min()},
245 {"-9223372036854775809", false, 0},
246 {"0x7fffffffffffffff", true, std::numeric_limits<int64_t>::max()},
247 {"0x8000000000000000", false, 0},
248 {"0xffffffffffffffff", false, 0},
249 {"0x10000000000000000", false, 0},
250 {"-0x7fffffffffffffff", true, -9223372036854775807},
251 {"-0x8000000000000000", true, std::numeric_limits<int64_t>::min()},
252 {"-0x8000000000000001", false, 0},
253 {"0x7Fffffffffffffff", true, std::numeric_limits<int64_t>::max()},
254 };
255
256 for (size_t index = 0; index < arraysize(kTestData); ++index) {
257 int64_t value;
258 bool valid = StringToNumber(kTestData[index].string, &value);
259 if (kTestData[index].valid) {
260 EXPECT_TRUE(valid) << "index " << index << ", string "
261 << kTestData[index].string;
262 if (valid) {
263 EXPECT_EQ(kTestData[index].value, value)
264 << "index " << index << ", string " << kTestData[index].string;
265 }
266 } else {
267 EXPECT_FALSE(valid) << "index " << index << ", string "
268 << kTestData[index].string << ", value " << value;
269 }
270 }
271 }
272
273 TEST(StringNumberConversion, StringToUnsignedInt64) {
274 const struct {
275 const char* string;
276 bool valid;
277 uint64_t value;
278 } kTestData[] = {
279 {"", false, 0},
280 {"0", true, 0},
281 {"1", true, 1},
282 {"2147483647", true, 2147483647},
283 {"2147483648", true, 2147483648},
284 {"4294967295", true, 4294967295},
285 {"4294967296", true, 4294967296},
286 {"9223372036854775807", true, 9223372036854775807},
287 {"9223372036854775808", true, 9223372036854775808u},
288 {"18446744073709551615", true, std::numeric_limits<uint64_t>::max()},
289 {"18446744073709551616", false, 0},
290 {"-1", false, 0},
291 {"-2147483648", false, 0},
292 {"-2147483649", false, 0},
293 {"-2147483648", false, 0},
294 {"-9223372036854775808", false, 0},
295 {"-9223372036854775809", false, 0},
296 {"0x7fffffffffffffff", true, 9223372036854775807},
297 {"0x8000000000000000", true, 9223372036854775808u},
298 {"0xffffffffffffffff", true, std::numeric_limits<uint64_t>::max()},
299 {"0x10000000000000000", false, 0},
300 {"-0x7fffffffffffffff", false, 0},
301 {"-0x8000000000000000", false, 0},
302 {"-0x8000000000000001", false, 0},
303 {"0xFfffffffffffffff", true, std::numeric_limits<uint64_t>::max()},
304 };
305
306 for (size_t index = 0; index < arraysize(kTestData); ++index) {
307 uint64_t value;
308 bool valid = StringToNumber(kTestData[index].string, &value);
309 if (kTestData[index].valid) {
310 EXPECT_TRUE(valid) << "index " << index << ", string "
311 << kTestData[index].string;
312 if (valid) {
313 EXPECT_EQ(kTestData[index].value, value)
314 << "index " << index << ", string " << kTestData[index].string;
315 }
316 } else {
317 EXPECT_FALSE(valid) << "index " << index << ", string "
318 << kTestData[index].string << ", value " << value;
319 }
320 }
321 }
322
224 } // namespace 323 } // namespace
225 } // namespace test 324 } // namespace test
226 } // namespace crashpad 325 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698