Radek Krejci | 3a4889a | 2020-05-19 17:01:58 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * @file macros.h |
| 3 | * @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 | */ |
| 14 | #ifndef TESTS_UTESTS_SCHEMA_MACROS_H_ |
| 15 | #define TESTS_UTESTS_SCHEMA_MACROS_H_ |
| 16 | |
| 17 | #define TEST_YANG_MODULE_10(MOD_NAME, MOD_PREFIX, MOD_NS, CONTENT) \ |
| 18 | "module "MOD_NAME" { namespace "MOD_NS"; prefix "MOD_PREFIX"; "CONTENT"}" |
| 19 | |
| 20 | #define TEST_YANG_MODULE_11(MOD_NAME, MOD_PREFIX, MOD_NS, CONTENT) \ |
| 21 | "module "MOD_NAME" {yang-version 1.1; namespace "MOD_NS"; prefix "MOD_PREFIX"; "CONTENT"}" |
| 22 | |
| 23 | #define TEST_YIN_MODULE_10(MOD_NAME, MOD_PREFIX, MOD_NS, CONTENT) \ |
| 24 | "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\""MOD_NAME"\">" \ |
| 25 | "<namespace uri=\""MOD_NS"\"/><prefix value=\""MOD_PREFIX"\"/>"CONTENT"</module>" |
| 26 | |
| 27 | #define TEST_YIN_MODULE_11(MOD_NAME, MOD_PREFIX, MOD_NS, CONTENT) \ |
| 28 | "<module xmlns=\"urn:ietf:params:xml:ns:yang:yin:1\" name=\""MOD_NAME"\"><yang-version value=\"1.1\"/>" \ |
| 29 | "<namespace uri=\""MOD_NS"\"/><prefix value=\""MOD_PREFIX"\"/>"CONTENT"</module>" |
| 30 | |
| 31 | #define TEST_SCHEMA_STR(CTX, RFC7950, YIN, MOD_NAME, CONTENT, STR) \ |
| 32 | if (YIN) { \ |
| 33 | if (RFC7950) { \ |
| 34 | STR = TEST_YIN_MODULE_11(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \ |
| 35 | } else { \ |
| 36 | STR = TEST_YIN_MODULE_10(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \ |
| 37 | } \ |
| 38 | } else { /* YANG */ \ |
| 39 | if (RFC7950) { \ |
| 40 | STR = TEST_YANG_MODULE_11(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \ |
| 41 | } else { \ |
| 42 | STR = TEST_YANG_MODULE_10(MOD_NAME, MOD_NAME, "urn:libyang:test:"MOD_NAME, CONTENT); \ |
| 43 | } \ |
| 44 | } |
| 45 | |
| 46 | #define TEST_SCHEMA_OK(CTX, RFC7950, YIN, MOD_NAME, CONTENT, RESULT) \ |
| 47 | { \ |
| 48 | const char *test_str__; \ |
| 49 | TEST_SCHEMA_STR(CTX, RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \ |
| 50 | assert_non_null(RESULT = lys_parse_mem(CTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG)); \ |
| 51 | } |
| 52 | |
| 53 | #define TEST_SCHEMA_ERR(CTX, RFC7950, YIN, MOD_NAME, CONTENT, ERRMSG) \ |
| 54 | { \ |
| 55 | const char *test_str__; \ |
| 56 | TEST_SCHEMA_STR(CTX, RFC7950, YIN, MOD_NAME, CONTENT, test_str__) \ |
| 57 | assert_null(lys_parse_mem(CTX, test_str__, YIN ? LYS_IN_YIN : LYS_IN_YANG)); \ |
| 58 | logbuf_assert(ERRMSG); \ |
| 59 | } |
| 60 | |
| 61 | #define TEST_STMT_DUP(CTX, RFC7950, YIN, STMT, MEMBER, VALUE1, VALUE2, LINE) \ |
| 62 | if (YIN) { \ |
| 63 | TEST_SCHEMA_ERR(CTX, RFC7950, YIN, "dup", "", "Duplicate keyword \""MEMBER"\". Line number "LINE"."); \ |
| 64 | } else { \ |
| 65 | TEST_SCHEMA_ERR(CTX, RFC7950, YIN, "dup", STMT"{"MEMBER" "VALUE1";"MEMBER" "VALUE2";}", \ |
| 66 | "Duplicate keyword \""MEMBER"\". Line number "LINE"."); \ |
| 67 | } |
| 68 | |
| 69 | #define TEST_STMT_SUBSTM_ERR(CTX, RFC7950, STMT, SUBSTMT, VALUE); \ |
| 70 | TEST_SCHEMA_ERR(CTX, RFC7950, 0, "inv", STMT" test {"SUBSTMT" "VALUE";}", "Invalid keyword \""SUBSTMT"\" as a child of \""STMT"\". Line number 1."); |
| 71 | |
| 72 | #endif /* TESTS_UTESTS_SCHEMA_MACROS_H_ */ |