Skip to content

Commit

Permalink
add variableTypes before objects, consider ParentNodeId for parent re…
Browse files Browse the repository at this point in the history
…ferences
  • Loading branch information
matkonnerth committed Feb 6, 2023
1 parent a4a7ce0 commit 3760a45
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 19 deletions.
2 changes: 1 addition & 1 deletion backends/open62541/src/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ static void addNodes(NodesetLoader *loader, ServerContext *serverContext,
{
const NL_NodeClass order[NL_NODECLASS_COUNT] = {
NODECLASS_REFERENCETYPE, NODECLASS_DATATYPE, NODECLASS_OBJECTTYPE,
NODECLASS_OBJECT, NODECLASS_METHOD, NODECLASS_VARIABLETYPE,
NODECLASS_VARIABLETYPE, NODECLASS_OBJECT, NODECLASS_METHOD,
NODECLASS_VARIABLE, NODECLASS_VIEW};

for (size_t i = 0; i < NL_NODECLASS_COUNT; i++)
Expand Down
7 changes: 7 additions & 0 deletions backends/open62541/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ add_test(NAME basicNodeClasses_Test
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND basicNodeClasses ${CMAKE_CURRENT_SOURCE_DIR}/basicNodeClasses.xml)

add_executable(issue_201 issue_201.c)
target_include_directories(issue_201 PRIVATE ${CHECK_INCLUDE_DIR})
target_link_libraries(issue_201 PRIVATE NodesetLoader open62541::open62541 ${CHECK_LIBRARIES} ${PTHREAD_LIB})
add_test(NAME issue_201_Test
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND issue_201 ${CMAKE_CURRENT_SOURCE_DIR}/issue_201.xml)

add_executable(cornerCases cornerCases.c)
target_include_directories(cornerCases PRIVATE ${CHECK_INCLUDE_DIR})
target_link_libraries(cornerCases PRIVATE NodesetLoader open62541::open62541 ${CHECK_LIBRARIES} ${PTHREAD_LIB})
Expand Down
76 changes: 76 additions & 0 deletions backends/open62541/tests/issue_201.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "check.h"
#include <NodesetLoader/backendOpen62541.h>
#include <NodesetLoader/dataTypes.h>
#include <open62541/server.h>
#include <open62541/server_config_default.h>
#include <open62541/types.h>

#include "testHelper.h"

UA_Server *server;
char *nodesetPath = NULL;

static void setup(void)
{
printf("path to testnodesets %s\n", nodesetPath);
server = UA_Server_new();
UA_ServerConfig *config = UA_Server_getConfig(server);
UA_ServerConfig_setDefault(config);
}

static void teardown(void)
{
UA_Server_run_shutdown(server);
#ifdef USE_CLEANUP_CUSTOM_DATATYPES
const UA_DataTypeArray *customTypes =
UA_Server_getConfig(server)->customDataTypes;
#endif
UA_Server_delete(server);
#ifdef USE_CLEANUP_CUSTOM_DATATYPES
NodesetLoader_cleanupCustomDataTypes(customTypes);
#endif
}

START_TEST(Server_Issue_201)
{
ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL));

ck_assert(hasReference(
server, UA_NODEID_NUMERIC(2, 5000), UA_NODEID_NUMERIC(2, 4000),
UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT), UA_BROWSEDIRECTION_INVERSE));

ck_assert(hasReference(server, UA_NODEID_NUMERIC(2, 6000),
UA_NODEID_NUMERIC(2, 4000),
UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
UA_BROWSEDIRECTION_INVERSE));
}
END_TEST

static Suite *testSuite_Client(void)
{
Suite *s = suite_create("server nodeset import");
TCase *tc_server = tcase_create("server nodeset import");
tcase_add_unchecked_fixture(tc_server, setup, teardown);
tcase_add_test(tc_server, Server_Issue_201);
suite_add_tcase(s, tc_server);
return s;
}

