Michal Vasko | f713cc0 | 2018-12-10 12:06:00 +0100 | [diff] [blame^] | 1 | /** |
| 2 | * \file test_invalid.c |
| 3 | * \author Michal Vasko <mvasko@cesnet.cz> |
| 4 | * \brief libyang tests - loading invalid schemas |
| 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 | |
| 15 | #include <errno.h> |
| 16 | #include <fcntl.h> |
| 17 | #include <pthread.h> |
| 18 | #include <setjmp.h> |
| 19 | #include <unistd.h> |
| 20 | #include <stddef.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
| 23 | #include <sys/stat.h> |
| 24 | #include <sys/types.h> |
| 25 | #include <stdarg.h> |
| 26 | #include <cmocka.h> |
| 27 | |
| 28 | #include "libyang.h" |
| 29 | #include "tests/config.h" |
| 30 | |
| 31 | struct state { |
| 32 | struct ly_ctx *ctx; |
| 33 | }; |
| 34 | |
| 35 | static int |
| 36 | setup_ctx(void **state) |
| 37 | { |
| 38 | struct state *st; |
| 39 | (*state) = st = calloc(1, sizeof *st); |
| 40 | if (!st) { |
| 41 | fprintf(stderr, "Memory allocation error"); |
| 42 | return -1; |
| 43 | } |
| 44 | |
| 45 | /* libyang context */ |
| 46 | st->ctx = ly_ctx_new(NULL, 0); |
| 47 | if (!st->ctx) { |
| 48 | fprintf(stderr, "Failed to create context.\n"); |
| 49 | goto error; |
| 50 | } |
| 51 | |
| 52 | return 0; |
| 53 | |
| 54 | error: |
| 55 | ly_ctx_destroy(st->ctx, NULL); |
| 56 | free(st); |
| 57 | (*state) = NULL; |
| 58 | |
| 59 | return -1; |
| 60 | } |
| 61 | |
| 62 | static int |
| 63 | teardown_ctx(void **state) |
| 64 | { |
| 65 | struct state *st = (*state); |
| 66 | |
| 67 | ly_ctx_destroy(st->ctx, NULL); |
| 68 | free(st); |
| 69 | (*state) = NULL; |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | static void |
| 75 | test_case_act_notif(void **state) |
| 76 | { |
| 77 | const char *schema = TESTS_DIR"/schema/yang/files/case-act-notif.yang"; |
| 78 | struct state *st = (*state); |
| 79 | const struct lys_module *mod; |
| 80 | |
| 81 | mod = lys_parse_path(st->ctx, schema, LYS_IN_YANG); |
| 82 | assert_ptr_equal(mod, NULL); |
| 83 | } |
| 84 | |
| 85 | int |
| 86 | main(void) |
| 87 | { |
| 88 | const struct CMUnitTest cmut[] = { |
| 89 | cmocka_unit_test_setup_teardown(test_case_act_notif, setup_ctx, teardown_ctx), |
| 90 | }; |
| 91 | |
| 92 | return cmocka_run_group_tests(cmut, NULL, NULL); |
| 93 | } |