diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 04:20:26 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 04:20:26 +0000 |
commit | 044203039cebe3c05161f8f104a039d4744ca6d0 (patch) | |
tree | 1073c2308492e6aea4c66cb7436ee92db2abfd42 /tests/style | |
parent | Initial commit. (diff) | |
download | libyang2-044203039cebe3c05161f8f104a039d4744ca6d0.tar.xz libyang2-044203039cebe3c05161f8f104a039d4744ca6d0.zip |
Adding upstream version 2.1.30.upstream/2.1.30
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/style')
-rw-r--r-- | tests/style/CMakeLists.txt | 12 | ||||
-rw-r--r-- | tests/style/cpp_compat.c | 95 |
2 files changed, 107 insertions, 0 deletions
diff --git a/tests/style/CMakeLists.txt b/tests/style/CMakeLists.txt new file mode 100644 index 0000000..93d6049 --- /dev/null +++ b/tests/style/CMakeLists.txt @@ -0,0 +1,12 @@ +add_test(NAME headers + COMMAND ${CMAKE_SOURCE_DIR}/compat/check_includes.sh ${CMAKE_SOURCE_DIR}/src/ ${CMAKE_SOURCE_DIR}/tools/lint/ ${CMAKE_SOURCE_DIR}/tools/re/) + +if (${SOURCE_FORMAT_ENABLED}) + add_test(NAME format WORKING_DIRECTORY ${CMAKE_BINARY_DIR} COMMAND cmake --build ${CMAKE_BINARY_DIR} --target format-check) +endif() + +# just compile +add_executable(cpp_compat cpp_compat.c $<TARGET_OBJECTS:yangobj>) +target_include_directories(cpp_compat BEFORE PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(cpp_compat ${CMAKE_THREAD_LIBS_INIT} ${PCRE2_LIBRARIES} ${CMAKE_DL_LIBS} m) +target_compile_options(cpp_compat PUBLIC "-Werror=c++-compat") diff --git a/tests/style/cpp_compat.c b/tests/style/cpp_compat.c new file mode 100644 index 0000000..28a8ffd --- /dev/null +++ b/tests/style/cpp_compat.c @@ -0,0 +1,95 @@ +/** + * @file cpp_compat.c + * @author Michal Vasko <mvasko@cesnet.cz> + * @brief test for C++ compatibility of public headers (macros) + * + * Copyright (c) 2021 CESNET, z.s.p.o. + * + * This source code is licensed under BSD 3-Clause License (the "License"). + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + */ + +/* LOCAL INCLUDE HEADERS */ +#include "libyang.h" +#include "plugins_exts.h" +#include "plugins_types.h" + +int +main(void) +{ + struct ly_ctx *ctx = NULL; + const struct lys_module *mod; + int *sa = NULL, *item; + struct test_list { + int val; + struct test_list *next; + } *tl = NULL, *tl_item = NULL, *tl_next; + LY_ARRAY_COUNT_TYPE u; + const struct lysc_node *scnode; + struct lyd_node *data = NULL, *next, *elem, *opaq = NULL; + LY_ERR ret = LY_SUCCESS; + + if ((ret = ly_ctx_new(NULL, 0, &ctx))) { + goto cleanup; + } + if (!(mod = ly_ctx_get_module_latest(ctx, "ietf-yang-library"))) { + ret = LY_EINT; + goto cleanup; + } + if ((ret = ly_ctx_get_yanglib_data(ctx, &data, "%u", ly_ctx_get_change_count(ctx)))) { + goto cleanup; + } + if ((ret = lyd_new_opaq(NULL, ctx, "name", "val", NULL, "module", &opaq))) { + goto cleanup; + } + + /* tree_edit.h / tree.h */ + LY_ARRAY_NEW_GOTO(ctx, sa, item, ret, cleanup); + LY_ARRAY_NEW_GOTO(ctx, sa, item, ret, cleanup); + LY_ARRAY_FOR(sa, int, item) {} + LY_ARRAY_FREE(sa); + sa = NULL; + + LY_ARRAY_CREATE_GOTO(ctx, sa, 2, ret, cleanup); + LY_ARRAY_INCREMENT(sa); + LY_ARRAY_INCREMENT(sa); + LY_ARRAY_FOR(sa, u) {} + LY_ARRAY_DECREMENT_FREE(sa); + LY_ARRAY_DECREMENT_FREE(sa); + + LY_LIST_NEW_GOTO(ctx, &tl, tl_item, next, ret, cleanup); + LY_LIST_NEW_GOTO(ctx, &tl, tl_item, next, ret, cleanup); + LY_LIST_FOR(tl, tl_item) {} + LY_LIST_FOR_SAFE(tl, tl_next, tl_item) {} + tl_item = tl->next; + + /* tree_data.h */ + LYD_TREE_DFS_BEGIN(data, elem) { + LYD_TREE_DFS_END(data, elem); + } + LYD_LIST_FOR_INST(data, data->schema, elem) {} + LYD_LIST_FOR_INST_SAFE(data, data->schema, next, elem) {} + (void)LYD_CTX(data); + (void)LYD_NAME(data); + + /* tree_schema.h */ + LYSC_TREE_DFS_BEGIN(mod->compiled->data, scnode) { + LYSC_TREE_DFS_END(mod->compiled->data, scnode); + } + (void)LYSP_MODULE_NAME(mod->parsed); + (void)lysc_is_userordered(data->schema); + (void)lysc_is_key(data->schema); + (void)lysc_is_np_cont(data->schema); + (void)lysc_is_dup_inst_list(data->schema); + +cleanup: + free(tl_item); + free(tl); + lyd_free_tree(opaq); + lyd_free_all(data); + ly_ctx_destroy(ctx); + return ret; +} |