int main(int argc, char *argv[])
{
printf("%s", argv[0]);
if (!(argc > 1))
return 1;
nodesetPath = argv[1];
Suite *s = testSuite_Client();
SRunner *sr = srunner_create(s);
srunner_set_fork_status(sr, CK_NOFORK);
srunner_run_all(sr, CK_NORMAL);
int number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
40 changes: 40 additions & 0 deletions backends/open62541/tests/issue_201.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<UANodeSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:uax="http://opcfoundation.org/UA/2008/02/Types.xsd" xmlns="http://opcfoundation.org/UA/2011/03/UANodeSet.xsd" xmlns:s1="http://yourorganisation.org/TestProjectsOpen/Types.xsd" xmlns:ua="http://unifiedautomation.com/Configuration/NodeSet.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<NamespaceUris>
<Uri>http://open62541.com/tests/issue_201/</Uri>
</NamespaceUris>
<Aliases>
<Alias Alias="Double">i=11</Alias>
<Alias Alias="String">i=12</Alias>
<Alias Alias="ByteString">i=15</Alias>
<Alias Alias="Organizes">i=35</Alias>
<Alias Alias="HasModellingRule">i=37</Alias>
<Alias Alias="HasEncoding">i=38</Alias>
<Alias Alias="HasDescription">i=39</Alias>
<Alias Alias="HasTypeDefinition">i=40</Alias>
<Alias Alias="HasSubtype">i=45</Alias>
<Alias Alias="HasProperty">i=46</Alias>
<Alias Alias="HasComponent">i=47</Alias>
<Alias Alias="Point">ns=1;i=3002</Alias>
</Aliases>
<UAObject NodeId="ns=1;i=4000" BrowseName="1:Parent">
<DisplayName>Parent</DisplayName>
<References>
<Reference ReferenceType="HasComponent" IsForward="false">i=85</Reference>
<Reference ReferenceType="HasComponent" IsForward="true">ns=1;i=5000</Reference>
</References>
</UAObject>
<UAObject NodeId="ns=1;i=5000" BrowseName="1:Child" ParentNodeId="ns=1;i=4000">
<DisplayName>Child</DisplayName>
<References>
<!--hierachical ref, but not to parent-->
<Reference ReferenceType="HasComponent" IsForward="true">ns=1;i=6000</Reference>
</References>
</UAObject>
<UAObject NodeId="ns=1;i=6000" BrowseName="1:Child2">
<DisplayName>Child2</DisplayName>
<References>
<Reference ReferenceType="HasComponent" IsForward="false">ns=1;i=4000</Reference>
</References>
</UAObject>
</UANodeSet>
35 changes: 17 additions & 18 deletions src/Sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,25 +294,24 @@ void Sort_addNode(SortContext *ctx, NL_Node *data) {
}
hierachicalRef = hierachicalRef->next;
}
} else {
// there are no hierachical refs on it, can we find the nodes
// referencing it? -> try it with parentNodeId
if (NodesetLoader_isInstanceNode(data)) {
NL_InstanceNode *instanceNode = (NL_InstanceNode *)data;
S_Node *k = search_node(ctx->root1, &instanceNode->parentNodeId);
if (k->data) {
NL_Reference *r = k->data->hierachicalRefs;
while (r) {
if (UA_NodeId_equal(&r->target, &data->id)) {
NL_Reference *newRef = (NL_Reference *)calloc(1, sizeof(NL_Reference));
newRef->isForward = !r->isForward;
newRef->target = k->data->id;
newRef->refType = r->refType;
data->hierachicalRefs = newRef;
break;
}
r = r->next;
}
// there are no hierachical refs on it, can we find the nodes
// referencing it? -> try it with parentNodeId
if (NodesetLoader_isInstanceNode(data)) {
NL_InstanceNode *instanceNode = (NL_InstanceNode *)data;
S_Node *k = search_node(ctx->root1, &instanceNode->parentNodeId);
if (k->data) {
NL_Reference *r = k->data->hierachicalRefs;
while (r) {
if (UA_NodeId_equal(&r->target, &data->id)) {
NL_Reference *newRef = (NL_Reference *)calloc(1, sizeof(NL_Reference));
newRef->isForward = !r->isForward;
newRef->target = k->data->id;
newRef->refType = r->refType;
data->hierachicalRefs = newRef;
break;
}
r = r->next;
}
}
}
Expand Down

0 comments on commit 3760a45

Please sign in to comment.