blob: 4a01ddc438213bf66fcd62b56deaf07e14b23e23 [file] [log] [blame]
David Sedlák3b4db242018-10-19 16:11:01 +02001#include <stdarg.h>
2#include <stddef.h>
3#include <setjmp.h>
4#include <cmocka.h>
5
6#include <stdio.h>
7#include <string.h>
8
9#include "libyang.h"
10#include "tree_schema_internal.h"
11#include "../../src/parser_yin.c"
12
David Sedlák872c7b42018-10-26 13:15:20 +020013static void
14test_parse(void **state)
15{
16 (void)state; /* unused */
17
David Sedlák3b4db242018-10-19 16:11:01 +020018 struct ly_ctx *ctx;
19 struct lysp_module *mod;
David Sedlák872c7b42018-10-26 13:15:20 +020020
David Sedlák3b4db242018-10-19 16:11:01 +020021 ly_ctx_new(NULL, 0, &ctx);
David Sedláke4889912018-11-02 09:52:40 +010022 mod = calloc(1, sizeof(*mod));
David Sedlák872c7b42018-10-26 13:15:20 +020023 mod->ctx = ctx;
David Sedlák3b4db242018-10-19 16:11:01 +020024
25 yin_parse(ctx, "<module name=\"example-foo\" xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" xmlns:foo=\"urn:example:foo\" xmlns:myext=\"urn:example:extensions\">",
26 &mod);
David Sedlák872c7b42018-10-26 13:15:20 +020027
28 assert_string_equal(mod->name, "example-foo");
29
David Sedlák3b4db242018-10-19 16:11:01 +020030 ly_ctx_destroy(ctx, NULL);
David Sedlák872c7b42018-10-26 13:15:20 +020031
32 free(mod);
David Sedlák3b4db242018-10-19 16:11:01 +020033}
34
35static int
36test_setup(void **state) {
37 (void)state; /* unused */
38 return 0;
39}
40
41static void
42test_match_keyword(void **state)
43{
44 (void)state; /* unused */
45
David Sedlák872c7b42018-10-26 13:15:20 +020046 assert_int_equal(match_keyword("anydata"), YANG_ANYDATA);
47 assert_int_equal(match_keyword("asdasd"), YANG_NONE);
48 assert_int_equal(match_keyword(""), YANG_NONE);
49 assert_int_equal(match_keyword("anydata"), YANG_ANYDATA);
50 assert_int_equal(match_keyword("anyxml"), YANG_ANYXML);
51 assert_int_equal(match_keyword("argument"), YANG_ARGUMENT);
52 assert_int_equal(match_keyword("augment"), YANG_AUGMENT);
53 assert_int_equal(match_keyword("base"), YANG_BASE);
54 assert_int_equal(match_keyword("belongs-to"), YANG_BELONGS_TO);
55 assert_int_equal(match_keyword("bit"), YANG_BIT);
56 assert_int_equal(match_keyword("case"), YANG_CASE);
57 assert_int_equal(match_keyword("choice"), YANG_CHOICE);
58 assert_int_equal(match_keyword("config"), YANG_CONFIG);
59 assert_int_equal(match_keyword("contact"), YANG_CONTACT);
60 assert_int_equal(match_keyword("container"), YANG_CONTAINER);
61 assert_int_equal(match_keyword("default"), YANG_DEFAULT);
62 assert_int_equal(match_keyword("description"), YANG_DESCRIPTION);
63 assert_int_equal(match_keyword("deviate"), YANG_DEVIATE);
64 assert_int_equal(match_keyword("deviation"), YANG_DEVIATION);
65 assert_int_equal(match_keyword("enum"), YANG_ENUM);
66 assert_int_equal(match_keyword("error-app-tag"), YANG_ERROR_APP_TAG);
67 assert_int_equal(match_keyword("error-message"), YANG_ERROR_MESSAGE);
68 assert_int_equal(match_keyword("extension"), YANG_EXTENSION);
69 assert_int_equal(match_keyword("feature"), YANG_FEATURE);
70 assert_int_equal(match_keyword("fraction-digits"), YANG_FRACTION_DIGITS);
71 assert_int_equal(match_keyword("grouping"), YANG_GROUPING);
72 assert_int_equal(match_keyword("identity"), YANG_IDENTITY);
73 assert_int_equal(match_keyword("if-feature"), YANG_IF_FEATURE);
74 assert_int_equal(match_keyword("import"), YANG_IMPORT);
75 assert_int_equal(match_keyword("include"), YANG_INCLUDE);
76 assert_int_equal(match_keyword("input"), YANG_INPUT);
77 assert_int_equal(match_keyword("key"), YANG_KEY);
78 assert_int_equal(match_keyword("leaf"), YANG_LEAF);
79 assert_int_equal(match_keyword("leaf-list"), YANG_LEAF_LIST);
80 assert_int_equal(match_keyword("length"), YANG_LENGTH);
81 assert_int_equal(match_keyword("list"), YANG_LIST);
82 assert_int_equal(match_keyword("mandatory"), YANG_MANDATORY);
83 assert_int_equal(match_keyword("max-elements"), YANG_MAX_ELEMENTS);
84 assert_int_equal(match_keyword("min-elements"), YANG_MIN_ELEMENTS);
85 assert_int_equal(match_keyword("modifier"), YANG_MODIFIER);
86 assert_int_equal(match_keyword("module"), YANG_MODULE);
87 assert_int_equal(match_keyword("must"), YANG_MUST);
88 assert_int_equal(match_keyword("namespace"), YANG_NAMESPACE);
89 assert_int_equal(match_keyword("notification"), YANG_NOTIFICATION);
90 assert_int_equal(match_keyword("ordered-by"), YANG_ORDERED_BY);
91 assert_int_equal(match_keyword("organization"), YANG_ORGANIZATION);
92 assert_int_equal(match_keyword("output"), YANG_OUTPUT);
93 assert_int_equal(match_keyword("path"), YANG_PATH);
94 assert_int_equal(match_keyword("pattern"), YANG_PATTERN);
95 assert_int_equal(match_keyword("position"), YANG_POSITION);
96 assert_int_equal(match_keyword("prefix"), YANG_PREFIX);
97 assert_int_equal(match_keyword("presence"), YANG_PRESENCE);
98 assert_int_equal(match_keyword("range"), YANG_RANGE);
99 assert_int_equal(match_keyword("reference"), YANG_REFERENCE);
100 assert_int_equal(match_keyword("refine"), YANG_REFINE);
101 assert_int_equal(match_keyword("require-instance"), YANG_REQUIRE_INSTANCE);
102 assert_int_equal(match_keyword("revision"), YANG_REVISION);
103 assert_int_equal(match_keyword("revision-date"), YANG_REVISION_DATE);
104 assert_int_equal(match_keyword("rpc"), YANG_RPC);
105 assert_int_equal(match_keyword("status"), YANG_STATUS);
106 assert_int_equal(match_keyword("submodule"), YANG_SUBMODULE);
107 assert_int_equal(match_keyword("type"), YANG_TYPE);
108 assert_int_equal(match_keyword("typedef"), YANG_TYPEDEF);
109 assert_int_equal(match_keyword("unique"), YANG_UNIQUE);
110 assert_int_equal(match_keyword("units"), YANG_UNITS);
111 assert_int_equal(match_keyword("uses"), YANG_USES);
112 assert_int_equal(match_keyword("value"), YANG_VALUE);
113 assert_int_equal(match_keyword("when"), YANG_WHEN);
114 assert_int_equal(match_keyword("yang-version"), YANG_YANG_VERSION);
115 assert_int_equal(match_keyword("yin-element"), YANG_YIN_ELEMENT);
116}
David Sedlák3b4db242018-10-19 16:11:01 +0200117
David Sedlák872c7b42018-10-26 13:15:20 +0200118static void
119test_match_argument(void **state)
120{
121 (void)state;
122
123 assert_int_equal(match_argument_name("", 5), YIN_ARG_NONE);
124 assert_int_equal(match_argument_name("qwertyasd", 5), YIN_ARG_NONE);
125 assert_int_equal(match_argument_name("conditionasd", 8), YIN_ARG_NONE);
126 assert_int_equal(match_argument_name("condition", 9), YIN_ARG_CONDITION);
127 assert_int_equal(match_argument_name("date", 4), YIN_ARG_DATE);
128 assert_int_equal(match_argument_name("module", 6), YIN_ARG_MODULE);
129 assert_int_equal(match_argument_name("name", 4), YIN_ARG_NAME);
130 assert_int_equal(match_argument_name("tag", 3), YIN_ARG_TAG);
131 assert_int_equal(match_argument_name("target-node", 11), YIN_ARG_TARGET_NODE);
132 assert_int_equal(match_argument_name("text", 4), YIN_ARG_TEXT);
133 assert_int_equal(match_argument_name("uri", 3), YIN_ARG_URI);
134 assert_int_equal(match_argument_name("value", 5), YIN_ARG_VALUE);
David Sedlák3b4db242018-10-19 16:11:01 +0200135}
136
137int
138main(void)
139{
140
141 const struct CMUnitTest tests[] = {
David Sedlák872c7b42018-10-26 13:15:20 +0200142 cmocka_unit_test_setup(test_parse, test_setup),
David Sedlák3b4db242018-10-19 16:11:01 +0200143 cmocka_unit_test(test_match_keyword),
David Sedlák872c7b42018-10-26 13:15:20 +0200144 cmocka_unit_test(test_match_argument),
David Sedlák3b4db242018-10-19 16:11:01 +0200145 };
146
147 return cmocka_run_group_tests(tests, NULL, NULL);
148}