[poppler] Branch 'utoa7_test' - qt5/tests

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Dec 6 17:45:00 UTC 2019


Rebased ref, commits from common ancestor:
commit 3955fe7fae320f3122f663efa1d66a5296db7e6d
Author: Nelson Benítez León <nbenitezl at gmail.com>
Date:   Fri Dec 6 18:42:49 2019 +0100

    autotest for unicodeToAscii7 crasher
    
    Includes some small code tweaks by Albert Astals Cid

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"


More information about the poppler mailing list