mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
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>
35 lines
1.1 KiB
C++
35 lines
1.1 KiB
C++
#ifndef COCKATRICE_TEST_MODEL_CONTRACT_CHECKER_H
|
|
#define COCKATRICE_TEST_MODEL_CONTRACT_CHECKER_H
|
|
|
|
#include <QAbstractItemModel>
|
|
#include <QAbstractItemModelTester>
|
|
#include <memory>
|
|
|
|
namespace test_support
|
|
{
|
|
/**
|
|
* @brief Keeps a QAbstractItemModelTester alive for the lifetime of a scope.
|
|
*
|
|
* The tester only observes the model while it exists, so construct this before
|
|
* the mutations a test wants to validate and keep it in scope until the end.
|
|
* Fatal reporting mode aborts on the first contract violation; a warning would
|
|
* let the test pass while printing a line nobody reads in CI.
|
|
*/
|
|
class ModelContractChecker
|
|
{
|
|
public:
|
|
explicit ModelContractChecker(QAbstractItemModel *model)
|
|
: tester(
|
|
std::make_unique<QAbstractItemModelTester>(model, QAbstractItemModelTester::FailureReportingMode::Fatal))
|
|
{
|
|
}
|
|
|
|
ModelContractChecker(const ModelContractChecker &) = delete;
|
|
ModelContractChecker &operator=(const ModelContractChecker &) = delete;
|
|
|
|
private:
|
|
std::unique_ptr<QAbstractItemModelTester> tester;
|
|
};
|
|
} // namespace test_support
|
|
|
|
#endif // COCKATRICE_TEST_MODEL_CONTRACT_CHECKER_H
|