Commit 3bcd2927 authored by Julian Helfferich's avatar Julian Helfferich 💬
Browse files

Add test for KBlocksItemGroup::refreshPosition()

Create test to verify that the positions of the individual SVG items
are set correctly. This method will need to be extended to address
bug 380474.
parent 807fb960
......@@ -22,11 +22,72 @@ class testKBlocksItemGroup : public QObject
{
Q_OBJECT
private slots:
void refreshPositionShouldSetCorrectPositions();
void updateGameShouldProcessGameActionsOnGameOver();
void updateGameShouldRefreshItemsOnGameOver();
void stopGameShouldProcessRemainingGameActions();
};
void testKBlocksItemGroup::refreshPositionShouldSetCorrectPositions()
{
/**
* When refreshPosition is called, the positions of the SVG items
* in the prepare area and the playing field are updated. The new
* positions are determined from the (possibly updated) layout.
*/
MockSingleGame singleGame;
MockGraphics graphics;
graphics.m_PreviewArea_CenterPoint_X = 1;
graphics.m_PreviewArea_CenterPoint_Y = 1;
graphics.m_Block_Size = 1;
graphics.m_PlayArea_NumberOfBlocks_X = 2;
graphics.m_PlayArea_NumberOfBlocks_Y = 2;
graphics.m_PlayArea_OffsetPoint_X = 1;
graphics.m_PlayArea_OffsetPoint_Y = 1;
MockSound sound;
TestingKBlocksItemGroup itemGroup(0, &singleGame, &graphics, &sound);
graphics.m_PreviewArea_CenterPoint_X = 30;
graphics.m_PreviewArea_CenterPoint_Y = 50;
graphics.m_Block_Size = 12;
graphics.m_PlayArea_OffsetPoint_X = 10;
graphics.m_PlayArea_OffsetPoint_Y = 15;
itemGroup.refreshPosition();
std::vector<QPointF> expectedPreparePositions{
{ 0, 20},
{12, 20},
{24, 20},
{36, 20},
{48, 20},
{ 0, 32},
{12, 32},
{24, 32},
{36, 32}
};
for (size_t i = 0; i < expectedPreparePositions.size(); ++i) {
auto *prepareCell = itemGroup.getPrepareCell(i);
QVERIFY(prepareCell != nullptr);
QCOMPARE(prepareCell->pos(), expectedPreparePositions.at(i));
}
std::vector<QPointF> expectedFreezePositions{
{10, 15},
{22, 15},
{10, 27},
{22, 27}
};
for (size_t i = 0; i < expectedFreezePositions.size(); ++i) {
auto *freezeCell = itemGroup.getFreezeCell(i);
QVERIFY(freezeCell != nullptr);
QCOMPARE(freezeCell->pos(), expectedFreezePositions.at(i));
}
}
void testKBlocksItemGroup::updateGameShouldProcessGameActionsOnGameOver()
{
/**
......
......@@ -33,7 +33,7 @@ KBlocksItemGroup::KBlocksItemGroup(int groupID, SingleGameInterface *p, Graphics
addToGroup(mpBackground);
mMaxPrepareCellNum = PREPARE_AREA_WIDTH * PREPARE_AREA_WIDTH;
maPrepareCells = new KBlocksSvgItem*[mMaxPrepareCellNum];
maPrepareCells = new SvgItemInterface*[mMaxPrepareCellNum];
for (int i = 0; i < mMaxPrepareCellNum; i++) {
maPrepareCells[i] = new KBlocksSvgItem(mpGameLayout, KBlocksSvgItem_PrepareArea,
i % PREPARE_AREA_WIDTH, i / PREPARE_AREA_WIDTH);
......
......@@ -74,14 +74,14 @@ protected:
int mMaxFreezeCellNum;
SvgItemInterface **maFreezeCells;
int mMaxPrepareCellNum;
SvgItemInterface **maPrepareCells;
private:
int mGroupID;
KBlocksSvgItem *mpBackground;
int mMaxPrepareCellNum;
KBlocksSvgItem **maPrepareCells;
SingleGameInterface *mpSingleGame;
KBlocksLayout *mpGameLayout = nullptr;
GraphicsInterface *mpGrafx = nullptr;
......
......@@ -27,6 +27,22 @@ public:
KBlocksItemGroup::updateGame();
}
SvgItemInterface *getFreezeCell(int cellNum)
{
if (cellNum < mMaxFreezeCellNum) {
return maFreezeCells[cellNum];
}
return nullptr;
}
SvgItemInterface *getPrepareCell(int cellNum)
{
if (cellNum < mMaxPrepareCellNum) {
return maPrepareCells[cellNum];
}
return nullptr;
}
void replaceFreezeCells(SvgItemInterface* newItem)
{
for (int i = 0; i < mMaxFreezeCellNum; i++) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment