blob: 24df3d27a2683bc3a8b1c2f612bc48f662f648b3 [file] [log] [blame]
Michal Vasko45365802021-04-15 13:10:44 +02001/**
2 * @file cpp_compat.c
3 * @author Michal Vasko <mvasko@cesnet.cz>
4 * @brief test for C++ compatibility of public headers (macros)
5 *
6 * Copyright (c) 2021 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15/* LOCAL INCLUDE HEADERS */
16#include "libyang.h"
17#include "plugins_exts.h"
18#include "plugins_types.h"
19
20int
21main(void)
22{
23 struct ly_ctx *ctx = NULL;
24 const struct lys_module *mod;
25 int *sa = NULL, *item;
26 struct test_list {
27 int val;
28 struct test_list *next;
29 } *tl = NULL, *tl_item = NULL, *tl_next;
30 LY_ARRAY_COUNT_TYPE u;
31 const struct lysc_node *scnode;
32 struct lyd_node *data = NULL, *next, *elem, *opaq = NULL;
33 LY_ERR ret = LY_SUCCESS;
34
35 if ((ret = ly_ctx_new(NULL, 0, &ctx))) {
36 goto cleanup;
37 }
38 if (!(mod = ly_ctx_get_module_latest(ctx, "ietf-yang-library"))) {
39 ret = LY_EINT;
40 goto cleanup;
41 }
42 if ((ret = ly_ctx_get_yanglib_data(ctx, &data, "%u", ly_ctx_get_change_count(ctx)))) {
43 goto cleanup;
44 }
45 if ((ret = lyd_new_opaq(NULL, ctx, "name", "val", NULL, "module", &opaq))) {
46 goto cleanup;
47 }
48
49 /* tree_edit.h / tree.h */
50 LY_ARRAY_NEW_GOTO(ctx, sa, item, ret, cleanup);
51 LY_ARRAY_NEW_GOTO(ctx, sa, item, ret, cleanup);
52 LY_ARRAY_FOR(sa, int, item) {}
53 LY_ARRAY_FREE(sa);
54 sa = NULL;
55
56 LY_ARRAY_CREATE_GOTO(ctx, sa, 2, ret, cleanup);
57 LY_ARRAY_INCREMENT(sa);
58 LY_ARRAY_INCREMENT(sa);
59 LY_ARRAY_FOR(sa, u) {}
60 LY_ARRAY_DECREMENT_FREE(sa);
61 LY_ARRAY_DECREMENT_FREE(sa);
62
63 LY_LIST_NEW_GOTO(ctx, &tl, tl_item, next, ret, cleanup);
64 LY_LIST_NEW_GOTO(ctx, &tl, tl_item, next, ret, cleanup);
65 LY_LIST_FOR(tl, tl_item) {}
66 LY_LIST_FOR_SAFE(tl, tl_next, tl_item) {}
67 tl_item = tl->next;
68
69 /* tree_data.h */
70 LYD_TREE_DFS_BEGIN(data, elem) {
71 LYD_TREE_DFS_END(data, elem);
72 }
73 LYD_LIST_FOR_INST(data, data->schema, elem) {}
74 LYD_LIST_FOR_INST_SAFE(data, data->schema, next, elem) {}
75 (void)LYD_CTX(data);
76 (void)LYD_CANON_VALUE(lyd_child(data));
77 (void)LYD_NAME(data);
78 (void)LYD_OPAQ_VALUE(opaq);
79
80 /* tree_schema.h */
81 LYSC_TREE_DFS_BEGIN(mod->compiled->data, scnode) {
82 LYSC_TREE_DFS_END(mod->compiled->data, scnode);
83 }
84 (void)LYSP_MODULE_NAME(mod->parsed);
85 (void)lysc_is_userordered(data->schema);
86 (void)lysc_is_key(data->schema);
87 (void)lysc_is_np_cont(data->schema);
88 (void)lysc_is_dup_inst_list(data->schema);
89
90cleanup:
91 free(tl_item);
92 free(tl);
93 lyd_free_tree(opaq);
94 lyd_free_all(data);
95 ly_ctx_destroy(ctx);
96 return ret;
97}