summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarius Bugge Monsen <mmonsen@trolltech.com>2009-05-11 16:04:42 +0200
committerMarius Bugge Monsen <mmonsen@trolltech.com>2009-05-11 16:04:42 +0200
commit55613da7aa981da0e124b895b1bd903111efae97 (patch)
treef76ed65af028d2038e49d9a42096ce35c9406f69 /tests
parent0582eb2ff4a3a7707ac602c9e90203301a4cf0df (diff)
Add more test-data for QtTableSelectionManager. Also expand the QtListSelectionManager test.
Diffstat (limited to 'tests')
-rw-r--r--tests/qlistselectionmanager/tst_qlistselectionmanager.cpp26
-rw-r--r--tests/qtableselectionmanager/tst_qtableselectionmanager.cpp195
2 files changed, 217 insertions, 4 deletions
diff --git a/tests/qlistselectionmanager/tst_qlistselectionmanager.cpp b/tests/qlistselectionmanager/tst_qlistselectionmanager.cpp
index 1d68692..4821aa0 100644
--- a/tests/qlistselectionmanager/tst_qlistselectionmanager.cpp
+++ b/tests/qlistselectionmanager/tst_qlistselectionmanager.cpp
@@ -384,16 +384,16 @@ void tst_QtListSelectionManager::selections_data()
QTest::addColumn<QList<int> >("changedSelectionIndexes");
QTest::addColumn<int>("signalCount");
- QTest::newRow("no data")
+ QTest::newRow("no model")
<< false << 0 // model
<< QList<int>() << QList<int>() << QList<int>() // initial
<< 0 << 0 // insert
<< 0 << 0 // remove
<< 0 << 0 << 0 // move
<< QList<int>() // changed
- << 0; // signal
+ << 0; // signal
- QTest::newRow("no data, one selection")
+ QTest::newRow("no model, one selection")
<< false << 0
<< (QList<int>() << 3) << (QList<int>() << int(Select)) << QList<int>()
<< 0 << 0
@@ -402,6 +402,24 @@ void tst_QtListSelectionManager::selections_data()
<< QList<int>()
<< 0;
+ QTest::newRow("no data")
+ << true << 0
+ << QList<int>() << QList<int>() << QList<int>()
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0 << 0
+ << QList<int>()
+ << 0;
+
+ QTest::newRow("no data, one selection")
+ << true << 0
+ << (QList<int>() << 3) << (QList<int>() << int(Select)) << QList<int>()
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0 << 0
+ << QList<int>()
+ << 0;
+
QTest::newRow("no selections")
<< true << 10
<< QList<int>() << QList<int>() << QList<int>()
@@ -582,7 +600,7 @@ void tst_QtListSelectionManager::anchoredSelections_data()
QTest::addColumn<QList<int> >("commitedSelectionIndexes");
QTest::addColumn<int>("signalCount");
- QTest::newRow("no data")
+ QTest::newRow("no model")
<< false << 0 // model
<< QList<int>() // initial
<< int(Select) << 0 << 0 // range
diff --git a/tests/qtableselectionmanager/tst_qtableselectionmanager.cpp b/tests/qtableselectionmanager/tst_qtableselectionmanager.cpp
index 5b1ebff..be314fa 100644
--- a/tests/qtableselectionmanager/tst_qtableselectionmanager.cpp
+++ b/tests/qtableselectionmanager/tst_qtableselectionmanager.cpp
@@ -39,6 +39,12 @@ class tst_QtTableSelectionManager : public QObject
Q_OBJECT
public:
+ enum SelectionMode {
+ Select = QtTableSelectionManager::Select,
+ Deselect = QtTableSelectionManager::Deselect,
+ Toggle = QtTableSelectionManager::Toggle
+ };
+
tst_QtTableSelectionManager();
virtual ~tst_QtTableSelectionManager();
@@ -67,6 +73,7 @@ private:
Q_DECLARE_METATYPE(QList<int>)
Q_DECLARE_METATYPE(QList<bool>)
Q_DECLARE_METATYPE(QtTableSelectionRange)
+Q_DECLARE_METATYPE(QList<QtTableSelectionRange>)
tst_QtTableSelectionManager::tst_QtTableSelectionManager()
: manager(0), model(0)
@@ -493,10 +500,198 @@ void tst_QtTableSelectionManager::anchorCell()
void tst_QtTableSelectionManager::selections_data()
{
+ QTest::addColumn<bool>("useModel");
+ QTest::addColumn<int>("rowCount");
+ QTest::addColumn<int>("columnCount");
+ QTest::addColumn<QList<QtTableSelectionRange> >("newSelections");
+ QTest::addColumn<QList<int> >("newSelectionModes");
+ QTest::addColumn<QList<QtTableSelectionRange> >("expectedSelections");
+ QTest::addColumn<int>("insertRowsAt");
+ QTest::addColumn<int>("insertRowCount");
+ QTest::addColumn<int>("insertColumnsAt");
+ QTest::addColumn<int>("insertColumnCount");
+ QTest::addColumn<int>("removeRowsAt");
+ QTest::addColumn<int>("removeRowCount");
+ QTest::addColumn<int>("removeColumnsAt");
+ QTest::addColumn<int>("removeColumnCount");
+ QTest::addColumn<int>("moveRowsFrom");
+ QTest::addColumn<int>("moveRowsTo");
+ QTest::addColumn<int>("moveRowCount");
+ QTest::addColumn<int>("moveColumnsFrom");
+ QTest::addColumn<int>("moveColumnsTo");
+ QTest::addColumn<int>("moveColumnCount");
+ QTest::addColumn<QList<QtTableSelectionRange> >("changedSelections");
+ QTest::addColumn<int>("signalCount");
+
+ QTest::newRow("no model")
+ << false // use model
+ << 0 << 0 // cell count
+ << QList<QtTableSelectionRange>()
+ << QList<int>() // modes
+ << QList<QtTableSelectionRange>()
+ << 0 << 0 // insert rows
+ << 0 << 0 // insert columns
+ << 0 << 0 // remove rows
+ << 0 << 0 // remove columns
+ << 0 << 0 << 0 // move rows
+ << 0 << 0 << 0 // move columns
+ << QList<QtTableSelectionRange>()
+ << 0; // signals
+
+ QTest::newRow("no model, one selection")
+ << false
+ << 0 << 0
+ << (QList<QtTableSelectionRange>() << QtTableSelectionRange(0, 0, 1, 1))
+ << (QList<int>() << int(Select))
+ << QList<QtTableSelectionRange>()
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0 << 0
+ << 0 << 0 << 0
+ << QList<QtTableSelectionRange>()
+ << 0;
+
+ QTest::newRow("no data")
+ << true
+ << 0 << 0
+ << QList<QtTableSelectionRange>()
+ << QList<int>()
+ << QList<QtTableSelectionRange>()
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0 << 0
+ << 0 << 0 << 0
+ << QList<QtTableSelectionRange>()
+ << 0;
+
+ QTest::newRow("no data, one selection")
+ << true
+ << 0 << 0
+ << (QList<QtTableSelectionRange>() << QtTableSelectionRange(0, 0, 1, 1))
+ << (QList<int>() << int(Select))
+ << QList<QtTableSelectionRange>()
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0 << 0
+ << 0 << 0 << 0
+ << QList<QtTableSelectionRange>()
+ << 0;
+
+ QTest::newRow("no selections")
+ << true
+ << 10 << 10
+ << QList<QtTableSelectionRange>()
+ << QList<int>()
+ << QList<QtTableSelectionRange>()
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0 << 0
+ << 0 << 0 << 0
+ << QList<QtTableSelectionRange>()
+ << 0;
+
+ QTest::newRow("one selection")
+ << true
+ << 10 << 10
+ << (QList<QtTableSelectionRange>() << QtTableSelectionRange(0, 0, 1, 1))
+ << (QList<int>() << int(Select))
+ << (QList<QtTableSelectionRange>() << QtTableSelectionRange(0, 0, 1, 1))
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0
+ << 0 << 0 << 0
+ << 0 << 0 << 0
+ << (QList<QtTableSelectionRange>() << QtTableSelectionRange(0, 0, 1, 1))
+ << 0;
}
void tst_QtTableSelectionManager::selections()
{
+ QFETCH(bool, useModel);
+ QFETCH(int, rowCount);
+ QFETCH(int, columnCount);
+ QFETCH(QList<QtTableSelectionRange>, newSelections);
+ QFETCH(QList<int>, newSelectionModes);
+ QFETCH(QList<QtTableSelectionRange>, expectedSelections);
+ QFETCH(int, insertRowsAt);
+ QFETCH(int, insertRowCount);
+ QFETCH(int, insertColumnsAt);
+ QFETCH(int, insertColumnCount);
+ QFETCH(int, removeRowsAt);
+ QFETCH(int, removeRowCount);
+ QFETCH(int, removeColumnsAt);
+ QFETCH(int, removeColumnCount);
+ QFETCH(int, moveRowsFrom);
+ QFETCH(int, moveRowsTo);
+ QFETCH(int, moveRowCount);
+ QFETCH(int, moveColumnsFrom);
+ QFETCH(int, moveColumnsTo);
+ QFETCH(int, moveColumnCount);
+ QFETCH(QList<QtTableSelectionRange>, changedSelections);
+ QFETCH(int, signalCount);
+
+ QSignalSpy selectionsChanged(manager, SIGNAL(selectionsChanged(const QList<QtTableSelectionRange>&)));
+
+ // start without model
+ manager->setModel(0);
+
+ // setup the model item count
+ model->setRowCount(rowCount);
+ model->setColumnCount(columnCount);
+
+ // with or without data model
+ manager->setModel(useModel ? model : 0);
+ QCOMPARE(manager->model(), (useModel ? model : 0));
+
+ // set and check selection
+ for (int a = 0; a < newSelections.count(); ++a)
+ manager->setSelected(newSelections.at(a), QtTableSelectionManager::SelectionMode(newSelectionModes.at(a)));
+ QList<QtTableSelectionRange> selectionRanges = manager->selectionRanges();
+ QCOMPARE(selectionRanges.count(), expectedSelections.count());
+ for (int b = 0; b < expectedSelections.count(); ++b)
+ QCOMPARE(selectionRanges.at(b), expectedSelections.at(b));
+
+ // insert rows
+ for (int j = insertRowsAt; j < insertRowsAt + insertRowCount; ++j)
+ model->insertRow(j);
+
+ // insert columns
+ for (int k = insertColumnsAt; k < insertColumnsAt + insertColumnCount; ++k)
+ model->insertColumn(k);
+
+ // remove rows
+ for (int l = removeRowsAt; l < removeRowsAt + removeRowCount; ++l)
+ model->removeRow(l);
+
+ // remove columns
+ for (int m = removeColumnsAt; m < removeColumnsAt + removeColumnCount; ++m)
+ model->removeColumn(m);
+
+ // move rows
+ for (int n = 0; n < moveRowCount; ++n)
+ model->moveRow(moveRowsFrom, moveRowsTo + n);
+
+ // move columns
+ for (int o = 0; o < moveColumnCount; ++o)
+ model->moveColumn(moveColumnsFrom, moveColumnsTo + o);
+
+ // check selection again
+ selectionRanges = manager->selectionRanges();
+ QCOMPARE(selectionRanges.count(), changedSelections.count());
+ for (int p = 0; p < changedSelections.count(); ++p)
+ QCOMPARE(selectionRanges.at(p), changedSelections.at(p));
+
+ // check signals
+ QCOMPARE(selectionsChanged.count(), signalCount);
}
void tst_QtTableSelectionManager::anchoredSelections_data()