summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorRobin Burchell <robin+qt@viroteck.net>2012-01-30 14:23:22 +0200
committerQt by Nokia <qt-info@nokia.com>2012-02-22 14:00:32 +0100
commit186692f81f2612c3cf3a4090cbf949f2fb1558f8 (patch)
treee4506e520a88a1c75086516a1edeb1ab2fb4d057 /tests/auto/corelib
parent9d173c92183c30144e8bd4f115b2cd93c3da0d40 (diff)
Remove custom text codec for C strings.
This setting is extremely harmful, as code cannot know whether or not to expect it. It also made the behaviour of QString::fromAscii and ::toAscii unintuitive, and caused a lot of people to make mistakes with it. Change-Id: I2f429fa7ef93bd75bb93a7f64c56db15b7283388 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/tools/qstring/tst_qstring.cpp18
-rw-r--r--tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp16
2 files changed, 14 insertions, 20 deletions
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
index 3fb253c646..7e4f591f47 100644
--- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
@@ -808,10 +808,7 @@ void tst_QString::constructorQByteArray()
QCOMPARE(str1.length(), expected.length());
QCOMPARE( str1, expected );
- QTextCodec::setCodecForCStrings( QTextCodec::codecForMib(4) ); // Latin 1
QString strBA(src);
- QTextCodec::setCodecForCStrings( 0 );
-
QCOMPARE( strBA, expected );
}
@@ -928,12 +925,7 @@ void tst_QString::sprintf()
QCOMPARE(a.sprintf("%-5.5s", "Hello" ),(QString)"Hello");
// Check utf8 conversion for %s
- QCOMPARE(a.sprintf("%s", "\303\266\303\244\303\274\303\226\303\204\303\234\303\270\303\246\303\245\303\230\303\206\303\205"), QString("\366\344\374\326\304\334\370\346\345\330\306\305"));
-
- // Check codecForCStrings is used to read non-modifier sequences in the format string
- QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
- QCOMPARE(a.sprintf("\303\251\303\250\303\240 %s", "\303\251\303\250\303\240"), QString("\303\251\303\250\303\240 \303\251\303\250\303\240"));
- QTextCodec::setCodecForCStrings(0);
+ QCOMPARE(a.sprintf("%s", "\303\266\303\244\303\274\303\226\303\204\303\234\303\270\303\246\303\245\303\230\303\206\303\205"), QString::fromLatin1("\366\344\374\326\304\334\370\346\345\330\306\305"));
int n1;
a.sprintf("%s%n%s", "hello", &n1, "goodbye");
@@ -1871,9 +1863,7 @@ void tst_QString::append_bytearray()
QFETCH( QString, str );
QFETCH( QByteArray, ba );
- QTextCodec::setCodecForCStrings( QTextCodec::codecForMib(4) ); // Latin 1
str.append( ba );
- QTextCodec::setCodecForCStrings( 0 );
QTEST( str, "res" );
}
@@ -1898,9 +1888,7 @@ void tst_QString::operator_pluseq_bytearray()
QFETCH( QString, str );
QFETCH( QByteArray, ba );
- QTextCodec::setCodecForCStrings( QTextCodec::codecForMib(4) ); // Latin 1
str += ba;
- QTextCodec::setCodecForCStrings( 0 );
QTEST( str, "res" );
}
@@ -1960,9 +1948,7 @@ void tst_QString::prepend_bytearray()
QFETCH( QString, str );
QFETCH( QByteArray, ba );
- QTextCodec::setCodecForCStrings( QTextCodec::codecForMib(4) ); // Latin 1
str.prepend( ba );
- QTextCodec::setCodecForCStrings( 0 );
QTEST( str, "res" );
}
@@ -3211,7 +3197,7 @@ void tst_QString::utf8()
QFETCH( QByteArray, utf8 );
QFETCH( QString, res );
- QCOMPARE( utf8, QByteArray(res.toUtf8()) );
+ QCOMPARE(res.toUtf8(), utf8);
}
void tst_QString::stringRef_utf8_data()
diff --git a/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp b/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp
index 95e24b22fb..afc16078b8 100644
--- a/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp
+++ b/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp
@@ -66,10 +66,8 @@
void runScenario()
{
- // set codec for C strings to 0, enforcing Latin1
- QTextCodec::setCodecForCStrings(0);
- QVERIFY(!QTextCodec::codecForCStrings());
-
+ // this code is latin1. TODO: replace it with the utf8 block below, once
+ // strings default to utf8.
QLatin1Literal l1literal(LITERAL);
QLatin1String l1string(LITERAL);
QString string(l1string);
@@ -130,7 +128,10 @@ void runScenario()
r = string P ba;
QCOMPARE(r, r2);
+#if 0
// now test with codec for C strings set
+ // TODO: to be re-enabled once strings default to utf8, in place of the
+ // latin1 code above.
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
QVERIFY(QTextCodec::codecForCStrings());
QCOMPARE(QTextCodec::codecForCStrings()->name(), QByteArray("UTF-8"));
@@ -153,6 +154,7 @@ void runScenario()
QCOMPARE(r, r3);
r = string P ba;
QCOMPARE(r, r3);
+#endif
ba = QByteArray(); // empty
r = ba P string;
@@ -212,9 +214,12 @@ void runScenario()
str += QLatin1String(LITERAL) P str;
QCOMPARE(str, QString::fromUtf8(UTF8_LITERAL LITERAL UTF8_LITERAL));
#ifndef QT_NO_CAST_FROM_ASCII
+#if 0
+ // TODO: this relies on strings defaulting to utf8, so disable this for now.
str = (QString::fromUtf8(UTF8_LITERAL) += QLatin1String(LITERAL) P UTF8_LITERAL);
QCOMPARE(str, QString::fromUtf8(UTF8_LITERAL LITERAL UTF8_LITERAL));
#endif
+#endif
}
//operator QByteArray +=
@@ -229,11 +234,14 @@ void runScenario()
ba2 += ba2 P withZero;
QCOMPARE(ba2, QByteArray(withZero + withZero + withZero));
#ifndef QT_NO_CAST_TO_ASCII
+#if 0
+ // TODO: this relies on strings defaulting to utf8, so disable this for now.
ba = UTF8_LITERAL;
ba2 = (ba += QLatin1String(LITERAL) + QString::fromUtf8(UTF8_LITERAL));
QCOMPARE(ba2, ba);
QCOMPARE(ba, QByteArray(UTF8_LITERAL LITERAL UTF8_LITERAL));
#endif
+#endif
}
}