Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
razaqq committed Sep 13, 2024
1 parent dc9824a commit 2f526fa
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 132 deletions.
159 changes: 90 additions & 69 deletions Test/GameTest/GameTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static fs::path GetGamePath(Test t)
const auto rootPath = PotatoAlert::Core::GetModuleRootPath();
if (!rootPath.has_value())
{
std::exit(1);
PotatoAlert::Core::ExitCurrentProcess(1);
}

switch (t)
Expand All @@ -53,42 +53,50 @@ static fs::path GetGamePath(Test t)
return fs::path(rootPath.value()).remove_filename() / "GameDirectories" / "steam_non_versioned_exe";
case Test::svcwd:
return fs::path(rootPath.value()).remove_filename() / "GameDirectories" / "steam_versioned_cwd";
default:
PotatoAlert::Core::ExitCurrentProcess(1);
}
PotatoAlert::Core::ExitCurrentProcess(1);
}

}

TEST_CASE( "GameTest_CheckPathTest" )
{
DirectoryStatus f1;
REQUIRE( CheckPath(GetGamePath(Test::nsnv), f1) );
REQUIRE( f1.gamePath == GetGamePath(Test::nsnv) );
REQUIRE( f1.replaysPath == std::vector<fs::path>{ GetGamePath(Test::nsnv) / "replays" } );

DirectoryStatus f2;
REQUIRE( CheckPath(GetGamePath(Test::nsv), f2) );
REQUIRE(f2.replaysPath == std::vector<fs::path>{ GetGamePath(Test::nsv) / "replays" / "0.9.4.0" });

DirectoryStatus f3;
REQUIRE( CheckPath(GetGamePath(Test::snvexe), f3) );
REQUIRE(f3.replaysPath == std::vector<fs::path>{
GetGamePath(Test::snvexe) / "bin" / "1427460" / "bin32" / "replays",
GetGamePath(Test::snvexe) / "bin" / "1427460" / "bin64" / "replays"
});

DirectoryStatus f4;
REQUIRE(CheckPath(GetGamePath(Test::svcwd), f4));
REQUIRE(f4.replaysPath == std::vector<fs::path>{ GetGamePath(Test::svcwd) / "replays" / "0.9.4.0" });
{
DirectoryStatus d;
REQUIRE( CheckPath(GetGamePath(Test::nsnv), d) );
REQUIRE( d.gamePath == GetGamePath(Test::nsnv) );
REQUIRE( d.replaysPath == std::vector<fs::path>{ GetGamePath(Test::nsnv) / "replays" } );
}

{
DirectoryStatus d;
REQUIRE( CheckPath(GetGamePath(Test::nsv), d) );
REQUIRE(d.replaysPath == std::vector<fs::path>{ GetGamePath(Test::nsv) / "replays" / "0.9.4.0" });
}

{
DirectoryStatus d;
REQUIRE( CheckPath(GetGamePath(Test::snvexe), d) );
REQUIRE(d.replaysPath == std::vector<fs::path>{
GetGamePath(Test::snvexe) / "bin" / "1427460" / "bin32" / "replays",
GetGamePath(Test::snvexe) / "bin" / "1427460" / "bin64" / "replays"
});
}

{
DirectoryStatus d;
REQUIRE(CheckPath(GetGamePath(Test::svcwd), d));
REQUIRE(d.replaysPath == std::vector<fs::path>{ GetGamePath(Test::svcwd) / "replays" / "0.9.4.0" });
}
}

