Skip to content

Commit c16c857

Browse files
committed
Focus received savegame path test
1 parent 9c4b684 commit c16c857

1 file changed

Lines changed: 20 additions & 45 deletions

File tree

tests/s25Main/network/testGameClient.cpp

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -79,27 +79,6 @@ class CustomUserMapFolderFixture
7979
}
8080
};
8181

82-
void AdvanceClientToMapInfoRequest(GameClient& client, GameMessageInterface& clientMsgInterface,
83-
MockClientInterface& callbacks, const std::string& password,
84-
ServerType serverType, int serverPort)
85-
{
86-
mock::sequence s;
87-
MOCK_EXPECT(callbacks.CI_NextConnectState).in(s).with(ConnectState::Initiated).once();
88-
MOCK_EXPECT(callbacks.CI_NextConnectState).in(s).with(ConnectState::VerifyServer).once();
89-
MOCK_EXPECT(callbacks.CI_NextConnectState).in(s).with(ConnectState::QueryPw).once();
90-
MOCK_EXPECT(callbacks.CI_NextConnectState).in(s).with(ConnectState::QueryMapInfo).once();
91-
92-
BOOST_TEST_REQUIRE(client.Connect("localhost", password, serverType, serverPort, false, false));
93-
clientMsgInterface.OnGameMessage(GameMessage_Player_Id(1));
94-
client.GetMainPlayer().sendQueue.clear();
95-
96-
clientMsgInterface.OnGameMessage(GameMessage_Server_TypeOK(GameMessage_Server_TypeOK::StatusCode::Ok, ""));
97-
client.GetMainPlayer().sendQueue.clear();
98-
99-
clientMsgInterface.OnGameMessage(GameMessage_Server_Password("true"));
100-
client.GetMainPlayer().sendQueue.clear();
101-
}
102-
10382
} // namespace
10483

10584
BOOST_FIXTURE_TEST_SUITE(GameClientTests, CustomUserMapFolderFixture)
@@ -269,46 +248,42 @@ BOOST_AUTO_TEST_CASE(ClientStoresReceivedSavegamesInSaveFolder)
269248
{
270249
rttr::test::TmpFolder testUserData;
271250
rttr::test::ConfigOverride userDataOverride("USERDATA", testUserData);
251+
const boost::filesystem::path testMapPath =
252+
rttr::test::rttrBaseDir / "tests" / "testData" / "maps" / "LuaFunctions.SWD";
253+
MapInfo mapInfo;
254+
mapInfo.mapData.CompressFromFile(testMapPath, &mapInfo.mapChecksum);
255+
const auto mapDataSize = mapInfo.mapData.data.size();
272256

273257
GameClient client;
274258
GameMessageInterface& clientMsgInterface = client;
275-
MockClientInterface callbacks;
276-
client.SetInterface(&callbacks);
277259
TestServer server;
278260
const auto serverPort = server.tryListen();
279261
BOOST_TEST_REQUIRE(serverPort >= 0);
280-
const auto pw = rttr::test::randString(10);
281-
const auto serverType = rttr::test::randomEnum<ServerType>();
282-
283-
MOCK_EXPECT(callbacks.CI_NextConnectState).with(ConnectState::ReceiveMap).once();
284-
AdvanceClientToMapInfoRequest(client, clientMsgInterface, callbacks, pw, serverType, serverPort);
285-
286-
const boost::filesystem::path testMapPath =
287-
rttr::test::rttrBaseDir / "tests" / "testData" / "maps" / "LuaFunctions.SWD";
288-
MapInfo mapInfo;
289-
mapInfo.mapData.CompressFromFile(testMapPath, &mapInfo.mapChecksum);
290-
const auto mapDataSize = mapInfo.mapData.data.size();
291262

292-
clientMsgInterface.OnGameMessage(GameMessage_Map_Info("received.sav", MapType::Savegame,
293-
mapInfo.mapData.uncompressedLength, mapDataSize, 0, 0));
263+
// Map info is ignored unless the client has reached QueryMapInfo; keep this setup minimal.
264+
BOOST_TEST_REQUIRE(client.Connect("localhost", rttr::test::randString(10), rttr::test::randomEnum<ServerType>(),
265+
serverPort, false, false));
266+
clientMsgInterface.OnGameMessage(GameMessage_Player_Id(1));
267+
client.GetMainPlayer().sendQueue.clear();
268+
clientMsgInterface.OnGameMessage(GameMessage_Server_TypeOK(GameMessage_Server_TypeOK::StatusCode::Ok, ""));
269+
client.GetMainPlayer().sendQueue.clear();
270+
clientMsgInterface.OnGameMessage(GameMessage_Server_Password("true"));
271+
client.GetMainPlayer().sendQueue.clear();
294272

295273
const auto expectedSavePath = RTTRCONFIG.ExpandPath(s25::folders::save) / "received.sav";
296274
const auto unexpectedMapsPath = RTTRCONFIG.ExpandPath(s25::folders::mapsPlayed) / "received.sav";
297275
BOOST_TEST(expectedSavePath.parent_path() == testUserData / "SAVE");
298276
BOOST_TEST(unexpectedMapsPath.parent_path() == testUserData / "MAPS");
277+
278+
clientMsgInterface.OnGameMessage(
279+
GameMessage_Map_Info("received.sav", MapType::Savegame, mapInfo.mapData.uncompressedLength, mapDataSize, 0, 0));
280+
const auto msg = boost::dynamic_pointer_cast<GameMessage_MapRequest>(client.GetMainPlayer().sendQueue.pop());
281+
BOOST_TEST_REQUIRE(msg);
282+
BOOST_TEST(!msg->requestInfo);
299283
BOOST_TEST(client.GetMapType() == MapType::Savegame);
300284
BOOST_TEST(client.GetMapPath() == expectedSavePath);
301-
BOOST_TEST(client.GetMapPath() != unexpectedMapsPath);
302285

303-
const auto transferRequest =
304-
boost::dynamic_pointer_cast<GameMessage_MapRequest>(client.GetMainPlayer().sendQueue.pop());
305-
BOOST_TEST_REQUIRE(transferRequest);
306-
BOOST_TEST(!transferRequest->requestInfo);
307-
308-
MOCK_EXPECT(callbacks.CI_MapPartReceived).with(mapDataSize, mapDataSize).once();
309-
MOCK_EXPECT(callbacks.CI_Error).once();
310286
clientMsgInterface.OnGameMessage(GameMessage_Map_Data(true, 0, mapInfo.mapData.data.data(), mapDataSize));
311-
312287
BOOST_TEST(bfs::exists(expectedSavePath));
313288
BOOST_TEST(!bfs::exists(unexpectedMapsPath));
314289
}

0 commit comments

Comments
 (0)