poppler/Makefile.am | 3 poppler/PageLabelInfo.cc | 160 -------------------------------------- poppler/PageLabelInfo_p.h | 147 ++++++++++++++++++++++++++++++++++ qt4/tests/CMakeLists.txt | 1 qt4/tests/Makefile.am | 4 qt4/tests/check_pagelabelinfo.cpp | 43 ++++++++++ 6 files changed, 198 insertions(+), 160 deletions(-)
New commits: commit 164805b4471256d3915c5e49fff28c9cdcbf89e6 Author: Albert Astals Cid <[email protected]> Date: Mon Feb 18 20:05:12 2013 +0100 Move the commented test to a proper one diff --git a/poppler/Makefile.am b/poppler/Makefile.am index c25ab03..86eddff 100644 --- a/poppler/Makefile.am +++ b/poppler/Makefile.am @@ -330,4 +330,5 @@ libpoppler_la_SOURCES = \ XpdfPluginAPI.cc EXTRA_DIST = gen-unicode-tables.py \ - GlobalParamsWin.cc + GlobalParamsWin.cc \ + PageLabelInfo_p.h diff --git a/poppler/PageLabelInfo.cc b/poppler/PageLabelInfo.cc index 7e1c155..467d85c 100644 --- a/poppler/PageLabelInfo.cc +++ b/poppler/PageLabelInfo.cc @@ -19,138 +19,7 @@ #include <assert.h> #include "PageLabelInfo.h" - -/* http://mathworld.wolfram.com/RomanNumerals.html */ - -static int fromRoman(const char *buffer) { - int digit_value, prev_digit_value, value; - int i; - - prev_digit_value = INT_MAX; - value = 0; - for (i = 0; buffer[i] != '\0'; i++) { - switch (buffer[i]) { - case 'm': - case 'M': - digit_value = 1000; - break; - case 'd': - case 'D': - digit_value = 500; - break; - case 'c': - case 'C': - digit_value = 100; - break; - case 'l': - case 'L': - digit_value = 50; - break; - case 'x': - case 'X': - digit_value = 10; - break; - case 'v': - case 'V': - digit_value = 5; - break; - case 'i': - case 'I': - digit_value = 1; - break; - default: - return -1; - } - - if (digit_value <= prev_digit_value) - value += digit_value; - else - value += digit_value - prev_digit_value * 2; - prev_digit_value = digit_value; - } - - return value; -} - -static void toRoman(int number, GooString *str, GBool uppercase) { - static const char uppercaseNumerals[] = "IVXLCDM"; - static const char lowercaseNumerals[] = "ivxlcdm"; - int divisor; - int i, j, k; - const char *wh; - - if (uppercase) - wh = uppercaseNumerals; - else - wh = lowercaseNumerals; - - divisor = 1000; - for (k = 3; k >= 0; k--) { - i = number / divisor; - number = number % divisor; - - switch (i) { - case 0: - break; - case 5: - str->append(wh[2 * k + 1]); - break; - case 9: - str->append(wh[2 * k + 0]); - str->append(wh[ 2 * k + 2]); - break; - case 4: - str->append(wh[2 * k + 0]); - str->append(wh[2 * k + 1]); - break; - default: - if (i > 5) { - str->append(wh[2 * k + 1]); - i -= 5; - } - for (j = 0; j < i; j++) { - str->append(wh[2 * k + 0]); - } - } - - divisor = divisor / 10; - } -} - -static int fromLatin(const char *buffer) -{ - int count; - const char *p; - - for (p = buffer; *p; p++) { - if (*p != buffer[0]) - return -1; - } - - count = p - buffer; - if (buffer[0] >= 'a' && buffer[0] <= 'z') - return 26 * (count - 1) + buffer[0] - 'a' + 1; - if (buffer[0] >= 'A' && buffer[0] <= 'Z') - return 26 * (count - 1) + buffer[0] - 'A' + 1; - - return -1; -} - -static void toLatin(int number, GooString *str, GBool uppercase) { - char base, letter; - int i, count; - - if (uppercase) - base = 'A'; - else - base = 'a'; - - count = (number - 1) / 26 + 1; - letter = base + (number - 1) % 26; - - for (i = 0; i < count; i++) - str->append(letter); -} +#include "PageLabelInfo_p.h" PageLabelInfo::Interval::Interval(Object *dict, int baseA) { Object obj; @@ -359,30 +228,3 @@ GBool PageLabelInfo::indexToLabel(int index, GooString *label) return gTrue; } - -#ifdef TEST -int main(int argc, char *argv[]) -{ - { - GooString str; - toRoman(177, &str, gFalse); - assert (str.cmp("clxxvii") == 0); - } - - { - GooString roman("clxxvii"); - assert (fromRoman(roman.getCString()) == 177); - } - - { - GooString str; - toLatin(54, &str, gFalse); - assert (str.cmp("bbb") == 0); - } - - { - GooString latin("ddd"); - assert (fromLatin(latin.getCString()) == 56); - } -} -#endif diff --git a/poppler/PageLabelInfo_p.h b/poppler/PageLabelInfo_p.h new file mode 100644 index 0000000..d3cd89f --- /dev/null +++ b/poppler/PageLabelInfo_p.h @@ -0,0 +1,147 @@ +//======================================================================== +// +// This file is under the GPLv2 or later license +// +// Copyright (C) 2005-2006 Kristian Høgsberg <[email protected]> +// Copyright (C) 2005, 2009 Albert Astals Cid <[email protected]> +// Copyright (C) 2011 Simon Kellner <[email protected]> +// Copyright (C) 2012 Fabio D'Urso <[email protected]> +// +// To see a description of the changes please see the Changelog file that +// came with your tarball or type make ChangeLog if you are building from git +// +//======================================================================== + +/* http://mathworld.wolfram.com/RomanNumerals.html */ + +#include "goo/GooString.h" + +static int fromRoman(const char *buffer) { + int digit_value, prev_digit_value, value; + int i; + + prev_digit_value = INT_MAX; + value = 0; + for (i = 0; buffer[i] != '\0'; i++) { + switch (buffer[i]) { + case 'm': + case 'M': + digit_value = 1000; + break; + case 'd': + case 'D': + digit_value = 500; + break; + case 'c': + case 'C': + digit_value = 100; + break; + case 'l': + case 'L': + digit_value = 50; + break; + case 'x': + case 'X': + digit_value = 10; + break; + case 'v': + case 'V': + digit_value = 5; + break; + case 'i': + case 'I': + digit_value = 1; + break; + default: + return -1; + } + + if (digit_value <= prev_digit_value) + value += digit_value; + else + value += digit_value - prev_digit_value * 2; + prev_digit_value = digit_value; + } + + return value; +} + +static void toRoman(int number, GooString *str, GBool uppercase) { + static const char uppercaseNumerals[] = "IVXLCDM"; + static const char lowercaseNumerals[] = "ivxlcdm"; + int divisor; + int i, j, k; + const char *wh; + + if (uppercase) + wh = uppercaseNumerals; + else + wh = lowercaseNumerals; + + divisor = 1000; + for (k = 3; k >= 0; k--) { + i = number / divisor; + number = number % divisor; + + switch (i) { + case 0: + break; + case 5: + str->append(wh[2 * k + 1]); + break; + case 9: + str->append(wh[2 * k + 0]); + str->append(wh[ 2 * k + 2]); + break; + case 4: + str->append(wh[2 * k + 0]); + str->append(wh[2 * k + 1]); + break; + default: + if (i > 5) { + str->append(wh[2 * k + 1]); + i -= 5; + } + for (j = 0; j < i; j++) { + str->append(wh[2 * k + 0]); + } + } + + divisor = divisor / 10; + } +} + +static int fromLatin(const char *buffer) +{ + int count; + const char *p; + + for (p = buffer; *p; p++) { + if (*p != buffer[0]) + return -1; + } + + count = p - buffer; + if (buffer[0] >= 'a' && buffer[0] <= 'z') + return 26 * (count - 1) + buffer[0] - 'a' + 1; + if (buffer[0] >= 'A' && buffer[0] <= 'Z') + return 26 * (count - 1) + buffer[0] - 'A' + 1; + + return -1; +} + +static void toLatin(int number, GooString *str, GBool uppercase) { + char base, letter; + int i, count; + + if (uppercase) + base = 'A'; + else + base = 'a'; + + count = (number - 1) / 26 + 1; + letter = base + (number - 1) % 26; + + for (i = 0; i < count; i++) + str->append(letter); +} diff --git a/qt4/tests/CMakeLists.txt b/qt4/tests/CMakeLists.txt index 187870f..9512617 100644 --- a/qt4/tests/CMakeLists.txt +++ b/qt4/tests/CMakeLists.txt @@ -57,6 +57,7 @@ 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) +qt4_add_qtest(check_pagelabelinfo check_pagelabelinfo.cpp) qt4_add_qtest(check_goostring check_goostring.cpp) if (NOT WIN32) qt4_add_qtest(check_strings check_strings.cpp) diff --git a/qt4/tests/Makefile.am b/qt4/tests/Makefile.am index 3dc6e13..05d2754 100644 --- a/qt4/tests/Makefile.am +++ b/qt4/tests/Makefile.am @@ -139,6 +139,10 @@ check_lexer_SOURCES = check_lexer.cpp check_lexer.$(OBJEXT): check_lexer.moc check_lexer_LDADD = $(LDADDS) $(POPPLER_QT4_TEST_LIBS) +check_pagelabelinfo_SOURCES = check_pagelabelinfo.cpp +check_pagelabelinfo.$(OBJEXT): check_pagelabelinfo.moc +check_pagelabelinfo_LDADD = $(LDADDS) $(POPPLER_QT4_TEST_LIBS) + check_goostring_SOURCES = check_goostring.cpp check_goostring.$(OBJEXT): check_goostring.moc check_goostring_LDADD = $(LDADDS) $(POPPLER_QT4_TEST_LIBS) diff --git a/qt4/tests/check_pagelabelinfo.cpp b/qt4/tests/check_pagelabelinfo.cpp new file mode 100644 index 0000000..4eb1ec3 --- /dev/null +++ b/qt4/tests/check_pagelabelinfo.cpp @@ -0,0 +1,43 @@ +#include <QtTest/QtTest> + +#include "PageLabelInfo_p.h" + +class TestPageLabelInfo : public QObject +{ + Q_OBJECT +private slots: + void testToRoman(); + void testFromRoman(); + void testToLatin(); + void testFromLatin(); +}; + +void TestPageLabelInfo::testToRoman() +{ + GooString str; + toRoman(177, &str, gFalse); + QCOMPARE (str.getCString(), "clxxvii"); +} + +void TestPageLabelInfo::testFromRoman() +{ + GooString roman("clxxvii"); + QCOMPARE(fromRoman(roman.getCString()), 177); +} + +void TestPageLabelInfo::testToLatin() +{ + GooString str; + toLatin(54, &str, gFalse); + QCOMPARE(str.getCString(), "bbb"); +} + +void TestPageLabelInfo::testFromLatin() +{ + GooString latin("ddd"); + QCOMPARE(fromLatin(latin.getCString()), 56); +} + +QTEST_MAIN(TestPageLabelInfo) +#include "check_pagelabelinfo.moc" +
_______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
