summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNelson Benítez León <nbenitezl@gmail.com>2020-07-09 01:36:24 -0400
committerAlbert Astals Cid <tsdgeos@yahoo.es>2020-07-10 20:54:24 +0000
commit9a880ecd7d865a12b0f91f56285907bbb409f32f (patch)
treed0a61c945a888e9388d2bc326cb213006e1714e1
parent232cba307e8be35022426ba85f34198af7406899 (diff)
Add test for UTF16LE string support
Issue #941
-rw-r--r--qt5/tests/check_utf_conversion.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/qt5/tests/check_utf_conversion.cpp b/qt5/tests/check_utf_conversion.cpp
index f28829f4..1f04c2a5 100644
--- a/qt5/tests/check_utf_conversion.cpp
+++ b/qt5/tests/check_utf_conversion.cpp
@@ -4,6 +4,7 @@
#include <poppler-private.h>
#include <cstring>
+#include <cstdint> // for uint16_t
#include "GlobalParams.h"
#include "UnicodeTypeTable.h"
@@ -18,6 +19,7 @@ private slots:
void testUTF_data();
void testUTF();
void testUnicodeToAscii7();
+ void testUnicodeLittleEndian();
};
static bool compare(const char *a, const char *b)
@@ -143,5 +145,35 @@ void TestUTFConversion::testUnicodeToAscii7()
free(out_ascii_idx);
}
+void TestUTFConversion::testUnicodeLittleEndian()
+{
+ uint16_t UTF16LE_hi[4] { 0xFFFE, 0x4800, 0x4900, 0x2100 }; // UTF16-LE "HI!"
+ GooString GooUTF16LE(reinterpret_cast<const char *>(UTF16LE_hi), 4 * 2);
+
+ uint16_t UTF16BE_hi[4] { 0xFEFF, 0x0048, 0x0049, 0x0021 }; // UTF16-BE "HI!"
+ GooString GooUTF16BE(reinterpret_cast<const char *>(UTF16BE_hi), 4 * 2);
+
+ // Let's assert both GooString's are different
+ Q_ASSERT(GooUTF16LE.cmp(&GooUTF16BE) != 0);
+
+ Unicode *UCS4fromLE, *UCS4fromBE;
+ const int len1 = TextStringToUCS4(&GooUTF16LE, &UCS4fromLE);
+ const int len2 = TextStringToUCS4(&GooUTF16BE, &UCS4fromBE);
+
+ // 3 as TextStringToUCS4() removes the two leading Byte Order Mark (BOM) code points
+ Q_ASSERT(len1 == len2);
+ Q_ASSERT(len1 == 3);
+
+ // Check that now after conversion, UCS4fromLE and UCS4fromBE are now the same
+ for (int i = 0; i < len1; i++) {
+ Q_ASSERT(UCS4fromLE[i] == UCS4fromBE[i]);
+ }
+
+ // Do some final verifications, checking the strings to be "HI!"
+ QVERIFY(*UCS4fromLE == *UCS4fromBE);
+ QVERIFY(compare(UCS4fromLE, "HI!", 3));
+ QVERIFY(compare(UCS4fromBE, "HI!", 3));
+}
+
QTEST_GUILESS_MAIN(TestUTFConversion)
#include "check_utf_conversion.moc"