Commit 35007319 authored by Julian Helfferich's avatar Julian Helfferich 💬
Browse files

Add test to get the reported bug under test

The test is currently failing: KBlocksItemGroup::updateGame() does not
call updateLayout() when the game is over. This means that the final
game actions are not processed.
parent fc62d508
......@@ -15,16 +15,16 @@
#include "Testing/MockSingleGame.h"
#include "Testing/MockSound.h"
#include "KBlocksItemGroup.h"
#include "Testing/TestingKBlocksItemGroup.h"
class testKBlocksItemGroup : public QObject
{
Q_OBJECT
private slots:
void testStopGameShouldCallUpdateLayout();
void testUpdateGameShouldProcessGameActionsOnGameOver();
};
void testKBlocksItemGroup::testStopGameShouldCallUpdateLayout()
void testKBlocksItemGroup::testUpdateGameShouldProcessGameActionsOnGameOver()
{
/**
* When the game is stopped (on game over), updateLayout needs to be
......@@ -34,10 +34,16 @@ void testKBlocksItemGroup::testStopGameShouldCallUpdateLayout()
* See bug 407244
*/
std::unique_ptr<SingleGameInterface> pSingleGame( new MockSingleGame() );
MockSingleGame *mock = dynamic_cast<MockSingleGame*>(pSingleGame.get());
mock->updateGameReturnValue = 1;
std::unique_ptr<GraphicsInterface> pGraphics( new MockGraphics() );
std::unique_ptr<SoundInterface> pSound( new MockSound() );
KBlocksItemGroup itemGroup(0, pSingleGame.get(), pGraphics.get(), pSound.get() );
QVERIFY( true );
TestingKBlocksItemGroup itemGroup(0, pSingleGame.get(), pGraphics.get(), pSound.get() );
itemGroup.callUpdateGame();
QCOMPARE( mock->numberOfPickGameActionCalls, 1 );
}
QTEST_MAIN(testKBlocksItemGroup)
......
......@@ -32,7 +32,7 @@ class KBlocksItemGroup : public QObject, public QGraphicsItemGroup
public:
KBlocksItemGroup(int groupID, SingleGameInterface *p, GraphicsInterface *pG, SoundInterface *pS, bool snapshotMode = false);
~KBlocksItemGroup();
virtual ~KBlocksItemGroup();
public:
void setUpdateInterval(int interval);
......@@ -48,8 +48,10 @@ public:
signals:
void readyForAction(int groupID);
private slots:
protected slots:
void updateGame();
private slots:
void updateSnapshot();
void endAnimation(int animType);
......
......@@ -24,6 +24,8 @@ class MockSingleGame : public SingleGameInterface
public:
MockSingleGame()
: SingleGameInterface(),
numberOfPickGameActionCalls(0),
updateGameReturnValue(0),
mockField(new MockField()),
mockPiece(new MockPiece())
{}
......@@ -39,13 +41,22 @@ public:
bool isGameRunning() override { return false; }
int forceUpdateGame() override { return 0; }
int updateGame() override { return 0; }
int updateGame() override { return updateGameReturnValue; }
int continueGame() override { return 0; }
bool setCurrentPiece(int, int, int) override { return false; }
bool pickGameResult(int *) override { return false; }
bool pickGameAction(int *, int *) override { return false; }
bool pickGameAction(int *, int *) override
{
++numberOfPickGameActionCalls;
return false;
}
public:
unsigned int numberOfPickGameActionCalls;
int updateGameReturnValue;
private:
std::unique_ptr<FieldInterface> mockField;
......
/******************************************************************************
* KBlocks, a falling blocks game by KDE *
* Copyright (C) 2010-2021 Julian Helfferich <julian.helfferich@mailbox.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
******************************************************************************/
#ifndef TESTINGKBLOCKSITEMGROUP_H
#define TESTINGKBLOCKSITEMGROUP_H
#include "KBlocksItemGroup.h"
class TestingKBlocksItemGroup : public KBlocksItemGroup
{
public:
TestingKBlocksItemGroup(int groupID, SingleGameInterface *p, GraphicsInterface *pG, SoundInterface *pS)
: KBlocksItemGroup(groupID, p, pG, pS)
{}
virtual ~TestingKBlocksItemGroup() = default;
void callUpdateGame()
{
KBlocksItemGroup::updateGame();
}
};
#endif // TESTINGKBLOCKSITEMGROUP_H
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