1#include <QtTest/QTest>
2
3#include "Object.h"
4#include "Lexer.h"
5
6class TestLexer : public QObject
7{
8 Q_OBJECT
9public:
10 explicit TestLexer(QObject *parent = nullptr) : QObject(parent) { }
11private slots:
12 void testNumbers();
13};
14
15void TestLexer::testNumbers()
16{
17 char data[] = "0 1 -1 2147483647 -2147483647 2147483648 -2147483648 4294967297 -2147483649 0.1 1.1 -1.1 2147483647.1 -2147483647.1 2147483648.1 -2147483648.1 4294967297.1 -2147483649.1 9223372036854775807 18446744073709551615";
18 MemStream *stream = new MemStream(data, 0, strlen(s: data), Object(objNull));
19 Lexer *lexer = new Lexer(nullptr, stream);
20 QVERIFY(lexer);
21
22 Object obj;
23
24 obj = lexer->getObj();
25 QCOMPARE(obj.getType(), objInt);
26 QCOMPARE(obj.getInt(), 0);
27
28 obj = lexer->getObj();
29 QCOMPARE(obj.getType(), objInt);
30 QCOMPARE(obj.getInt(), 1);
31
32 obj = lexer->getObj();
33 QCOMPARE(obj.getType(), objInt);
34 QCOMPARE(obj.getInt(), -1);
35
36 obj = lexer->getObj();
37 QCOMPARE(obj.getType(), objInt);
38 QCOMPARE(obj.getInt(), 2147483647);
39
40 obj = lexer->getObj();
41 QCOMPARE(obj.getType(), objInt);
42 QCOMPARE(obj.getInt(), -2147483647);
43
44 obj = lexer->getObj();
45 QCOMPARE(obj.getType(), objInt64);
46 QCOMPARE(obj.getInt64(), 2147483648ll);
47
48 obj = lexer->getObj();
49 QCOMPARE(obj.getType(), objInt);
50 QCOMPARE(obj.getInt(), -2147483647 - 1);
51
52 obj = lexer->getObj();
53 QCOMPARE(obj.getType(), objInt64);
54 QCOMPARE(obj.getInt64(), 4294967297ll);
55
56 obj = lexer->getObj();
57 QCOMPARE(obj.getType(), objInt64);
58 QCOMPARE(obj.getInt64(), -2147483649ll);
59
60 obj = lexer->getObj();
61 QCOMPARE(obj.getType(), objReal);
62 QCOMPARE(obj.getReal(), 0.1);
63
64 obj = lexer->getObj();
65 QCOMPARE(obj.getType(), objReal);
66 QCOMPARE(obj.getReal(), 1.1);
67
68 obj = lexer->getObj();
69 QCOMPARE(obj.getType(), objReal);
70 QCOMPARE(obj.getReal(), -1.1);
71
72 obj = lexer->getObj();
73 QCOMPARE(obj.getType(), objReal);
74 QCOMPARE(obj.getReal(), 2147483647.1);
75
76 obj = lexer->getObj();
77 QCOMPARE(obj.getType(), objReal);
78 QCOMPARE(obj.getReal(), -2147483647.1);
79
80 obj = lexer->getObj();
81 QCOMPARE(obj.getType(), objReal);
82 QCOMPARE(obj.getReal(), 2147483648.1);
83
84 obj = lexer->getObj();
85 QCOMPARE(obj.getType(), objReal);
86 QCOMPARE(obj.getReal(), -2147483648.1);
87
88 obj = lexer->getObj();
89 QCOMPARE(obj.getType(), objReal);
90 QCOMPARE(obj.getReal(), 4294967297.1);
91
92 obj = lexer->getObj();
93 QCOMPARE(obj.getType(), objReal);
94 QCOMPARE(obj.getReal(), -2147483649.1);
95
96 obj = lexer->getObj();
97 QCOMPARE(obj.getType(), objInt64);
98 QCOMPARE(obj.getInt64(), 9223372036854775807ll);
99
100 obj = lexer->getObj();
101 QCOMPARE(obj.getType(), objReal);
102 QCOMPARE(obj.getReal(), 18446744073709551616.);
103
104 delete lexer;
105}
106
107QTEST_GUILESS_MAIN(TestLexer)
108#include "check_lexer.moc"
109

source code of poppler/qt6/tests/check_lexer.cpp