[poppler] Branch 'poppler-0.20' - poppler/Lexer.cc qt4/tests

Albert Astals Cid aacid at kemper.freedesktop.org
Sun Sep 16 04:49:32 PDT 2012


 poppler/Lexer.cc          |   14 ++++-
 qt4/tests/CMakeLists.txt  |    1 
 qt4/tests/check_lexer.cpp |  118 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 131 insertions(+), 2 deletions(-)

New commits:
commit c6d7084d316e94b5b042b086f5440f8543ff5947
Author: Albert Astals Cid <aacid at kde.org>
Date:   Sun Sep 16 13:48:51 2012 +0200

    Fix parsing of numbers
    
    -2147483648 is an integer
    -2147483649 is a real

diff --git a/poppler/Lexer.cc b/poppler/Lexer.cc
index d12e2e8..01b730b 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 at kde.org>
+// Copyright (C) 2006-2010, 2012 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2006 Krzysztof Kowalczyk <kkowalczyk at gmail.com>
 // Copyright (C) 2010 Carlos Garcia Campos <carlosgc at gnome.org>
 // Copyright (C) 2012 Adrian Johnson <ajohnson at 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 028c1e1..9eaaa02 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 0000000..904be14
--- /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"
+


More information about the poppler mailing list