-
Notifications
You must be signed in to change notification settings - Fork 964
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a18e0f
commit 2337266
Showing
10 changed files
with
144 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
Tests/FeatureTests/HudFeaturesTests/BombTimerTests/BombTimerToggleTests.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <gmock/gmock.h> | ||
#include <gtest/gtest.h> | ||
|
||
#include <Fakes/FakeBombTimerState.h> | ||
#include <Features/Hud/BombTimer/BombTimerToggle.h> | ||
#include <Mocks/MockBombTimerContext.h> | ||
#include <Mocks/MockBombTimerPanel.h> | ||
#include <Mocks/MockGameBombStatusPanel.h> | ||
|
||
class BombTimerToggleTest : public testing::Test { | ||
protected: | ||
BombTimerToggleTest() | ||
{ | ||
EXPECT_CALL(mockBombTimerContext, state()).WillOnce(testing::ReturnRef(state)); | ||
} | ||
|
||
testing::StrictMock<MockBombTimerContext> mockBombTimerContext; | ||
testing::StrictMock<MockGameBombStatusPanel> mockGameBombStatusPanel; | ||
testing::StrictMock<MockBombTimerPanel> mockBombTimerPanel; | ||
|
||
BombTimerToggle<MockBombTimerContext&> bombTimerToggle{mockBombTimerContext}; | ||
FakeBombTimerState state; | ||
}; | ||
|
||
TEST_F(BombTimerToggleTest, EnablingSetsEnabledVariableToTrue) { | ||
state.enabled = false; | ||
bombTimerToggle.enable(); | ||
EXPECT_EQ(state.enabled, true); | ||
} | ||
|
||
TEST_F(BombTimerToggleTest, EnablingDoesNothingIfAlreadyEnabled) { | ||
state.enabled = true; | ||
bombTimerToggle.enable(); | ||
EXPECT_EQ(state.enabled, true); | ||
} | ||
|
||
TEST_F(BombTimerToggleTest, DisablingDoesNothingIfAlreadyDisabled) { | ||
state.enabled = false; | ||
bombTimerToggle.disable(); | ||
EXPECT_EQ(state.enabled, false); | ||
} | ||
|
||
TEST_F(BombTimerToggleTest, DisablingRestoresBombStatusPanelAndHidesBombTimerPanel) { | ||
state.enabled = true; | ||
|
||
EXPECT_CALL(mockBombTimerContext, gameBombStatusPanel()).WillOnce(testing::ReturnRef(mockGameBombStatusPanel)); | ||
EXPECT_CALL(mockGameBombStatusPanel, restore()); | ||
|
||
EXPECT_CALL(mockBombTimerContext, bombTimerPanel()).WillOnce(testing::ReturnRef(mockBombTimerPanel)); | ||
EXPECT_CALL(mockBombTimerPanel, hide()); | ||
|
||
bombTimerToggle.disable(); | ||
|
||
EXPECT_EQ(state.enabled, false); | ||
} |
60 changes: 60 additions & 0 deletions
60
Tests/FeatureTests/HudFeaturesTests/DefusingAlertTests/DefusingAlertPanelTests.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include <optional> | ||
|
||
#include <gmock/gmock.h> | ||
#include <gtest/gtest.h> | ||
|
||
#include <Features/Hud/DefusingAlert/DefusingAlertPanel.h> | ||
#include <Mocks/MockDefusingAlertContext.h> | ||
#include <Mocks/MockDefusingCountdownTextPanel.h> | ||
#include <Mocks/MockPanel.h> | ||
#include <Mocks/MockPlantedC4.h> | ||
|
||
class DefusingAlertPanelTest : public testing::Test { | ||
protected: | ||
testing::StrictMock<MockDefusingAlertContext> mockDefusingAlertContext; | ||
testing::StrictMock<MockPanel> mockDefusingAlertContainerPanel; | ||
testing::StrictMock<MockDefusingCountdownTextPanel> mockDefusingCountdownTextPanel; | ||
testing::StrictMock<MockPlantedC4> mockPlantedC4; | ||
|
||
DefusingAlertPanel<MockDefusingAlertContext&> defusingAlertPanel{mockDefusingAlertContext}; | ||
}; | ||
|
||
TEST_F(DefusingAlertPanelTest, HidesDefusingAlertContainerPanel) { | ||
EXPECT_CALL(mockDefusingAlertContext, defusingAlertContainerPanel()).WillOnce(testing::ReturnRef(mockDefusingAlertContainerPanel)); | ||
EXPECT_CALL(mockDefusingAlertContainerPanel, hide()); | ||
|
||
defusingAlertPanel.hide(); | ||
} | ||
|
||
struct DefusingAlertPanelTestParam { | ||
std::optional<float> timeToDefuseEnd{3.34f}; | ||
std::optional<bool> canBeDefused{true}; | ||
}; | ||
|
||
class DefusingAlertPanelTestWithParam : public DefusingAlertPanelTest, public testing::WithParamInterface<DefusingAlertPanelTestParam> { | ||
}; | ||
|
||
TEST_P(DefusingAlertPanelTestWithParam, ShowsDefusingAlertContainerPanelAndUpdatesCountdownTextPanel) { | ||
EXPECT_CALL(mockDefusingAlertContext, defusingAlertContainerPanel()).WillOnce(testing::ReturnRef(mockDefusingAlertContainerPanel)); | ||
EXPECT_CALL(mockDefusingAlertContainerPanel, show()); | ||
|
||
EXPECT_CALL(mockDefusingAlertContext, defusingCountdownTextPanel()).WillOnce(testing::ReturnRef(mockDefusingCountdownTextPanel)); | ||
EXPECT_CALL(mockDefusingCountdownTextPanel, setTimeToDefuseEnd(GetParam().timeToDefuseEnd)).WillOnce(testing::ReturnRef(mockDefusingCountdownTextPanel)); | ||
EXPECT_CALL(mockDefusingCountdownTextPanel, setCanBeDefused(GetParam().canBeDefused)).WillOnce(testing::ReturnRef(mockDefusingCountdownTextPanel)); | ||
|
||
EXPECT_CALL(mockPlantedC4, getTimeToDefuseEnd()).WillOnce(testing::Return(GetParam().timeToDefuseEnd)); | ||
EXPECT_CALL(mockPlantedC4, canBeDefused()).WillOnce(testing::Return(GetParam().canBeDefused)); | ||
|
||
defusingAlertPanel.showAndUpdate(mockPlantedC4); | ||
} | ||
|
||
INSTANTIATE_TEST_SUITE_P(, DefusingAlertPanelTestWithParam, testing::Values( | ||
DefusingAlertPanelTestParam{.timeToDefuseEnd = 0.0f}, | ||
DefusingAlertPanelTestParam{.timeToDefuseEnd = 3.45f}, | ||
DefusingAlertPanelTestParam{.timeToDefuseEnd = 10.0f}, | ||
DefusingAlertPanelTestParam{.timeToDefuseEnd = std::nullopt}, | ||
DefusingAlertPanelTestParam{.canBeDefused = false}, | ||
DefusingAlertPanelTestParam{.canBeDefused = true}, | ||
DefusingAlertPanelTestParam{.canBeDefused = std::nullopt}, | ||
DefusingAlertPanelTestParam{.timeToDefuseEnd = std::nullopt, .canBeDefused = std::nullopt} | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
struct MockDefusingCountdownTextPanel; | ||
struct MockPanel; | ||
|
||
struct MockDefusingAlertContext { | ||
MOCK_METHOD(MockPanel&, defusingAlertContainerPanel, ()); | ||
MOCK_METHOD(MockDefusingCountdownTextPanel&, defusingCountdownTextPanel, ()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
|
||
#include <optional> | ||
|
||
#include <gmock/gmock.h> | ||
|
||
struct MockDefusingCountdownTextPanel { | ||
MOCK_METHOD(MockDefusingCountdownTextPanel&, setTimeToDefuseEnd, (std::optional<float> timeToDefuseEnd)); | ||
MOCK_METHOD(MockDefusingCountdownTextPanel&, setCanBeDefused, (std::optional<bool> canBeDefused)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
#pragma once | ||
|
||
#include <optional> | ||
|
||
#include <gmock/gmock.h> | ||
|
||
struct MockPlantedC4 { | ||
MOCK_METHOD(const char*, getBombSiteIconUrl, ()); | ||
MOCK_METHOD(float, getTimeToExplosion, ()); | ||
MOCK_METHOD(std::optional<float>, getTimeToDefuseEnd, ()); | ||
MOCK_METHOD(std::optional<bool>, canBeDefused, ()); | ||
}; |