TEST_CASE( "GameTest_ReadPreferencesTest" )
{
DirectoryStatus status = {
GetGamePath(Test::nsnv),
Version(""), "", "", "", "cwd", "", "", "", {},
"", false
DirectoryStatus status =
{
GetGamePath(Test::nsnv),
Version(""), "", "", "", "cwd", "", "", "", {},
"", false
};
REQUIRE(ReadPreferences(status, status.gamePath));
REQUIRE(status.gameVersion == Version("0.9.4.0"));
Expand All @@ -97,10 +105,11 @@ TEST_CASE( "GameTest_ReadPreferencesTest" )

TEST_CASE( "GameTest_GetResFolderPathTest" )
{
DirectoryStatus status = {
GetGamePath(Test::nsnv),
Version(""), "", "", "", "", "", "", "", {},
"", false
DirectoryStatus status =
{
GetGamePath(Test::nsnv),
Version(""), "", "", "", "", "", "", "", {},
"", false
};
REQUIRE(GetBinPath(status));
REQUIRE(status.binPath == GetGamePath(Test::nsnv) / "bin" / "2666186");
Expand All @@ -113,68 +122,80 @@ TEST_CASE( "GameTest_GetResFolderPathTest" )

TEST_CASE( "GameTest_ReadEngineConfigTest" )
{
// non steam non versioned
DirectoryStatus f1 = {
{
// non steam non versioned
DirectoryStatus d = {
GetGamePath(Test::nsnv),
Version(""), "", "", "", "", "", "", "", {},
"", false
};
REQUIRE(GetBinPath(f1));
REQUIRE(ReadEngineConfig(f1, "res"));
REQUIRE(f1.replaysDirPath == "replays");
REQUIRE(f1.replaysPathBase == "cwd");
REQUIRE(!f1.versionedReplays);

// steam non versioned
DirectoryStatus f2 = {
};
REQUIRE(GetBinPath(d));
REQUIRE(ReadEngineConfig(d, "res"));
REQUIRE(d.replaysDirPath == "replays");
REQUIRE(d.replaysPathBase == "cwd");
REQUIRE(!d.versionedReplays);
}

{
// steam non versioned
DirectoryStatus d = {
GetGamePath(Test::snvexe),
Version(""), "", "", "", "", "", "", "", {},
"", false
};
REQUIRE( GetBinPath(f2) );
REQUIRE( ReadEngineConfig(f2, "res") );
REQUIRE( f2.replaysDirPath == "replays" );
REQUIRE( f2.replaysPathBase == "exe_path" );
REQUIRE( !f2.versionedReplays );
};
REQUIRE( GetBinPath(d) );
REQUIRE( ReadEngineConfig(d, "res") );
REQUIRE( d.replaysDirPath == "replays" );
REQUIRE( d.replaysPathBase == "exe_path" );
REQUIRE( !d.versionedReplays );
}
}

TEST_CASE( "GameTest_SetReplaysFolderTest" )
{
DirectoryStatus f1 = {
{
DirectoryStatus d = {
GetGamePath(Test::nsnv),
Version("0.9.4.0"), GetGamePath(Test::nsnv) / "bin" / "1427460", "", "", "", "", "cwd", "replays",
{}, "eu", false
};
SetReplaysFolder(f1);
REQUIRE(f1.replaysPath == std::vector<fs::path>{ GetGamePath(Test::nsnv) / "replays" });
};
SetReplaysFolder(d);
REQUIRE(d.replaysPath == std::vector<fs::path>{ GetGamePath(Test::nsnv) / "replays" });
}

DirectoryStatus f2 = {
{
DirectoryStatus d = {
GetGamePath(Test::snvexe),
Version("0.9.4.0"), GetGamePath(Test::snvexe) / "bin" / "1427460", "", "", "", "", "cwd", "replays",
{}, "eu", false
};
SetReplaysFolder(f2);
REQUIRE(f2.replaysPath == std::vector<fs::path>{ GetGamePath(Test::snvexe) / "replays" });
};
SetReplaysFolder(d);
REQUIRE(d.replaysPath == std::vector<fs::path>{ GetGamePath(Test::snvexe) / "replays" });
}

DirectoryStatus f3 = {
{
DirectoryStatus d = {
GetGamePath(Test::snvexe),
Version("0.9.4.0"), GetGamePath(Test::snvexe) / "bin" / "1427460", "", "", "", "1427460", "exe_path", "replays",
{}, "eu", false
};
SetReplaysFolder(f3);
REQUIRE(f3.replaysPath == std::vector<fs::path>{
GetGamePath(Test::snvexe) / "bin" / f3.directoryVersion / "bin32" / "replays",
GetGamePath(Test::snvexe) / "bin" / f3.directoryVersion / "bin64" / "replays"
});
};
SetReplaysFolder(d);
REQUIRE(d.replaysPath == std::vector<fs::path>{
GetGamePath(Test::snvexe) / "bin" / d.directoryVersion / "bin32" / "replays",
GetGamePath(Test::snvexe) / "bin" / d.directoryVersion / "bin64" / "replays"
});
}

DirectoryStatus f4 = {
{
DirectoryStatus d = {
GetGamePath(Test::svcwd),
Version("0.9.4.0"), GetGamePath(Test::svcwd) / "bin" / "1427460", "", "", "", "1427460", "exe_path", "replays",
{}, "eu", true
};
SetReplaysFolder(f4);
REQUIRE(f4.replaysPath == std::vector<fs::path>{
GetGamePath(Test::svcwd) / "bin" / f4.directoryVersion / "bin32" / "replays" / f4.gameVersion.ToString(),
GetGamePath(Test::svcwd) / "bin" / f4.directoryVersion / "bin64" / "replays" / f4.gameVersion.ToString()
});
};
SetReplaysFolder(d);
REQUIRE(d.replaysPath == std::vector<fs::path>{
GetGamePath(Test::svcwd) / "bin" / d.directoryVersion / "bin32" / "replays" / d.gameVersion.ToString(),
GetGamePath(Test::svcwd) / "bin" / d.directoryVersion / "bin64" / "replays" / d.gameVersion.ToString()
});
}
}
155 changes: 92 additions & 63 deletions Test/ReplayTest/ReplayTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,74 +51,103 @@ TEST_CASE( "ReplayTest" )
{
const fs::path gameFilePath = GetModuleRootPath().value() / "ReplayVersions";

ReplayResult<Replay> res = Replay::FromFile(GetReplay("20201107_155356_PISC110-Venezia_19_OC_prey.wowsreplay"), gameFilePath);
REQUIRE(res);
REQUIRE(res->Meta.Name == "12x12");
REQUIRE(res->Meta.DateTime == "07.11.2020 15:53:56");
REQUIRE(res->Packets.size() == 153376);
ReplayResult<ReplaySummary> result = res->Analyze();
REQUIRE(result);
REQUIRE(result->Outcome == MatchOutcome::Win);

res = Replay::FromFile(GetReplay("20210914_212320_PRSC610-Smolensk_25_sea_hope.wowsreplay"), gameFilePath);
REQUIRE(res);
ReplayResult<ReplaySummary> result2 = res->Analyze();
REQUIRE(result2);
REQUIRE(result2->Outcome == MatchOutcome::Win);

res = Replay::FromFile(GetReplay("20210913_011502_PASD510-Somers_53_Shoreside.wowsreplay"), gameFilePath);
REQUIRE(res);
ReplayResult<ReplaySummary> result3 = res->Analyze();
REQUIRE(result3);
REQUIRE(result3->Outcome == MatchOutcome::Loss);

res = Replay::FromFile(GetReplay("20210912_002554_PRSB110-Sovetskaya-Rossiya_53_Shoreside.wowsreplay"), gameFilePath);
REQUIRE(res);
ReplayResult<ReplaySummary> result4 = res->Analyze();
REQUIRE(result4);
REQUIRE(result4->Outcome == MatchOutcome::Win);

res = Replay::FromFile(GetReplay("20210915_180756_PRSC610-Smolensk_35_NE_north_winter.wowsreplay"), gameFilePath);
REQUIRE(res);
ReplayResult<ReplaySummary> result5 = res->Analyze();
REQUIRE(result5);
REQUIRE(result5->Outcome == MatchOutcome::Loss);

res = Replay::FromFile(GetReplay("20201117_104604_PWSD508-Orkan_50_Gold_harbor.wowsreplay"), gameFilePath);
REQUIRE(res.has_value());
ReplayResult<ReplaySummary> result6 = res->Analyze();
REQUIRE(result6);
REQUIRE(result6->Outcome == MatchOutcome::Draw);
{
ReplayResult<Replay> res = Replay::FromFile(GetReplay("20201107_155356_PISC110-Venezia_19_OC_prey.wowsreplay"), gameFilePath);
REQUIRE(res);
REQUIRE(res->Meta.Name == "12x12");
REQUIRE(res->Meta.DateTime == "07.11.2020 15:53:56");
REQUIRE(res->Packets.size() == 153376);
ReplayResult<ReplaySummary> result = res->Analyze();
REQUIRE(result);
REQUIRE(result->Outcome == MatchOutcome::Win);
}

{
ReplayResult<Replay> res = Replay::FromFile(GetReplay("20210914_212320_PRSC610-Smolensk_25_sea_hope.wowsreplay"), gameFilePath);
REQUIRE(res);
ReplayResult<ReplaySummary> result2 = res->Analyze();
REQUIRE(result2);
REQUIRE(result2->Outcome == MatchOutcome::Win);
}

{
ReplayResult<Replay> res = Replay::FromFile(GetReplay("20210913_011502_PASD510-Somers_53_Shoreside.wowsreplay"), gameFilePath);
REQUIRE(res);
ReplayResult<ReplaySummary> result3 = res->Analyze();
REQUIRE(result3);
REQUIRE(result3->Outcome == MatchOutcome::Loss);
}

{
ReplayResult<Replay> res = Replay::FromFile(GetReplay("20210912_002554_PRSB110-Sovetskaya-Rossiya_53_Shoreside.wowsreplay"), gameFilePath);
REQUIRE(res);
ReplayResult<ReplaySummary> result4 = res->Analyze();
REQUIRE(result4);
REQUIRE(result4->Outcome == MatchOutcome::Win);
}

{
ReplayResult<Replay> res = Replay::FromFile(GetReplay("20210915_180756_PRSC610-Smolensk_35_NE_north_winter.wowsreplay"), gameFilePath);
REQUIRE(res);
ReplayResult<ReplaySummary> result5 = res->Analyze();
REQUIRE(result5);
REQUIRE(result5->Outcome == MatchOutcome::Loss);
}

{
ReplayResult<Replay> res = Replay::FromFile(GetReplay("20201117_104604_PWSD508-Orkan_50_Gold_harbor.wowsreplay"), gameFilePath);
REQUIRE(res.has_value());
ReplayResult<ReplaySummary> result6 = res->Analyze();
REQUIRE(result6);
REQUIRE(result6->Outcome == MatchOutcome::Draw);
}

// 0.11.7
res = Replay::FromFile(GetReplay("20220815_100927_PRSB518-Lenin_19_OC_prey.wowsreplay"), gameFilePath);
REQUIRE(res.has_value());
ReplayResult<ReplaySummary> result7 = res->Analyze();
REQUIRE(result7);
REQUIRE(result7->Outcome == MatchOutcome::Loss);
REQUIRE((int)std::round(result7->DamageDealt) == 132976);
REQUIRE((int)std::round(result7->DamageTaken) == 94536);
REQUIRE((int)std::round(result7->DamageSpotting) == 17263);
REQUIRE((int)std::round(result7->DamagePotential) == 1616598);
REQUIRE(result7->Achievements.size() == 2);
REQUIRE(result7->Ribbons.size() == 10);
uint32_t count = std::accumulate(result7->Ribbons.begin(), result7->Ribbons.end(), 0, [](int current, const auto& ribbon)
{
return current + ribbon.second;
});
REQUIRE(count == 96);
ReplayResult<Replay> res = Replay::FromFile(GetReplay("20220815_100927_PRSB518-Lenin_19_OC_prey.wowsreplay"), gameFilePath);
REQUIRE(res.has_value());
ReplayResult<ReplaySummary> result7 = res->Analyze();
REQUIRE(result7);
REQUIRE(result7->Outcome == MatchOutcome::Loss);
REQUIRE((int)std::round(result7->DamageDealt) == 132976);
REQUIRE((int)std::round(result7->DamageTaken) == 94536);
REQUIRE((int)std::round(result7->DamageSpotting) == 17263);
REQUIRE((int)std::round(result7->DamagePotential) == 1616598);
REQUIRE(result7->Achievements.size() == 2);
REQUIRE(result7->Ribbons.size() == 10);
uint32_t count = std::accumulate(result7->Ribbons.begin(), result7->Ribbons.end(), 0, [](int current, const auto& ribbon)
{
return current + ribbon.second;
});
REQUIRE(count == 96);
}

// 12.6
res = Replay::FromFile(GetReplay("20230723_181537_PWSD207-Grom_42_Neighbors.wowsreplay"), gameFilePath);
REQUIRE(res.has_value());
ReplayResult<ReplaySummary> result8 = res->Analyze();
REQUIRE(result8);
REQUIRE(result8->Outcome == MatchOutcome::Loss);
REQUIRE((int)std::round(result8->DamageDealt) == 136864);
REQUIRE((int)std::round(result8->DamageTaken) == 16603);
REQUIRE((int)std::round(result8->DamageSpotting) == 5382);
REQUIRE((int)std::round(result8->DamagePotential) == 583300);
REQUIRE(result8->Achievements.size() == 2);
{
ReplayResult<Replay> res = Replay::FromFile(GetReplay("20230723_181537_PWSD207-Grom_42_Neighbors.wowsreplay"), gameFilePath);
REQUIRE(res.has_value());
ReplayResult<ReplaySummary> result8 = res->Analyze();
REQUIRE(result8);
REQUIRE(result8->Outcome == MatchOutcome::Loss);
REQUIRE((int)std::round(result8->DamageDealt) == 136864);
REQUIRE((int)std::round(result8->DamageTaken) == 16603);
REQUIRE((int)std::round(result8->DamageSpotting) == 5382);
REQUIRE((int)std::round(result8->DamagePotential) == 583300);
REQUIRE(result8->Achievements.size() == 2);
}

// 13.8.0
{
ReplayResult<Replay> res = Replay::FromFile(GetReplay("20240907_233354_PGSS208-U190_38_Canada.wowsreplay"), gameFilePath);
REQUIRE(res.has_value());
REQUIRE(res->Packets.size() == 123807);
}

{
ReplayResult<Replay> res = Replay::FromFile(GetReplay("20240907_212325_PFSD018-L-Aventurier_41_Conquest.wowsreplay"), gameFilePath);
REQUIRE(res.has_value());
REQUIRE(res->Packets.size() == 61455);
}
}

TEST_CASE( "ReplayGameFileTest" )
Expand Down

0 comments on commit 2f526fa

Please sign in to comment.