Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/opcua_client_module/src/opcua_client_module_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <opendaq/custom_log.h>
#include <coreobjects/property_object_factory.h>
#include <opendaq/device_type_factory.h>
#include <opendaq/device_private_ptr.h>
#include <opendaq/mirrored_signal_config_ptr.h>
#include <opendaq/search_filter_factory.h>
#include <regex>
Expand Down Expand Up @@ -115,6 +116,7 @@ DevicePtr OpcUaClientModule::onCreateDevice(const StringPtr& connectionString,
.addAddressInfo(addressInfo)
.freeze();

device.asPtr<IDevicePrivate>(true).setAsRoot();
return device;
}

Expand Down
2 changes: 2 additions & 0 deletions modules/opcua_client_module/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(MODULE_NAME opcua_client_module)
set(TEST_APP test_${MODULE_NAME})

set(TEST_SOURCES test_opcua_client_module.cpp
test_opcua_device_module.cpp
test_app.cpp
)

Expand All @@ -10,6 +11,7 @@ add_executable(${TEST_APP} ${TEST_SOURCES}

target_link_libraries(${TEST_APP} PRIVATE ${OPENDAQ_SDK_TARGET_NAMESPACE}::opendaq_test_utils gtest
${OPENDAQ_SDK_TARGET_NAMESPACE}::${MODULE_NAME}
${OPENDAQ_SDK_TARGET_NAMESPACE}::opendaq_mocks
)

add_test(NAME ${TEST_APP}
Expand Down
103 changes: 103 additions & 0 deletions modules/opcua_client_module/tests/test_opcua_device_module.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include <opcua_client_module/module_dll.h>
#include <opendaq/opendaq.h>
#include <opendaq/module_manager_ptr.h>
#include <opendaq/mock/mock_device_module.h>
#include <opendaq/mock/mock_fb_module.h>
#include <testutils/testutils.h>

using OpcuaDeviceModulesTest = testing::Test;

using namespace daq;

static ModulePtr CreateClientOpcUaModule(const ContextPtr& context)
{
ModulePtr module;
createOpcUaClientModule(&module, context);
return module;
}

static InstancePtr CreateServerInstance()
{
auto instance = InstanceBuilder().setDefaultRootDeviceLocalId("local").build();
ContextPtr context = instance.getContext();
ModuleManagerPtr manager = instance.getModuleManager();

manager.addModule(ModulePtr(MockDeviceModule_Create(context)));
manager.addModule(ModulePtr(MockFunctionBlockModule_Create(context)));

instance.addDevice("daqmock://phys_device");
instance.addFunctionBlock("mock_fb_uid");
instance.addServer("OpenDAQOPCUA", nullptr);
return instance;
}

static InstancePtr CreateClientInstance()
{
auto instance = InstanceBuilder().setModulePath("[[none]]").build();
ContextPtr context = instance.getContext();
ModuleManagerPtr manager = instance.getModuleManager();

manager.addModule(CreateClientOpcUaModule(context));

auto config = instance.createDefaultAddDeviceConfig();
PropertyObjectPtr general = config.getPropertyValue("General");
general.setPropertyValue("StreamingConnectionHeuristic", 2);

instance.addDevice("daq.opcua://127.0.0.1", config);
return instance;
}

TEST_F(OpcuaDeviceModulesTest, ComponentActiveChangedRecursive)
{
auto server = CreateServerInstance();
auto client = CreateClientInstance();

// Get the client's mirror of server device (this is a root device)
auto clientDevice = client.getDevices()[0];

// Get all components in clientDevice subtree
auto clientDeviceComponents = clientDevice.getItems(search::Recursive(search::Any()));

// Set client (Instance) active to false
client.setActive(false);

// client itself should be inactive
ASSERT_FALSE(client.getActive()) << "client should be inactive";

// clientDevice should still be active (it's a root device, doesn't receive parentActive)
ASSERT_TRUE(clientDevice.getActive()) << "clientDevice should remain active as it's a root device";

// All clientDevice subtree components should still be active
for (const auto& comp : clientDeviceComponents)
ASSERT_TRUE(comp.getActive()) << "Component should be active: " << comp.getGlobalId();
}

TEST_F(OpcuaDeviceModulesTest, ComponentActiveChangedRecursiveGateway)
{
// Create leaf server
auto leaf = InstanceBuilder().setDefaultRootDeviceLocalId("leaf").build();
leaf.addServer("OpenDAQOPCUA", nullptr);

// Create gateway that connects to leaf
auto gateway = Instance();
auto gatewayServerConfig = gateway.getAvailableServerTypes().get("OpenDAQOPCUA").createDefaultConfig();
gatewayServerConfig.setPropertyValue("Port", 4841);
gateway.addDevice("daq.opcua://127.0.0.1");
gateway.addServer("OpenDAQOPCUA", gatewayServerConfig);

// Create client that connects to gateway
auto client = Instance();
auto clientGatewayDevice = client.addDevice("daq.opcua://127.0.0.1:4841");

// Get the leaf device through gateway
auto clientLeafDevice = clientGatewayDevice.getDevices()[0];

// Set clientGatewayDevice active to false (from client side)
clientGatewayDevice.setActive(false);

// clientGatewayDevice itself should be inactive
ASSERT_FALSE(clientGatewayDevice.getActive()) << "clientGatewayDevice should be inactive";

// clientLeafDevice should still be active (it's a root device)
ASSERT_TRUE(clientLeafDevice.getActive()) << "clientLeafDevice should remain active as it's a root device";
}
2 changes: 1 addition & 1 deletion opendaq_ref
Original file line number Diff line number Diff line change
@@ -1 +1 @@
main
other/rework_active_attr
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ target_link_libraries(${TEST_APP} PRIVATE ${OPENDAQ_SDK_TARGET_NAMESPACE}::opcua
${OPENDAQ_SDK_TARGET_NAMESPACE}::opcuatms_server
${OPENDAQ_SDK_TARGET_NAMESPACE}::opcuatms_client
${OPENDAQ_SDK_TARGET_NAMESPACE}::opendaq_mocks
${BCRYPT_LIB}
${BCRYPT_LIB}
)

if(SUPPORTS_ASAN)
Expand Down
Loading