qt4/src/poppler-private.cc | 4 - qt4/tests/CMakeLists.txt | 3 qt4/tests/Makefile.am | 7 + qt4/tests/check_strings.cpp | 174 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 186 insertions(+), 2 deletions(-)
New commits: commit ffd227b7669895325d752009d5185973cf86ce5b Author: Pino Toscano <[email protected]> Date: Fri Sep 17 14:25:57 2010 +0200 [Qt4] optimize UnicodeParsedString using less memory from QString - reserve() the right number of chars in the result string, so there is less possibility to make it gr ow its buffer - do not call unicodeToQString() just to create a 1 character string, but directly append a QChar crea ted with the resulting unicode value (always belonging to the BMP) this should reduce of a very little bit the memory usage, while give a sensible speedup of UnicodeParsedString invocations diff --git a/qt4/src/poppler-private.cc b/qt4/src/poppler-private.cc index 4612fcf..df55b20 100644 --- a/qt4/src/poppler-private.cc +++ b/qt4/src/poppler-private.cc @@ -71,11 +71,13 @@ namespace Poppler { { isUnicode = gTrue; i = 2; + result.reserve( ( s1->getLength() - 2 ) / 2 ); } else { isUnicode = gFalse; i = 0; + result.reserve( s1->getLength() ); } while ( i < s1->getLength() ) { @@ -89,7 +91,7 @@ namespace Poppler { u = s1->getChar(i) & 0xff; ++i; } - result += unicodeToQString( &u, 1 ); + result += QChar( u ); } return result; } commit 6180890008f2b1814f092f50b8f75376399905ba Author: Pino Toscano <[email protected]> Date: Fri Sep 17 13:23:25 2010 +0200 [Qt4/tests] check_strings: add a test case for UnicodeParsedString very simple test data for it, at the moment diff --git a/qt4/tests/check_strings.cpp b/qt4/tests/check_strings.cpp index f45556a..f9913c8 100644 --- a/qt4/tests/check_strings.cpp +++ b/qt4/tests/check_strings.cpp @@ -15,6 +15,8 @@ private slots: void cleanupTestCase(); void check_unicodeToQString_data(); void check_unicodeToQString(); + void check_UnicodeParsedString_data(); + void check_UnicodeParsedString(); void check_QStringToGooString_data(); void check_QStringToGooString(); @@ -81,6 +83,52 @@ void TestStrings::check_unicodeToQString() delete [] data; } +void TestStrings::check_UnicodeParsedString_data() +{ + QTest::addColumn<GooString*>("string"); + QTest::addColumn<QString>("result"); + + // non-unicode strings + QTest::newRow("<empty>") << newGooString("") + << QString(); + QTest::newRow("a") << newGooString("a") + << QString::fromUtf8("a"); + QTest::newRow("ab") << newGooString("ab") + << QString::fromUtf8("ab"); + QTest::newRow("~") << newGooString("~") + << QString::fromUtf8("~"); + QTest::newRow("test string") << newGooString("test string") + << QString::fromUtf8("test string"); + + // unicode strings + QTest::newRow("<unicode marks>") << newGooString("\xFE\xFF") + << QString(); + QTest::newRow("U a") << newGooString("\xFE\xFF\0a", 4) + << QString::fromUtf8("a"); + QTest::newRow("U ~") << newGooString("\xFE\xFF\0~", 4) + << QString::fromUtf8("~"); + QTest::newRow("U aa") << newGooString("\xFE\xFF\0a\0a", 6) + << QString::fromUtf8("aa"); + QTest::newRow("U \xC3\x9F") << newGooString("\xFE\xFF\0\xDF", 4) + << QString::fromUtf8("\xC3\x9F"); + QTest::newRow("U \xC3\x9F\x61") << newGooString("\xFE\xFF\0\xDF\0\x61", 6) + << QString::fromUtf8("\xC3\x9F\x61"); + QTest::newRow("U \xC5\xA1") << newGooString("\xFE\xFF\x01\x61", 4) + << QString::fromUtf8("\xC5\xA1"); + QTest::newRow("U \xC5\xA1\x61") << newGooString("\xFE\xFF\x01\x61\0\x61", 6) + << QString::fromUtf8("\xC5\xA1\x61"); + QTest::newRow("test string") << newGooString("\xFE\xFF\0t\0e\0s\0t\0 \0s\0t\0r\0i\0n\0g", 24) + << QString::fromUtf8("test string"); +} + +void TestStrings::check_UnicodeParsedString() +{ + QFETCH(GooString*, string); + QFETCH(QString, result); + + QCOMPARE(Poppler::UnicodeParsedString(string), result); +} + void TestStrings::check_QStringToGooString_data() { QTest::addColumn<QString>("string"); commit c5f78d7d3953d62a746c6f5a90085ea020fe5ec7 Author: Pino Toscano <[email protected]> Date: Fri Sep 17 12:54:32 2010 +0200 [Qt4/tests] check_string: use a pool of GooString this way we can reuse the GooString in a data set even after a test run (eg in benchmarks), making sure they all are properly freed diff --git a/qt4/tests/check_strings.cpp b/qt4/tests/check_strings.cpp index 474556e..f45556a 100644 --- a/qt4/tests/check_strings.cpp +++ b/qt4/tests/check_strings.cpp @@ -12,10 +12,17 @@ class TestStrings : public QObject private slots: void initTestCase(); + void cleanupTestCase(); void check_unicodeToQString_data(); void check_unicodeToQString(); void check_QStringToGooString_data(); void check_QStringToGooString(); + +private: + GooString* newGooString(const char *s); + GooString* newGooString(const char *s, int l); + + QVector<GooString *> m_gooStrings; }; void TestStrings::initTestCase() @@ -24,6 +31,11 @@ void TestStrings::initTestCase() qRegisterMetaType<Unicode*>("Unicode*"); } +void TestStrings::cleanupTestCase() +{ + qDeleteAll(m_gooStrings); +} + void TestStrings::check_unicodeToQString_data() { QTest::addColumn<Unicode*>("data"); @@ -75,13 +87,13 @@ void TestStrings::check_QStringToGooString_data() QTest::addColumn<GooString*>("result"); QTest::newRow("<null>") << QString() - << new GooString(""); + << newGooString(""); QTest::newRow("<empty>") << QString::fromUtf8("") - << new GooString(""); + << newGooString(""); QTest::newRow("a") << QString::fromUtf8("a") - << new GooString("a"); + << newGooString("a"); QTest::newRow("ab") << QString::fromUtf8("ab") - << new GooString("ab"); + << newGooString("ab"); } void TestStrings::check_QStringToGooString() @@ -93,7 +105,20 @@ void TestStrings::check_QStringToGooString() QCOMPARE(goo->getCString(), result->getCString()); delete goo; - delete result; +} + +GooString* TestStrings::newGooString(const char *s) +{ + GooString *goo = new GooString(s); + m_gooStrings.append(goo); + return goo; +} + +GooString* TestStrings::newGooString(const char *s, int l) +{ + GooString *goo = new GooString(s, l); + m_gooStrings.append(goo); + return goo; } QTEST_MAIN(TestStrings) commit 0cd5a256bdf7778c0c720941a611ad8ab56fa2e9 Author: Pino Toscano <[email protected]> Date: Fri Sep 17 00:27:53 2010 +0200 [Qt4/tests] first version of a unit test for strings this is used for testing the various string conversions: - unicodeToQString - UnicodeParsedString - QStringToUnicodeGooString - QStringToGooString the 1st and the 4th have basic tests given private symbols are used, this unit test is not compiled on windows (at least, it supposed to be so) diff --git a/qt4/tests/CMakeLists.txt b/qt4/tests/CMakeLists.txt index 3a67614..d0ba762 100644 --- a/qt4/tests/CMakeLists.txt +++ b/qt4/tests/CMakeLists.txt @@ -55,3 +55,6 @@ 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) +if (NOT WIN32) + qt4_add_qtest(check_strings check_strings.cpp) +endif (NOT WIN32) diff --git a/qt4/tests/Makefile.am b/qt4/tests/Makefile.am index 244097c..93e1132 100644 --- a/qt4/tests/Makefile.am +++ b/qt4/tests/Makefile.am @@ -78,7 +78,8 @@ TESTS = \ check_pagemode \ check_password \ check_pagelayout \ - check_search + check_search \ + check_strings check_PROGRAMS = $(TESTS) @@ -130,5 +131,9 @@ check_search_SOURCES = check_search.cpp check_search.$(OBJEXT): check_search.moc check_search_LDADD = $(LDADDS) $(POPPLER_QT4_TEST_LIBS) +check_strings_SOURCES = check_strings.cpp +check_strings.$(OBJEXT): check_strings.moc +check_strings_LDADD = $(LDADDS) $(POPPLER_QT4_TEST_LIBS) + endif diff --git a/qt4/tests/check_strings.cpp b/qt4/tests/check_strings.cpp new file mode 100644 index 0000000..474556e --- /dev/null +++ b/qt4/tests/check_strings.cpp @@ -0,0 +1,101 @@ +#include <QtTest/QtTest> + +#include <poppler-qt4.h> +#include <poppler-private.h> + +Q_DECLARE_METATYPE(GooString*) +Q_DECLARE_METATYPE(Unicode*) + +class TestStrings : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + void check_unicodeToQString_data(); + void check_unicodeToQString(); + void check_QStringToGooString_data(); + void check_QStringToGooString(); +}; + +void TestStrings::initTestCase() +{ + qRegisterMetaType<GooString*>("GooString*"); + qRegisterMetaType<Unicode*>("Unicode*"); +} + +void TestStrings::check_unicodeToQString_data() +{ + QTest::addColumn<Unicode*>("data"); + QTest::addColumn<int>("length"); + QTest::addColumn<QString>("result"); + + { + const int l = 1; + Unicode *u = new Unicode[l]; + u[0] = int('a'); + QTest::newRow("a") << u << l << QString::fromUtf8("a"); + } + { + const int l = 1; + Unicode *u = new Unicode[l]; + u[0] = 0x0161; + QTest::newRow("\u0161") << u << l << QString::fromUtf8("\u0161"); + } + { + const int l = 2; + Unicode *u = new Unicode[l]; + u[0] = int('a'); + u[1] = int('b'); + QTest::newRow("ab") << u << l << QString::fromUtf8("ab"); + } + { + const int l = 2; + Unicode *u = new Unicode[l]; + u[0] = int('a'); + u[1] = 0x0161; + QTest::newRow("a\u0161") << u << l << QString::fromUtf8("a\u0161"); + } +} + +void TestStrings::check_unicodeToQString() +{ + QFETCH(Unicode*, data); + QFETCH(int, length); + QFETCH(QString, result); + + QCOMPARE(Poppler::unicodeToQString(data, length), result); + + delete [] data; +} + +void TestStrings::check_QStringToGooString_data() +{ + QTest::addColumn<QString>("string"); + QTest::addColumn<GooString*>("result"); + + QTest::newRow("<null>") << QString() + << new GooString(""); + QTest::newRow("<empty>") << QString::fromUtf8("") + << new GooString(""); + QTest::newRow("a") << QString::fromUtf8("a") + << new GooString("a"); + QTest::newRow("ab") << QString::fromUtf8("ab") + << new GooString("ab"); +} + +void TestStrings::check_QStringToGooString() +{ + QFETCH(QString, string); + QFETCH(GooString*, result); + + GooString *goo = Poppler::QStringToGooString(string); + QCOMPARE(goo->getCString(), result->getCString()); + + delete goo; + delete result; +} + +QTEST_MAIN(TestStrings) + +#include "check_strings.moc" _______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
