mirror of
https://github.com/open62541/open62541.git
synced 2025-06-03 04:00:21 +00:00
feat(tests): Add a test scaffoling for client discovery functionality
This commit is contained in:
parent
c6e0a7a7fa
commit
e250b5c9dd
@ -538,6 +538,11 @@ add_executable(check_client client/check_client.c $<TARGET_OBJECTS:open62541-obj
|
||||
target_link_libraries(check_client ${LIBS})
|
||||
add_test_valgrind(client ${TESTS_BINARY_DIR}/check_client)
|
||||
|
||||
add_executable(check_client_discovery client/check_client_discovery.c
|
||||
$<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
|
||||
target_link_libraries(check_client_discovery ${LIBS})
|
||||
add_test_valgrind(client ${TESTS_BINARY_DIR}/check_client_discovery)
|
||||
|
||||
add_executable(check_client_securechannel client/check_client_securechannel.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
|
||||
target_link_libraries(check_client_securechannel ${LIBS})
|
||||
add_test_valgrind(client_securechannel ${TESTS_BINARY_DIR}/check_client_securechannel)
|
||||
|
80
tests/client/check_client_discovery.c
Normal file
80
tests/client/check_client_discovery.c
Normal file
@ -0,0 +1,80 @@
|
||||
/* 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 <open62541/client_config_default.h>
|
||||
#include <open62541/server_config_default.h>
|
||||
|
||||
#include "client/ua_client_internal.h"
|
||||
|
||||
#include <check.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "thread_wrapper.h"
|
||||
|
||||
UA_Server *server;
|
||||
UA_Boolean running;
|
||||
UA_ServerNetworkLayer nl;
|
||||
THREAD_HANDLE server_thread;
|
||||
|
||||
|
||||
THREAD_CALLBACK(serverloop) {
|
||||
while(running)
|
||||
UA_Server_run_iterate(server, true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void setup(void) {
|
||||
running = true;
|
||||
server = UA_Server_new();
|
||||
UA_ServerConfig_setDefault(UA_Server_getConfig(server));
|
||||
UA_Server_run_startup(server);
|
||||
THREAD_CREATE(server_thread, serverloop);
|
||||
}
|
||||
|
||||
static void teardown(void) {
|
||||
running = false;
|
||||
THREAD_JOIN(server_thread);
|
||||
UA_Server_run_shutdown(server);
|
||||
UA_Server_delete(server);
|
||||
}
|
||||
|
||||
START_TEST(Client_connect_badEndpointUrl) {
|
||||
UA_Client *client = UA_Client_new();
|
||||
UA_ClientConfig_setDefault(UA_Client_getConfig(client));
|
||||
|
||||
/* Use the internal API to force a bad DiscoveryUrl */
|
||||
UA_String_clear(&client->endpointUrl);
|
||||
UA_String_clear(&client->discoveryUrl);
|
||||
client->endpointUrl = UA_STRING_ALLOC("opc.tcp://localhost:4840");
|
||||
client->discoveryUrl = UA_STRING_ALLOC("abc://xxx:4840");
|
||||
|
||||
/* Open a Session when possible */
|
||||
client->noSession = false;
|
||||
|
||||
UA_StatusCode res = connectSync(client);
|
||||
ck_assert_uint_eq(res, UA_STATUSCODE_GOOD);
|
||||
|
||||
UA_Client_disconnect(client);
|
||||
UA_Client_delete(client);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
static Suite* testSuite_Client(void) {
|
||||
Suite *s = suite_create("Client");
|
||||
TCase *tc_client = tcase_create("Client Discovery");
|
||||
tcase_add_checked_fixture(tc_client, setup, teardown);
|
||||
tcase_add_test(tc_client, Client_connect_badEndpointUrl);
|
||||
suite_add_tcase(s,tc_client);
|
||||
return s;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user