feat(resource-manager): added working singleton resource manager

all external data should now be handled through the resource manager. This will take care of location on disk as well as ownership
This commit is contained in:
2025-03-20 14:26:44 -04:00
parent 1cc21a368b
commit 08075f5108
7 changed files with 303 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
#include <gtest/gtest.h>
#include "resourceManager.h"
#include "config.h"
#include "eosIO.h"
#include "helm.h"
#include "resourceManagerTypes.h"
#include <string>
#include <stdexcept>
#include <vector>
#include <set>
#include "debug.h"
/**
* @file configTest.cpp
* @brief Unit tests for the resourceManager class.
*/
std::string TEST_CONFIG = std::string(getenv("MESON_SOURCE_ROOT")) + "/tests/testsConfig.yaml";
/**
* @brief Test suite for the resourceManager class.
*/
class resourceManagerTest : public ::testing::Test {};
/**
* @brief Test the constructor of the resourceManager class.
*/
TEST_F(resourceManagerTest, constructor) {
Config::getInstance().loadConfig(TEST_CONFIG);
EXPECT_NO_THROW(ResourceManager::getInstance());
}
TEST_F(resourceManagerTest, getAvaliableResources) {
Config::getInstance().loadConfig(TEST_CONFIG);
ResourceManager& rm = ResourceManager::getInstance();
std::vector<std::string> resources = rm.getAvaliableResources();
std::set<std::string> expected = {"eos:helm", "mesh:sphere"};
std::set<std::string> actual(resources.begin(), resources.end());
EXPECT_EQ(expected, actual);
}
TEST_F(resourceManagerTest, getResource) {
Config::getInstance().loadConfig(TEST_CONFIG);
ResourceManager& rm = ResourceManager::getInstance();
std::string name = "eos:helm";
const Resource &r = rm.getResource(name);
// BREAKPOINT();
const auto &eos = std::get<std::unique_ptr<EosIO>>(r);
EXPECT_EQ("helm", eos->getFormat());
EOSTable &table = eos->getTable();
// -- Extract the Helm table from the EOSTable
helmholtz::HELMTable &helmTable = *std::get<std::unique_ptr<helmholtz::HELMTable>>(table);
EXPECT_DOUBLE_EQ(helmTable.f[0][0], -1692098915534.8142);
EXPECT_THROW(rm.getResource("opac:GS98:high:doesNotExist"), std::runtime_error);
}