Skip to content

Commit a524acc

Browse files
ccvcajpfr
authored andcommitted
Add test for UA_Server_deleteCondition
1 parent 1e29c33 commit a524acc

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

tests/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,12 @@ if(UA_ENABLE_SUBSCRIPTIONS)
429429
add_test_no_valgrind(server_monitoringspeed ${TESTS_BINARY_DIR}/check_server_monitoringspeed)
430430
endif()
431431

432+
if(UA_ENABLE_SUBSCRIPTIONS_ALARMS_CONDITIONS)
433+
add_executable(check_server_alarmsconditions server/check_server_alarmsconditions.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
434+
target_link_libraries(check_server_alarmsconditions ${LIBS})
435+
add_test_no_valgrind(check_server_alarmsconditions ${TESTS_BINARY_DIR}/check_server_alarmsconditions)
436+
endif()
437+
432438
if(UA_ENABLE_ASYNCOPERATIONS)
433439
add_executable(check_server_asyncop server/check_server_asyncop.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
434440
target_link_libraries(check_server_asyncop ${LIBS})
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
*
5+
* Copyright 2020 (c) Christian von Arnim
6+
*/
7+
8+
#include <open62541/server.h>
9+
#include <open62541/server_config_default.h>
10+
11+
#include <check.h>
12+
13+
UA_Server *server_ac;
14+
15+
16+
static void setup(void) {
17+
server_ac = UA_Server_new();
18+
UA_ServerConfig_setDefault(UA_Server_getConfig(server_ac));
19+
}
20+
21+
static void teardown(void) {
22+
UA_Server_delete(server_ac);
23+
}
24+
25+
#ifdef UA_ENABLE_SUBSCRIPTIONS_ALARMS_CONDITIONS
26+
27+
START_TEST(createDelete) {
28+
UA_StatusCode retval;
29+
// Loop to increase the chance of capturing dead pointers
30+
for(UA_UInt16 i = 0; i < 3; ++i)
31+
{
32+
UA_NodeId conditionInstance = UA_NODEID_NULL;
33+
34+
retval = UA_Server_createCondition(
35+
server_ac,
36+
UA_NODEID_NULL,
37+
UA_NODEID_NUMERIC(0, UA_NS0ID_OFFNORMALALARMTYPE),
38+
UA_QUALIFIEDNAME(0, "Condition createDelete"),
39+
UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER),
40+
UA_NODEID_NULL,
41+
&conditionInstance);
42+
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
43+
ck_assert_msg(!UA_NodeId_isNull(&conditionInstance), "ConditionId is null");
44+
45+
UA_Server_deleteCondition(
46+
server_ac,
47+
conditionInstance,
48+
UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER)
49+
);
50+
ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
51+
}
52+
} END_TEST
53+
#endif
54+
55+
int main(void) {
56+
Suite *s = suite_create("server_alarmcondition");
57+
58+
TCase *tc_call = tcase_create("Alarms and Conditions");
59+
#ifdef UA_ENABLE_SUBSCRIPTIONS_ALARMS_CONDITIONS
60+
tcase_add_test(tc_call, createDelete);
61+
#endif
62+
tcase_add_checked_fixture(tc_call, setup, teardown);
63+
64+
suite_add_tcase(s, tc_call);
65+
66+
SRunner *sr = srunner_create(s);
67+
srunner_set_fork_status(sr, CK_NOFORK);
68+
srunner_run_all(sr, CK_NORMAL);
69+
int number_failed = srunner_ntests_failed(sr);
70+
srunner_free(sr);
71+
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
72+
}

0 commit comments

Comments
 (0)