summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-01-14 15:39:36 +0100
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-01-24 11:50:13 +0100
commitdd07b1e38927d47802087c75c365f13d13a04248 (patch)
treedbb2116dfde06fbf22eea7e4f55c42b0f77e3b2d /tests/auto/corelib
parent05cda3d46514822ab6748514ee8fb658e60fdc0b (diff)
Add conversion functions for C++11 u16string and u32string
The patch adds convenience functions for working on C++11's new char width specific unicode strings u16string and u32string. [ChangeLog][QtCore][QString] Added methods for convenient conversion to and from std::u16string and std::u32string. Change-Id: I67c082e4755c592d61daaaaa70c8867ef0b23dcb Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/tools/qstring/qstring.pro1
-rw-r--r--tests/auto/corelib/tools/qstring/tst_qstring.cpp23
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");