mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 14:58:10 -05:00
Add base for menu parsing integration tests
This commit is contained in:
56
test/ObjLoadingTests/Mock/MockAssetLoadingManager.cpp
Normal file
56
test/ObjLoadingTests/Mock/MockAssetLoadingManager.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
#include "MockAssetLoadingManager.h"
|
||||
|
||||
MockAssetLoadingManager::MockAssetLoadingManager(Zone* zone, ISearchPath* searchPath)
|
||||
: m_zone(zone),
|
||||
m_mock_gdt(std::make_unique<Gdt>()),
|
||||
m_context(std::make_unique<AssetLoadingContext>(zone, searchPath, std::vector({m_mock_gdt.get()})))
|
||||
{
|
||||
}
|
||||
|
||||
AssetLoadingContext* MockAssetLoadingManager::GetAssetLoadingContext() const
|
||||
{
|
||||
return m_context.get();
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* MockAssetLoadingManager::AddAsset(const asset_type_t assetType, const std::string& assetName, void* asset, std::vector<XAssetInfoGeneric*> dependencies,
|
||||
std::vector<scr_string_t> usedScriptStrings)
|
||||
{
|
||||
XAssetInfoGeneric assetInfoObj{assetType, assetName, m_zone, std::move(dependencies), std::move(usedScriptStrings), asset};
|
||||
auto assetInfo = std::make_unique<XAssetInfoGeneric>(std::move(assetInfoObj));
|
||||
const auto assetInfoPtr = assetInfo.get();
|
||||
m_added_assets.emplace(std::make_pair(assetInfo->m_name, std::move(assetInfo)));
|
||||
|
||||
return assetInfoPtr;
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* MockAssetLoadingManager::LoadDependency(const asset_type_t assetType, const std::string& assetName)
|
||||
{
|
||||
auto foundDependencies = m_available_dependencies.find(assetName);
|
||||
|
||||
while (foundDependencies != m_available_dependencies.end())
|
||||
{
|
||||
if (foundDependencies->second->m_type == assetType)
|
||||
return foundDependencies->second.get();
|
||||
|
||||
++foundDependencies;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void MockAssetLoadingManager::MockAddAvailableDependency(const asset_type_t assetType, std::string assetName, void* asset)
|
||||
{
|
||||
XAssetInfoGeneric assetInfoObj{assetType, std::move(assetName), m_zone, std::vector<XAssetInfoGeneric*>(), std::vector<scr_string_t>(), asset};
|
||||
auto assetInfo = std::make_unique<XAssetInfoGeneric>(std::move(assetInfoObj));
|
||||
m_available_dependencies.emplace(std::make_pair(assetInfo->m_name, std::move(assetInfo)));
|
||||
}
|
||||
|
||||
XAssetInfoGeneric* MockAssetLoadingManager::MockGetAddedAsset(const std::string& assetName)
|
||||
{
|
||||
const auto foundAsset = m_added_assets.find(assetName);
|
||||
|
||||
if (foundAsset != m_added_assets.end())
|
||||
return foundAsset->second.get();
|
||||
|
||||
return nullptr;
|
||||
}
|
25
test/ObjLoadingTests/Mock/MockAssetLoadingManager.h
Normal file
25
test/ObjLoadingTests/Mock/MockAssetLoadingManager.h
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <map>
|
||||
|
||||
#include "AssetLoading/IAssetLoadingManager.h"
|
||||
|
||||
class MockAssetLoadingManager final : public IAssetLoadingManager
|
||||
{
|
||||
Zone* m_zone;
|
||||
std::unique_ptr<Gdt> m_mock_gdt;
|
||||
std::unique_ptr<AssetLoadingContext> m_context;
|
||||
std::map<std::string, std::unique_ptr<XAssetInfoGeneric>> m_added_assets;
|
||||
std::multimap<std::string, std::unique_ptr<XAssetInfoGeneric>> m_available_dependencies;
|
||||
|
||||
public:
|
||||
MockAssetLoadingManager(Zone* zone, ISearchPath* searchPath);
|
||||
|
||||
_NODISCARD AssetLoadingContext* GetAssetLoadingContext() const override;
|
||||
XAssetInfoGeneric* AddAsset(asset_type_t assetType, const std::string& assetName, void* asset, std::vector<XAssetInfoGeneric*> dependencies, std::vector<scr_string_t> usedScriptStrings) override;
|
||||
XAssetInfoGeneric* LoadDependency(asset_type_t assetType, const std::string& assetName) override;
|
||||
|
||||
void MockAddAvailableDependency(asset_type_t assetType, std::string assetName, void* asset);
|
||||
XAssetInfoGeneric* MockGetAddedAsset(const std::string& assetName);
|
||||
};
|
27
test/ObjLoadingTests/Mock/MockSearchPath.cpp
Normal file
27
test/ObjLoadingTests/Mock/MockSearchPath.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include "MockSearchPath.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
void MockSearchPath::AddFileData(std::string fileName, std::string fileData)
|
||||
{
|
||||
m_file_data_map.emplace(std::make_pair(std::move(fileName), std::move(fileData)));
|
||||
}
|
||||
|
||||
SearchPathOpenFile MockSearchPath::Open(const std::string& fileName)
|
||||
{
|
||||
const auto foundFileData = m_file_data_map.find(fileName);
|
||||
|
||||
if(foundFileData == m_file_data_map.end())
|
||||
return {};
|
||||
|
||||
return {std::make_unique<std::istringstream>(foundFileData->second), foundFileData->second.size()};
|
||||
}
|
||||
|
||||
std::string MockSearchPath::GetPath()
|
||||
{
|
||||
return "MockFiles";
|
||||
}
|
||||
|
||||
void MockSearchPath::Find(const SearchPathSearchOptions& options, const std::function<void(const std::string&)>& callback)
|
||||
{
|
||||
}
|
16
test/ObjLoadingTests/Mock/MockSearchPath.h
Normal file
16
test/ObjLoadingTests/Mock/MockSearchPath.h
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include <map>
|
||||
|
||||
#include "SearchPath/ISearchPath.h"
|
||||
|
||||
class MockSearchPath final : public ISearchPath
|
||||
{
|
||||
std::map<std::string, std::string> m_file_data_map;
|
||||
|
||||
public:
|
||||
void AddFileData(std::string fileName, std::string fileData);
|
||||
|
||||
SearchPathOpenFile Open(const std::string& fileName) override;
|
||||
std::string GetPath() override;
|
||||
void Find(const SearchPathSearchOptions& options, const std::function<void(const std::string&)>& callback) override;
|
||||
};
|
Reference in New Issue
Block a user