feat(tests): Add check_yxml.c unit test

This commit is contained in:
Julius Pfrommer 2025-02-28 23:14:52 +01:00 committed by Julius Pfrommer
parent ffd5330245
commit 05c3e632c1
3 changed files with 40 additions and 3 deletions

View File

@ -951,16 +951,15 @@ if(UA_ENABLE_XML_ENCODING)
unset(LIBXML2_LIBRARIES)
set(LIBXML2_LIBRARIES ${LIBXML2_LIBRARIES_32BIT})
endif()
set(ua_architecture_directories_to_include
${ua_architecture_directories_to_include}
${LIBXML2_INCLUDE_DIRS})
list(APPEND open62541_LIBRARIES ${LIBXML2_LIBRARIES})
endif()
if(NOT UA_ENABLE_JSON_ENCODING)
list(APPEND lib_headers ${PROJECT_SOURCE_DIR}/deps/parse_num.h)
list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/deps/parse_num.c)
endif()
list(APPEND lib_headers ${PROJECT_SOURCE_DIR}/deps/yxml.h)
list(APPEND lib_headers ${PROJECT_SOURCE_DIR}/src/ua_types_encoding_xml.h)
list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/deps/yxml.c)
list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/ua_types_encoding_xml.c)
endif()
@ -1384,6 +1383,10 @@ endfunction()
include_directories_private("${PROJECT_SOURCE_DIR}/deps")
if(UA_ENABLE_XML_ENCODING)
include_directories_private(${LIBXML2_INCLUDE_DIRS})
endif()
if(UA_ENABLE_ENCRYPTION_MBEDTLS)
include_directories_private(${MBEDTLS_INCLUDE_DIRS})
endif()

View File

@ -174,6 +174,7 @@ if(UA_ENABLE_JSON_ENCODING)
endif()
if(UA_ENABLE_XML_ENCODING)
ua_add_test(check_yxml.c)
ua_add_test(check_types_builtin_xml.c)
endif()

33
tests/check_yxml.c Normal file
View File

@ -0,0 +1,33 @@
/* 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 "ua_types_encoding_xml.h"
#include <check.h>
START_TEST(parseElement) {
const char *xml = "<test attr1=\"attr\">my-content</test>";
xml_token tokens[32];
xml_result r = xml_tokenize(xml, (unsigned int)strlen(xml), tokens, 32);
ck_assert(r.error == XML_ERROR_NONE);
} END_TEST
static Suite *testSuite_yxml(void) {
TCase *tc_parse= tcase_create("yxml_parse");
tcase_add_test(tc_parse, parseElement);
Suite *s = suite_create("Test XML decoding with the yxml library");
suite_add_tcase(s, tc_parse);
return s;
}
int main(void) {
int number_failed = 0;
Suite *s = testSuite_yxml();
SRunner *sr = srunner_create(s);
srunner_set_fork_status(sr, CK_NOFORK);
srunner_run_all(sr, CK_NORMAL);
number_failed += srunner_ntests_failed(sr);
srunner_free(sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}