@@ -244,6 +244,65 @@ BOOST_DATA_TEST_CASE(ClientFollowsConnectProtocol, usesLuaScriptValues, usesLuaS
244244 }
245245}
246246
247+ BOOST_AUTO_TEST_CASE (ClientStoresReceivedSavegamesInSaveFolder)
248+ {
249+ GameClient client;
250+ GameMessageInterface& clientMsgInterface = client;
251+ MockClientInterface callbacks;
252+ client.SetInterface (&callbacks);
253+ TestServer server;
254+ const auto serverPort = server.tryListen ();
255+ BOOST_TEST_REQUIRE (serverPort >= 0 );
256+ const auto pw = rttr::test::randString (10 );
257+ const auto serverType = rttr::test::randomEnum<ServerType>();
258+
259+ mock::sequence s;
260+ MOCK_EXPECT (callbacks.CI_NextConnectState ).in (s).with (ConnectState::Initiated).once ();
261+ MOCK_EXPECT (callbacks.CI_NextConnectState ).in (s).with (ConnectState::VerifyServer).once ();
262+ MOCK_EXPECT (callbacks.CI_NextConnectState ).in (s).with (ConnectState::QueryPw).once ();
263+ MOCK_EXPECT (callbacks.CI_NextConnectState ).in (s).with (ConnectState::QueryMapInfo).once ();
264+ MOCK_EXPECT (callbacks.CI_NextConnectState ).in (s).with (ConnectState::ReceiveMap).once ();
265+
266+ BOOST_TEST_REQUIRE (client.Connect (" localhost" , pw, serverType, serverPort, false , false ));
267+ clientMsgInterface.OnGameMessage (GameMessage_Player_Id (1 ));
268+ BOOST_TEST_REQUIRE (boost::dynamic_pointer_cast<GameMessage_Server_Type>(client.GetMainPlayer ().sendQueue .pop ()));
269+
270+ clientMsgInterface.OnGameMessage (GameMessage_Server_TypeOK (GameMessage_Server_TypeOK::StatusCode::Ok, " " ));
271+ BOOST_TEST_REQUIRE (boost::dynamic_pointer_cast<GameMessage_Server_Password>(client.GetMainPlayer ().sendQueue .pop ()));
272+
273+ clientMsgInterface.OnGameMessage (GameMessage_Server_Password (" true" ));
274+ BOOST_TEST_REQUIRE (dynamic_cast <GameMessage_Player_Name*>(client.GetMainPlayer ().sendQueue .pop ().get ()));
275+ BOOST_TEST_REQUIRE (dynamic_cast <GameMessage_Player_Portrait*>(client.GetMainPlayer ().sendQueue .pop ().get ()));
276+ const auto infoRequest = boost::dynamic_pointer_cast<GameMessage_MapRequest>(client.GetMainPlayer ().sendQueue .pop ());
277+ BOOST_TEST_REQUIRE (infoRequest);
278+ BOOST_TEST (infoRequest->requestInfo );
279+
280+ const boost::filesystem::path testMapPath =
281+ rttr::test::rttrBaseDir / " tests" / " testData" / " maps" / " LuaFunctions.SWD" ;
282+ MapInfo mapInfo;
283+ mapInfo.mapData .CompressFromFile (testMapPath, &mapInfo.mapChecksum );
284+ const auto mapDataSize = mapInfo.mapData .data .size ();
285+
286+ clientMsgInterface.OnGameMessage (GameMessage_Map_Info (" received.sav" , MapType::Savegame,
287+ mapInfo.mapData .uncompressedLength , mapDataSize, 0 , 0 ));
288+
289+ const auto expectedSavePath = RTTRCONFIG.ExpandPath (s25::folders::save) / " received.sav" ;
290+ const auto unexpectedMapsPath = RTTRCONFIG.ExpandPath (s25::folders::mapsPlayed) / " received.sav" ;
291+ BOOST_TEST (client.GetMapType () == MapType::Savegame);
292+ BOOST_TEST (client.GetMapPath () == expectedSavePath);
293+ BOOST_TEST (client.GetMapPath () != unexpectedMapsPath);
294+
295+ const auto transferRequest = boost::dynamic_pointer_cast<GameMessage_MapRequest>(client.GetMainPlayer ().sendQueue .pop ());
296+ BOOST_TEST_REQUIRE (transferRequest);
297+ BOOST_TEST (!transferRequest->requestInfo );
298+
299+ MOCK_EXPECT (callbacks.CI_MapPartReceived ).with (mapDataSize, mapDataSize).once ();
300+ MOCK_EXPECT (callbacks.CI_Error ).once ();
301+ clientMsgInterface.OnGameMessage (GameMessage_Map_Data (true , 0 , mapInfo.mapData .data .data (), mapDataSize));
302+
303+ BOOST_TEST (bfs::exists (expectedSavePath));
304+ BOOST_TEST (!bfs::exists (unexpectedMapsPath));
305+ }
247306BOOST_AUTO_TEST_CASE (ClientDetectsMapBufferOverflow)
248307{
249308 rttr::test::LogAccessor _suppressLogOutput;
0 commit comments