summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2022-05-19 10:17:32 -0700
committerEdward Welbourne <edward.welbourne@qt.io>2023-01-27 15:24:22 +0100
commit5ed684e79e71e5e11159d8df998a4576113981e0 (patch)
tree4a2f0b89290b04c469c397ae575f979ace1e72aa /tests
parent3eb6b13c0b30263c6c4d17e1b8c4e5a2cbc73b9e (diff)
QStringConverter: use the QUtf8 codec when Windows is using UTF-8
The QLocal8Bit implementation assumes that there's at most one continuation byte -- that is, that all codecs are either Single or Double Byte Character Sets (SBCS or DBCS). It appears to be the case for all Windows default codepages, except for CP_UTF8, which is an opt-in anyway. Instead of fixing our codec, let's just use the optimized UTF-8 implementation. [ChangeLog][Windows] Fixed support for using Qt applications with UTF-8 as the system codepage or by enabling that in the application's manifest. Discussed-on: https://lists.qt-project.org/pipermail/interest/2022-May/038241.html Change-Id: I77c8221eb2824c369feffffd16f0912550a98049 Reviewed-by: Lars Knoll <lars.knoll@qt.io> (cherry picked from commit 9bad4be21482d36bff76357a000e008755b60361) Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp64
1 files changed, 50 insertions, 14 deletions
diff --git a/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp b/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp
index 23d8fd429c..198fb59dfb 100644
--- a/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp
+++ b/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp
@@ -32,11 +32,52 @@
#include <qstringconverter.h>
#include <qthreadpool.h>
+#include <array>
+
+enum CodecLimitation {
+ AsciiOnly,
+ Latin1Only,
+ FullUnicode
+};
+
+#ifdef Q_OS_WIN
+# include <qt_windows.h>
+static bool localeIsUtf8()
+{
+ return GetACP() == CP_UTF8;
+}
+#else
+static constexpr bool localeIsUtf8()
+{
+ return true;
+}
+#endif
+
+struct Codec
+{
+ const char name[12];
+ QStringConverter::Encoding code;
+ CodecLimitation limitation = FullUnicode;
+};
+static const std::array codes = {
+ Codec{ "UTF-8", QStringConverter::Utf8 },
+ Codec{ "UTF-16", QStringConverter::Utf16 },
+ Codec{ "UTF-16-le", QStringConverter::Utf16LE },
+ Codec{ "UTF-16-be", QStringConverter::Utf16BE },
+ Codec{ "UTF-32", QStringConverter::Utf32 },
+ Codec{ "UTF-32-le", QStringConverter::Utf32LE },
+ Codec{ "UTF-32-be", QStringConverter::Utf32BE },
+ Codec{ "Latin-1", QStringConverter::Latin1, Latin1Only },
+ Codec{ "System", QStringConverter::System, localeIsUtf8() ? FullUnicode : AsciiOnly }
+};
+
class tst_QStringConverter : public QObject
{
Q_OBJECT
private slots:
+ void initTestCase();
+
void threadSafety();
void constructByName();
@@ -155,24 +196,11 @@ void tst_QStringConverter::roundtrip_data()
QTest::addColumn<QString>("utf16");
QTest::addColumn<QStringConverter::Encoding>("code");
- const struct {
- QStringConverter::Encoding code;
- const char *name;
- } codes[] = {
- { QStringConverter::Utf8, "UTF-8" },
- { QStringConverter::Utf16, "UTF-16" },
- { QStringConverter::Utf16LE, "UTF-16-le" },
- { QStringConverter::Utf16BE, "UTF-16-be" },
- { QStringConverter::Utf32, "UTF-32" },
- { QStringConverter::Utf32LE, "UTF-32-le" },
- { QStringConverter::Utf32BE, "UTF-32-be" },
- // Latin1, System: not guaranteed to be able to represent arbitrary Unicode.
- };
// TODO: include flag variations, too.
for (const auto code : codes) {
QTest::addRow("empty-%s", code.name) << u""_qs << code.code;
- {
+ if (code.limitation == FullUnicode) {
const char32_t zeroVal = 0x11136; // Unicode's representation of Chakma zero
const QChar data[] = {
QChar::highSurrogate(zeroVal), QChar::lowSurrogate(zeroVal),
@@ -1893,6 +1921,14 @@ public:
}
};
+void tst_QStringConverter::initTestCase()
+{
+ if (localeIsUtf8())
+ qInfo("System locale is UTF-8");
+ else
+ qInfo("System locale is not UTF-8");
+}
+
void tst_QStringConverter::threadSafety()
{
QThreadPool::globalInstance()->setMaxThreadCount(12);