summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2013-02-26 12:41:59 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-02-27 03:13:30 +0100
commit996db96d5eb4927a130605e8c1820d7e1b303191 (patch)
tree894ce9fb99955ba2f607b1d7e11bd371c465a860 /tests/auto
parent7729d89e15bc68899554b28f480a891c61ef0872 (diff)
Fix QString::toUcs4() returns incorrectly resized QVector
...when the string contains surrogate code points. Task-number: QTBUG-25536 Change-Id: I07251fee641c14f33175678768ddbe551dbe2bb1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/tools/qstring/tst_qstring.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
index c902d421ed..aa61885a47 100644
--- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
@@ -195,6 +195,8 @@ private slots:
void stringRef_local8Bit();
void fromLatin1();
void fromAscii();
+ void fromUcs4();
+ void toUcs4();
void arg();
void number();
void arg_fillChar_data();
@@ -3931,6 +3933,52 @@ void tst_QString::fromAscii()
QVERIFY(a.size() == 5);
}
+void tst_QString::fromUcs4()
+{
+ QString s;
+ s = QString::fromUcs4( 0 );
+ QVERIFY( s.isNull() );
+ QCOMPARE( s.size(), 0 );
+ s = QString::fromUcs4( 0, 0 );
+ QVERIFY( s.isNull() );
+ QCOMPARE( s.size(), 0 );
+ s = QString::fromUcs4( 0, 5 );
+ QVERIFY( s.isNull() );
+ QCOMPARE( s.size(), 0 );
+
+ uint nil = '\0';
+ s = QString::fromUcs4( &nil );
+ QVERIFY( !s.isNull() );
+ QCOMPARE( s.size(), 0 );
+ s = QString::fromUcs4( &nil, 0 );
+ QVERIFY( !s.isNull() );
+ QCOMPARE( s.size(), 0 );
+
+ uint bmp = 'a';
+ s = QString::fromUcs4( &bmp, 1 );
+ QVERIFY( !s.isNull() );
+ QCOMPARE( s.size(), 1 );
+
+ uint smp = 0x10000;
+ s = QString::fromUcs4( &smp, 1 );
+ QVERIFY( !s.isNull() );
+ QCOMPARE( s.size(), 2 );
+}
+
+void tst_QString::toUcs4()
+{
+ QString s;
+ QCOMPARE( s.toUcs4().size(), 0 );
+
+ QChar bmp = QLatin1Char('a');
+ s = QString(&bmp, 1);
+ QCOMPARE( s.toUcs4().size(), 1 );
+
+ QChar smp[] = { QChar::highSurrogate(0x10000), QChar::lowSurrogate(0x10000) };
+ s = QString(smp, 2);
+ QCOMPARE( s.toUcs4().size(), 1 );
+}
+
void tst_QString::arg()
{
/*