mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
vcmi: make tests builds at least
This commit is contained in:
parent
cf2304d8c7
commit
2680046dd0
@ -1,4 +1,5 @@
|
||||
include(GoogleTest)
|
||||
include(CheckCXXCompilerFlag)
|
||||
|
||||
set(googleTest_Dir ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
|
||||
if(EXISTS ${googleTest_Dir})
|
||||
@ -148,6 +149,14 @@ set(mock_HEADERS
|
||||
if(MSVC)
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "Use shared (DLL) run-time lib even when Google Test is built as static lib." FORCE)
|
||||
endif()
|
||||
check_cxx_compiler_flag(-Wimplicit-int-float-conversion CONV)
|
||||
if(CONV)
|
||||
add_compile_options(-Wno-error=implicit-int-float-conversion) #Used in googletest
|
||||
endif()
|
||||
check_cxx_compiler_flag(-Wdeprecated-copy-with-user-provided-copy COPY)
|
||||
if(COPY)
|
||||
add_compile_options(-Wno-deprecated-copy-with-user-provided-copy) #Used in googletest
|
||||
endif()
|
||||
add_subdirectory_with_folder("3rdparty" googletest EXCLUDE_FROM_ALL)
|
||||
|
||||
add_executable(vcmitest ${test_SRCS} ${test_HEADERS} ${mock_HEADERS})
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "../../lib/CGameState.h"
|
||||
#include "../../lib/NetPacks.h"
|
||||
#include "../../lib/StartInfo.h"
|
||||
#include "../../lib/TerrainHandler.h"
|
||||
|
||||
#include "../../lib/battle/BattleInfo.h"
|
||||
#include "../../lib/CStack.h"
|
||||
@ -193,7 +194,7 @@ public:
|
||||
|
||||
const auto & t = *gameCallback->getTile(tile);
|
||||
|
||||
TerrainId terrain = t.terType->id;
|
||||
auto terrain = t.terType->getId();
|
||||
BattleField terType = BattleField::fromString("grass_hills");
|
||||
|
||||
//send info about battles
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "../lib/filesystem/ResourceID.h"
|
||||
#include "../lib/mapping/CMapService.h"
|
||||
#include "../lib/mapping/CMap.h"
|
||||
#include "../lib/TerrainHandler.h"
|
||||
#include "../lib/JsonNode.h"
|
||||
#include "../lib/mapping/CMapEditManager.h"
|
||||
#include "../lib/int3.h"
|
||||
@ -33,30 +34,30 @@ TEST(MapManager, DrawTerrain_Type)
|
||||
|
||||
// 1x1 Blow up
|
||||
editManager->getTerrainSelection().select(int3(5, 5, 0));
|
||||
editManager->drawTerrain(Terrain::GRASS);
|
||||
editManager->drawTerrain(ETerrainId::GRASS);
|
||||
static const int3 squareCheck[] = { int3(5,5,0), int3(5,4,0), int3(4,4,0), int3(4,5,0) };
|
||||
for(int i = 0; i < ARRAY_COUNT(squareCheck); ++i)
|
||||
{
|
||||
EXPECT_EQ(map->getTile(squareCheck[i]).terType->id, Terrain::GRASS);
|
||||
EXPECT_EQ(map->getTile(squareCheck[i]).terType->getId(), ETerrainId::GRASS);
|
||||
}
|
||||
|
||||
// Concat to square
|
||||
editManager->getTerrainSelection().select(int3(6, 5, 0));
|
||||
editManager->drawTerrain(Terrain::GRASS);
|
||||
EXPECT_EQ(map->getTile(int3(6, 4, 0)).terType->id, Terrain::GRASS);
|
||||
editManager->drawTerrain(ETerrainId::GRASS);
|
||||
EXPECT_EQ(map->getTile(int3(6, 4, 0)).terType->getId(), ETerrainId::GRASS);
|
||||
editManager->getTerrainSelection().select(int3(6, 5, 0));
|
||||
editManager->drawTerrain(Terrain::LAVA);
|
||||
EXPECT_EQ(map->getTile(int3(4, 4, 0)).terType->id, Terrain::GRASS);
|
||||
EXPECT_EQ(map->getTile(int3(7, 4, 0)).terType->id, Terrain::LAVA);
|
||||
editManager->drawTerrain(ETerrainId::LAVA);
|
||||
EXPECT_EQ(map->getTile(int3(4, 4, 0)).terType->getId(), ETerrainId::GRASS);
|
||||
EXPECT_EQ(map->getTile(int3(7, 4, 0)).terType->getId(), ETerrainId::LAVA);
|
||||
|
||||
// Special case water,rock
|
||||
editManager->getTerrainSelection().selectRange(MapRect(int3(10, 10, 0), 10, 5));
|
||||
editManager->drawTerrain(Terrain::GRASS);
|
||||
editManager->drawTerrain(ETerrainId::GRASS);
|
||||
editManager->getTerrainSelection().selectRange(MapRect(int3(15, 17, 0), 10, 5));
|
||||
editManager->drawTerrain(Terrain::GRASS);
|
||||
editManager->drawTerrain(ETerrainId::GRASS);
|
||||
editManager->getTerrainSelection().select(int3(21, 16, 0));
|
||||
editManager->drawTerrain(Terrain::GRASS);
|
||||
EXPECT_EQ(map->getTile(int3(20, 15, 0)).terType->id, Terrain::GRASS);
|
||||
editManager->drawTerrain(ETerrainId::GRASS);
|
||||
EXPECT_EQ(map->getTile(int3(20, 15, 0)).terType->getId(), ETerrainId::GRASS);
|
||||
|
||||
// Special case non water,rock
|
||||
static const int3 diagonalCheck[] = { int3(31,42,0), int3(32,42,0), int3(32,43,0), int3(33,43,0), int3(33,44,0),
|
||||
@ -66,16 +67,16 @@ TEST(MapManager, DrawTerrain_Type)
|
||||
{
|
||||
editManager->getTerrainSelection().select(diagonalCheck[i]);
|
||||
}
|
||||
editManager->drawTerrain(Terrain::GRASS);
|
||||
EXPECT_EQ(map->getTile(int3(35, 44, 0)).terType->id, Terrain::WATER);
|
||||
editManager->drawTerrain(ETerrainId::GRASS);
|
||||
EXPECT_EQ(map->getTile(int3(35, 44, 0)).terType->getId(), ETerrainId::WATER);
|
||||
|
||||
// Rock case
|
||||
editManager->getTerrainSelection().selectRange(MapRect(int3(1, 1, 1), 15, 15));
|
||||
editManager->drawTerrain(Terrain::SUBTERRANEAN);
|
||||
editManager->drawTerrain(ETerrainId::SUBTERRANEAN);
|
||||
std::vector<int3> vec({ int3(6, 6, 1), int3(7, 6, 1), int3(8, 6, 1), int3(5, 7, 1), int3(6, 7, 1), int3(7, 7, 1),
|
||||
int3(8, 7, 1), int3(4, 8, 1), int3(5, 8, 1), int3(6, 8, 1)});
|
||||
editManager->getTerrainSelection().setSelection(vec);
|
||||
editManager->drawTerrain(Terrain::ROCK);
|
||||
editManager->drawTerrain(ETerrainId::ROCK);
|
||||
EXPECT_TRUE(!map->getTile(int3(5, 6, 1)).terType->isPassable() || !map->getTile(int3(7, 8, 1)).terType->isPassable());
|
||||
|
||||
//todo: add checks here and enable, also use smaller size
|
||||
@ -143,7 +144,7 @@ TEST(MapManager, DrawTerrain_View)
|
||||
int3 pos((si32)posVector[0].Float(), (si32)posVector[1].Float(), (si32)posVector[2].Float());
|
||||
const auto & originalTile = originalMap->getTile(pos);
|
||||
editManager->getTerrainSelection().selectRange(MapRect(pos, 1, 1));
|
||||
editManager->drawTerrain(originalTile.terType->id, &gen);
|
||||
editManager->drawTerrain(originalTile.terType->getId(), &gen);
|
||||
const auto & tile = map->getTile(pos);
|
||||
bool isInRange = false;
|
||||
for(const auto & range : mapping)
|
||||
|
@ -18,9 +18,15 @@ class FactionID;
|
||||
class CreatureMock : public Creature
|
||||
{
|
||||
public:
|
||||
MOCK_CONST_METHOD0(getNameTranslated, std::string ());
|
||||
MOCK_CONST_METHOD0(getNameTextID, std::string ());
|
||||
MOCK_CONST_METHOD0(getNameSingularTranslated, std::string ());
|
||||
MOCK_CONST_METHOD0(getNameSingularTextID, std::string ());
|
||||
MOCK_CONST_METHOD0(getNamePluralTranslated, std::string ());
|
||||
MOCK_CONST_METHOD0(getNamePluralTextID, std::string ());
|
||||
MOCK_CONST_METHOD0(getIndex, int32_t());
|
||||
MOCK_CONST_METHOD0(getIconIndex, int32_t());
|
||||
MOCK_CONST_METHOD0(getJsonKey, const std::string &());
|
||||
MOCK_CONST_METHOD0(getJsonKey, std::string ());
|
||||
MOCK_CONST_METHOD0(getName, const std::string &());
|
||||
MOCK_CONST_METHOD0(getId, CreatureID());
|
||||
MOCK_CONST_METHOD0(getBonusBearer, const IBonusBearer *());
|
||||
|
@ -22,7 +22,7 @@ public:
|
||||
MOCK_CONST_METHOD0(getTerrainType, TerrainId());
|
||||
MOCK_CONST_METHOD0(getAllObstacles, IBattleInfo::ObstacleCList());
|
||||
MOCK_CONST_METHOD0(getDefendedTown, const CGTownInstance *());
|
||||
MOCK_CONST_METHOD1(getWallState, si8(int));
|
||||
MOCK_CONST_METHOD1(getWallState, EWallState(EWallPart));
|
||||
MOCK_CONST_METHOD0(getGateState, EGateState());
|
||||
MOCK_CONST_METHOD1(getSidePlayer, PlayerColor(ui8));
|
||||
MOCK_CONST_METHOD1(getSideArmy, const CArmedInstance *(ui8));
|
||||
@ -45,7 +45,7 @@ public:
|
||||
MOCK_METHOD2(addUnitBonus, void(uint32_t, const std::vector<Bonus> &));
|
||||
MOCK_METHOD2(updateUnitBonus, void(uint32_t, const std::vector<Bonus> &));
|
||||
MOCK_METHOD2(removeUnitBonus, void(uint32_t, const std::vector<Bonus> &));
|
||||
MOCK_METHOD2(setWallState, void(int, si8));
|
||||
MOCK_METHOD2(setWallState, void(EWallPart, EWallState));
|
||||
MOCK_METHOD1(addObstacle, void(const ObstacleChanges &));
|
||||
MOCK_METHOD1(removeObstacle, void(uint32_t));
|
||||
MOCK_METHOD1(updateObstacle, void(const ObstacleChanges &));
|
||||
|
@ -18,10 +18,14 @@ namespace spells
|
||||
class SpellMock : public Spell
|
||||
{
|
||||
public:
|
||||
MOCK_CONST_METHOD0(getNameTranslated, std::string ());
|
||||
MOCK_CONST_METHOD0(getNameTextID, std::string ());
|
||||
MOCK_CONST_METHOD1(getDescriptionTextID, std::string (int32_t));
|
||||
MOCK_CONST_METHOD1(getDescriptionTranslated, std::string (int32_t));
|
||||
MOCK_CONST_METHOD1(calculateDamage, int64_t(const Caster *));
|
||||
MOCK_CONST_METHOD0(getIndex, int32_t());
|
||||
MOCK_CONST_METHOD0(getIconIndex, int32_t());
|
||||
MOCK_CONST_METHOD0(getJsonKey, const std::string &());
|
||||
MOCK_CONST_METHOD0(getJsonKey, std::string ());
|
||||
MOCK_CONST_METHOD0(getName, const std::string &());
|
||||
MOCK_CONST_METHOD0(getId, SpellID());
|
||||
MOCK_CONST_METHOD0(getLevel, int32_t());
|
||||
|
@ -123,11 +123,11 @@ TEST_F(CatapultApplyTest, DamageToIntactPart)
|
||||
|
||||
setDefaultExpectations();
|
||||
|
||||
const EWallPart::EWallPart targetPart = EWallPart::BELOW_GATE;
|
||||
const EWallPart targetPart = EWallPart::BELOW_GATE;
|
||||
|
||||
EXPECT_CALL(*battleFake, getWallState(_)).WillRepeatedly(Return(EWallState::DESTROYED));
|
||||
EXPECT_CALL(*battleFake, getWallState(Eq(int(targetPart)))).WillRepeatedly(Return(EWallState::INTACT));
|
||||
EXPECT_CALL(*battleFake, setWallState(Eq(int(targetPart)), Eq(EWallState::DAMAGED))).Times(1);
|
||||
EXPECT_CALL(*battleFake, getWallState(Eq(targetPart))).WillRepeatedly(Return(EWallState::INTACT));
|
||||
EXPECT_CALL(*battleFake, setWallState(Eq(targetPart), Eq(EWallState::DAMAGED))).Times(1);
|
||||
EXPECT_CALL(serverMock, apply(Matcher<CatapultAttack *>(_))).Times(1);
|
||||
|
||||
EffectTarget target;
|
||||
|
@ -411,7 +411,7 @@ TEST_P(HealApplyTest, Heals)
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P
|
||||
INSTANTIATE_TEST_SUITE_P
|
||||
(
|
||||
ByConfig1,
|
||||
HealApplyTest,
|
||||
@ -422,7 +422,7 @@ INSTANTIATE_TEST_CASE_P
|
||||
)
|
||||
);
|
||||
|
||||
INSTANTIATE_TEST_CASE_P
|
||||
INSTANTIATE_TEST_SUITE_P
|
||||
(
|
||||
ByConfig2,
|
||||
HealApplyTest,
|
||||
|
@ -127,7 +127,7 @@ TEST_P(SummonTest, Transform)
|
||||
EXPECT_THAT(transformed, ContainerEq(expected));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P
|
||||
INSTANTIATE_TEST_SUITE_P
|
||||
(
|
||||
ByConfig,
|
||||
SummonTest,
|
||||
@ -270,7 +270,7 @@ TEST_P(SummonApplyTest, UpdatesOldUnit)
|
||||
subject->apply(&serverMock, &mechanicsMock, target);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P
|
||||
INSTANTIATE_TEST_SUITE_P
|
||||
(
|
||||
ByConfig,
|
||||
SummonApplyTest,
|
||||
|
@ -124,7 +124,7 @@ TEST_P(TimedApplyTest, ChangesBonuses)
|
||||
EXPECT_THAT(actualBonus, UnorderedElementsAreArray(expectedBonus));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P
|
||||
INSTANTIATE_TEST_SUITE_P
|
||||
(
|
||||
ByConfig,
|
||||
TimedApplyTest,
|
||||
|
@ -62,7 +62,7 @@ TEST_P(AbsoluteSpellConditionTest, IgnoresNormalCase)
|
||||
EXPECT_TRUE(subject->isReceptive(&mechanicsMock, &unitMock));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P
|
||||
INSTANTIATE_TEST_SUITE_P
|
||||
(
|
||||
BySpells,
|
||||
AbsoluteSpellConditionTest,
|
||||
|
@ -76,7 +76,7 @@ TEST_P(ElementalConditionTest, ImmuneIfBothBonusesPresent)
|
||||
EXPECT_FALSE(subject->isReceptive(&mechanicsMock, &unitMock));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P
|
||||
INSTANTIATE_TEST_SUITE_P
|
||||
(
|
||||
ByPositiveness,
|
||||
ElementalConditionTest,
|
||||
|
@ -68,7 +68,7 @@ TEST_P(ImmunityNegationConditionTest, WithBattleWideNegation)
|
||||
EXPECT_EQ(!ownerMatches, subject->isReceptive(&mechanicsMock, &unitMock));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P
|
||||
INSTANTIATE_TEST_SUITE_P
|
||||
(
|
||||
ByUnitOwner,
|
||||
ImmunityNegationConditionTest,
|
||||
|
@ -65,7 +65,7 @@ TEST_P(NormalSpellConditionTest, ChecksNormalCase)
|
||||
EXPECT_TRUE(subject->isReceptive(&mechanicsMock, &unitMock));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P
|
||||
INSTANTIATE_TEST_SUITE_P
|
||||
(
|
||||
BySpells,
|
||||
NormalSpellConditionTest,
|
||||
|
@ -50,7 +50,7 @@ TEST_P(ReceptiveFeatureConditionTest, isReceptive)
|
||||
EXPECT_EQ(isPositive && hasBonus, subject->isReceptive(&mechanicsMock, &unitMock));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P
|
||||
INSTANTIATE_TEST_SUITE_P
|
||||
(
|
||||
ByFlags,
|
||||
ReceptiveFeatureConditionTest,
|
||||
|
Loading…
Reference in New Issue
Block a user