summaryrefslogtreecommitdiff
path: root/qt4
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 /qt4
parent365808837080574080b4f8da079124c172fb2123 (diff)
Fix parsing of numbers
-2147483648 is an integer -2147483649 is a real
Diffstat (limited to 'qt4')
-rw-r--r--qt4/tests/CMakeLists.txt1
-rw-r--r--qt4/tests/check_lexer.cpp118
2 files changed, 119 insertions, 0 deletions
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"
+