mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
[Tests] Use QtTest for model contracts and signal spies (#7630)
Qt6::Test was linked into every test but never used. Add a small RAII QAbstractItemModelTester helper and apply it to the deck list model, the card database model and display proxy, and the sets model. Add QSignalSpy coverage for the card-added and download-settings signals, and assert explicitly that a card row is a leaf with no child columns (the tester does not check that). The contract checker immediately found four model bugs, fixed here: - DeckListModel allowed children below non-zero columns. - CardDatabaseModel reported every card as a child of every card row. - CardDatabaseModel reported six columns for a valid (leaf) card index. - CardDatabaseDisplayModel claimed more rows were fetchable while rowCount already exposed them all, so fetchMore() inserted duplicates. Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
429eb2a1fd
commit
ce543896f5
9 changed files with 207 additions and 46 deletions
|
|
@ -27,14 +27,18 @@ CardDatabaseModel::CardDatabaseModel(CardDatabase *_db, bool _showOnlyCardsFromE
|
|||
|
||||
CardDatabaseModel::~CardDatabaseModel() = default;
|
||||
|
||||
int CardDatabaseModel::rowCount(const QModelIndex & /*parent*/) const
|
||||
int CardDatabaseModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return cardList.size();
|
||||
// A list model's card rows are leaves; returning the full card count for a
|
||||
// valid parent makes every row claim all cards as children.
|
||||
return parent.isValid() ? 0 : cardList.size();
|
||||
}
|
||||
|
||||
int CardDatabaseModel::columnCount(const QModelIndex & /*parent*/) const
|
||||
int CardDatabaseModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return CARDDBMODEL_COLUMNS;
|
||||
// Card rows are leaves, so a valid parent holds no columns. Reporting the
|
||||
// row width for a card index would claim child cells that do not exist.
|
||||
return parent.isValid() ? 0 : CARDDBMODEL_COLUMNS;
|
||||
}
|
||||
|
||||
QVariant CardDatabaseModel::data(const QModelIndex &index, int role) const
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue