|
2 | 2 | // |
3 | 3 | // SPDX-License-Identifier: GPL-2.0-or-later |
4 | 4 |
|
| 5 | +#include "GameCommands.h" |
5 | 6 | #include "GamePlayer.h" |
6 | 7 | #include "PointOutput.h" |
7 | 8 | #include "RttrForeachPt.h" |
|
12 | 13 | #include "enum_cast.hpp" |
13 | 14 | #include "factories/BuildingFactory.h" |
14 | 15 | #include "figures/nofPassiveSoldier.h" |
| 16 | +#include "helpers/serializeEnums.h" |
| 17 | +#include "helpers/serializePoint.h" |
15 | 18 | #include "postSystem/PostBox.h" |
16 | 19 | #include "worldFixtures/WorldWithGCExecution.h" |
17 | 20 | #include "worldFixtures/initGameRNG.hpp" |
@@ -53,8 +56,41 @@ static void dummySuppressUnused(std::ostream& out) |
53 | 56 | } |
54 | 57 | // LCOV_EXCL_STOP |
55 | 58 |
|
| 59 | +namespace { |
| 60 | +// Expose the protected constructors only to serialize the actual command format in this test, |
| 61 | +// rather than duplicating the production Serialize() implementation. |
| 62 | +class TestSetTroopLimit : public gc::SetTroopLimit |
| 63 | +{ |
| 64 | +public: |
| 65 | + TestSetTroopLimit(const MapPoint pt, const uint8_t rank, const uint32_t count) : gc::SetTroopLimit(pt, rank, count) |
| 66 | + {} |
| 67 | +}; |
| 68 | + |
| 69 | +class TestChangeReserve : public gc::ChangeReserve |
| 70 | +{ |
| 71 | +public: |
| 72 | + TestChangeReserve(const MapPoint pt, const uint8_t rank, const uint32_t count) : gc::ChangeReserve(pt, rank, count) |
| 73 | + {} |
| 74 | +}; |
| 75 | +} // namespace |
| 76 | + |
56 | 77 | BOOST_AUTO_TEST_SUITE(GameCommandSuite) |
57 | 78 |
|
| 79 | +BOOST_AUTO_TEST_CASE(SoldierRankCommandsRejectInvalidSerializedRank) |
| 80 | +{ |
| 81 | + constexpr auto invalidRank = static_cast<uint8_t>(MAX_MILITARY_RANK + 1u); |
| 82 | + const auto pt = rttr::test::randomPoint<MapPoint>(); |
| 83 | + const auto count = rttr::test::randomValue<unsigned>(); |
| 84 | + |
| 85 | + gc::Deserializer troopLimitCommand; |
| 86 | + TestSetTroopLimit(pt, invalidRank, count).Serialize(troopLimitCommand); |
| 87 | + BOOST_REQUIRE_THROW(gc::GameCommand::Deserialize(troopLimitCommand), std::range_error); |
| 88 | + |
| 89 | + gc::Deserializer reserveCommand; |
| 90 | + TestChangeReserve(pt, invalidRank, count).Serialize(reserveCommand); |
| 91 | + BOOST_REQUIRE_THROW(gc::GameCommand::Deserialize(reserveCommand), std::range_error); |
| 92 | +} |
| 93 | + |
58 | 94 | BOOST_FIXTURE_TEST_CASE(PlaceFlagTest, WorldWithGCExecution2P) |
59 | 95 | { |
60 | 96 | (void)&dummySuppressUnused; |
|
0 commit comments