소스 검색

Add a few basic tests for functionality in ua_server.c

Frank Meerkoetter 5 년 전
부모
커밋
1cb21cf536
2개의 변경된 파일68개의 추가작업 그리고 0개의 파일을 삭제
  1. 4 0
      tests/CMakeLists.txt
  2. 64 0
      tests/server/check_server.c

+ 4 - 0
tests/CMakeLists.txt

@@ -204,6 +204,10 @@ add_executable(check_session server/check_session.c $<TARGET_OBJECTS:open62541-o
 target_link_libraries(check_session ${LIBS})
 add_test_valgrind(session ${TESTS_BINARY_DIR}/check_session)
 
+add_executable(check_server server/check_server.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
+target_link_libraries(check_server ${LIBS})
+add_test_valgrind(server ${TESTS_BINARY_DIR}/check_server)
+
 add_executable(check_server_jobs server/check_server_jobs.c $<TARGET_OBJECTS:open62541-object> $<TARGET_OBJECTS:open62541-testplugins>)
 target_link_libraries(check_server_jobs ${LIBS})
 add_test_valgrind(server_jobs ${TESTS_BINARY_DIR}/check_server_jobs)

+ 64 - 0
tests/server/check_server.c

@@ -0,0 +1,64 @@
+/* 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 2019 (c) basysKom GmbH <opensource@basyskom.com> (Author: Frank Meerkötter)
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include "check.h"
+#include "server/ua_services.h"
+#include "ua_client.h"
+#include "ua_types.h"
+#include "ua_config_default.h"
+#include "server/ua_server_internal.h"
+
+static UA_Server *server = NULL;
+static UA_ServerConfig *config = NULL;
+
+static void setup(void) {
+    config = UA_ServerConfig_new_default();
+    server = UA_Server_new(config);
+}
+
+static void teardown(void) {
+    UA_Server_delete(server);
+    UA_ServerConfig_delete(config);
+}
+
+START_TEST(checkGetConfig) {
+    ck_assert_ptr_eq(UA_Server_getConfig(NULL), NULL);
+    ck_assert_ptr_ne(UA_Server_getConfig(server), NULL);
+} END_TEST
+
+START_TEST(checkGetNamespaceByName) {
+    size_t notFoundIndex = -1;
+    UA_StatusCode notFound = UA_Server_getNamespaceByName(server, UA_STRING("http://opcfoundation.org/UA/invalid"), &notFoundIndex);
+    ck_assert_int_eq(notFoundIndex, -1); // not changed
+    ck_assert_int_eq(notFound, UA_STATUSCODE_BADNOTFOUND);
+
+    size_t foundIndex = -1;
+    UA_StatusCode found = UA_Server_getNamespaceByName(server, UA_STRING("http://opcfoundation.org/UA/"), &foundIndex);
+    ck_assert_int_eq(foundIndex, 0); // this namespace always has index 0 (defined by the standard)
+    ck_assert_int_eq(found, UA_STATUSCODE_GOOD);
+} END_TEST
+
+int main(void) {
+    Suite *s = suite_create("server");
+
+    TCase *tc_call = tcase_create("server - basics");
+    tcase_add_checked_fixture(tc_call, setup, teardown);
+    tcase_add_test(tc_call, checkGetConfig);
+    tcase_add_test(tc_call, checkGetNamespaceByName);
+    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;
+}