diff options
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r-- | tests/auto/corelib/tools/qstring/qstring.pro | 1 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qstring/tst_qstring.cpp | 23 |
2 files changed, 24 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qstring/qstring.pro b/tests/auto/corelib/tools/qstring/qstring.pro index 971e2fb782..1eda27e1ff 100644 --- a/tests/auto/corelib/tools/qstring/qstring.pro +++ b/tests/auto/corelib/tools/qstring/qstring.pro @@ -4,6 +4,7 @@ QT = core testlib SOURCES = tst_qstring.cpp DEFINES += QT_NO_CAST_TO_ASCII contains(QT_CONFIG,icu):DEFINES += QT_USE_ICU +contains(QT_CONFIG,c++11): CONFIG += c++11 DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 mac { diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 875bf6571a..b0f0b24a67 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -59,6 +59,7 @@ #include <locale.h> #include <qhash.h> +#include <string> #define CREATE_REF(string) \ const QString padded = QString::fromLatin1(" %1 ").arg(string); \ @@ -263,6 +264,7 @@ private slots: void assignQLatin1String(); void isRightToLeft_data(); void isRightToLeft(); + void unicodeStrings(); }; template <class T> const T &verifyZeroTermination(const T &t) { return t; } @@ -5222,6 +5224,27 @@ void tst_QString::fromUtf16_char16() #endif } +void tst_QString::unicodeStrings() +{ +#ifdef Q_COMPILER_UNICODE_STRINGS + QString s1, s2; + static const std::u16string u16str1(u"Hello Unicode World"); + static const std::u32string u32str1(U"Hello Unicode World"); + s1 = QString::fromStdU16String(u16str1); + s2 = QString::fromStdU32String(u32str1); + QCOMPARE(s1, QString("Hello Unicode World")); + QCOMPARE(s1, s2); + + QCOMPARE(s2.toStdU16String(), u16str1); + QCOMPARE(s1.toStdU32String(), u32str1); + + s1 = QString::fromStdU32String(std::u32string(U"\u221212\U000020AC\U00010000")); + QCOMPARE(s1, QString::fromUtf8("\342\210\222" "12" "\342\202\254" "\360\220\200\200")); +#else + QSKIP("Compiler does not support C++11 unicode strings"); +#endif +} + void tst_QString::latin1String() { QString s("Hello"); |