Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
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
21 CFGAS_Decimal big(std::numeric_limits<int32_t>::max());
22 CFGAS_Decimal small(std::numeric_limits<int32_t>::min());
23 EXPECT_STREQ(L"2147483647", big.ToWideString().c_str());
24 EXPECT_STREQ(L"-2147483648", small.ToWideString().c_str());
25}
26
28 CFGAS_Decimal big(std::numeric_limits<uint32_t>::max());
29 CFGAS_Decimal small(std::numeric_limits<uint32_t>::min());
30 EXPECT_STREQ(L"4294967295", big.ToWideString().c_str());
31 EXPECT_STREQ(L"0", small.ToWideString().c_str());
32}
33
35 CFGAS_Decimal big(std::numeric_limits<uint64_t>::max());
36 CFGAS_Decimal small(std::numeric_limits<uint64_t>::min());
37 EXPECT_STREQ(L"18446744073709551615", big.ToWideString().c_str());
38 EXPECT_STREQ(L"0", small.ToWideString().c_str());
39}
40
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_STREQ(big_expected.First(8).c_str(), big.First(8).c_str());
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_STREQ(tiny_expected.First(8).c_str(), tiny.First(8).c_str());
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_STREQ(teeny_expected.First(8).c_str(), teeny.First(8).c_str());
58}
59
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_STREQ(case1_expected.First(8).c_str(), case1.First(8).c_str());
67}
68
70 CFGAS_Decimal big(L"100000000000000000000000000");
71 CFGAS_Decimal small(L"-1000000000000000000000000");
72 EXPECT_STREQ(L"100000000000000000000000000", big.ToWideString().c_str());
73 EXPECT_STREQ(L"-1000000000000000000000000", small.ToWideString().c_str());
74}
75
77 CFGAS_Decimal frac(L"32109876543210.0123456890123");
78 EXPECT_STREQ(L"32109876543210.0123456890123", frac.ToWideString().c_str());
79}
TEST(CFGAS_Decimal, Empty)
CFGAS_Decimal(uint64_t val)
CFGAS_Decimal(float val, uint8_t scale)
CFGAS_Decimal(uint32_t val)
double ToDouble() const
WideString ToWideString() const
CFGAS_Decimal(int32_t val)
float ToFloat() const
const wchar_t * c_str() const
Definition widestring.h:81