summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/qdate/tst_qdate.cpp97
-rw-r--r--tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp63
-rw-r--r--tests/auto/corelib/tools/qlocale/tst_qlocale.cpp18
-rw-r--r--tests/auto/corelib/tools/qstring/tst_qstring.cpp76
-rw-r--r--tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp10
-rw-r--r--tests/auto/corelib/tools/qtime/tst_qtime.cpp11
-rw-r--r--tests/auto/corelib/tools/qvector/tst_qvector.cpp117
7 files changed, 273 insertions, 119 deletions
diff --git a/tests/auto/corelib/tools/qdate/tst_qdate.cpp b/tests/auto/corelib/tools/qdate/tst_qdate.cpp
index 04393cebcb..01805e1271 100644
--- a/tests/auto/corelib/tools/qdate/tst_qdate.cpp
+++ b/tests/auto/corelib/tools/qdate/tst_qdate.cpp
@@ -59,6 +59,7 @@ private slots:
void dayOfYear();
void daysInMonth_data();
void daysInMonth();
+ void daysInYear_data();
void daysInYear();
void getDate();
void weekNumber_invalid_data();
@@ -342,6 +343,7 @@ void tst_QDate::daysInMonth_data()
QTest::newRow("data11") << 2000 << 11 << 1 << 30;
QTest::newRow("data12") << 2000 << 12 << 1 << 31;
QTest::newRow("data13") << 2001 << 2 << 1 << 28;
+ QTest::newRow("data14") << 2000 << 0 << 1 << 0;
}
void tst_QDate::daysInMonth()
@@ -355,16 +357,24 @@ void tst_QDate::daysInMonth()
QCOMPARE(dt.daysInMonth(), daysInMonth);
}
+void tst_QDate::daysInYear_data()
+{
+ QTest::addColumn<QDate>("date");
+ QTest::addColumn<int>("expectedDaysInYear");
+
+ QTest::newRow("2000, 1, 1") << QDate(2000, 1, 1) << 366;
+ QTest::newRow("2001, 1, 1") << QDate(2001, 1, 1) << 365;
+ QTest::newRow("4, 1, 1") << QDate(4, 1, 1) << 366;
+ QTest::newRow("5, 1, 1") << QDate(5, 1, 1) << 365;
+ QTest::newRow("0, 0, 0") << QDate(0, 0, 0) << 0;
+}
+
void tst_QDate::daysInYear()
{
- QDate dt(2000, 1, 1);
- QCOMPARE(dt.daysInYear(), 366);
- dt.setDate(2001, 1, 1);
- QCOMPARE(dt.daysInYear(), 365);
- dt.setDate(4, 1, 1);
- QCOMPARE(dt.daysInYear(), 366);
- dt.setDate(5, 1, 1);
- QCOMPARE(dt.daysInYear(), 365);
+ QFETCH(QDate, date);
+ QFETCH(int, expectedDaysInYear);
+
+ QCOMPARE(date.daysInYear(), expectedDaysInYear);
}
void tst_QDate::getDate()
@@ -399,6 +409,7 @@ void tst_QDate::weekNumber_data()
QTest::newRow( "data5" ) << 53 << 1998 << 1998 << 12 << 31;
QTest::newRow( "data6" ) << 1 << 1985 << 1984 << 12 << 31;
QTest::newRow( "data7" ) << 52 << 2006 << 2006 << 12 << 31;
+ QTest::newRow( "data8" ) << 53 << 2004 << 2005 << 1 << 1;
}
void tst_QDate::weekNumber()
@@ -539,6 +550,8 @@ void tst_QDate::addDays_data()
QTest::newRow( "data12" ) << -4713 << 1 << 2 << -2 << -4714 << 12 << 31;
QTest::newRow( "data13" ) << -4713 << 1 << 2 << 2 << -4713 << 1 << 4;
+
+ QTest::newRow( "invalid" ) << 0 << 0 << 0 << 1 << 0 << 0 << 0;
}
void tst_QDate::addMonths()
@@ -591,6 +604,9 @@ void tst_QDate::addMonths_data()
QTest::newRow( "data16" ) << 1 << 1 << 1 << -12 << -1 << 1 << 1;
QTest::newRow( "data17" ) << -1 << 12 << 1 << 1 << 1 << 1 << 1;
QTest::newRow( "data18" ) << -1 << 1 << 1 << 12 << 1 << 1 << 1;
+ QTest::newRow( "data19" ) << -2 << 1 << 1 << 12 << -1 << 1 << 1;
+
+ QTest::newRow( "invalid" ) << 0 << 0 << 0 << 1 << 0 << 0 << 0;
}
void tst_QDate::addYears()
@@ -642,6 +658,8 @@ void tst_QDate::addYears_data()
QTest::newRow( "data17" ) << -2000 << 1 << 1 << 1999 << -1 << 1 << 1;
QTest::newRow( "data18" ) << -2000 << 1 << 1 << 2000 << 1 << 1 << 1;
QTest::newRow( "data19" ) << -2000 << 1 << 1 << 2001 << 2 << 1 << 1;
+
+ QTest::newRow( "invalid" ) << 0 << 0 << 0 << 1 << 0 << 0 << 0;
}
void tst_QDate::daysTo()
@@ -903,36 +921,39 @@ void tst_QDate::operator_insert_extract()
void tst_QDate::fromStringDateFormat_data()
{
- // Since we can't define an element of Qt::DateFormat, d1 will be the date
- // expected when we have a TextDate, and d2 will be the date expected when
- // we have an ISODate.
-
- QTest::addColumn<QString>("str1");
- QTest::addColumn<QString>("str2");
- QTest::addColumn<QDate>("d1");
-
- QTest::newRow( "data0" ) << QString("Sat May 20 1995") << QString("1995-05-20") << QDate(1995,5,20);
- QTest::newRow( "data1" ) << QString("Tue Dec 17 2002") << QString("2002-12-17") << QDate(2002,12,17);
- QDate d( 1999, 11, 14 );
- QTest::newRow( "data2" ) << d.toString( Qt::TextDate ) << d.toString( Qt::ISODate ) << d;
-
- QTest::newRow( "data3" ) << QString("xxx Jan 1 0999") << QString("0999-01-01") << QDate(999, 1, 1);
- QTest::newRow( "data3b" ) << QString("xxx Jan 1 999") << QString("0999-01-01") << QDate(999, 1, 1);
- QTest::newRow( "data4" ) << QString("xxx Jan 1 12345") << QString() << QDate(12345, 1, 1);
- QTest::newRow( "data5" ) << QString("xxx Jan 1 -0001") << QString() << QDate(-1, 1, 1);
- QTest::newRow( "data6" ) << QString("xxx Jan 1 -4712") << QString() << QDate(-4712, 1, 1);
- QTest::newRow( "data7" ) << QString("xxx Nov 25 -4713") << QString() << QDate(-4713, 11, 25);
+ QTest::addColumn<QString>("dateStr");
+ QTest::addColumn<Qt::DateFormat>("dateFormat");
+ QTest::addColumn<QDate>("expectedDate");
+
+ QTest::newRow("text0") << QString("Sat May 20 1995") << Qt::TextDate << QDate(1995, 5, 20);
+ QTest::newRow("text1") << QString("Tue Dec 17 2002") << Qt::TextDate << QDate(2002, 12, 17);
+ QTest::newRow("text2") << QDate(1999, 11, 14).toString(Qt::TextDate) << Qt::TextDate << QDate(1999, 11, 14);
+ QTest::newRow("text3") << QString("xxx Jan 1 0999") << Qt::TextDate << QDate(999, 1, 1);
+ QTest::newRow("text3b") << QString("xxx Jan 1 999") << Qt::TextDate << QDate(999, 1, 1);
+ QTest::newRow("text4") << QString("xxx Jan 1 12345") << Qt::TextDate << QDate(12345, 1, 1);
+ QTest::newRow("text5") << QString("xxx Jan 1 -0001") << Qt::TextDate << QDate(-1, 1, 1);
+ QTest::newRow("text6") << QString("xxx Jan 1 -4712") << Qt::TextDate << QDate(-4712, 1, 1);
+ QTest::newRow("text7") << QString("xxx Nov 25 -4713") << Qt::TextDate << QDate(-4713, 11, 25);
+ QTest::newRow("text, empty") << QString() << Qt::TextDate << QDate();
+ QTest::newRow("text, 3 part") << QString("part1 part2 part3") << Qt::TextDate << QDate();
+ QTest::newRow("text, invalid month name") << QString("Wed BabytownFrolics 8 2012") << Qt::TextDate << QDate();
+ QTest::newRow("text, invalid day") << QString("Wed May Wilhelm 2012") << Qt::TextDate << QDate();
+ QTest::newRow("text, invalid year") << QString("Wed May 8 Cats") << Qt::TextDate << QDate();
+
+ QTest::newRow("iso0") << QString("1995-05-20") << Qt::ISODate << QDate(1995, 5, 20);
+ QTest::newRow("iso1") << QString("2002-12-17") << Qt::ISODate << QDate(2002, 12, 17);
+ QTest::newRow("iso2") << QDate(1999, 11, 14).toString(Qt::ISODate) << Qt::ISODate << QDate(1999, 11, 14);
+ QTest::newRow("iso3") << QString("0999-01-01") << Qt::ISODate << QDate(999, 1, 1);
+ QTest::newRow("iso3b") << QString("0999-01-01") << Qt::ISODate << QDate(999, 1, 1);
}
void tst_QDate::fromStringDateFormat()
{
- QFETCH( QString, str1 );
- QFETCH( QString, str2 );
- QFETCH( QDate, d1 );
+ QFETCH(QString, dateStr);
+ QFETCH(Qt::DateFormat, dateFormat);
+ QFETCH(QDate, expectedDate);
- QCOMPARE( QDate::fromString( str1, Qt::TextDate ), d1 );
- if (!str2.isEmpty())
- QCOMPARE( QDate::fromString( str2, Qt::ISODate ), d1 );
+ QCOMPARE(QDate::fromString(dateStr, dateFormat), expectedDate);
}
void tst_QDate::fromStringFormat_data()
@@ -1050,6 +1071,8 @@ void tst_QDate::toStringDateFormat_data()
QTest::newRow("data1") << QDate(11,1,1) << Qt::ISODate << QString("0011-01-01");
QTest::newRow("data2") << QDate(111,1,1) << Qt::ISODate << QString("0111-01-01");
QTest::newRow("data3") << QDate(1974,12,1) << Qt::ISODate << QString("1974-12-01");
+ QTest::newRow("year < 0") << QDate(-1,1,1) << Qt::ISODate << QString();
+ QTest::newRow("year > 9999") << QDate(-1,1,1) << Qt::ISODate << QString();
}
void tst_QDate::toStringDateFormat()
@@ -1202,6 +1225,7 @@ void tst_QDate::roundtripGermanLocale() const
void tst_QDate::shortDayName() const
{
QCOMPARE(QDate::shortDayName(0), QString());
+ QCOMPARE(QDate::shortDayName(8), QString());
if (QLocale::system().language() == QLocale::C) {
QCOMPARE(QDate::shortDayName(1), QLatin1String("Mon"));
@@ -1217,6 +1241,7 @@ void tst_QDate::shortDayName() const
void tst_QDate::standaloneShortDayName() const
{
QCOMPARE(QDate::shortDayName(0, QDate::StandaloneFormat), QString());
+ QCOMPARE(QDate::shortDayName(8, QDate::StandaloneFormat), QString());
if (QLocale::system().language() == QLocale::C) {
QCOMPARE(QDate::shortDayName(1, QDate::StandaloneFormat), QLatin1String("Mon"));
@@ -1232,6 +1257,7 @@ void tst_QDate::standaloneShortDayName() const
void tst_QDate::longDayName() const
{
QCOMPARE(QDate::longDayName(0), QString());
+ QCOMPARE(QDate::longDayName(8), QString());
if (QLocale::system().language() == QLocale::C) {
QCOMPARE(QDate::longDayName(1), QLatin1String("Monday"));
@@ -1247,6 +1273,7 @@ void tst_QDate::longDayName() const
void tst_QDate::standaloneLongDayName() const
{
QCOMPARE(QDate::longDayName(0, QDate::StandaloneFormat), QString());
+ QCOMPARE(QDate::longDayName(8, QDate::StandaloneFormat), QString());
if (QLocale::system().language() == QLocale::C) {
QCOMPARE(QDate::longDayName(1, QDate::StandaloneFormat), QLatin1String("Monday"));
@@ -1262,6 +1289,7 @@ void tst_QDate::standaloneLongDayName() const
void tst_QDate::shortMonthName() const
{
QCOMPARE(QDate::shortMonthName(0), QString());
+ QCOMPARE(QDate::shortMonthName(13), QString());
if (QLocale::system().language() == QLocale::C) {
QCOMPARE(QDate::shortMonthName(1), QLatin1String("Jan"));
@@ -1277,6 +1305,7 @@ void tst_QDate::shortMonthName() const
void tst_QDate::standaloneShortMonthName() const
{
QCOMPARE(QDate::shortMonthName(0, QDate::StandaloneFormat), QString());
+ QCOMPARE(QDate::shortMonthName(13, QDate::StandaloneFormat), QString());
if (QLocale::system().language() == QLocale::C) {
QCOMPARE(QDate::shortMonthName(1, QDate::StandaloneFormat), QLatin1String("Jan"));
@@ -1292,6 +1321,7 @@ void tst_QDate::standaloneShortMonthName() const
void tst_QDate::longMonthName() const
{
QCOMPARE(QDate::longMonthName(0), QString());
+ QCOMPARE(QDate::longMonthName(13), QString());
if (QLocale::system().language() == QLocale::C) {
QCOMPARE(QDate::longMonthName(1), QLatin1String("January"));
@@ -1307,6 +1337,7 @@ void tst_QDate::longMonthName() const
void tst_QDate::standaloneLongMonthName() const
{
QCOMPARE(QDate::longMonthName(0, QDate::StandaloneFormat), QString());
+ QCOMPARE(QDate::longMonthName(13, QDate::StandaloneFormat), QString());
if (QLocale::system().language() == QLocale::C) {
QCOMPARE(QDate::longMonthName(1, QDate::StandaloneFormat), QLatin1String("January"));
diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
index 0189306a1b..9e71a32f87 100644
--- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
@@ -728,6 +728,8 @@ void tst_QDateTime::addSecs_data()
QTest::newRow("toPositive") << QDateTime(QDate(-1, 12, 31), QTime(23, 59, 59), Qt::UTC)
<< 1
<< QDateTime(QDate(1, 1, 1), QTime(0, 0, 0), Qt::UTC);
+
+ QTest::newRow("invalid") << invalidDateTime() << 1 << invalidDateTime();
}
void tst_QDateTime::addSecs()
@@ -915,17 +917,22 @@ void tst_QDateTime::secsTo()
QFETCH(int, nsecs);
QFETCH(QDateTime, result);
-#ifdef Q_OS_IRIX
- QEXPECT_FAIL("cet4", "IRIX databases say 1970 had DST", Abort);
-#endif
- QCOMPARE(dt.secsTo(result), (qint64)nsecs);
- QCOMPARE(result.secsTo(dt), (qint64)-nsecs);
- QVERIFY((dt == result) == (0 == nsecs));
- QVERIFY((dt != result) == (0 != nsecs));
- QVERIFY((dt < result) == (0 < nsecs));
- QVERIFY((dt <= result) == (0 <= nsecs));
- QVERIFY((dt > result) == (0 > nsecs));
- QVERIFY((dt >= result) == (0 >= nsecs));
+ if (dt.isValid()) {
+ #ifdef Q_OS_IRIX
+ QEXPECT_FAIL("cet4", "IRIX databases say 1970 had DST", Abort);
+ #endif
+ QCOMPARE(dt.secsTo(result), (qint64)nsecs);
+ QCOMPARE(result.secsTo(dt), (qint64)-nsecs);
+ QVERIFY((dt == result) == (0 == nsecs));
+ QVERIFY((dt != result) == (0 != nsecs));
+ QVERIFY((dt < result) == (0 < nsecs));
+ QVERIFY((dt <= result) == (0 <= nsecs));
+ QVERIFY((dt > result) == (0 > nsecs));
+ QVERIFY((dt >= result) == (0 >= nsecs));
+ } else {
+ QVERIFY(dt.secsTo(result) == 0);
+ QVERIFY(result.secsTo(dt) == 0);
+ }
}
void tst_QDateTime::msecsTo_data()
@@ -939,17 +946,22 @@ void tst_QDateTime::msecsTo()
QFETCH(int, nsecs);
QFETCH(QDateTime, result);
-#ifdef Q_OS_IRIX
- QEXPECT_FAIL("cet4", "IRIX databases say 1970 had DST", Abort);
-#endif
- QCOMPARE(dt.msecsTo(result), qint64(nsecs) * 1000);
- QCOMPARE(result.msecsTo(dt), -qint64(nsecs) * 1000);
- QVERIFY((dt == result) == (0 == (qint64(nsecs) * 1000)));
- QVERIFY((dt != result) == (0 != (qint64(nsecs) * 1000)));
- QVERIFY((dt < result) == (0 < (qint64(nsecs) * 1000)));
- QVERIFY((dt <= result) == (0 <= (qint64(nsecs) * 1000)));
- QVERIFY((dt > result) == (0 > (qint64(nsecs) * 1000)));
- QVERIFY((dt >= result) == (0 >= (qint64(nsecs) * 1000)));
+ if (dt.isValid()) {
+ #ifdef Q_OS_IRIX
+ QEXPECT_FAIL("cet4", "IRIX databases say 1970 had DST", Abort);
+ #endif
+ QCOMPARE(dt.msecsTo(result), qint64(nsecs) * 1000);
+ QCOMPARE(result.msecsTo(dt), -qint64(nsecs) * 1000);
+ QVERIFY((dt == result) == (0 == (qint64(nsecs) * 1000)));
+ QVERIFY((dt != result) == (0 != (qint64(nsecs) * 1000)));
+ QVERIFY((dt < result) == (0 < (qint64(nsecs) * 1000)));
+ QVERIFY((dt <= result) == (0 <= (qint64(nsecs) * 1000)));
+ QVERIFY((dt > result) == (0 > (qint64(nsecs) * 1000)));
+ QVERIFY((dt >= result) == (0 >= (qint64(nsecs) * 1000)));
+ } else {
+ QVERIFY(dt.msecsTo(result) == 0);
+ QVERIFY(result.msecsTo(dt) == 0);
+ }
}
void tst_QDateTime::currentDateTime()
@@ -1579,6 +1591,13 @@ void tst_QDateTime::fromStringToStringLocale()
QCOMPARE(QDateTime::fromString(dateTime.toString(Qt::SystemLocaleDate), Qt::SystemLocaleDate), dateTime);
QCOMPARE(QDateTime::fromString(dateTime.toString(Qt::LocaleDate), Qt::LocaleDate), dateTime);
+ QEXPECT_FAIL("data0", "This format is apparently failing because of a bug in the datetime parser. (QTBUG-22833)", Continue);
+ QCOMPARE(QDateTime::fromString(dateTime.toString(Qt::DefaultLocaleLongDate), Qt::DefaultLocaleLongDate), dateTime);
+#ifndef Q_OS_WIN
+ QEXPECT_FAIL("data0", "This format is apparently failing because of a bug in the datetime parser. (QTBUG-22833)", Continue);
+#endif
+ QCOMPARE(QDateTime::fromString(dateTime.toString(Qt::SystemLocaleLongDate), Qt::SystemLocaleLongDate), dateTime);
+
QLocale::setDefault(def);
}
diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
index af9f03c551..299ae104f1 100644
--- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
@@ -95,7 +95,9 @@ private slots:
#endif
void ctor();
+#if !defined(Q_OS_WINCE) && !defined(QT_NO_PROCESS)
void emptyCtor();
+#endif
void unixLocaleName();
void double_conversion_data();
void double_conversion();
@@ -374,6 +376,10 @@ void tst_QLocale::ctor()
#undef TEST_CTOR
}
+#if !defined(Q_OS_WINCE) && !defined(QT_NO_PROCESS)
+// Not when Q_OS_WINCE is defined because the test uses unsupported
+// Windows CE QProcess functionality (std streams, env)
+// Also Qt needs to be compiled without QT_NO_PROCESS
static inline bool runSysApp(const QString &binary,
const QStringList &env,
QString *output,
@@ -424,12 +430,6 @@ static inline bool runSysAppTest(const QString &binary,
void tst_QLocale::emptyCtor()
{
-#if defined(Q_OS_WINCE)
- QSKIP("Uses unsupported Windows CE QProcess functionality (std streams, env)");
-#endif
-#if defined(QT_NO_PROCESS)
- QSKIP("Qt was compiled with QT_NO_PROCESS");
-#else
#define TEST_CTOR(req_lc, exp_str) \
{ \
/* Test constructor without arguments. Needs separate process */ \
@@ -492,8 +492,8 @@ void tst_QLocale::emptyCtor()
TEST_CTOR("123456", defaultLoc.toLatin1());
#undef TEST_CTOR
-#endif
}
+#endif
void tst_QLocale::unixLocaleName()
{
@@ -875,6 +875,7 @@ void tst_QLocale::formatDate_data()
QTest::newRow("28") << QDate() << "'\"yy\"'" << "";
QTest::newRow("29") << QDate(1974, 12, 1) << "hh:mm:ss.zzz ap d'd'dd/M/yy" << "hh:mm:ss.zzz ap 1d01/12/74";
+ QTest::newRow("dd MMMM yyyy") << QDate(1, 1, 1) << "dd MMMM yyyy" << "01 January 0001";
}
void tst_QLocale::formatDate()
@@ -974,6 +975,9 @@ void tst_QLocale::formatDateTime_data()
QTest::newRow("12C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
<< "d'd'dd/M/yyh" << "1d01/12/7415";
+ QTest::newRow("dd MMMM yyyy, hh:mm:ss") << "C" << QDateTime(QDate(1, 1, 1), QTime(12, 00, 00))
+ << "dd MMMM yyyy, hh:mm:ss" << "01 January 0001, 12:00:00";
+
QTest::newRow("20C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
<< "foo" << "foo";
QTest::newRow("21C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
index 2bf8119b9e..bc6bc585f2 100644
--- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
@@ -49,6 +49,10 @@
# undef QT_ASCII_CAST_WARNINGS
#endif
+#if defined(Q_OS_WIN) && defined(Q_OS_WINCE)
+#define Q_OS_WIN_AND_WINCE
+#endif
+
#include <QtTest/QtTest>
#include <qregexp.h>
#include <qregularexpression.h>
@@ -78,8 +82,10 @@ public:
public slots:
void cleanup();
private slots:
+#ifndef Q_CC_HPACC
void fromStdString();
void toStdString();
+#endif
void check_QTextIOStream();
void check_QTextStream();
void check_QDataStream();
@@ -204,8 +210,10 @@ private slots:
void integer_conversion();
void tortureSprintfDouble();
void toNum();
+#if !defined(Q_OS_WIN) || defined(Q_OS_WIN_AND_WINCE)
void localeAwareCompare_data();
void localeAwareCompare();
+#endif
void split_data();
void split();
void split_regexp_data();
@@ -228,8 +236,12 @@ private slots:
void repeated_data() const;
void compareRef();
void arg_locale();
+#ifdef QT_USE_ICU
void toUpperLower_icu();
+#endif
+#if defined(QT_UNICODE_LITERAL) && (defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU))
void literals();
+#endif
void eightBitLiterals_data();
void eightBitLiterals();
void reserve();
@@ -3444,11 +3456,10 @@ void tst_QString::setRawData()
QVERIFY(cstr.data_ptr() != csd);
}
+#ifndef Q_CC_HPACC
+// This test crashes on HP-UX with aCC (not supported)
void tst_QString::fromStdString()
{
-#ifdef Q_CC_HPACC
- QSKIP("This test crashes on HP-UX with aCC");
-#endif
std::string stroustrup = "foo";
QString eng = QString::fromStdString( stroustrup );
QCOMPARE( eng, QString("foo") );
@@ -3457,12 +3468,12 @@ void tst_QString::fromStdString()
QString qtnull = QString::fromStdString( stdnull );
QCOMPARE( qtnull.size(), int(stdnull.size()) );
}
+#endif
+#ifndef Q_CC_HPACC
+// This test crashes on HP-UX with aCC (not supported)
void tst_QString::toStdString()
{
-#ifdef Q_CC_HPACC
- QSKIP("This test crashes on HP-UX with aCC");
-#endif
QString nord = "foo";
std::string stroustrup1 = nord.toStdString();
QVERIFY( qstrcmp(stroustrup1.c_str(), "foo") == 0 );
@@ -3477,6 +3488,7 @@ void tst_QString::toStdString()
std::string stdnull = qtnull.toStdString();
QCOMPARE( int(stdnull.size()), qtnull.size() );
}
+#endif
void tst_QString::utf8()
{
@@ -4463,9 +4475,11 @@ void tst_QString::tortureSprintfDouble()
#include <locale.h>
+#if !defined(Q_OS_WIN) || defined(Q_OS_WIN_AND_WINCE)
+// On Q_OS_WIN others than Win CE, we cannot set the system or user locale
void tst_QString::localeAwareCompare_data()
{
-#ifdef Q_OS_WIN
+#ifdef Q_OS_WIN_AND_WINCE
QTest::addColumn<ulong>("locale");
#else
QTest::addColumn<QString>("locale");
@@ -4479,7 +4493,7 @@ void tst_QString::localeAwareCompare_data()
Latin-1-specific characters (I think). Compare with Swedish
below.
*/
-#ifdef Q_OS_WIN // assume c locale to be english
+#ifdef Q_OS_WIN_AND_WINCE // assume c locale to be english
QTest::newRow("c1") << MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) << QString::fromLatin1("\xe5") << QString::fromLatin1("\xe4") << 1;
QTest::newRow("c2") << MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1;
QTest::newRow("c3") << MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) << QString::fromLatin1("\xe5") << QString::fromLatin1("\xf6") << -1;
@@ -4497,7 +4511,7 @@ void tst_QString::localeAwareCompare_data()
comparison of Latin-1 values, although I'm not sure. So I
just test digits to make sure that it's not totally broken.
*/
-#ifdef Q_OS_WIN
+#ifdef Q_OS_WIN_AND_WINCE
QTest::newRow("english1") << MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) << QString("5") << QString("4") << 1;
QTest::newRow("english2") << MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) << QString("4") << QString("6") << -1;
QTest::newRow("english3") << MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) << QString("5") << QString("6") << -1;
@@ -4516,7 +4530,7 @@ void tst_QString::localeAwareCompare_data()
QTest::newRow("swedish2") << QString("sv_SE.ISO8859-1") << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1;
QTest::newRow("swedish3") << QString("sv_SE.ISO8859-1") << QString::fromLatin1("\xe5") << QString::fromLatin1("\xf6") << -1;
QTest::newRow("swedish4") << QString("sv_SE.ISO8859-1") << QString::fromLatin1("z") << QString::fromLatin1("\xe5") << -1;
-#elif defined(Q_OS_WIN)
+#elif defined(Q_OS_WIN_AND_WINCE)
QTest::newRow("swedish1") << MAKELCID(MAKELANGID(LANG_SWEDISH, SUBLANG_SWEDISH), SORT_DEFAULT) << QString::fromLatin1("\xe5") << QString::fromLatin1("\xe4") << -1;
QTest::newRow("swedish2") << MAKELCID(MAKELANGID(LANG_SWEDISH, SUBLANG_SWEDISH), SORT_DEFAULT) << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1;
QTest::newRow("swedish3") << MAKELCID(MAKELANGID(LANG_SWEDISH, SUBLANG_SWEDISH), SORT_DEFAULT) << QString::fromLatin1("\xe5") << QString::fromLatin1("\xf6") << -1;
@@ -4546,7 +4560,7 @@ void tst_QString::localeAwareCompare_data()
QTest::newRow("german1") << QString("de_DE.ISO8859-1") << QString::fromLatin1("z") << QString::fromLatin1("\xe4") << 1;
QTest::newRow("german2") << QString("de_DE.ISO8859-1") << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1;
QTest::newRow("german3") << QString("de_DE.ISO8859-1") << QString::fromLatin1("z") << QString::fromLatin1("\xf6") << 1;
-#elif defined(Q_OS_WIN)
+#elif defined(Q_OS_WIN_AND_WINCE)
QTest::newRow("german1") << MAKELCID(MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), SORT_DEFAULT) << QString::fromLatin1("z") << QString::fromLatin1("\xe4") << 1;
QTest::newRow("german2") << MAKELCID(MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), SORT_DEFAULT) << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1;
QTest::newRow("german3") << MAKELCID(MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), SORT_DEFAULT) << QString::fromLatin1("z") << QString::fromLatin1("\xf6") << 1;
@@ -4559,10 +4573,7 @@ void tst_QString::localeAwareCompare_data()
void tst_QString::localeAwareCompare()
{
-#ifdef Q_OS_WIN
-# ifndef Q_OS_WINCE
- QSKIP("On others than Win CE, we cannot set the system or user locale.");
-# endif
+#ifdef Q_OS_WIN_AND_WINCE
QFETCH(ulong, locale);
#else
QFETCH(QString, locale);
@@ -4574,19 +4585,10 @@ void tst_QString::localeAwareCompare()
QStringRef r1(&s1, 0, s1.length());
QStringRef r2(&s2, 0, s2.length());
-#ifdef Q_OS_WIN
-# if defined(Q_OS_WINCE)
+#ifdef Q_OS_WIN_AND_WINCE
DWORD oldLcid = GetUserDefaultLCID();
SetUserDefaultLCID(locale);
-
QCOMPARE(locale, GetUserDefaultLCID());
-# else
- DWORD oldLcid = GetThreadLocale();
- SetThreadLocale(locale);
-
- QCOMPARE(locale, GetThreadLocale());
-# endif
-
#elif defined (Q_OS_MAC)
QSKIP("Setting the locale is not supported on OS X (you can set the C locale, but that won't affect CFStringCompare which is used to compare strings)");
#elif defined(QT_USE_ICU)
@@ -4651,18 +4653,14 @@ void tst_QString::localeAwareCompare()
QVERIFY(testres == 0);
}
-#ifdef Q_OS_WIN
-# if defined(Q_OS_WINCE)
+#ifdef Q_OS_WIN_AND_WINCE
SetUserDefaultLCID(oldLcid);
-# else
- SetThreadLocale(oldLcid);
-# endif
-
#else
if (!locale.isEmpty())
setlocale(LC_ALL, "");
#endif
}
+#endif //!defined(Q_OS_WIN) || defined(Q_OS_WIN_AND_WINCE)
void tst_QString::split_data()
{
@@ -5349,12 +5347,11 @@ void tst_QString::arg_locale()
QLocale::setDefault(QLocale::C);
}
+
+#ifdef QT_USE_ICU
+// Qt has to be built with ICU support
void tst_QString::toUpperLower_icu()
{
-#ifndef QT_USE_ICU
- QSKIP("Qt was built without ICU support");
-#endif
-
QString s = QString::fromLatin1("i");
QCOMPARE(s.toUpper(), QString::fromLatin1("I"));
@@ -5387,10 +5384,12 @@ void tst_QString::toUpperLower_icu()
// the cleanup function will restore the default locale
}
+#endif
+#if defined(QT_UNICODE_LITERAL) && (defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU))
+// Only tested on c++0x compliant compiler or gcc
void tst_QString::literals()
{
-#if defined(QT_UNICODE_LITERAL) && (defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU))
QString str(QStringLiteral("abcd"));
QVERIFY(str.length() == 4);
@@ -5407,11 +5406,8 @@ void tst_QString::literals()
QVERIFY(str2.constData() == s);
QVERIFY(str2.data() != s);
-
-#else
- QSKIP("Only tested on c++0x compliant compiler or gcc");
-#endif
}
+#endif
void tst_QString::eightBitLiterals_data()
{
diff --git a/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp b/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp
index 2c4ec62936..ef549bc660 100644
--- a/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp
+++ b/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp
@@ -72,7 +72,9 @@ private slots:
void joinChar() const;
void joinChar_data() const;
+#ifdef Q_COMPILER_INITIALIZER_LISTS
void initializeList() const;
+#endif
};
extern const char email[];
@@ -422,16 +424,16 @@ void tst_QStringList::joinEmptiness() const
QVERIFY(string.isNull());
}
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+// C++0x support is required
void tst_QStringList::initializeList() const
{
-#ifdef Q_COMPILER_INITIALIZER_LISTS
+
QStringList v1{QLatin1String("hello"),"world",QString::fromLatin1("plop")};
QCOMPARE(v1, (QStringList() << "hello" << "world" << "plop"));
QCOMPARE(v1, (QStringList{"hello","world","plop"}));
-#else
- QSKIP("Require C++0x support, pass the right flag to the compiler");
-#endif
}
+#endif
QTEST_APPLESS_MAIN(tst_QStringList)
#include "tst_qstringlist.moc"
diff --git a/tests/auto/corelib/tools/qtime/tst_qtime.cpp b/tests/auto/corelib/tools/qtime/tst_qtime.cpp
index a1a31d754f..bfb8b4c42d 100644
--- a/tests/auto/corelib/tools/qtime/tst_qtime.cpp
+++ b/tests/auto/corelib/tools/qtime/tst_qtime.cpp
@@ -192,6 +192,8 @@ void tst_QTime::addMSecs_data()
QTest::newRow( "Data17_2") << QTime(0,0,0,0) << -5 << QTime(23,59,59,995);
QTest::newRow( "Data17_3") << QTime(0,0,0,1) << -6 << QTime(23,59,59,995);
QTest::newRow( "Data17_4") << QTime(0,0,0,2) << -7 << QTime(23,59,59,995);
+
+ QTest::newRow( "Data18_0" ) << invalidTime() << 1 << invalidTime();
}
void tst_QTime::addMSecs()
@@ -574,6 +576,9 @@ void tst_QTime::fromStringDateFormat_data()
QTest::newRow("TextDate - data1") << QString("10:12:34") << Qt::TextDate << QTime(10,12,34,0);
QTest::newRow("TextDate - data2") << QString("19:03:54.998601") << Qt::TextDate << QTime(19, 3, 54, 999);
QTest::newRow("TextDate - data3") << QString("19:03:54.999601") << Qt::TextDate << QTime(19, 3, 54, 999);
+ QTest::newRow("TextDate - invalid, minutes") << QString::fromLatin1("23:XX:00") << Qt::TextDate << invalidTime();
+ QTest::newRow("TextDate - invalid, seconds") << QString::fromLatin1("23:00:XX") << Qt::TextDate << invalidTime();
+ QTest::newRow("TextDate - invalid, milliseconds") << QString::fromLatin1("23:01:01:XXXX") << Qt::TextDate << QTime(23, 1, 1, 0);
QTest::newRow("IsoDate - valid, start of day, omit seconds") << QString::fromLatin1("00:00") << Qt::ISODate << QTime(0, 0, 0);
QTest::newRow("IsoDate - valid, omit seconds") << QString::fromLatin1("22:21") << Qt::ISODate << QTime(22, 21, 0);
@@ -585,11 +590,17 @@ void tst_QTime::fromStringDateFormat_data()
QTest::newRow("IsoDate - invalid, too many minutes") << QString::fromLatin1("10:70") << Qt::ISODate << invalidTime();
// This is a valid time if it happens on June 30 or December 31 (leap seconds).
QTest::newRow("IsoDate - invalid, too many seconds") << QString::fromLatin1("23:59:60") << Qt::ISODate << invalidTime();
+ QTest::newRow("IsoDate - invalid, minutes") << QString::fromLatin1("23:XX:00") << Qt::ISODate << invalidTime();
+ QTest::newRow("IsoDate - invalid, not enough minutes") << QString::fromLatin1("23:0") << Qt::ISODate << invalidTime();
+ QTest::newRow("IsoDate - invalid, minute fraction") << QString::fromLatin1("23:00,XX") << Qt::ISODate << invalidTime();
+ QTest::newRow("IsoDate - invalid, seconds") << QString::fromLatin1("23:00:XX") << Qt::ISODate << invalidTime();
+ QTest::newRow("IsoDate - invalid, milliseconds") << QString::fromLatin1("23:01:01:XXXX") << Qt::ISODate << QTime(23, 1, 1, 0);
QTest::newRow("IsoDate - data0") << QString("00:00:00") << Qt::ISODate << QTime(0,0,0,0);
QTest::newRow("IsoDate - data1") << QString("10:12:34") << Qt::ISODate << QTime(10,12,34,0);
QTest::newRow("IsoDate - data2") << QString("19:03:54.998601") << Qt::ISODate << QTime(19, 3, 54, 999);
QTest::newRow("IsoDate - data3") << QString("19:03:54.999601") << Qt::ISODate << QTime(19, 3, 54, 999);
+ QTest::newRow("IsoDate - minute fraction midnight") << QString("24:00,0") << Qt::ISODate << QTime(0, 0, 0, 0);
}
void tst_QTime::fromStringDateFormat()
diff --git a/tests/auto/corelib/tools/qvector/tst_qvector.cpp b/tests/auto/corelib/tools/qvector/tst_qvector.cpp
index 6304477ba3..0eda837644 100644
--- a/tests/auto/corelib/tools/qvector/tst_qvector.cpp
+++ b/tests/auto/corelib/tools/qvector/tst_qvector.cpp
@@ -205,8 +205,11 @@ private slots:
void eraseEmptyReservedMovable() const;
void eraseEmptyReservedCustom() const;
void eraseInt() const;
+ void eraseIntShared() const;
void eraseMovable() const;
+ void eraseMovableShared() const;
void eraseCustom() const;
+ void eraseCustomShared() const;
void eraseReservedInt() const;
void eraseReservedMovable() const;
void eraseReservedCustom() const;
@@ -268,6 +271,7 @@ private slots:
void detachInt() const;
void detachMovable() const;
void detachCustom() const;
+
private:
template<typename T> void copyConstructor() const;
template<typename T> void add() const;
@@ -278,7 +282,7 @@ private:
template<typename T> void empty() const;
template<typename T> void eraseEmpty() const;
template<typename T> void eraseEmptyReserved() const;
- template<typename T> void erase() const;
+ template<typename T> void erase(bool shared) const;
template<typename T> void eraseReserved() const;
template<typename T> void fill() const;
template<typename T> void fromList() const;
@@ -300,6 +304,15 @@ template<typename T> struct SimpleValue
{
return Values[index % MaxIndex];
}
+
+ static QVector<T> vector(int size)
+ {
+ QVector<T> ret;
+ for (int i = 0; i < size; i++)
+ ret.append(at(i));
+ return ret;
+ }
+
static const uint MaxIndex = 6;
static const T Values[MaxIndex];
};
@@ -565,7 +578,6 @@ void tst_QVector::capacity() const
// make sure it grows ok
myvec << SimpleValue<T>::at(0) << SimpleValue<T>::at(1) << SimpleValue<T>::at(2);
QVERIFY(myvec.capacity() >= 6);
-
// let's try squeeze a bit
myvec.remove(3);
myvec.remove(3);
@@ -865,60 +877,139 @@ void tst_QVector::eraseEmptyReservedCustom() const
}
template<typename T>
-void tst_QVector::erase() const
+struct SharedVectorChecker
{
+ SharedVectorChecker(const QVector<T> &original, bool doCopyVector)
+ : originalSize(-1),
+ copy(0)
{
- QVector<T> v(12);
+ if (doCopyVector) {
+ originalSize = original.size();
+ copy = new QVector<T>(original);
+ // this is unlikely to fail, but if the check in the destructor fails it's good to know that
+ // we were still alright here.
+ QCOMPARE(originalSize, copy->size());
+ }
+ }
+
+ ~SharedVectorChecker()
+ {
+ if (copy)
+ QCOMPARE(copy->size(), originalSize);
+ delete copy;
+ }
+
+ int originalSize;
+ QVector<T> *copy;
+};
+
+template<typename T>
+void tst_QVector::erase(bool shared) const
+{
+ // note: remove() is actually more efficient, and more dangerous, because it uses the non-detaching
+ // begin() / end() internally. you can also use constBegin() and constEnd() with erase(), but only
+ // using reinterpret_cast... because both iterator types are really just pointers.
+ // so we use a mix of erase() and remove() to cover more cases.
+ {
+ QVector<T> v = SimpleValue<T>::vector(12);
+ SharedVectorChecker<T> svc(v, shared);
v.erase(v.begin());
QCOMPARE(v.size(), 11);
+ for (int i = 0; i < 11; i++)
+ QCOMPARE(v.at(i), SimpleValue<T>::at(i + 1));
v.erase(v.begin(), v.end());
QCOMPARE(v.size(), 0);
+ if (shared)
+ QCOMPARE(SimpleValue<T>::vector(12), *svc.copy);
}
{
- QVector<T> v(12);
- v.erase(v.begin() + 1);
+ QVector<T> v = SimpleValue<T>::vector(12);
+ SharedVectorChecker<T> svc(v, shared);
+ v.remove(1);
QCOMPARE(v.size(), 11);
+ QCOMPARE(v.at(0), SimpleValue<T>::at(0));
+ for (int i = 1; i < 11; i++)
+ QCOMPARE(v.at(i), SimpleValue<T>::at(i + 1));
v.erase(v.begin() + 1, v.end());
QCOMPARE(v.size(), 1);
+ QCOMPARE(v.at(0), SimpleValue<T>::at(0));
+ if (shared)
+ QCOMPARE(SimpleValue<T>::vector(12), *svc.copy);
}
{
- QVector<T> v(12);
+ QVector<T> v = SimpleValue<T>::vector(12);
+ SharedVectorChecker<T> svc(v, shared);
v.erase(v.begin(), v.end() - 1);
QCOMPARE(v.size(), 1);
+ QCOMPARE(v.at(0), SimpleValue<T>::at(11));
+ if (shared)
+ QCOMPARE(SimpleValue<T>::vector(12), *svc.copy);
}
{
- QVector<T> v(12);
- v.erase(v.begin() + 5);
+ QVector<T> v = SimpleValue<T>::vector(12);
+ SharedVectorChecker<T> svc(v, shared);
+ v.remove(5);
QCOMPARE(v.size(), 11);
+ for (int i = 0; i < 5; i++)
+ QCOMPARE(v.at(i), SimpleValue<T>::at(i));
+ for (int i = 5; i < 11; i++)
+ QCOMPARE(v.at(i), SimpleValue<T>::at(i + 1));
v.erase(v.begin() + 1, v.end() - 1);
+ QCOMPARE(v.at(0), SimpleValue<T>::at(0));
+ QCOMPARE(v.at(1), SimpleValue<T>::at(11));
QCOMPARE(v.size(), 2);
+ if (shared)
+ QCOMPARE(SimpleValue<T>::vector(12), *svc.copy);
}
{
- QVector<T> v(10);
+ QVector<T> v = SimpleValue<T>::vector(10);
+ SharedVectorChecker<T> svc(v, shared);
v.setSharable(false);
+ SharedVectorChecker<T> svc2(v, shared);
v.erase(v.begin() + 3);
QCOMPARE(v.size(), 9);
v.erase(v.begin(), v.end() - 1);
QCOMPARE(v.size(), 1);
+ if (shared)
+ QCOMPARE(SimpleValue<T>::vector(10), *svc.copy);
}
}
void tst_QVector::eraseInt() const
{
- erase<int>();
+ erase<int>(false);
+}
+
+void tst_QVector::eraseIntShared() const
+{
+ erase<int>(true);
}
void tst_QVector::eraseMovable() const
{
const int instancesCount = Movable::counter;
- erase<Movable>();
+ erase<Movable>(false);
+ QCOMPARE(instancesCount, Movable::counter);
+}
+
+void tst_QVector::eraseMovableShared() const
+{
+ const int instancesCount = Movable::counter;
+ erase<Movable>(true);
QCOMPARE(instancesCount, Movable::counter);
}
void tst_QVector::eraseCustom() const
{
const int instancesCount = Custom::counter;
- erase<Custom>();
+ erase<Custom>(false);
+ QCOMPARE(instancesCount, Custom::counter);
+}
+
+void tst_QVector::eraseCustomShared() const
+{
+ const int instancesCount = Custom::counter;
+ erase<Custom>(true);
QCOMPARE(instancesCount, Custom::counter);
}