| /** |
| * \file test_invalid.c |
| * \author Michal Vasko <mvasko@cesnet.cz> |
| * \brief libyang tests - loading invalid schemas |
| * |
| * Copyright (c) 2018 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 <errno.h> |
| #include <fcntl.h> |
| #include <pthread.h> |
| #include <setjmp.h> |
| #include <unistd.h> |
| #include <stddef.h> |
| #include <stdlib.h> |
| #include <string.h> |
| #include <sys/stat.h> |
| #include <sys/types.h> |
| #include <stdarg.h> |
| #include <cmocka.h> |
| |
| #include "libyang.h" |
| #include "tests/config.h" |
| |
| struct state { |
| struct ly_ctx *ctx; |
| }; |
| |
| static int |
| setup_ctx(void **state) |
| { |
| struct state *st; |
| (*state) = st = calloc(1, sizeof *st); |
| if (!st) { |
| fprintf(stderr, "Memory allocation error"); |
| return -1; |
| } |
| |
| /* libyang context */ |
| st->ctx = ly_ctx_new(NULL, 0); |
| if (!st->ctx) { |
| fprintf(stderr, "Failed to create context.\n"); |
| goto error; |
| } |
| |
| return 0; |
| |
| error: |
| ly_ctx_destroy(st->ctx, NULL); |
| free(st); |
| (*state) = NULL; |
| |
| return -1; |
| } |
| |
| static int |
| teardown_ctx(void **state) |
| { |
| struct state *st = (*state); |
| |
| ly_ctx_destroy(st->ctx, NULL); |
| free(st); |
| (*state) = NULL; |
| |
| return 0; |
| } |
| |
| static void |
| test_case_act_notif(void **state) |
| { |
| const char *schema = TESTS_DIR"/schema/yang/files/case-act-notif.yang"; |
| struct state *st = (*state); |
| const struct lys_module *mod; |
| |
| mod = lys_parse_path(st->ctx, schema, LYS_IN_YANG); |
| assert_ptr_equal(mod, NULL); |
| } |
| |
| int |
| main(void) |
| { |
| const struct CMUnitTest cmut[] = { |
| cmocka_unit_test_setup_teardown(test_case_act_notif, setup_ctx, teardown_ctx), |
| }; |
| |
| return cmocka_run_group_tests(cmut, NULL, NULL); |
| } |