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