mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-08 17:13:57 -07:00
feat(command-zone): add logic layer with tests
Implement CommandZoneLogic - the card data management layer for zones. This layer handles card insertion, removal, and ordering independently of Qt graphics rendering. Key components: - CommandZoneLogic: manages card data within a zone - AddCardAlgorithm: generic insertion algorithm for ordered zones - CardZoneLogic modifications: integrate with existing zone hierarchy Design decisions: - Separation of data logic from graphics enables unit testing - addCardImpl uses a stable insertion algorithm for consistent ordering - Mock card items enable testing without Qt graphics dependencies Test coverage verifies card insertion behavior across edge cases.
This commit is contained in:
parent
3c2e4a3fb2
commit
8422357878
10 changed files with 480 additions and 5 deletions
4
tests/command_zone/mocks/mock_card_item.cpp
Normal file
4
tests/command_zone/mocks/mock_card_item.cpp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#include "mock_card_item.h"
|
||||
|
||||
// MOC requires at least one non-inline method in a translation unit
|
||||
// when using Q_OBJECT macro. This file provides that.
|
||||
72
tests/command_zone/mocks/mock_card_item.h
Normal file
72
tests/command_zone/mocks/mock_card_item.h
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/**
|
||||
* @file mock_card_item.h
|
||||
* @brief Lightweight CardItem stub for command zone unit tests.
|
||||
*
|
||||
* This mock provides minimal CardItem functionality needed to test
|
||||
* CommandZoneLogic::addCardImpl without pulling in graphics dependencies.
|
||||
*/
|
||||
|
||||
#ifndef MOCK_CARD_ITEM_H
|
||||
#define MOCK_CARD_ITEM_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
/**
|
||||
* @brief Stub CardRef for tests (avoids network/protobuf dependencies)
|
||||
*/
|
||||
struct CardRef
|
||||
{
|
||||
QString name;
|
||||
QString setCode;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Lightweight CardItem mock for testing zone logic.
|
||||
*
|
||||
* Tracks method calls and state changes for verification in tests.
|
||||
*/
|
||||
class MockCardItem : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MockCardItem(int _id = 1, QObject *parent = nullptr) : QObject(parent), id(_id)
|
||||
{
|
||||
}
|
||||
|
||||
// State tracking
|
||||
int id;
|
||||
bool visible = false;
|
||||
bool resetStateCalled = false;
|
||||
bool resetStateShowFaceDown = false;
|
||||
CardRef cardRef;
|
||||
|
||||
// CardItem interface methods used by CommandZoneLogic::addCardImpl
|
||||
[[nodiscard]] int getId() const
|
||||
{
|
||||
return id;
|
||||
}
|
||||
void setId(int _id)
|
||||
{
|
||||
id = _id;
|
||||
}
|
||||
void setVisible(bool v)
|
||||
{
|
||||
visible = v;
|
||||
}
|
||||
[[nodiscard]] bool isVisible() const
|
||||
{
|
||||
return visible;
|
||||
}
|
||||
void resetState(bool showFaceDown)
|
||||
{
|
||||
resetStateCalled = true;
|
||||
resetStateShowFaceDown = showFaceDown;
|
||||
}
|
||||
void setCardRef(const CardRef &ref)
|
||||
{
|
||||
cardRef = ref;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // MOCK_CARD_ITEM_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue