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

Side by Side Diff: core/fxcrt/fx_basic_gcc_unittest.cpp

Issue 1828873002: Fix FXSYS_StrToInt() (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: 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
« core/fxcrt/fx_basic_gcc.cpp ('K') | « core/fxcrt/fx_basic_gcc.cpp ('k') | 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 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium 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 "core/include/fxcrt/fx_system.h" 5 #include "core/include/fxcrt/fx_system.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 7
8 TEST(fxcrt, FXSYS_atoi) { 8 TEST(fxcrt, FXSYS_atoi) {
9 EXPECT_EQ(0, FXSYS_atoi("")); 9 EXPECT_EQ(0, FXSYS_atoi(""));
10 EXPECT_EQ(0, FXSYS_atoi("0")); 10 EXPECT_EQ(0, FXSYS_atoi("0"));
11 EXPECT_EQ(-1, FXSYS_atoi("-1")); 11 EXPECT_EQ(-1, FXSYS_atoi("-1"));
12 EXPECT_EQ(2345, FXSYS_atoi("2345")); 12 EXPECT_EQ(2345, FXSYS_atoi("2345"));
13 EXPECT_EQ(-2147483647, FXSYS_atoi("-2147483647"));
14 // Handle the sign.
15 EXPECT_EQ(-2345, FXSYS_atoi("-2345"));
16 EXPECT_EQ(2345, FXSYS_atoi("+2345"));
17 // The max value.
13 EXPECT_EQ(2147483647, FXSYS_atoi("2147483647")); 18 EXPECT_EQ(2147483647, FXSYS_atoi("2147483647"));
14 EXPECT_EQ(-2147483647, FXSYS_atoi("-2147483647")); 19 // The min value.
20 EXPECT_EQ(-2147483648, FXSYS_atoi("-2147483648"));
21 // With invalid char.
15 EXPECT_EQ(9, FXSYS_atoi("9x9")); 22 EXPECT_EQ(9, FXSYS_atoi("9x9"));
16 23
17 // TODO(dsinclair): These are all wacky ..... 24 // Out of range values.
18 EXPECT_EQ(2147483623, FXSYS_atoi("2147483623423412348")); 25 EXPECT_EQ(2147483647, FXSYS_atoi("2147483623423412348"));
19 EXPECT_EQ(214748364, FXSYS_atoi("2147483648")); 26 EXPECT_EQ(2147483647, FXSYS_atoi("2147483648"));
20 // The digit is parsed as a positive value, so we end up not being able to 27 EXPECT_EQ(-2147483648, FXSYS_atoi("-2147483650"));
21 // handle the largest possible negative value.
22 EXPECT_EQ(-214748364, FXSYS_atoi("-2147483648"));
23 } 28 }
24 29
25 TEST(fxcrt, FXSYS_atoi64) { 30 TEST(fxcrt, FXSYS_atoi64) {
26 EXPECT_EQ(0, FXSYS_atoi64("")); 31 EXPECT_EQ(0, FXSYS_atoi64(""));
27 EXPECT_EQ(0, FXSYS_atoi64("0")); 32 EXPECT_EQ(0, FXSYS_atoi64("0"));
28 EXPECT_EQ(-1, FXSYS_atoi64("-1")); 33 EXPECT_EQ(-1, FXSYS_atoi64("-1"));
29 EXPECT_EQ(2345, FXSYS_atoi64("2345")); 34 EXPECT_EQ(2345, FXSYS_atoi64("2345"));
35 EXPECT_EQ(-9223372036854775807LL, FXSYS_atoi64("-9223372036854775807"));
36 // Handle the sign.
37 EXPECT_EQ(-2345, FXSYS_atoi64("-2345"));
38 EXPECT_EQ(2345, FXSYS_atoi64("+2345"));
39 // The max value.
30 EXPECT_EQ(9223372036854775807LL, FXSYS_atoi64("9223372036854775807")); 40 EXPECT_EQ(9223372036854775807LL, FXSYS_atoi64("9223372036854775807"));
31 EXPECT_EQ(-9223372036854775807LL, FXSYS_atoi64("-9223372036854775807")); 41 // The min value.
42 EXPECT_EQ(-9223372036854775808LL, FXSYS_atoi64("-9223372036854775808"));
43 // With invalid char.
32 EXPECT_EQ(9, FXSYS_atoi64("9x9")); 44 EXPECT_EQ(9, FXSYS_atoi64("9x9"));
33 45
34 // TODO(dsinclair): These are all wacky ..... 46 // Out of range values.
35 EXPECT_EQ(9223372036854712341LL, FXSYS_atoi64("922337203685471234123475807")); 47 EXPECT_EQ(9223372036854775807LL, FXSYS_atoi64("922337203685471234123475807"));
36 EXPECT_EQ(922337203685477580LL, FXSYS_atoi64("9223372036854775808")); 48 EXPECT_EQ(9223372036854775807LL, FXSYS_atoi64("9223372036854775808"));
37 // The digit is parsed as a positive value, so we end up not being able to 49 EXPECT_EQ(-9223372036854775808LL, FXSYS_atoi64("-9223372036854775810"));
38 // handle the largest possible negative value.
39 EXPECT_EQ(-922337203685477580LL, FXSYS_atoi64("-9223372036854775808"));
40 } 50 }
41 51
42 TEST(fxcrt, FXSYS_wtoi) { 52 TEST(fxcrt, FXSYS_wtoi) {
43 EXPECT_EQ(0, FXSYS_wtoi(L"")); 53 EXPECT_EQ(0, FXSYS_wtoi(L""));
44 EXPECT_EQ(0, FXSYS_wtoi(L"0")); 54 EXPECT_EQ(0, FXSYS_wtoi(L"0"));
45 EXPECT_EQ(-1, FXSYS_wtoi(L"-1")); 55 EXPECT_EQ(-1, FXSYS_wtoi(L"-1"));
46 EXPECT_EQ(2345, FXSYS_wtoi(L"2345")); 56 EXPECT_EQ(2345, FXSYS_wtoi(L"2345"));
57 EXPECT_EQ(-2147483647, FXSYS_wtoi(L"-2147483647"));
58 // The max value.
47 EXPECT_EQ(2147483647, FXSYS_wtoi(L"2147483647")); 59 EXPECT_EQ(2147483647, FXSYS_wtoi(L"2147483647"));
48 EXPECT_EQ(-2147483647, FXSYS_wtoi(L"-2147483647")); 60 // The min value.
61 EXPECT_EQ(-2147483648, FXSYS_wtoi(L"-2147483648"));
49 EXPECT_EQ(9, FXSYS_wtoi64(L"9x9")); 62 EXPECT_EQ(9, FXSYS_wtoi64(L"9x9"));
50 63
51 // TODO(dsinclair): These are all wacky ..... 64 // Out of range values.
52 EXPECT_EQ(2147483623, FXSYS_wtoi(L"2147483623423412348")); 65 EXPECT_EQ(2147483647, FXSYS_wtoi(L"2147483623423412348"));
53 EXPECT_EQ(214748364, FXSYS_wtoi(L"2147483648")); 66 EXPECT_EQ(2147483647, FXSYS_wtoi(L"2147483648"));
54 // The digit is parsed as a positive value, so we end up not being able to 67 EXPECT_EQ(-2147483648, FXSYS_wtoi(L"-2147483652"));
55 // handle the largest possible negative value.
56 EXPECT_EQ(-214748364, FXSYS_wtoi(L"-2147483648"));
57 } 68 }
58 69
59 TEST(fxcrt, FXSYS_wtoi64) { 70 TEST(fxcrt, FXSYS_wtoi64) {
60 EXPECT_EQ(0, FXSYS_wtoi64(L"")); 71 EXPECT_EQ(0, FXSYS_wtoi64(L""));
61 EXPECT_EQ(0, FXSYS_wtoi64(L"0")); 72 EXPECT_EQ(0, FXSYS_wtoi64(L"0"));
62 EXPECT_EQ(-1, FXSYS_wtoi64(L"-1")); 73 EXPECT_EQ(-1, FXSYS_wtoi64(L"-1"));
63 EXPECT_EQ(2345, FXSYS_wtoi64(L"2345")); 74 EXPECT_EQ(2345, FXSYS_wtoi64(L"2345"));
75 EXPECT_EQ(-9223372036854775807LL, FXSYS_wtoi64(L"-9223372036854775807"));
76 // Handle the sign.
77 EXPECT_EQ(-2345, FXSYS_wtoi64(L"-2345"));
78 EXPECT_EQ(2345, FXSYS_wtoi64(L"+2345"));
79 // The max value.
64 EXPECT_EQ(9223372036854775807LL, FXSYS_wtoi64(L"9223372036854775807")); 80 EXPECT_EQ(9223372036854775807LL, FXSYS_wtoi64(L"9223372036854775807"));
65 EXPECT_EQ(-9223372036854775807LL, FXSYS_wtoi64(L"-9223372036854775807")); 81 // The min value.
82 EXPECT_EQ(-9223372036854775808LL, FXSYS_wtoi64(L"-9223372036854775808"));
83 // With invalid char.
66 EXPECT_EQ(9, FXSYS_wtoi64(L"9x9")); 84 EXPECT_EQ(9, FXSYS_wtoi64(L"9x9"));
67 85
68 // TODO(dsinclair): These are all wacky ..... 86 // Out of range values.
69 EXPECT_EQ(9223372036854712341LL, 87 EXPECT_EQ(9223372036854775807LL,
70 FXSYS_wtoi64(L"922337203685471234123475807")); 88 FXSYS_wtoi64(L"922337203685471234123475807"));
71 EXPECT_EQ(922337203685477580LL, FXSYS_wtoi64(L"9223372036854775808")); 89 EXPECT_EQ(9223372036854775807LL, FXSYS_wtoi64(L"9223372036854775808"));
72 // The digit is parsed as a positive value, so we end up not being able to 90 EXPECT_EQ(-9223372036854775808LL, FXSYS_wtoi64(L"-9223372036854775810"));
73 // handle the largest possible negative value.
74 EXPECT_EQ(-922337203685477580LL, FXSYS_wtoi64(L"-9223372036854775808"));
75 } 91 }
76 92
77 TEST(fxcrt, FXSYS_atoui) { 93 TEST(fxcrt, FXSYS_atoui) {
78 EXPECT_EQ(0, FXSYS_atoui("")); 94 EXPECT_EQ(0, FXSYS_atoui(""));
79 EXPECT_EQ(0, FXSYS_atoui("0")); 95 EXPECT_EQ(0, FXSYS_atoui("0"));
80 EXPECT_EQ(0, FXSYS_atoui("-1")); 96 EXPECT_EQ(4294967295, FXSYS_atoui("-1"));
dsinclair 2016/03/24 02:41:06 I think this is wrong, it should return 0 because
81 EXPECT_EQ(2345, FXSYS_atoui("2345")); 97 EXPECT_EQ(2345, FXSYS_atoui("2345"));
98 // Handle the sign.
99 EXPECT_EQ(4294964951, FXSYS_atoui("-2345"));
dsinclair 2016/03/24 02:41:06 This should also be 0 I think.
100 EXPECT_EQ(2345, FXSYS_atoui("+2345"));
101 // The max value.
82 EXPECT_EQ(4294967295, FXSYS_atoui("4294967295")); 102 EXPECT_EQ(4294967295, FXSYS_atoui("4294967295"));
83 EXPECT_EQ(9, FXSYS_atoui("9x9")); 103 EXPECT_EQ(9, FXSYS_atoui("9x9"));
84 104
85 // TODO(dsinclair): These are all wacky ..... 105 // Out of range values.
86 EXPECT_EQ(2147483623, FXSYS_atoi("2147483623423412348")); 106 EXPECT_EQ(4294967295, FXSYS_atoui("2147483623423412348"));
87 EXPECT_EQ(429496729, FXSYS_atoi("4294967296")); 107 EXPECT_EQ(4294967295, FXSYS_atoui("4294967296"));
108 EXPECT_EQ(4294967295, FXSYS_atoui("-4294967345"));
dsinclair 2016/03/24 02:41:06 Also 0.
88 } 109 }
OLDNEW
« core/fxcrt/fx_basic_gcc.cpp ('K') | « core/fxcrt/fx_basic_gcc.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698