summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp4
-rw-r--r--tests/auto/corelib/io/qsettings/tst_qsettings.cpp23
-rw-r--r--tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp98
3 files changed, 124 insertions, 1 deletions
diff --git a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
index 9cae582143..7e04fa5957 100644
--- a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
+++ b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp
@@ -112,9 +112,11 @@ void tst_QFileSystemWatcher::basicTest_data()
+ QChar(ushort(0x00DC)) // LATIN_CAPITAL_LETTER_U_WITH_DIAERESIS
+ QStringLiteral(".txt");
+#if !defined(Q_OS_QNX) || !defined(QT_NO_INOTIFY)
QTest::newRow("native backend-testfile") << "native" << testFile;
- QTest::newRow("poller backend-testfile") << "poller" << testFile;
QTest::newRow("native backend-specialchars") << "native" << specialCharacterFile;
+#endif
+ QTest::newRow("poller backend-testfile") << "poller" << testFile;
}
void tst_QFileSystemWatcher::basicTest()
diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp
index 501ad6f415..2c9868cd10 100644
--- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp
+++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp
@@ -166,6 +166,7 @@ private slots:
void testByteArray_data();
void testByteArray();
+ void iniCodec();
private:
const bool m_canWriteNativeSystemSettings;
@@ -695,6 +696,28 @@ void tst_QSettings::testByteArray()
}
}
+void tst_QSettings::iniCodec()
+{
+ {
+ QSettings settings("QtProject", "tst_qsettings");
+ settings.setIniCodec("cp1251");
+ QByteArray ba;
+ ba.resize(256);
+ for (int i = 0; i < ba.size(); i++)
+ ba[i] = i;
+ settings.setValue("array",ba);
+ }
+ {
+ QSettings settings("QtProject", "tst_qsettings");
+ settings.setIniCodec("cp1251");
+ QByteArray ba = settings.value("array").toByteArray();
+ QCOMPARE(ba.size(), 256);
+ for (int i = 0; i < ba.size(); i++)
+ QCOMPARE((uchar)ba.at(i), (uchar)i);
+ }
+
+}
+
void tst_QSettings::testErrorHandling_data()
{
QTest::addColumn<int>("filePerms"); // -1 means file should not exist
diff --git a/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp b/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp
index c385a02b9c..f36bbbc5b6 100644
--- a/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp
+++ b/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp
@@ -71,6 +71,7 @@ private slots:
void submit_data();
void submit();
void testRoleNames();
+ void testSwappingRowsProxy();
};
// Subclass that exposes the protected functions.
@@ -397,6 +398,103 @@ void tst_QAbstractProxyModel::testRoleNames()
QVERIFY( proxy2RoleNames.value(StandardItemModelWithCustomRoleNames::CustomRole2) == "custom2" );
}
+// This class only supports very simple table models
+class SwappingProxy : public QAbstractProxyModel
+{
+ static int swapRow(const int row)
+ {
+ if (row == 2) {
+ return 3;
+ } else if (row == 3) {
+ return 2;
+ } else {
+ return row;
+ }
+ }
+public:
+ virtual QModelIndex index(int row, int column, const QModelIndex &parentIdx) const
+ {
+ if (!sourceModel())
+ return QModelIndex();
+ if (row < 0 || column < 0)
+ return QModelIndex();
+ if (row >= sourceModel()->rowCount())
+ return QModelIndex();
+ if (column >= sourceModel()->columnCount())
+ return QModelIndex();
+ return createIndex(row, column, parentIdx.internalPointer());
+ }
+
+ virtual QModelIndex parent(const QModelIndex &parentIdx) const
+ {
+ // well, we're a 2D model
+ Q_UNUSED(parentIdx);
+ return QModelIndex();
+ }
+
+ virtual int rowCount(const QModelIndex &parentIdx) const
+ {
+ if (parentIdx.isValid() || !sourceModel())
+ return 0;
+ return sourceModel()->rowCount();
+ }
+
+ virtual int columnCount(const QModelIndex &parentIdx) const
+ {
+ if (parentIdx.isValid() || !sourceModel())
+ return 0;
+ return sourceModel()->rowCount();
+ }
+
+ virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const
+ {
+ if (!proxyIndex.isValid())
+ return QModelIndex();
+ if (!sourceModel())
+ return QModelIndex();
+ Q_ASSERT(!proxyIndex.parent().isValid());
+ return sourceModel()->index(swapRow(proxyIndex.row()), proxyIndex.column(), QModelIndex());
+ }
+
+ virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const
+ {
+ if (!sourceIndex.isValid())
+ return QModelIndex();
+ if (!sourceModel())
+ return QModelIndex();
+ Q_ASSERT(!sourceIndex.parent().isValid());
+ return index(swapRow(sourceIndex.row()), sourceIndex.column(), QModelIndex());
+ }
+};
+
+void tst_QAbstractProxyModel::testSwappingRowsProxy()
+{
+ QStandardItemModel defaultModel;
+ defaultModel.setRowCount(4);
+ defaultModel.setColumnCount(2);
+ for (int row = 0; row < defaultModel.rowCount(); ++row) {
+ defaultModel.setItem(row, 0, new QStandardItem(QString::number(row) + QLatin1Char('A')));
+ defaultModel.setItem(row, 1, new QStandardItem(QString::number(row) + QLatin1Char('B')));
+ }
+ SwappingProxy proxy;
+ proxy.setSourceModel(&defaultModel);
+ QCOMPARE(proxy.data(proxy.index(0, 0, QModelIndex())), QVariant("0A"));
+ QCOMPARE(proxy.data(proxy.index(0, 1, QModelIndex())), QVariant("0B"));
+ QCOMPARE(proxy.data(proxy.index(1, 0, QModelIndex())), QVariant("1A"));
+ QCOMPARE(proxy.data(proxy.index(1, 1, QModelIndex())), QVariant("1B"));
+ QCOMPARE(proxy.data(proxy.index(2, 0, QModelIndex())), QVariant("3A"));
+ QCOMPARE(proxy.data(proxy.index(2, 1, QModelIndex())), QVariant("3B"));
+ QCOMPARE(proxy.data(proxy.index(3, 0, QModelIndex())), QVariant("2A"));
+ QCOMPARE(proxy.data(proxy.index(3, 1, QModelIndex())), QVariant("2B"));
+
+ for (int row = 0; row < defaultModel.rowCount(); ++row) {
+ QModelIndex left = proxy.index(row, 0, QModelIndex());
+ QModelIndex right = proxy.index(row, 1, QModelIndex());
+ QCOMPARE(left.sibling(left.row(), 1), right);
+ QCOMPARE(right.sibling(right.row(), 0), left);
+ }
+}
+
QTEST_MAIN(tst_QAbstractProxyModel)
#include "tst_qabstractproxymodel.moc"