|
| 1 | +#include <coreobjects/authentication_provider_factory.h> |
| 2 | +#include <coretypes/common.h> |
| 3 | +#include <opcua_server_module/module_dll.h> |
| 4 | +#include <opcua_server_module/version.h> |
| 5 | +#include <opcuaclient/opcuaclient.h> |
| 6 | +#include <opendaq/context_factory.h> |
| 7 | +#include <opendaq/instance_factory.h> |
| 8 | +#include <opendaq/instance_ptr.h> |
| 9 | +#include <opendaq/mock/mock_device_module.h> |
| 10 | +#include <opendaq/mock/mock_fb_module.h> |
| 11 | +#include <opendaq/module_manager_factory.h> |
| 12 | +#include <opendaq/module_ptr.h> |
| 13 | +#include <opendaq/opendaq.h> |
| 14 | + |
| 15 | +#include <testutils/testutils.h> |
| 16 | + |
| 17 | +using OpcUaComponentFilteringTest = testing::Test; |
| 18 | + |
| 19 | +using namespace daq; |
| 20 | + |
| 21 | +static ModulePtr CreateModule(ContextPtr context = NullContext()) |
| 22 | +{ |
| 23 | + ModulePtr module; |
| 24 | + createOpcUaServerModule(&module, context); |
| 25 | + return module; |
| 26 | +} |
| 27 | + |
| 28 | +static InstancePtr CreateServerInstance() |
| 29 | +{ |
| 30 | + const auto logger = Logger(); |
| 31 | + const auto moduleManager = ModuleManager("[[none]]"); |
| 32 | + const auto authenticationProvider = AuthenticationProvider(); |
| 33 | + const auto context = Context(Scheduler(logger), logger, TypeManager(), moduleManager, authenticationProvider); |
| 34 | + |
| 35 | + const ModulePtr deviceModule(MockDeviceModule_Create(context)); |
| 36 | + moduleManager.addModule(deviceModule); |
| 37 | + |
| 38 | + const ModulePtr fbModule(MockFunctionBlockModule_Create(context)); |
| 39 | + moduleManager.addModule(fbModule); |
| 40 | + |
| 41 | + const ModulePtr opcuaServerModule = CreateModule(context); |
| 42 | + moduleManager.addModule(opcuaServerModule); |
| 43 | + |
| 44 | + auto instance = InstanceBuilder().setContext(context).setDefaultRootDeviceLocalId("local").build(); |
| 45 | + |
| 46 | + instance.addDevice("daqmock://phys_device"); |
| 47 | + FunctionBlockPtr fb = instance.addFunctionBlock("mock_fb_uid"); |
| 48 | + // Set first input port to private |
| 49 | + auto inputPort = fb.getInputPorts(search::LocalId("TestInputPort1"))[0]; |
| 50 | + inputPort.setPublic(false); |
| 51 | + |
| 52 | + instance.addServer("OpenDAQOPCUA", nullptr); |
| 53 | + return instance; |
| 54 | +} |
| 55 | + |
| 56 | +static InstancePtr CreateClientInstance() |
| 57 | +{ |
| 58 | + auto instance = InstanceBuilder().build(); |
| 59 | + |
| 60 | + auto config = instance.createDefaultAddDeviceConfig(); |
| 61 | + PropertyObjectPtr general = config.getPropertyValue("General"); |
| 62 | + general.setPropertyValue("StreamingConnectionHeuristic", 2); |
| 63 | + |
| 64 | + instance.addDevice("daq.opcua://127.0.0.1", config); |
| 65 | + return instance; |
| 66 | +} |
| 67 | + |
| 68 | +TEST_F(OpcUaComponentFilteringTest, FilterComponents) |
| 69 | +{ |
| 70 | + auto serverDevice = CreateServerInstance(); |
| 71 | + auto client = CreateClientInstance(); |
| 72 | + auto clientDevice = client.getDevices(search::LocalId("local"))[0]; |
| 73 | + ASSERT_TRUE(clientDevice.assigned()); |
| 74 | + |
| 75 | + auto childDevicesServer = serverDevice.getDevices(search::LocalId("mockdev")); |
| 76 | + ASSERT_EQ(childDevicesServer.getCount(), 1u); |
| 77 | + auto childDevicesClient = clientDevice.getDevices(search::LocalId("mockdev")); |
| 78 | + ASSERT_EQ(childDevicesClient.getCount(), 1u); |
| 79 | + |
| 80 | + auto signalsServer = childDevicesServer[0].getSignals(search::LocalId("devicetimesigprivate")); |
| 81 | + ASSERT_EQ(signalsServer.getCount(), 1u); |
| 82 | + ASSERT_EQ(signalsServer[0].getPublic(), False); |
| 83 | + |
| 84 | + // Not available on client |
| 85 | + auto signalsClient = childDevicesClient[0].getSignals(search::LocalId("devicetimesigprivate")); |
| 86 | + ASSERT_EQ(signalsClient.getCount(), 0u); |
| 87 | + |
| 88 | + auto fbsServer = serverDevice.getFunctionBlocks(); |
| 89 | + ASSERT_EQ(fbsServer.getCount(), 1u); |
| 90 | + auto fbsClient = clientDevice.getFunctionBlocks(); |
| 91 | + ASSERT_EQ(fbsClient.getCount(), 1u); |
| 92 | + |
| 93 | + auto portsServer = fbsServer[0].getInputPorts(search::LocalId("TestInputPort1")); |
| 94 | + ASSERT_EQ(portsServer.getCount(), 1u); |
| 95 | + ASSERT_FALSE(portsServer[0].getPublic()); |
| 96 | + |
| 97 | + // Not available on client |
| 98 | + auto portsClient = fbsClient[0].getInputPorts(search::LocalId("TestInputPort1")); |
| 99 | + ASSERT_EQ(portsClient.getCount(), 0u); |
| 100 | +} |
0 commit comments