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/plugins | |
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 '')
-rw-r--r-- | tests/plugins/CMakeLists.txt | 19 | ||||
-rw-r--r-- | tests/plugins/invalid.c | 41 | ||||
-rw-r--r-- | tests/plugins/simple.c | 92 |
3 files changed, 152 insertions, 0 deletions
diff --git a/tests/plugins/CMakeLists.txt b/tests/plugins/CMakeLists.txt new file mode 100644 index 0000000..1e21824 --- /dev/null +++ b/tests/plugins/CMakeLists.txt @@ -0,0 +1,19 @@ +include(CMakeParseArguments) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +function(ly_add_plugin) + cmake_parse_arguments(ADDPLUGIN "" "NAME" "SOURCES" ${ARGN}) + set(PLUGIN_NAME plugin_${ADDPLUGIN_NAME}) + + foreach(PLUGIN_SOURCE ${ADDPLUGIN_SOURCES}) + list(APPEND PLUGIN_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/${PLUGIN_SOURCE}) + endforeach() + + add_library(${PLUGIN_NAME} MODULE ${PLUGIN_SOURCES}) + set_target_properties(${PLUGIN_NAME} PROPERTIES PREFIX "") + target_link_libraries(${PLUGIN_NAME} yang) +endfunction(ly_add_plugin) + +ly_add_plugin(NAME invalid SOURCES invalid.c) +ly_add_plugin(NAME simple SOURCES simple.c) diff --git a/tests/plugins/invalid.c b/tests/plugins/invalid.c new file mode 100644 index 0000000..000ccb4 --- /dev/null +++ b/tests/plugins/invalid.c @@ -0,0 +1,41 @@ +/** + * @file invalid.c + * @author Radek Krejci <rkrejci@cesnet.cz> + * @brief Invalid testing plugins implementation + * + * 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 + */ + +#include <stdint.h> + +#include "libyang.h" +#include "plugins_exts.h" +#include "plugins_types.h" + +/* + * EXTENSION PLUGIN + */ + +/** + * @brief Instead of plugin description, only the API version is declared. + * + * Here should be LY_PLUGINS_EXTENSIONS used. + */ +uint32_t plugins_extensions_apiver__ = LYPLG_EXT_API_VERSION; + +/* + * TYPE PLUGIN + */ + +/** + * @brief Instead of plugin description, only the API version is declared. + * + * Here should be LYPLG_TYPES used. + */ +uint32_t plugins_types_apiver__ = LYPLG_TYPE_API_VERSION; diff --git a/tests/plugins/simple.c b/tests/plugins/simple.c new file mode 100644 index 0000000..3595c76 --- /dev/null +++ b/tests/plugins/simple.c @@ -0,0 +1,92 @@ +/** + * @file simple.c + * @author Radek Krejci <rkrejci@cesnet.cz> + * @brief Simple testing plugins implementation + * + * 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 + */ + +#include <stdlib.h> + +#include "libyang.h" +#include "plugins_exts.h" +#include "plugins_types.h" + +/* + * EXTENSION PLUGIN + */ + +/** + * @brief Compile simple extension instances. + * + * Implementation of ::lyplg_ext_compile_clb callback set as lyext_plugin::compile. + */ +static LY_ERR +hint_compile(struct lysc_ctx *cctx, const struct lysp_ext_instance *extp, struct lysc_ext_instance *ext) +{ + /* check that the extension is instantiated at an allowed place - data node */ + if (!(ext->parent_stmt & LY_STMT_DATA_NODE_MASK)) { + lyplg_ext_compile_log(cctx, ext, LY_LLWRN, 0, + "Extension %s is allowed only in a data nodes, but it is placed in \"%s\" statement.", + extp->name, lyplg_ext_stmt2str(ext->parent_stmt)); + return LY_ENOT; + } + + return LY_SUCCESS; +} + +/** + * @brief Plugin descriptions for the test extensions + */ +LYPLG_EXTENSIONS = { + { + .module = "libyang-plugins-simple", + .revision = NULL, + .name = "hint", + + .plugin.id = "ly2 simple test v1", + .plugin.parse = NULL, + .plugin.compile = hint_compile, + .plugin.printer_info = NULL, + .plugin.node = NULL, + .plugin.snode = NULL, + .plugin.validate = NULL, + .plugin.pfree = NULL, + .plugin.cfree = NULL + }, + {0} /* terminating zeroed item */ +}; + +/* + * TYPE PLUGIN + */ + +/** + * @brief Plugin information for note (string) type implementation. + * + * Everything is just the same as for built-in string. + */ +LYPLG_TYPES = { + { + .module = "libyang-plugins-simple", + .revision = NULL, + .name = "note", + + .plugin.id = "ly2 simple test v1", + .plugin.store = lyplg_type_store_string, + .plugin.validate = NULL, + .plugin.compare = lyplg_type_compare_simple, + .plugin.sort = NULL, + .plugin.print = lyplg_type_print_simple, + .plugin.duplicate = lyplg_type_dup_simple, + .plugin.free = lyplg_type_free_simple, + .plugin.lyb_data_len = 0 + }, + {0} +}; |