summaryrefslogtreecommitdiff
path: root/core/fxcrt/fx_basic_gcc_unittest.cpp
blob: 73e7446de0081e8ee9d8b8b9371bacb6635f6323 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright 2016 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "core/fxcrt/include/fx_system.h"
#include "testing/gtest/include/gtest/gtest.h"

TEST(fxcrt, FXSYS_atoi) {
  EXPECT_EQ(0, FXSYS_atoi(""));
  EXPECT_EQ(0, FXSYS_atoi("0"));
  EXPECT_EQ(-1, FXSYS_atoi("-1"));
  EXPECT_EQ(2345, FXSYS_atoi("2345"));
  EXPECT_EQ(-2147483647, FXSYS_atoi("-2147483647"));
  // Handle the sign.
  EXPECT_EQ(-2345, FXSYS_atoi("-2345"));
  EXPECT_EQ(2345, FXSYS_atoi("+2345"));
  // The max value.
  EXPECT_EQ(2147483647, FXSYS_atoi("2147483647"));
  // The min value. Written in -1 format to avoid "unary minus operator applied
  // to unsigned type" warning.
  EXPECT_EQ(-2147483647 - 1, FXSYS_atoi("-2147483648"));
  // With invalid char.
  EXPECT_EQ(9, FXSYS_atoi("9x9"));

  // Out of range values.
  EXPECT_EQ(2147483647, FXSYS_atoi("2147483623423412348"));
  EXPECT_EQ(2147483647, FXSYS_atoi("2147483648"));
  EXPECT_EQ(-2147483647 - 1, FXSYS_atoi("-2147483650"));
}

TEST(fxcrt, FXSYS_atoi64) {
  EXPECT_EQ(0, FXSYS_atoi64(""));
  EXPECT_EQ(0, FXSYS_atoi64("0"));
  EXPECT_EQ(-1, FXSYS_atoi64("-1"));
  EXPECT_EQ(2345, FXSYS_atoi64("2345"));
  EXPECT_EQ(-9223372036854775807LL, FXSYS_atoi64("-9223372036854775807"));
  // Handle the sign.
  EXPECT_EQ(-2345, FXSYS_atoi64("-2345"));
  EXPECT_EQ(2345, FXSYS_atoi64("+2345"));
  // The max value.
  EXPECT_EQ(9223372036854775807LL, FXSYS_atoi64("9223372036854775807"));
  // The min value. Written in -1 format to avoid implicit unsigned warning.
  EXPECT_EQ(-9223372036854775807LL - 1LL, FXSYS_atoi64("-9223372036854775808"));
  // With invalid char.
  EXPECT_EQ(9, FXSYS_atoi64("9x9"));

  // Out of range values.
  EXPECT_EQ(9223372036854775807LL, FXSYS_atoi64("922337203685471234123475807"));
  EXPECT_EQ(9223372036854775807LL, FXSYS_atoi64("9223372036854775808"));
  EXPECT_EQ(-9223372036854775807LL - 1LL, FXSYS_atoi64("-9223372036854775810"));
}

TEST(fxcrt, FXSYS_wtoi) {
  EXPECT_EQ(0, FXSYS_wtoi(L""));
  EXPECT_EQ(0, FXSYS_wtoi(L"0"));
  EXPECT_EQ(-1, FXSYS_wtoi(L"-1"));
  EXPECT_EQ(2345, FXSYS_wtoi(L"2345"));
  EXPECT_EQ(-2147483647, FXSYS_wtoi(L"-2147483647"));
  // The max value.
  EXPECT_EQ(2147483647, FXSYS_wtoi(L"2147483647"));
  // The min value.
  EXPECT_EQ(-2147483647 - 1, FXSYS_wtoi(L"-2147483648"));
  EXPECT_EQ(9, FXSYS_wtoi64(L"9x9"));

  // Out of range values.
  EXPECT_EQ(2147483647, FXSYS_wtoi(L"2147483623423412348"));
  EXPECT_EQ(2147483647, FXSYS_wtoi(L"2147483648"));
  EXPECT_EQ(-2147483647 - 1, FXSYS_wtoi(L"-2147483652"));
}

TEST(fxcrt, FXSYS_wtoi64) {
  EXPECT_EQ(0, FXSYS_wtoi64(L""));
  EXPECT_EQ(0, FXSYS_wtoi64(L"0"));
  EXPECT_EQ(-1, FXSYS_wtoi64(L"-1"));
  EXPECT_EQ(2345, FXSYS_wtoi64(L"2345"));
  EXPECT_EQ(-9223372036854775807LL, FXSYS_wtoi64(L"-9223372036854775807"));
  // Handle the sign.
  EXPECT_EQ(-2345, FXSYS_wtoi64(L"-2345"));
  EXPECT_EQ(2345, FXSYS_wtoi64(L"+2345"));
  // The max value.
  EXPECT_EQ(9223372036854775807LL, FXSYS_wtoi64(L"9223372036854775807"));
  // The min value.
  EXPECT_EQ(-9223372036854775807LL - 1LL,
            FXSYS_wtoi64(L"-9223372036854775808"));
  // With invalid char.
  EXPECT_EQ(9, FXSYS_wtoi64(L"9x9"));

  // Out of range values.
  EXPECT_EQ(9223372036854775807LL,
            FXSYS_wtoi64(L"922337203685471234123475807"));
  EXPECT_EQ(9223372036854775807LL, FXSYS_wtoi64(L"9223372036854775808"));
  EXPECT_EQ(-9223372036854775807LL - 1LL,
            FXSYS_wtoi64(L"-9223372036854775810"));
}

TEST(fxcrt, FXSYS_atoui) {
  EXPECT_EQ(0u, FXSYS_atoui(""));
  EXPECT_EQ(0u, FXSYS_atoui("0"));
  EXPECT_EQ(4294967295, FXSYS_atoui("-1"));
  EXPECT_EQ(2345u, FXSYS_atoui("2345"));
  // Handle the sign.
  EXPECT_EQ(4294964951, FXSYS_atoui("-2345"));
  EXPECT_EQ(2345u, FXSYS_atoui("+2345"));
  // The max value.
  EXPECT_EQ(4294967295, FXSYS_atoui("4294967295"));
  EXPECT_EQ(9u, FXSYS_atoui("9x9"));

  // Out of range values.
  EXPECT_EQ(4294967295, FXSYS_atoui("2147483623423412348"));
  EXPECT_EQ(4294967295, FXSYS_atoui("4294967296"));
  EXPECT_EQ(4294967295, FXSYS_atoui("-4294967345"));
}