@@ -79,6 +79,27 @@ 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+
82103} // namespace
83104
84105BOOST_FIXTURE_TEST_SUITE (GameClientTests, CustomUserMapFolderFixture)
@@ -246,6 +267,9 @@ BOOST_DATA_TEST_CASE(ClientFollowsConnectProtocol, usesLuaScriptValues, usesLuaS
246267
247268BOOST_AUTO_TEST_CASE (ClientStoresReceivedSavegamesInSaveFolder)
248269{
270+ rttr::test::TmpFolder testUserData;
271+ rttr::test::ConfigOverride userDataOverride (" USERDATA" , testUserData);
272+
249273 GameClient client;
250274 GameMessageInterface& clientMsgInterface = client;
251275 MockClientInterface callbacks;
@@ -256,26 +280,8 @@ BOOST_AUTO_TEST_CASE(ClientStoresReceivedSavegamesInSaveFolder)
256280 const auto pw = rttr::test::randString (10 );
257281 const auto serverType = rttr::test::randomEnum<ServerType>();
258282
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 );
283+ MOCK_EXPECT (callbacks.CI_NextConnectState ).with (ConnectState::ReceiveMap).once ();
284+ AdvanceClientToMapInfoRequest (client, clientMsgInterface, callbacks, pw, serverType, serverPort);
279285
280286 const boost::filesystem::path testMapPath =
281287 rttr::test::rttrBaseDir / " tests" / " testData" / " maps" / " LuaFunctions.SWD" ;
@@ -288,11 +294,14 @@ BOOST_AUTO_TEST_CASE(ClientStoresReceivedSavegamesInSaveFolder)
288294
289295 const auto expectedSavePath = RTTRCONFIG .ExpandPath (s25::folders::save) / " received.sav" ;
290296 const auto unexpectedMapsPath = RTTRCONFIG .ExpandPath (s25::folders::mapsPlayed) / " received.sav" ;
297+ BOOST_TEST (expectedSavePath.parent_path () == testUserData / " SAVE" );
298+ BOOST_TEST (unexpectedMapsPath.parent_path () == testUserData / " MAPS" );
291299 BOOST_TEST (client.GetMapType () == MapType::Savegame);
292300 BOOST_TEST (client.GetMapPath () == expectedSavePath);
293301 BOOST_TEST (client.GetMapPath () != unexpectedMapsPath);
294302
295- const auto transferRequest = boost::dynamic_pointer_cast<GameMessage_MapRequest>(client.GetMainPlayer ().sendQueue .pop ());
303+ const auto transferRequest =
304+ boost::dynamic_pointer_cast<GameMessage_MapRequest>(client.GetMainPlayer ().sendQueue .pop ());
296305 BOOST_TEST_REQUIRE (transferRequest);
297306 BOOST_TEST (!transferRequest->requestInfo );
298307
0 commit comments