Skip to content

Commit

Permalink
fix-some-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pospelove committed Dec 19, 2024
1 parent 6f7a1a1 commit 5dbfb90
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
19 changes: 12 additions & 7 deletions unit/PartOneTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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\"})"));

Expand All @@ -61,22 +62,25 @@ 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);

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"));
}

Expand Down Expand Up @@ -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<int>(MsgType::CustomPacket) },
{ "contentJsonDump", nlohmann::json{ { "x", "y" } }.dump() } }
.dump());
REQUIRE(partOne.Messages()[0].userId == 1);
REQUIRE(partOne.Messages()[0].reliable);
Expand Down
25 changes: 15 additions & 10 deletions unit/PartOne_ActivateTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(MsgType::CreateActor) &&
m.j["refrId"] == refrId &&
m.j["props"] == nlohmann::json{ { "isHarvested", true } };
});
Expand Down Expand Up @@ -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<int>(MsgType::CreateActor) &&
m.j["refrId"] == refrId &&
m.j["props"] == nlohmann::json{ { "isOpen", true } };
});
Expand Down Expand Up @@ -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<int>(MsgType::CreateActor) &&
m.j["refrId"] == refrId && m.j["props"] == nullptr;
});
REQUIRE(it != partOne.Messages().end());
Expand Down Expand Up @@ -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<int>(MsgType::CreateActor) &&
m.j["refrId"] == refrId && m.j["props"] == nullptr;
});
REQUIRE(it != partOne.Messages().end());
Expand Down Expand Up @@ -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<int>(MsgType::CreateActor) &&
m.reliable && m.userId == 0 && m.j["refrId"] == 0x01000f69;
}) != partOne.Messages().end());

auto& ac = partOne.worldState.GetFormAt<MpActor>(0xff000ABC);
ac.SetPos({ 0, 0, 0 });
Expand Down Expand Up @@ -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<int>(MsgType::CreateActor) &&
m.j["refrId"] == refrId && m.j["props"] == nullptr;
});
REQUIRE(it != partOne.Messages().end());
Expand Down

0 comments on commit 5dbfb90

Please sign in to comment.