From 5dbfb9090adcb9bd917d0e1c45d1aa90adc393d3 Mon Sep 17 00:00:00 2001 From: Leonid Pospelov Date: Thu, 19 Dec 2024 10:22:11 +0000 Subject: [PATCH] fix-some-tests --- unit/PartOneTest.cpp | 19 ++++++++++++------- unit/PartOne_ActivateTest.cpp | 25 +++++++++++++++---------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/unit/PartOneTest.cpp b/unit/PartOneTest.cpp index f30cb39853..934031c8a3 100644 --- a/unit/PartOneTest.cpp +++ b/unit/PartOneTest.cpp @@ -44,8 +44,9 @@ TEST_CASE("OnCustomPacket", "[PartOne]") DoConnect(partOne, 0); DoMessage(partOne, 0, - nlohmann::json{ { "t", MsgType::CustomPacket }, - { "content", { { "x", "y" } } } }); + nlohmann::json{ + { "t", MsgType::CustomPacket }, + { "contentJsonDump", nlohmann::json{ { "x", "y" } }.dump() } }); REQUIRE_THAT(lst->str(), ContainsSubstring("OnCustomPacket(0, {\"x\":\"y\"})")); @@ -61,7 +62,8 @@ TEST_CASE("Messages for non-existent users", "[PartOne]") REQUIRE_THROWS_WITH( DoMessage(partOne, 0, nlohmann::json{ { "t", MsgType::CustomPacket }, - { "content", { { "x", "y" } } } }), + { "contentJsonDump", + nlohmann::json{ { "x", "y" } }.dump() } }), ContainsSubstring("User with id 0 doesn't exist")); DoConnect(partOne, 0); @@ -69,14 +71,16 @@ TEST_CASE("Messages for non-existent users", "[PartOne]") REQUIRE_NOTHROW( DoMessage(partOne, 0, nlohmann::json{ { "t", MsgType::CustomPacket }, - { "content", { { "x", "y" } } } })); + { "contentJsonDump", + nlohmann::json{ { "x", "y" } }.dump() } })); DoDisconnect(partOne, 0); REQUIRE_THROWS_WITH( DoMessage(partOne, 0, nlohmann::json{ { "t", MsgType::CustomPacket }, - { "content", { { "x", "y" } } } }), + { "contentJsonDump", + nlohmann::json{ { "x", "y" } }.dump() } }), ContainsSubstring("User with id 0 doesn't exist")); } @@ -118,8 +122,9 @@ TEST_CASE("Server custom packet", "[PartOne]") partOne.SendCustomPacket(1, nlohmann::json({ { "x", "y" } }).dump()); REQUIRE(partOne.Messages().size() == 1); REQUIRE(partOne.Messages()[0].j.dump() == - nlohmann::json{ { "type", "customPacket" }, - { "content", { { "x", "y" } } } } + nlohmann::json{ + { "t", static_cast(MsgType::CustomPacket) }, + { "contentJsonDump", nlohmann::json{ { "x", "y" } }.dump() } } .dump()); REQUIRE(partOne.Messages()[0].userId == 1); REQUIRE(partOne.Messages()[0].reliable); diff --git a/unit/PartOne_ActivateTest.cpp b/unit/PartOne_ActivateTest.cpp index 7cdac93449..0d898d62c4 100644 --- a/unit/PartOne_ActivateTest.cpp +++ b/unit/PartOne_ActivateTest.cpp @@ -154,7 +154,8 @@ TEST_CASE("See harvested PurpleMountainFlower in Whiterun", "[PartOne][espm]") auto it = std::find_if( partOne.Messages().begin(), partOne.Messages().end(), [&](auto m) { - return m.reliable && m.userId == 0 && m.j["type"] == "createActor" && + return m.reliable && m.userId == 0 && + m.j["t"] == static_cast(MsgType::CreateActor) && m.j["refrId"] == refrId && m.j["props"] == nlohmann::json{ { "isHarvested", true } }; }); @@ -182,7 +183,8 @@ TEST_CASE("See open DisplayCaseSmFlat01 in Whiterun", "[PartOne][espm]") auto it = std::find_if( partOne.Messages().begin(), partOne.Messages().end(), [&](auto m) { - return m.reliable && m.userId == 0 && m.j["type"] == "createActor" && + return m.reliable && m.userId == 0 && + m.j["t"] == static_cast(MsgType::CreateActor) && m.j["refrId"] == refrId && m.j["props"] == nlohmann::json{ { "isOpen", true } }; }); @@ -210,7 +212,8 @@ TEST_CASE("Activate DisplayCaseSmFlat01 in Whiterun", "[PartOne][espm]") auto it = std::find_if( partOne.Messages().begin(), partOne.Messages().end(), [&](auto m) { - return m.reliable && m.userId == 0 && m.j["type"] == "createActor" && + return m.reliable && m.userId == 0 && + m.j["t"] == static_cast(MsgType::CreateActor) && m.j["refrId"] == refrId && m.j["props"] == nullptr; }); REQUIRE(it != partOne.Messages().end()); @@ -316,7 +319,8 @@ TEST_CASE("Activate PurpleMountainFlower in Whiterun", "[PartOne][espm]") auto it = std::find_if( partOne.Messages().begin(), partOne.Messages().end(), [&](auto m) { - return m.reliable && m.userId == 0 && m.j["type"] == "createActor" && + return m.reliable && m.userId == 0 && + m.j["t"] == static_cast(MsgType::CreateActor) && m.j["refrId"] == refrId && m.j["props"] == nullptr; }); REQUIRE(it != partOne.Messages().end()); @@ -490,11 +494,11 @@ TEST_CASE("Server creates and destroys an object for user correcly", partOne.SetUserActor(0, 0xff000ABC); auto refId = 0x01000f69; - REQUIRE(std::find_if(partOne.Messages().begin(), partOne.Messages().end(), - [&](auto m) { - return m.j["type"] == "createActor" && m.reliable && - m.userId == 0 && m.j["refrId"] == 0x01000f69; - }) != partOne.Messages().end()); + REQUIRE(std::find_if( + partOne.Messages().begin(), partOne.Messages().end(), [&](auto m) { + return m.j["t"] == static_cast(MsgType::CreateActor) && + m.reliable && m.userId == 0 && m.j["refrId"] == 0x01000f69; + }) != partOne.Messages().end()); auto& ac = partOne.worldState.GetFormAt(0xff000ABC); ac.SetPos({ 0, 0, 0 }); @@ -570,7 +574,8 @@ TEST_CASE("Activate torch", "[espm][PartOne]") auto it = std::find_if( partOne.Messages().begin(), partOne.Messages().end(), [&](auto m) { - return m.reliable && m.userId == 0 && m.j["type"] == "createActor" && + return m.reliable && m.userId == 0 && + m.j["t"] == static_cast(MsgType::CreateActor) && m.j["refrId"] == refrId && m.j["props"] == nullptr; }); REQUIRE(it != partOne.Messages().end());