diff --git a/backends/open62541/src/Value.c b/backends/open62541/src/Value.c index d525021..59bd496 100644 --- a/backends/open62541/src/Value.c +++ b/backends/open62541/src/Value.c @@ -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) { @@ -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 { diff --git a/backends/open62541/tests/CMakeLists.txt b/backends/open62541/tests/CMakeLists.txt index 16705f9..0bdd204 100644 --- a/backends/open62541/tests/CMakeLists.txt +++ b/backends/open62541/tests/CMakeLists.txt @@ -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}) diff --git a/backends/open62541/tests/issue_241.c b/backends/open62541/tests/issue_241.c new file mode 100644 index 0000000..9da1e2a --- /dev/null +++ b/backends/open62541/tests/issue_241.c @@ -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 +#include +#include +#include +#include + +#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; +} diff --git a/backends/open62541/tests/issue_241.xml b/backends/open62541/tests/issue_241.xml new file mode 100644 index 0000000..6048f19 --- /dev/null +++ b/backends/open62541/tests/issue_241.xml @@ -0,0 +1,82 @@ + + + + http://www.unifiedautomation.com/DemoServer/ + + + i=1 + i=2 + i=3 + i=4 + i=5 + i=6 + i=7 + i=8 + i=9 + i=10 + i=11 + i=12 + i=13 + i=14 + i=15 + i=16 + i=17 + i=18 + i=19 + i=20 + i=21 + i=22 + i=24 + i=26 + i=27 + i=28 + i=35 + i=40 + i=290 + i=291 + i=294 + i=852 + i=2003 + + + StatusCode + + i=63 + i=85 + + + + + 0 + + + 2150694912 + + + 2150825984 + + + 2151022592 + + + 2151284736 + + + 2151677952 + + + 0 + + + 2150694912 + + + 2150825984 + + + 2151022592 + + + + + \ No newline at end of file