Skip to content

Commit

Permalink
Tests for checking the SecondChance algorithm.
Browse files Browse the repository at this point in the history
  • Loading branch information
xydan83 committed Dec 11, 2023
1 parent e4a3eed commit f9ef032
Show file tree
Hide file tree
Showing 5 changed files with 558 additions and 0 deletions.
14 changes: 14 additions & 0 deletions backends/open62541/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,20 @@ add_test(NAME conversion_Test
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND conversion)

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

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

if(${ENABLE_DATATYPEIMPORT_TEST})
add_subdirectory(dataTypeImport)
endif()
Expand Down
72 changes: 72 additions & 0 deletions backends/open62541/tests/issue_246.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* 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>

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_246)
{
ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL));

UA_Variant var;
UA_Variant_init(&var);
// Check if the last node in the chain exists. It should be.
UA_StatusCode retval = UA_Server_readValue(
server, UA_NODEID_STRING(2, "Test.Var4"), &var);
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
UA_Variant_clear(&var);
}
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_246);
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;
}
68 changes: 68 additions & 0 deletions backends/open62541/tests/issue_246.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?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:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://opcfoundation.org/UA/2011/03/UANodeSet.xsd">
<NamespaceUris>
<Uri>http://test/object_node/to/variable_node/parent/connection</Uri>
</NamespaceUris>
<Aliases>
<Alias Alias="Byte">i=3</Alias>
<Alias Alias="HasComponent">i=47</Alias>
<Alias Alias="HasProperty">i=46</Alias>
<Alias Alias="HasTypeDefinition">i=40</Alias>
<Alias Alias="Organizes">i=35</Alias>
</Aliases>
<UAVariable NodeId="ns=2;s=Test.Var1" BrowseName="2:Test.Var1" ParentNodeId="i=85" DataType="Byte">
<DisplayName>Test.Var1</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
<Reference ReferenceType="Organizes" IsForward="false">i=85</Reference>
<Reference ReferenceType="HasComponent">ns=2;s=Test.Obj1</Reference>
</References>
</UAVariable>
<UAObject NodeId="ns=2;s=Test.Obj1" BrowseName="2:Test.Obj1" ParentNodeId="ns=2;s=Test.Var1">
<DisplayName>Test.Obj1</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=61</Reference>
<Reference ReferenceType="HasProperty">ns=2;s=Test.Var2</Reference>
<Reference ReferenceType="HasComponent" IsForward="false">ns=2;s=Test.Var1</Reference>
</References>
</UAObject>
<UAVariable NodeId="ns=2;s=Test.Var2" BrowseName="2:Test.Var2" ParentNodeId="ns=2;s=Test.Obj1" DataType="Byte">
<DisplayName>Test.Var2</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
<Reference ReferenceType="HasProperty" IsForward="false">ns=2;s=Test.Obj1</Reference>
<Reference ReferenceType="HasComponent">ns=2;s=Test.Obj2</Reference>
</References>
</UAVariable>
<UAObject NodeId="ns=2;s=Test.Obj2" BrowseName="2:Test.Obj2" ParentNodeId="ns=2;s=Test.Var2">
<DisplayName>Test.Obj2</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=61</Reference>
<Reference ReferenceType="HasProperty">ns=2;s=Test.Var3</Reference>
<Reference ReferenceType="HasComponent" IsForward="false">ns=2;s=Test.Var2</Reference>
</References>
</UAObject>
<UAVariable NodeId="ns=2;s=Test.Var3" BrowseName="2:Test.Var3" ParentNodeId="ns=2;s=Test.Obj2" DataType="Byte">
<DisplayName>Test.Var3</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
<Reference ReferenceType="HasProperty" IsForward="false">ns=2;s=Test.Obj2</Reference>
<Reference ReferenceType="HasComponent">ns=2;s=Test.Obj3</Reference>
</References>
</UAVariable>
<UAObject NodeId="ns=2;s=Test.Obj3" BrowseName="2:Test.Obj3" ParentNodeId="ns=2;s=Test.Var3">
<DisplayName>Test.Obj3</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=61</Reference>
<Reference ReferenceType="HasProperty">ns=2;s=Test.Var4</Reference>
<Reference ReferenceType="HasComponent" IsForward="false">ns=2;s=Test.Var3</Reference>
</References>
</UAObject>
<UAVariable NodeId="ns=2;s=Test.Var4" BrowseName="2:Test.Var4" ParentNodeId="ns=2;s=Test.Obj3" DataType="Byte">
<DisplayName>Test.Var4</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
<Reference ReferenceType="HasProperty" IsForward="false">ns=2;s=Test.Obj3</Reference>
</References>
</UAVariable>
</UANodeSet>
97 changes: 97 additions & 0 deletions backends/open62541/tests/issue_246_2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* 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>

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_246)
{
ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL));
// Check if [Object Type] nodes exist with a HasHistoricalConfiguration type inverse reference to the Variable nodes.
UA_NodeClass node_class;
UA_NodeClass_init(&node_class);
UA_StatusCode retval = UA_Server_readNodeClass(
server, UA_NODEID_STRING(2, "History1.HistoricalDataConfiguration"), &node_class);
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
ck_assert_uint_eq(node_class, UA_NODECLASS_OBJECT);
UA_NodeClass_clear(&node_class);

ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL));
UA_NodeClass_init(&node_class);
retval = UA_Server_readNodeClass(
server, UA_NODEID_STRING(2, "History2.HistoricalDataConfiguration"), &node_class);
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
ck_assert_uint_eq(node_class, UA_NODECLASS_OBJECT);
UA_NodeClass_clear(&node_class);

ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL));
UA_NodeClass_init(&node_class);
retval = UA_Server_readNodeClass(
server, UA_NODEID_STRING(2, "History3.HistoricalDataConfiguration"), &node_class);
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
ck_assert_uint_eq(node_class, UA_NODECLASS_OBJECT);
UA_NodeClass_clear(&node_class);


ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL));
UA_NodeClass_init(&node_class);
retval = UA_Server_readNodeClass(
server, UA_NODEID_STRING(2, "History4.HistoricalDataConfiguration"), &node_class);
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
ck_assert_uint_eq(node_class, UA_NODECLASS_OBJECT);
UA_NodeClass_clear(&node_class);
}
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_246);
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;
}
Loading

0 comments on commit f9ef032

Please sign in to comment.