diff --git a/src/cosim/observer/file_observer.cpp b/src/cosim/observer/file_observer.cpp index 14a2224e..52e38846 100644 --- a/src/cosim/observer/file_observer.cpp +++ b/src/cosim/observer/file_observer.cpp @@ -566,8 +566,16 @@ file_observer_config file_observer_config::parse(const filesystem::path& configP boost::property_tree::read_xml(configPath.string(), ptree, boost::property_tree::xml_parser::no_comments | boost::property_tree::xml_parser::trim_whitespace); + const auto& simulators = ptree.get_child("simulators"); + file_observer_config config; - for (const auto& simulator : ptree.get_child("simulators")) { + if (const auto timestamps = get_optional_attribute(simulators, "timestampedFilenames")) { + config.set_timestamped_filenames(*timestamps); + } + if (const auto precision = get_optional_attribute(simulators, "floatingPointPrecision")) { + config.fixed_precision(*precision); + } + for (const auto& simulator : simulators) { if (simulator.first == "simulator") { const auto modelName = get_attribute(simulator.second, "name"); const auto decimationFactor = get_optional_attribute(simulator.second, "decimationFactor"); @@ -581,15 +589,6 @@ file_observer_config file_observer_config::parse(const filesystem::path& configP config.log_simulator_variables(modelName, variableNames, decimationFactor); } } - if (const auto configuration = ptree.get_child_optional("configuration")) { - if (const auto timestamps = get_optional_attribute(*configuration, "timestampedFilenames")) { - config.set_timestamped_filenames(*timestamps); - } - if (const auto precision = get_optional_attribute(*configuration, "floatingPointPrecision")) { - config.fixed_precision(*precision); - } - } - return config; } diff --git a/tests/data/LogConfig.xml b/tests/data/LogConfig.xml index 9621355e..2b1fcfa0 100644 --- a/tests/data/LogConfig.xml +++ b/tests/data/LogConfig.xml @@ -1,6 +1,5 @@ - - + diff --git a/tests/file_observer_logging_from_config_test.cpp b/tests/file_observer_logging_from_config_test.cpp index 4e0d8d45..39dd401c 100644 --- a/tests/file_observer_logging_from_config_test.cpp +++ b/tests/file_observer_logging_from_config_test.cpp @@ -7,7 +7,9 @@ #include #include +#include #include +#include #include @@ -63,10 +65,17 @@ int main() // Run the simulation auto simResult = execution.simulate_until(endTime); REQUIRE(simResult); + csv_observer->stop_recording(); REQUIRE(cosim::filesystem::exists(cosim::filesystem::path(csvPath / "slave.csv"))); REQUIRE(cosim::filesystem::exists(cosim::filesystem::path(csvPath / "slave2.csv"))); + std::ifstream slaveLog(csvPath / "slave.csv"); + REQUIRE(slaveLog); + std::stringstream slaveLogContents; + slaveLogContents << slaveLog.rdbuf(); + REQUIRE(slaveLogContents.str().find(",1.2,1,hello log") != std::string::npos); + } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; return 1;