Skip to content

Commit

Permalink
Add test for UA_Server_deleteCondition
Browse files Browse the repository at this point in the history
  • Loading branch information
ccvca authored and jpfr committed Jun 7, 2020
1 parent 1e29c33 commit a524acc
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,12 @@ if(UA_ENABLE_SUBSCRIPTIONS)
add_test_no_valgrind(server_monitoringspeed ${TESTS_BINARY_DIR}/check_server_monitoringspeed)
endif()

if(UA_ENABLE_SUBSCRIPTIONS_ALARMS_CONDITIONS)
add_executable(check_server_alarmsconditions server/check_server_alarmsconditions.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
target_link_libraries(check_server_alarmsconditions ${LIBS})
add_test_no_valgrind(check_server_alarmsconditions ${TESTS_BINARY_DIR}/check_server_alarmsconditions)
endif()

if(UA_ENABLE_ASYNCOPERATIONS)
add_executable(check_server_asyncop server/check_server_asyncop.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
target_link_libraries(check_server_asyncop ${LIBS})
Expand Down
72 changes: 72 additions & 0 deletions tests/server/check_server_alarmsconditions.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/.
*
* Copyright 2020 (c) Christian von Arnim
*/

#include <open62541/server.h>
#include <open62541/server_config_default.h>

#include <check.h>

UA_Server *server_ac;


static void setup(void) {
server_ac = UA_Server_new();
UA_ServerConfig_setDefault(UA_Server_getConfig(server_ac));
}

static void teardown(void) {
UA_Server_delete(server_ac);
}

#ifdef UA_ENABLE_SUBSCRIPTIONS_ALARMS_CONDITIONS

START_TEST(createDelete) {
UA_StatusCode retval;
// Loop to increase the chance of capturing dead pointers
for(UA_UInt16 i = 0; i < 3; ++i)
{
UA_NodeId conditionInstance = UA_NODEID_NULL;

retval = UA_Server_createCondition(
server_ac,
UA_NODEID_NULL,
UA_NODEID_NUMERIC(0, UA_NS0ID_OFFNORMALALARMTYPE),
UA_QUALIFIEDNAME(0, "Condition createDelete"),
UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER),
UA_NODEID_NULL,
&conditionInstance);
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
ck_assert_msg(!UA_NodeId_isNull(&conditionInstance), "ConditionId is null");

UA_Server_deleteCondition(
server_ac,
conditionInstance,
UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER)
);
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
}
} END_TEST
#endif

int main(void) {
Suite *s = suite_create("server_alarmcondition");

TCase *tc_call = tcase_create("Alarms and Conditions");
#ifdef UA_ENABLE_SUBSCRIPTIONS_ALARMS_CONDITIONS
tcase_add_test(tc_call, createDelete);
#endif
tcase_add_checked_fixture(tc_call, setup, teardown);

suite_add_tcase(s, tc_call);

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;
}

0 comments on commit a524acc

Please sign in to comment.