summaryrefslogtreecommitdiffstats
path: root/tests/auto/qstring
diff options
context:
space:
mode:
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>2010-08-23 07:07:11 (GMT)
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2010-08-24 06:57:53 (GMT)
commit2916b0749902ee51a3deab982e53189e72c3b693 (patch)
tree6d3b905428ce0585cca8f171e0f220ec80d15919 /tests/auto/qstring
parent10e69e1d5069efa24dd70ef3fb5f9ef827ff9a4a (diff)
downloadQt-2916b0749902ee51a3deab982e53189e72c3b693.zip
Qt-2916b0749902ee51a3deab982e53189e72c3b693.tar.gz
Qt-2916b0749902ee51a3deab982e53189e72c3b693.tar.bz2
Added encoding conversion functions to QStringRef.
Reviewed-by: Olivier Goffart
Diffstat (limited to 'tests/auto/qstring')
-rw-r--r--tests/auto/qstring/tst_qstring.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/auto/qstring/tst_qstring.cpp b/tests/auto/qstring/tst_qstring.cpp
index a3f7f15..af6b371 100644
--- a/tests/auto/qstring/tst_qstring.cpp
+++ b/tests/auto/qstring/tst_qstring.cpp
@@ -174,6 +174,12 @@ private slots:
void fromLatin1Roundtrip();
void toLatin1Roundtrip_data();
void toLatin1Roundtrip();
+ void stringRef_toLatin1Roundtrip_data();
+ void stringRef_toLatin1Roundtrip();
+ void stringRef_utf8_data();
+ void stringRef_utf8();
+ void stringRef_local8Bit_data();
+ void stringRef_local8Bit();
void fromLatin1();
void fromAscii();
void arg();
@@ -3128,6 +3134,20 @@ void tst_QString::utf8()
QCOMPARE( utf8, QByteArray(res.toUtf8()) );
}
+void tst_QString::stringRef_utf8_data()
+{
+ utf8_data();
+}
+
+void tst_QString::stringRef_utf8()
+{
+ QFETCH( QByteArray, utf8 );
+ QFETCH( QString, res );
+
+ QStringRef ref(&res, 0, res.length());
+ QCOMPARE( utf8, QByteArray(ref.toUtf8()) );
+}
+
// copied to tst_QTextCodec::utf8Codec_data()
void tst_QString::fromUtf8_data()
{
@@ -3307,6 +3327,20 @@ void tst_QString::local8Bit()
QCOMPARE(local8Bit.toLocal8Bit(), QByteArray(result));
}
+void tst_QString::stringRef_local8Bit_data()
+{
+ local8Bit_data();
+}
+
+void tst_QString::stringRef_local8Bit()
+{
+ QFETCH(QString, local8Bit);
+ QFETCH(QByteArray, result);
+
+ QStringRef ref(&local8Bit, 0, local8Bit.length());
+ QCOMPARE(ref.toLocal8Bit(), QByteArray(result));
+}
+
void tst_QString::fromLatin1Roundtrip_data()
{
QTest::addColumn<QByteArray>("latin1");
@@ -3410,6 +3444,38 @@ void tst_QString::toLatin1Roundtrip()
QCOMPARE(QString::fromLatin1(latin1, latin1.length()), unicodedst);
}
+void tst_QString::stringRef_toLatin1Roundtrip_data()
+{
+ toLatin1Roundtrip_data();
+}
+
+void tst_QString::stringRef_toLatin1Roundtrip()
+{
+ QFETCH(QByteArray, latin1);
+ QFETCH(QString, unicodesrc);
+ QFETCH(QString, unicodedst);
+
+ // QtTest safety check:
+ Q_ASSERT(latin1.isNull() == unicodesrc.isNull());
+ Q_ASSERT(latin1.isEmpty() == unicodesrc.isEmpty());
+ Q_ASSERT(latin1.length() == unicodesrc.length());
+ Q_ASSERT(latin1.isNull() == unicodedst.isNull());
+ Q_ASSERT(latin1.isEmpty() == unicodedst.isEmpty());
+ Q_ASSERT(latin1.length() == unicodedst.length());
+
+ if (!latin1.isEmpty())
+ while (latin1.length() < 128) {
+ latin1 += latin1;
+ unicodesrc += unicodesrc;
+ unicodedst += unicodedst;
+ }
+
+ // toLatin1
+ QStringRef src(&unicodesrc, 0, unicodesrc.length());
+ QCOMPARE(src.toLatin1().length(), latin1.length());
+ QCOMPARE(src.toLatin1(), latin1);
+}
+
void tst_QString::fromLatin1()
{
QString a;