Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 1 | /* |
| 2 | * @file set.c |
| 3 | * @author: Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief unit tests for functions from context.c |
| 5 | * |
| 6 | * Copyright (c) 2018 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 | |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 15 | #include <stdarg.h> |
| 16 | #include <stddef.h> |
| 17 | #include <setjmp.h> |
| 18 | #include <cmocka.h> |
| 19 | |
| 20 | #include <string.h> |
| 21 | #include <stdio.h> |
| 22 | |
Radek Krejci | 70593c1 | 2020-06-13 20:48:09 +0200 | [diff] [blame^] | 23 | #include "common.h" |
| 24 | #include "context.h" |
| 25 | #include "tests/config.h" |
| 26 | #include "tree_schema_internal.h" |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 27 | |
| 28 | #define BUFSIZE 1024 |
| 29 | char logbuf[BUFSIZE] = {0}; |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 30 | int store = -1; /* negative for infinite logging, positive for limited logging */ |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 31 | |
| 32 | /* set to 0 to printing error messages to stderr instead of checking them in code */ |
| 33 | #define ENABLE_LOGGER_CHECKING 1 |
| 34 | |
| 35 | static void |
| 36 | logger(LY_LOG_LEVEL level, const char *msg, const char *path) |
| 37 | { |
| 38 | (void) level; /* unused */ |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 39 | if (store) { |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 40 | if (path && path[0]) { |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 41 | snprintf(logbuf, BUFSIZE - 1, "%s %s", msg, path); |
| 42 | } else { |
| 43 | strncpy(logbuf, msg, BUFSIZE - 1); |
| 44 | } |
| 45 | if (store > 0) { |
| 46 | --store; |
| 47 | } |
| 48 | } |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | static int |
| 52 | logger_setup(void **state) |
| 53 | { |
| 54 | (void) state; /* unused */ |
| 55 | #if ENABLE_LOGGER_CHECKING |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 56 | ly_set_log_clb(logger, 1); |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 57 | #endif |
| 58 | return 0; |
| 59 | } |
| 60 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 61 | static int |
| 62 | logger_teardown(void **state) |
| 63 | { |
| 64 | (void) state; /* unused */ |
| 65 | #if ENABLE_LOGGER_CHECKING |
| 66 | if (*state) { |
| 67 | fprintf(stderr, "%s\n", logbuf); |
| 68 | } |
| 69 | #endif |
| 70 | return 0; |
| 71 | } |
| 72 | |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 73 | #if ENABLE_LOGGER_CHECKING |
| 74 | # define logbuf_assert(str) assert_string_equal(logbuf, str) |
| 75 | #else |
| 76 | # define logbuf_assert(str) |
| 77 | #endif |
| 78 | |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 79 | static void |
| 80 | test_searchdirs(void **state) |
| 81 | { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 82 | *state = test_searchdirs; |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 83 | |
| 84 | struct ly_ctx *ctx; |
| 85 | const char * const *list; |
| 86 | |
| 87 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx)); |
| 88 | |
| 89 | /* invalid arguments */ |
| 90 | assert_int_equal(LY_EINVAL, ly_ctx_set_searchdir(NULL, NULL)); |
| 91 | logbuf_assert("Invalid argument ctx (ly_ctx_set_searchdir())."); |
| 92 | assert_null(ly_ctx_get_searchdirs(NULL)); |
| 93 | logbuf_assert("Invalid argument ctx (ly_ctx_get_searchdirs())."); |
Radek Krejci | 0759b79 | 2018-09-20 13:53:15 +0200 | [diff] [blame] | 94 | assert_int_equal(LY_EINVAL, ly_ctx_unset_searchdirs(NULL, NULL)); |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 95 | logbuf_assert("Invalid argument ctx (ly_ctx_unset_searchdirs())."); |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 96 | |
| 97 | /* readable and executable, but not a directory */ |
Radek Krejci | 1fd5ad6 | 2020-05-15 15:48:42 +0200 | [diff] [blame] | 98 | assert_int_equal(LY_EINVAL, ly_ctx_set_searchdir(ctx, TESTS_BIN"/utest_context")); |
| 99 | logbuf_assert("Given search directory \""TESTS_BIN"/utest_context\" is not a directory."); |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 100 | /* not executable */ |
Radek Krejci | 9efa87a | 2018-09-26 15:14:03 +0200 | [diff] [blame] | 101 | assert_int_equal(LY_EINVAL, ly_ctx_set_searchdir(ctx, __FILE__)); |
Radek Krejci | 3a077b9 | 2019-04-09 17:10:35 +0200 | [diff] [blame] | 102 | logbuf_assert("Unable to fully access search directory \""__FILE__"\" (Permission denied)."); |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 103 | /* not existing */ |
| 104 | assert_int_equal(LY_EINVAL, ly_ctx_set_searchdir(ctx, "/nonexistingfile")); |
Radek Krejci | 3a077b9 | 2019-04-09 17:10:35 +0200 | [diff] [blame] | 105 | logbuf_assert("Unable to use search directory \"/nonexistingfile\" (No such file or directory)."); |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 106 | |
| 107 | /* ly_set_add() fails */ |
Radek Krejci | a77e0e1 | 2018-09-20 12:39:15 +0200 | [diff] [blame] | 108 | /* no change */ |
| 109 | assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(ctx, NULL)); |
| 110 | |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 111 | /* correct path */ |
Radek Krejci | 1fd5ad6 | 2020-05-15 15:48:42 +0200 | [diff] [blame] | 112 | assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(ctx, TESTS_BIN"/utests")); |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 113 | assert_int_equal(1, ctx->search_paths.count); |
Radek Krejci | 1fd5ad6 | 2020-05-15 15:48:42 +0200 | [diff] [blame] | 114 | assert_string_equal(TESTS_BIN"/utests", ctx->search_paths.objs[0]); |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 115 | |
Radek Krejci | 14946ab | 2018-09-20 13:42:06 +0200 | [diff] [blame] | 116 | /* duplicated paths */ |
Radek Krejci | 1fd5ad6 | 2020-05-15 15:48:42 +0200 | [diff] [blame] | 117 | assert_int_equal(LY_EEXIST, ly_ctx_set_searchdir(ctx, TESTS_BIN"/utests")); |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 118 | assert_int_equal(1, ctx->search_paths.count); |
Radek Krejci | 1fd5ad6 | 2020-05-15 15:48:42 +0200 | [diff] [blame] | 119 | assert_string_equal(TESTS_BIN"/utests", ctx->search_paths.objs[0]); |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 120 | |
| 121 | /* another paths - add 8 to fill the initial buffer of the searchpaths list */ |
| 122 | assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(ctx, TESTS_BIN"/CMakeFiles")); |
| 123 | assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(ctx, TESTS_SRC"/../src")); |
| 124 | assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(ctx, TESTS_SRC"/../CMakeModules")); |
| 125 | assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(ctx, TESTS_SRC"/../doc")); |
| 126 | assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(ctx, TESTS_SRC)); |
| 127 | assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(ctx, TESTS_BIN)); |
Radek Krejci | ef6867f | 2018-11-27 11:32:00 +0100 | [diff] [blame] | 128 | assert_int_equal(LY_SUCCESS, ly_ctx_set_searchdir(ctx, "/home")); |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 129 | assert_int_equal(8, ctx->search_paths.count); |
| 130 | |
| 131 | /* get searchpaths */ |
| 132 | list = ly_ctx_get_searchdirs(ctx); |
| 133 | assert_non_null(list); |
Radek Krejci | 1fd5ad6 | 2020-05-15 15:48:42 +0200 | [diff] [blame] | 134 | assert_string_equal(TESTS_BIN"/utests", list[0]); |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 135 | assert_string_equal(TESTS_BIN"/CMakeFiles", list[1]); |
| 136 | assert_string_equal(TESTS_SRC, list[5]); |
| 137 | assert_string_equal(TESTS_BIN, list[6]); |
Radek Krejci | ef6867f | 2018-11-27 11:32:00 +0100 | [diff] [blame] | 138 | assert_string_equal("/home", list[7]); |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 139 | assert_null(list[8]); |
| 140 | |
| 141 | /* removing searchpaths */ |
Radek Krejci | 0759b79 | 2018-09-20 13:53:15 +0200 | [diff] [blame] | 142 | /* nonexisting */ |
| 143 | assert_int_equal(LY_EINVAL, ly_ctx_unset_searchdirs(ctx, "/nonexistingfile")); |
| 144 | logbuf_assert("Invalid argument value (ly_ctx_unset_searchdirs())."); |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 145 | /* first */ |
Radek Krejci | 1fd5ad6 | 2020-05-15 15:48:42 +0200 | [diff] [blame] | 146 | assert_int_equal(LY_SUCCESS, ly_ctx_unset_searchdirs(ctx, TESTS_BIN"/utests")); |
| 147 | assert_string_not_equal(TESTS_BIN"/utests", list[0]); |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 148 | assert_int_equal(7, ctx->search_paths.count); |
| 149 | /* middle */ |
Radek Krejci | 0759b79 | 2018-09-20 13:53:15 +0200 | [diff] [blame] | 150 | assert_int_equal(LY_SUCCESS, ly_ctx_unset_searchdirs(ctx, TESTS_SRC)); |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 151 | assert_int_equal(6, ctx->search_paths.count); |
| 152 | /* last */ |
Radek Krejci | ef6867f | 2018-11-27 11:32:00 +0100 | [diff] [blame] | 153 | assert_int_equal(LY_SUCCESS, ly_ctx_unset_searchdirs(ctx, "/home")); |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 154 | assert_int_equal(5, ctx->search_paths.count); |
| 155 | /* all */ |
Radek Krejci | 0759b79 | 2018-09-20 13:53:15 +0200 | [diff] [blame] | 156 | assert_int_equal(LY_SUCCESS, ly_ctx_unset_searchdirs(ctx, NULL)); |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 157 | assert_int_equal(0, ctx->search_paths.count); |
| 158 | |
Radek Krejci | 555c9bb | 2018-09-20 12:45:13 +0200 | [diff] [blame] | 159 | /* again - no change */ |
Radek Krejci | 0759b79 | 2018-09-20 13:53:15 +0200 | [diff] [blame] | 160 | assert_int_equal(LY_SUCCESS, ly_ctx_unset_searchdirs(ctx, NULL)); |
Radek Krejci | 555c9bb | 2018-09-20 12:45:13 +0200 | [diff] [blame] | 161 | |
| 162 | /* cleanup */ |
| 163 | ly_ctx_destroy(ctx, NULL); |
| 164 | |
| 165 | /* test searchdir list in ly_ctx_new() */ |
| 166 | assert_int_equal(LY_EINVAL, ly_ctx_new("/nonexistingfile", 0, &ctx)); |
Radek Krejci | 3a077b9 | 2019-04-09 17:10:35 +0200 | [diff] [blame] | 167 | logbuf_assert("Unable to use search directory \"/nonexistingfile\" (No such file or directory)."); |
Radek Krejci | b3289d6 | 2019-09-18 12:21:39 +0200 | [diff] [blame] | 168 | assert_int_equal(LY_SUCCESS, ly_ctx_new(TESTS_SRC":/home:/home:"TESTS_SRC, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
Radek Krejci | 555c9bb | 2018-09-20 12:45:13 +0200 | [diff] [blame] | 169 | assert_int_equal(2, ctx->search_paths.count); |
| 170 | assert_string_equal(TESTS_SRC, ctx->search_paths.objs[0]); |
Radek Krejci | ef6867f | 2018-11-27 11:32:00 +0100 | [diff] [blame] | 171 | assert_string_equal("/home", ctx->search_paths.objs[1]); |
Radek Krejci | 555c9bb | 2018-09-20 12:45:13 +0200 | [diff] [blame] | 172 | |
| 173 | /* cleanup */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 174 | *state = NULL; |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 175 | ly_ctx_destroy(ctx, NULL); |
| 176 | } |
| 177 | |
Radek Krejci | 0c4b22b | 2018-09-20 12:55:46 +0200 | [diff] [blame] | 178 | static void |
| 179 | test_options(void **state) |
| 180 | { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 181 | *state = test_options; |
Radek Krejci | 0c4b22b | 2018-09-20 12:55:46 +0200 | [diff] [blame] | 182 | |
| 183 | struct ly_ctx *ctx; |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 184 | |
Radek Krejci | 0c4b22b | 2018-09-20 12:55:46 +0200 | [diff] [blame] | 185 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0xffffffff, &ctx)); |
| 186 | |
Radek Krejci | 962a810 | 2018-09-20 14:21:06 +0200 | [diff] [blame] | 187 | /* invalid arguments */ |
| 188 | assert_int_equal(0, ly_ctx_get_options(NULL)); |
| 189 | logbuf_assert("Invalid argument ctx (ly_ctx_get_options())."); |
| 190 | |
Radek Krejci | 3fa46b6 | 2019-09-11 10:47:30 +0200 | [diff] [blame] | 191 | assert_int_equal(LY_EINVAL, ly_ctx_set_options(NULL, 0)); |
| 192 | logbuf_assert("Invalid argument ctx (ly_ctx_set_options())."); |
| 193 | assert_int_equal(LY_EINVAL, ly_ctx_unset_options(NULL, 0)); |
| 194 | logbuf_assert("Invalid argument ctx (ly_ctx_unset_options())."); |
Radek Krejci | 962a810 | 2018-09-20 14:21:06 +0200 | [diff] [blame] | 195 | |
| 196 | /* option not allowed to be changed */ |
Radek Krejci | 3fa46b6 | 2019-09-11 10:47:30 +0200 | [diff] [blame] | 197 | assert_int_equal(LY_EINVAL, ly_ctx_set_options(ctx, LY_CTX_NOYANGLIBRARY)); |
| 198 | logbuf_assert("Invalid argument option (ly_ctx_set_options())."); |
| 199 | assert_int_equal(LY_EINVAL, ly_ctx_set_options(ctx, LY_CTX_NOYANGLIBRARY)); |
| 200 | logbuf_assert("Invalid argument option (ly_ctx_set_options())."); |
Radek Krejci | 962a810 | 2018-09-20 14:21:06 +0200 | [diff] [blame] | 201 | |
| 202 | |
Radek Krejci | 0c4b22b | 2018-09-20 12:55:46 +0200 | [diff] [blame] | 203 | /* unset */ |
| 204 | /* LY_CTX_ALLIMPLEMENTED */ |
| 205 | assert_int_not_equal(0, ctx->flags & LY_CTX_ALLIMPLEMENTED); |
Radek Krejci | 3fa46b6 | 2019-09-11 10:47:30 +0200 | [diff] [blame] | 206 | assert_int_equal(LY_SUCCESS, ly_ctx_unset_options(ctx, LY_CTX_ALLIMPLEMENTED)); |
Radek Krejci | 0c4b22b | 2018-09-20 12:55:46 +0200 | [diff] [blame] | 207 | assert_int_equal(0, ctx->flags & LY_CTX_ALLIMPLEMENTED); |
| 208 | |
| 209 | /* LY_CTX_DISABLE_SEARCHDIRS */ |
| 210 | assert_int_not_equal(0, ctx->flags & LY_CTX_DISABLE_SEARCHDIRS); |
Radek Krejci | 3fa46b6 | 2019-09-11 10:47:30 +0200 | [diff] [blame] | 211 | assert_int_equal(LY_SUCCESS, ly_ctx_unset_options(ctx, LY_CTX_DISABLE_SEARCHDIRS)); |
Radek Krejci | 0c4b22b | 2018-09-20 12:55:46 +0200 | [diff] [blame] | 212 | assert_int_equal(0, ctx->flags & LY_CTX_DISABLE_SEARCHDIRS); |
| 213 | |
| 214 | /* LY_CTX_DISABLE_SEARCHDIR_CWD */ |
| 215 | assert_int_not_equal(0, ctx->flags & LY_CTX_DISABLE_SEARCHDIR_CWD); |
Radek Krejci | 3fa46b6 | 2019-09-11 10:47:30 +0200 | [diff] [blame] | 216 | assert_int_equal(LY_SUCCESS, ly_ctx_unset_options(ctx, LY_CTX_DISABLE_SEARCHDIR_CWD)); |
Radek Krejci | 0c4b22b | 2018-09-20 12:55:46 +0200 | [diff] [blame] | 217 | assert_int_equal(0, ctx->flags & LY_CTX_DISABLE_SEARCHDIR_CWD); |
| 218 | |
Radek Krejci | 0c4b22b | 2018-09-20 12:55:46 +0200 | [diff] [blame] | 219 | /* LY_CTX_PREFER_SEARCHDIRS */ |
| 220 | assert_int_not_equal(0, ctx->flags & LY_CTX_PREFER_SEARCHDIRS); |
Radek Krejci | 3fa46b6 | 2019-09-11 10:47:30 +0200 | [diff] [blame] | 221 | assert_int_equal(LY_SUCCESS, ly_ctx_unset_options(ctx, LY_CTX_PREFER_SEARCHDIRS)); |
Radek Krejci | 0c4b22b | 2018-09-20 12:55:46 +0200 | [diff] [blame] | 222 | assert_int_equal(0, ctx->flags & LY_CTX_PREFER_SEARCHDIRS); |
| 223 | |
| 224 | /* LY_CTX_TRUSTED */ |
| 225 | assert_int_not_equal(0, ctx->flags & LY_CTX_TRUSTED); |
Radek Krejci | 3fa46b6 | 2019-09-11 10:47:30 +0200 | [diff] [blame] | 226 | assert_int_equal(LY_SUCCESS, ly_ctx_unset_options(ctx, LY_CTX_TRUSTED)); |
Radek Krejci | 0c4b22b | 2018-09-20 12:55:46 +0200 | [diff] [blame] | 227 | assert_int_equal(0, ctx->flags & LY_CTX_TRUSTED); |
| 228 | |
Radek Krejci | 962a810 | 2018-09-20 14:21:06 +0200 | [diff] [blame] | 229 | assert_int_equal(ctx->flags, ly_ctx_get_options(ctx)); |
| 230 | |
Radek Krejci | 0c4b22b | 2018-09-20 12:55:46 +0200 | [diff] [blame] | 231 | /* set back */ |
| 232 | /* LY_CTX_ALLIMPLEMENTED */ |
Radek Krejci | 3fa46b6 | 2019-09-11 10:47:30 +0200 | [diff] [blame] | 233 | assert_int_equal(LY_SUCCESS, ly_ctx_set_options(ctx, LY_CTX_ALLIMPLEMENTED)); |
Radek Krejci | 0c4b22b | 2018-09-20 12:55:46 +0200 | [diff] [blame] | 234 | assert_int_not_equal(0, ctx->flags & LY_CTX_ALLIMPLEMENTED); |
| 235 | |
| 236 | /* LY_CTX_DISABLE_SEARCHDIRS */ |
Radek Krejci | 3fa46b6 | 2019-09-11 10:47:30 +0200 | [diff] [blame] | 237 | assert_int_equal(LY_SUCCESS, ly_ctx_set_options(ctx, LY_CTX_DISABLE_SEARCHDIRS)); |
Radek Krejci | 0c4b22b | 2018-09-20 12:55:46 +0200 | [diff] [blame] | 238 | assert_int_not_equal(0, ctx->flags & LY_CTX_DISABLE_SEARCHDIRS); |
| 239 | |
| 240 | /* LY_CTX_DISABLE_SEARCHDIR_CWD */ |
Radek Krejci | 3fa46b6 | 2019-09-11 10:47:30 +0200 | [diff] [blame] | 241 | assert_int_equal(LY_SUCCESS, ly_ctx_set_options(ctx, LY_CTX_DISABLE_SEARCHDIR_CWD)); |
Radek Krejci | 0c4b22b | 2018-09-20 12:55:46 +0200 | [diff] [blame] | 242 | assert_int_not_equal(0, ctx->flags & LY_CTX_DISABLE_SEARCHDIR_CWD); |
| 243 | |
| 244 | /* LY_CTX_PREFER_SEARCHDIRS */ |
Radek Krejci | 3fa46b6 | 2019-09-11 10:47:30 +0200 | [diff] [blame] | 245 | assert_int_equal(LY_SUCCESS, ly_ctx_set_options(ctx, LY_CTX_PREFER_SEARCHDIRS)); |
Radek Krejci | 0c4b22b | 2018-09-20 12:55:46 +0200 | [diff] [blame] | 246 | assert_int_not_equal(0, ctx->flags & LY_CTX_PREFER_SEARCHDIRS); |
| 247 | |
| 248 | /* LY_CTX_TRUSTED */ |
Radek Krejci | 3fa46b6 | 2019-09-11 10:47:30 +0200 | [diff] [blame] | 249 | assert_int_equal(LY_SUCCESS, ly_ctx_set_options(ctx, LY_CTX_TRUSTED)); |
Radek Krejci | 0c4b22b | 2018-09-20 12:55:46 +0200 | [diff] [blame] | 250 | assert_int_not_equal(0, ctx->flags & LY_CTX_TRUSTED); |
| 251 | |
Radek Krejci | 962a810 | 2018-09-20 14:21:06 +0200 | [diff] [blame] | 252 | assert_int_equal(ctx->flags, ly_ctx_get_options(ctx)); |
| 253 | |
| 254 | /* cleanup */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 255 | *state = NULL; |
Radek Krejci | 962a810 | 2018-09-20 14:21:06 +0200 | [diff] [blame] | 256 | ly_ctx_destroy(ctx, NULL); |
| 257 | } |
| 258 | |
Radek Krejci | 2d31ea7 | 2018-10-25 15:46:42 +0200 | [diff] [blame] | 259 | static LY_ERR test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name), |
| 260 | const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format, |
| 261 | const char **module_data, void (**free_module_data)(void *model_data, void *user_data)) |
| 262 | { |
| 263 | *module_data = user_data; |
| 264 | *format = LYS_IN_YANG; |
| 265 | *free_module_data = NULL; |
| 266 | return LY_SUCCESS; |
| 267 | } |
| 268 | |
Radek Krejci | 962a810 | 2018-09-20 14:21:06 +0200 | [diff] [blame] | 269 | static void |
| 270 | test_models(void **state) |
| 271 | { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 272 | *state = test_models; |
Radek Krejci | 962a810 | 2018-09-20 14:21:06 +0200 | [diff] [blame] | 273 | |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 274 | struct ly_ctx *ctx; |
Radek Krejci | 2d31ea7 | 2018-10-25 15:46:42 +0200 | [diff] [blame] | 275 | const char *str; |
Radek Krejci | 1aefdf7 | 2018-11-01 11:01:39 +0100 | [diff] [blame] | 276 | struct lys_module *mod1, *mod2; |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 277 | |
Radek Krejci | 962a810 | 2018-09-20 14:21:06 +0200 | [diff] [blame] | 278 | /* invalid arguments */ |
| 279 | assert_int_equal(0, ly_ctx_get_module_set_id(NULL)); |
| 280 | logbuf_assert("Invalid argument ctx (ly_ctx_get_module_set_id())."); |
| 281 | |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 282 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
Radek Krejci | 962a810 | 2018-09-20 14:21:06 +0200 | [diff] [blame] | 283 | assert_int_equal(ctx->module_set_id, ly_ctx_get_module_set_id(ctx)); |
| 284 | |
David Sedlák | 1b62312 | 2019-08-05 15:27:49 +0200 | [diff] [blame] | 285 | assert_null(lys_parse_mem_module(ctx, "module x {namespace urn:x;prefix x;}", 4, 1, NULL, NULL)); |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 286 | logbuf_assert("Invalid schema input format."); |
| 287 | |
Radek Krejci | 2d31ea7 | 2018-10-25 15:46:42 +0200 | [diff] [blame] | 288 | /* import callback */ |
| 289 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, (void*)(str = "test")); |
| 290 | assert_ptr_equal(test_imp_clb, ctx->imp_clb); |
| 291 | assert_ptr_equal(str, ctx->imp_clb_data); |
| 292 | assert_ptr_equal(test_imp_clb, ly_ctx_get_module_imp_clb(ctx, (void**)&str)); |
| 293 | assert_string_equal("test", str); |
| 294 | |
| 295 | ly_ctx_set_module_imp_clb(ctx, NULL, NULL); |
| 296 | assert_null(ctx->imp_clb); |
| 297 | assert_null(ctx->imp_clb_data); |
| 298 | |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 299 | /* name collision of module and submodule */ |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 300 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule y {belongs-to a {prefix a;} revision 2018-10-30;}"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 301 | assert_null(lys_parse_mem_module(ctx, "module y {namespace urn:y;prefix y;include y;}", LYS_IN_YANG, 1, NULL, NULL)); |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 302 | assert_int_equal(LY_EVALID, ly_errcode(ctx)); |
| 303 | logbuf_assert("Name collision between module and submodule of name \"y\". Line number 1."); |
| 304 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 305 | assert_non_null(lys_parse_mem_module(ctx, "module a {namespace urn:a;prefix a;include y;revision 2018-10-30; }", LYS_IN_YANG, 1, NULL, NULL)); |
| 306 | assert_null(lys_parse_mem_module(ctx, "module y {namespace urn:y;prefix y;}", LYS_IN_YANG, 1, NULL, NULL)); |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 307 | assert_int_equal(LY_EVALID, ly_errcode(ctx)); |
| 308 | logbuf_assert("Name collision between module and submodule of name \"y\". Line number 1."); |
| 309 | |
| 310 | store = 1; |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 311 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule y {belongs-to b {prefix b;}}"); |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 312 | assert_null(lys_parse_mem_module(ctx, "module b {namespace urn:b;prefix b;include y;}", LYS_IN_YANG, 1, NULL, NULL)); |
Radek Krejci | faa1eac | 2018-10-30 14:34:55 +0100 | [diff] [blame] | 313 | assert_int_equal(LY_EVALID, ly_errcode(ctx)); |
| 314 | logbuf_assert("Name collision between submodules of name \"y\". Line number 1."); |
| 315 | store = -1; |
| 316 | |
Radek Krejci | e9e987e | 2018-10-31 12:50:27 +0100 | [diff] [blame] | 317 | /* selecting correct revision of the submodules */ |
| 318 | ly_ctx_reset_latests(ctx); |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 319 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "submodule y {belongs-to a {prefix a;} revision 2018-10-31;}"); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 320 | mod2 = lys_parse_mem_module(ctx, "module a {namespace urn:a;prefix a;include y; revision 2018-10-31;}", LYS_IN_YANG, 0, NULL, NULL); |
Radek Krejci | e9e987e | 2018-10-31 12:50:27 +0100 | [diff] [blame] | 321 | assert_non_null(mod2); |
| 322 | assert_string_equal("2018-10-31", mod2->parsed->includes[0].submodule->revs[0].date); |
| 323 | |
Radek Krejci | 9c53696 | 2018-10-31 14:52:13 +0100 | [diff] [blame] | 324 | /* reloading module in case only the compiled module resists in the context */ |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 325 | mod1 = lys_parse_mem_module(ctx, "module w {namespace urn:w;prefix w;revision 2018-10-24;}", LYS_IN_YANG, 1, NULL, NULL); |
Radek Krejci | 9c53696 | 2018-10-31 14:52:13 +0100 | [diff] [blame] | 326 | assert_non_null(mod1); |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 327 | assert_int_equal(LY_SUCCESS, lys_compile(&mod1, LYSC_OPT_FREE_SP)); |
Radek Krejci | 9c53696 | 2018-10-31 14:52:13 +0100 | [diff] [blame] | 328 | assert_non_null(mod1->compiled); |
| 329 | assert_null(mod1->parsed); |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 330 | |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 331 | mod2 = lys_parse_mem_module(ctx, "module z {namespace urn:z;prefix z;import w {prefix w;revision-date 2018-10-24;}}", LYS_IN_YANG, 1, NULL, NULL); |
Radek Krejci | 9c53696 | 2018-10-31 14:52:13 +0100 | [diff] [blame] | 332 | assert_non_null(mod2); |
| 333 | /* mod1->parsed is necessary to compile mod2 because of possible groupings, typedefs, ... */ |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 334 | ly_ctx_set_module_imp_clb(ctx, NULL, NULL); |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 335 | assert_int_equal(LY_ENOTFOUND, lys_compile(&mod2, 0)); |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 336 | logbuf_assert("Unable to reload \"w\" module to import it into \"z\", source data not found."); |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 337 | assert_null(mod2); |
| 338 | |
| 339 | mod2 = lys_parse_mem_module(ctx, "module z {namespace urn:z;prefix z;import w {prefix w;revision-date 2018-10-24;}}", LYS_IN_YANG, 1, NULL, NULL); |
| 340 | assert_non_null(mod2); |
Radek Krejci | 9ed7a19 | 2018-10-31 16:23:51 +0100 | [diff] [blame] | 341 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module w {namespace urn:w;prefix w;revision 2018-10-24;}"); |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 342 | assert_int_equal(LY_SUCCESS, lys_compile(&mod2, 0)); |
| 343 | assert_non_null(mod2); |
Radek Krejci | 9c53696 | 2018-10-31 14:52:13 +0100 | [diff] [blame] | 344 | assert_non_null(mod1->parsed); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 345 | assert_string_equal("w", mod1->name); |
Radek Krejci | e9e987e | 2018-10-31 12:50:27 +0100 | [diff] [blame] | 346 | |
Radek Krejci | 0c4b22b | 2018-09-20 12:55:46 +0200 | [diff] [blame] | 347 | /* cleanup */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 348 | *state = NULL; |
Radek Krejci | 0c4b22b | 2018-09-20 12:55:46 +0200 | [diff] [blame] | 349 | ly_ctx_destroy(ctx, NULL); |
| 350 | } |
| 351 | |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 352 | static void |
Radek Krejci | b3289d6 | 2019-09-18 12:21:39 +0200 | [diff] [blame] | 353 | test_imports(void **state) |
| 354 | { |
| 355 | *state = test_imports; |
| 356 | |
| 357 | struct ly_ctx *ctx; |
| 358 | struct lys_module *mod1, *mod2, *import; |
| 359 | |
| 360 | /* import callback provides newer revision of module 'a' than present in context, so when importing 'a', the newer revision |
| 361 | * from the callback should be loaded into the context and used as an import */ |
| 362 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 363 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module a {namespace urn:a; prefix a; revision 2019-09-17;}"); |
| 364 | assert_non_null(mod1 = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;revision 2019-09-16;}", LYS_IN_YANG)); |
| 365 | assert_int_equal(1, mod1->latest_revision); |
| 366 | assert_int_equal(1, mod1->implemented); |
| 367 | assert_non_null(mod2 = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;import a {prefix a;}}", LYS_IN_YANG)); |
| 368 | import = mod2->compiled->imports[0].module; |
| 369 | assert_int_equal(2, import->latest_revision); |
| 370 | assert_int_equal(0, mod1->latest_revision); |
| 371 | assert_ptr_not_equal(mod1, import); |
| 372 | assert_string_equal("2019-09-17", import->revision); |
| 373 | assert_int_equal(0, import->implemented); |
| 374 | assert_non_null(ly_ctx_get_module(ctx, "a", "2019-09-16")); |
| 375 | ly_ctx_destroy(ctx, NULL); |
| 376 | |
| 377 | /* import callback provides older revision of module 'a' than present in context, so when importing a, the newer revision |
| 378 | * already present in the context should be selected and the callback's revision should not be loaded into the context */ |
| 379 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx)); |
| 380 | ly_ctx_set_module_imp_clb(ctx, test_imp_clb, "module a {namespace urn:a; prefix a; revision 2019-09-17;}"); |
| 381 | assert_non_null(mod1 = lys_parse_mem(ctx, "module a {namespace urn:a;prefix a;revision 2019-09-18;}", LYS_IN_YANG)); |
| 382 | assert_int_equal(1, mod1->latest_revision); |
| 383 | assert_int_equal(1, mod1->implemented); |
| 384 | assert_non_null(mod2 = lys_parse_mem(ctx, "module b {namespace urn:b;prefix b;import a {prefix a;}}", LYS_IN_YANG)); |
| 385 | import = mod2->compiled->imports[0].module; |
| 386 | assert_ptr_equal(mod1, import); |
| 387 | assert_int_equal(2, import->latest_revision); |
| 388 | assert_int_equal(1, import->implemented); |
| 389 | assert_string_equal("2019-09-18", import->revision); |
| 390 | assert_null(ly_ctx_get_module(ctx, "a", "2019-09-17")); |
| 391 | ly_ctx_destroy(ctx, NULL); |
| 392 | |
| 393 | /* cleanup */ |
| 394 | *state = NULL; |
| 395 | } |
| 396 | |
| 397 | static void |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 398 | test_get_models(void **state) |
| 399 | { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 400 | *state = test_get_models; |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 401 | |
| 402 | struct ly_ctx *ctx; |
| 403 | const struct lys_module *mod, *mod2; |
Radek Krejci | 5e163df | 2018-10-24 14:42:15 +0200 | [diff] [blame] | 404 | const char *str0 = "module a {namespace urn:a;prefix a;}"; |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 405 | const char *str1 = "module a {namespace urn:a;prefix a;revision 2018-10-23;}"; |
| 406 | const char *str2 = "module a {namespace urn:a;prefix a;revision 2018-10-23;revision 2018-10-24;}"; |
| 407 | |
Radek Krejci | 2390fb5 | 2019-04-30 13:27:43 +0200 | [diff] [blame] | 408 | unsigned int index = 0; |
| 409 | const char *names[] = {"ietf-yang-metadata", "yang", "ietf-inet-types", "ietf-yang-types", "ietf-datastores", "ietf-yang-library", "a", "a", "a"}; |
| 410 | |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 411 | assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, &ctx)); |
| 412 | |
| 413 | /* invalid arguments */ |
| 414 | assert_ptr_equal(NULL, ly_ctx_get_module(NULL, NULL, NULL)); |
| 415 | logbuf_assert("Invalid argument ctx (ly_ctx_get_module())."); |
| 416 | assert_ptr_equal(NULL, ly_ctx_get_module(ctx, NULL, NULL)); |
| 417 | logbuf_assert("Invalid argument name (ly_ctx_get_module())."); |
| 418 | assert_ptr_equal(NULL, ly_ctx_get_module_ns(NULL, NULL, NULL)); |
| 419 | logbuf_assert("Invalid argument ctx (ly_ctx_get_module_ns())."); |
| 420 | assert_ptr_equal(NULL, ly_ctx_get_module_ns(ctx, NULL, NULL)); |
| 421 | logbuf_assert("Invalid argument ns (ly_ctx_get_module_ns())."); |
| 422 | assert_null(ly_ctx_get_module(ctx, "nonsence", NULL)); |
| 423 | |
| 424 | /* internal modules */ |
| 425 | assert_null(ly_ctx_get_module_implemented(ctx, "ietf-yang-types")); |
| 426 | mod = ly_ctx_get_module_implemented(ctx, "yang"); |
| 427 | assert_non_null(mod); |
| 428 | assert_non_null(mod->parsed); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 429 | assert_string_equal("yang", mod->name); |
| 430 | mod2 = ly_ctx_get_module_implemented_ns(ctx, mod->ns); |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 431 | assert_ptr_equal(mod, mod2); |
| 432 | assert_non_null(ly_ctx_get_module(ctx, "ietf-yang-metadata", "2016-08-05")); |
| 433 | assert_non_null(ly_ctx_get_module(ctx, "ietf-yang-types", "2013-07-15")); |
| 434 | assert_non_null(ly_ctx_get_module(ctx, "ietf-inet-types", "2013-07-15")); |
Michal Vasko | f872e20 | 2020-05-27 11:49:06 +0200 | [diff] [blame] | 435 | assert_non_null(ly_ctx_get_module_ns(ctx, "urn:ietf:params:xml:ns:yang:ietf-datastores", "2018-02-14")); |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 436 | |
| 437 | /* select module by revision */ |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 438 | mod = lys_parse_mem_module(ctx, str1, LYS_IN_YANG, 1, NULL, NULL); |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 439 | /* invalid attempts - implementing module of the same name and inserting the same module */ |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 440 | assert_null(lys_parse_mem_module(ctx, str2, LYS_IN_YANG, 1, NULL, NULL)); |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 441 | logbuf_assert("Module \"a\" is already implemented in the context."); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 442 | assert_null(lys_parse_mem_module(ctx, str1, LYS_IN_YANG, 0, NULL, NULL)); |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 443 | logbuf_assert("Module \"a\" of revision \"2018-10-23\" is already present in the context."); |
| 444 | /* insert the second module only as imported, not implemented */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 445 | mod2 = lys_parse_mem_module(ctx, str2, LYS_IN_YANG, 0, NULL, NULL); |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 446 | assert_non_null(mod); |
| 447 | assert_non_null(mod2); |
| 448 | assert_ptr_not_equal(mod, mod2); |
| 449 | mod = ly_ctx_get_module_latest(ctx, "a"); |
| 450 | assert_ptr_equal(mod, mod2); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 451 | mod2 = ly_ctx_get_module_latest_ns(ctx, mod->ns); |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 452 | assert_ptr_equal(mod, mod2); |
Radek Krejci | 5e163df | 2018-10-24 14:42:15 +0200 | [diff] [blame] | 453 | /* work with module with no revision */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 454 | mod = lys_parse_mem_module(ctx, str0, LYS_IN_YANG, 0, NULL, NULL); |
Radek Krejci | 5e163df | 2018-10-24 14:42:15 +0200 | [diff] [blame] | 455 | assert_non_null(mod); |
| 456 | assert_ptr_equal(mod, ly_ctx_get_module(ctx, "a", NULL)); |
| 457 | assert_ptr_not_equal(mod, ly_ctx_get_module_latest(ctx, "a")); |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 458 | |
Radek Krejci | 313d990 | 2018-11-08 09:42:58 +0100 | [diff] [blame] | 459 | str1 = "submodule b {belongs-to a {prefix a;}}"; |
Radek Krejci | 096235c | 2019-01-11 11:12:19 +0100 | [diff] [blame] | 460 | assert_null(lys_parse_mem_module(ctx, str1, LYS_IN_YANG, 1, NULL, NULL)); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 461 | logbuf_assert("Input data contains submodule which cannot be parsed directly without its main module."); |
Radek Krejci | d33273d | 2018-10-25 14:55:52 +0200 | [diff] [blame] | 462 | |
Radek Krejci | 2390fb5 | 2019-04-30 13:27:43 +0200 | [diff] [blame] | 463 | while ((mod = ly_ctx_get_module_iter(ctx, &index))) { |
| 464 | assert_string_equal(names[index - 1], mod->name); |
| 465 | } |
| 466 | assert_int_equal(9, index); |
| 467 | |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 468 | /* cleanup */ |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 469 | *state = NULL; |
Radek Krejci | b7db73a | 2018-10-24 14:18:40 +0200 | [diff] [blame] | 470 | ly_ctx_destroy(ctx, NULL); |
| 471 | } |
| 472 | |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 473 | int main(void) |
| 474 | { |
| 475 | const struct CMUnitTest tests[] = { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 476 | cmocka_unit_test_setup_teardown(test_searchdirs, logger_setup, logger_teardown), |
| 477 | cmocka_unit_test_setup_teardown(test_options, logger_setup, logger_teardown), |
| 478 | cmocka_unit_test_setup_teardown(test_models, logger_setup, logger_teardown), |
Radek Krejci | b3289d6 | 2019-09-18 12:21:39 +0200 | [diff] [blame] | 479 | cmocka_unit_test_setup_teardown(test_imports, logger_setup, logger_teardown), |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 480 | cmocka_unit_test_setup_teardown(test_get_models, logger_setup, logger_teardown), |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 481 | }; |
| 482 | |
| 483 | return cmocka_run_group_tests(tests, NULL, NULL); |
| 484 | } |