blob: fb6170ca49d59776c68e814d72f21607ab8b6deb [file] [log] [blame]
Radek Krejci3a4889a2020-05-19 17:01:58 +02001/*
aPiecek023f83a2021-05-11 07:37:03 +02002 * @file test_schema.h
Radek Krejci3a4889a2020-05-19 17:01:58 +02003 * @author: Radek Krejci <rkrejci@cesnet.cz>
4 * @brief macros for schema tests
5 *
6 * Copyright (c) 2018-2020 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 */
Radek Krejcib4ac5a92020-11-23 17:54:33 +010014
Radek Krejci18abde42020-06-13 20:04:39 +020015#ifndef TESTS_UTESTS_SCHEMA_TEST_SCHEMA_H_
16#define TESTS_UTESTS_SCHEMA_TEST_SCHEMA_H_
17
Radek Iša56ca9e42020-09-08 18:42:00 +020018#include "utests.h"
19
Radek Krejci18abde42020-06-13 20:04:39 +020020#include "log.h"
21#include "parser_schema.h"
Radek Krejcief5f7672021-04-01 17:04:12 +020022#include "tests_config.h"
Radek Krejci18abde42020-06-13 20:04:39 +020023
Radek Krejci18abde42020-06-13 20:04:39 +020024LY_ERR test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name),
Radek Krejcib4ac5a92020-11-23 17:54:33 +010025 const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT * format,
26 const char **module_data, void (**free_module_data)(void *model_data, void *user_data));
Radek Krejci3a4889a2020-05-19 17:01:58 +020027
28#define TEST_YANG_MODULE_10(MOD_NAME, MOD_PREFIX, MOD_NS, CONTENT) \
29 "module "MOD_NAME" { namespace "MOD_NS"; prefix "MOD_PREFIX"; "CONTENT"}"
30
31#define TEST_YANG_MODULE_11(MOD_NAME, MOD_PREFIX, MOD_NS, CONTENT) \
32 "module "MOD_NAME" {yang-version 1.1; namespace "MOD_NS"; prefix "MOD_PREFIX"; "CONTENT"}"
33
34#define TEST_YIN_MODULE_10(MOD_NAME, MOD_PREFIX, MOD_NS, CONTENT) \
35 "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\""MOD_NAME"\">" \
36 "<namespace uri=\""MOD_NS"\"/><prefix value=\""MOD_PREFIX"\"/>"CONTENT"</module>"
37
38#define TEST_YIN_MODULE_11(MOD_NAME, MOD_PREFIX, MOD_NS, CONTENT) \
39 "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\""MOD_NAME"\"><yang-version value=\"1.1\"/>" \
40 "<namespace uri=\""MOD_NS"\"/><prefix value=\""MOD_PREFIX"\"/>"CONTENT"</module>"
41
Radek Iša56ca9e42020-09-08 18:42:00 +020042#define TEST_SCHEMA_STR(RFC7950, YIN, MOD_NAME, CONTENT, STR) \
Radek Krejci3a4889a2020-05-19 17:01:58 +020043 if (YIN) { \
44 if (RFC7950) { \
45 STR = TEST_YIN_MODULE_11(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \
46 } else { \
47 STR = TEST_YIN_MODULE_10(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \
48 } \
49 } else { /* YANG */ \
50 if (RFC7950) { \
51 STR = TEST_YANG_MODULE_11(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \
52 } else { \
53 STR = TEST_YANG_MODULE_10(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \
54 } \
55 }
56
Radek Iša56ca9e42020-09-08 18:42:00 +020057#define TEST_SCHEMA_OK(RFC7950, YIN, MOD_NAME, CONTENT, RESULT) \
Radek Krejci3a4889a2020-05-19 17:01:58 +020058 { \
59 const char *test_str__; \
Radek Iša56ca9e42020-09-08 18:42:00 +020060 TEST_SCHEMA_STR(RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \
61 assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG, &(RESULT))); \
Radek Krejci3a4889a2020-05-19 17:01:58 +020062 }
63
Radek Iša56ca9e42020-09-08 18:42:00 +020064#define TEST_SCHEMA_ERR(RFC7950, YIN, MOD_NAME, CONTENT, ERRMSG, ERRPATH) \
Radek Krejci3a4889a2020-05-19 17:01:58 +020065 { \
66 const char *test_str__; \
Radek Iša56ca9e42020-09-08 18:42:00 +020067 TEST_SCHEMA_STR(RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \
68 assert_int_not_equal(lys_parse_mem(UTEST_LYCTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG, NULL), LY_SUCCESS); \
69 CHECK_LOG_CTX(ERRMSG, ERRPATH); \
Radek Krejci3a4889a2020-05-19 17:01:58 +020070 }
71
Radek Iša56ca9e42020-09-08 18:42:00 +020072#define TEST_STMT_DUP(RFC7950, YIN, STMT, MEMBER, VALUE1, VALUE2, LINE) \
Radek Krejci3a4889a2020-05-19 17:01:58 +020073 if (YIN) { \
Radek Iša56ca9e42020-09-08 18:42:00 +020074 TEST_SCHEMA_ERR(RFC7950, YIN, "dup", "", "Duplicate keyword \""MEMBER"\".", "Line number "LINE"."); \
Radek Krejci3a4889a2020-05-19 17:01:58 +020075 } else { \
Radek Iša56ca9e42020-09-08 18:42:00 +020076 TEST_SCHEMA_ERR(RFC7950, YIN, "dup", STMT"{"MEMBER" "VALUE1";"MEMBER" "VALUE2";}", \
77 "Duplicate keyword \""MEMBER"\".", "Line number "LINE"."); \
Radek Krejci3a4889a2020-05-19 17:01:58 +020078 }
79
Radek Iša56ca9e42020-09-08 18:42:00 +020080#define TEST_STMT_SUBSTM_ERR(RFC7950, STMT, SUBSTMT, VALUE) ;\
81 TEST_SCHEMA_ERR(RFC7950, 0, "inv", STMT" test {"SUBSTMT" "VALUE";}", \
82 "Invalid keyword \""SUBSTMT"\" as a child of \""STMT"\".", "Line number 1.");
Radek Krejci3a4889a2020-05-19 17:01:58 +020083
Radek Krejci18abde42020-06-13 20:04:39 +020084#endif /* TESTS_UTESTS_SCHEMA_TEST_SCHEMA_H_ */