summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/io/qfile/tst_qfile.cpp40
-rw-r--r--tests/auto/corelib/tools/qcollator/tst_qcollator.cpp62
2 files changed, 77 insertions, 25 deletions
diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp
index 9ce931d78a..ddfb68cabc 100644
--- a/tests/auto/corelib/io/qfile/tst_qfile.cpp
+++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp
@@ -234,6 +234,8 @@ private slots:
void mapResource();
void mapOpenMode_data();
void mapOpenMode();
+ void mapWrittenFile_data();
+ void mapWrittenFile();
#ifndef Q_OS_WINCE
void openStandardStreamsFileDescriptors();
@@ -3087,6 +3089,44 @@ void tst_QFile::mapOpenMode()
file.close();
}
+void tst_QFile::mapWrittenFile_data()
+{
+ QTest::addColumn<int>("mode");
+ QTest::newRow("buffered") << 0;
+ QTest::newRow("unbuffered") << int(QIODevice::Unbuffered);
+}
+
+void tst_QFile::mapWrittenFile()
+{
+ static const char data[128] = "Some data padded with nulls\n";
+ QFETCH(int, mode);
+
+ QString fileName = QDir::currentPath() + '/' + "qfile_map_testfile";
+
+#ifdef Q_OS_WINCE
+ fileName = QFileInfo(fileName).absoluteFilePath();
+#endif
+
+ if (QFile::exists(fileName)) {
+ QVERIFY(QFile::setPermissions(fileName,
+ QFile::WriteOwner | QFile::ReadOwner | QFile::WriteUser | QFile::ReadUser));
+ QFile::remove(fileName);
+ }
+ QFile file(fileName);
+ QVERIFY(file.open(QIODevice::ReadWrite | QFile::OpenMode(mode)));
+ QCOMPARE(file.write(data, sizeof data), qint64(sizeof data));
+ if ((mode & QIODevice::Unbuffered) == 0)
+ file.flush();
+
+ // test that we can read the data we've just written, without closing the file
+ uchar *memory = file.map(0, sizeof data);
+ QVERIFY(memory);
+ QVERIFY(memcmp(memory, data, sizeof data) == 0);
+
+ file.close();
+ file.remove();
+}
+
void tst_QFile::openDirectory()
{
QFile f1(m_resourcesDir);
diff --git a/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp b/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp
index f6fd13007a..ed57b7cce0 100644
--- a/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp
+++ b/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp
@@ -100,6 +100,7 @@ void tst_QCollator::compare_data()
QTest::addColumn<QString>("s2");
QTest::addColumn<int>("result");
QTest::addColumn<int>("caseInsensitiveResult");
+ QTest::addColumn<bool>("numericMode");
/*
A few tests below are commented out on the mac. It's unclear why they fail,
@@ -114,49 +115,55 @@ void tst_QCollator::compare_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.
*/
- QTest::newRow("english1") << QString("en_US") << QString("5") << QString("4") << 1 << 1;
- QTest::newRow("english2") << QString("en_US") << QString("4") << QString("6") << -1 << -1;
- QTest::newRow("english3") << QString("en_US") << QString("5") << QString("6") << -1 << -1;
- QTest::newRow("english4") << QString("en_US") << QString("a") << QString("b") << -1 << -1;
+ QTest::newRow("english1") << QString("en_US") << QString("5") << QString("4") << 1 << 1 << false;
+ QTest::newRow("english2") << QString("en_US") << QString("4") << QString("6") << -1 << -1 << false;
+ QTest::newRow("english3") << QString("en_US") << QString("5") << QString("6") << -1 << -1 << false;
+ QTest::newRow("english4") << QString("en_US") << QString("a") << QString("b") << -1 << -1 << false;
+ QTest::newRow("english5") << QString("en_US") << QString("test 9") << QString("test 19") << -1 << -1 << true;
+
/*
In Swedish, a with ring above (E5) comes before a with
diaresis (E4), which comes before o diaresis (F6), which
all come after z.
*/
- QTest::newRow("swedish1") << QString("sv_SE") << QString::fromLatin1("\xe5") << QString::fromLatin1("\xe4") << -1 << -1;
- QTest::newRow("swedish2") << QString("sv_SE") << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1 << -1;
- QTest::newRow("swedish3") << QString("sv_SE") << QString::fromLatin1("\xe5") << QString::fromLatin1("\xf6") << -1 << -1;
- QTest::newRow("swedish4") << QString("sv_SE") << QString::fromLatin1("z") << QString::fromLatin1("\xe5") << -1 << -1;
+ QTest::newRow("swedish1") << QString("sv_SE") << QString::fromLatin1("\xe5") << QString::fromLatin1("\xe4") << -1 << -1 << false;
+ QTest::newRow("swedish2") << QString("sv_SE") << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1 << -1 << false;
+ QTest::newRow("swedish3") << QString("sv_SE") << QString::fromLatin1("\xe5") << QString::fromLatin1("\xf6") << -1 << -1 << false;
+ QTest::newRow("swedish4") << QString("sv_SE") << QString::fromLatin1("z") << QString::fromLatin1("\xe5") << -1 << -1 << false;
+ QTest::newRow("swedish5") << QString("sv_SE") << QString("9") << QString("19") << -1 << -1 << true;
/*
In Norwegian, ae (E6) comes before o with stroke (D8), which
comes before a with ring above (E5).
*/
- QTest::newRow("norwegian1") << QString("no_NO") << QString::fromLatin1("\xe6") << QString::fromLatin1("\xd8") << -1 << -1;
- QTest::newRow("norwegian2") << QString("no_NO") << QString::fromLatin1("\xd8") << QString::fromLatin1("\xe5") << -1 << -1;
- QTest::newRow("norwegian3") << QString("no_NO") << QString::fromLatin1("\xe6") << QString::fromLatin1("\xe5") << -1 << -1;
+ QTest::newRow("norwegian1") << QString("no_NO") << QString::fromLatin1("\xe6") << QString::fromLatin1("\xd8") << -1 << -1 << false;
+ QTest::newRow("norwegian2") << QString("no_NO") << QString::fromLatin1("\xd8") << QString::fromLatin1("\xe5") << -1 << -1 << false;
+ QTest::newRow("norwegian3") << QString("no_NO") << QString::fromLatin1("\xe6") << QString::fromLatin1("\xe5") << -1 << -1 << false;
+ QTest::newRow("norwegian4") << QString("no_NO") << QString("9") << QString("19") << -1 << -1 << true;
+
/*
In German, z comes *after* a with diaresis (E4),
which comes before o diaresis (F6).
*/
- QTest::newRow("german1") << QString("de_DE") << QString::fromLatin1("a") << QString::fromLatin1("\xe4") << -1 << -1;
- QTest::newRow("german2") << QString("de_DE") << QString::fromLatin1("b") << QString::fromLatin1("\xe4") << 1 << 1;
- QTest::newRow("german3") << QString("de_DE") << QString::fromLatin1("z") << QString::fromLatin1("\xe4") << 1 << 1;
- QTest::newRow("german4") << QString("de_DE") << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1 << -1;
- QTest::newRow("german5") << QString("de_DE") << QString::fromLatin1("z") << QString::fromLatin1("\xf6") << 1 << 1;
- QTest::newRow("german6") << QString("de_DE") << QString::fromLatin1("\xc0") << QString::fromLatin1("\xe0") << 1 << 0;
- QTest::newRow("german7") << QString("de_DE") << QString::fromLatin1("\xd6") << QString::fromLatin1("\xf6") << 1 << 0;
- QTest::newRow("german8") << QString("de_DE") << QString::fromLatin1("oe") << QString::fromLatin1("\xf6") << 1 << 1;
- QTest::newRow("german9") << QString("de_DE") << QString("A") << QString("a") << 1 << 0;
+ QTest::newRow("german1") << QString("de_DE") << QString::fromLatin1("a") << QString::fromLatin1("\xe4") << -1 << -1 << false;
+ QTest::newRow("german2") << QString("de_DE") << QString::fromLatin1("b") << QString::fromLatin1("\xe4") << 1 << 1 << false;
+ QTest::newRow("german3") << QString("de_DE") << QString::fromLatin1("z") << QString::fromLatin1("\xe4") << 1 << 1 << false;
+ QTest::newRow("german4") << QString("de_DE") << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1 << -1 << false;
+ QTest::newRow("german5") << QString("de_DE") << QString::fromLatin1("z") << QString::fromLatin1("\xf6") << 1 << 1 << false;
+ QTest::newRow("german6") << QString("de_DE") << QString::fromLatin1("\xc0") << QString::fromLatin1("\xe0") << 1 << 0 << false;
+ QTest::newRow("german7") << QString("de_DE") << QString::fromLatin1("\xd6") << QString::fromLatin1("\xf6") << 1 << 0 << false;
+ QTest::newRow("german8") << QString("de_DE") << QString::fromLatin1("oe") << QString::fromLatin1("\xf6") << 1 << 1 << false;
+ QTest::newRow("german9") << QString("de_DE") << QString("A") << QString("a") << 1 << 0 << false;
+ QTest::newRow("german10") << QString("de_DE") << QString("9") << QString("19") << -1 << -1 << true;
/*
French sorting of e and e with accent
*/
- QTest::newRow("french1") << QString("fr_FR") << QString::fromLatin1("\xe9") << QString::fromLatin1("e") << 1 << 1;
- QTest::newRow("french2") << QString("fr_FR") << QString::fromLatin1("\xe9t") << QString::fromLatin1("et") << 1 << 1;
- QTest::newRow("french3") << QString("fr_FR") << QString::fromLatin1("\xe9") << QString::fromLatin1("d") << 1 << 1;
- QTest::newRow("french4") << QString("fr_FR") << QString::fromLatin1("\xe9") << QString::fromLatin1("f") << -1 << -1;
-
+ QTest::newRow("french1") << QString("fr_FR") << QString::fromLatin1("\xe9") << QString::fromLatin1("e") << 1 << 1 << false;
+ QTest::newRow("french2") << QString("fr_FR") << QString::fromLatin1("\xe9t") << QString::fromLatin1("et") << 1 << 1 << false;
+ QTest::newRow("french3") << QString("fr_FR") << QString::fromLatin1("\xe9") << QString::fromLatin1("d") << 1 << 1 << false;
+ QTest::newRow("french4") << QString("fr_FR") << QString::fromLatin1("\xe9") << QString::fromLatin1("f") << -1 << -1 << false;
+ QTest::newRow("french5") << QString("fr_FR") << QString("9") << QString("19") << -1 << -1 << true;
}
@@ -167,8 +174,13 @@ void tst_QCollator::compare()
QFETCH(QString, s2);
QFETCH(int, result);
QFETCH(int, caseInsensitiveResult);
+ QFETCH(bool, numericMode);
QCollator collator(locale);
+
+ if (numericMode)
+ collator.setNumericMode(true);
+
QCOMPARE(collator.compare(s1, s2), result);
collator.setCaseSensitivity(Qt::CaseInsensitive);
QCOMPARE(collator.compare(s1, s2), caseInsensitiveResult);