Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
cfgas_decimal_unittest.cpp
Go to the documentation of this file.
1
// Copyright 2019 The PDFium Authors
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
"xfa/fgas/crt/cfgas_decimal.h"
6
7
#
include
<
math
.
h
>
8
9
#
include
<
limits
>
10
11
#
include
"testing/gtest/include/gtest/gtest.h"
12
13
TEST
(
CFGAS_Decimal
,
Empty
) {
14
CFGAS_Decimal
empty;
15
EXPECT_EQ(L"0", empty
.
ToWideString
(
)
);
16
EXPECT_EQ(0.0f, empty
.
ToFloat
(
)
);
17
EXPECT_EQ(0.0, empty
.
ToDouble
(
)
);
18
}
19
20
TEST
(
CFGAS_Decimal
,
FromInt32
) {
21
CFGAS_Decimal
big
(
std
::numeric_limits<int32_t>::max()
)
;
22
CFGAS_Decimal
small
(
std
::numeric_limits<int32_t>::min()
)
;
23
EXPECT_EQ(L"2147483647", big
.
ToWideString
(
)
);
24
EXPECT_EQ(L"-2147483648", small
.
ToWideString
(
)
);
25
}
26
27
TEST
(
CFGAS_Decimal
,
FromUint32
) {
28
CFGAS_Decimal
big
(
std
::numeric_limits<uint32_t>::max()
)
;
29
CFGAS_Decimal
small
(
std
::numeric_limits<uint32_t>::min()
)
;
30
EXPECT_EQ(L"4294967295", big
.
ToWideString
(
)
);
31
EXPECT_EQ(L"0", small
.
ToWideString
(
)
);
32
}
33
34
TEST
(
CFGAS_Decimal
,
FromUint64
) {
35
CFGAS_Decimal
big
(
std
::numeric_limits<uint64_t>::max()
)
;
36
CFGAS_Decimal
small
(
std
::numeric_limits<uint64_t>::min()
)
;
37
EXPECT_EQ(L"18446744073709551615", big
.
ToWideString
(
)
);
38
EXPECT_EQ(L"0", small
.
ToWideString
(
)
);
39
}
40
41
TEST
(
CFGAS_Decimal
,
FromFloat
) {
42
WideString
big =
CFGAS_Decimal
(
powf(2.0f, 95.0f)
,
0
)
.
ToWideString
(
)
;
43
WideString
big_expected = L"39614081257132168796771975168";
44
45
// Precision may not be the same on all platforms.
46
EXPECT_EQ(big_expected.GetLength(), big.GetLength());
47
EXPECT_EQ(big_expected.First(8).c_str(), big.First(8));
48
49
WideString
tiny =
CFGAS_Decimal
(
1e20f
,
0
)
.
ToWideString
(
)
;
50
WideString
tiny_expected = L"100000000000000000000";
51
EXPECT_EQ(tiny_expected.GetLength(), tiny.GetLength());
52
EXPECT_EQ(tiny_expected.First(8).c_str(), tiny.First(8));
53
54
WideString
teeny =
CFGAS_Decimal
(
1e14f
,
4
)
.
ToWideString
(
)
;
55
WideString
teeny_expected = L"100000000000000.0000";
56
EXPECT_EQ(teeny_expected.GetLength(), teeny.GetLength());
57
EXPECT_EQ(teeny_expected.First(8).c_str(), teeny.First(8));
58
}
59
60
TEST
(
CFGAS_Decimal
,
FromFloatFractional
) {
61
WideString
case1 =
CFGAS_Decimal
(
123.456f
,
10
)
.
ToWideString
(
)
;
62
WideString
case1_expected = L"123.4560000000";
63
64
// Precision may not be the same on all platforms.
65
EXPECT_EQ(case1_expected.GetLength(), case1.GetLength());
66
EXPECT_EQ(case1_expected.First(8).c_str(), case1.First(8));
67
}
68
69
TEST
(
CFGAS_Decimal
,
FromString
) {
70
CFGAS_Decimal
big(L"100000000000000000000000000");
71
CFGAS_Decimal
small(L"-1000000000000000000000000");
72
EXPECT_EQ(L"100000000000000000000000000", big
.
ToWideString
(
)
);
73
EXPECT_EQ(L"-1000000000000000000000000", small
.
ToWideString
(
)
);
74
}
75
76
TEST
(
CFGAS_Decimal
,
FromString28Digits
) {
77
CFGAS_Decimal
frac(L"32109876543210.0123456890123");
78
EXPECT_EQ(L"32109876543210.0123456890123", frac
.
ToWideString
(
)
);
79
}
TEST
TEST(CFGAS_Decimal, Empty)
Definition
cfgas_decimal_unittest.cpp:13
CFGAS_Decimal
Definition
cfgas_decimal.h:12
CFGAS_Decimal::CFGAS_Decimal
CFGAS_Decimal(uint64_t val)
Definition
cfgas_decimal.cpp:272
CFGAS_Decimal::CFGAS_Decimal
CFGAS_Decimal(float val, uint8_t scale)
Definition
cfgas_decimal.cpp:302
CFGAS_Decimal::CFGAS_Decimal
CFGAS_Decimal(uint32_t val)
Definition
cfgas_decimal.cpp:276
CFGAS_Decimal::ToDouble
double ToDouble() const
Definition
cfgas_decimal.cpp:393
CFGAS_Decimal::ToWideString
WideString ToWideString() const
Definition
cfgas_decimal.cpp:363
CFGAS_Decimal::CFGAS_Decimal
CFGAS_Decimal(int32_t val)
Definition
cfgas_decimal.cpp:290
CFGAS_Decimal::ToFloat
float ToFloat() const
Definition
cfgas_decimal.cpp:389
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
WideString
fxcrt::WideString WideString
Definition
widestring.h:207
qtwebengine
src
3rdparty
chromium
third_party
pdfium
xfa
fgas
crt
cfgas_decimal_unittest.cpp
Generated on
for Qt by
1.18.0