From 8e72c9b92d55d8187a4c9b83785b686f43d707e1 Mon Sep 17 00:00:00 2001 From: msteinsto Date: Mon, 28 Feb 2022 11:31:47 +0100 Subject: [PATCH 01/20] Removed file scheme check --- src/cosim/osp_config_parser.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/cosim/osp_config_parser.cpp b/src/cosim/osp_config_parser.cpp index 87cbf777..5de889ac 100644 --- a/src/cosim/osp_config_parser.cpp +++ b/src/cosim/osp_config_parser.cpp @@ -938,24 +938,26 @@ osp_config load_osp_config( const auto modelUri = resolve_reference(baseURI, simulator.source); cosim::filesystem::path msmiFilePath; - if (modelUri.scheme() == "file") { - msmiFilePath = file_uri_to_path(modelUri).remove_filename() / msmiFileName; - if (cosim::filesystem::exists(msmiFilePath)) { - emds.emplace(simulator.name, msmiFilePath); - } else { - msmiFilePath = configFile.parent_path() / msmiFileName; - if (cosim::filesystem::exists(msmiFilePath)) { - emds.emplace(simulator.name, msmiFilePath); - } - } + msmiFilePath = file_uri_to_path(modelUri).remove_filename() / msmiFileName; + if (cosim::filesystem::exists(msmiFilePath)) { + emds.emplace(simulator.name, msmiFilePath); } else { - // Makes it possible to keep OspModelDescription at configuration path - // even when there are FMUs with other URI than file (fmu-proxy). msmiFilePath = configFile.parent_path() / msmiFileName; if (cosim::filesystem::exists(msmiFilePath)) { emds.emplace(simulator.name, msmiFilePath); } } + +// if (modelUri.scheme() == "file") { +// +// } else { +// // Makes it possible to keep OspModelDescription at configuration path +// // even when there are FMUs with other URI than file (fmu-proxy). +// msmiFilePath = configFile.parent_path() / msmiFileName; +// if (cosim::filesystem::exists(msmiFilePath)) { +// emds.emplace(simulator.name, msmiFilePath); +// } +// } } connect_variables(parser.get_variable_connections(), config.system_structure); From 8fced5e03f243b47722b49f49acc0ca52872331c Mon Sep 17 00:00:00 2001 From: msteinsto Date: Mon, 28 Feb 2022 14:47:28 +0100 Subject: [PATCH 02/20] Allow proxyfmu URI scheme --- src/cosim/osp_config_parser.cpp | 1 + src/cosim/uri.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cosim/osp_config_parser.cpp b/src/cosim/osp_config_parser.cpp index 5de889ac..23948709 100644 --- a/src/cosim/osp_config_parser.cpp +++ b/src/cosim/osp_config_parser.cpp @@ -953,6 +953,7 @@ osp_config load_osp_config( // } else { // // Makes it possible to keep OspModelDescription at configuration path // // even when there are FMUs with other URI than file (fmu-proxy). +// // msmiFilePath = configFile.parent_path() / msmiFileName; // if (cosim::filesystem::exists(msmiFilePath)) { // emds.emplace(simulator.name, msmiFilePath); diff --git a/src/cosim/uri.cpp b/src/cosim/uri.cpp index db5857a0..1072e244 100644 --- a/src/cosim/uri.cpp +++ b/src/cosim/uri.cpp @@ -528,7 +528,7 @@ uri path_to_file_uri(const cosim::filesystem::path& path) cosim::filesystem::path file_uri_to_path(const uri& fileUri) { - COSIM_INPUT_CHECK(fileUri.scheme() && *fileUri.scheme() == "file"); + COSIM_INPUT_CHECK(fileUri.scheme() && (*fileUri.scheme() == "file" || *fileUri.scheme() == "proxyfmu")); COSIM_INPUT_CHECK(fileUri.authority() && (fileUri.authority()->empty() || *fileUri.authority() == "localhost")); From fab82a6dab16d957beb824b600916765a739b42a Mon Sep 17 00:00:00 2001 From: msteinsto Date: Mon, 28 Feb 2022 15:37:50 +0100 Subject: [PATCH 03/20] Removed URI authority check --- src/cosim/uri.cpp | 5 +++-- tests/uri_unittest.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cosim/uri.cpp b/src/cosim/uri.cpp index 1072e244..3b52f3b9 100644 --- a/src/cosim/uri.cpp +++ b/src/cosim/uri.cpp @@ -529,8 +529,9 @@ uri path_to_file_uri(const cosim::filesystem::path& path) cosim::filesystem::path file_uri_to_path(const uri& fileUri) { COSIM_INPUT_CHECK(fileUri.scheme() && (*fileUri.scheme() == "file" || *fileUri.scheme() == "proxyfmu")); - COSIM_INPUT_CHECK(fileUri.authority() && - (fileUri.authority()->empty() || *fileUri.authority() == "localhost")); + COSIM_INPUT_CHECK(fileUri.authority() + // && (fileUri.authority()->empty() || *fileUri.authority() == "localhost") + ); #ifdef _WIN32 // Windows has some special rules for file URIs; better use the built-in diff --git a/tests/uri_unittest.cpp b/tests/uri_unittest.cpp index e5e74529..ed45cd9f 100644 --- a/tests/uri_unittest.cpp +++ b/tests/uri_unittest.cpp @@ -220,5 +220,5 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) BOOST_TEST(file_uri_to_path("file://localhost/c:/foo%20bar/baz") == "/c:/foo bar/baz"); #endif BOOST_CHECK_THROW(file_uri_to_path("http://foo/bar"), std::invalid_argument); - BOOST_CHECK_THROW(file_uri_to_path("file://foo/bar"), std::invalid_argument); + //BOOST_CHECK_THROW(file_uri_to_path("file://foo/bar"), std::invalid_argument); } From ae14c69a07a99137bf79dbf30bd0e9a399366eab Mon Sep 17 00:00:00 2001 From: msteinsto Date: Wed, 2 Mar 2022 09:58:30 +0100 Subject: [PATCH 04/20] Check model relative path for OspModelDescription with fmuproxy --- src/cosim/osp_config_parser.cpp | 46 ++++++++++++++++++---------- src/cosim/uri.cpp | 1 + tests/uri_unittest.cpp | 53 ++++++++++++++++++++++++++++++++- 3 files changed, 83 insertions(+), 17 deletions(-) diff --git a/src/cosim/osp_config_parser.cpp b/src/cosim/osp_config_parser.cpp index 23948709..572e9cd5 100644 --- a/src/cosim/osp_config_parser.cpp +++ b/src/cosim/osp_config_parser.cpp @@ -938,27 +938,41 @@ osp_config load_osp_config( const auto modelUri = resolve_reference(baseURI, simulator.source); cosim::filesystem::path msmiFilePath; - msmiFilePath = file_uri_to_path(modelUri).remove_filename() / msmiFileName; - if (cosim::filesystem::exists(msmiFilePath)) { - emds.emplace(simulator.name, msmiFilePath); +// msmiFilePath = modelUri.view().substr(modelUri.view().find("file=") + 5); +// BOOST_LOG_SEV(log::logger(), log::error) << "msmiFilePath: " << msmiFilePath; + + if (modelUri.scheme() == "file") { + msmiFilePath = file_uri_to_path(modelUri).remove_filename() / msmiFileName; +// BOOST_LOG_SEV(log::logger(), log::error) << "msmiFilePath: " << msmiFilePath; +// BOOST_LOG_SEV(log::logger(), log::error) << +// "msmiFilePath proxy: " << file_uri_to_path("proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu").remove_filename() / msmiFileName; + + if (cosim::filesystem::exists(msmiFilePath)) { + emds.emplace(simulator.name, msmiFilePath); + } else { + msmiFilePath = configFile.parent_path() / msmiFileName; + if (cosim::filesystem::exists(msmiFilePath)) { + emds.emplace(simulator.name, msmiFilePath); + } + } } else { - msmiFilePath = configFile.parent_path() / msmiFileName; + // Makes it possible to keep OspModelDescription at configuration path + // even when there are FMUs with other URI than file (fmu-proxy). + // msmiFilePath = file_uri_to_path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() /msmiFileName; + + msmiFilePath = cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; + //BOOST_LOG_SEV(log::logger(), log::error) << "msmiFilePath: " << msmiFilePath; + + // msmiFilePath = file_uri_to_path(modelUri).remove_filename() / msmiFileName; if (cosim::filesystem::exists(msmiFilePath)) { emds.emplace(simulator.name, msmiFilePath); + } else { + msmiFilePath = configFile.parent_path() / msmiFileName; + if (cosim::filesystem::exists(msmiFilePath)) { + emds.emplace(simulator.name, msmiFilePath); + } } } - -// if (modelUri.scheme() == "file") { -// -// } else { -// // Makes it possible to keep OspModelDescription at configuration path -// // even when there are FMUs with other URI than file (fmu-proxy). -// -// msmiFilePath = configFile.parent_path() / msmiFileName; -// if (cosim::filesystem::exists(msmiFilePath)) { -// emds.emplace(simulator.name, msmiFilePath); -// } -// } } connect_variables(parser.get_variable_connections(), config.system_structure); diff --git a/src/cosim/uri.cpp b/src/cosim/uri.cpp index 3b52f3b9..1f73a9c3 100644 --- a/src/cosim/uri.cpp +++ b/src/cosim/uri.cpp @@ -533,6 +533,7 @@ cosim::filesystem::path file_uri_to_path(const uri& fileUri) // && (fileUri.authority()->empty() || *fileUri.authority() == "localhost") ); + #ifdef _WIN32 // Windows has some special rules for file URIs; better use the built-in // functions. diff --git a/tests/uri_unittest.cpp b/tests/uri_unittest.cpp index ed45cd9f..a65e7c7c 100644 --- a/tests/uri_unittest.cpp +++ b/tests/uri_unittest.cpp @@ -1,7 +1,9 @@ #define BOOST_TEST_MODULE uri.hpp unittests + #include #include +#include "cosim/log/logger.hpp" #include @@ -198,6 +200,7 @@ BOOST_AUTO_TEST_CASE(percent_encoding) BOOST_AUTO_TEST_CASE(file_uri_conversions) { + //BOOST_TEST_LOG_LEVEL=message file_uri_conversions // From path to URI BOOST_TEST(path_to_file_uri("/foo bar/baz") == "file:///foo%20bar/baz"); BOOST_TEST(path_to_file_uri(cosim::filesystem::path()) == "file:"); @@ -213,12 +216,60 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) BOOST_TEST(file_uri_to_path("file:///c:/foo%20bar/baz") == "c:\\foo bar\\baz"); BOOST_TEST(file_uri_to_path("file://localhost/foo%20bar/baz") == "\\foo bar\\baz"); BOOST_TEST(file_uri_to_path("file://localhost/c:/foo%20bar/baz") == "c:\\foo bar\\baz"); + //BOOST_WARN("test message"); + BOOST_LOG_SEV(log::logger(), log::warning) + << "testing log "; + + + //const auto modelUri = resolve_reference("proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu", "Damper"); + // cosim::filesystem::path msmiFilePath; + +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "model uri scheme: " << (modelUri.scheme() == "proxyfmu"); +// +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "model uri authority: " << (modelUri.authority() == "10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"); +// +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "model uri query: " << modelUri.query().has_value(); + + +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "file uri to path: " << file_uri_to_path("proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"); + // "msmiFilePath proxy: " << + + std::string str = "proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"; + + //std::size_t pos = str.find("file="); + + const auto modelUri = resolve_reference("C://asdfasdf/asdfasasdf/OspSystemStructure.xml", "proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"); + + BOOST_LOG_SEV(log::logger(), log::warning) + << "model uri view : " << modelUri.view(); + + cosim::filesystem::path filePath = cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)); + + // str.substr(str.find("file=") + 5) + + cosim::filesystem::path file = filePath.remove_filename(); + + BOOST_LOG_SEV(log::logger(), log::warning) + << "model uri file : " << file; + + + + + // BOOST_TEST(file_uri_to_path("proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu") == "c:\\foo bar\\baz"); + //BOOST_TEST(file_uri_to_path("proxyfmu://localhost/88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu") == "c:\\foo bar\\baz"); + #else BOOST_TEST(file_uri_to_path("file:///foo%20bar/baz") == "/foo bar/baz"); BOOST_TEST(file_uri_to_path("file:///c:/foo%20bar/baz") == "/c:/foo bar/baz"); BOOST_TEST(file_uri_to_path("file://localhost/foo%20bar/baz") == "/foo bar/baz"); BOOST_TEST(file_uri_to_path("file://localhost/c:/foo%20bar/baz") == "/c:/foo bar/baz"); #endif + // proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu BOOST_CHECK_THROW(file_uri_to_path("http://foo/bar"), std::invalid_argument); - //BOOST_CHECK_THROW(file_uri_to_path("file://foo/bar"), std::invalid_argument); + //BOOST_CHECK_THROW(file_uri_to_path("proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"), std::invalid_argument); + // BOOST_CHECK_THROW(file_uri_to_path("file://foo/bar"), std::invalid_argument); } From f3b2330e303f4b852ac3cd24c40b4aee76ae8332 Mon Sep 17 00:00:00 2001 From: msteinsto Date: Wed, 2 Mar 2022 12:48:17 +0100 Subject: [PATCH 05/20] Fixed fmuproxy model path --- src/cosim/osp_config_parser.cpp | 2 +- tests/uri_unittest.cpp | 37 ++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/cosim/osp_config_parser.cpp b/src/cosim/osp_config_parser.cpp index 572e9cd5..c7fdef4d 100644 --- a/src/cosim/osp_config_parser.cpp +++ b/src/cosim/osp_config_parser.cpp @@ -960,7 +960,7 @@ osp_config load_osp_config( // even when there are FMUs with other URI than file (fmu-proxy). // msmiFilePath = file_uri_to_path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() /msmiFileName; - msmiFilePath = cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; + msmiFilePath = configFile.parent_path().remove_filename() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; //BOOST_LOG_SEV(log::logger(), log::error) << "msmiFilePath: " << msmiFilePath; // msmiFilePath = file_uri_to_path(modelUri).remove_filename() / msmiFileName; diff --git a/tests/uri_unittest.cpp b/tests/uri_unittest.cpp index a65e7c7c..d54b090d 100644 --- a/tests/uri_unittest.cpp +++ b/tests/uri_unittest.cpp @@ -238,23 +238,50 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) // << "file uri to path: " << file_uri_to_path("proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"); // "msmiFilePath proxy: " << - std::string str = "proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"; + // std::string str = "proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"; //std::size_t pos = str.find("file="); - const auto modelUri = resolve_reference("C://asdfasdf/asdfasasdf/OspSystemStructure.xml", "proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"); + const cosim::filesystem::path configPath = cosim::filesystem::path("C://asdfasdf/asdfasasdf/OspSystemStructure.xml"); + + const auto absolutePath = cosim::filesystem::absolute(configPath); + const auto configFile = cosim::filesystem::is_regular_file(absolutePath) + ? absolutePath + : absolutePath / "OspSystemStructure.xml"; + const auto baseURI = path_to_file_uri(configFile); + + //configFile.parent_path() + + const auto modelUri = resolve_reference(baseURI, "proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"); + + //const auto modelUri = resolve_reference(baseURI, "proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"); BOOST_LOG_SEV(log::logger(), log::warning) << "model uri view : " << modelUri.view(); - cosim::filesystem::path filePath = cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)); + + BOOST_LOG_SEV(log::logger(), log::warning) + << "model uri view local : " << resolve_reference("C://asdfasdf/asdfasasdf/OspSystemStructure.xml", "C://asdfasfasdfasdf/afsdfasdf/88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"); + + // cosim::filesystem::path filePath = cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)); + + // const auto testDataDir = std::getenv("TEST_DATA_DIR"); + + +// const auto absolutePath = cosim::filesystem::absolute(configPath); +// const auto configFile = cosim::filesystem::is_regular_file(absolutePath) +// ? absolutePath +// : absolutePath / "OspSystemStructure.xml"; +// const auto baseURI = path_to_file_uri(configFile); // str.substr(str.find("file=") + 5) - cosim::filesystem::path file = filePath.remove_filename(); + std::string msmiFileName = "Damper_OspModelDescription.xml"; + + cosim::filesystem::path file = cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename(); BOOST_LOG_SEV(log::logger(), log::warning) - << "model uri file : " << file; + << "model uri file : " << configFile.parent_path().remove_filename() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; From 4485b9fc52acfde5efbda762397a39283e7f26d9 Mon Sep 17 00:00:00 2001 From: msteinsto Date: Wed, 2 Mar 2022 15:32:50 +0100 Subject: [PATCH 06/20] File path fix --- src/cosim/osp_config_parser.cpp | 6 ++++- tests/uri_unittest.cpp | 44 ++++++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/cosim/osp_config_parser.cpp b/src/cosim/osp_config_parser.cpp index c7fdef4d..6d90da52 100644 --- a/src/cosim/osp_config_parser.cpp +++ b/src/cosim/osp_config_parser.cpp @@ -960,9 +960,13 @@ osp_config load_osp_config( // even when there are FMUs with other URI than file (fmu-proxy). // msmiFilePath = file_uri_to_path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() /msmiFileName; - msmiFilePath = configFile.parent_path().remove_filename() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; + // msmiFilePath = configFile.parent_path().remove_filename() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; //BOOST_LOG_SEV(log::logger(), log::error) << "msmiFilePath: " << msmiFilePath; + msmiFilePath = configFile.parent_path() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; + + // proxyfmu://10.1.13.203:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu + // msmiFilePath = file_uri_to_path(modelUri).remove_filename() / msmiFileName; if (cosim::filesystem::exists(msmiFilePath)) { emds.emplace(simulator.name, msmiFilePath); diff --git a/tests/uri_unittest.cpp b/tests/uri_unittest.cpp index d54b090d..4c5ccdbb 100644 --- a/tests/uri_unittest.cpp +++ b/tests/uri_unittest.cpp @@ -242,16 +242,30 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) //std::size_t pos = str.find("file="); - const cosim::filesystem::path configPath = cosim::filesystem::path("C://asdfasdf/asdfasasdf/OspSystemStructure.xml"); + // const cosim::filesystem::path configPath = cosim::filesystem::path("C://asdfasdf/asdfasasdf/OspSystemStructure.xml"); + + + const auto testDataDir = std::getenv("TEST_DATA_DIR"); + //BOOST_TEST_REQUIRE(!!testDataDir); + const auto configPath = cosim::filesystem::path(testDataDir) / "asdfasdfasdfasdfsdaf" / "asdf" / "OspSystemStructure.xml"; + + const auto absolutePath = cosim::filesystem::absolute(configPath); const auto configFile = cosim::filesystem::is_regular_file(absolutePath) ? absolutePath - : absolutePath / "OspSystemStructure.xml"; + : absolutePath; + //: absolutePath / "OspSystemStructure.xml"; const auto baseURI = path_to_file_uri(configFile); + //const auto baseURI = path_to_file_uri(absolutePath); //configFile.parent_path() + + const auto modelPathLocal = cosim::filesystem::path(testDataDir) / "asdfasdfasdfasdfsdaf" / "asdf" / "88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C" / "Damper_OspModelDescription.xml"; + + // const auto modelUriLocal = resolve_reference(baseURI, modelPathLocal); + const auto modelUri = resolve_reference(baseURI, "proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"); //const auto modelUri = resolve_reference(baseURI, "proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"); @@ -260,8 +274,6 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) << "model uri view : " << modelUri.view(); - BOOST_LOG_SEV(log::logger(), log::warning) - << "model uri view local : " << resolve_reference("C://asdfasdf/asdfasasdf/OspSystemStructure.xml", "C://asdfasfasdfasdf/afsdfasdf/88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"); // cosim::filesystem::path filePath = cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)); @@ -277,11 +289,31 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) // str.substr(str.find("file=") + 5) std::string msmiFileName = "Damper_OspModelDescription.xml"; + //const auto testDataDir = std::getenv("TEST_DATA_DIR"); + // cosim::filesystem::path(testDataDir) + +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "model uri view local : " << file_uri_to_path(modelUri).remove_filename() / msmiFileName; - cosim::filesystem::path file = cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename(); + // cosim::filesystem::path file = cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename(); + + BOOST_LOG_SEV(log::logger(), log::warning) + << "model uri file : " << configFile.parent_path() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; + + BOOST_LOG_SEV(log::logger(), log::warning) + << "model uri file config : " << configFile; + + BOOST_LOG_SEV(log::logger(), log::warning) + << "model uri file parent : " << configFile.parent_path(); + + BOOST_LOG_SEV(log::logger(), log::warning) + << "model uri file parent substring : " << modelUri.view().substr(modelUri.view().find("file=") + 5); + + BOOST_LOG_SEV(log::logger(), log::warning) + << "model uri file file : " << cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename(); BOOST_LOG_SEV(log::logger(), log::warning) - << "model uri file : " << configFile.parent_path().remove_filename() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; + << "model uri file msmi : " << msmiFileName; From 7433063e5594615996c0c44723c2b21043e74f32 Mon Sep 17 00:00:00 2001 From: msteinsto Date: Thu, 3 Mar 2022 10:11:40 +0100 Subject: [PATCH 07/20] Added logging for debugging --- src/cosim/osp_config_parser.cpp | 4 ++ tests/uri_unittest.cpp | 78 +++++++++++++++++++++++++++------ 2 files changed, 69 insertions(+), 13 deletions(-) diff --git a/src/cosim/osp_config_parser.cpp b/src/cosim/osp_config_parser.cpp index 6d90da52..f5320905 100644 --- a/src/cosim/osp_config_parser.cpp +++ b/src/cosim/osp_config_parser.cpp @@ -969,10 +969,14 @@ osp_config load_osp_config( // msmiFilePath = file_uri_to_path(modelUri).remove_filename() / msmiFileName; if (cosim::filesystem::exists(msmiFilePath)) { + BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy relative path: " << msmiFilePath; + BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy relative path: simulator name: " << simulator.name; emds.emplace(simulator.name, msmiFilePath); } else { msmiFilePath = configFile.parent_path() / msmiFileName; if (cosim::filesystem::exists(msmiFilePath)) { + BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path: " << msmiFilePath; + BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path: simulator name: " << simulator.name; emds.emplace(simulator.name, msmiFilePath); } } diff --git a/tests/uri_unittest.cpp b/tests/uri_unittest.cpp index 4c5ccdbb..b343cb11 100644 --- a/tests/uri_unittest.cpp +++ b/tests/uri_unittest.cpp @@ -5,6 +5,13 @@ #include #include "cosim/log/logger.hpp" +//#include +//#include + +//#include + +#include + #include using namespace cosim; @@ -112,13 +119,13 @@ BOOST_AUTO_TEST_CASE(uri_copy_and_move) // Special case: Short strings which may be affected by the small-string // optimisation (see issue #361) - auto small = uri("x"); - const auto smallCopy = small; - const auto smallMove = std::move(small); - small = uri(); - - BOOST_TEST(smallCopy.path() == "x"); - BOOST_TEST(smallMove.path() == "x"); +// auto small = uri("x"); +// const auto smallCopy = small; +// const auto smallMove = std::move(small); +// small = uri(); +// +// BOOST_TEST(smallCopy.path() == "x"); +// BOOST_TEST(smallMove.path() == "x"); } @@ -247,33 +254,66 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) const auto testDataDir = std::getenv("TEST_DATA_DIR"); //BOOST_TEST_REQUIRE(!!testDataDir); - const auto configPath = cosim::filesystem::path(testDataDir) / "asdfasdfasdfasdfsdaf" / "asdf" / "OspSystemStructure.xml"; + const auto configPath = cosim::filesystem::path(testDataDir) / "msmi" / "OspSystemStructure.xml"; const auto absolutePath = cosim::filesystem::absolute(configPath); const auto configFile = cosim::filesystem::is_regular_file(absolutePath) ? absolutePath - : absolutePath; - //: absolutePath / "OspSystemStructure.xml"; + //: absolutePath; + : absolutePath / "OspSystemStructure.xml"; const auto baseURI = path_to_file_uri(configFile); //const auto baseURI = path_to_file_uri(absolutePath); //configFile.parent_path() - const auto modelPathLocal = cosim::filesystem::path(testDataDir) / "asdfasdfasdfasdfsdaf" / "asdf" / "88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C" / "Damper_OspModelDescription.xml"; + const auto modelPathLocal = cosim::filesystem::path(testDataDir) / "msmi" / "D679C8C9-657E-39E9-8B4E-0799CA3745E4" / "Damper_OspModelDescription.xml"; // const auto modelUriLocal = resolve_reference(baseURI, modelPathLocal); - const auto modelUri = resolve_reference(baseURI, "proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"); + // const auto modelURI = - //const auto modelUri = resolve_reference(baseURI, "proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"); + const auto modelUri = resolve_reference(baseURI, "proxyfmu://10.1.13.178:9090?file=D679C8C9-657E-39E9-8B4E-0799CA3745E4/Damper.fmu"); + + //auto resolver = cosim::default_model_uri_resolver(); + // resolver.add_sub_resolver(std::make_shared()); + // auto model = resolver->lookup_model(baseURI, "proxyfmu://10.1.13.178:9090?file=D679C8C9-657E-39E9-8B4E-0799CA3745E4/Damper.fmu"); + + +// const auto& mur = modelUriReference; +// const auto query = mur.query(); +// if (query) { +// if (query->find("file=file:///") < query->size()) { +// const auto newQuery = "file=" + std::string(query->substr(13)); +// return model_uri_sub_resolver::lookup_model( +// baseUri, uri(mur.scheme(), mur.authority(), mur.path(), newQuery, mur.fragment())); +// } else if (query->find("file=") < query->size()) { +// const auto pathToAppend = cosim::file_uri_to_path(baseUri).parent_path().string(); +// const auto newQuery = "file=" + pathToAppend + "/" + std::string(query->substr(5)); +// return model_uri_sub_resolver::lookup_model( +// baseUri, uri(mur.scheme(), mur.authority(), mur.path(), newQuery, mur.fragment())); +// } +// } +// return model_uri_sub_resolver::lookup_model(baseUri, mur); + +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "model query has query: " << (modelUri.query()); BOOST_LOG_SEV(log::logger(), log::warning) << "model uri view : " << modelUri.view(); +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "model query file: " << (modelUri.query()->find("file=") -> modelUri.query()->size()); + + + //const auto modelUri = resolve_reference(baseURI, "proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"); + + + + // cosim::filesystem::path filePath = cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)); @@ -303,6 +343,18 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) BOOST_LOG_SEV(log::logger(), log::warning) << "model uri file config : " << configFile; + + + BOOST_LOG_SEV(log::logger(), log::warning) + << "model uri file config uri: " << path_to_file_uri(configFile.parent_path()); + + // path_to_file_uri + + + +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "model uri file config file uri to path : " << file_uri_to_path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename(); + BOOST_LOG_SEV(log::logger(), log::warning) << "model uri file parent : " << configFile.parent_path(); From 555ca0b37a83108b2f1588f9446b2250e545f377 Mon Sep 17 00:00:00 2001 From: msteinsto Date: Thu, 3 Mar 2022 11:30:19 +0100 Subject: [PATCH 08/20] Fix prototype --- src/cosim/osp_config_parser.cpp | 89 +++++++++++++++++++++++++++------ tests/uri_unittest.cpp | 32 ++++++++++++ 2 files changed, 105 insertions(+), 16 deletions(-) diff --git a/src/cosim/osp_config_parser.cpp b/src/cosim/osp_config_parser.cpp index f5320905..e187f471 100644 --- a/src/cosim/osp_config_parser.cpp +++ b/src/cosim/osp_config_parser.cpp @@ -946,7 +946,6 @@ osp_config load_osp_config( // BOOST_LOG_SEV(log::logger(), log::error) << "msmiFilePath: " << msmiFilePath; // BOOST_LOG_SEV(log::logger(), log::error) << // "msmiFilePath proxy: " << file_uri_to_path("proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu").remove_filename() / msmiFileName; - if (cosim::filesystem::exists(msmiFilePath)) { emds.emplace(simulator.name, msmiFilePath); } else { @@ -955,31 +954,89 @@ osp_config load_osp_config( emds.emplace(simulator.name, msmiFilePath); } } - } else { - // Makes it possible to keep OspModelDescription at configuration path - // even when there are FMUs with other URI than file (fmu-proxy). - // msmiFilePath = file_uri_to_path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() /msmiFileName; + } +// else if (modelUri.scheme() == "proxyfmu") { +// const auto query = *modelUri.query(); +// if (query.substr(0, 5) == "file=") { +// auto queryPath = cosim::filesystem::path(std::string(query.substr(5))); +// +// msmiFilePath = configFile.parent_path() / queryPath.remove_filename() / msmiFileName; +// +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "msmi file path query: " << msmiFilePath; +// } +// } + else { +// msmiFilePath = configFile.parent_path() / msmiFileName; +// if (cosim::filesystem::exists(msmiFilePath)) { +// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: " << msmiFilePath; +// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: simulator name: " << simulator.name; +// emds.emplace(simulator.name, msmiFilePath); +// } + + const auto query = *modelUri.query(); + if (query.substr(0, 5) == "file=") { + auto queryPath = cosim::filesystem::path(std::string(query.substr(5))); + msmiFilePath = configFile.parent_path() / queryPath.remove_filename() / msmiFileName; + + BOOST_LOG_SEV(log::logger(), log::warning) + << "msmi file path query: " << msmiFilePath; - // msmiFilePath = configFile.parent_path().remove_filename() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; - //BOOST_LOG_SEV(log::logger(), log::error) << "msmiFilePath: " << msmiFilePath; + if (cosim::filesystem::exists(msmiFilePath)) { + BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy relative path query: " << msmiFilePath; + BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy relative path query: simulator name: " << simulator.name; + emds.emplace(simulator.name, msmiFilePath); + } else { + msmiFilePath = configFile.parent_path() / msmiFileName; + if (cosim::filesystem::exists(msmiFilePath)) { + BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path no query: " << msmiFilePath; + BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path no query: simulator name: " << simulator.name; + emds.emplace(simulator.name, msmiFilePath); + } + } - msmiFilePath = configFile.parent_path() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; - // proxyfmu://10.1.13.203:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu - // msmiFilePath = file_uri_to_path(modelUri).remove_filename() / msmiFileName; - if (cosim::filesystem::exists(msmiFilePath)) { - BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy relative path: " << msmiFilePath; - BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy relative path: simulator name: " << simulator.name; - emds.emplace(simulator.name, msmiFilePath); + // if (!cosim::filesystem::exists(file)) { + // BOOST_LOG_SEV(log::logger(), log::warning) + // << "no query file : " << file.string(); + // } else { + // BOOST_LOG_SEV(log::logger(), log::warning) + // << "query file found: " << file.string(); + // } } else { msmiFilePath = configFile.parent_path() / msmiFileName; if (cosim::filesystem::exists(msmiFilePath)) { - BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path: " << msmiFilePath; - BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path: simulator name: " << simulator.name; + BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: " << msmiFilePath; + BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: simulator name: " << simulator.name; emds.emplace(simulator.name, msmiFilePath); } } + + // Makes it possible to keep OspModelDescription at configuration path + // even when there are FMUs with other URI than file (fmu-proxy). + // msmiFilePath = file_uri_to_path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() /msmiFileName; + + // msmiFilePath = configFile.parent_path().remove_filename() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; + //BOOST_LOG_SEV(log::logger(), log::error) << "msmiFilePath: " << msmiFilePath; + +// msmiFilePath = configFile.parent_path() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; +// +// // proxyfmu://10.1.13.203:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu +// +// // msmiFilePath = file_uri_to_path(modelUri).remove_filename() / msmiFileName; +// if (cosim::filesystem::exists(msmiFilePath)) { +// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy relative path: " << msmiFilePath; +// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy relative path: simulator name: " << simulator.name; +// emds.emplace(simulator.name, msmiFilePath); +// } else { +// msmiFilePath = configFile.parent_path() / msmiFileName; +// if (cosim::filesystem::exists(msmiFilePath)) { +// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: " << msmiFilePath; +// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: simulator name: " << simulator.name; +// emds.emplace(simulator.name, msmiFilePath); +// } +// } } } diff --git a/tests/uri_unittest.cpp b/tests/uri_unittest.cpp index b343cb11..daa47efa 100644 --- a/tests/uri_unittest.cpp +++ b/tests/uri_unittest.cpp @@ -329,6 +329,38 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) // str.substr(str.find("file=") + 5) std::string msmiFileName = "Damper_OspModelDescription.xml"; + + + cosim::filesystem::path msmiFilePath; + + + const auto query = *modelUri.query(); + if (query.substr(0, 5) == "file=") { + auto queryPath = cosim::filesystem::path(std::string(query.substr(5))); + msmiFilePath = configFile.parent_path() / queryPath.remove_filename() / msmiFileName; + + BOOST_LOG_SEV(log::logger(), log::warning) + << "msmi file path query: " << msmiFilePath; + +// if (!cosim::filesystem::exists(file)) { +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "no query file : " << file.string(); +// } else { +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "query file found: " << file.string(); +// } + } else { + BOOST_LOG_SEV(log::logger(), log::warning) + << "no file in query: "; + } + + // msmiFilePath = configFile.parent_path() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; + + + + + + //const auto testDataDir = std::getenv("TEST_DATA_DIR"); // cosim::filesystem::path(testDataDir) From 7173d9a84b80753a1baa76247e7d3352a27e6ab2 Mon Sep 17 00:00:00 2001 From: msteinsto Date: Fri, 4 Mar 2022 09:59:45 +0100 Subject: [PATCH 09/20] Absolute path query file support --- include/cosim/uri.hpp | 17 +- src/cosim/osp_config_parser.cpp | 214 ++++++++++++++------- src/cosim/proxy/proxy_uri_sub_resolver.cpp | 11 ++ src/cosim/uri.cpp | 21 +- tests/uri_unittest.cpp | 51 +++-- 5 files changed, 218 insertions(+), 96 deletions(-) diff --git a/include/cosim/uri.hpp b/include/cosim/uri.hpp index 6436cd79..d1d25717 100644 --- a/include/cosim/uri.hpp +++ b/include/cosim/uri.hpp @@ -266,7 +266,7 @@ uri path_to_file_uri(const cosim::filesystem::path& path); * * \param [in] fileUri * An URI where the scheme component is equal to `file` and the `authority` - * component is either empty or equel to `localhost` (but not undefined). + * component is either empty or equal to `localhost` (but not undefined). * * \returns * The path that corresponds to `fileUri`. @@ -274,5 +274,20 @@ uri path_to_file_uri(const cosim::filesystem::path& path); cosim::filesystem::path file_uri_to_path(const uri& fileUri); +/** + * Converts a query parameter URI to a local filesystem path. + * + * \param [in] baseUri + * An (absolute) base URI. + * \param [in] queryUri + * An URI with arbitrary scheme component. Query file parameter path (if any) + * is specified after `file=`. A prefix of `file:///` specifies absolute path. + * + * \returns + * The path that corresponds to `queryUri` parameter or the `baseUri` parent path. + */ +cosim::filesystem::path file_query_uri_to_path(const uri& baseUri, const uri& queryUri); + + } // namespace cosim #endif // header guard diff --git a/src/cosim/osp_config_parser.cpp b/src/cosim/osp_config_parser.cpp index e187f471..1cc12412 100644 --- a/src/cosim/osp_config_parser.cpp +++ b/src/cosim/osp_config_parser.cpp @@ -941,20 +941,52 @@ osp_config load_osp_config( // msmiFilePath = modelUri.view().substr(modelUri.view().find("file=") + 5); // BOOST_LOG_SEV(log::logger(), log::error) << "msmiFilePath: " << msmiFilePath; - if (modelUri.scheme() == "file") { - msmiFilePath = file_uri_to_path(modelUri).remove_filename() / msmiFileName; -// BOOST_LOG_SEV(log::logger(), log::error) << "msmiFilePath: " << msmiFilePath; -// BOOST_LOG_SEV(log::logger(), log::error) << -// "msmiFilePath proxy: " << file_uri_to_path("proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu").remove_filename() / msmiFileName; + msmiFilePath = (modelUri.scheme() == "file") + ? file_uri_to_path(modelUri).remove_filename() / msmiFileName + : file_query_uri_to_path(baseURI, modelUri).remove_filename() / msmiFileName; + + if (cosim::filesystem::exists(msmiFilePath)) { + BOOST_LOG_SEV(log::logger(), log::error) << "msmiFilePath function exists: " << msmiFilePath; + emds.emplace(simulator.name, msmiFilePath); + } else { + msmiFilePath = configFile.parent_path() / msmiFileName; if (cosim::filesystem::exists(msmiFilePath)) { + BOOST_LOG_SEV(log::logger(), log::error) << "msmiFilePath conf exists: " << msmiFilePath; emds.emplace(simulator.name, msmiFilePath); - } else { - msmiFilePath = configFile.parent_path() / msmiFileName; - if (cosim::filesystem::exists(msmiFilePath)) { - emds.emplace(simulator.name, msmiFilePath); - } } } + +// if (modelUri.scheme() == "file") { +// msmiFilePath = file_uri_to_path(modelUri).remove_filename() / msmiFileName; +//// BOOST_LOG_SEV(log::logger(), log::error) << "msmiFilePath: " << msmiFilePath; +//// BOOST_LOG_SEV(log::logger(), log::error) << +//// "msmiFilePath proxy: " << file_uri_to_path("proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu").remove_filename() / msmiFileName; +// if (cosim::filesystem::exists(msmiFilePath)) { +// emds.emplace(simulator.name, msmiFilePath); +// } else { +// msmiFilePath = configFile.parent_path() / msmiFileName; +// if (cosim::filesystem::exists(msmiFilePath)) { +// emds.emplace(simulator.name, msmiFilePath); +// } +// } +// } + + +// else if (modelUri.scheme() == "proxyfmu") { +// // msmiFilePath = configFile.parent_path() / proxyfmu_uri_to_relative_path(modelUri).remove_filename() / msmiFileName; +// msmiFilePath = proxyfmu_uri_to_path(baseURI, modelUri).remove_filename() / msmiFileName; +// +// if (cosim::filesystem::exists(msmiFilePath)) { +// emds.emplace(simulator.name, msmiFilePath); +// } else { +// msmiFilePath = configFile.parent_path() / msmiFileName; +// if (cosim::filesystem::exists(msmiFilePath)) { +// emds.emplace(simulator.name, msmiFilePath); +// } +// } +// } + + // else if (modelUri.scheme() == "proxyfmu") { // const auto query = *modelUri.query(); // if (query.substr(0, 5) == "file=") { @@ -966,78 +998,112 @@ osp_config load_osp_config( // << "msmi file path query: " << msmiFilePath; // } // } - else { -// msmiFilePath = configFile.parent_path() / msmiFileName; -// if (cosim::filesystem::exists(msmiFilePath)) { -// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: " << msmiFilePath; -// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: simulator name: " << simulator.name; -// emds.emplace(simulator.name, msmiFilePath); -// } - - const auto query = *modelUri.query(); - if (query.substr(0, 5) == "file=") { - auto queryPath = cosim::filesystem::path(std::string(query.substr(5))); - msmiFilePath = configFile.parent_path() / queryPath.remove_filename() / msmiFileName; - - BOOST_LOG_SEV(log::logger(), log::warning) - << "msmi file path query: " << msmiFilePath; - - if (cosim::filesystem::exists(msmiFilePath)) { - BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy relative path query: " << msmiFilePath; - BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy relative path query: simulator name: " << simulator.name; - emds.emplace(simulator.name, msmiFilePath); - } else { - msmiFilePath = configFile.parent_path() / msmiFileName; - if (cosim::filesystem::exists(msmiFilePath)) { - BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path no query: " << msmiFilePath; - BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path no query: simulator name: " << simulator.name; - emds.emplace(simulator.name, msmiFilePath); - } - } - - - - // if (!cosim::filesystem::exists(file)) { - // BOOST_LOG_SEV(log::logger(), log::warning) - // << "no query file : " << file.string(); - // } else { - // BOOST_LOG_SEV(log::logger(), log::warning) - // << "query file found: " << file.string(); - // } - } else { - msmiFilePath = configFile.parent_path() / msmiFileName; - if (cosim::filesystem::exists(msmiFilePath)) { - BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: " << msmiFilePath; - BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: simulator name: " << simulator.name; - emds.emplace(simulator.name, msmiFilePath); - } - } - - // Makes it possible to keep OspModelDescription at configuration path - // even when there are FMUs with other URI than file (fmu-proxy). - // msmiFilePath = file_uri_to_path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() /msmiFileName; - - // msmiFilePath = configFile.parent_path().remove_filename() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; - //BOOST_LOG_SEV(log::logger(), log::error) << "msmiFilePath: " << msmiFilePath; - -// msmiFilePath = configFile.parent_path() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; -// -// // proxyfmu://10.1.13.203:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu -// -// // msmiFilePath = file_uri_to_path(modelUri).remove_filename() / msmiFileName; +// else { +// msmiFilePath = file_query_uri_to_path(baseURI, modelUri).remove_filename() / msmiFileName; // if (cosim::filesystem::exists(msmiFilePath)) { -// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy relative path: " << msmiFilePath; -// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy relative path: simulator name: " << simulator.name; // emds.emplace(simulator.name, msmiFilePath); // } else { // msmiFilePath = configFile.parent_path() / msmiFileName; // if (cosim::filesystem::exists(msmiFilePath)) { -// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: " << msmiFilePath; -// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: simulator name: " << simulator.name; // emds.emplace(simulator.name, msmiFilePath); // } // } - } +// +// // msmiFilePath = configFile.parent_path() / proxyfmu_uri_to_relative_path(modelUri).remove_filename() / msmiFileName; +// +// +//// msmiFilePath = configFile.parent_path() / msmiFileName; +//// if (cosim::filesystem::exists(msmiFilePath)) { +//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: " << msmiFilePath; +//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: simulator name: " << simulator.name; +//// emds.emplace(simulator.name, msmiFilePath); +//// } +//// msmiFilePath = configFile.parent_path() / msmiFileName; +//// if (cosim::filesystem::exists(msmiFilePath)) { +//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: " << msmiFilePath; +//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: simulator name: " << simulator.name; +//// emds.emplace(simulator.name, msmiFilePath); +//// } +// // Makes it possible to keep OspModelDescription at configuration path +// // even when there are FMUs with other URI than file. +// // Relative path to the OspModelDescription file can be specified as a file query parameter +// +// +// +//// if (modelUri.scheme().has_value() && modelUri.authority() && modelUri.query()) { +//// const auto query = *modelUri.query(); +//// if (query.substr(0, 5) == "file=") { +//// auto queryFile = cosim::filesystem::path(std::string(query.substr(5))); +//// if (!cosim::filesystem::exists(queryFile)) { +//// msmiFilePath = configFile.parent_path() / queryFile.remove_filename() / msmiFileName; +//// +//// BOOST_LOG_SEV(log::logger(), log::warning) +//// << "msmi file path query: " << msmiFilePath; +//// +//// if (cosim::filesystem::exists(msmiFilePath)) { +//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy relative path query: " << msmiFilePath; +//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy relative path query: simulator name: " << simulator.name; +//// emds.emplace(simulator.name, msmiFilePath); +//// } else { +//// msmiFilePath = configFile.parent_path() / msmiFileName; +//// if (cosim::filesystem::exists(msmiFilePath)) { +//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path no query: " << msmiFilePath; +//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path no query: simulator name: " << simulator.name; +//// emds.emplace(simulator.name, msmiFilePath); +//// } +//// } +//// } else { +//// msmiFilePath = configFile.parent_path() / msmiFileName; +//// if (cosim::filesystem::exists(msmiFilePath)) { +//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: " << msmiFilePath; +//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: simulator name: " << simulator.name; +//// emds.emplace(simulator.name, msmiFilePath); +//// } +//// } +//// } else { +//// msmiFilePath = configFile.parent_path() / msmiFileName; +//// if (cosim::filesystem::exists(msmiFilePath)) { +//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: " << msmiFilePath; +//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: simulator name: " << simulator.name; +//// emds.emplace(simulator.name, msmiFilePath); +//// } +//// } +//// } +// +// +// +//// assert(modelUri.scheme().has_value()); +//// if (*modelUri.scheme() != "proxyfmu") return nullptr; +//// COSIM_INPUT_CHECK(modelUri.authority()); +//// COSIM_INPUT_CHECK(modelUri.query()); +// +// +// +// // Makes it possible to keep OspModelDescription at configuration path +// // even when there are FMUs with other URI than file (fmu-proxy). +// // msmiFilePath = file_uri_to_path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() /msmiFileName; +// +// // msmiFilePath = configFile.parent_path().remove_filename() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; +// //BOOST_LOG_SEV(log::logger(), log::error) << "msmiFilePath: " << msmiFilePath; +// +//// msmiFilePath = configFile.parent_path() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; +//// +//// // proxyfmu://10.1.13.203:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu +//// +//// // msmiFilePath = file_uri_to_path(modelUri).remove_filename() / msmiFileName; +//// if (cosim::filesystem::exists(msmiFilePath)) { +//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy relative path: " << msmiFilePath; +//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy relative path: simulator name: " << simulator.name; +//// emds.emplace(simulator.name, msmiFilePath); +//// } else { +//// msmiFilePath = configFile.parent_path() / msmiFileName; +//// if (cosim::filesystem::exists(msmiFilePath)) { +//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: " << msmiFilePath; +//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: simulator name: " << simulator.name; +//// emds.emplace(simulator.name, msmiFilePath); +//// } +//// } +// } } connect_variables(parser.get_variable_connections(), config.system_structure); diff --git a/src/cosim/proxy/proxy_uri_sub_resolver.cpp b/src/cosim/proxy/proxy_uri_sub_resolver.cpp index 15007414..1267e7a2 100644 --- a/src/cosim/proxy/proxy_uri_sub_resolver.cpp +++ b/src/cosim/proxy/proxy_uri_sub_resolver.cpp @@ -42,6 +42,17 @@ std::shared_ptr cosim::proxy::proxy_uri_sub_resolver::lookup_model return model_uri_sub_resolver::lookup_model(baseUri, mur); } +//cosim::filesystem::path cosim::proxy::file_query_relative_path(const cosim::uri& modelUri) +//{ +// assert(modelUri.scheme().has_value()); +// if (*modelUri.scheme() != "proxyfmu") return nullptr; +// COSIM_INPUT_CHECK(modelUri.authority()); +// COSIM_INPUT_CHECK(modelUri.query()); +// +// +// +//} + std::shared_ptr cosim::proxy::proxy_uri_sub_resolver::lookup_model(const cosim::uri& modelUri) { assert(modelUri.scheme().has_value()); diff --git a/src/cosim/uri.cpp b/src/cosim/uri.cpp index 1f73a9c3..382b959a 100644 --- a/src/cosim/uri.cpp +++ b/src/cosim/uri.cpp @@ -528,9 +528,9 @@ uri path_to_file_uri(const cosim::filesystem::path& path) cosim::filesystem::path file_uri_to_path(const uri& fileUri) { - COSIM_INPUT_CHECK(fileUri.scheme() && (*fileUri.scheme() == "file" || *fileUri.scheme() == "proxyfmu")); + COSIM_INPUT_CHECK(fileUri.scheme() && (*fileUri.scheme() == "file")); COSIM_INPUT_CHECK(fileUri.authority() - // && (fileUri.authority()->empty() || *fileUri.authority() == "localhost") + && (fileUri.authority()->empty() || *fileUri.authority() == "localhost") ); @@ -560,5 +560,22 @@ cosim::filesystem::path file_uri_to_path(const uri& fileUri) #endif } +cosim::filesystem::path file_query_uri_to_path( + const uri& baseUri, + const uri& queryUri) +{ + COSIM_INPUT_CHECK(queryUri.scheme()); + COSIM_INPUT_CHECK(queryUri.authority()); + const auto query = queryUri.query(); + if (query && query->find("file=") < query->size()) { + if (query->find("file=file:///") < query->size()) { + return cosim::filesystem::path(std::string(query->substr(13))); + } + const auto pathToAppend = cosim::file_uri_to_path(baseUri).parent_path().string(); + return cosim::filesystem::path(pathToAppend + "/" + std::string(query->substr(5))); + } + return file_uri_to_path(baseUri).parent_path(); +} + } // namespace cosim diff --git a/tests/uri_unittest.cpp b/tests/uri_unittest.cpp index daa47efa..228ea2f5 100644 --- a/tests/uri_unittest.cpp +++ b/tests/uri_unittest.cpp @@ -334,29 +334,40 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) cosim::filesystem::path msmiFilePath; - const auto query = *modelUri.query(); - if (query.substr(0, 5) == "file=") { - auto queryPath = cosim::filesystem::path(std::string(query.substr(5))); - msmiFilePath = configFile.parent_path() / queryPath.remove_filename() / msmiFileName; +// const auto query = *modelUri.query(); +// if (query.substr(0, 5) == "file=") { +// auto queryPath = cosim::filesystem::path(std::string(query.substr(5))); +// msmiFilePath = configFile.parent_path() / queryPath.remove_filename() / msmiFileName; +// +// +// +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "msmi file path query: " << msmiFilePath; +// +//// if (!cosim::filesystem::exists(file)) { +//// BOOST_LOG_SEV(log::logger(), log::warning) +//// << "no query file : " << file.string(); +//// } else { +//// BOOST_LOG_SEV(log::logger(), log::warning) +//// << "query file found: " << file.string(); +//// } +// } else { +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "no file in query: "; +// } - BOOST_LOG_SEV(log::logger(), log::warning) - << "msmi file path query: " << msmiFilePath; - -// if (!cosim::filesystem::exists(file)) { -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "no query file : " << file.string(); -// } else { -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "query file found: " << file.string(); -// } - } else { - BOOST_LOG_SEV(log::logger(), log::warning) - << "no file in query: "; - } + + + msmiFilePath = file_query_uri_to_path(baseURI, modelUri).remove_filename() / msmiFileName; // msmiFilePath = configFile.parent_path() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; + BOOST_LOG_SEV(log::logger(), log::warning) + << "proxyfmu uri relative : " << file_query_uri_to_path(baseURI, modelUri); + + BOOST_LOG_SEV(log::logger(), log::warning) + << "msmi file path: " << msmiFilePath; @@ -414,5 +425,7 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) // proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu BOOST_CHECK_THROW(file_uri_to_path("http://foo/bar"), std::invalid_argument); //BOOST_CHECK_THROW(file_uri_to_path("proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"), std::invalid_argument); - // BOOST_CHECK_THROW(file_uri_to_path("file://foo/bar"), std::invalid_argument); + // BOOST_CHECK_THROW(file_uri_to_path("file://foo/bar"), std::invalid_argument);' + + //BOOST_TEST(file_query_uri_to_path("", "proxyfmu:///foo/bar?file=baz") == "\\foo bar\\baz"); } From f3c80d6e34d5aa2039233173ba621f46ca705e05 Mon Sep 17 00:00:00 2001 From: msteinsto Date: Fri, 4 Mar 2022 11:31:51 +0100 Subject: [PATCH 10/20] Added some tests --- src/cosim/proxy/proxy_uri_sub_resolver.cpp | 11 -- src/cosim/uri.cpp | 12 +- tests/uri_unittest.cpp | 127 ++++++++++++--------- 3 files changed, 77 insertions(+), 73 deletions(-) diff --git a/src/cosim/proxy/proxy_uri_sub_resolver.cpp b/src/cosim/proxy/proxy_uri_sub_resolver.cpp index 1267e7a2..15007414 100644 --- a/src/cosim/proxy/proxy_uri_sub_resolver.cpp +++ b/src/cosim/proxy/proxy_uri_sub_resolver.cpp @@ -42,17 +42,6 @@ std::shared_ptr cosim::proxy::proxy_uri_sub_resolver::lookup_model return model_uri_sub_resolver::lookup_model(baseUri, mur); } -//cosim::filesystem::path cosim::proxy::file_query_relative_path(const cosim::uri& modelUri) -//{ -// assert(modelUri.scheme().has_value()); -// if (*modelUri.scheme() != "proxyfmu") return nullptr; -// COSIM_INPUT_CHECK(modelUri.authority()); -// COSIM_INPUT_CHECK(modelUri.query()); -// -// -// -//} - std::shared_ptr cosim::proxy::proxy_uri_sub_resolver::lookup_model(const cosim::uri& modelUri) { assert(modelUri.scheme().has_value()); diff --git a/src/cosim/uri.cpp b/src/cosim/uri.cpp index 382b959a..d3f6f0d1 100644 --- a/src/cosim/uri.cpp +++ b/src/cosim/uri.cpp @@ -528,11 +528,9 @@ uri path_to_file_uri(const cosim::filesystem::path& path) cosim::filesystem::path file_uri_to_path(const uri& fileUri) { - COSIM_INPUT_CHECK(fileUri.scheme() && (*fileUri.scheme() == "file")); - COSIM_INPUT_CHECK(fileUri.authority() - && (fileUri.authority()->empty() || *fileUri.authority() == "localhost") - ); - + COSIM_INPUT_CHECK(fileUri.scheme() && *fileUri.scheme() == "file"); + COSIM_INPUT_CHECK(fileUri.authority() && + (fileUri.authority()->empty() || *fileUri.authority() == "localhost")); #ifdef _WIN32 // Windows has some special rules for file URIs; better use the built-in @@ -571,8 +569,8 @@ cosim::filesystem::path file_query_uri_to_path( if (query->find("file=file:///") < query->size()) { return cosim::filesystem::path(std::string(query->substr(13))); } - const auto pathToAppend = cosim::file_uri_to_path(baseUri).parent_path().string(); - return cosim::filesystem::path(pathToAppend + "/" + std::string(query->substr(5))); + const auto pathToAppend = cosim::file_uri_to_path(baseUri).parent_path(); + return pathToAppend / cosim::filesystem::path(std::string(query->substr(5))); } return file_uri_to_path(baseUri).parent_path(); } diff --git a/tests/uri_unittest.cpp b/tests/uri_unittest.cpp index 228ea2f5..01eccc79 100644 --- a/tests/uri_unittest.cpp +++ b/tests/uri_unittest.cpp @@ -1,16 +1,10 @@ #define BOOST_TEST_MODULE uri.hpp unittests - #include #include -#include "cosim/log/logger.hpp" - -//#include -//#include - -//#include - -#include +#include +//#include "cosim/log/logger.hpp" +////#include #include @@ -119,13 +113,13 @@ BOOST_AUTO_TEST_CASE(uri_copy_and_move) // Special case: Short strings which may be affected by the small-string // optimisation (see issue #361) -// auto small = uri("x"); -// const auto smallCopy = small; -// const auto smallMove = std::move(small); -// small = uri(); -// -// BOOST_TEST(smallCopy.path() == "x"); -// BOOST_TEST(smallMove.path() == "x"); + auto small = uri("x"); + const auto smallCopy = small; + const auto smallMove = std::move(small); + small = uri(); + + BOOST_TEST(smallCopy.path() == "x"); + BOOST_TEST(smallMove.path() == "x"); } @@ -252,30 +246,30 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) // const cosim::filesystem::path configPath = cosim::filesystem::path("C://asdfasdf/asdfasasdf/OspSystemStructure.xml"); - const auto testDataDir = std::getenv("TEST_DATA_DIR"); - //BOOST_TEST_REQUIRE(!!testDataDir); - const auto configPath = cosim::filesystem::path(testDataDir) / "msmi" / "OspSystemStructure.xml"; +// const auto testDataDir = std::getenv("TEST_DATA_DIR"); +// //BOOST_TEST_REQUIRE(!!testDataDir); +// const auto configPath = cosim::filesystem::path(testDataDir) / "msmi" / "OspSystemStructure.xml"; - const auto absolutePath = cosim::filesystem::absolute(configPath); - const auto configFile = cosim::filesystem::is_regular_file(absolutePath) - ? absolutePath - //: absolutePath; - : absolutePath / "OspSystemStructure.xml"; - const auto baseURI = path_to_file_uri(configFile); +// const auto absolutePath = cosim::filesystem::absolute(configPath); +// const auto configFile = cosim::filesystem::is_regular_file(absolutePath) +// ? absolutePath +// //: absolutePath; +// : absolutePath / "OspSystemStructure.xml"; + //const auto baseURI = path_to_file_uri(configFile); //const auto baseURI = path_to_file_uri(absolutePath); //configFile.parent_path() - const auto modelPathLocal = cosim::filesystem::path(testDataDir) / "msmi" / "D679C8C9-657E-39E9-8B4E-0799CA3745E4" / "Damper_OspModelDescription.xml"; + //const auto modelPathLocal = cosim::filesystem::path(testDataDir) / "msmi" / "D679C8C9-657E-39E9-8B4E-0799CA3745E4" / "Damper_OspModelDescription.xml"; // const auto modelUriLocal = resolve_reference(baseURI, modelPathLocal); // const auto modelURI = - const auto modelUri = resolve_reference(baseURI, "proxyfmu://10.1.13.178:9090?file=D679C8C9-657E-39E9-8B4E-0799CA3745E4/Damper.fmu"); + // const auto modelUri = resolve_reference(baseURI, "proxyfmu://10.1.13.178:9090?file=D679C8C9-657E-39E9-8B4E-0799CA3745E4/Damper.fmu"); //auto resolver = cosim::default_model_uri_resolver(); // resolver.add_sub_resolver(std::make_shared()); @@ -301,8 +295,8 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) // BOOST_LOG_SEV(log::logger(), log::warning) // << "model query has query: " << (modelUri.query()); - BOOST_LOG_SEV(log::logger(), log::warning) - << "model uri view : " << modelUri.view(); +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "model uri view : " << modelUri.view(); // BOOST_LOG_SEV(log::logger(), log::warning) @@ -328,10 +322,37 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) // str.substr(str.find("file=") + 5) - std::string msmiFileName = "Damper_OspModelDescription.xml"; + const auto baseURI = uri("file:///c:/foo/bar"); + + // const auto fileName + + BOOST_LOG_SEV(log::logger(), log::warning) + << "file uri query: " << file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar/?file=baz.txt") == "c:\\foo\\baz.txt"); + BOOST_LOG_SEV(log::logger(), log::warning) + << "file uri query: " << file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/foo/bar?file=foo/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/foo/bar?file=foo/baz.txt") == "c:\\foo\\foo/baz.txt"); + BOOST_LOG_SEV(log::logger(), log::warning) + << "file uri query: " << file_query_uri_to_path(baseURI, "http://foo/bar?file=baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/bar/?file=baz.txt") == "c:\\foo\\baz.txt"); + BOOST_LOG_SEV(log::logger(), log::warning) + << "file uri query: " << file_query_uri_to_path(baseURI, "http://foo%20bar/foo/bar?file=foo/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/foo/bar?file=foo/baz.txt") == "c:\\foo\\foo/baz.txt"); + + + BOOST_LOG_SEV(log::logger(), log::warning) + << "file uri query: " << file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "c:/baz.txt"); +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "file uri query: " << file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/foo/bar?file=foo/baz.txt"); + + - cosim::filesystem::path msmiFilePath; +// std::string msmiFileName = "Damper_OspModelDescription.xml"; +// +// +// cosim::filesystem::path msmiFilePath; // const auto query = *modelUri.query(); @@ -358,16 +379,16 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) - msmiFilePath = file_query_uri_to_path(baseURI, modelUri).remove_filename() / msmiFileName; + // msmiFilePath = file_query_uri_to_path(baseURI, modelUri).remove_filename() / msmiFileName; // msmiFilePath = configFile.parent_path() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; - BOOST_LOG_SEV(log::logger(), log::warning) - << "proxyfmu uri relative : " << file_query_uri_to_path(baseURI, modelUri); +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "proxyfmu uri relative : " << file_query_uri_to_path(baseURI, modelUri); - BOOST_LOG_SEV(log::logger(), log::warning) - << "msmi file path: " << msmiFilePath; +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "msmi file path: " << msmiFilePath; @@ -380,16 +401,16 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) // cosim::filesystem::path file = cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename(); - BOOST_LOG_SEV(log::logger(), log::warning) - << "model uri file : " << configFile.parent_path() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "model uri file : " << configFile.parent_path() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; - BOOST_LOG_SEV(log::logger(), log::warning) - << "model uri file config : " << configFile; +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "model uri file config : " << configFile; - BOOST_LOG_SEV(log::logger(), log::warning) - << "model uri file config uri: " << path_to_file_uri(configFile.parent_path()); +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "model uri file config uri: " << path_to_file_uri(configFile.parent_path()); // path_to_file_uri @@ -398,17 +419,17 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) // BOOST_LOG_SEV(log::logger(), log::warning) // << "model uri file config file uri to path : " << file_uri_to_path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename(); - BOOST_LOG_SEV(log::logger(), log::warning) - << "model uri file parent : " << configFile.parent_path(); +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "model uri file parent : " << configFile.parent_path(); - BOOST_LOG_SEV(log::logger(), log::warning) - << "model uri file parent substring : " << modelUri.view().substr(modelUri.view().find("file=") + 5); +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "model uri file parent substring : " << modelUri.view().substr(modelUri.view().find("file=") + 5); - BOOST_LOG_SEV(log::logger(), log::warning) - << "model uri file file : " << cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename(); +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "model uri file file : " << cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename(); - BOOST_LOG_SEV(log::logger(), log::warning) - << "model uri file msmi : " << msmiFileName; +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "model uri file msmi : " << msmiFileName; @@ -422,10 +443,6 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) BOOST_TEST(file_uri_to_path("file://localhost/foo%20bar/baz") == "/foo bar/baz"); BOOST_TEST(file_uri_to_path("file://localhost/c:/foo%20bar/baz") == "/c:/foo bar/baz"); #endif - // proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu BOOST_CHECK_THROW(file_uri_to_path("http://foo/bar"), std::invalid_argument); - //BOOST_CHECK_THROW(file_uri_to_path("proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"), std::invalid_argument); - // BOOST_CHECK_THROW(file_uri_to_path("file://foo/bar"), std::invalid_argument);' - - //BOOST_TEST(file_query_uri_to_path("", "proxyfmu:///foo/bar?file=baz") == "\\foo bar\\baz"); + BOOST_CHECK_THROW(file_uri_to_path("file://foo/bar"), std::invalid_argument); } From 3b3472a552b0eddbf7c5e9bd1144bec0ba26678f Mon Sep 17 00:00:00 2001 From: msteinsto Date: Fri, 4 Mar 2022 14:40:00 +0100 Subject: [PATCH 11/20] Final testing implementation with logging --- include/cosim/uri.hpp | 4 +- src/cosim/osp_config_parser.cpp | 153 -------------------- src/cosim/uri.cpp | 8 +- tests/uri_unittest.cpp | 248 ++++---------------------------- 4 files changed, 30 insertions(+), 383 deletions(-) diff --git a/include/cosim/uri.hpp b/include/cosim/uri.hpp index d1d25717..26255a63 100644 --- a/include/cosim/uri.hpp +++ b/include/cosim/uri.hpp @@ -275,13 +275,13 @@ cosim::filesystem::path file_uri_to_path(const uri& fileUri); /** - * Converts a query parameter URI to a local filesystem path. + * Converts a URI with query parameter to a local filesystem path. * * \param [in] baseUri * An (absolute) base URI. * \param [in] queryUri * An URI with arbitrary scheme component. Query file parameter path (if any) - * is specified after `file=`. A prefix of `file:///` specifies absolute path. + * is specified after `file=`. Prefix `file:///` can be used for absolute path. * * \returns * The path that corresponds to `queryUri` parameter or the `baseUri` parent path. diff --git a/src/cosim/osp_config_parser.cpp b/src/cosim/osp_config_parser.cpp index 1cc12412..86feac8e 100644 --- a/src/cosim/osp_config_parser.cpp +++ b/src/cosim/osp_config_parser.cpp @@ -938,13 +938,9 @@ osp_config load_osp_config( const auto modelUri = resolve_reference(baseURI, simulator.source); cosim::filesystem::path msmiFilePath; -// msmiFilePath = modelUri.view().substr(modelUri.view().find("file=") + 5); -// BOOST_LOG_SEV(log::logger(), log::error) << "msmiFilePath: " << msmiFilePath; - msmiFilePath = (modelUri.scheme() == "file") ? file_uri_to_path(modelUri).remove_filename() / msmiFileName : file_query_uri_to_path(baseURI, modelUri).remove_filename() / msmiFileName; - if (cosim::filesystem::exists(msmiFilePath)) { BOOST_LOG_SEV(log::logger(), log::error) << "msmiFilePath function exists: " << msmiFilePath; emds.emplace(simulator.name, msmiFilePath); @@ -955,155 +951,6 @@ osp_config load_osp_config( emds.emplace(simulator.name, msmiFilePath); } } - -// if (modelUri.scheme() == "file") { -// msmiFilePath = file_uri_to_path(modelUri).remove_filename() / msmiFileName; -//// BOOST_LOG_SEV(log::logger(), log::error) << "msmiFilePath: " << msmiFilePath; -//// BOOST_LOG_SEV(log::logger(), log::error) << -//// "msmiFilePath proxy: " << file_uri_to_path("proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu").remove_filename() / msmiFileName; -// if (cosim::filesystem::exists(msmiFilePath)) { -// emds.emplace(simulator.name, msmiFilePath); -// } else { -// msmiFilePath = configFile.parent_path() / msmiFileName; -// if (cosim::filesystem::exists(msmiFilePath)) { -// emds.emplace(simulator.name, msmiFilePath); -// } -// } -// } - - -// else if (modelUri.scheme() == "proxyfmu") { -// // msmiFilePath = configFile.parent_path() / proxyfmu_uri_to_relative_path(modelUri).remove_filename() / msmiFileName; -// msmiFilePath = proxyfmu_uri_to_path(baseURI, modelUri).remove_filename() / msmiFileName; -// -// if (cosim::filesystem::exists(msmiFilePath)) { -// emds.emplace(simulator.name, msmiFilePath); -// } else { -// msmiFilePath = configFile.parent_path() / msmiFileName; -// if (cosim::filesystem::exists(msmiFilePath)) { -// emds.emplace(simulator.name, msmiFilePath); -// } -// } -// } - - -// else if (modelUri.scheme() == "proxyfmu") { -// const auto query = *modelUri.query(); -// if (query.substr(0, 5) == "file=") { -// auto queryPath = cosim::filesystem::path(std::string(query.substr(5))); -// -// msmiFilePath = configFile.parent_path() / queryPath.remove_filename() / msmiFileName; -// -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "msmi file path query: " << msmiFilePath; -// } -// } -// else { -// msmiFilePath = file_query_uri_to_path(baseURI, modelUri).remove_filename() / msmiFileName; -// if (cosim::filesystem::exists(msmiFilePath)) { -// emds.emplace(simulator.name, msmiFilePath); -// } else { -// msmiFilePath = configFile.parent_path() / msmiFileName; -// if (cosim::filesystem::exists(msmiFilePath)) { -// emds.emplace(simulator.name, msmiFilePath); -// } -// } -// -// // msmiFilePath = configFile.parent_path() / proxyfmu_uri_to_relative_path(modelUri).remove_filename() / msmiFileName; -// -// -//// msmiFilePath = configFile.parent_path() / msmiFileName; -//// if (cosim::filesystem::exists(msmiFilePath)) { -//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: " << msmiFilePath; -//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: simulator name: " << simulator.name; -//// emds.emplace(simulator.name, msmiFilePath); -//// } -//// msmiFilePath = configFile.parent_path() / msmiFileName; -//// if (cosim::filesystem::exists(msmiFilePath)) { -//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: " << msmiFilePath; -//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: simulator name: " << simulator.name; -//// emds.emplace(simulator.name, msmiFilePath); -//// } -// // Makes it possible to keep OspModelDescription at configuration path -// // even when there are FMUs with other URI than file. -// // Relative path to the OspModelDescription file can be specified as a file query parameter -// -// -// -//// if (modelUri.scheme().has_value() && modelUri.authority() && modelUri.query()) { -//// const auto query = *modelUri.query(); -//// if (query.substr(0, 5) == "file=") { -//// auto queryFile = cosim::filesystem::path(std::string(query.substr(5))); -//// if (!cosim::filesystem::exists(queryFile)) { -//// msmiFilePath = configFile.parent_path() / queryFile.remove_filename() / msmiFileName; -//// -//// BOOST_LOG_SEV(log::logger(), log::warning) -//// << "msmi file path query: " << msmiFilePath; -//// -//// if (cosim::filesystem::exists(msmiFilePath)) { -//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy relative path query: " << msmiFilePath; -//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy relative path query: simulator name: " << simulator.name; -//// emds.emplace(simulator.name, msmiFilePath); -//// } else { -//// msmiFilePath = configFile.parent_path() / msmiFileName; -//// if (cosim::filesystem::exists(msmiFilePath)) { -//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path no query: " << msmiFilePath; -//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path no query: simulator name: " << simulator.name; -//// emds.emplace(simulator.name, msmiFilePath); -//// } -//// } -//// } else { -//// msmiFilePath = configFile.parent_path() / msmiFileName; -//// if (cosim::filesystem::exists(msmiFilePath)) { -//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: " << msmiFilePath; -//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: simulator name: " << simulator.name; -//// emds.emplace(simulator.name, msmiFilePath); -//// } -//// } -//// } else { -//// msmiFilePath = configFile.parent_path() / msmiFileName; -//// if (cosim::filesystem::exists(msmiFilePath)) { -//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: " << msmiFilePath; -//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: simulator name: " << simulator.name; -//// emds.emplace(simulator.name, msmiFilePath); -//// } -//// } -//// } -// -// -// -//// assert(modelUri.scheme().has_value()); -//// if (*modelUri.scheme() != "proxyfmu") return nullptr; -//// COSIM_INPUT_CHECK(modelUri.authority()); -//// COSIM_INPUT_CHECK(modelUri.query()); -// -// -// -// // Makes it possible to keep OspModelDescription at configuration path -// // even when there are FMUs with other URI than file (fmu-proxy). -// // msmiFilePath = file_uri_to_path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() /msmiFileName; -// -// // msmiFilePath = configFile.parent_path().remove_filename() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; -// //BOOST_LOG_SEV(log::logger(), log::error) << "msmiFilePath: " << msmiFilePath; -// -//// msmiFilePath = configFile.parent_path() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; -//// -//// // proxyfmu://10.1.13.203:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu -//// -//// // msmiFilePath = file_uri_to_path(modelUri).remove_filename() / msmiFileName; -//// if (cosim::filesystem::exists(msmiFilePath)) { -//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy relative path: " << msmiFilePath; -//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy relative path: simulator name: " << simulator.name; -//// emds.emplace(simulator.name, msmiFilePath); -//// } else { -//// msmiFilePath = configFile.parent_path() / msmiFileName; -//// if (cosim::filesystem::exists(msmiFilePath)) { -//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: " << msmiFilePath; -//// BOOST_LOG_SEV(log::logger(), log::error) << "fmuproxy path default: simulator name: " << simulator.name; -//// emds.emplace(simulator.name, msmiFilePath); -//// } -//// } -// } } connect_variables(parser.get_variable_connections(), config.system_structure); diff --git a/src/cosim/uri.cpp b/src/cosim/uri.cpp index d3f6f0d1..e18dbca9 100644 --- a/src/cosim/uri.cpp +++ b/src/cosim/uri.cpp @@ -558,19 +558,19 @@ cosim::filesystem::path file_uri_to_path(const uri& fileUri) #endif } + cosim::filesystem::path file_query_uri_to_path( const uri& baseUri, const uri& queryUri) { COSIM_INPUT_CHECK(queryUri.scheme()); - COSIM_INPUT_CHECK(queryUri.authority()); const auto query = queryUri.query(); if (query && query->find("file=") < query->size()) { if (query->find("file=file:///") < query->size()) { - return cosim::filesystem::path(std::string(query->substr(13))); + return file_uri_to_path("file:///" + std::string(query->substr(13))); } - const auto pathToAppend = cosim::file_uri_to_path(baseUri).parent_path(); - return pathToAppend / cosim::filesystem::path(std::string(query->substr(5))); + const auto pathToAppend = cosim::file_uri_to_path(baseUri).parent_path().string(); + return file_uri_to_path("file:///" + pathToAppend + "/" + std::string(query->substr(5))); } return file_uri_to_path(baseUri).parent_path(); } diff --git a/tests/uri_unittest.cpp b/tests/uri_unittest.cpp index 01eccc79..966e61e1 100644 --- a/tests/uri_unittest.cpp +++ b/tests/uri_unittest.cpp @@ -2,9 +2,6 @@ #include #include -#include -//#include "cosim/log/logger.hpp" -////#include #include @@ -201,7 +198,6 @@ BOOST_AUTO_TEST_CASE(percent_encoding) BOOST_AUTO_TEST_CASE(file_uri_conversions) { - //BOOST_TEST_LOG_LEVEL=message file_uri_conversions // From path to URI BOOST_TEST(path_to_file_uri("/foo bar/baz") == "file:///foo%20bar/baz"); BOOST_TEST(path_to_file_uri(cosim::filesystem::path()) == "file:"); @@ -217,226 +213,6 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) BOOST_TEST(file_uri_to_path("file:///c:/foo%20bar/baz") == "c:\\foo bar\\baz"); BOOST_TEST(file_uri_to_path("file://localhost/foo%20bar/baz") == "\\foo bar\\baz"); BOOST_TEST(file_uri_to_path("file://localhost/c:/foo%20bar/baz") == "c:\\foo bar\\baz"); - //BOOST_WARN("test message"); - BOOST_LOG_SEV(log::logger(), log::warning) - << "testing log "; - - - //const auto modelUri = resolve_reference("proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu", "Damper"); - // cosim::filesystem::path msmiFilePath; - -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "model uri scheme: " << (modelUri.scheme() == "proxyfmu"); -// -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "model uri authority: " << (modelUri.authority() == "10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"); -// -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "model uri query: " << modelUri.query().has_value(); - - -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "file uri to path: " << file_uri_to_path("proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"); - // "msmiFilePath proxy: " << - - // std::string str = "proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"; - - //std::size_t pos = str.find("file="); - - // const cosim::filesystem::path configPath = cosim::filesystem::path("C://asdfasdf/asdfasasdf/OspSystemStructure.xml"); - - -// const auto testDataDir = std::getenv("TEST_DATA_DIR"); -// //BOOST_TEST_REQUIRE(!!testDataDir); -// const auto configPath = cosim::filesystem::path(testDataDir) / "msmi" / "OspSystemStructure.xml"; - - - -// const auto absolutePath = cosim::filesystem::absolute(configPath); -// const auto configFile = cosim::filesystem::is_regular_file(absolutePath) -// ? absolutePath -// //: absolutePath; -// : absolutePath / "OspSystemStructure.xml"; - //const auto baseURI = path_to_file_uri(configFile); - //const auto baseURI = path_to_file_uri(absolutePath); - - //configFile.parent_path() - - - //const auto modelPathLocal = cosim::filesystem::path(testDataDir) / "msmi" / "D679C8C9-657E-39E9-8B4E-0799CA3745E4" / "Damper_OspModelDescription.xml"; - - // const auto modelUriLocal = resolve_reference(baseURI, modelPathLocal); - - // const auto modelURI = - - // const auto modelUri = resolve_reference(baseURI, "proxyfmu://10.1.13.178:9090?file=D679C8C9-657E-39E9-8B4E-0799CA3745E4/Damper.fmu"); - - //auto resolver = cosim::default_model_uri_resolver(); - // resolver.add_sub_resolver(std::make_shared()); - // auto model = resolver->lookup_model(baseURI, "proxyfmu://10.1.13.178:9090?file=D679C8C9-657E-39E9-8B4E-0799CA3745E4/Damper.fmu"); - - -// const auto& mur = modelUriReference; -// const auto query = mur.query(); -// if (query) { -// if (query->find("file=file:///") < query->size()) { -// const auto newQuery = "file=" + std::string(query->substr(13)); -// return model_uri_sub_resolver::lookup_model( -// baseUri, uri(mur.scheme(), mur.authority(), mur.path(), newQuery, mur.fragment())); -// } else if (query->find("file=") < query->size()) { -// const auto pathToAppend = cosim::file_uri_to_path(baseUri).parent_path().string(); -// const auto newQuery = "file=" + pathToAppend + "/" + std::string(query->substr(5)); -// return model_uri_sub_resolver::lookup_model( -// baseUri, uri(mur.scheme(), mur.authority(), mur.path(), newQuery, mur.fragment())); -// } -// } -// return model_uri_sub_resolver::lookup_model(baseUri, mur); - -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "model query has query: " << (modelUri.query()); - -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "model uri view : " << modelUri.view(); - - -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "model query file: " << (modelUri.query()->find("file=") -> modelUri.query()->size()); - - - //const auto modelUri = resolve_reference(baseURI, "proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu"); - - - - - - // cosim::filesystem::path filePath = cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)); - - // const auto testDataDir = std::getenv("TEST_DATA_DIR"); - - -// const auto absolutePath = cosim::filesystem::absolute(configPath); -// const auto configFile = cosim::filesystem::is_regular_file(absolutePath) -// ? absolutePath -// : absolutePath / "OspSystemStructure.xml"; -// const auto baseURI = path_to_file_uri(configFile); - - // str.substr(str.find("file=") + 5) - - const auto baseURI = uri("file:///c:/foo/bar"); - - // const auto fileName - - BOOST_LOG_SEV(log::logger(), log::warning) - << "file uri query: " << file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar/?file=baz.txt") == "c:\\foo\\baz.txt"); - BOOST_LOG_SEV(log::logger(), log::warning) - << "file uri query: " << file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/foo/bar?file=foo/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/foo/bar?file=foo/baz.txt") == "c:\\foo\\foo/baz.txt"); - BOOST_LOG_SEV(log::logger(), log::warning) - << "file uri query: " << file_query_uri_to_path(baseURI, "http://foo/bar?file=baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/bar/?file=baz.txt") == "c:\\foo\\baz.txt"); - BOOST_LOG_SEV(log::logger(), log::warning) - << "file uri query: " << file_query_uri_to_path(baseURI, "http://foo%20bar/foo/bar?file=foo/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/foo/bar?file=foo/baz.txt") == "c:\\foo\\foo/baz.txt"); - - - BOOST_LOG_SEV(log::logger(), log::warning) - << "file uri query: " << file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "c:/baz.txt"); -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "file uri query: " << file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/foo/bar?file=foo/baz.txt"); - - - - -// std::string msmiFileName = "Damper_OspModelDescription.xml"; -// -// -// cosim::filesystem::path msmiFilePath; - - -// const auto query = *modelUri.query(); -// if (query.substr(0, 5) == "file=") { -// auto queryPath = cosim::filesystem::path(std::string(query.substr(5))); -// msmiFilePath = configFile.parent_path() / queryPath.remove_filename() / msmiFileName; -// -// -// -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "msmi file path query: " << msmiFilePath; -// -//// if (!cosim::filesystem::exists(file)) { -//// BOOST_LOG_SEV(log::logger(), log::warning) -//// << "no query file : " << file.string(); -//// } else { -//// BOOST_LOG_SEV(log::logger(), log::warning) -//// << "query file found: " << file.string(); -//// } -// } else { -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "no file in query: "; -// } - - - - // msmiFilePath = file_query_uri_to_path(baseURI, modelUri).remove_filename() / msmiFileName; - - // msmiFilePath = configFile.parent_path() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; - - -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "proxyfmu uri relative : " << file_query_uri_to_path(baseURI, modelUri); - -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "msmi file path: " << msmiFilePath; - - - - - //const auto testDataDir = std::getenv("TEST_DATA_DIR"); - // cosim::filesystem::path(testDataDir) - -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "model uri view local : " << file_uri_to_path(modelUri).remove_filename() / msmiFileName; - - // cosim::filesystem::path file = cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename(); - -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "model uri file : " << configFile.parent_path() / cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename() / msmiFileName; - -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "model uri file config : " << configFile; - - - -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "model uri file config uri: " << path_to_file_uri(configFile.parent_path()); - - // path_to_file_uri - - - -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "model uri file config file uri to path : " << file_uri_to_path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename(); - -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "model uri file parent : " << configFile.parent_path(); - -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "model uri file parent substring : " << modelUri.view().substr(modelUri.view().find("file=") + 5); - -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "model uri file file : " << cosim::filesystem::path(modelUri.view().substr(modelUri.view().find("file=") + 5)).remove_filename(); - -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "model uri file msmi : " << msmiFileName; - - - - - // BOOST_TEST(file_uri_to_path("proxyfmu://10.1.13.178:9090?file=88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu") == "c:\\foo bar\\baz"); - //BOOST_TEST(file_uri_to_path("proxyfmu://localhost/88EAF9B4-BAAB-449C-97A1-FEE85CDFE38C/Damper.fmu") == "c:\\foo bar\\baz"); - #else BOOST_TEST(file_uri_to_path("file:///foo%20bar/baz") == "/foo bar/baz"); BOOST_TEST(file_uri_to_path("file:///c:/foo%20bar/baz") == "/c:/foo bar/baz"); @@ -446,3 +222,27 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) BOOST_CHECK_THROW(file_uri_to_path("http://foo/bar"), std::invalid_argument); BOOST_CHECK_THROW(file_uri_to_path("file://foo/bar"), std::invalid_argument); } + +BOOST_AUTO_TEST_CASE(file_query_uri_conversions) +{ + // From URI file query to path + const auto baseURI = uri("file:///c:/foo/bar"); +#ifdef _WIN32 + BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "c:\\foo\\baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar/foo?file=bar/baz.txt") == "c:\\foo\\bar\\baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/bar?file=baz.txt") == "c:\\foo\\baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/foo/bar?file=bar%20foo/baz.txt") == "c:\\foo\\bar foo\\baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "c:\\baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "c:\\foo\\bar\\baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?foo=baz.txt") == "c:\\foo"); +#else + BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar/foo?file=bar/baz.txt") == "/c:/foo/bar/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/foo/bar?file=bar%20foo/baz.txt") == "/c:/foo/bar foo/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "/c:/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "/c:/foo/bar/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?foo=baz.txt") == "/c:/foo"); +#endif + BOOST_CHECK_THROW(file_query_uri_to_path(baseURI, "foo/bar/baz.txt"), std::invalid_argument); +} From ebd8ace5ad70023fd9650178a2646fd4b0e4961f Mon Sep 17 00:00:00 2001 From: msteinsto Date: Fri, 4 Mar 2022 15:17:41 +0100 Subject: [PATCH 12/20] Temporary removal of Linux file query uri tests --- tests/uri_unittest.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/uri_unittest.cpp b/tests/uri_unittest.cpp index 966e61e1..5965a1c1 100644 --- a/tests/uri_unittest.cpp +++ b/tests/uri_unittest.cpp @@ -235,7 +235,8 @@ BOOST_AUTO_TEST_CASE(file_query_uri_conversions) BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "c:\\baz.txt"); BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "c:\\foo\\bar\\baz.txt"); BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?foo=baz.txt") == "c:\\foo"); -#else + + BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar/foo?file=bar/baz.txt") == "/c:/foo/bar/baz.txt"); BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); @@ -243,6 +244,15 @@ BOOST_AUTO_TEST_CASE(file_query_uri_conversions) BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "/c:/baz.txt"); BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "/c:/foo/bar/baz.txt"); BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?foo=baz.txt") == "/c:/foo"); + +//#else +// BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); +// BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar/foo?file=bar/baz.txt") == "/c:/foo/bar/baz.txt"); +// BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); +// BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/foo/bar?file=bar%20foo/baz.txt") == "/c:/foo/bar foo/baz.txt"); +// BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "/c:/baz.txt"); +// BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "/c:/foo/bar/baz.txt"); +// BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?foo=baz.txt") == "/c:/foo"); #endif BOOST_CHECK_THROW(file_query_uri_to_path(baseURI, "foo/bar/baz.txt"), std::invalid_argument); } From 67312ccc26a52b0a39dd30840799d8abc9ff7584 Mon Sep 17 00:00:00 2001 From: msteinsto Date: Fri, 4 Mar 2022 15:38:49 +0100 Subject: [PATCH 13/20] Edited invalid tests --- tests/uri_unittest.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/uri_unittest.cpp b/tests/uri_unittest.cpp index 5965a1c1..c1d2de68 100644 --- a/tests/uri_unittest.cpp +++ b/tests/uri_unittest.cpp @@ -237,13 +237,13 @@ BOOST_AUTO_TEST_CASE(file_query_uri_conversions) BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?foo=baz.txt") == "c:\\foo"); - BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar/foo?file=bar/baz.txt") == "/c:/foo/bar/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/foo/bar?file=bar%20foo/baz.txt") == "/c:/foo/bar foo/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "/c:/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "/c:/foo/bar/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?foo=baz.txt") == "/c:/foo"); +// BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); +// BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar/foo?file=bar/baz.txt") == "/c:/foo/bar/baz.txt"); +// BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); +// BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/foo/bar?file=bar%20foo/baz.txt") == "/c:/foo/bar foo/baz.txt"); +// BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "/c:/baz.txt"); +// BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "/c:/foo/bar/baz.txt"); +// BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?foo=baz.txt") == "/c:/foo"); //#else // BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); From 3fb00eb152b6c4932e1b2402030f02bf5aaa013e Mon Sep 17 00:00:00 2001 From: msteinsto Date: Mon, 7 Mar 2022 08:36:45 +0100 Subject: [PATCH 14/20] Reintroduced non Windows tests --- tests/uri_unittest.cpp | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/tests/uri_unittest.cpp b/tests/uri_unittest.cpp index c1d2de68..966e61e1 100644 --- a/tests/uri_unittest.cpp +++ b/tests/uri_unittest.cpp @@ -235,24 +235,14 @@ BOOST_AUTO_TEST_CASE(file_query_uri_conversions) BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "c:\\baz.txt"); BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "c:\\foo\\bar\\baz.txt"); BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?foo=baz.txt") == "c:\\foo"); - - -// BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); -// BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar/foo?file=bar/baz.txt") == "/c:/foo/bar/baz.txt"); -// BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); -// BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/foo/bar?file=bar%20foo/baz.txt") == "/c:/foo/bar foo/baz.txt"); -// BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "/c:/baz.txt"); -// BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "/c:/foo/bar/baz.txt"); -// BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?foo=baz.txt") == "/c:/foo"); - -//#else -// BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); -// BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar/foo?file=bar/baz.txt") == "/c:/foo/bar/baz.txt"); -// BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); -// BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/foo/bar?file=bar%20foo/baz.txt") == "/c:/foo/bar foo/baz.txt"); -// BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "/c:/baz.txt"); -// BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "/c:/foo/bar/baz.txt"); -// BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?foo=baz.txt") == "/c:/foo"); +#else + BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar/foo?file=bar/baz.txt") == "/c:/foo/bar/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/foo/bar?file=bar%20foo/baz.txt") == "/c:/foo/bar foo/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "/c:/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "/c:/foo/bar/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?foo=baz.txt") == "/c:/foo"); #endif BOOST_CHECK_THROW(file_query_uri_to_path(baseURI, "foo/bar/baz.txt"), std::invalid_argument); } From 53f4f52df1a583716adacce672d84d66f42c20cc Mon Sep 17 00:00:00 2001 From: msteinsto Date: Mon, 7 Mar 2022 08:46:28 +0100 Subject: [PATCH 15/20] Non Windows tests corrections --- tests/uri_unittest.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/uri_unittest.cpp b/tests/uri_unittest.cpp index 966e61e1..7e017c6f 100644 --- a/tests/uri_unittest.cpp +++ b/tests/uri_unittest.cpp @@ -236,13 +236,13 @@ BOOST_AUTO_TEST_CASE(file_query_uri_conversions) BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "c:\\foo\\bar\\baz.txt"); BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?foo=baz.txt") == "c:\\foo"); #else - BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar/foo?file=bar/baz.txt") == "/c:/foo/bar/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/foo/bar?file=bar%20foo/baz.txt") == "/c:/foo/bar foo/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "/c:/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "/c:/foo/bar/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?foo=baz.txt") == "/c:/foo"); + BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "//c:/foo/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar/foo?file=bar/baz.txt") == "//c:/foo/bar/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/bar?file=baz.txt") == "//c:/foo/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/foo/bar?file=bar%20foo/baz.txt") == "//c:/foo/bar foo/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "//c:/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "//c:/foo/bar/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?foo=baz.txt") == "//c:/foo"); #endif BOOST_CHECK_THROW(file_query_uri_to_path(baseURI, "foo/bar/baz.txt"), std::invalid_argument); } From f1937d8985231b4d1fbc60e792add9588f84562a Mon Sep 17 00:00:00 2001 From: msteinsto Date: Mon, 7 Mar 2022 14:24:07 +0100 Subject: [PATCH 16/20] UNIX filesystem compatible function rewrite --- src/cosim/uri.cpp | 65 ++++++++++++++++++++++++++++++++++++++---- tests/uri_unittest.cpp | 58 ++++++++++++++++++++++++++++++++----- 2 files changed, 111 insertions(+), 12 deletions(-) diff --git a/src/cosim/uri.cpp b/src/cosim/uri.cpp index e18dbca9..591d0695 100644 --- a/src/cosim/uri.cpp +++ b/src/cosim/uri.cpp @@ -559,18 +559,73 @@ cosim::filesystem::path file_uri_to_path(const uri& fileUri) } +//cosim::filesystem::path file_query_uri_to_path( +// const uri& baseUri, +// const uri& queryUri) +//{ +// COSIM_INPUT_CHECK(queryUri.scheme()); +// const auto query = queryUri.query(); +// if (query && query->find("file=") < query->size()) { +// if (query->find("file=file:///") < query->size()) { +// return file_uri_to_path("file:///" + std::string(query->substr(13))); +// } +// const auto pathToAppend = cosim::file_uri_to_path(baseUri).parent_path().string(); +// return file_uri_to_path("file:///" + pathToAppend + "/" + std::string(query->substr(5))); +// } +// return file_uri_to_path(baseUri).parent_path(); +//} + cosim::filesystem::path file_query_uri_to_path( - const uri& baseUri, - const uri& queryUri) + const cosim::uri& baseUri, + const cosim::uri& queryUri) { COSIM_INPUT_CHECK(queryUri.scheme()); const auto query = queryUri.query(); if (query && query->find("file=") < query->size()) { if (query->find("file=file:///") < query->size()) { - return file_uri_to_path("file:///" + std::string(query->substr(13))); + //return file_uri_to_path("file:///" + std::string(query->substr(13))); + return file_uri_to_path(std::string(query->substr(5))); } - const auto pathToAppend = cosim::file_uri_to_path(baseUri).parent_path().string(); - return file_uri_to_path("file:///" + pathToAppend + "/" + std::string(query->substr(5))); + // const auto pathToAppend = cosim::file_uri_to_path(baseUri).parent_path().string(); + const auto pathToAppend = cosim::path_to_file_uri(cosim::file_uri_to_path(baseUri).parent_path()); + + // const auto parentPath = cosim::file_uri_to_path(baseUri).parent_path(); + //BOOST_LOG_SEV(log::logger(), log::error) << "pathToAppend: " << pathToAppend; + // uri(baseUri.scheme(), baseUri.authority(), cosim::file_uri_to_path(baseUri).parent_path(), "", baseUri.fragment()); + // BOOST_LOG_SEV(log::logger(), log::error) << "query file uri: " << uri(baseUri.scheme(), baseUri.authority(), cosim::file_uri_to_path(baseUri).parent_path() / cosim::filesystem::path(std::string(query->substr(5))), "", baseUri.fragment()); + + // const auto parentUri = file_uri_to_path(pathToAppend); + + // return file_uri_to_path(); + + // const auto uriToAppend = path_to_file_uri(cosim::file_uri_to_path(baseUri).parent_path()); + + + + // return file_uri_to_path(uriToAppend); + + //return cosim::file_uri_to_path(baseUri).parent_path() / cosim::filesystem::path(std::string(query->substr(5))) + // ; + + //return file_uri_to_path("file:///" + pathToAppend + "/" + std::string(query->substr(5))); + return file_uri_to_path(std::string(pathToAppend.view()) + "/" + std::string(query->substr(5))); + + //return file_uri_to_path(cosim::uri("file", std::nullopt, cosim::file_uri_to_path(baseUri).parent_path().string() + "/" + std::string(query->substr(5)))); + + //return cosim::file_uri_to_path(baseUri).parent_path() / cosim::file_uri_to_path("file:///" + std::string(query->substr(5))); + +// return file_uri_to_path(uri( +// //baseUri.scheme(), +// //std::nullopt, +// //baseUri.authority(), +// //baseUri.path(), +// "file", +// std::nullopt, +// cosim::file_uri_to_path(baseUri).parent_path().string() + "/" + std::string(query->substr(5)) +// //, +// //std::string_view(cosim::file_uri_to_path(baseUri).parent_path()) / std::filesystem::path(std::string(query->substr(5))), +// //std::nullopt, std::nullopt +// )); } return file_uri_to_path(baseUri).parent_path(); } diff --git a/tests/uri_unittest.cpp b/tests/uri_unittest.cpp index 7e017c6f..2c02bce9 100644 --- a/tests/uri_unittest.cpp +++ b/tests/uri_unittest.cpp @@ -2,6 +2,7 @@ #include #include +#include "cosim/log/logger.hpp" #include @@ -228,6 +229,48 @@ BOOST_AUTO_TEST_CASE(file_query_uri_conversions) // From URI file query to path const auto baseURI = uri("file:///c:/foo/bar"); #ifdef _WIN32 + +// const auto queryUri = uri("proxyfmu://foo%20bar/bar?file=baz.txt"); +// const auto query = queryUri.query(); + +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "model uri scheme: " << baseURI.scheme().value(); +// +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "model uri authority: " << baseURI.authority().value(); + +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "model uri view: " << uri( +// //baseUri.scheme(), +// //std::nullopt, +// //baseUri.authority(), +// //baseUri.path(), +// "file", +// std::nullopt, +// cosim::file_uri_to_path(baseURI).parent_path().string() + "/" + std::string(query->substr(5))); + + +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "sub path: " << cosim::file_uri_to_path(uri("file", "", std::string(query->substr(5)))); +// +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "new path: " << cosim::file_uri_to_path(baseURI).parent_path() / cosim::file_uri_to_path("file:///" + std::string(query->substr(5))); + BOOST_LOG_SEV(log::logger(), log::warning) + << "file uri"; + + BOOST_LOG_SEV(log::logger(), log::warning) + << "file uri view: " << baseURI.view(); + + const std::string emptyStr; + +// BOOST_LOG_SEV(log::logger(), log::warning) +// << "file uri path: " << file_uri_to_path(uri(baseURI.scheme(), std::nullopt, "c:/foo/bar")); + + BOOST_LOG_SEV(log::logger(), log::warning) + << "file uri path path: " << cosim::path_to_file_uri(cosim::file_uri_to_path(baseURI).parent_path()); + + // file_uri_to_path(uri(std::nullopt, std::nullopt, "c:/foo/bar")) + BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "c:\\foo\\baz.txt"); BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar/foo?file=bar/baz.txt") == "c:\\foo\\bar\\baz.txt"); BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/bar?file=baz.txt") == "c:\\foo\\baz.txt"); @@ -236,13 +279,14 @@ BOOST_AUTO_TEST_CASE(file_query_uri_conversions) BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "c:\\foo\\bar\\baz.txt"); BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?foo=baz.txt") == "c:\\foo"); #else - BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "//c:/foo/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar/foo?file=bar/baz.txt") == "//c:/foo/bar/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/bar?file=baz.txt") == "//c:/foo/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/foo/bar?file=bar%20foo/baz.txt") == "//c:/foo/bar foo/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "//c:/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "//c:/foo/bar/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?foo=baz.txt") == "//c:/foo"); + BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar/foo?file=bar/baz.txt") == "/c:/foo/bar/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/foo/bar?file=bar%20foo/baz.txt") == "/c:/foo/bar foo/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "/c:/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "/c:/foo/bar/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?foo=baz.txt") == "/c:/foo"); #endif BOOST_CHECK_THROW(file_query_uri_to_path(baseURI, "foo/bar/baz.txt"), std::invalid_argument); + //BOOST_CHECK_THROW(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar?file="), std::invalid_argument); } From b9aba4a71826f9f345b70fe1bcb9cd89354fb67d Mon Sep 17 00:00:00 2001 From: msteinsto Date: Tue, 8 Mar 2022 11:31:51 +0100 Subject: [PATCH 17/20] Removed scheme assertion --- include/cosim/uri.hpp | 3 +- src/cosim/osp_config_parser.cpp | 2 -- src/cosim/uri.cpp | 60 ++------------------------------- tests/uri_unittest.cpp | 46 +------------------------ 4 files changed, 5 insertions(+), 106 deletions(-) diff --git a/include/cosim/uri.hpp b/include/cosim/uri.hpp index 26255a63..b9f391c0 100644 --- a/include/cosim/uri.hpp +++ b/include/cosim/uri.hpp @@ -284,7 +284,8 @@ cosim::filesystem::path file_uri_to_path(const uri& fileUri); * is specified after `file=`. Prefix `file:///` can be used for absolute path. * * \returns - * The path that corresponds to `queryUri` parameter or the `baseUri` parent path. + * The local absolute path that corresponds to the `queryUri`, or the `baseUri` + * parent path if no file query is available. */ cosim::filesystem::path file_query_uri_to_path(const uri& baseUri, const uri& queryUri); diff --git a/src/cosim/osp_config_parser.cpp b/src/cosim/osp_config_parser.cpp index 86feac8e..8d0c9942 100644 --- a/src/cosim/osp_config_parser.cpp +++ b/src/cosim/osp_config_parser.cpp @@ -942,12 +942,10 @@ osp_config load_osp_config( ? file_uri_to_path(modelUri).remove_filename() / msmiFileName : file_query_uri_to_path(baseURI, modelUri).remove_filename() / msmiFileName; if (cosim::filesystem::exists(msmiFilePath)) { - BOOST_LOG_SEV(log::logger(), log::error) << "msmiFilePath function exists: " << msmiFilePath; emds.emplace(simulator.name, msmiFilePath); } else { msmiFilePath = configFile.parent_path() / msmiFileName; if (cosim::filesystem::exists(msmiFilePath)) { - BOOST_LOG_SEV(log::logger(), log::error) << "msmiFilePath conf exists: " << msmiFilePath; emds.emplace(simulator.name, msmiFilePath); } } diff --git a/src/cosim/uri.cpp b/src/cosim/uri.cpp index 591d0695..657f92b1 100644 --- a/src/cosim/uri.cpp +++ b/src/cosim/uri.cpp @@ -559,73 +559,17 @@ cosim::filesystem::path file_uri_to_path(const uri& fileUri) } -//cosim::filesystem::path file_query_uri_to_path( -// const uri& baseUri, -// const uri& queryUri) -//{ -// COSIM_INPUT_CHECK(queryUri.scheme()); -// const auto query = queryUri.query(); -// if (query && query->find("file=") < query->size()) { -// if (query->find("file=file:///") < query->size()) { -// return file_uri_to_path("file:///" + std::string(query->substr(13))); -// } -// const auto pathToAppend = cosim::file_uri_to_path(baseUri).parent_path().string(); -// return file_uri_to_path("file:///" + pathToAppend + "/" + std::string(query->substr(5))); -// } -// return file_uri_to_path(baseUri).parent_path(); -//} - cosim::filesystem::path file_query_uri_to_path( const cosim::uri& baseUri, const cosim::uri& queryUri) { - COSIM_INPUT_CHECK(queryUri.scheme()); const auto query = queryUri.query(); if (query && query->find("file=") < query->size()) { if (query->find("file=file:///") < query->size()) { - //return file_uri_to_path("file:///" + std::string(query->substr(13))); return file_uri_to_path(std::string(query->substr(5))); } - // const auto pathToAppend = cosim::file_uri_to_path(baseUri).parent_path().string(); - const auto pathToAppend = cosim::path_to_file_uri(cosim::file_uri_to_path(baseUri).parent_path()); - - // const auto parentPath = cosim::file_uri_to_path(baseUri).parent_path(); - //BOOST_LOG_SEV(log::logger(), log::error) << "pathToAppend: " << pathToAppend; - // uri(baseUri.scheme(), baseUri.authority(), cosim::file_uri_to_path(baseUri).parent_path(), "", baseUri.fragment()); - // BOOST_LOG_SEV(log::logger(), log::error) << "query file uri: " << uri(baseUri.scheme(), baseUri.authority(), cosim::file_uri_to_path(baseUri).parent_path() / cosim::filesystem::path(std::string(query->substr(5))), "", baseUri.fragment()); - - // const auto parentUri = file_uri_to_path(pathToAppend); - - // return file_uri_to_path(); - - // const auto uriToAppend = path_to_file_uri(cosim::file_uri_to_path(baseUri).parent_path()); - - - - // return file_uri_to_path(uriToAppend); - - //return cosim::file_uri_to_path(baseUri).parent_path() / cosim::filesystem::path(std::string(query->substr(5))) - // ; - - //return file_uri_to_path("file:///" + pathToAppend + "/" + std::string(query->substr(5))); - return file_uri_to_path(std::string(pathToAppend.view()) + "/" + std::string(query->substr(5))); - - //return file_uri_to_path(cosim::uri("file", std::nullopt, cosim::file_uri_to_path(baseUri).parent_path().string() + "/" + std::string(query->substr(5)))); - - //return cosim::file_uri_to_path(baseUri).parent_path() / cosim::file_uri_to_path("file:///" + std::string(query->substr(5))); - -// return file_uri_to_path(uri( -// //baseUri.scheme(), -// //std::nullopt, -// //baseUri.authority(), -// //baseUri.path(), -// "file", -// std::nullopt, -// cosim::file_uri_to_path(baseUri).parent_path().string() + "/" + std::string(query->substr(5)) -// //, -// //std::string_view(cosim::file_uri_to_path(baseUri).parent_path()) / std::filesystem::path(std::string(query->substr(5))), -// //std::nullopt, std::nullopt -// )); + const auto uriToAppend = cosim::path_to_file_uri(cosim::file_uri_to_path(baseUri).parent_path()); + return file_uri_to_path(std::string(uriToAppend.view()) + "/" + std::string(query->substr(5))); } return file_uri_to_path(baseUri).parent_path(); } diff --git a/tests/uri_unittest.cpp b/tests/uri_unittest.cpp index 2c02bce9..8a4a3e36 100644 --- a/tests/uri_unittest.cpp +++ b/tests/uri_unittest.cpp @@ -2,7 +2,6 @@ #include #include -#include "cosim/log/logger.hpp" #include @@ -224,53 +223,12 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) BOOST_CHECK_THROW(file_uri_to_path("file://foo/bar"), std::invalid_argument); } + BOOST_AUTO_TEST_CASE(file_query_uri_conversions) { // From URI file query to path const auto baseURI = uri("file:///c:/foo/bar"); #ifdef _WIN32 - -// const auto queryUri = uri("proxyfmu://foo%20bar/bar?file=baz.txt"); -// const auto query = queryUri.query(); - -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "model uri scheme: " << baseURI.scheme().value(); -// -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "model uri authority: " << baseURI.authority().value(); - -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "model uri view: " << uri( -// //baseUri.scheme(), -// //std::nullopt, -// //baseUri.authority(), -// //baseUri.path(), -// "file", -// std::nullopt, -// cosim::file_uri_to_path(baseURI).parent_path().string() + "/" + std::string(query->substr(5))); - - -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "sub path: " << cosim::file_uri_to_path(uri("file", "", std::string(query->substr(5)))); -// -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "new path: " << cosim::file_uri_to_path(baseURI).parent_path() / cosim::file_uri_to_path("file:///" + std::string(query->substr(5))); - BOOST_LOG_SEV(log::logger(), log::warning) - << "file uri"; - - BOOST_LOG_SEV(log::logger(), log::warning) - << "file uri view: " << baseURI.view(); - - const std::string emptyStr; - -// BOOST_LOG_SEV(log::logger(), log::warning) -// << "file uri path: " << file_uri_to_path(uri(baseURI.scheme(), std::nullopt, "c:/foo/bar")); - - BOOST_LOG_SEV(log::logger(), log::warning) - << "file uri path path: " << cosim::path_to_file_uri(cosim::file_uri_to_path(baseURI).parent_path()); - - // file_uri_to_path(uri(std::nullopt, std::nullopt, "c:/foo/bar")) - BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "c:\\foo\\baz.txt"); BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar/foo?file=bar/baz.txt") == "c:\\foo\\bar\\baz.txt"); BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/bar?file=baz.txt") == "c:\\foo\\baz.txt"); @@ -287,6 +245,4 @@ BOOST_AUTO_TEST_CASE(file_query_uri_conversions) BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "/c:/foo/bar/baz.txt"); BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?foo=baz.txt") == "/c:/foo"); #endif - BOOST_CHECK_THROW(file_query_uri_to_path(baseURI, "foo/bar/baz.txt"), std::invalid_argument); - //BOOST_CHECK_THROW(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar?file="), std::invalid_argument); } From 42aecf7af02527af4491e3a6a48a14fff61f0c3a Mon Sep 17 00:00:00 2001 From: msteinsto Date: Mon, 21 Mar 2022 12:56:16 +0100 Subject: [PATCH 18/20] Changed input parameter from baseUri to baseParentUri --- include/cosim/uri.hpp | 8 ++++---- src/cosim/osp_config_parser.cpp | 2 +- src/cosim/uri.cpp | 7 +++---- tests/uri_unittest.cpp | 30 +++++++++++++++--------------- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/include/cosim/uri.hpp b/include/cosim/uri.hpp index b9f391c0..d201d23e 100644 --- a/include/cosim/uri.hpp +++ b/include/cosim/uri.hpp @@ -277,17 +277,17 @@ cosim::filesystem::path file_uri_to_path(const uri& fileUri); /** * Converts a URI with query parameter to a local filesystem path. * - * \param [in] baseUri - * An (absolute) base URI. + * \param [in] baseParentUri + * An (absolute) base parent URI. * \param [in] queryUri * An URI with arbitrary scheme component. Query file parameter path (if any) * is specified after `file=`. Prefix `file:///` can be used for absolute path. * * \returns - * The local absolute path that corresponds to the `queryUri`, or the `baseUri` + * The local absolute path that corresponds to the `queryUri`, or the `baseParentUri` * parent path if no file query is available. */ -cosim::filesystem::path file_query_uri_to_path(const uri& baseUri, const uri& queryUri); +cosim::filesystem::path file_query_uri_to_path(const uri& baseParentUri, const uri& queryUri); } // namespace cosim diff --git a/src/cosim/osp_config_parser.cpp b/src/cosim/osp_config_parser.cpp index 8d0c9942..9331f5a8 100644 --- a/src/cosim/osp_config_parser.cpp +++ b/src/cosim/osp_config_parser.cpp @@ -940,7 +940,7 @@ osp_config load_osp_config( msmiFilePath = (modelUri.scheme() == "file") ? file_uri_to_path(modelUri).remove_filename() / msmiFileName - : file_query_uri_to_path(baseURI, modelUri).remove_filename() / msmiFileName; + : file_query_uri_to_path(cosim::path_to_file_uri(cosim::file_uri_to_path(baseURI).parent_path()), modelUri).remove_filename() / msmiFileName; if (cosim::filesystem::exists(msmiFilePath)) { emds.emplace(simulator.name, msmiFilePath); } else { diff --git a/src/cosim/uri.cpp b/src/cosim/uri.cpp index 657f92b1..84f3294f 100644 --- a/src/cosim/uri.cpp +++ b/src/cosim/uri.cpp @@ -560,7 +560,7 @@ cosim::filesystem::path file_uri_to_path(const uri& fileUri) cosim::filesystem::path file_query_uri_to_path( - const cosim::uri& baseUri, + const cosim::uri& baseParentUri, const cosim::uri& queryUri) { const auto query = queryUri.query(); @@ -568,10 +568,9 @@ cosim::filesystem::path file_query_uri_to_path( if (query->find("file=file:///") < query->size()) { return file_uri_to_path(std::string(query->substr(5))); } - const auto uriToAppend = cosim::path_to_file_uri(cosim::file_uri_to_path(baseUri).parent_path()); - return file_uri_to_path(std::string(uriToAppend.view()) + "/" + std::string(query->substr(5))); + return file_uri_to_path(std::string(baseParentUri.view()) + "/" + std::string(query->substr(5))); } - return file_uri_to_path(baseUri).parent_path(); + return file_uri_to_path(baseParentUri); } diff --git a/tests/uri_unittest.cpp b/tests/uri_unittest.cpp index 8a4a3e36..03b6fd4c 100644 --- a/tests/uri_unittest.cpp +++ b/tests/uri_unittest.cpp @@ -227,22 +227,22 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) BOOST_AUTO_TEST_CASE(file_query_uri_conversions) { // From URI file query to path - const auto baseURI = uri("file:///c:/foo/bar"); + const auto baseParentURI = uri("file:///c:/foo"); #ifdef _WIN32 - BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "c:\\foo\\baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar/foo?file=bar/baz.txt") == "c:\\foo\\bar\\baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/bar?file=baz.txt") == "c:\\foo\\baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/foo/bar?file=bar%20foo/baz.txt") == "c:\\foo\\bar foo\\baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "c:\\baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "c:\\foo\\bar\\baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?foo=baz.txt") == "c:\\foo"); + BOOST_TEST(file_query_uri_to_path(baseParentURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "c:\\foo\\baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseParentURI, "proxyfmu://foo%20bar/bar/foo?file=bar/baz.txt") == "c:\\foo\\bar\\baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseParentURI, "http://foo%20bar/bar?file=baz.txt") == "c:\\foo\\baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseParentURI, "http://foo%20bar/foo/bar?file=bar%20foo/baz.txt") == "c:\\foo\\bar foo\\baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseParentURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "c:\\baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseParentURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "c:\\foo\\bar\\baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseParentURI, "http://foo%20baz/bar?foo=baz.txt") == "c:\\foo"); #else - BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo%20bar/bar/foo?file=bar/baz.txt") == "/c:/foo/bar/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20bar/foo/bar?file=bar%20foo/baz.txt") == "/c:/foo/bar foo/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "/c:/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "/c:/foo/bar/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseURI, "http://foo%20baz/bar?foo=baz.txt") == "/c:/foo"); + BOOST_TEST(file_query_uri_to_path(baseParentURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseParentURI, "proxyfmu://foo%20bar/bar/foo?file=bar/baz.txt") == "/c:/foo/bar/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseParentURI, "http://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseParentURI, "http://foo%20bar/foo/bar?file=bar%20foo/baz.txt") == "/c:/foo/bar foo/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseParentURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "/c:/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseParentURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "/c:/foo/bar/baz.txt"); + BOOST_TEST(file_query_uri_to_path(baseParentURI, "http://foo%20baz/bar?foo=baz.txt") == "/c:/foo"); #endif } From 6213f43f3fc6e4661be130e455b0ba6afdfee455 Mon Sep 17 00:00:00 2001 From: msteinsto Date: Wed, 23 Mar 2022 14:42:22 +0100 Subject: [PATCH 19/20] Moved file_query_uri_to_path function from uri to osp_config_parser --- include/cosim/uri.hpp | 18 +----- src/cosim/osp_config_parser.cpp | 14 +++++ src/cosim/uri.cpp | 15 ----- tests/CMakeLists.txt | 6 ++ .../data/msmi/OspSystemStructure_proxyfmu.xml | 45 ++++++++++++++ tests/proxyfmu_osp_config_parser_test.cpp | 58 +++++++++++++++++++ tests/uri_unittest.cpp | 24 -------- 7 files changed, 124 insertions(+), 56 deletions(-) create mode 100644 tests/data/msmi/OspSystemStructure_proxyfmu.xml create mode 100644 tests/proxyfmu_osp_config_parser_test.cpp diff --git a/include/cosim/uri.hpp b/include/cosim/uri.hpp index d201d23e..f8bf727d 100644 --- a/include/cosim/uri.hpp +++ b/include/cosim/uri.hpp @@ -274,21 +274,5 @@ uri path_to_file_uri(const cosim::filesystem::path& path); cosim::filesystem::path file_uri_to_path(const uri& fileUri); -/** - * Converts a URI with query parameter to a local filesystem path. - * - * \param [in] baseParentUri - * An (absolute) base parent URI. - * \param [in] queryUri - * An URI with arbitrary scheme component. Query file parameter path (if any) - * is specified after `file=`. Prefix `file:///` can be used for absolute path. - * - * \returns - * The local absolute path that corresponds to the `queryUri`, or the `baseParentUri` - * parent path if no file query is available. - */ -cosim::filesystem::path file_query_uri_to_path(const uri& baseParentUri, const uri& queryUri); - - } // namespace cosim -#endif // header guard +#endif // header guard \ No newline at end of file diff --git a/src/cosim/osp_config_parser.cpp b/src/cosim/osp_config_parser.cpp index 9331f5a8..ebaf3178 100644 --- a/src/cosim/osp_config_parser.cpp +++ b/src/cosim/osp_config_parser.cpp @@ -890,6 +890,20 @@ void connect_vector_sum_functions( } } +cosim::filesystem::path file_query_uri_to_path( + const cosim::uri& baseParentUri, + const cosim::uri& queryUri) +{ + const auto query = queryUri.query(); + if (query && query->find("file=") < query->size()) { + if (query->find("file=file:///") < query->size()) { + return file_uri_to_path(std::string(query->substr(5))); + } + return file_uri_to_path(std::string(baseParentUri.view()) + "/" + std::string(query->substr(5))); + } + return file_uri_to_path(baseParentUri); +} + } // namespace osp_config load_osp_config( diff --git a/src/cosim/uri.cpp b/src/cosim/uri.cpp index 84f3294f..db5857a0 100644 --- a/src/cosim/uri.cpp +++ b/src/cosim/uri.cpp @@ -559,19 +559,4 @@ cosim::filesystem::path file_uri_to_path(const uri& fileUri) } -cosim::filesystem::path file_query_uri_to_path( - const cosim::uri& baseParentUri, - const cosim::uri& queryUri) -{ - const auto query = queryUri.query(); - if (query && query->find("file=") < query->size()) { - if (query->find("file=file:///") < query->size()) { - return file_uri_to_path(std::string(query->substr(5))); - } - return file_uri_to_path(std::string(baseParentUri.view()) + "/" + std::string(query->substr(5))); - } - return file_uri_to_path(baseParentUri); -} - - } // namespace cosim diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e9136171..20fdf640 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -37,10 +37,16 @@ if(LIBCOSIM_WITH_PROXYFMU) "proxyfmu_integration_unittest" "proxyfmu_library_unittest" ) + list(APPEND tests + "proxyfmu_osp_config_parser_test" + ) endif() include("AddTestExecutable") foreach(test IN LISTS tests) + if (LIBCOSIM_WITH_PROXYFMU) + list(APPEND dependencies "proxyfmu::proxyfmu-client") + endif() add_test_executable( "cpp_${test}" FOLDER "C++ tests" diff --git a/tests/data/msmi/OspSystemStructure_proxyfmu.xml b/tests/data/msmi/OspSystemStructure_proxyfmu.xml new file mode 100644 index 00000000..c6d5c684 --- /dev/null +++ b/tests/data/msmi/OspSystemStructure_proxyfmu.xml @@ -0,0 +1,45 @@ + + + 0.0 + 1e-4 + fixedStep + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/proxyfmu_osp_config_parser_test.cpp b/tests/proxyfmu_osp_config_parser_test.cpp new file mode 100644 index 00000000..5fc898f6 --- /dev/null +++ b/tests/proxyfmu_osp_config_parser_test.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include +#include + +#include +#include + + +#define REQUIRE(test) \ + if (!(test)) throw std::runtime_error("Requirement not satisfied: " #test) + +void test(const cosim::filesystem::path& configPath, size_t expectedNumConnections) +{ + auto resolver = cosim::default_model_uri_resolver(); + const auto config = cosim::load_osp_config(configPath, *resolver); + auto execution = cosim::execution( + config.start_time, + std::make_shared(config.step_size)); + + const auto entityMaps = cosim::inject_system_structure( + execution, config.system_structure, config.initial_values); + REQUIRE(entityMaps.simulators.size() == 4); + REQUIRE(boost::size(config.system_structure.connections()) == expectedNumConnections); + + auto obs = std::make_shared(); + execution.add_observer(obs); + + auto result = execution.simulate_until(cosim::to_time_point(1e-3)); + REQUIRE(result.get()); + + const auto simIndex = entityMaps.simulators.at("CraneController"); + const auto varReference = + config.system_structure.get_variable_description({"CraneController", "cl1_min"}).reference; + double realValue = -1.0; + obs->get_real(simIndex, gsl::make_span(&varReference, 1), gsl::make_span(&realValue, 1)); + + double magicNumberFromConf = 2.2; + REQUIRE(std::fabs(realValue - magicNumberFromConf) < 1e-9); +} + +int main() +{ + try { + cosim::log::setup_simple_console_logging(); + cosim::log::set_global_output_level(cosim::log::info); + + const auto testDataDir = std::getenv("TEST_DATA_DIR"); + REQUIRE(testDataDir); + test(cosim::filesystem::path(testDataDir) / "msmi" / "OspSystemStructure_proxyfmu.xml", 9); + } catch (const std::exception& e) { + std::cerr << "Error: " << e.what(); + return 1; + } + return 0; +} \ No newline at end of file diff --git a/tests/uri_unittest.cpp b/tests/uri_unittest.cpp index 03b6fd4c..e5e74529 100644 --- a/tests/uri_unittest.cpp +++ b/tests/uri_unittest.cpp @@ -222,27 +222,3 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) BOOST_CHECK_THROW(file_uri_to_path("http://foo/bar"), std::invalid_argument); BOOST_CHECK_THROW(file_uri_to_path("file://foo/bar"), std::invalid_argument); } - - -BOOST_AUTO_TEST_CASE(file_query_uri_conversions) -{ - // From URI file query to path - const auto baseParentURI = uri("file:///c:/foo"); -#ifdef _WIN32 - BOOST_TEST(file_query_uri_to_path(baseParentURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "c:\\foo\\baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseParentURI, "proxyfmu://foo%20bar/bar/foo?file=bar/baz.txt") == "c:\\foo\\bar\\baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseParentURI, "http://foo%20bar/bar?file=baz.txt") == "c:\\foo\\baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseParentURI, "http://foo%20bar/foo/bar?file=bar%20foo/baz.txt") == "c:\\foo\\bar foo\\baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseParentURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "c:\\baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseParentURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "c:\\foo\\bar\\baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseParentURI, "http://foo%20baz/bar?foo=baz.txt") == "c:\\foo"); -#else - BOOST_TEST(file_query_uri_to_path(baseParentURI, "proxyfmu://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseParentURI, "proxyfmu://foo%20bar/bar/foo?file=bar/baz.txt") == "/c:/foo/bar/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseParentURI, "http://foo%20bar/bar?file=baz.txt") == "/c:/foo/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseParentURI, "http://foo%20bar/foo/bar?file=bar%20foo/baz.txt") == "/c:/foo/bar foo/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseParentURI, "proxyfmu://foo/bar?file=file:///c:/baz.txt") == "/c:/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseParentURI, "http://foo%20baz/bar?file=file:///c:/foo/bar/baz.txt") == "/c:/foo/bar/baz.txt"); - BOOST_TEST(file_query_uri_to_path(baseParentURI, "http://foo%20baz/bar?foo=baz.txt") == "/c:/foo"); -#endif -} From a5ae80c3fa61c9cf423d38b126bfac86f56903d8 Mon Sep 17 00:00:00 2001 From: msteinsto Date: Wed, 23 Mar 2022 15:18:50 +0100 Subject: [PATCH 20/20] Removed unused proxyfmu client dependency for tests --- tests/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 20fdf640..e4250a13 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -44,9 +44,6 @@ endif() include("AddTestExecutable") foreach(test IN LISTS tests) - if (LIBCOSIM_WITH_PROXYFMU) - list(APPEND dependencies "proxyfmu::proxyfmu-client") - endif() add_test_executable( "cpp_${test}" FOLDER "C++ tests"