|
|
|
|
@ -80,84 +80,84 @@ void HistoryModelTest::testInsertRemove() |
|
|
|
|
history->insert(QSharedPointer<HistoryItem>(new HistoryStringItem(fooText))); |
|
|
|
|
QModelIndex index = history->index(0, 0); |
|
|
|
|
QCOMPARE(index.data().toString(), fooText); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->next_uuid(), index.data(Qt::UserRole + 1).toByteArray()); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->previous_uuid(), index.data(Qt::UserRole + 1).toByteArray()); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->next_uuid(), index.data(HistoryModel::UuidRole).toByteArray()); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->previous_uuid(), index.data(HistoryModel::UuidRole).toByteArray()); |
|
|
|
|
|
|
|
|
|
history->insert(QSharedPointer<HistoryItem>(new HistoryStringItem(barText))); |
|
|
|
|
QCOMPARE(index.data().toString(), barText); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->next_uuid(), fooUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->previous_uuid(), fooUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->next_uuid(), fooUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->previous_uuid(), fooUuid); |
|
|
|
|
index = history->indexOf(fooUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->next_uuid(), barUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->previous_uuid(), barUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->next_uuid(), barUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->previous_uuid(), barUuid); |
|
|
|
|
|
|
|
|
|
history->insert(QSharedPointer<HistoryItem>(new HistoryStringItem(fooBarText))); |
|
|
|
|
QCOMPARE(history->data(history->index(0, 0)).toString(), fooBarText); |
|
|
|
|
index = history->index(0, 0); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->next_uuid(), barUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->previous_uuid(), fooUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->next_uuid(), barUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->previous_uuid(), fooUuid); |
|
|
|
|
index = history->indexOf(fooUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->next_uuid(), foobarUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->previous_uuid(), barUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->next_uuid(), foobarUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->previous_uuid(), barUuid); |
|
|
|
|
index = history->indexOf(barUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->next_uuid(), fooUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->previous_uuid(), foobarUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->next_uuid(), fooUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->previous_uuid(), foobarUuid); |
|
|
|
|
|
|
|
|
|
// insert one again - it should be moved to top
|
|
|
|
|
history->insert(QSharedPointer<HistoryItem>(new HistoryStringItem(barText))); |
|
|
|
|
QCOMPARE(history->data(history->index(0, 0)).toString(), barText); |
|
|
|
|
index = history->index(0, 0); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->next_uuid(), foobarUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->previous_uuid(), fooUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->next_uuid(), foobarUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->previous_uuid(), fooUuid); |
|
|
|
|
index = history->indexOf(fooUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->next_uuid(), barUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->previous_uuid(), foobarUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->next_uuid(), barUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->previous_uuid(), foobarUuid); |
|
|
|
|
index = history->indexOf(foobarUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->next_uuid(), fooUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->previous_uuid(), barUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->next_uuid(), fooUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->previous_uuid(), barUuid); |
|
|
|
|
|
|
|
|
|
// move one to top using the slot
|
|
|
|
|
// already on top, shouldn't change anything
|
|
|
|
|
history->moveToTop(barUuid); |
|
|
|
|
QCOMPARE(history->data(history->index(0, 0)).toString(), barText); |
|
|
|
|
index = history->index(0, 0); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->next_uuid(), foobarUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->previous_uuid(), fooUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->next_uuid(), foobarUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->previous_uuid(), fooUuid); |
|
|
|
|
index = history->indexOf(fooUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->next_uuid(), barUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->previous_uuid(), foobarUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->next_uuid(), barUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->previous_uuid(), foobarUuid); |
|
|
|
|
index = history->indexOf(foobarUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->next_uuid(), fooUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->previous_uuid(), barUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->next_uuid(), fooUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->previous_uuid(), barUuid); |
|
|
|
|
|
|
|
|
|
// another one should change, though
|
|
|
|
|
history->moveToTop(foobarUuid); |
|
|
|
|
QCOMPARE(history->data(history->index(0, 0)).toString(), fooBarText); |
|
|
|
|
index = history->index(0, 0); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->next_uuid(), barUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->previous_uuid(), fooUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->next_uuid(), barUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->previous_uuid(), fooUuid); |
|
|
|
|
index = history->indexOf(fooUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->next_uuid(), foobarUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->previous_uuid(), barUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->next_uuid(), foobarUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->previous_uuid(), barUuid); |
|
|
|
|
index = history->indexOf(barUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->next_uuid(), fooUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->previous_uuid(), foobarUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->next_uuid(), fooUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->previous_uuid(), foobarUuid); |
|
|
|
|
|
|
|
|
|
// remove them again
|
|
|
|
|
QVERIFY(history->remove(foobarUuid)); |
|
|
|
|
QCOMPARE(history->data(history->index(0, 0)).toString(), barText); |
|
|
|
|
index = history->index(0, 0); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->next_uuid(), fooUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->previous_uuid(), fooUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->next_uuid(), fooUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->previous_uuid(), fooUuid); |
|
|
|
|
index = history->indexOf(fooUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->next_uuid(), barUuid); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->previous_uuid(), barUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->next_uuid(), barUuid); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->previous_uuid(), barUuid); |
|
|
|
|
|
|
|
|
|
QVERIFY(history->remove(barUuid)); |
|
|
|
|
QCOMPARE(history->data(history->index(0, 0)).toString(), fooText); |
|
|
|
|
index = history->index(0, 0); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->next_uuid(), index.data(Qt::UserRole + 1).toByteArray()); |
|
|
|
|
QCOMPARE(index.data(Qt::UserRole).value<HistoryItemConstPtr>()->previous_uuid(), index.data(Qt::UserRole + 1).toByteArray()); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->next_uuid(), index.data(HistoryModel::UuidRole).toByteArray()); |
|
|
|
|
QCOMPARE(index.data(HistoryModel::HistoryItemConstPtrRole).value<HistoryItemConstPtr>()->previous_uuid(), index.data(HistoryModel::UuidRole).toByteArray()); |
|
|
|
|
|
|
|
|
|
QVERIFY(history->remove(fooUuid)); |
|
|
|
|
QCOMPARE(history->rowCount(), 0); |
|
|
|
|
@ -200,7 +200,7 @@ void HistoryModelTest::testIndexOf() |
|
|
|
|
QVERIFY(!history->indexOf(QByteArray()).isValid()); |
|
|
|
|
const QByteArray fooUuid = QCryptographicHash::hash(QByteArrayLiteral("foo"), QCryptographicHash::Sha1); |
|
|
|
|
QVERIFY(history->indexOf(fooUuid).isValid()); |
|
|
|
|
QCOMPARE(history->indexOf(fooUuid).data(Qt::UserRole + 1).toByteArray(), fooUuid); |
|
|
|
|
QCOMPARE(history->indexOf(fooUuid).data(HistoryModel::UuidRole).toByteArray(), fooUuid); |
|
|
|
|
|
|
|
|
|
history->clear(); |
|
|
|
|
QVERIFY(!history->indexOf(fooUuid).isValid()); |
|
|
|
|
@ -229,7 +229,7 @@ void HistoryModelTest::testType() |
|
|
|
|
QFETCH(HistoryItem *, item); |
|
|
|
|
QFETCH(HistoryItemType, expectedType); |
|
|
|
|
history->insert(QSharedPointer<HistoryItem>(item)); |
|
|
|
|
QCOMPARE(history->index(0).data(Qt::UserRole + 2).value<HistoryItemType>(), expectedType); |
|
|
|
|
QCOMPARE(history->index(0).data(HistoryModel::TypeRole).value<HistoryItemType>(), expectedType); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QTEST_MAIN(HistoryModelTest) |
|
|
|
|
|