From a3ac4f26e1bc699f1e4ef15853d6db32f13d5c7f Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 12 Jul 2011 09:08:28 +0200 Subject: Add autotest for QStringLiteral MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ia5a82bf3bf489373bc0823065aa9c2990430440c Reviewed-on: http://codereview.qt.nokia.com/1486 Reviewed-by: Qt Sanity Bot Reviewed-by: João Abecasis --- tests/auto/qstring/tst_qstring.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests/auto/qstring') diff --git a/tests/auto/qstring/tst_qstring.cpp b/tests/auto/qstring/tst_qstring.cpp index abec5102b5..8c725fa109 100644 --- a/tests/auto/qstring/tst_qstring.cpp +++ b/tests/auto/qstring/tst_qstring.cpp @@ -223,6 +223,7 @@ private slots: void QTBUG9281_arg_locale(); void toUpperLower_icu(); + void literals(); }; typedef QList IntList; @@ -5107,6 +5108,31 @@ void tst_QString::toUpperLower_icu() // the cleanup function will restore the default locale } +void tst_QString::literals() +{ +#if defined(QT_QSTRING_UNICODE_MARKER) && (defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU)) + QString str(QStringLiteral("abcd")); + + QVERIFY(str.length() == 4); + QVERIFY(str == QLatin1String("abcd")); + QVERIFY(str.data_ptr()->ref == -1); + QVERIFY(str.data_ptr()->offset == 0); + + const QChar *s = str.constData(); + QString str2 = str; + QVERIFY(str2.constData() == s); + + // detach on non const access + QVERIFY(str.data() != s); + + QVERIFY(str2.constData() == s); + QVERIFY(str2.data() != s); + +#else + QSKIP("Only tested on c++0x compliant compiler or gcc", SkipAll); +#endif +} + QTEST_APPLESS_MAIN(tst_QString) -- cgit v1.2.3