Skip to content

Commit

Permalink
add tests and fix issue_241
Browse files Browse the repository at this point in the history
  • Loading branch information
matkonnerth committed Nov 25, 2023
1 parent aa5754d commit 74daf75
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 3 deletions.
17 changes: 14 additions & 3 deletions backends/open62541/src/Value.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,19 @@ static void setUnion(const NL_Data *value, const UA_DataType *type, RawData *dat
}
}

static void setStatusCode(const NL_Data *value, RawData *data)
{
// StatusCode is a complex type with a primitive
assert(value->type == DATATYPE_COMPLEX);
if (value->val.complexData.membersSize == 1)
{
NL_Data *code = value->val.complexData.members[0];
setPrimitiveValue(
data, code->val.primitiveData.value, UA_DATATYPEKIND_UINT32,
UA_TYPES[UA_TYPES_UINT32].memSize);
}
}

static void setScalar(const NL_Data *value, const UA_DataType *type, RawData *data,
const UA_DataType *customTypes, const ServerContext *serverContext)
{
Expand Down Expand Up @@ -405,9 +418,7 @@ static void setScalar(const NL_Data *value, const UA_DataType *type, RawData *da
}
else if (type->typeKind == UA_DATATYPEKIND_STATUSCODE)
{
setPrimitiveValue(data, value->val.primitiveData.value,
UA_DATATYPEKIND_UINT32,
UA_TYPES[UA_TYPES_UINT32].memSize);
setStatusCode(value, data);
}
else
{
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 @@ -47,6 +47,13 @@ add_test(NAME issue_201_Test
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND issue_201 ${CMAKE_CURRENT_SOURCE_DIR}/issue_201.xml)

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

add_executable(stringNodeId_issue_224 stringNodeId_issue_224.c)
target_include_directories(stringNodeId_issue_224 PRIVATE ${CHECK_INCLUDE_DIR})
target_link_libraries(stringNodeId_issue_224 PRIVATE NodesetLoader open62541::open62541 ${CHECK_LIBRARIES} ${PTHREAD_LIB})
Expand Down
83 changes: 83 additions & 0 deletions backends/open62541/tests/issue_241.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* 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_241)
{
ck_assert(NodesetLoader_loadFile(server, nodesetPath, NULL));

UA_Variant var;
UA_Variant_init(&var);
UA_StatusCode retval = UA_Server_readValue(
server, UA_NODEID_STRING(2, "Demo.Static.Arrays.StatusCode"), &var);
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);

ck_assert(var.type = &UA_TYPES[UA_TYPES_STATUSCODE]);
ck_assert(var.arrayLength==10);

UA_StatusCode *first = (UA_StatusCode*)var.data;
ck_assert(*first == 0u);
UA_StatusCode last = first[9];
ck_assert(last == 2151022592u);

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_241);
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;
}
82 changes: 82 additions & 0 deletions backends/open62541/tests/issue_241.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?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://www.unifiedautomation.com/DemoServer/</Uri>
</NamespaceUris>
<Aliases>
<Alias Alias="Boolean">i=1</Alias>
<Alias Alias="SByte">i=2</Alias>
<Alias Alias="Byte">i=3</Alias>
<Alias Alias="Int16">i=4</Alias>
<Alias Alias="UInt16">i=5</Alias>
<Alias Alias="Int32">i=6</Alias>
<Alias Alias="UInt32">i=7</Alias>
<Alias Alias="Int64">i=8</Alias>
<Alias Alias="UInt64">i=9</Alias>
<Alias Alias="Float">i=10</Alias>
<Alias Alias="Double">i=11</Alias>
<Alias Alias="String">i=12</Alias>
<Alias Alias="DateTime">i=13</Alias>
<Alias Alias="Guid">i=14</Alias>
<Alias Alias="ByteString">i=15</Alias>
<Alias Alias="XmlElement">i=16</Alias>
<Alias Alias="NodeId">i=17</Alias>
<Alias Alias="ExpandedNodeId">i=18</Alias>
<Alias Alias="StatusCode">i=19</Alias>
<Alias Alias="QualifiedName">i=20</Alias>
<Alias Alias="LocalizedText">i=21</Alias>
<Alias Alias="Structure">i=22</Alias>
<Alias Alias="BaseDataType">i=24</Alias>
<Alias Alias="Number">i=26</Alias>
<Alias Alias="Integer">i=27</Alias>
<Alias Alias="UInteger">i=28</Alias>
<Alias Alias="Organizes">i=35</Alias>
<Alias Alias="HasTypeDefinition">i=40</Alias>
<Alias Alias="Duration">i=290</Alias>
<Alias Alias="NumericRange">i=291</Alias>
<Alias Alias="UtcTime">i=294</Alias>
<Alias Alias="ServerState">i=852</Alias>
<Alias Alias="ImagePNG">i=2003</Alias>
</Aliases>
<UAVariable NodeId="ns=1;s=Demo.Static.Arrays.StatusCode" BrowseName="1:StatusCode" ParentNodeId="i=85" ValueRank="1" ArrayDimensions="10" DataType="StatusCode" AccessLevel="3" UserAccessLevel="3">
<DisplayName>StatusCode</DisplayName>
<References>
<Reference ReferenceType="HasTypeDefinition">i=63</Reference>
<Reference ReferenceType="Organizes" IsForward="false">i=85</Reference>
</References>
<Value>
<uax:ListOfStatusCode>
<uax:StatusCode>
<uax:Code>0</uax:Code>
</uax:StatusCode>
<uax:StatusCode>
<uax:Code>2150694912</uax:Code>
</uax:StatusCode>
<uax:StatusCode>
<uax:Code>2150825984</uax:Code>
</uax:StatusCode>
<uax:StatusCode>
<uax:Code>2151022592</uax:Code>
</uax:StatusCode>
<uax:StatusCode>
<uax:Code>2151284736</uax:Code>
</uax:StatusCode>
<uax:StatusCode>
<uax:Code>2151677952</uax:Code>
</uax:StatusCode>
<uax:StatusCode>
<uax:Code>0</uax:Code>
</uax:StatusCode>
<uax:StatusCode>
<uax:Code>2150694912</uax:Code>
</uax:StatusCode>
<uax:StatusCode>
<uax:Code>2150825984</uax:Code>
</uax:StatusCode>
<uax:StatusCode>
<uax:Code>2151022592</uax:Code>
</uax:StatusCode>
</uax:ListOfStatusCode>
</Value>
</UAVariable>
</UANodeSet>

0 comments on commit 74daf75

Please sign in to comment.