diff options
author | Nelson Benítez León <nbenitezl@gmail.com> | 2019-12-06 18:42:49 +0100 |
---|---|---|
committer | Albert Astals Cid <aacid@kde.org> | 2019-12-06 18:44:48 +0100 |
commit | 3955fe7fae320f3122f663efa1d66a5296db7e6d (patch) | |
tree | 8702103ce4fd89b75861be4a1f6bf75aa157af17 | |
parent | f7414ccb517fcadf8b0d8732d40c4abfb74cccba (diff) |
autotest for unicodeToAscii7 crasher
Includes some small code tweaks by Albert Astals Cid
-rw-r--r-- | qt5/tests/check_utf_conversion.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/qt5/tests/check_utf_conversion.cpp b/qt5/tests/check_utf_conversion.cpp index d451ac46..23ea4c0b 100644 --- a/qt5/tests/check_utf_conversion.cpp +++ b/qt5/tests/check_utf_conversion.cpp @@ -1,7 +1,12 @@ #include <QtCore/QScopedPointer> #include <QtTest/QtTest> +#include <poppler-private.h> + #include <cstring> + +#include "GlobalParams.h" +#include "UnicodeTypeTable.h" #include "UTF.h" class TestUTFConversion : public QObject @@ -12,6 +17,7 @@ public: private slots: void testUTF_data(); void testUTF(); + void testUnicodeToAscii7(); }; static bool compare(const char *a, const char *b) @@ -28,6 +34,16 @@ static bool compare(const uint16_t *a, const uint16_t *b) return *a == *b; } +static bool compare(const Unicode *a, const char *b, int len) +{ + for (int i = 0; i < len; i++) { + if (a[i] != (Unicode) b[i]) + return false; + } + + return *a == (Unicode) *b; +} + void TestUTFConversion::testUTF_data() { QTest::addColumn<QString>("s"); @@ -88,5 +104,44 @@ void TestUTFConversion::testUTF() free(str); } +void TestUTFConversion::testUnicodeToAscii7() +{ + globalParams = std::make_unique<GlobalParams>(); + + // Test string is one 'Registered' and twenty 'Copyright' chars + // so it's long enough to reproduce the bug given that glibc + // malloc() always returns 8-byte aligned memory addresses. + GooString *goo = Poppler::QStringToUnicodeGooString(QString::fromUtf8("®©©©©©©©©©©©©©©©©©©©©")); //clazy:exclude=qstring-allocations + + Unicode *in; + const int in_len = TextStringToUCS4(goo, &in); + + delete goo; + + int in_norm_len; + int *in_norm_idx; + Unicode *in_norm = unicodeNormalizeNFKC(in, in_len, &in_norm_len, &in_norm_idx, true); + + free(in); + + Unicode *out; + int out_len; + int *out_ascii_idx; + + unicodeToAscii7(in_norm, in_norm_len, &out, &out_len, in_norm_idx, &out_ascii_idx); + + free(in_norm); + free(in_norm_idx); + + //ascii7 conversion: ® -> (R) © -> (c) + const char *expected_ascii = (char*) "(R)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)(c)"; + + QCOMPARE(out_len, (int)strlen(expected_ascii) ); + QVERIFY( compare(out, expected_ascii, out_len) ); + + free(out); + free(out_ascii_idx); +} + QTEST_GUILESS_MAIN(TestUTFConversion) #include "check_utf_conversion.moc" |