Skip to content

Commit

Permalink
Switch to configuration file argument to Parse, extract configuration…
Browse files Browse the repository at this point in the history
… dir from file path.
  • Loading branch information
dwfncar committed Oct 25, 2023
1 parent 55c0ddd commit 458a2e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
15 changes: 7 additions & 8 deletions include/micm/configure/camp_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,25 @@ namespace micm
std::unordered_map<std::string, Phase> phases_;
std::vector<Process> processes_;

// Constants
// Configure files
static const inline std::string CAMP_CONFIG = "config.json";

// Common JSON
static const inline std::string CAMP_DATA = "camp-data";
static const inline std::string CAMP_FILES = "camp-files";
static const inline std::string CAMP_DATA = "camp-data";
static const inline std::string TYPE = "type";

// Functions

/// @brief Parse configures
/// @param config_dir Path to a the configuration directory
/// @param config_file Path to a the configuration file
/// @return True for successful parsing
ConfigParseStatus Parse(const std::filesystem::path& config_dir)
ConfigParseStatus Parse(const std::filesystem::path& config_file)
{
// Extract configuration dir from configuration file path
std::filesystem::path config_dir = config_file.parent_path();

std::vector<std::string> camp_files;

// Look for CAMP config file
std::filesystem::path camp_config(config_dir / CAMP_CONFIG);
std::filesystem::path camp_config(config_file);
if (std::filesystem::exists(camp_config))
{
json camp_data = json::parse(std::ifstream(camp_config));
Expand Down
10 changes: 5 additions & 5 deletions test/unit/configure/test_camp_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ TEST(SolverConfig, ReadAndParseCAMPFiles)
micm::SolverConfig solverConfig{};

// Read and parse the CAMP configure file
micm::ConfigParseStatus status = solverConfig.ReadAndParse("./unit_configs/CAMP/camp_valid");
micm::ConfigParseStatus status = solverConfig.ReadAndParse("./unit_configs/CAMP/camp_valid/config.json");
EXPECT_EQ(micm::ConfigParseStatus::Success, status);
}

Expand All @@ -16,7 +16,7 @@ TEST(SolverConfig, ReadAndParseSystemObject)
micm::SolverConfig solverConfig;

// Read and parse the configure files
micm::ConfigParseStatus status = solverConfig.ReadAndParse("./unit_configs/chapman");
micm::ConfigParseStatus status = solverConfig.ReadAndParse("./unit_configs/chapman/config.json");
EXPECT_EQ(micm::ConfigParseStatus::Success, status);

// Get solver parameters ('System', the collection of 'Process')
Expand Down Expand Up @@ -49,7 +49,7 @@ TEST(SolverConfig, ReadAndParseProcessObjects)
micm::SolverConfig<micm::JsonReaderPolicy> solverConfig;

// Read and parse the configure files
micm::ConfigParseStatus status = solverConfig.ReadAndParse("./unit_configs/chapman");
micm::ConfigParseStatus status = solverConfig.ReadAndParse("./unit_configs/chapman/config.json");
EXPECT_EQ(micm::ConfigParseStatus::Success, status);

// Get solver parameters ('System', the collection of 'Process')
Expand Down Expand Up @@ -133,7 +133,7 @@ TEST(SolverConfig, ReadAndParseProcessObjects)
TEST(SolverConfig, ReadAndParseSystemObjectfromMZ326)
{
micm::SolverConfig solverConfig;
micm::ConfigParseStatus status = solverConfig.ReadAndParse("./unit_configs/MZ326");
micm::ConfigParseStatus status = solverConfig.ReadAndParse("./unit_configs/MZ326/config.json");
EXPECT_EQ(micm::ConfigParseStatus::Success, status);

// Get solver parameters ('System', the collection of 'Process')
Expand Down Expand Up @@ -163,7 +163,7 @@ TEST(SolverConfig, ReadAndParseSystemObjectfromMZ326)
TEST(SolverConfig, ReadAndParseProcessObjectsfromMZ326)
{
micm::SolverConfig solverConfig;
micm::ConfigParseStatus status = solverConfig.ReadAndParse("./unit_configs/MZ326");
micm::ConfigParseStatus status = solverConfig.ReadAndParse("./unit_configs/MZ326/config.json");
EXPECT_EQ(micm::ConfigParseStatus::Success, status);

// Get solver parameters ('System', the collection of 'Process')
Expand Down

0 comments on commit 458a2e8

Please sign in to comment.