summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2012-09-16 13:48:51 +0200
committerAlbert Astals Cid <aacid@kde.org>2012-09-16 13:48:51 +0200
commitc6d7084d316e94b5b042b086f5440f8543ff5947 (patch)
tree5390873d39996cbf4bd55c4ea7ed10294e94651b
parent365808837080574080b4f8da079124c172fb2123 (diff)
Fix parsing of numbers
-2147483648 is an integer -2147483649 is a real
-rw-r--r--poppler/Lexer.cc14
-rw-r--r--qt4/tests/CMakeLists.txt1
-rw-r--r--qt4/tests/check_lexer.cpp118
3 files changed, 131 insertions, 2 deletions
diff --git a/poppler/Lexer.cc b/poppler/Lexer.cc
index d12e2e8c..01b730bd 100644
--- a/poppler/Lexer.cc
+++ b/poppler/Lexer.cc
@@ -13,7 +13,7 @@
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
-// Copyright (C) 2006-2010 Albert Astals Cid <aacid@kde.org>
+// Copyright (C) 2006-2010, 2012 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2006 Krzysztof Kowalczyk <kkowalczyk@gmail.com>
// Copyright (C) 2010 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2012 Adrian Johnson <ajohnson@redneon.com>
@@ -237,7 +237,17 @@ Object *Lexer::getObj(Object *obj, int objNum) {
if (overflownUnsignedInteger) {
obj->initReal(xf);
} else {
- obj->initUint(xui);
+ if (neg) {
+ if (xui-1 == INT_MAX) {
+ obj->initInt(INT_MIN);
+ } else {
+ xf = xui;
+ xf = -xf;
+ obj->initReal(xf);
+ }
+ } else {
+ obj->initUint(xui);
+ }
}
} else {
obj->initInt(xi);
diff --git a/qt4/tests/CMakeLists.txt b/qt4/tests/CMakeLists.txt
index 028c1e1d..9eaaa026 100644
--- a/qt4/tests/CMakeLists.txt
+++ b/qt4/tests/CMakeLists.txt
@@ -56,6 +56,7 @@ qt4_add_qtest(check_password check_password.cpp)
qt4_add_qtest(check_permissions check_permissions.cpp)
qt4_add_qtest(check_search check_search.cpp)
qt4_add_qtest(check_actualtext check_actualtext.cpp)
+qt4_add_qtest(check_lexer check_lexer.cpp)
if (NOT WIN32)
qt4_add_qtest(check_strings check_strings.cpp)
endif (NOT WIN32)
diff --git a/qt4/tests/check_lexer.cpp b/qt4/tests/check_lexer.cpp
new file mode 100644
index 00000000..904be14a
--- /dev/null
+++ b/qt4/tests/check_lexer.cpp
@@ -0,0 +1,118 @@
+#include <QtTest/QtTest>
+
+#include "Object.h"
+#include "Lexer.h"
+
+class TestLexer : public QObject
+{
+ Q_OBJECT
+private slots:
+ void testNumbers();
+};
+
+void TestLexer::testNumbers()
+{
+ 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";
+ Object dummy;
+ MemStream *stream = new MemStream(data, 0, strlen(data), &dummy);
+ Lexer *lexer = new Lexer(NULL, stream);
+ QVERIFY( lexer );
+
+ Object obj;
+
+ lexer->getObj(&obj);
+ QCOMPARE(obj.getType(), objInt);
+ QCOMPARE(obj.getInt(), 0);
+ obj.free();
+
+ lexer->getObj(&obj);
+ QCOMPARE(obj.getType(), objInt);
+ QCOMPARE(obj.getInt(), 1);
+ obj.free();
+
+ lexer->getObj(&obj);
+ QCOMPARE(obj.getType(), objInt);
+ QCOMPARE(obj.getInt(), -1);
+ obj.free();
+
+ lexer->getObj(&obj);
+ QCOMPARE(obj.getType(), objInt);
+ QCOMPARE(obj.getInt(), 2147483647);
+ obj.free();
+
+ lexer->getObj(&obj);
+ QCOMPARE(obj.getType(), objInt);
+ QCOMPARE(obj.getInt(), -2147483647);
+ obj.free();
+
+ lexer->getObj(&obj);
+ QCOMPARE(obj.getType(), objUint);
+ QCOMPARE(obj.getUint(), (unsigned int)2147483648);
+ obj.free();
+
+ lexer->getObj(&obj);
+ QCOMPARE(obj.getType(), objInt);
+ QCOMPARE(obj.getInt(), (int)-2147483648);
+ obj.free();
+
+ lexer->getObj(&obj);
+ QCOMPARE(obj.getType(), objReal);
+ QCOMPARE(obj.getReal(), (double)4294967297);
+ obj.free();
+
+ lexer->getObj(&obj);
+ QCOMPARE(obj.getType(), objReal);
+ QCOMPARE(obj.getReal(), (double)-2147483649);
+ obj.free();
+
+ lexer->getObj(&obj);
+ QCOMPARE(obj.getType(), objReal);
+ QCOMPARE(obj.getReal(), 0.1);
+ obj.free();
+
+ lexer->getObj(&obj);
+ QCOMPARE(obj.getType(), objReal);
+ QCOMPARE(obj.getReal(), 1.1);
+ obj.free();
+
+ lexer->getObj(&obj);
+ QCOMPARE(obj.getType(), objReal);
+ QCOMPARE(obj.getReal(), -1.1);
+ obj.free();
+
+ lexer->getObj(&obj);
+ QCOMPARE(obj.getType(), objReal);
+ QCOMPARE(obj.getReal(), 2147483647.1);
+ obj.free();
+
+ lexer->getObj(&obj);
+ QCOMPARE(obj.getType(), objReal);
+ QCOMPARE(obj.getReal(), -2147483647.1);
+ obj.free();
+
+ lexer->getObj(&obj);
+ QCOMPARE(obj.getType(), objReal);
+ QCOMPARE(obj.getReal(), 2147483648.1);
+ obj.free();
+
+ lexer->getObj(&obj);
+ QCOMPARE(obj.getType(), objReal);
+ QCOMPARE(obj.getReal(), -2147483648.1);
+ obj.free();
+
+ lexer->getObj(&obj);
+ QCOMPARE(obj.getType(), objReal);
+ QCOMPARE(obj.getReal(), 4294967297.1);
+ obj.free();
+
+ lexer->getObj(&obj);
+ QCOMPARE(obj.getType(), objReal);
+ QCOMPARE(obj.getReal(), -2147483649.1);
+ obj.free();
+
+ delete lexer;
+}
+
+QTEST_MAIN(TestLexer)
+#include "check_lexer.moc"
+