Skip to content

Commit

Permalink
Fix testCheats when running standalone
Browse files Browse the repository at this point in the history
The test creates a desktop instance that requires access to the
VideoDriver and potentially resources (graphics) which are not available
at this point. This leads to failures when the test is not started after
a test installing a test-videodriver in the same process.

Manually create the required instances without that desktop.
  • Loading branch information
Flamefire committed Jan 19, 2025
1 parent d2be19d commit 48d1ba8
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions tests/s25Main/integration/testCheats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later

#include "Cheats.h"
#include "GameInterface.h"
#include "GamePlayer.h"
#include "desktops/dskGameInterface.h"
#include "worldFixtures/CreateEmptyWorld.h"
#include "worldFixtures/WorldFixture.h"
#include "world/GameWorldView.h"
#include "world/GameWorldViewer.h"
#include <turtle/mock.hpp>

BOOST_AUTO_TEST_SUITE(CheatsTests)
Expand All @@ -17,17 +19,16 @@ constexpr auto worldWidth = 64;
constexpr auto worldHeight = 64;
struct CheatsFixture : WorldFixture<CreateEmptyWorld, numPlayers, worldWidth, worldHeight>
{
CheatsFixture()
: cheats{gameDesktop.GI_GetCheats()}, viewer{gameDesktop.GetView().GetViewer()}, p1HQPos{p1.GetHQPos()}
{}
CheatsFixture() : cheats(world), p1(world.GetPlayer(0)), p1HQPos(p1.GetHQPos()), viewer(0, world) {}

dskGameInterface gameDesktop{game, nullptr, 0, false};
Cheats& cheats;
const GameWorldViewer& viewer;
const GameWorldViewer& getViewer() const { return viewer; }

GamePlayer& getPlayer(unsigned id) { return world.GetPlayer(id); }
GamePlayer& p1 = getPlayer(0);
Cheats cheats;
const GamePlayer& p1;
const MapPoint p1HQPos;

private:
GameWorldViewer viewer;
};
} // namespace

Expand Down Expand Up @@ -68,13 +69,15 @@ MOCK_BASE_CLASS(MockGameInterface, GameInterface)
BOOST_FIXTURE_TEST_CASE(CanToggleAllVisible_IfCheatModeIsOn_ButOnlyDisableAllVisible_IfCheatModeIsNotOn, CheatsFixture)
{
MockGameInterface mgi;
MOCK_EXPECT(mgi.GI_GetCheats).returns(std::ref(gameDesktop.GI_GetCheats()));
MOCK_EXPECT(mgi.GI_GetCheats).returns(std::ref(this->cheats));
MOCK_EXPECT(mgi.GI_UpdateMapVisibility).exactly(4); // because the actual toggling should occur 4 times
world.SetGameInterface(&mgi);

MapPoint farawayPos = p1HQPos;
farawayPos.x += 20;

const auto& viewer = getViewer();

// initially farawayPos is not visible
BOOST_TEST_REQUIRE((viewer.GetVisibility(farawayPos) == Visibility::Visible) == false);

Expand Down

0 comments on commit 48d1ba8

Please sign in to comment.