forked from Laupetin/OpenAssetTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add unit tests for string table asset loaders
- Loading branch information
Showing
5 changed files
with
269 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
test/ObjLoadingTests/Game/IW3/AssetLoaders/AssetLoaderStringTableTest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "Game/IW3/AssetLoaders/AssetLoaderStringTable.h" | ||
|
||
#include "Game/IW3/GameIW3.h" | ||
#include "Mock/MockAssetLoadingManager.h" | ||
#include "Mock/MockSearchPath.h" | ||
#include "Utils/MemoryManager.h" | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
#include <string> | ||
|
||
using namespace IW3; | ||
using namespace std::literals; | ||
|
||
namespace | ||
{ | ||
TEST_CASE("AssetLoaderStringTable(IW3): Can parse string table", "[iw3][stringtable][assetloader]") | ||
{ | ||
MockSearchPath searchPath; | ||
searchPath.AddFileData("mp/cooltable.csv", | ||
"test,data,lol\n" | ||
"lorem,ipsum"); | ||
|
||
Zone zone("MockZone", 0, &g_GameIW3); | ||
MockAssetLoadingManager assetLoadingManager(&zone, &searchPath); | ||
|
||
AssetLoaderStringTable assetLoader; | ||
MemoryManager memory; | ||
|
||
assetLoader.LoadFromRaw("mp/cooltable.csv", &searchPath, &memory, &assetLoadingManager, &zone); | ||
|
||
auto* assetInfo = reinterpret_cast<XAssetInfo<StringTable>*>(assetLoadingManager.MockGetAddedAsset("mp/cooltable.csv")); | ||
REQUIRE(assetInfo != nullptr); | ||
|
||
const auto* stringTable = assetInfo->Asset(); | ||
REQUIRE(stringTable->name == "mp/cooltable.csv"s); | ||
REQUIRE(stringTable->columnCount == 3); | ||
REQUIRE(stringTable->rowCount == 2); | ||
|
||
REQUIRE(stringTable->values[0] == "test"s); | ||
REQUIRE(stringTable->values[1] == "data"s); | ||
REQUIRE(stringTable->values[2] == "lol"s); | ||
REQUIRE(stringTable->values[3] == "lorem"s); | ||
REQUIRE(stringTable->values[4] == "ipsum"s); | ||
REQUIRE(stringTable->values[5] == ""s); | ||
} | ||
} // namespace |
53 changes: 53 additions & 0 deletions
53
test/ObjLoadingTests/Game/IW4/AssetLoaders/AssetLoaderStringTableTest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "Game/IW4/AssetLoaders/AssetLoaderStringTable.h" | ||
|
||
#include "Game/IW4/CommonIW4.h" | ||
#include "Game/IW4/GameIW4.h" | ||
#include "Mock/MockAssetLoadingManager.h" | ||
#include "Mock/MockSearchPath.h" | ||
#include "Utils/MemoryManager.h" | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
#include <string> | ||
|
||
using namespace IW4; | ||
using namespace std::literals; | ||
|
||
namespace | ||
{ | ||
TEST_CASE("AssetLoaderStringTable(IW4): Can parse string table", "[iw4][stringtable][assetloader]") | ||
{ | ||
MockSearchPath searchPath; | ||
searchPath.AddFileData("mp/cooltable.csv", | ||
"test,data,lol\n" | ||
"lorem,ipsum"); | ||
|
||
Zone zone("MockZone", 0, &g_GameIW4); | ||
MockAssetLoadingManager assetLoadingManager(&zone, &searchPath); | ||
|
||
AssetLoaderStringTable assetLoader; | ||
MemoryManager memory; | ||
|
||
assetLoader.LoadFromRaw("mp/cooltable.csv", &searchPath, &memory, &assetLoadingManager, &zone); | ||
|
||
auto* assetInfo = reinterpret_cast<XAssetInfo<StringTable>*>(assetLoadingManager.MockGetAddedAsset("mp/cooltable.csv")); | ||
REQUIRE(assetInfo != nullptr); | ||
|
||
const auto* stringTable = assetInfo->Asset(); | ||
REQUIRE(stringTable->name == "mp/cooltable.csv"s); | ||
REQUIRE(stringTable->columnCount == 3); | ||
REQUIRE(stringTable->rowCount == 2); | ||
|
||
CHECK(stringTable->values[0].string == "test"s); | ||
CHECK(stringTable->values[0].hash == 0x364492); | ||
CHECK(stringTable->values[1].string == "data"s); | ||
CHECK(stringTable->values[1].hash == 0x2eefaa); | ||
CHECK(stringTable->values[2].string == "lol"s); | ||
CHECK(stringTable->values[2].hash == 0x1a349); | ||
CHECK(stringTable->values[3].string == "lorem"s); | ||
CHECK(stringTable->values[3].hash == 0x6261837); | ||
CHECK(stringTable->values[4].string == "ipsum"s); | ||
CHECK(stringTable->values[4].hash == 0x5fc4bc4); | ||
CHECK(stringTable->values[5].string == ""s); | ||
CHECK(stringTable->values[5].hash == 0x0); | ||
} | ||
} // namespace |
52 changes: 52 additions & 0 deletions
52
test/ObjLoadingTests/Game/IW5/AssetLoaders/AssetLoaderStringTableTest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "Game/IW5/AssetLoaders/AssetLoaderStringTable.h" | ||
|
||
#include "Game/IW5/GameIW5.h" | ||
#include "Mock/MockAssetLoadingManager.h" | ||
#include "Mock/MockSearchPath.h" | ||
#include "Utils/MemoryManager.h" | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
#include <string> | ||
|
||
using namespace IW5; | ||
using namespace std::literals; | ||
|
||
namespace | ||
{ | ||
TEST_CASE("AssetLoaderStringTable(IW5): Can parse string table", "[iw5][stringtable][assetloader]") | ||
{ | ||
MockSearchPath searchPath; | ||
searchPath.AddFileData("mp/cooltable.csv", | ||
"test,data,lol\n" | ||
"lorem,ipsum"); | ||
|
||
Zone zone("MockZone", 0, &g_GameIW5); | ||
MockAssetLoadingManager assetLoadingManager(&zone, &searchPath); | ||
|
||
AssetLoaderStringTable assetLoader; | ||
MemoryManager memory; | ||
|
||
assetLoader.LoadFromRaw("mp/cooltable.csv", &searchPath, &memory, &assetLoadingManager, &zone); | ||
|
||
auto* assetInfo = reinterpret_cast<XAssetInfo<StringTable>*>(assetLoadingManager.MockGetAddedAsset("mp/cooltable.csv")); | ||
REQUIRE(assetInfo != nullptr); | ||
|
||
const auto* stringTable = assetInfo->Asset(); | ||
REQUIRE(stringTable->name == "mp/cooltable.csv"s); | ||
REQUIRE(stringTable->columnCount == 3); | ||
REQUIRE(stringTable->rowCount == 2); | ||
|
||
CHECK(stringTable->values[0].string == "test"s); | ||
CHECK(stringTable->values[0].hash == 0x364492); | ||
CHECK(stringTable->values[1].string == "data"s); | ||
CHECK(stringTable->values[1].hash == 0x2eefaa); | ||
CHECK(stringTable->values[2].string == "lol"s); | ||
CHECK(stringTable->values[2].hash == 0x1a349); | ||
CHECK(stringTable->values[3].string == "lorem"s); | ||
CHECK(stringTable->values[3].hash == 0x6261837); | ||
CHECK(stringTable->values[4].string == "ipsum"s); | ||
CHECK(stringTable->values[4].hash == 0x5fc4bc4); | ||
CHECK(stringTable->values[5].string == ""s); | ||
CHECK(stringTable->values[5].hash == 0x0); | ||
} | ||
} // namespace |
59 changes: 59 additions & 0 deletions
59
test/ObjLoadingTests/Game/T5/AssetLoaders/AssetLoaderStringTableTest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "Game/T5/AssetLoaders/AssetLoaderStringTable.h" | ||
|
||
#include "Game/T5/GameT5.h" | ||
#include "Mock/MockAssetLoadingManager.h" | ||
#include "Mock/MockSearchPath.h" | ||
#include "Utils/MemoryManager.h" | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
#include <string> | ||
|
||
using namespace T5; | ||
using namespace std::literals; | ||
|
||
namespace | ||
{ | ||
TEST_CASE("AssetLoaderStringTable(T5): Can parse string table", "[t5][stringtable][assetloader]") | ||
{ | ||
MockSearchPath searchPath; | ||
searchPath.AddFileData("mp/cooltable.csv", | ||
"test,data,lol\n" | ||
"lorem,ipsum"); | ||
|
||
Zone zone("MockZone", 0, &g_GameT5); | ||
MockAssetLoadingManager assetLoadingManager(&zone, &searchPath); | ||
|
||
AssetLoaderStringTable assetLoader; | ||
MemoryManager memory; | ||
|
||
assetLoader.LoadFromRaw("mp/cooltable.csv", &searchPath, &memory, &assetLoadingManager, &zone); | ||
|
||
auto* assetInfo = reinterpret_cast<XAssetInfo<StringTable>*>(assetLoadingManager.MockGetAddedAsset("mp/cooltable.csv")); | ||
REQUIRE(assetInfo != nullptr); | ||
|
||
const auto* stringTable = assetInfo->Asset(); | ||
REQUIRE(stringTable->name == "mp/cooltable.csv"s); | ||
REQUIRE(stringTable->columnCount == 3); | ||
REQUIRE(stringTable->rowCount == 2); | ||
|
||
CHECK(stringTable->values[0].string == "test"s); | ||
CHECK(stringTable->values[0].hash == 0x7c9e6865); | ||
CHECK(stringTable->values[1].string == "data"s); | ||
CHECK(stringTable->values[1].hash == 0x7c95915f); | ||
CHECK(stringTable->values[2].string == "lol"s); | ||
CHECK(stringTable->values[2].hash == 0xb888d0c); | ||
CHECK(stringTable->values[3].string == "lorem"s); | ||
CHECK(stringTable->values[3].hash == 0xfe02704); | ||
CHECK(stringTable->values[4].string == "ipsum"s); | ||
CHECK(stringTable->values[4].hash == 0xfaa7033); | ||
CHECK(stringTable->values[5].string == ""s); | ||
CHECK(stringTable->values[5].hash == 0x1505); | ||
|
||
REQUIRE(stringTable->cellIndex != nullptr); | ||
CHECK(stringTable->cellIndex[0] == 2); | ||
CHECK(stringTable->cellIndex[1] == 4); | ||
CHECK(stringTable->cellIndex[2] == 3); | ||
CHECK(stringTable->cellIndex[3] == 1); | ||
CHECK(stringTable->cellIndex[4] == 0); | ||
} | ||
} // namespace |
59 changes: 59 additions & 0 deletions
59
test/ObjLoadingTests/Game/T6/AssetLoaders/AssetLoaderStringTableTest.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "Game/T6/AssetLoaders/AssetLoaderStringTable.h" | ||
|
||
#include "Game/T6/GameT6.h" | ||
#include "Mock/MockAssetLoadingManager.h" | ||
#include "Mock/MockSearchPath.h" | ||
#include "Utils/MemoryManager.h" | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
#include <string> | ||
|
||
using namespace T6; | ||
using namespace std::literals; | ||
|
||
namespace | ||
{ | ||
TEST_CASE("AssetLoaderStringTable(T6): Can parse string table", "[t6][stringtable][assetloader]") | ||
{ | ||
MockSearchPath searchPath; | ||
searchPath.AddFileData("mp/cooltable.csv", | ||
"test,data,lol\n" | ||
"lorem,ipsum"); | ||
|
||
Zone zone("MockZone", 0, &g_GameT6); | ||
MockAssetLoadingManager assetLoadingManager(&zone, &searchPath); | ||
|
||
AssetLoaderStringTable assetLoader; | ||
MemoryManager memory; | ||
|
||
assetLoader.LoadFromRaw("mp/cooltable.csv", &searchPath, &memory, &assetLoadingManager, &zone); | ||
|
||
auto* assetInfo = reinterpret_cast<XAssetInfo<StringTable>*>(assetLoadingManager.MockGetAddedAsset("mp/cooltable.csv")); | ||
REQUIRE(assetInfo != nullptr); | ||
|
||
const auto* stringTable = assetInfo->Asset(); | ||
REQUIRE(stringTable->name == "mp/cooltable.csv"s); | ||
REQUIRE(stringTable->columnCount == 3); | ||
REQUIRE(stringTable->rowCount == 2); | ||
|
||
CHECK(stringTable->values[0].string == "test"s); | ||
CHECK(stringTable->values[0].hash == 0x7c9e6865); | ||
CHECK(stringTable->values[1].string == "data"s); | ||
CHECK(stringTable->values[1].hash == 0x7c95915f); | ||
CHECK(stringTable->values[2].string == "lol"s); | ||
CHECK(stringTable->values[2].hash == 0xb888d0c); | ||
CHECK(stringTable->values[3].string == "lorem"s); | ||
CHECK(stringTable->values[3].hash == 0xfe02704); | ||
CHECK(stringTable->values[4].string == "ipsum"s); | ||
CHECK(stringTable->values[4].hash == 0xfaa7033); | ||
CHECK(stringTable->values[5].string == ""s); | ||
CHECK(stringTable->values[5].hash == 0x1505); | ||
|
||
REQUIRE(stringTable->cellIndex != nullptr); | ||
CHECK(stringTable->cellIndex[0] == 2); | ||
CHECK(stringTable->cellIndex[1] == 4); | ||
CHECK(stringTable->cellIndex[2] == 3); | ||
CHECK(stringTable->cellIndex[3] == 1); | ||
CHECK(stringTable->cellIndex[4] == 0); | ||
} | ||
} // namespace |