aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/qutil.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2019-01-13 15:41:13 +0100
committerJay Berkenbilt <ejb@ql.org>2019-01-17 17:43:56 +0100
commit8f389f14c0584861c712c049bdba3ed0d9036506 (patch)
treef7f85a3f7f5ba29e16238f589724a60d1b59728f /libtests/qutil.cc
parent6817ca585a44eec2c50961ba7c714b419774da36 (diff)
downloadqpdf-8f389f14c0584861c712c049bdba3ed0d9036506.tar.zst
QUtil::analyze_encoding
Diffstat (limited to 'libtests/qutil.cc')
-rw-r--r--libtests/qutil.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/libtests/qutil.cc b/libtests/qutil.cc
index 355bb9a2..91a656be 100644
--- a/libtests/qutil.cc
+++ b/libtests/qutil.cc
@@ -262,6 +262,20 @@ void transcoding_test(std::string (*to_utf8)(std::string const&),
}
}
+void check_analyze(std::string const& str, bool has8bit, bool utf8, bool utf16)
+{
+ bool has_8bit_chars = false;
+ bool is_valid_utf8 = false;
+ bool is_utf16 = false;
+ QUtil::analyze_encoding(str, has_8bit_chars, is_valid_utf8, is_utf16);
+ if (! ((has_8bit_chars == has8bit) &&
+ (is_valid_utf8 == utf8) &&
+ (is_utf16 == utf16)))
+ {
+ std::cout << "analysis failed: " << str << std::endl;
+ }
+}
+
void transcoding_test()
{
transcoding_test(&QUtil::pdf_doc_to_utf8,
@@ -273,6 +287,11 @@ void transcoding_test()
transcoding_test(&QUtil::mac_roman_to_utf8,
&QUtil::utf8_to_mac_roman, 255, "?");
std::cout << "bidirectional mac roman done" << std::endl;
+ check_analyze("pi = \317\200", true, true, false);
+ check_analyze("pi != \317", true, false, false);
+ check_analyze("pi != 22/7", false, false, false);
+ check_analyze(std::string("\xfe\xff\00\x51", 4), true, false, true);
+ std::cout << "analysis done" << std::endl;
}
void print_whoami(char const* str)