From b2d9649fa3021695db3ac703e7d9efe7f11cb16e Mon Sep 17 00:00:00 2001 From: Will Sobel Date: Wed, 31 May 2023 22:18:48 -0400 Subject: [PATCH 1/3] Checkpoint --- src/mtconnect/agent.cpp | 33 ++++++++-- src/mtconnect/agent.hpp | 10 ++- .../configuration/config_options.hpp | 1 + src/mtconnect/pipeline/deliver.cpp | 13 ++++ src/mtconnect/pipeline/deliver.hpp | 17 +++++ src/mtconnect/pipeline/guard.hpp | 10 +-- src/mtconnect/pipeline/response_document.cpp | 38 +++++++++++ src/mtconnect/ruby/ruby_transform.hpp | 12 ++-- .../source/adapter/adapter_pipeline.cpp | 14 +++- .../source/adapter/adapter_pipeline.hpp | 3 +- .../adapter/agent_adapter/agent_adapter.cpp | 37 +++++++++-- .../adapter/agent_adapter/agent_adapter.hpp | 4 +- .../source/adapter/shdr/shdr_adapter.cpp | 3 +- test/agent_adapter_test.cpp | 52 +++++++++++++-- test/agent_device_test.cpp | 2 +- test/agent_test.cpp | 64 +++++++++---------- test/asset_hash_test.cpp | 2 +- test/composition_test.cpp | 2 +- test/config_test.cpp | 20 +++--- test/coordinate_system_test.cpp | 2 +- test/cutting_tool_test.cpp | 2 +- test/data_set_test.cpp | 2 +- test/embedded_ruby_test.cpp | 2 +- test/image_file_test.cpp | 4 +- test/json_printer_probe_test.cpp | 6 +- test/json_printer_stream_test.cpp | 4 +- test/kinematics_test.cpp | 2 +- test/mqtt_sink_test.cpp | 10 +-- test/mtconnect_xml_transform_test.cpp | 2 +- test/pipeline_deliver_test.cpp | 2 +- test/qif_document_test.cpp | 2 +- test/raw_material_test.cpp | 2 +- test/references_test.cpp | 2 +- test/relationship_test.cpp | 2 +- .../resources/samples}/128.32.164.245.xml | 0 .../resources/samples}/NoNamespace.xml | 0 .../resources/samples}/SimpleDevlce.xml | 0 .../samples}/agent.mtconnect.org.xml | 0 .../resources/samples}/configuration.xml | 0 .../resources/samples}/configuration1.6.xml | 0 .../resources/samples}/data_set.cfg | 0 .../resources/samples}/data_set.xml | 0 .../resources/samples}/data_set_variable.xml | 0 .../resources/samples}/discrete_example.xml | 0 .../resources/samples}/dyn_load.xml | 0 {samples => test/resources/samples}/empty.xml | 0 .../resources/samples}/extension.xml | 0 {samples => test/resources/samples}/fanuc.xml | 0 .../resources/samples}/filter_example.xml | 0 .../resources/samples}/filter_example_1.3.xml | 0 {samples => test/resources/samples}/haas.xml | 0 .../resources/samples}/kinematics.xml | 0 .../resources/samples}/min_config.xml | 0 .../resources/samples}/min_config2.xml | 0 .../resources/samples}/reference_example.xml | 0 .../resources/samples}/relationship_test.xml | 0 .../resources/samples}/solid_model.xml | 0 .../resources/samples}/test_config.xml | 0 .../resources/samples}/two_devices.xml | 0 test/response_document_test.cpp | 2 +- test/sensor_configuration_test.cpp | 2 +- test/solid_model_test.cpp | 2 +- test/specification_test.cpp | 4 +- test/table_test.cpp | 2 +- test/xml_parser_test.cpp | 36 +++++------ test/xml_printer_test.cpp | 22 +++---- 66 files changed, 314 insertions(+), 139 deletions(-) rename {samples => test/resources/samples}/128.32.164.245.xml (100%) rename {samples => test/resources/samples}/NoNamespace.xml (100%) rename {samples => test/resources/samples}/SimpleDevlce.xml (100%) rename {samples => test/resources/samples}/agent.mtconnect.org.xml (100%) rename {samples => test/resources/samples}/configuration.xml (100%) rename {samples => test/resources/samples}/configuration1.6.xml (100%) rename {samples => test/resources/samples}/data_set.cfg (100%) rename {samples => test/resources/samples}/data_set.xml (100%) rename {samples => test/resources/samples}/data_set_variable.xml (100%) rename {samples => test/resources/samples}/discrete_example.xml (100%) rename {samples => test/resources/samples}/dyn_load.xml (100%) rename {samples => test/resources/samples}/empty.xml (100%) rename {samples => test/resources/samples}/extension.xml (100%) rename {samples => test/resources/samples}/fanuc.xml (100%) rename {samples => test/resources/samples}/filter_example.xml (100%) rename {samples => test/resources/samples}/filter_example_1.3.xml (100%) rename {samples => test/resources/samples}/haas.xml (100%) rename {samples => test/resources/samples}/kinematics.xml (100%) rename {samples => test/resources/samples}/min_config.xml (100%) rename {samples => test/resources/samples}/min_config2.xml (100%) rename {samples => test/resources/samples}/reference_example.xml (100%) rename {samples => test/resources/samples}/relationship_test.xml (100%) rename {samples => test/resources/samples}/solid_model.xml (100%) rename {samples => test/resources/samples}/test_config.xml (100%) rename {samples => test/resources/samples}/two_devices.xml (100%) diff --git a/src/mtconnect/agent.cpp b/src/mtconnect/agent.cpp index d962648f7..c39e27015 100644 --- a/src/mtconnect/agent.cpp +++ b/src/mtconnect/agent.cpp @@ -388,15 +388,34 @@ namespace mtconnect { throw f; } } + + void Agent::loadDeviceXml(const string &deviceXml, const optional source) + { + try + { + auto printer = dynamic_cast(m_printers["xml"].get()); + auto device = m_xmlParser->parseDevice(deviceXml, printer); + loadDevice(device, source); + } + catch (runtime_error &e) + { + LOG(error) << "Error loading device: " << deviceXml; + LOG(error) << "Error detail: " << e.what(); + cerr << e.what() << endl; + } + catch (exception &f) + { + LOG(error) << "Error loading device: " << deviceXml; + LOG(error) << "Error detail: " << f.what(); + cerr << f.what() << endl; + } + } - void Agent::loadDevice(const string &deviceXml, const optional source) + void Agent::loadDevice(DevicePtr device, const optional source) { m_context.pause([=](config::AsyncContext &context) { try { - auto printer = dynamic_cast(m_printers["xml"].get()); - auto device = m_xmlParser->parseDevice(deviceXml, printer); - if (device) { bool changed = receiveDevice(device, true); @@ -416,13 +435,13 @@ namespace mtconnect { } catch (runtime_error &e) { - LOG(error) << "Error loading device: " + deviceXml; + LOG(error) << "Error loading device: " << *device->getComponentName(); LOG(error) << "Error detail: " << e.what(); cerr << e.what() << endl; } catch (exception &f) { - LOG(error) << "Error loading device: " + deviceXml; + LOG(error) << "Error loading device: " << *device->getComponentName(); LOG(error) << "Error detail: " << f.what(); cerr << f.what() << endl; } @@ -1421,7 +1440,7 @@ namespace mtconnect { } else if (command == "devicemodel") { - loadDevice(value, source); + loadDeviceXml(value, source); } else { diff --git a/src/mtconnect/agent.hpp b/src/mtconnect/agent.hpp index 4b4cbc6dc..e7b902d39 100644 --- a/src/mtconnect/agent.hpp +++ b/src/mtconnect/agent.hpp @@ -263,10 +263,16 @@ namespace mtconnect { /// @return true if successful bool reloadDevices(const std::string &deviceFile); + /// @brief receive a single device from a source + /// @param[in] deviceXml the device xml as a string + /// @param[in] source the source loading the device + void loadDevice(DevicePtr device, + const std::optional source = std::nullopt); + /// @brief receive and parse a single device from a source /// @param[in] deviceXml the device xml as a string /// @param[in] source the source loading the device - void loadDevice(const std::string &deviceXml, + void loadDeviceXml(const std::string &deviceXml, const std::optional source = std::nullopt); /// @name Message when source has connected and disconnected @@ -564,7 +570,7 @@ namespace mtconnect { void deliverConnectStatus(entity::EntityPtr, const StringList &devices, bool autoAvailable) override; void deliverCommand(entity::EntityPtr) override; - void deliverDevice(DevicePtr device) override { m_agent->receiveDevice(device); } + void deliverDevice(DevicePtr device) override { m_agent->loadDevice(device); } void sourceFailed(const std::string &identity) override { m_agent->sourceFailed(identity); } diff --git a/src/mtconnect/configuration/config_options.hpp b/src/mtconnect/configuration/config_options.hpp index a012d3993..2b79c7dd3 100644 --- a/src/mtconnect/configuration/config_options.hpp +++ b/src/mtconnect/configuration/config_options.hpp @@ -121,6 +121,7 @@ namespace mtconnect { DECLARE_CONFIGURATION(UpcaseDataItemValue); DECLARE_CONFIGURATION(Url); DECLARE_CONFIGURATION(UsePolling); + DECLARE_CONFIGURATION(UpdateDeviceXml); ///@} } // namespace configuration diff --git a/src/mtconnect/pipeline/deliver.cpp b/src/mtconnect/pipeline/deliver.cpp index f07630afe..601d92ef2 100644 --- a/src/mtconnect/pipeline/deliver.cpp +++ b/src/mtconnect/pipeline/deliver.cpp @@ -135,6 +135,19 @@ namespace mtconnect { return entity; } + EntityPtr DeliverDevice::operator()(entity::EntityPtr &&entity) + { + auto d = std::dynamic_pointer_cast(entity); + if (!d) + { + throw EntityError("Unexpected entity type, cannot convert to asset in DeliverAsset"); + } + + m_contract->deliverDevice(d); + + return entity; + } + entity::EntityPtr DeliverConnectionStatus::operator()(entity::EntityPtr &&entity) { m_contract->deliverConnectStatus(entity, m_devices, m_autoAvailable); diff --git a/src/mtconnect/pipeline/deliver.hpp b/src/mtconnect/pipeline/deliver.hpp index 26191374a..f4da6af3d 100644 --- a/src/mtconnect/pipeline/deliver.hpp +++ b/src/mtconnect/pipeline/deliver.hpp @@ -21,6 +21,7 @@ #include +#include "mtconnect/device_model/device.hpp" #include "mtconnect/asset/asset.hpp" #include "mtconnect/config.hpp" #include "mtconnect/observation/observation.hpp" @@ -153,6 +154,22 @@ namespace mtconnect::pipeline { entity::EntityPtr operator()(entity::EntityPtr &&entity) override; }; + /// @brief A transform to deliver a device + class AGENT_LIB_API DeliverDevice : public Transform + { + public: + using Deliver = std::function; + DeliverDevice(PipelineContextPtr context) + : Transform("DeliverDevice"), m_contract(context->m_contract.get()) + { + m_guard = TypeGuard(RUN); + } + entity::EntityPtr operator()(entity::EntityPtr &&entity) override; + + protected: + PipelineContract *m_contract; + }; + /// @brief deliver the connection status of an adapter class AGENT_LIB_API DeliverConnectionStatus : public Transform { diff --git a/src/mtconnect/pipeline/guard.hpp b/src/mtconnect/pipeline/guard.hpp index 5c66c9355..43bf83a23 100644 --- a/src/mtconnect/pipeline/guard.hpp +++ b/src/mtconnect/pipeline/guard.hpp @@ -40,11 +40,11 @@ namespace mtconnect { { public: /// @brief Construct a GuardCls - /// @param match the match to return if matched - GuardCls(GuardAction match) : m_match(match) {} + /// @param match the action if matched + GuardCls(GuardAction action) : m_action(action) {} GuardCls(const GuardCls &) = default; - GuardAction operator()(const entity::Entity *entity) { return m_match; } + GuardAction operator()(const entity::Entity *entity) { return m_action; } /// @brief set the alternative guard /// @param alt alternative @@ -57,7 +57,7 @@ namespace mtconnect { GuardAction check(bool matched, const entity::Entity *entity) { if (matched) - return m_match; + return m_action; else if (m_alternative) return m_alternative(entity); else @@ -83,7 +83,7 @@ namespace mtconnect { protected: Guard m_alternative; - GuardAction m_match; + GuardAction m_action; }; /// @brief A guard that checks if the entity is one of the types or sub-types diff --git a/src/mtconnect/pipeline/response_document.cpp b/src/mtconnect/pipeline/response_document.cpp index b9c793679..5d22b1baa 100644 --- a/src/mtconnect/pipeline/response_document.cpp +++ b/src/mtconnect/pipeline/response_document.cpp @@ -147,6 +147,40 @@ namespace mtconnect::pipeline { return ""; } + + inline static bool parseDevices(ResponseDocument &out, xmlNodePtr node, + pipeline::PipelineContextPtr context, + const std::optional &device) + { + using namespace entity; + using namespace device_model; + + auto devices = findChild(node, "Devices"); + if (devices == nullptr) + return false; + + entity::XmlParser parser; + eachElement(devices, [&out, &parser, &device](xmlNodePtr n) { + ErrorList errors; + auto dev = parser.parseXmlNode(Device::getRoot(), n, errors); + if (!errors.empty()) + { + LOG(warning) << "Could not parse asset: " << (const char *)n->name; + for (auto &e : errors) + { + LOG(warning) << " Message: " << e->what(); + } + } + + if (dev && (!device || *device == dev->get("name"))) + out.m_entities.emplace_back(dev); + + return true; + }); + + return true; + } + inline DataSetValue type(const string &s) { @@ -454,6 +488,10 @@ namespace mtconnect::pipeline { { return parseObservations(out, root, context, device); } + else if (xmlStrcmp(BAD_CAST "MTConnectDevices", root->name) == 0) + { + return parseDevices(out, root, context, device); + } else if (xmlStrcmp(BAD_CAST "MTConnectAssets", root->name) == 0) { return parseAssets(out, root, device); diff --git a/src/mtconnect/ruby/ruby_transform.hpp b/src/mtconnect/ruby/ruby_transform.hpp index c679b71c0..b1c78a95f 100644 --- a/src/mtconnect/ruby/ruby_transform.hpp +++ b/src/mtconnect/ruby/ruby_transform.hpp @@ -165,15 +165,17 @@ namespace mtconnect::ruby { void setGuard() { if (m_guardString == "Observation") - m_guard = TypeGuard(RUN) || TypeGuard(SKIP); + m_guard = TypeGuard(RUN) || GuardCls(SKIP); else if (m_guardString == "Sample") - m_guard = TypeGuard(RUN) || TypeGuard(SKIP); + m_guard = TypeGuard(RUN) || GuardCls(SKIP); else if (m_guardString == "Event") - m_guard = TypeGuard(RUN) || TypeGuard(SKIP); + m_guard = TypeGuard(RUN) || GuardCls(SKIP); + else if (m_guardString == "Condition") + m_guard = TypeGuard(RUN) || GuardCls(SKIP); else if (m_guardString == "Tokens") - m_guard = TypeGuard(RUN) || TypeGuard(SKIP); + m_guard = TypeGuard(RUN) || GuardCls(SKIP); else if (m_guardString == "Message") - m_guard = TypeGuard(RUN) || TypeGuard(SKIP); + m_guard = TypeGuard(RUN) || GuardCls(SKIP); else m_guard = TypeGuard(RUN); diff --git a/src/mtconnect/source/adapter/adapter_pipeline.cpp b/src/mtconnect/source/adapter/adapter_pipeline.cpp index b902164fd..56d780c42 100644 --- a/src/mtconnect/source/adapter/adapter_pipeline.cpp +++ b/src/mtconnect/source/adapter/adapter_pipeline.cpp @@ -103,11 +103,14 @@ namespace mtconnect { } } - void AdapterPipeline::buildCommandAndStatusDelivery() + void AdapterPipeline::buildCommandAndStatusDelivery(pipeline::TransformPtr next) { - bind(make_shared( + if (next == nullptr) + next = m_start; + + next->bind(make_shared( m_context, m_devices, IsOptionSet(m_options, configuration::AutoAvailable))); - bind(make_shared(m_context, m_device)); + next->bind(make_shared(m_context, m_device)); } void AdapterPipeline::buildAssetDelivery(pipeline::TransformPtr next) @@ -120,6 +123,11 @@ namespace mtconnect { next->bind(make_shared(m_context)); } + void AdapterPipeline::buildDeviceDelivery(pipeline::TransformPtr next) + { + next->bind(make_shared(m_context)); + } + void AdapterPipeline::buildObservationDelivery(pipeline::TransformPtr next) { // Uppercase Events diff --git a/src/mtconnect/source/adapter/adapter_pipeline.hpp b/src/mtconnect/source/adapter/adapter_pipeline.hpp index 6f1660cff..9af9ddadd 100644 --- a/src/mtconnect/source/adapter/adapter_pipeline.hpp +++ b/src/mtconnect/source/adapter/adapter_pipeline.hpp @@ -72,7 +72,8 @@ namespace mtconnect::source::adapter { protected: void buildDeviceList(); - void buildCommandAndStatusDelivery(); + void buildCommandAndStatusDelivery(pipeline::TransformPtr next = nullptr); + void buildDeviceDelivery(pipeline::TransformPtr next); void buildAssetDelivery(pipeline::TransformPtr next); void buildObservationDelivery(pipeline::TransformPtr next); diff --git a/src/mtconnect/source/adapter/agent_adapter/agent_adapter.cpp b/src/mtconnect/source/adapter/agent_adapter/agent_adapter.cpp index c2eb9648c..6eb755e15 100644 --- a/src/mtconnect/source/adapter/agent_adapter/agent_adapter.cpp +++ b/src/mtconnect/source/adapter/agent_adapter/agent_adapter.cpp @@ -51,8 +51,10 @@ namespace mtconnect::source::adapter::agent_adapter { std::optional obsMetrics; obsMetrics = m_identity + "_observation_update_rate"; next->bind(make_shared(m_context, obsMetrics)); - + buildDeviceDelivery(next); buildAssetDelivery(next); + + applySplices(); } AgentAdapter::AgentAdapter(boost::asio::io_context &io, pipeline::PipelineContextPtr context, @@ -82,6 +84,7 @@ namespace mtconnect::source::adapter::agent_adapter { {configuration::ReconnectInterval, 10000ms}, {configuration::RelativeTime, false}, {configuration::UsePolling, false}, + {configuration::UpdateDeviceXml, false}, {"!CloseConnectionAfterResponse!", false}}); m_handler = m_pipeline.makeHandler(); @@ -107,6 +110,8 @@ namespace mtconnect::source::adapter::agent_adapter { m_usePolling = *GetOption(m_options, configuration::UsePolling); m_reconnectInterval = *GetOption(m_options, configuration::ReconnectInterval); m_pollingInterval = *GetOption(m_options, configuration::PollingInterval); + m_probeAgent = *GetOption(m_options, configuration::UpdateDeviceXml); + m_closeConnectionAfterResponse = *GetOption(m_options, "!CloseConnectionAfterResponse!"); @@ -344,8 +349,15 @@ namespace mtconnect::source::adapter::agent_adapter { clear(); m_reconnecting = false; - assets(); - current(); + if (m_probeAgent) + { + probe(); + } + else + { + assets(); + current(); + } } void AgentAdapter::recover() @@ -356,15 +368,28 @@ namespace mtconnect::source::adapter::agent_adapter { m_reconnecting = false; sample(); } + + bool AgentAdapter::probe() + { + if (m_stopped) + return false; - void AgentAdapter::current() + m_streamRequest.emplace(m_sourceDevice, "probe", UrlQuery(), false, + [this]() { + assets(); + return current(); + }); + return m_session->makeRequest(*m_streamRequest); + } + + bool AgentAdapter::current() { if (m_stopped) - return; + return false; m_streamRequest.emplace(m_sourceDevice, "current", UrlQuery(), false, [this]() { return sample(); }); - m_session->makeRequest(*m_streamRequest); + return m_session->makeRequest(*m_streamRequest); } bool AgentAdapter::sample() diff --git a/src/mtconnect/source/adapter/agent_adapter/agent_adapter.hpp b/src/mtconnect/source/adapter/agent_adapter/agent_adapter.hpp index 40f056d8b..b07855e63 100644 --- a/src/mtconnect/source/adapter/agent_adapter/agent_adapter.hpp +++ b/src/mtconnect/source/adapter/agent_adapter/agent_adapter.hpp @@ -106,7 +106,8 @@ namespace mtconnect::source::adapter::agent_adapter { protected: void run(); void recover(); - void current(); + bool probe(); + bool current(); bool sample(); void assets(); void updateAssets(); @@ -132,6 +133,7 @@ namespace mtconnect::source::adapter::agent_adapter { bool m_failed = false; bool m_stopped = false; bool m_usePolling = false; + bool m_probeAgent = false; std::chrono::milliseconds m_reconnectInterval; std::chrono::milliseconds m_pollingInterval; diff --git a/src/mtconnect/source/adapter/shdr/shdr_adapter.cpp b/src/mtconnect/source/adapter/shdr/shdr_adapter.cpp index 616c13e88..6eefc2f3c 100644 --- a/src/mtconnect/source/adapter/shdr/shdr_adapter.cpp +++ b/src/mtconnect/source/adapter/shdr/shdr_adapter.cpp @@ -63,7 +63,8 @@ namespace mtconnect::source::adapter::shdr { {configuration::Port, 7878}, {configuration::AutoAvailable, false}, {configuration::RealTime, false}, - {configuration::RelativeTime, false}}); + {configuration::RelativeTime, false}, + {configuration::UpdateDeviceXml, false}}); m_server = get(m_options[configuration::Host]); m_port = get(m_options[configuration::Port]); diff --git a/test/agent_adapter_test.cpp b/test/agent_adapter_test.cpp index c5f2a7ae0..1d5fbd6d4 100644 --- a/test/agent_adapter_test.cpp +++ b/test/agent_adapter_test.cpp @@ -77,7 +77,7 @@ struct MockPipelineContract : public PipelineContract m_observations.push_back(obs); } void deliverAsset(AssetPtr) override {} - void deliverDevice(DevicePtr) override {} + void deliverDevice(DevicePtr d) override { m_receivedDevice = d; } void deliverAssetCommand(entity::EntityPtr) override {} void deliverCommand(entity::EntityPtr) override {} void deliverConnectStatus(entity::EntityPtr, const StringList &dev, bool flag) override {} @@ -88,6 +88,7 @@ struct MockPipelineContract : public PipelineContract std::string m_result; std::string m_deviceName; DevicePtr m_device; + DevicePtr m_receivedDevice; std::vector m_observations; }; @@ -106,7 +107,7 @@ class AgentAdapterTest : public testing::Test auto parser = make_unique(); m_device = - parser->parseFile(PROJECT_ROOT_DIR "/samples/test_config.xml", printer.get()).front(); + parser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/test_config.xml", printer.get()).front(); m_context = make_shared(); m_context->m_contract = make_unique(m_device); @@ -128,9 +129,9 @@ class AgentAdapterTest : public testing::Test m_adapter.reset(); } - void createAgent(ConfigOptions options = {}) + void createAgent(ConfigOptions options = {}, std::string deviceFile = "/test/resources/samples/test_config.xml") { - m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "2.0", 25, false, true, + m_agentTestHelper->createAgent(deviceFile, 8, 4, "2.0", 25, false, true, options); m_agentTestHelper->getAgent()->start(); m_agentId = to_string(getCurrentTimeInSec()); @@ -627,7 +628,7 @@ TEST_F(AgentAdapterTest, should_use_polling_when_option_is_set) throw runtime_error("test timed out"); } }); - + while (rc < 2) { m_agentTestHelper->m_ioContext.run_one(); @@ -717,3 +718,44 @@ TEST_F(AgentAdapterTest, should_connect_to_tls_agent) timeout.cancel(); } + +TEST_F(AgentAdapterTest, should_create_device_when_option_supplied) +{ + createAgent({}, "/test/resources/samples/solid_model.xml"); + + auto port = m_agentTestHelper->m_restService->getServer()->getPort(); + auto adapter = createAdapter(port, {{configuration::UpdateDeviceXml, true}}); + + addAdapter(); + + unique_ptr handler = make_unique(); + + int rc = 0; + ResponseDocument rd; + handler->m_processData = [&](const string &d, const string &s) { + ResponseDocument::parse(d, rd, m_context); + rc++; + + adapter->getFeedback().m_next = rd.m_next; + }; + handler->m_connecting = [&](const string id) {}; + handler->m_connected = [&](const string id) {}; + + adapter->setHandler(handler); + adapter->start(); + + boost::asio::steady_timer timeout(m_agentTestHelper->m_ioContext, 2s); + timeout.async_wait([](boost::system::error_code ec) { + if (!ec) + { + throw runtime_error("test timed out"); + } + }); + + while (rc < 2) + { + m_agentTestHelper->m_ioContext.run_one(); + } + ASSERT_EQ(2, rc); + +} diff --git a/test/agent_device_test.cpp b/test/agent_device_test.cpp index 84899f8a7..a6a75627d 100644 --- a/test/agent_device_test.cpp +++ b/test/agent_device_test.cpp @@ -55,7 +55,7 @@ class AgentDeviceTest : public testing::Test { m_agentTestHelper = make_unique(); auto version = to_string(AGENT_VERSION_MAJOR) + "." + to_string(AGENT_VERSION_MINOR); - m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, version, 25); + m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, version, 25); m_agentId = to_string(getCurrentTimeInSec()); m_agentDevice = m_agentTestHelper->m_agent->getAgentDevice(); } diff --git a/test/agent_test.cpp b/test/agent_test.cpp index 1ed4fc5cf..83ad3291d 100644 --- a/test/agent_test.cpp +++ b/test/agent_test.cpp @@ -65,7 +65,7 @@ class AgentTest : public testing::Test void SetUp() override { m_agentTestHelper = make_unique(); - m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "1.3", 25, true); + m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "1.3", 25, true); m_agentId = to_string(getCurrentTimeInSec()); } @@ -90,7 +90,7 @@ TEST_F(AgentTest, Constructor) ConfigOptions options {{BufferSize, 17}, {MaxAssets, 8}, {SchemaVersion, "1.7"s}}; unique_ptr agent = make_unique(m_agentTestHelper->m_ioContext, - PROJECT_ROOT_DIR "/samples/badPath.xml", options); + PROJECT_ROOT_DIR "/test/resources/samples/badPath.xml", options); auto context = std::make_shared(); context->m_contract = agent->makePipelineContract(); @@ -98,7 +98,7 @@ TEST_F(AgentTest, Constructor) agent.reset(); agent = make_unique(m_agentTestHelper->m_ioContext, - PROJECT_ROOT_DIR "/samples/test_config.xml", options); + PROJECT_ROOT_DIR "/test/resources/samples/test_config.xml", options); context = std::make_shared(); context->m_contract = agent->makePipelineContract(); @@ -134,7 +134,7 @@ TEST_F(AgentTest, FailWithDuplicateDeviceUUID) ConfigOptions options {{BufferSize, 17}, {MaxAssets, 8}, {SchemaVersion, "1.5"s}}; unique_ptr agent = make_unique(m_agentTestHelper->m_ioContext, - PROJECT_ROOT_DIR "/samples/dup_uuid.xml", options); + PROJECT_ROOT_DIR "/test/resources/samples/dup_uuid.xml", options); auto context = std::make_shared(); context->m_contract = agent->makePipelineContract(); @@ -1051,7 +1051,7 @@ TEST_F(AgentTest, DynamicCalibration) TEST_F(AgentTest, FilterValues13) { - m_agentTestHelper->createAgent("/samples/filter_example_1.3.xml", 8, 4, "1.5", 25); + m_agentTestHelper->createAgent("/test/resources/samples/filter_example_1.3.xml", 8, 4, "1.5", 25); addAdapter(); { @@ -1090,7 +1090,7 @@ TEST_F(AgentTest, FilterValues13) TEST_F(AgentTest, FilterValues) { - m_agentTestHelper->createAgent("/samples/filter_example_1.3.xml", 8, 4, "1.5", 25); + m_agentTestHelper->createAgent("/test/resources/samples/filter_example_1.3.xml", 8, 4, "1.5", 25); addAdapter(); { @@ -1155,7 +1155,7 @@ TEST_F(AgentTest, FilterValues) TEST_F(AgentTest, TestPeriodFilterWithIgnoreTimestamps) { // Test period filter with ignore timestamps - m_agentTestHelper->createAgent("/samples/filter_example_1.3.xml", 8, 4, "1.5", 25); + m_agentTestHelper->createAgent("/test/resources/samples/filter_example_1.3.xml", 8, 4, "1.5", 25); addAdapter({{configuration::IgnoreTimestamps, true}}); { @@ -1186,7 +1186,7 @@ TEST_F(AgentTest, TestPeriodFilterWithIgnoreTimestamps) TEST_F(AgentTest, TestPeriodFilterWithRelativeTime) { // Test period filter with relative time - m_agentTestHelper->createAgent("/samples/filter_example_1.3.xml", 8, 4, "1.5", 25); + m_agentTestHelper->createAgent("/test/resources/samples/filter_example_1.3.xml", 8, 4, "1.5", 25); addAdapter({{configuration::RelativeTime, true}}); { @@ -1240,7 +1240,7 @@ TEST_F(AgentTest, References) { using namespace device_model; - m_agentTestHelper->createAgent("/samples/reference_example.xml"); + m_agentTestHelper->createAgent("/test/resources/samples/reference_example.xml"); addAdapter(); auto agent = m_agentTestHelper->getAgent(); @@ -1300,7 +1300,7 @@ TEST_F(AgentTest, References) TEST_F(AgentTest, Discrete) { - m_agentTestHelper->createAgent("/samples/discrete_example.xml"); + m_agentTestHelper->createAgent("/test/resources/samples/discrete_example.xml"); addAdapter({{configuration::FilterDuplicates, true}}); auto agent = m_agentTestHelper->getAgent(); @@ -1682,7 +1682,7 @@ TEST_F(AgentTest, AdapterCommands) TEST_F(AgentTest, AdapterDeviceCommand) { - m_agentTestHelper->createAgent("/samples/two_devices.xml"); + m_agentTestHelper->createAgent("/test/resources/samples/two_devices.xml"); auto agent = m_agentTestHelper->getAgent(); auto device1 = agent->getDeviceByName("Device1"); @@ -1713,7 +1713,7 @@ TEST_F(AgentTest, AdapterDeviceCommand) TEST_F(AgentTest, adapter_command_should_set_adapter_and_mtconnect_versions) { - m_agentTestHelper->createAgent("/samples/kinematics.xml", 8, 4, "1.7", 25); + m_agentTestHelper->createAgent("/test/resources/samples/kinematics.xml", 8, 4, "1.7", 25); addAdapter(); auto printer = m_agentTestHelper->m_agent->getPrinter("xml"); @@ -1795,7 +1795,7 @@ TEST_F(AgentTest, UUIDChange) TEST_F(AgentTest, AssetStorage) { - auto agent = m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "1.3", 4, true); + auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "1.3", 4, true); auto rest = m_agentTestHelper->getRestService(); ASSERT_TRUE(rest->getServer()->arePutsAllowed()); @@ -1830,7 +1830,7 @@ TEST_F(AgentTest, AssetStorage) TEST_F(AgentTest, AssetBuffer) { - auto agent = m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "1.3", 4, true); + auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "1.3", 4, true); string body = "TEST 1"; QueryMap queries; @@ -2236,7 +2236,7 @@ TEST_F(AgentTest, AssetRemovalByAdapter) TEST_F(AgentTest, AssetAdditionOfAssetChanged12) { - m_agentTestHelper->createAgent("/samples/min_config.xml", 8, 4, "1.2", 25); + m_agentTestHelper->createAgent("/test/resources/samples/min_config.xml", 8, 4, "1.2", 25); { PARSE_XML_RESPONSE("/LinuxCNC/probe"); @@ -2248,7 +2248,7 @@ TEST_F(AgentTest, AssetAdditionOfAssetChanged12) TEST_F(AgentTest, AssetAdditionOfAssetRemoved13) { - m_agentTestHelper->createAgent("/samples/min_config.xml", 8, 4, "1.3", 25); + m_agentTestHelper->createAgent("/test/resources/samples/min_config.xml", 8, 4, "1.3", 25); { PARSE_XML_RESPONSE("/LinuxCNC/probe"); @@ -2260,7 +2260,7 @@ TEST_F(AgentTest, AssetAdditionOfAssetRemoved13) TEST_F(AgentTest, AssetAdditionOfAssetRemoved15) { - m_agentTestHelper->createAgent("/samples/min_config.xml", 8, 4, "1.5", 25); + m_agentTestHelper->createAgent("/test/resources/samples/min_config.xml", 8, 4, "1.5", 25); { PARSE_XML_RESPONSE("/LinuxCNC/probe"); ASSERT_XML_PATH_COUNT(doc, "//m:DataItem[@type='ASSET_CHANGED']", 1); @@ -2320,7 +2320,7 @@ TEST_F(AgentTest, RemoveLastAssetChanged) TEST_F(AgentTest, RemoveAssetUsingHttpDelete) { - auto agent = m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "1.3", 4, true); + auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "1.3", 4, true); addAdapter(); const auto &storage = agent->getAssetStorage(); @@ -2417,7 +2417,7 @@ TEST_F(AgentTest, RemoveAllAssets) TEST_F(AgentTest, AssetProbe) { - auto agent = m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "1.3", 4, true); + auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "1.3", 4, true); string body = "TEST 1"; QueryMap queries; const auto &storage = agent->getAssetStorage(); @@ -2443,7 +2443,7 @@ TEST_F(AgentTest, AssetProbe) TEST_F(AgentTest, ResponseToHTTPAssetPutErrors) { - m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "1.3", 4, true); + m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "1.3", 4, true); const string body { R"DOC( @@ -2506,7 +2506,7 @@ TEST_F(AgentTest, ResponseToHTTPAssetPutErrors) TEST_F(AgentTest, update_asset_count_data_item_v2_0) { - m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 10, "2.0", 4, true); + m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 10, "2.0", 4, true); addAdapter(); m_agentTestHelper->m_adapter->processData( @@ -2722,7 +2722,7 @@ TEST_F(AgentTest, StreamDataObserver) TEST_F(AgentTest, Put) { - m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "1.3", 4, true); + m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "1.3", 4, true); QueryMap queries; string body; @@ -2745,7 +2745,7 @@ TEST_F(AgentTest, Put) TEST_F(AgentTest, put_condition_should_parse_condition_data) { - m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "1.3", 4, true); + m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "1.3", 4, true); QueryMap queries; string body; @@ -2768,7 +2768,7 @@ TEST_F(AgentTest, put_condition_should_parse_condition_data) TEST_F(AgentTest, shound_add_asset_count_when_20) { - m_agentTestHelper->createAgent("/samples/min_config.xml", 8, 4, "2.0", 25); + m_agentTestHelper->createAgent("/test/resources/samples/min_config.xml", 8, 4, "2.0", 25); { PARSE_XML_RESPONSE("/LinuxCNC/probe"); @@ -2782,7 +2782,7 @@ TEST_F(AgentTest, shound_add_asset_count_when_20) TEST_F(AgentTest, asset_count_should_not_occur_in_header_post_20) { - auto agent = m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "2.0", 4, true); + auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "2.0", 4, true); string body = "TEST 1"; QueryMap queries; @@ -2808,7 +2808,7 @@ TEST_F(AgentTest, asset_count_should_not_occur_in_header_post_20) TEST_F(AgentTest, asset_count_should_track_asset_additions_by_type) { - auto agent = m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "2.0", 4, true); + auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "2.0", 4, true); string body1 = "TEST 1"; QueryMap queries; @@ -2866,7 +2866,7 @@ TEST_F(AgentTest, asset_count_should_track_asset_additions_by_type) TEST_F(AgentTest, asset_should_also_work_using_post_with_assets) { - auto agent = m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "2.0", 4, true); + auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "2.0", 4, true); string body = "TEST 1"; QueryMap queries; @@ -2890,7 +2890,7 @@ TEST_F(AgentTest, pre_start_hook_should_be_called) helper.getAgent()->beforeStartHooks().add(lambda); }; m_agentTestHelper->setAgentCreateHook(helperHook); - auto agent = m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "2.0", 4, true); + auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "2.0", 4, true); ASSERT_FALSE(called); agent->start(); @@ -2906,7 +2906,7 @@ TEST_F(AgentTest, pre_initialize_hooks_should_be_called) helper.getAgent()->beforeInitializeHooks().add(lambda); }; m_agentTestHelper->setAgentCreateHook(helperHook); - m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "2.0", 4, true); + m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "2.0", 4, true); ASSERT_TRUE(called); } @@ -2919,7 +2919,7 @@ TEST_F(AgentTest, post_initialize_hooks_should_be_called) helper.getAgent()->afterInitializeHooks().add(lambda); }; m_agentTestHelper->setAgentCreateHook(helperHook); - m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "2.0", 4, true); + m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "2.0", 4, true); ASSERT_TRUE(called); } @@ -2932,7 +2932,7 @@ TEST_F(AgentTest, pre_stop_hook_should_be_called) helper.getAgent()->beforeStopHooks().add(lambda); }; m_agentTestHelper->setAgentCreateHook(helperHook); - auto agent = m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "2.0", 4, true); + auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "2.0", 4, true); ASSERT_FALSE(called); agent->start(); @@ -2943,7 +2943,7 @@ TEST_F(AgentTest, pre_stop_hook_should_be_called) TEST_F(AgentTest, device_should_have_hash_for_2_2) { - m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "2.2", 4, true); + m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "2.2", 4, true); auto device = m_agentTestHelper->getAgent()->getDeviceByName("LinuxCNC"); ASSERT_TRUE(device); diff --git a/test/asset_hash_test.cpp b/test/asset_hash_test.cpp index 6d5529e48..16c3a92dc 100644 --- a/test/asset_hash_test.cpp +++ b/test/asset_hash_test.cpp @@ -50,7 +50,7 @@ class AssetHashTest : public testing::Test void SetUp() override { // Create an agent with only 16 slots and 8 data items. m_agentTestHelper = make_unique(); - m_agentTestHelper->createAgent("/samples/solid_model.xml", 8, 4, "2.2", 25); + m_agentTestHelper->createAgent("/test/resources/samples/solid_model.xml", 8, 4, "2.2", 25); m_agentId = to_string(getCurrentTimeInSec()); m_device = m_agentTestHelper->m_agent->getDeviceByName("LinuxCNC"); } diff --git a/test/composition_test.cpp b/test/composition_test.cpp index b9e75879b..2bb788743 100644 --- a/test/composition_test.cpp +++ b/test/composition_test.cpp @@ -52,7 +52,7 @@ class CompositionTest : public testing::Test void SetUp() override { // Create an agent with only 16 slots and 8 data items. m_agentTestHelper = make_unique(); - m_agentTestHelper->createAgent("/samples/configuration.xml", 8, 4, "1.5", 25); + m_agentTestHelper->createAgent("/test/resources/samples/configuration.xml", 8, 4, "1.5", 25); auto device = m_agentTestHelper->m_agent->getDeviceByName("LinuxCNC"); m_component = device->getComponentById("power"); diff --git a/test/config_test.cpp b/test/config_test.cpp index 866309786..36e5fdea9 100644 --- a/test/config_test.cpp +++ b/test/config_test.cpp @@ -143,7 +143,7 @@ namespace { TEST_F(ConfigTest, Device) { - string str("Devices = " PROJECT_ROOT_DIR "/samples/test_config.xml\n"); + string str("Devices = " PROJECT_ROOT_DIR "/test/resources/samples/test_config.xml\n"); m_config->loadConfig(str); const auto agent = m_config->getAgent(); @@ -168,7 +168,7 @@ namespace { using namespace std::chrono_literals; string str("Devices = " PROJECT_ROOT_DIR - "/samples/test_config.xml\n" + "/test/resources/samples/test_config.xml\n" "Adapters { LinuxCNC { \n" "Port = 23\n" "Host = 10.211.55.1\n" @@ -200,7 +200,7 @@ namespace { TEST_F(ConfigTest, DefaultPreserveUUID) { string str("Devices = " PROJECT_ROOT_DIR - "/samples/test_config.xml\n" + "/test/resources/samples/test_config.xml\n" "PreserveUUID = true\n"); m_config->loadConfig(str); @@ -214,7 +214,7 @@ namespace { TEST_F(ConfigTest, DefaultPreserveOverride) { string str("Devices = " PROJECT_ROOT_DIR - "/samples/test_config.xml\n" + "/test/resources/samples/test_config.xml\n" "PreserveUUID = true\n" "Adapters { LinuxCNC { \n" "PreserveUUID = false\n" @@ -231,7 +231,7 @@ namespace { TEST_F(ConfigTest, DisablePut) { string str("Devices = " PROJECT_ROOT_DIR - "/samples/test_config.xml\n" + "/test/resources/samples/test_config.xml\n" "AllowPut = true\n"); m_config->loadConfig(str); @@ -247,7 +247,7 @@ namespace { TEST_F(ConfigTest, LimitPut) { string str("Devices = " PROJECT_ROOT_DIR - "/samples/test_config.xml\n" + "/test/resources/samples/test_config.xml\n" "AllowPutFrom = localhost\n"); m_config->loadConfig(str); @@ -265,7 +265,7 @@ namespace { TEST_F(ConfigTest, LimitPutFromHosts) { string str("Devices = " PROJECT_ROOT_DIR - "/samples/test_config.xml\n" + "/test/resources/samples/test_config.xml\n" "AllowPutFrom = localhost, 192.168.0.1\n"); m_config->loadConfig(str); @@ -358,7 +358,7 @@ namespace { using namespace std::chrono_literals; string str("Devices = " PROJECT_ROOT_DIR - "/samples/test_config.xml\n" + "/test/resources/samples/test_config.xml\n" "LegacyTimeout = 2000\n"); m_config->loadConfig(str); @@ -372,7 +372,7 @@ namespace { TEST_F(ConfigTest, IgnoreTimestamps) { string str("Devices = " PROJECT_ROOT_DIR - "/samples/test_config.xml\n" + "/test/resources/samples/test_config.xml\n" "IgnoreTimestamps = true\n"); m_config->loadConfig(str); @@ -386,7 +386,7 @@ namespace { TEST_F(ConfigTest, IgnoreTimestampsOverride) { string str("Devices = " PROJECT_ROOT_DIR - "/samples/test_config.xml\n" + "/test/resources/samples/test_config.xml\n" "IgnoreTimestamps = true\n" "Adapters { LinuxCNC { \n" "IgnoreTimestamps = false\n" diff --git a/test/coordinate_system_test.cpp b/test/coordinate_system_test.cpp index 3b9c380a0..aec82b415 100644 --- a/test/coordinate_system_test.cpp +++ b/test/coordinate_system_test.cpp @@ -50,7 +50,7 @@ class CoordinateSystemTest : public testing::Test void SetUp() override { // Create an agent with only 16 slots and 8 data items. m_agentTestHelper = make_unique(); - m_agentTestHelper->createAgent("/samples/configuration.xml", 8, 4, "1.6", 25); + m_agentTestHelper->createAgent("/test/resources/samples/configuration.xml", 8, 4, "1.6", 25); m_agentId = to_string(getCurrentTimeInSec()); m_device = m_agentTestHelper->m_agent->getDeviceByName("LinuxCNC"); } diff --git a/test/cutting_tool_test.cpp b/test/cutting_tool_test.cpp index 85e7afe14..2999209e9 100644 --- a/test/cutting_tool_test.cpp +++ b/test/cutting_tool_test.cpp @@ -60,7 +60,7 @@ class CuttingToolTest : public testing::Test void SetUp() override { // Create an agent with only 16 slots and 8 data items. m_agentTestHelper = make_unique(); - m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "1.7", 25); + m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "1.7", 25); m_agentId = to_string(getCurrentTimeInSec()); m_device = m_agentTestHelper->m_agent->getDeviceByName("LinuxCNC"); diff --git a/test/data_set_test.cpp b/test/data_set_test.cpp index 66b781d63..33a38dce1 100644 --- a/test/data_set_test.cpp +++ b/test/data_set_test.cpp @@ -48,7 +48,7 @@ class DataSetTest : public testing::Test void SetUp() override { // Create an agent with only 16 slots and 8 data items. m_agentTestHelper = make_unique(); - m_agentTestHelper->createAgent("/samples/data_set.xml", 8, 4, "1.5", 25); + m_agentTestHelper->createAgent("/test/resources/samples/data_set.xml", 8, 4, "1.5", 25); m_agentId = to_string(getCurrentTimeInSec()); m_checkpoint = nullptr; diff --git a/test/embedded_ruby_test.cpp b/test/embedded_ruby_test.cpp index 4056960b1..444809234 100644 --- a/test/embedded_ruby_test.cpp +++ b/test/embedded_ruby_test.cpp @@ -117,7 +117,7 @@ namespace { void load(const char *file) { string str("Devices = " PROJECT_ROOT_DIR - "/samples/test_config.xml\n" + "/test/resources/samples/test_config.xml\n" "Ruby {\n" " module = " PROJECT_ROOT_DIR "/test/resources/ruby/" + string(file) + diff --git a/test/image_file_test.cpp b/test/image_file_test.cpp index eca9fa5e8..dd74af885 100644 --- a/test/image_file_test.cpp +++ b/test/image_file_test.cpp @@ -50,7 +50,7 @@ class ImageFileTest : public testing::Test void SetUp() override { // Create an agent with only 16 slots and 8 data items. m_agentTestHelper = make_unique(); - m_agentTestHelper->createAgent("/samples/solid_model.xml", 8, 4, "2.2", 25); + m_agentTestHelper->createAgent("/test/resources/samples/solid_model.xml", 8, 4, "2.2", 25); m_agentId = to_string(getCurrentTimeInSec()); m_device = m_agentTestHelper->m_agent->getDeviceByName("LinuxCNC"); } @@ -141,7 +141,7 @@ TEST_F(ImageFileTest, should_print_configuration_with_image_file_in_json) TEST_F(ImageFileTest, should_print_configuration_with_image_file_in_json_v2) { - m_agentTestHelper->createAgent("/samples/solid_model.xml", 8, 4, "2.2", 25, false, false, + m_agentTestHelper->createAgent("/test/resources/samples/solid_model.xml", 8, 4, "2.2", 25, false, false, {{configuration::JsonVersion, 2}}); { diff --git a/test/json_printer_probe_test.cpp b/test/json_printer_probe_test.cpp index 064c757f8..bc08ddf93 100644 --- a/test/json_printer_probe_test.cpp +++ b/test/json_printer_probe_test.cpp @@ -60,7 +60,7 @@ class JsonPrinterProbeTest : public testing::Test m_printer = std::make_unique(1, true); m_agentTestHelper = make_unique(); - m_agentTestHelper->createAgent("/samples/SimpleDevlce.xml", 8, 4, "1.5", 25); + m_agentTestHelper->createAgent("/test/resources/samples/SimpleDevlce.xml", 8, 4, "1.5", 25); // Asset types are registered in the agent. m_devices = m_agentTestHelper->m_agent->getDevices(); @@ -333,7 +333,7 @@ TEST_F(JsonPrinterProbeTest, PrintDataItemRelationships) auto server = std::make_unique(m_agentTestHelper->m_ioContext); auto cache = std::make_unique(); - m_agentTestHelper->createAgent("/samples/relationship_test.xml", 8, 4, "1.7", 25); + m_agentTestHelper->createAgent("/test/resources/samples/relationship_test.xml", 8, 4, "1.7", 25); auto printer = m_agentTestHelper->m_agent->getPrinter("json"); m_devices = m_agentTestHelper->m_agent->getDevices(); auto doc = printer->printProbe(123, 9999, 1, 1024, 10, m_devices); @@ -376,7 +376,7 @@ TEST_F(JsonPrinterProbeTest, PrintDataItemRelationships) TEST_F(JsonPrinterProbeTest, version_2_with_multiple_devices) { m_printer = std::make_unique(2, true); - m_agentTestHelper->createAgent("/samples/two_devices.xml", 8, 4, "1.5", 25); + m_agentTestHelper->createAgent("/test/resources/samples/two_devices.xml", 8, 4, "1.5", 25); m_devices = m_agentTestHelper->m_agent->getDevices(); auto doc = m_printer->printProbe(123, 9999, 1, 1024, 10, m_devices); diff --git a/test/json_printer_stream_test.cpp b/test/json_printer_stream_test.cpp index ff0db4cc5..3aab035ee 100644 --- a/test/json_printer_stream_test.cpp +++ b/test/json_printer_stream_test.cpp @@ -61,7 +61,7 @@ class JsonPrinterStreamTest : public testing::Test m_printer = std::make_unique(1, true); m_config = std::make_unique(); m_devices = - m_config->parseFile(PROJECT_ROOT_DIR "/samples/SimpleDevlce.xml", m_xmlPrinter.get()); + m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/SimpleDevlce.xml", m_xmlPrinter.get()); } void TearDown() override @@ -193,7 +193,7 @@ TEST_F(JsonPrinterStreamTest, DeviceStream_version_2_one_device) TEST_F(JsonPrinterStreamTest, DeviceStream_version_2_two_devices) { m_printer = std::make_unique(2, true); - m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/samples/min_config2.xml", m_xmlPrinter.get()); + m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/min_config2.xml", m_xmlPrinter.get()); Checkpoint checkpoint; addObservationToCheckpoint(checkpoint, "Sspeed", 10254804, 100_value); diff --git a/test/kinematics_test.cpp b/test/kinematics_test.cpp index 1dd927cb1..d535294bf 100644 --- a/test/kinematics_test.cpp +++ b/test/kinematics_test.cpp @@ -49,7 +49,7 @@ class KinematicsTest : public testing::Test void SetUp() override { // Create an agent with only 16 slots and 8 data items. m_agentTestHelper = make_unique(); - m_agentTestHelper->createAgent("/samples/kinematics.xml", 8, 4, "1.7", 25); + m_agentTestHelper->createAgent("/test/resources/samples/kinematics.xml", 8, 4, "1.7", 25); m_agentId = to_string(getCurrentTimeInSec()); m_device = m_agentTestHelper->m_agent->getDeviceByName("LinuxCNC"); } diff --git a/test/mqtt_sink_test.cpp b/test/mqtt_sink_test.cpp index d98836a02..b1d5a53dc 100644 --- a/test/mqtt_sink_test.cpp +++ b/test/mqtt_sink_test.cpp @@ -84,13 +84,13 @@ class MqttSinkTest : public testing::Test void createAgent(std::string testFile = {}, ConfigOptions options = {}) { if (testFile == "") - testFile = "/samples/test_config.xml"; + testFile = "/test/resources/samples/test_config.xml"; ConfigOptions opts(options); MergeOptions(opts, {{"MqttSink", true}, {configuration::MqttPort, m_port}, {configuration::MqttHost, "127.0.0.1"s}}); - m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "2.0", 25, false, true, opts); + m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "2.0", 25, false, true, opts); addAdapter(); m_agentTestHelper->getAgent()->start(); @@ -372,7 +372,7 @@ TEST_F(MqttSinkTest, mqtt_sink_should_publish_RotaryMode) createClient(options, std::move(handler)); ASSERT_TRUE(startClient()); - createAgent("/samples/discrete_example.xml"); + createAgent("/test/resources/samples/discrete_example.xml"); auto service = m_agentTestHelper->getMqttService(); ASSERT_TRUE(waitFor(1s, [&service]() { return service->isConnected(); })); @@ -408,7 +408,7 @@ TEST_F(MqttSinkTest, mqtt_sink_should_publish_Dataset) }; createClient(options, std::move(handler)); ASSERT_TRUE(startClient()); - createAgent("/samples/data_set.xml"); + createAgent("/test/resources/samples/data_set.xml"); auto service = m_agentTestHelper->getMqttService(); ASSERT_TRUE(waitFor(1s, [&service]() { return service->isConnected(); })); m_agentTestHelper->m_adapter->processData("TIME|vars|a=1 b=2 c=3"); @@ -474,7 +474,7 @@ TEST_F(MqttSinkTest, mqtt_sink_should_publish_Table) }; createClient(options, std::move(handler)); ASSERT_TRUE(startClient()); - createAgent("/samples/data_set.xml"); + createAgent("/test/resources/samples/data_set.xml"); auto service = m_agentTestHelper->getMqttService(); ASSERT_TRUE(waitFor(1s, [&service]() { return service->isConnected(); })); diff --git a/test/mtconnect_xml_transform_test.cpp b/test/mtconnect_xml_transform_test.cpp index dbdc1bc37..1c2370023 100644 --- a/test/mtconnect_xml_transform_test.cpp +++ b/test/mtconnect_xml_transform_test.cpp @@ -72,7 +72,7 @@ class MTConnectXmlTransformTest : public testing::Test auto parser = make_unique(); m_device = - parser->parseFile(PROJECT_ROOT_DIR "/samples/test_config.xml", printer.get()).front(); + parser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/test_config.xml", printer.get()).front(); m_context = make_shared(); m_context->m_contract = make_unique(m_device); diff --git a/test/pipeline_deliver_test.cpp b/test/pipeline_deliver_test.cpp index 4d611663f..2df4ad8ab 100644 --- a/test/pipeline_deliver_test.cpp +++ b/test/pipeline_deliver_test.cpp @@ -52,7 +52,7 @@ class PipelineDeliverTest : public testing::Test void SetUp() override { // Create an agent with only 16 slots and 8 data items. m_agentTestHelper = make_unique(); - m_agentTestHelper->createAgent("/samples/SimpleDevlce.xml", 8, 4, "1.7", 25); + m_agentTestHelper->createAgent("/test/resources/samples/SimpleDevlce.xml", 8, 4, "1.7", 25); m_agentId = to_string(getCurrentTimeInSec()); m_device = m_agentTestHelper->m_agent->getDeviceByName("LinuxCNC"); } diff --git a/test/qif_document_test.cpp b/test/qif_document_test.cpp index 8955bd71a..908ab37b1 100644 --- a/test/qif_document_test.cpp +++ b/test/qif_document_test.cpp @@ -61,7 +61,7 @@ class QIFDocumentTest : public testing::Test void SetUp() override { // Create an agent with only 16 slots and 8 data items. m_agentTestHelper = make_unique(); - m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "2.0", 25); + m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "2.0", 25); m_agentId = to_string(getCurrentTimeInSec()); m_device = m_agentTestHelper->m_agent->getDeviceByName("LinuxCNC"); diff --git a/test/raw_material_test.cpp b/test/raw_material_test.cpp index 558dd262c..9547ada2a 100644 --- a/test/raw_material_test.cpp +++ b/test/raw_material_test.cpp @@ -61,7 +61,7 @@ class RawMaterialTest : public testing::Test void SetUp() override { // Create an agent with only 16 slots and 8 data items. m_agentTestHelper = make_unique(); - m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "2.0", 25); + m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "2.0", 25); m_agentId = to_string(getCurrentTimeInSec()); m_device = m_agentTestHelper->m_agent->getDeviceByName("LinuxCNC"); diff --git a/test/references_test.cpp b/test/references_test.cpp index c87835386..8331eb16d 100644 --- a/test/references_test.cpp +++ b/test/references_test.cpp @@ -51,7 +51,7 @@ class ReferencesTest : public testing::Test void SetUp() override { // Create an agent with only 16 slots and 8 data items. m_agentTestHelper = make_unique(); - m_agentTestHelper->createAgent("/samples/reference_example.xml", 8, 4, "1.6", 25); + m_agentTestHelper->createAgent("/test/resources/samples/reference_example.xml", 8, 4, "1.6", 25); m_agentId = to_string(getCurrentTimeInSec()); m_device = m_agentTestHelper->m_agent->getDeviceByName("LinuxCNC"); m_component = m_device->getComponentById("bf"); diff --git a/test/relationship_test.cpp b/test/relationship_test.cpp index c4feb60a6..e7d8086eb 100644 --- a/test/relationship_test.cpp +++ b/test/relationship_test.cpp @@ -52,7 +52,7 @@ class RelationshipTest : public testing::Test void SetUp() override { // Create an agent with only 16 slots and 8 data items. m_agentTestHelper = make_unique(); - m_agentTestHelper->createAgent("/samples/configuration.xml", 8, 4, "1.7", 25); + m_agentTestHelper->createAgent("/test/resources/samples/configuration.xml", 8, 4, "1.7", 25); m_agentId = to_string(getCurrentTimeInSec()); auto device = m_agentTestHelper->m_agent->getDeviceByName("LinuxCNC"); diff --git a/samples/128.32.164.245.xml b/test/resources/samples/128.32.164.245.xml similarity index 100% rename from samples/128.32.164.245.xml rename to test/resources/samples/128.32.164.245.xml diff --git a/samples/NoNamespace.xml b/test/resources/samples/NoNamespace.xml similarity index 100% rename from samples/NoNamespace.xml rename to test/resources/samples/NoNamespace.xml diff --git a/samples/SimpleDevlce.xml b/test/resources/samples/SimpleDevlce.xml similarity index 100% rename from samples/SimpleDevlce.xml rename to test/resources/samples/SimpleDevlce.xml diff --git a/samples/agent.mtconnect.org.xml b/test/resources/samples/agent.mtconnect.org.xml similarity index 100% rename from samples/agent.mtconnect.org.xml rename to test/resources/samples/agent.mtconnect.org.xml diff --git a/samples/configuration.xml b/test/resources/samples/configuration.xml similarity index 100% rename from samples/configuration.xml rename to test/resources/samples/configuration.xml diff --git a/samples/configuration1.6.xml b/test/resources/samples/configuration1.6.xml similarity index 100% rename from samples/configuration1.6.xml rename to test/resources/samples/configuration1.6.xml diff --git a/samples/data_set.cfg b/test/resources/samples/data_set.cfg similarity index 100% rename from samples/data_set.cfg rename to test/resources/samples/data_set.cfg diff --git a/samples/data_set.xml b/test/resources/samples/data_set.xml similarity index 100% rename from samples/data_set.xml rename to test/resources/samples/data_set.xml diff --git a/samples/data_set_variable.xml b/test/resources/samples/data_set_variable.xml similarity index 100% rename from samples/data_set_variable.xml rename to test/resources/samples/data_set_variable.xml diff --git a/samples/discrete_example.xml b/test/resources/samples/discrete_example.xml similarity index 100% rename from samples/discrete_example.xml rename to test/resources/samples/discrete_example.xml diff --git a/samples/dyn_load.xml b/test/resources/samples/dyn_load.xml similarity index 100% rename from samples/dyn_load.xml rename to test/resources/samples/dyn_load.xml diff --git a/samples/empty.xml b/test/resources/samples/empty.xml similarity index 100% rename from samples/empty.xml rename to test/resources/samples/empty.xml diff --git a/samples/extension.xml b/test/resources/samples/extension.xml similarity index 100% rename from samples/extension.xml rename to test/resources/samples/extension.xml diff --git a/samples/fanuc.xml b/test/resources/samples/fanuc.xml similarity index 100% rename from samples/fanuc.xml rename to test/resources/samples/fanuc.xml diff --git a/samples/filter_example.xml b/test/resources/samples/filter_example.xml similarity index 100% rename from samples/filter_example.xml rename to test/resources/samples/filter_example.xml diff --git a/samples/filter_example_1.3.xml b/test/resources/samples/filter_example_1.3.xml similarity index 100% rename from samples/filter_example_1.3.xml rename to test/resources/samples/filter_example_1.3.xml diff --git a/samples/haas.xml b/test/resources/samples/haas.xml similarity index 100% rename from samples/haas.xml rename to test/resources/samples/haas.xml diff --git a/samples/kinematics.xml b/test/resources/samples/kinematics.xml similarity index 100% rename from samples/kinematics.xml rename to test/resources/samples/kinematics.xml diff --git a/samples/min_config.xml b/test/resources/samples/min_config.xml similarity index 100% rename from samples/min_config.xml rename to test/resources/samples/min_config.xml diff --git a/samples/min_config2.xml b/test/resources/samples/min_config2.xml similarity index 100% rename from samples/min_config2.xml rename to test/resources/samples/min_config2.xml diff --git a/samples/reference_example.xml b/test/resources/samples/reference_example.xml similarity index 100% rename from samples/reference_example.xml rename to test/resources/samples/reference_example.xml diff --git a/samples/relationship_test.xml b/test/resources/samples/relationship_test.xml similarity index 100% rename from samples/relationship_test.xml rename to test/resources/samples/relationship_test.xml diff --git a/samples/solid_model.xml b/test/resources/samples/solid_model.xml similarity index 100% rename from samples/solid_model.xml rename to test/resources/samples/solid_model.xml diff --git a/samples/test_config.xml b/test/resources/samples/test_config.xml similarity index 100% rename from samples/test_config.xml rename to test/resources/samples/test_config.xml diff --git a/samples/two_devices.xml b/test/resources/samples/two_devices.xml similarity index 100% rename from samples/two_devices.xml rename to test/resources/samples/two_devices.xml diff --git a/test/response_document_test.cpp b/test/response_document_test.cpp index 9926cd0ab..235b9ac8e 100644 --- a/test/response_document_test.cpp +++ b/test/response_document_test.cpp @@ -75,7 +75,7 @@ class ResponseDocumentTest : public testing::Test m_doc.emplace(); - m_device = parser->parseFile(PROJECT_ROOT_DIR "/samples/data_set.xml", printer.get()).front(); + m_device = parser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/data_set.xml", printer.get()).front(); m_context = make_shared(); m_context->m_contract = make_unique(m_device); diff --git a/test/sensor_configuration_test.cpp b/test/sensor_configuration_test.cpp index 1d94d46ab..b3c254028 100644 --- a/test/sensor_configuration_test.cpp +++ b/test/sensor_configuration_test.cpp @@ -50,7 +50,7 @@ class SensorConfigurationTest : public testing::Test void SetUp() override { // Create an agent with only 16 slots and 8 data items. m_agentTestHelper = make_unique(); - m_agentTestHelper->createAgent("/samples/configuration.xml", 8, 4, "1.6", 25); + m_agentTestHelper->createAgent("/test/resources/samples/configuration.xml", 8, 4, "1.6", 25); m_agentId = to_string(getCurrentTimeInSec()); m_device = m_agentTestHelper->m_agent->getDeviceByName("LinuxCNC"); } diff --git a/test/solid_model_test.cpp b/test/solid_model_test.cpp index 169eea1ef..3d9561dc8 100644 --- a/test/solid_model_test.cpp +++ b/test/solid_model_test.cpp @@ -50,7 +50,7 @@ class SolidModelTest : public testing::Test void SetUp() override { // Create an agent with only 16 slots and 8 data items. m_agentTestHelper = make_unique(); - m_agentTestHelper->createAgent("/samples/solid_model.xml", 8, 4, "1.7", 25); + m_agentTestHelper->createAgent("/test/resources/samples/solid_model.xml", 8, 4, "1.7", 25); m_agentId = to_string(getCurrentTimeInSec()); m_device = m_agentTestHelper->m_agent->getDeviceByName("LinuxCNC"); } diff --git a/test/specification_test.cpp b/test/specification_test.cpp index dff297813..4234b324d 100644 --- a/test/specification_test.cpp +++ b/test/specification_test.cpp @@ -51,7 +51,7 @@ class SpecificationTest : public testing::Test void SetUp() override { // Create an agent with only 16 slots and 8 data items. m_agentTestHelper = make_unique(); - m_agentTestHelper->createAgent("/samples/configuration.xml", 8, 4, "1.7", 25); + m_agentTestHelper->createAgent("/test/resources/samples/configuration.xml", 8, 4, "1.7", 25); auto device = m_agentTestHelper->m_agent->getDeviceByName("LinuxCNC"); m_component = device->getComponentById("c"); } @@ -98,7 +98,7 @@ TEST_F(SpecificationTest, ParseDeviceAndComponentRelationships) TEST_F(SpecificationTest, test_1_6_specification_without_id) { m_agentTestHelper = make_unique(); - m_agentTestHelper->createAgent("/samples/configuration1.6.xml", 8, 4, "1.6", 25); + m_agentTestHelper->createAgent("/test/resources/samples/configuration1.6.xml", 8, 4, "1.6", 25); auto device = m_agentTestHelper->m_agent->getDeviceByName("LinuxCNC"); m_component = device->getComponentById("power"); diff --git a/test/table_test.cpp b/test/table_test.cpp index 8da67faa2..14ba3db08 100644 --- a/test/table_test.cpp +++ b/test/table_test.cpp @@ -56,7 +56,7 @@ class TableTest : public testing::Test void SetUp() override { // Create an agent with only 16 slots and 8 data items. m_agentTestHelper = make_unique(); - m_agentTestHelper->createAgent("/samples/data_set.xml", 8, 4, "1.6", 25); + m_agentTestHelper->createAgent("/test/resources/samples/data_set.xml", 8, 4, "1.6", 25); m_agentId = to_string(getCurrentTimeInSec()); m_checkpoint = nullptr; diff --git a/test/xml_parser_test.cpp b/test/xml_parser_test.cpp index 7ce318b93..936f90bd3 100644 --- a/test/xml_parser_test.cpp +++ b/test/xml_parser_test.cpp @@ -54,11 +54,11 @@ class XmlParserTest : public testing::Test std::unique_ptr printer(new printer::XmlPrinter()); m_xmlParser = new parser::XmlParser(); m_devices = - m_xmlParser->parseFile(PROJECT_ROOT_DIR "/samples/test_config.xml", printer.get()); + m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/test_config.xml", printer.get()); } catch (exception &) { - FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR << " /samples/test_config.xml"; + FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR << " /test/resources/samples/test_config.xml"; } } @@ -85,13 +85,13 @@ TEST_F(XmlParserTest, Constructor) std::unique_ptr printer(new printer::XmlPrinter()); m_xmlParser = new parser::XmlParser(); - ASSERT_THROW(m_xmlParser->parseFile(PROJECT_ROOT_DIR "/samples/badPath.xml", printer.get()), + ASSERT_THROW(m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/badPath.xml", printer.get()), std::runtime_error); delete m_xmlParser; m_xmlParser = nullptr; m_xmlParser = new parser::XmlParser(); ASSERT_NO_THROW( - m_xmlParser->parseFile(PROJECT_ROOT_DIR "/samples/test_config.xml", printer.get())); + m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/test_config.xml", printer.get())); } TEST_F(XmlParserTest, GetDevices) @@ -187,11 +187,11 @@ TEST_F(XmlParserTest, GetDataItemsExt) { std::unique_ptr printer(new printer::XmlPrinter()); m_xmlParser = new parser::XmlParser(); - m_xmlParser->parseFile(PROJECT_ROOT_DIR "/samples/extension.xml", printer.get()); + m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/extension.xml", printer.get()); } catch (exception &) { - FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR << "/samples/extension.xml"; + FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR << "/test/resources/samples/extension.xml"; } filter.clear(); @@ -215,11 +215,11 @@ TEST_F(XmlParserTest, ExtendedSchema) { std::unique_ptr printer(new printer::XmlPrinter()); m_xmlParser = new parser::XmlParser(); - m_devices = m_xmlParser->parseFile(PROJECT_ROOT_DIR "/samples/extension.xml", printer.get()); + m_devices = m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/extension.xml", printer.get()); } catch (exception &) { - FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR << "/samples/extension.xml"; + FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR << "/test/resources/samples/extension.xml"; } ASSERT_EQ((size_t)1, m_devices.size()); @@ -288,7 +288,7 @@ TEST_F(XmlParserTest, NoNamespace) unique_ptr printer(new printer::XmlPrinter()); m_xmlParser = new parser::XmlParser(); ASSERT_NO_THROW( - m_xmlParser->parseFile(PROJECT_ROOT_DIR "/samples/NoNamespace.xml", printer.get())); + m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/NoNamespace.xml", printer.get())); } TEST_F(XmlParserTest, FilteredDataItem13) @@ -300,12 +300,12 @@ TEST_F(XmlParserTest, FilteredDataItem13) unique_ptr printer(new printer::XmlPrinter()); m_xmlParser = new parser::XmlParser(); m_devices = - m_xmlParser->parseFile(PROJECT_ROOT_DIR "/samples/filter_example_1.3.xml", printer.get()); + m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/filter_example_1.3.xml", printer.get()); } catch (exception &) { FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR - << "/samples/filter_example_1.3.xml"; + << "/test/resources/samples/filter_example_1.3.xml"; } DevicePtr dev = m_devices.front(); @@ -328,11 +328,11 @@ TEST_F(XmlParserTest, FilteredDataItem) unique_ptr printer(new printer::XmlPrinter()); m_xmlParser = new parser::XmlParser(); m_devices = - m_xmlParser->parseFile(PROJECT_ROOT_DIR "/samples/filter_example.xml", printer.get()); + m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/filter_example.xml", printer.get()); } catch (exception &) { - FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR << "/samples/filter_example.xml"; + FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR << "/test/resources/samples/filter_example.xml"; } auto di = m_devices.front()->getDeviceDataItem("c1"); @@ -360,11 +360,11 @@ TEST_F(XmlParserTest, References) unique_ptr printer(new printer::XmlPrinter()); m_xmlParser = new parser::XmlParser(); m_devices = - m_xmlParser->parseFile(PROJECT_ROOT_DIR "/samples/reference_example.xml", printer.get()); + m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/reference_example.xml", printer.get()); } catch (exception &) { - FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR << "/samples/reference_example.xml"; + FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR << "/test/resources/samples/reference_example.xml"; } string id = "mf"; @@ -422,11 +422,11 @@ TEST_F(XmlParserTest, SourceReferences) unique_ptr printer(new printer::XmlPrinter()); m_xmlParser = new parser::XmlParser(); m_devices = - m_xmlParser->parseFile(PROJECT_ROOT_DIR "/samples/reference_example.xml", printer.get()); + m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/reference_example.xml", printer.get()); } catch (exception &) { - FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR << "/samples/reference_example.xml"; + FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR << "/test/resources/samples/reference_example.xml"; } const auto item = m_devices.front()->getDeviceDataItem("bfc"); @@ -451,7 +451,7 @@ TEST_F(XmlParserTest, DataItemRelationships) unique_ptr printer(new printer::XmlPrinter()); m_xmlParser = new parser::XmlParser(); m_devices = - m_xmlParser->parseFile(PROJECT_ROOT_DIR "/samples/relationship_test.xml", printer.get()); + m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/relationship_test.xml", printer.get()); const auto &device = m_devices.front(); const auto &dataItemsMap = device->getDeviceDataItems(); diff --git a/test/xml_printer_test.cpp b/test/xml_printer_test.cpp index a929b2f1d..a9b2ca605 100644 --- a/test/xml_printer_test.cpp +++ b/test/xml_printer_test.cpp @@ -57,7 +57,7 @@ class XmlPrinterTest : public testing::Test m_config = new XmlParser(); m_printer = new printer::XmlPrinter(true); m_printer->setSchemaVersion("1.2"); - m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/samples/test_config.xml", m_printer); + m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/test_config.xml", m_printer); } void TearDown() override @@ -271,7 +271,7 @@ TEST_F(XmlPrinterTest, ChangeDevicesNamespace) { XmlParser ext; std::list extdevs = - ext.parseFile(PROJECT_ROOT_DIR "/samples/extension.xml", m_printer); + ext.parseFile(PROJECT_ROOT_DIR "/test/resources/samples/extension.xml", m_printer); PARSE_XML(m_printer->printProbe(123, 9999, 1024, 10, 1, extdevs)); ASSERT_XML_PATH_EQUAL(doc, "/m:MTConnectDevices@schemaLocation", @@ -324,7 +324,7 @@ TEST_F(XmlPrinterTest, ChangeStreamsNamespace) { XmlParser ext; - m_devices = ext.parseFile(PROJECT_ROOT_DIR "/samples/extension.xml", m_printer); + m_devices = ext.parseFile(PROJECT_ROOT_DIR "/test/resources/samples/extension.xml", m_printer); m_printer->addStreamsNamespace("urn:example.com:ExampleDevices:1.3", "ExtensionDevices_1.3.xsd", "x"); @@ -344,7 +344,7 @@ TEST_F(XmlPrinterTest, ChangeStreamsNamespace) { XmlParser ext; - m_devices = ext.parseFile(PROJECT_ROOT_DIR "/samples/extension.xml", m_printer); + m_devices = ext.parseFile(PROJECT_ROOT_DIR "/test/resources/samples/extension.xml", m_printer); m_printer->addStreamsNamespace("urn:example.com:ExampleDevices:1.3", "ExtensionDevices_1.3.xsd", "x"); @@ -713,7 +713,7 @@ TEST_F(XmlPrinterTest, ProbeWithFilter13) delete m_config; m_config = new XmlParser(); - m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/samples/filter_example_1.3.xml", m_printer); + m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/filter_example_1.3.xml", m_printer); PARSE_XML(m_printer->printProbe(123, 9999, 1024, 10, 1, m_devices)); @@ -729,7 +729,7 @@ TEST_F(XmlPrinterTest, ProbeWithFilter) m_config = nullptr; m_config = new XmlParser(); - m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/samples/filter_example.xml", m_printer); + m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/filter_example.xml", m_printer); PARSE_XML(m_printer->printProbe(123, 9999, 1024, 10, 1, m_devices)); @@ -746,7 +746,7 @@ TEST_F(XmlPrinterTest, References) m_config = nullptr; m_config = new XmlParser(); - m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/samples/reference_example.xml", m_printer); + m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/reference_example.xml", m_printer); PARSE_XML(m_printer->printProbe(123, 9999, 1024, 10, 1, m_devices)); @@ -762,7 +762,7 @@ TEST_F(XmlPrinterTest, LegacyReferences) m_config = nullptr; m_config = new XmlParser(); - m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/samples/reference_example.xml", m_printer); + m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/reference_example.xml", m_printer); PARSE_XML(m_printer->printProbe(123, 9999, 1024, 10, 1, m_devices)); @@ -775,7 +775,7 @@ TEST_F(XmlPrinterTest, CheckDeviceChangeTime) { m_printer = new XmlPrinter(true); m_printer->setSchemaVersion("1.7"); - m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/samples/test_config.xml", m_printer); + m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/test_config.xml", m_printer); m_printer->setModelChangeTime(getCurrentTime(GMT_UV_SEC)); ASSERT_FALSE(m_printer->getModelChangeTime().empty()); @@ -796,7 +796,7 @@ TEST_F(XmlPrinterTest, SourceReferences) m_config = nullptr; m_config = new XmlParser(); - m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/samples/reference_example.xml", m_printer); + m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/reference_example.xml", m_printer); PARSE_XML(m_printer->printProbe(123, 9999, 1024, 10, 1, m_devices)); @@ -867,7 +867,7 @@ TEST_F(XmlPrinterTest, PrintDataItemRelationships) m_config = nullptr; m_config = new XmlParser(); - m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/samples/relationship_test.xml", m_printer); + m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/relationship_test.xml", m_printer); PARSE_XML(m_printer->printProbe(123, 9999, 1024, 10, 1, m_devices)); From 1bfdcd8fb516e9f1b0cadceb0b4c3eddf62123b0 Mon Sep 17 00:00:00 2001 From: Will Sobel Date: Wed, 12 Jul 2023 18:02:53 -0700 Subject: [PATCH 2/3] Added unit conversion check for CUBIC_FOOT/MINUTE to CUBIC_MILLIMETER/SECOND --- test/unit_conversion_test.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/unit_conversion_test.cpp b/test/unit_conversion_test.cpp index 970778cab..b73223e3b 100644 --- a/test/unit_conversion_test.cpp +++ b/test/unit_conversion_test.cpp @@ -98,3 +98,10 @@ TEST(UnitConversionTest, check_revolution_per_second) auto conv = UnitConversion::make("REVOLUTION/SECOND", "REVOLUTION/MINUTE"); EXPECT_NEAR(420.0, conv->convert(7.0), 0.0001); } + + +TEST(UnitConversionTest, check_cubic_feet_per_minute) +{ + auto conv = UnitConversion::make("CUBIC_FOOT/MINUTE", "CUBIC_MILLIMETER/SECOND"); + EXPECT_NEAR(3303632.15, conv->convert(7.0), 0.1); +} From 3c339d44fb157e2d02afba9b9a2344cefcdc6c62 Mon Sep 17 00:00:00 2001 From: Will Sobel Date: Mon, 17 Jul 2023 17:23:26 -0700 Subject: [PATCH 3/3] Working multi-version agent adapter with dynamic initialization of Device configuration from source. --- README.md | 4 ++ appveyor.yml | 6 +- demo/agent/Devices.xml | 19 ++++++ src/mtconnect/agent.cpp | 5 +- src/mtconnect/agent.hpp | 7 +-- src/mtconnect/configuration/agent_config.cpp | 9 ++- .../configuration/config_options.hpp | 2 +- src/mtconnect/configuration/parser.cpp | 2 +- src/mtconnect/device_model/component.cpp | 2 +- src/mtconnect/device_model/component.hpp | 37 ++++++------ src/mtconnect/entity/data_set.cpp | 2 +- src/mtconnect/pipeline/deliver.hpp | 4 +- .../pipeline/mtconnect_xml_transform.hpp | 9 ++- src/mtconnect/pipeline/response_document.cpp | 52 ++++++++++++++--- src/mtconnect/pipeline/response_document.hpp | 4 +- .../source/adapter/adapter_pipeline.cpp | 2 +- .../adapter/agent_adapter/agent_adapter.cpp | 26 +++++---- .../adapter/agent_adapter/agent_adapter.hpp | 3 + .../source/adapter/agent_adapter/session.hpp | 12 ++-- .../adapter/agent_adapter/session_impl.hpp | 27 ++++++--- .../source/adapter/shdr/shdr_adapter.cpp | 2 +- src/mtconnect/utilities.hpp | 2 +- test/agent_adapter_test.cpp | 18 +++--- test/agent_test.cpp | 40 ++++++++----- test/config_test.cpp | 10 ++-- test/image_file_test.cpp | 4 +- test/json_printer_stream_test.cpp | 7 ++- test/mtconnect_xml_transform_test.cpp | 3 +- test/references_test.cpp | 4 +- test/response_document_test.cpp | 4 +- test/unit_conversion_test.cpp | 1 - test/xml_parser_test.cpp | 58 +++++++++++-------- test/xml_printer_test.cpp | 24 +++++--- 33 files changed, 269 insertions(+), 142 deletions(-) diff --git a/README.md b/README.md index fdd942577..00a0558db 100644 --- a/README.md +++ b/README.md @@ -689,6 +689,10 @@ Configuration Parameters *Default*: 1 +* `EnableSourceDeviceModels` - + + *Default*: false + #### Configuration Pameters for TLS (https) Support #### The following parameters must be present to enable https requests. If there is no password on the certificate, `TlsCertificatePassword` may be omitted. diff --git a/appveyor.yml b/appveyor.yml index 465cdddab..b95bf1b68 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -23,8 +23,7 @@ configuration: #C:\ - x86 cache: - - c:\.conan2\ -> **\conanfile.py - - c:\conan2\ -> **\conanfile.py + - C:\Users\appveyor\.conan2 -> **\conanfile.py - /home/appveyor/.conan2 -> **/conanfile.py - /Users/appveyor/.conan2 -> **/conanfile.py @@ -43,10 +42,7 @@ before_build: - cmd: |- set PATH=C:\Python39-x64\;C:\Python39-x64\Scripts;C:\Ruby30\bin;%PATH% "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" - if not exist C:\conan mkdir C:\conan if %SHARED%==True (set CONAN_PROFILE=conan/profiles/vs64shared) else (set CONAN_PROFILE=conan/profiles/vs64) - set CONAN_USER_HOME=C:\conan - rem set CPACK=True pip install conan conan profile detect -f diff --git a/demo/agent/Devices.xml b/demo/agent/Devices.xml index d90d17aff..f3fff6ef1 100644 --- a/demo/agent/Devices.xml +++ b/demo/agent/Devices.xml @@ -897,9 +897,28 @@ 7000 1 + + + + + + + + + + + + + + + + + + + diff --git a/src/mtconnect/agent.cpp b/src/mtconnect/agent.cpp index 1f548ed9b..f5c81bab4 100644 --- a/src/mtconnect/agent.cpp +++ b/src/mtconnect/agent.cpp @@ -388,7 +388,7 @@ namespace mtconnect { throw f; } } - + void Agent::loadDeviceXml(const string &deviceXml, const optional source) { try @@ -440,7 +440,8 @@ namespace mtconnect { } else { - LOG(error) << "Cannot parse device xml: " << deviceXml; + LOG(error) << "Cannot parse device xml: " << *device->getComponentName() << " with uuid " + << *device->getUuid(); } } catch (runtime_error &e) diff --git a/src/mtconnect/agent.hpp b/src/mtconnect/agent.hpp index 28ef642be..1a02cd2ed 100644 --- a/src/mtconnect/agent.hpp +++ b/src/mtconnect/agent.hpp @@ -274,14 +274,13 @@ namespace mtconnect { /// @brief receive a single device from a source /// @param[in] deviceXml the device xml as a string /// @param[in] source the source loading the device - void loadDevice(DevicePtr device, - const std::optional source = std::nullopt); - + void loadDevice(DevicePtr device, const std::optional source = std::nullopt); + /// @brief receive and parse a single device from a source /// @param[in] deviceXml the device xml as a string /// @param[in] source the source loading the device void loadDeviceXml(const std::string &deviceXml, - const std::optional source = std::nullopt); + const std::optional source = std::nullopt); /// @name Message when source has connected and disconnected ///@{ diff --git a/src/mtconnect/configuration/agent_config.cpp b/src/mtconnect/configuration/agent_config.cpp index 39fcca9a3..d8c74bac2 100644 --- a/src/mtconnect/configuration/agent_config.cpp +++ b/src/mtconnect/configuration/agent_config.cpp @@ -808,7 +808,14 @@ namespace mtconnect::configuration { GetOptions(block.second, adapterOptions, options); AddOptions(block.second, adapterOptions, - {{configuration::Url, string()}, {configuration::Device, string()}}); + {{configuration::Url, string()}, + {configuration::Device, string()}, + {configuration::UUID, string()}, + {configuration::Uuid, string()}}); + + if (HasOption(adapterOptions, configuration::Uuid) && + !HasOption(adapterOptions, configuration::UUID)) + adapterOptions[configuration::UUID] = adapterOptions[configuration::Uuid]; auto qname = entity::QName(block.first); auto [factory, name] = qname.getPair(); diff --git a/src/mtconnect/configuration/config_options.hpp b/src/mtconnect/configuration/config_options.hpp index c65bc5097..1a4cb9b27 100644 --- a/src/mtconnect/configuration/config_options.hpp +++ b/src/mtconnect/configuration/config_options.hpp @@ -119,10 +119,10 @@ namespace mtconnect { DECLARE_CONFIGURATION(SuppressIPAddress); DECLARE_CONFIGURATION(Topics); DECLARE_CONFIGURATION(UUID); + DECLARE_CONFIGURATION(Uuid); DECLARE_CONFIGURATION(UpcaseDataItemValue); DECLARE_CONFIGURATION(Url); DECLARE_CONFIGURATION(UsePolling); - DECLARE_CONFIGURATION(UpdateDeviceXml); ///@} } // namespace configuration diff --git a/src/mtconnect/configuration/parser.cpp b/src/mtconnect/configuration/parser.cpp index 451a7cba1..f79cc1b65 100644 --- a/src/mtconnect/configuration/parser.cpp +++ b/src/mtconnect/configuration/parser.cpp @@ -22,7 +22,7 @@ #include "mtconnect/utilities.hpp" -//#define BOOST_SPIRIT_DEBUG 1 +// #define BOOST_SPIRIT_DEBUG 1 #ifdef BOOST_SPIRIT_DEBUG namespace std { static ostream &operator<<(ostream &s, const boost::property_tree::ptree &t); diff --git a/src/mtconnect/device_model/component.cpp b/src/mtconnect/device_model/component.cpp index 1c9b6a139..5d9e2523b 100644 --- a/src/mtconnect/device_model/component.cpp +++ b/src/mtconnect/device_model/component.cpp @@ -40,7 +40,7 @@ namespace mtconnect { : Entity(name, props) { m_id = get("id"); - m_name = maybeGet("name"); + m_componentName = maybeGet("name"); m_uuid = maybeGet("uuid"); } diff --git a/src/mtconnect/device_model/component.hpp b/src/mtconnect/device_model/component.hpp index a554e4c38..ca0c09d42 100644 --- a/src/mtconnect/device_model/component.hpp +++ b/src/mtconnect/device_model/component.hpp @@ -81,7 +81,7 @@ namespace mtconnect { const auto &getId() const { return m_id; } /// @brief get the name property of the component /// @return name if it exists - const auto &getComponentName() const { return m_name; } + const auto &getComponentName() const { return m_componentName; } /// @brief get the component uuid /// @return uuid if it exists const auto &getUuid() const { return m_uuid; } @@ -94,9 +94,9 @@ namespace mtconnect { { auto *self = const_cast(this); self->m_topicName.emplace(getName()); - if (m_name) + if (m_componentName) { - self->m_topicName->append("[").append(*m_name).append("]"); + self->m_topicName->append("[").append(*m_componentName).append("]"); } } return *m_topicName; @@ -161,9 +161,19 @@ namespace mtconnect { /// @param name name property void setComponentName(const std::string &name) { - m_name = name; + m_componentName = name; setProperty("name", name); } + /// @brief set the compoent name property, not the compoent type + /// @param name name property + void setComponentName(const std::optional &name) + { + m_componentName = name; + if (name) + setProperty("name", *name); + else + m_properties.erase("name"); + } /// @brief get the device (top level component) /// @return shared pointer to the device @@ -272,22 +282,15 @@ namespace mtconnect { void setDevice(DevicePtr device) { m_device = device; } protected: - // Unique ID for each component - std::string m_id; - - // Name for itself - std::optional m_name; - - // Universal unique identifier - std::optional m_uuid; + std::string m_id; //< Unique ID for each component + std::optional m_componentName; //< Name property for the component + std::optional m_uuid; //< Universal unique identifier // Component relationships - // Pointer to the parent component - std::weak_ptr m_parent; - std::weak_ptr m_device; - // Topic - std::optional m_topicName; + std::weak_ptr m_parent; //< Pointer to the parent component + std::weak_ptr m_device; //< Pointer to the device related to the component + std::optional m_topicName; //< The cached topic name }; /// @brief Comparison lambda to sort components diff --git a/src/mtconnect/entity/data_set.cpp b/src/mtconnect/entity/data_set.cpp index 1ca2779e4..598d5b811 100644 --- a/src/mtconnect/entity/data_set.cpp +++ b/src/mtconnect/entity/data_set.cpp @@ -19,7 +19,7 @@ #include "mtconnect/utilities.hpp" -//#define BOOST_SPIRIT_DEBUG 1 +// #define BOOST_SPIRIT_DEBUG 1 #include diff --git a/src/mtconnect/pipeline/deliver.hpp b/src/mtconnect/pipeline/deliver.hpp index f4da6af3d..ac23e4c84 100644 --- a/src/mtconnect/pipeline/deliver.hpp +++ b/src/mtconnect/pipeline/deliver.hpp @@ -21,9 +21,9 @@ #include -#include "mtconnect/device_model/device.hpp" #include "mtconnect/asset/asset.hpp" #include "mtconnect/config.hpp" +#include "mtconnect/device_model/device.hpp" #include "mtconnect/observation/observation.hpp" #include "transform.hpp" @@ -165,7 +165,7 @@ namespace mtconnect::pipeline { m_guard = TypeGuard(RUN); } entity::EntityPtr operator()(entity::EntityPtr &&entity) override; - + protected: PipelineContract *m_contract; }; diff --git a/src/mtconnect/pipeline/mtconnect_xml_transform.hpp b/src/mtconnect/pipeline/mtconnect_xml_transform.hpp index 5cf7d55b7..8a14ef095 100644 --- a/src/mtconnect/pipeline/mtconnect_xml_transform.hpp +++ b/src/mtconnect/pipeline/mtconnect_xml_transform.hpp @@ -31,6 +31,7 @@ namespace mtconnect::pipeline { struct XmlTransformFeedback { uint64_t m_instanceId = 0; + int32_t m_agentVersion = 0; SequenceNumber_t m_next = 0; entity::EntityList m_assetEvents; ResponseDocument::Errors m_errors; @@ -49,10 +50,12 @@ namespace mtconnect::pipeline { /// @param feedback a feedback object to pass back protocol info /// @param device an associated device MTConnectXmlTransform(PipelineContextPtr context, XmlTransformFeedback &feedback, - const std::optional &device = std::nullopt) + const std::optional &device = std::nullopt, + const std::optional &uuid = std::nullopt) : Transform("MTConnectXmlTransform"), m_context(context), m_defaultDevice(device), + m_uuid(uuid), m_feedback(feedback) { m_guard = EntityNameGuard("Data", RUN); @@ -66,7 +69,7 @@ namespace mtconnect::pipeline { const auto &data = entity->getValue(); ResponseDocument rd; - ResponseDocument::parse(data, rd, m_context, m_defaultDevice); + ResponseDocument::parse(data, rd, m_context, m_defaultDevice, m_uuid); if (m_feedback.m_instanceId != 0 && m_feedback.m_instanceId != rd.m_instanceId) { @@ -79,6 +82,7 @@ namespace mtconnect::pipeline { } m_feedback.m_instanceId = rd.m_instanceId; + m_feedback.m_agentVersion = rd.m_agentVersion; m_feedback.m_next = rd.m_next; m_feedback.m_assetEvents = rd.m_assetEvents; m_feedback.m_errors = rd.m_errors; @@ -99,6 +103,7 @@ namespace mtconnect::pipeline { protected: PipelineContextPtr m_context; std::optional m_defaultDevice; + std::optional m_uuid; XmlTransformFeedback &m_feedback; }; } // namespace mtconnect::pipeline diff --git a/src/mtconnect/pipeline/response_document.cpp b/src/mtconnect/pipeline/response_document.cpp index 5d22b1baa..2a146d936 100644 --- a/src/mtconnect/pipeline/response_document.cpp +++ b/src/mtconnect/pipeline/response_document.cpp @@ -147,20 +147,32 @@ namespace mtconnect::pipeline { return ""; } - + inline static bool parseDevices(ResponseDocument &out, xmlNodePtr node, pipeline::PipelineContextPtr context, - const std::optional &device) + const std::optional &device, + const std::optional &uuid) { using namespace entity; using namespace device_model; + auto header = findChild(node, "Header"); + if (header) + { + out.m_instanceId = + boost::lexical_cast(attributeValue(header, "instanceId")); + out.m_agentVersion = IntSchemaVersion(attributeValue(header, "version")); + } + auto devices = findChild(node, "Devices"); if (devices == nullptr) + { + LOG(warning) << "Cannot find Devices node in MTConnectDevices Document"; return false; + } entity::XmlParser parser; - eachElement(devices, [&out, &parser, &device](xmlNodePtr n) { + eachElement(devices, [&out, &parser, &device, &uuid](xmlNodePtr n) { ErrorList errors; auto dev = parser.parseXmlNode(Device::getRoot(), n, errors); if (!errors.empty()) @@ -171,9 +183,31 @@ namespace mtconnect::pipeline { LOG(warning) << " Message: " << e->what(); } } - - if (dev && (!device || *device == dev->get("name"))) - out.m_entities.emplace_back(dev); + + auto devicePtr = dynamic_pointer_cast(dev); + if (!devicePtr) + { + LOG(error) << "Device could not be parsed from XML"; + return false; + } + + if (device && *device != *(devicePtr->getComponentName())) + { + LOG(warning) << "Source and Target Device Name mismatch: " << *device << " and " + << *(devicePtr->getComponentName()); + LOG(warning) << "Setting device name to " << *device; + + devicePtr->setComponentName(*device); + } + if (uuid && *uuid != *(devicePtr->getUuid())) + { + LOG(warning) << "Source and Target Device uuid mismatch: " << *uuid << " and " + << *(devicePtr->getUuid()); + LOG(warning) << "Setting device uuid to " << *uuid; + devicePtr->setUuid(*uuid); + } + + out.m_entities.emplace_back(dev); return true; }); @@ -181,7 +215,6 @@ namespace mtconnect::pipeline { return true; } - inline DataSetValue type(const string &s) { using namespace boost; @@ -468,7 +501,8 @@ namespace mtconnect::pipeline { bool ResponseDocument::parse(const std::string_view &content, ResponseDocument &out, pipeline::PipelineContextPtr context, - const std::optional &device) + const std::optional &device, + const std::optional &uuid) { // xmlInitParser(); // xmlXPathInit(); @@ -490,7 +524,7 @@ namespace mtconnect::pipeline { } else if (xmlStrcmp(BAD_CAST "MTConnectDevices", root->name) == 0) { - return parseDevices(out, root, context, device); + return parseDevices(out, root, context, device, uuid); } else if (xmlStrcmp(BAD_CAST "MTConnectAssets", root->name) == 0) { diff --git a/src/mtconnect/pipeline/response_document.hpp b/src/mtconnect/pipeline/response_document.hpp index a2e2421ec..3e78bba31 100644 --- a/src/mtconnect/pipeline/response_document.hpp +++ b/src/mtconnect/pipeline/response_document.hpp @@ -45,11 +45,13 @@ namespace mtconnect::pipeline { /// @return `true` if successful static bool parse(const std::string_view &content, ResponseDocument &doc, pipeline::PipelineContextPtr context, - const std::optional &device = std::nullopt); + const std::optional &device = std::nullopt, + const std::optional &uuid = std::nullopt); // Parsed data SequenceNumber_t m_next; ///< Next sequence number uint64_t m_instanceId; ///< Agent instance id + int32_t m_agentVersion = 0; ///< Agent version entity::EntityList m_entities; ///< List of entities entity::EntityList m_assetEvents; ///< List of asset events Errors m_errors; ///< List of Errors diff --git a/src/mtconnect/source/adapter/adapter_pipeline.cpp b/src/mtconnect/source/adapter/adapter_pipeline.cpp index 56d780c42..2589afdba 100644 --- a/src/mtconnect/source/adapter/adapter_pipeline.cpp +++ b/src/mtconnect/source/adapter/adapter_pipeline.cpp @@ -107,7 +107,7 @@ namespace mtconnect { { if (next == nullptr) next = m_start; - + next->bind(make_shared( m_context, m_devices, IsOptionSet(m_options, configuration::AutoAvailable))); next->bind(make_shared(m_context, m_device)); diff --git a/src/mtconnect/source/adapter/agent_adapter/agent_adapter.cpp b/src/mtconnect/source/adapter/agent_adapter/agent_adapter.cpp index 6eb755e15..bcf4e231b 100644 --- a/src/mtconnect/source/adapter/agent_adapter/agent_adapter.cpp +++ b/src/mtconnect/source/adapter/agent_adapter/agent_adapter.cpp @@ -44,16 +44,19 @@ namespace mtconnect::source::adapter::agent_adapter { void AgentAdapterPipeline::build(const ConfigOptions &options) { m_options = options; + m_uuid = GetOption(options, configuration::UUID); + buildDeviceList(); buildCommandAndStatusDelivery(); - TransformPtr next = bind(make_shared(m_context, m_feedback, m_device)); + TransformPtr next = + bind(make_shared(m_context, m_feedback, m_device, m_uuid)); std::optional obsMetrics; obsMetrics = m_identity + "_observation_update_rate"; next->bind(make_shared(m_context, obsMetrics)); - buildDeviceDelivery(next); + buildDeviceDelivery(next); buildAssetDelivery(next); - + applySplices(); } @@ -84,7 +87,7 @@ namespace mtconnect::source::adapter::agent_adapter { {configuration::ReconnectInterval, 10000ms}, {configuration::RelativeTime, false}, {configuration::UsePolling, false}, - {configuration::UpdateDeviceXml, false}, + {configuration::EnableSourceDeviceModels, false}, {"!CloseConnectionAfterResponse!", false}}); m_handler = m_pipeline.makeHandler(); @@ -110,8 +113,7 @@ namespace mtconnect::source::adapter::agent_adapter { m_usePolling = *GetOption(m_options, configuration::UsePolling); m_reconnectInterval = *GetOption(m_options, configuration::ReconnectInterval); m_pollingInterval = *GetOption(m_options, configuration::PollingInterval); - m_probeAgent = *GetOption(m_options, configuration::UpdateDeviceXml); - + m_probeAgent = *GetOption(m_options, configuration::EnableSourceDeviceModels); m_closeConnectionAfterResponse = *GetOption(m_options, "!CloseConnectionAfterResponse!"); @@ -368,14 +370,14 @@ namespace mtconnect::source::adapter::agent_adapter { m_reconnecting = false; sample(); } - + bool AgentAdapter::probe() { if (m_stopped) return false; - m_streamRequest.emplace(m_sourceDevice, "probe", UrlQuery(), false, - [this]() { + m_streamRequest.emplace(m_sourceDevice, "probe", UrlQuery(), false, [this]() { + m_agentVersion = m_feedback.m_agentVersion; assets(); return current(); }); @@ -445,7 +447,11 @@ namespace mtconnect::source::adapter::agent_adapter { void AgentAdapter::assets() { UrlQuery query({{"count", "1048576"}}); - m_assetRequest.emplace(m_sourceDevice, "assets", query, false, [this]() { + + std::optional source; + if (m_agentVersion >= 200) + source.emplace(m_sourceDevice); + m_assetRequest.emplace(source, "assets", query, false, [this]() { m_assetRequest.reset(); return true; }); diff --git a/src/mtconnect/source/adapter/agent_adapter/agent_adapter.hpp b/src/mtconnect/source/adapter/agent_adapter/agent_adapter.hpp index b07855e63..6a0cebcb5 100644 --- a/src/mtconnect/source/adapter/agent_adapter/agent_adapter.hpp +++ b/src/mtconnect/source/adapter/agent_adapter/agent_adapter.hpp @@ -52,6 +52,7 @@ namespace mtconnect::source::adapter::agent_adapter { Handler *m_handler = nullptr; pipeline::XmlTransformFeedback &m_feedback; + std::optional m_uuid; }; /// @brief An adapter to connnect to another Agent and replicate data @@ -153,6 +154,8 @@ namespace mtconnect::source::adapter::agent_adapter { std::optional m_streamRequest; std::optional m_assetRequest; + int32_t m_agentVersion = 0; + // For testing bool m_closeConnectionAfterResponse; }; diff --git a/src/mtconnect/source/adapter/agent_adapter/session.hpp b/src/mtconnect/source/adapter/agent_adapter/session.hpp index 00c3bb950..89e146829 100644 --- a/src/mtconnect/source/adapter/agent_adapter/session.hpp +++ b/src/mtconnect/source/adapter/agent_adapter/session.hpp @@ -64,10 +64,11 @@ namespace mtconnect::source::adapter::agent_adapter { Request(const Request &request) = default; std::optional m_sourceDevice; ///< optional source device - std::string m_operation; ///< The REST operation (probe, current, sample, asset) - UrlQuery m_query; ///< URL Query parameters - bool m_stream; ///< `true` if using HTTP long pull - Next m_next; ///< function to call on successful read + std::string m_operation; ///< The REST operation (probe, current, sample, asset) + UrlQuery m_query; ///< URL Query parameters + bool m_stream; ///< `true` if using HTTP long pull + Next m_next; ///< function to call on successful read + int32_t m_agentVersion = 0; ///< agent version if required > 0 for asset requests /// @brief Given a url, get a formatted target for a given operation /// @param url The base url @@ -89,6 +90,8 @@ namespace mtconnect::source::adapter::agent_adapter { /// @param ec the error code /// @param what descriptive message virtual void failed(std::error_code ec, const char *what) = 0; + /// @brief close the connection + virtual void close() = 0; /// @brief Make a request of the remote agent /// @param request the request @@ -102,6 +105,7 @@ namespace mtconnect::source::adapter::agent_adapter { UpdateAssets m_updateAssets; bool m_closeConnectionAfterResponse = false; std::chrono::milliseconds m_timeout = std::chrono::milliseconds(30000); + bool m_closeOnRead = false; }; } // namespace mtconnect::source::adapter::agent_adapter diff --git a/src/mtconnect/source/adapter/agent_adapter/session_impl.hpp b/src/mtconnect/source/adapter/agent_adapter/session_impl.hpp index bdd4ac421..43ff13e54 100644 --- a/src/mtconnect/source/adapter/agent_adapter/session_impl.hpp +++ b/src/mtconnect/source/adapter/agent_adapter/session_impl.hpp @@ -66,6 +66,9 @@ namespace mtconnect::source::adapter::agent_adapter { /// @return `true` if the socket is open bool isOpen() const override { return derived().lowestLayer().socket().is_open(); } + /// @brief close the connection + void close() override { derived().lowestLayer().socket().close(); } + /// @brief Method called when a request fails /// /// Closes the socket and resets the request @@ -74,9 +77,12 @@ namespace mtconnect::source::adapter::agent_adapter { void failed(std::error_code ec, const char *what) override { derived().lowestLayer().socket().close(); - m_request.reset(); - LOG(error) << what << ": " << ec.message() << "\n"; + LOG(error) << "Agent Adapter Connection Failed: " << m_url.getUrlText(nullopt); + if (m_request) + LOG(error) << "Agent Adapter Target: " << m_request->getTarget(m_url); + LOG(error) << "Agent Adapter " << what << ": " << ec.message() << "\n"; + m_request.reset(); if (m_failed) m_failed(ec); } @@ -98,7 +104,6 @@ namespace mtconnect::source::adapter::agent_adapter { m_textParser.reset(); m_req.reset(); m_hasHeader = false; - m_closeOnRead = false; if (m_chunk.size() > 0) m_chunk.consume(m_chunk.size()); @@ -241,6 +246,9 @@ namespace mtconnect::source::adapter::agent_adapter { derived().lowestLayer().expires_after(m_timeout); + LOG(debug) << "Agent adapter making request: " << m_url.getUrlText(nullopt) << " target " + << m_request->getTarget(m_url); + http::async_write(derived().stream(), *m_req, beast::bind_front_handler(&SessionImpl::onWrite, derived().getptr())); } @@ -281,7 +289,7 @@ namespace mtconnect::source::adapter::agent_adapter { { if (ec) { - LOG(error) << "Error getting request header: " << ec.category().name() << " " + LOG(error) << "Agent Adapter Error getting request header: " << ec.category().name() << " " << ec.message(); derived().lowestLayer().close(); if (m_request->m_stream && ec == beast::error::timeout) @@ -304,7 +312,12 @@ namespace mtconnect::source::adapter::agent_adapter { } auto &msg = m_headerParser->get(); - if (auto a = msg.find(beast::http::field::connection); a != msg.end()) + if (msg.version() < 11) + { + LOG(trace) << "Agent adapter: HTTP 10 requires close on read"; + m_closeOnRead = true; + } + else if (auto a = msg.find(beast::http::field::connection); a != msg.end()) { m_closeOnRead = a->value() == "close"; } @@ -357,7 +370,7 @@ namespace mtconnect::source::adapter::agent_adapter { m_request.reset(); if (m_closeOnRead) - derived().disconnect(); + close(); if (next) { @@ -599,8 +612,6 @@ namespace mtconnect::source::adapter::agent_adapter { // For request queuing std::optional m_request; RequestQueue m_queue; - - bool m_closeOnRead = false; }; } // namespace mtconnect::source::adapter::agent_adapter diff --git a/src/mtconnect/source/adapter/shdr/shdr_adapter.cpp b/src/mtconnect/source/adapter/shdr/shdr_adapter.cpp index 6eefc2f3c..fcdb1f185 100644 --- a/src/mtconnect/source/adapter/shdr/shdr_adapter.cpp +++ b/src/mtconnect/source/adapter/shdr/shdr_adapter.cpp @@ -64,7 +64,7 @@ namespace mtconnect::source::adapter::shdr { {configuration::AutoAvailable, false}, {configuration::RealTime, false}, {configuration::RelativeTime, false}, - {configuration::UpdateDeviceXml, false}}); + {configuration::EnableSourceDeviceModels, false}}); m_server = get(m_options[configuration::Host]); m_port = get(m_options[configuration::Port]); diff --git a/src/mtconnect/utilities.hpp b/src/mtconnect/utilities.hpp index 07e48f10e..491c664f1 100644 --- a/src/mtconnect/utilities.hpp +++ b/src/mtconnect/utilities.hpp @@ -33,7 +33,7 @@ #include "mtconnect/config.hpp" -//####### CONSTANTS ####### +// ####### CONSTANTS ####### // Port number to put server on const unsigned int SERVER_PORT = 8080; diff --git a/test/agent_adapter_test.cpp b/test/agent_adapter_test.cpp index 1d5fbd6d4..447954690 100644 --- a/test/agent_adapter_test.cpp +++ b/test/agent_adapter_test.cpp @@ -107,7 +107,8 @@ class AgentAdapterTest : public testing::Test auto parser = make_unique(); m_device = - parser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/test_config.xml", printer.get()).front(); + parser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/test_config.xml", printer.get()) + .front(); m_context = make_shared(); m_context->m_contract = make_unique(m_device); @@ -129,10 +130,10 @@ class AgentAdapterTest : public testing::Test m_adapter.reset(); } - void createAgent(ConfigOptions options = {}, std::string deviceFile = "/test/resources/samples/test_config.xml") + void createAgent(ConfigOptions options = {}, + std::string deviceFile = "/test/resources/samples/test_config.xml") { - m_agentTestHelper->createAgent(deviceFile, 8, 4, "2.0", 25, false, true, - options); + m_agentTestHelper->createAgent(deviceFile, 8, 4, "2.0", 25, false, true, options); m_agentTestHelper->getAgent()->start(); m_agentId = to_string(getCurrentTimeInSec()); } @@ -628,7 +629,7 @@ TEST_F(AgentAdapterTest, should_use_polling_when_option_is_set) throw runtime_error("test timed out"); } }); - + while (rc < 2) { m_agentTestHelper->m_ioContext.run_one(); @@ -722,9 +723,9 @@ TEST_F(AgentAdapterTest, should_connect_to_tls_agent) TEST_F(AgentAdapterTest, should_create_device_when_option_supplied) { createAgent({}, "/test/resources/samples/solid_model.xml"); - + auto port = m_agentTestHelper->m_restService->getServer()->getPort(); - auto adapter = createAdapter(port, {{configuration::UpdateDeviceXml, true}}); + auto adapter = createAdapter(port, {{configuration::EnableSourceDeviceModels, true}}); addAdapter(); @@ -751,11 +752,10 @@ TEST_F(AgentAdapterTest, should_create_device_when_option_supplied) throw runtime_error("test timed out"); } }); - + while (rc < 2) { m_agentTestHelper->m_ioContext.run_one(); } ASSERT_EQ(2, rc); - } diff --git a/test/agent_test.cpp b/test/agent_test.cpp index 83ad3291d..6b1918aa5 100644 --- a/test/agent_test.cpp +++ b/test/agent_test.cpp @@ -65,7 +65,8 @@ class AgentTest : public testing::Test void SetUp() override { m_agentTestHelper = make_unique(); - m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "1.3", 25, true); + m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "1.3", 25, + true); m_agentId = to_string(getCurrentTimeInSec()); } @@ -89,8 +90,9 @@ TEST_F(AgentTest, Constructor) using namespace configuration; ConfigOptions options {{BufferSize, 17}, {MaxAssets, 8}, {SchemaVersion, "1.7"s}}; - unique_ptr agent = make_unique(m_agentTestHelper->m_ioContext, - PROJECT_ROOT_DIR "/test/resources/samples/badPath.xml", options); + unique_ptr agent = + make_unique(m_agentTestHelper->m_ioContext, + PROJECT_ROOT_DIR "/test/resources/samples/badPath.xml", options); auto context = std::make_shared(); context->m_contract = agent->makePipelineContract(); @@ -133,8 +135,9 @@ TEST_F(AgentTest, FailWithDuplicateDeviceUUID) using namespace configuration; ConfigOptions options {{BufferSize, 17}, {MaxAssets, 8}, {SchemaVersion, "1.5"s}}; - unique_ptr agent = make_unique(m_agentTestHelper->m_ioContext, - PROJECT_ROOT_DIR "/test/resources/samples/dup_uuid.xml", options); + unique_ptr agent = + make_unique(m_agentTestHelper->m_ioContext, + PROJECT_ROOT_DIR "/test/resources/samples/dup_uuid.xml", options); auto context = std::make_shared(); context->m_contract = agent->makePipelineContract(); @@ -1795,7 +1798,8 @@ TEST_F(AgentTest, UUIDChange) TEST_F(AgentTest, AssetStorage) { - auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "1.3", 4, true); + auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, + "1.3", 4, true); auto rest = m_agentTestHelper->getRestService(); ASSERT_TRUE(rest->getServer()->arePutsAllowed()); @@ -1830,7 +1834,8 @@ TEST_F(AgentTest, AssetStorage) TEST_F(AgentTest, AssetBuffer) { - auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "1.3", 4, true); + auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, + "1.3", 4, true); string body = "TEST 1"; QueryMap queries; @@ -2320,7 +2325,8 @@ TEST_F(AgentTest, RemoveLastAssetChanged) TEST_F(AgentTest, RemoveAssetUsingHttpDelete) { - auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "1.3", 4, true); + auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, + "1.3", 4, true); addAdapter(); const auto &storage = agent->getAssetStorage(); @@ -2417,7 +2423,8 @@ TEST_F(AgentTest, RemoveAllAssets) TEST_F(AgentTest, AssetProbe) { - auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "1.3", 4, true); + auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, + "1.3", 4, true); string body = "TEST 1"; QueryMap queries; const auto &storage = agent->getAssetStorage(); @@ -2782,7 +2789,8 @@ TEST_F(AgentTest, shound_add_asset_count_when_20) TEST_F(AgentTest, asset_count_should_not_occur_in_header_post_20) { - auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "2.0", 4, true); + auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, + "2.0", 4, true); string body = "TEST 1"; QueryMap queries; @@ -2808,7 +2816,8 @@ TEST_F(AgentTest, asset_count_should_not_occur_in_header_post_20) TEST_F(AgentTest, asset_count_should_track_asset_additions_by_type) { - auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "2.0", 4, true); + auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, + "2.0", 4, true); string body1 = "TEST 1"; QueryMap queries; @@ -2866,7 +2875,8 @@ TEST_F(AgentTest, asset_count_should_track_asset_additions_by_type) TEST_F(AgentTest, asset_should_also_work_using_post_with_assets) { - auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "2.0", 4, true); + auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, + "2.0", 4, true); string body = "TEST 1"; QueryMap queries; @@ -2890,7 +2900,8 @@ TEST_F(AgentTest, pre_start_hook_should_be_called) helper.getAgent()->beforeStartHooks().add(lambda); }; m_agentTestHelper->setAgentCreateHook(helperHook); - auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "2.0", 4, true); + auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, + "2.0", 4, true); ASSERT_FALSE(called); agent->start(); @@ -2932,7 +2943,8 @@ TEST_F(AgentTest, pre_stop_hook_should_be_called) helper.getAgent()->beforeStopHooks().add(lambda); }; m_agentTestHelper->setAgentCreateHook(helperHook); - auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, "2.0", 4, true); + auto agent = m_agentTestHelper->createAgent("/test/resources/samples/test_config.xml", 8, 4, + "2.0", 4, true); ASSERT_FALSE(called); agent->start(); diff --git a/test/config_test.cpp b/test/config_test.cpp index 17653f50d..9072955db 100644 --- a/test/config_test.cpp +++ b/test/config_test.cpp @@ -90,7 +90,7 @@ namespace { fs::path copyFile(const std::string &src, fs::path target, chrono::seconds delta) { - fs::path file {fs::path(PROJECT_ROOT_DIR) / "samples" / src}; + fs::path file {fs::path(PROJECT_ROOT_DIR) / "test" / "resources" / "samples" / src}; fs::copy_file(file, target, fs::copy_options::overwrite_existing); auto t = fs::last_write_time(target); @@ -1228,8 +1228,9 @@ Port = 0 } else { - fs::copy_file(fs::path(PROJECT_ROOT_DIR) / "samples" / "min_config2.xml", devices, - fs::copy_options::overwrite_existing); + fs::copy_file( + fs::path(PROJECT_ROOT_DIR) / "test" / "resources" / "samples" / "min_config2.xml", + devices, fs::copy_options::overwrite_existing); } }); @@ -2091,7 +2092,8 @@ Adapters { using namespace boost::algorithm; if (!ec) - {} + { + } m_config->stop(); }; diff --git a/test/image_file_test.cpp b/test/image_file_test.cpp index dd74af885..f9cc62b7f 100644 --- a/test/image_file_test.cpp +++ b/test/image_file_test.cpp @@ -141,8 +141,8 @@ TEST_F(ImageFileTest, should_print_configuration_with_image_file_in_json) TEST_F(ImageFileTest, should_print_configuration_with_image_file_in_json_v2) { - m_agentTestHelper->createAgent("/test/resources/samples/solid_model.xml", 8, 4, "2.2", 25, false, false, - {{configuration::JsonVersion, 2}}); + m_agentTestHelper->createAgent("/test/resources/samples/solid_model.xml", 8, 4, "2.2", 25, false, + false, {{configuration::JsonVersion, 2}}); { PARSE_JSON_RESPONSE("/LinuxCNC/probe"); diff --git a/test/json_printer_stream_test.cpp b/test/json_printer_stream_test.cpp index 3aab035ee..ae6365366 100644 --- a/test/json_printer_stream_test.cpp +++ b/test/json_printer_stream_test.cpp @@ -60,8 +60,8 @@ class JsonPrinterStreamTest : public testing::Test m_xmlPrinter = std::make_unique("1.5"); m_printer = std::make_unique(1, true); m_config = std::make_unique(); - m_devices = - m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/SimpleDevlce.xml", m_xmlPrinter.get()); + m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/SimpleDevlce.xml", + m_xmlPrinter.get()); } void TearDown() override @@ -193,7 +193,8 @@ TEST_F(JsonPrinterStreamTest, DeviceStream_version_2_one_device) TEST_F(JsonPrinterStreamTest, DeviceStream_version_2_two_devices) { m_printer = std::make_unique(2, true); - m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/min_config2.xml", m_xmlPrinter.get()); + m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/min_config2.xml", + m_xmlPrinter.get()); Checkpoint checkpoint; addObservationToCheckpoint(checkpoint, "Sspeed", 10254804, 100_value); diff --git a/test/mtconnect_xml_transform_test.cpp b/test/mtconnect_xml_transform_test.cpp index 1c2370023..3d72005d7 100644 --- a/test/mtconnect_xml_transform_test.cpp +++ b/test/mtconnect_xml_transform_test.cpp @@ -72,7 +72,8 @@ class MTConnectXmlTransformTest : public testing::Test auto parser = make_unique(); m_device = - parser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/test_config.xml", printer.get()).front(); + parser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/test_config.xml", printer.get()) + .front(); m_context = make_shared(); m_context->m_contract = make_unique(m_device); diff --git a/test/references_test.cpp b/test/references_test.cpp index edf67f67c..1648e32ad 100644 --- a/test/references_test.cpp +++ b/test/references_test.cpp @@ -54,8 +54,8 @@ class ReferencesTest : public testing::Test { // Create an agent with only 16 slots and 8 data items. m_agentTestHelper = make_unique(); - m_agentTestHelper->createAgent("/test/resources/samples/reference_example.xml", 8, 4, "1.6", 25, false, true, - options); + m_agentTestHelper->createAgent("/test/resources/samples/reference_example.xml", 8, 4, "1.6", 25, + false, true, options); m_agentId = to_string(getCurrentTimeInSec()); m_device = m_agentTestHelper->m_agent->getDeviceByName("LinuxCNC"); } diff --git a/test/response_document_test.cpp b/test/response_document_test.cpp index 235b9ac8e..bf705e1e4 100644 --- a/test/response_document_test.cpp +++ b/test/response_document_test.cpp @@ -75,7 +75,9 @@ class ResponseDocumentTest : public testing::Test m_doc.emplace(); - m_device = parser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/data_set.xml", printer.get()).front(); + m_device = + parser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/data_set.xml", printer.get()) + .front(); m_context = make_shared(); m_context->m_contract = make_unique(m_device); diff --git a/test/unit_conversion_test.cpp b/test/unit_conversion_test.cpp index b73223e3b..3debab2f2 100644 --- a/test/unit_conversion_test.cpp +++ b/test/unit_conversion_test.cpp @@ -99,7 +99,6 @@ TEST(UnitConversionTest, check_revolution_per_second) EXPECT_NEAR(420.0, conv->convert(7.0), 0.0001); } - TEST(UnitConversionTest, check_cubic_feet_per_minute) { auto conv = UnitConversion::make("CUBIC_FOOT/MINUTE", "CUBIC_MILLIMETER/SECOND"); diff --git a/test/xml_parser_test.cpp b/test/xml_parser_test.cpp index 936f90bd3..57b5e7075 100644 --- a/test/xml_parser_test.cpp +++ b/test/xml_parser_test.cpp @@ -53,12 +53,13 @@ class XmlParserTest : public testing::Test { std::unique_ptr printer(new printer::XmlPrinter()); m_xmlParser = new parser::XmlParser(); - m_devices = - m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/test_config.xml", printer.get()); + m_devices = m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/test_config.xml", + printer.get()); } catch (exception &) { - FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR << " /test/resources/samples/test_config.xml"; + FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR + << " /test/resources/samples/test_config.xml"; } } @@ -85,13 +86,14 @@ TEST_F(XmlParserTest, Constructor) std::unique_ptr printer(new printer::XmlPrinter()); m_xmlParser = new parser::XmlParser(); - ASSERT_THROW(m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/badPath.xml", printer.get()), - std::runtime_error); + ASSERT_THROW( + m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/badPath.xml", printer.get()), + std::runtime_error); delete m_xmlParser; m_xmlParser = nullptr; m_xmlParser = new parser::XmlParser(); - ASSERT_NO_THROW( - m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/test_config.xml", printer.get())); + ASSERT_NO_THROW(m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/test_config.xml", + printer.get())); } TEST_F(XmlParserTest, GetDevices) @@ -191,7 +193,8 @@ TEST_F(XmlParserTest, GetDataItemsExt) } catch (exception &) { - FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR << "/test/resources/samples/extension.xml"; + FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR + << "/test/resources/samples/extension.xml"; } filter.clear(); @@ -215,11 +218,13 @@ TEST_F(XmlParserTest, ExtendedSchema) { std::unique_ptr printer(new printer::XmlPrinter()); m_xmlParser = new parser::XmlParser(); - m_devices = m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/extension.xml", printer.get()); + m_devices = m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/extension.xml", + printer.get()); } catch (exception &) { - FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR << "/test/resources/samples/extension.xml"; + FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR + << "/test/resources/samples/extension.xml"; } ASSERT_EQ((size_t)1, m_devices.size()); @@ -287,8 +292,8 @@ TEST_F(XmlParserTest, NoNamespace) unique_ptr printer(new printer::XmlPrinter()); m_xmlParser = new parser::XmlParser(); - ASSERT_NO_THROW( - m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/NoNamespace.xml", printer.get())); + ASSERT_NO_THROW(m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/NoNamespace.xml", + printer.get())); } TEST_F(XmlParserTest, FilteredDataItem13) @@ -299,8 +304,8 @@ TEST_F(XmlParserTest, FilteredDataItem13) { unique_ptr printer(new printer::XmlPrinter()); m_xmlParser = new parser::XmlParser(); - m_devices = - m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/filter_example_1.3.xml", printer.get()); + m_devices = m_xmlParser->parseFile( + PROJECT_ROOT_DIR "/test/resources/samples/filter_example_1.3.xml", printer.get()); } catch (exception &) { @@ -327,12 +332,13 @@ TEST_F(XmlParserTest, FilteredDataItem) { unique_ptr printer(new printer::XmlPrinter()); m_xmlParser = new parser::XmlParser(); - m_devices = - m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/filter_example.xml", printer.get()); + m_devices = m_xmlParser->parseFile( + PROJECT_ROOT_DIR "/test/resources/samples/filter_example.xml", printer.get()); } catch (exception &) { - FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR << "/test/resources/samples/filter_example.xml"; + FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR + << "/test/resources/samples/filter_example.xml"; } auto di = m_devices.front()->getDeviceDataItem("c1"); @@ -359,12 +365,13 @@ TEST_F(XmlParserTest, References) { unique_ptr printer(new printer::XmlPrinter()); m_xmlParser = new parser::XmlParser(); - m_devices = - m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/reference_example.xml", printer.get()); + m_devices = m_xmlParser->parseFile( + PROJECT_ROOT_DIR "/test/resources/samples/reference_example.xml", printer.get()); } catch (exception &) { - FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR << "/test/resources/samples/reference_example.xml"; + FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR + << "/test/resources/samples/reference_example.xml"; } string id = "mf"; @@ -421,12 +428,13 @@ TEST_F(XmlParserTest, SourceReferences) { unique_ptr printer(new printer::XmlPrinter()); m_xmlParser = new parser::XmlParser(); - m_devices = - m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/reference_example.xml", printer.get()); + m_devices = m_xmlParser->parseFile( + PROJECT_ROOT_DIR "/test/resources/samples/reference_example.xml", printer.get()); } catch (exception &) { - FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR << "/test/resources/samples/reference_example.xml"; + FAIL() << "Could not locate test xml: " << PROJECT_ROOT_DIR + << "/test/resources/samples/reference_example.xml"; } const auto item = m_devices.front()->getDeviceDataItem("bfc"); @@ -450,8 +458,8 @@ TEST_F(XmlParserTest, DataItemRelationships) unique_ptr printer(new printer::XmlPrinter()); m_xmlParser = new parser::XmlParser(); - m_devices = - m_xmlParser->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/relationship_test.xml", printer.get()); + m_devices = m_xmlParser->parseFile( + PROJECT_ROOT_DIR "/test/resources/samples/relationship_test.xml", printer.get()); const auto &device = m_devices.front(); const auto &dataItemsMap = device->getDeviceDataItems(); diff --git a/test/xml_printer_test.cpp b/test/xml_printer_test.cpp index a9b2ca605..9d2099348 100644 --- a/test/xml_printer_test.cpp +++ b/test/xml_printer_test.cpp @@ -57,7 +57,8 @@ class XmlPrinterTest : public testing::Test m_config = new XmlParser(); m_printer = new printer::XmlPrinter(true); m_printer->setSchemaVersion("1.2"); - m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/test_config.xml", m_printer); + m_devices = + m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/test_config.xml", m_printer); } void TearDown() override @@ -713,7 +714,8 @@ TEST_F(XmlPrinterTest, ProbeWithFilter13) delete m_config; m_config = new XmlParser(); - m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/filter_example_1.3.xml", m_printer); + m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/filter_example_1.3.xml", + m_printer); PARSE_XML(m_printer->printProbe(123, 9999, 1024, 10, 1, m_devices)); @@ -729,7 +731,8 @@ TEST_F(XmlPrinterTest, ProbeWithFilter) m_config = nullptr; m_config = new XmlParser(); - m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/filter_example.xml", m_printer); + m_devices = + m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/filter_example.xml", m_printer); PARSE_XML(m_printer->printProbe(123, 9999, 1024, 10, 1, m_devices)); @@ -746,7 +749,8 @@ TEST_F(XmlPrinterTest, References) m_config = nullptr; m_config = new XmlParser(); - m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/reference_example.xml", m_printer); + m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/reference_example.xml", + m_printer); PARSE_XML(m_printer->printProbe(123, 9999, 1024, 10, 1, m_devices)); @@ -762,7 +766,8 @@ TEST_F(XmlPrinterTest, LegacyReferences) m_config = nullptr; m_config = new XmlParser(); - m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/reference_example.xml", m_printer); + m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/reference_example.xml", + m_printer); PARSE_XML(m_printer->printProbe(123, 9999, 1024, 10, 1, m_devices)); @@ -775,7 +780,8 @@ TEST_F(XmlPrinterTest, CheckDeviceChangeTime) { m_printer = new XmlPrinter(true); m_printer->setSchemaVersion("1.7"); - m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/test_config.xml", m_printer); + m_devices = + m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/test_config.xml", m_printer); m_printer->setModelChangeTime(getCurrentTime(GMT_UV_SEC)); ASSERT_FALSE(m_printer->getModelChangeTime().empty()); @@ -796,7 +802,8 @@ TEST_F(XmlPrinterTest, SourceReferences) m_config = nullptr; m_config = new XmlParser(); - m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/reference_example.xml", m_printer); + m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/reference_example.xml", + m_printer); PARSE_XML(m_printer->printProbe(123, 9999, 1024, 10, 1, m_devices)); @@ -867,7 +874,8 @@ TEST_F(XmlPrinterTest, PrintDataItemRelationships) m_config = nullptr; m_config = new XmlParser(); - m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/relationship_test.xml", m_printer); + m_devices = m_config->parseFile(PROJECT_ROOT_DIR "/test/resources/samples/relationship_test.xml", + m_printer); PARSE_XML(m_printer->printProbe(123, 9999, 1024, 10, 1, m_devices));