blob: b7588dc6e7a990b601b2dfb10af3a6392bf11996 [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 Krejci8297b792020-08-16 14:49:05 +020022#include "set.h"
Radek Krejcief5f7672021-04-01 17:04:12 +020023#include "tests_config.h"
Radek Krejci18abde42020-06-13 20:04:39 +020024
Radek Krejci18abde42020-06-13 20:04:39 +020025LY_ERR test_imp_clb(const char *UNUSED(mod_name), const char *UNUSED(mod_rev), const char *UNUSED(submod_name),
Michal Vasko84b35fd2021-07-15 15:03:43 +020026 const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT * format,
Radek Krejcib4ac5a92020-11-23 17:54:33 +010027 const char **module_data, void (**free_module_data)(void *model_data, void *user_data));
Radek Krejci3a4889a2020-05-19 17:01:58 +020028
29#define TEST_YANG_MODULE_10(MOD_NAME, MOD_PREFIX, MOD_NS, CONTENT) \
30 "module "MOD_NAME" { namespace "MOD_NS"; prefix "MOD_PREFIX"; "CONTENT"}"
31
32#define TEST_YANG_MODULE_11(MOD_NAME, MOD_PREFIX, MOD_NS, CONTENT) \
33 "module "MOD_NAME" {yang-version 1.1; namespace "MOD_NS"; prefix "MOD_PREFIX"; "CONTENT"}"
34
35#define TEST_YIN_MODULE_10(MOD_NAME, MOD_PREFIX, MOD_NS, CONTENT) \
36 "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\""MOD_NAME"\">" \
37 "<namespace uri=\""MOD_NS"\"/><prefix value=\""MOD_PREFIX"\"/>"CONTENT"</module>"
38
39#define TEST_YIN_MODULE_11(MOD_NAME, MOD_PREFIX, MOD_NS, CONTENT) \
40 "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\""MOD_NAME"\"><yang-version value=\"1.1\"/>" \
41 "<namespace uri=\""MOD_NS"\"/><prefix value=\""MOD_PREFIX"\"/>"CONTENT"</module>"
42
Radek Iša56ca9e42020-09-08 18:42:00 +020043#define TEST_SCHEMA_STR(RFC7950, YIN, MOD_NAME, CONTENT, STR) \
Radek Krejci3a4889a2020-05-19 17:01:58 +020044 if (YIN) { \
45 if (RFC7950) { \
46 STR = TEST_YIN_MODULE_11(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \
47 } else { \
48 STR = TEST_YIN_MODULE_10(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \
49 } \
50 } else { /* YANG */ \
51 if (RFC7950) { \
52 STR = TEST_YANG_MODULE_11(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \
53 } else { \
54 STR = TEST_YANG_MODULE_10(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \
55 } \
56 }
57
Radek Iša56ca9e42020-09-08 18:42:00 +020058#define TEST_SCHEMA_OK(RFC7950, YIN, MOD_NAME, CONTENT, RESULT) \
Radek Krejci3a4889a2020-05-19 17:01:58 +020059 { \
60 const char *test_str__; \
Radek Iša56ca9e42020-09-08 18:42:00 +020061 TEST_SCHEMA_STR(RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \
62 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 +020063 }
64
Radek Iša56ca9e42020-09-08 18:42:00 +020065#define TEST_SCHEMA_ERR(RFC7950, YIN, MOD_NAME, CONTENT, ERRMSG, ERRPATH) \
Radek Krejci3a4889a2020-05-19 17:01:58 +020066 { \
67 const char *test_str__; \
Radek Iša56ca9e42020-09-08 18:42:00 +020068 TEST_SCHEMA_STR(RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \
69 assert_int_not_equal(lys_parse_mem(UTEST_LYCTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG, NULL), LY_SUCCESS); \
70 CHECK_LOG_CTX(ERRMSG, ERRPATH); \
Radek Krejci3a4889a2020-05-19 17:01:58 +020071 }
72
Radek Krejci8297b792020-08-16 14:49:05 +020073#define TEST_SCHEMA_PARSE_ERR(RFC7950, YIN, MOD_NAME, CONTENT, ERRMSG, ERRPATH) \
74 { \
75 const char *test_str__; \
76 TEST_SCHEMA_STR(RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \
77 assert_int_not_equal(lys_parse_mem(UTEST_LYCTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG, NULL), LY_SUCCESS); \
78 CHECK_LOG_CTX("Parsing module \""MOD_NAME"\" failed.", NULL, ERRMSG, ERRPATH); \
79 }
80
Radek Iša56ca9e42020-09-08 18:42:00 +020081#define TEST_STMT_DUP(RFC7950, YIN, STMT, MEMBER, VALUE1, VALUE2, LINE) \
Radek Krejci3a4889a2020-05-19 17:01:58 +020082 if (YIN) { \
Radek Krejci8297b792020-08-16 14:49:05 +020083 TEST_SCHEMA_PARSE_ERR(RFC7950, YIN, "dup", "", "Duplicate keyword \""MEMBER"\".", "Line number "LINE"."); \
Radek Krejci3a4889a2020-05-19 17:01:58 +020084 } else { \
Radek Krejci8297b792020-08-16 14:49:05 +020085 TEST_SCHEMA_PARSE_ERR(RFC7950, YIN, "dup", STMT"{"MEMBER" "VALUE1";"MEMBER" "VALUE2";}", \
Radek Iša56ca9e42020-09-08 18:42:00 +020086 "Duplicate keyword \""MEMBER"\".", "Line number "LINE"."); \
Radek Krejci3a4889a2020-05-19 17:01:58 +020087 }
88
Radek Iša56ca9e42020-09-08 18:42:00 +020089#define TEST_STMT_SUBSTM_ERR(RFC7950, STMT, SUBSTMT, VALUE) ;\
Radek Krejci8297b792020-08-16 14:49:05 +020090 TEST_SCHEMA_PARSE_ERR(RFC7950, 0, "inv", STMT" test {"SUBSTMT" "VALUE";}", \
Radek Iša56ca9e42020-09-08 18:42:00 +020091 "Invalid keyword \""SUBSTMT"\" as a child of \""STMT"\".", "Line number 1.");
Radek Krejci3a4889a2020-05-19 17:01:58 +020092
Radek Krejci18abde42020-06-13 20:04:39 +020093#endif /* TESTS_UTESTS_SCHEMA_TEST_SCHEMA_H_ */