1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505
|
/**
* @file utests.h
* @author Radek Iša <isa@cesnet.cz>
* @author Radek Krejci <rkrejci@cesnet.cz>
* @author Michal Vasko <mvasko@cesnet.cz>
* @brief this file contains macros for simplification test writing
*
* Copyright (c) 2021 - 2022 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
*/
#ifndef _UTESTS_H_
#define _UTESTS_H_
#define _POSIX_C_SOURCE 200809L /* strdup */
#include <setjmp.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <cmocka.h>
#include <string.h>
#include "libyang.h"
#include "plugins_exts/metadata.h"
#include "plugins_internal.h"
#include "plugins_types.h"
#include "tests_config.h"
#include "tree_schema_internal.h"
/**
* TESTS OVERVIEW
*
* To include utest's environment, just include "utests.h" in the test's source
* code. In case it is the main source code for a cmocka test group (there is a
* main() function), define _UTEST_MAIN_ before including this header.
*
* TESTS VARIABLES
*
* Checking macros use internal storage to store various variables necessary
* during the checking. It is possible to access these variables using the
* following macros:
*
* UTEST_LYCTX - libyang context
* UTEST_IN - input handler
* UTEST_OUT - output handler
*
* All these variables are cleaned with test's teardown.
*
* TESTS SETUP
*
* CMocka's CMUnitTest list definition macros (cmoka_unit_test*()) are replaced
* by UTEST macro with possibility to specify own setup and teardown functions:
*
* UTEST(test_func) - only implicit setup and teardown functions are used
* UTEST(test_func, setup) - implicit teardown but own setup
* UTEST(test_func, setup, teardown) - both setup and teardown are test-specific
*
* Note that the tests environment always provide (and need) internal setup and
* teardown functions. In case the test-specific setup or teardown are used, they
* are supposed to include UTEST_SETUP at the setup beginning and UTEST_TEARDOWN
* at the teardown end.
*
* Libyang context is part of the prepared environment. To add a schema into the
* context (despite it is in the test-specific setup or in test function itself),
* use UTEST_ADD_MODULE macro.
*
* LOGGING
*
* There are 2 macros to check content of the log from the previously called
* libyang function. CHECK_LOG macro test only the last error message and path
* stored directly via logging callback. CHECK_LOG_CTX gets error message and
* path from the libyang context (in case the function does not store the error
* information into the libyang context, the message cannot be checked this way).
* libyang is set to store multiple error information, so multiple couples of
* error message and path can be provided to be checked (the first couple
* corresponds to the latest error). The macro also cleanups the errors list, so
* it is fine to check that there is no error after succeeding successful
* function call.
*/
/**
* @brief Test's context to provide common storage for various variables.
*/
struct utest_context {
struct ly_ctx *ctx; /**< libyang context */
char *err_msg; /**< Directly logged error message */
char *err_path; /**< Directly logged error path */
struct ly_in *in; /**< Input handler */
struct ly_out *out; /**< Outpu handler */
char *orig_tz; /**< Original "TZ" environment variable value */
};
/**
* @brief Shortcut to access utest_context.
*/
#define _UC ((struct utest_context *)*state)
/**
* @brief libyang context provider.
*/
#define UTEST_LYCTX (_UC->ctx)
/**
* @brief Context's input handler provider
*/
#define UTEST_IN (_UC->in)
/**
* @brief Context's input handler provider
*/
#define UTEST_OUT (_UC->out)
/**
* @brief Parse (and validate) data from the input handler as a YANG data tree.
*
* @param[in] INPUT The input data in the specified @p format to parse (and validate)
* @param[in] INPUT_FORMAT Format of the input data to be parsed. Can be 0 to try to detect format from the input handler.
* @param[in] PARSE_OPTIONS Options for parser, see @ref dataparseroptions.
* @param[in] VALIDATE_OPTIONS Options for the validation phase, see @ref datavalidationoptions.
* @param[in] RET expected return status
* @param[out] OUT_NODE Resulting data tree built from the input data. Note that NULL can be a valid result as a
* representation of an empty YANG data tree.
*/
#define CHECK_PARSE_LYD_PARAM(INPUT, INPUT_FORMAT, PARSE_OPTIONS, VALIDATE_OPTIONS, RET, OUT_NODE) \
{ \
LY_ERR _r = lyd_parse_data_mem(_UC->ctx, INPUT, INPUT_FORMAT, PARSE_OPTIONS, VALIDATE_OPTIONS, &OUT_NODE); \
if (_r != RET) { \
if (_r) { \
fail_msg("%s != 0x%d; MSG: %s", #RET, _r, ly_err_last(_UC->ctx)->msg); \
} else { \
fail_msg("%s != 0x%d", #RET, _r); \
} \
} \
}
/**
* @brief Check if lyd_node and his subnodes have correct values. Print lyd_node and his sunodes int o string in json or xml format.
* @param[in] NODE pointer to lyd_node
* @param[in] TEXT expected output string in json or xml format.
* @param[in] FORMAT format of input text. LYD_JSON, LYD_XML
* @param[in] PARAM options [Data printer flags](@ref dataprinterflags).
*/
#define CHECK_LYD_STRING_PARAM(NODE, TEXT, FORMAT, PARAM) \
{ \
char *str; \
LY_ERR _r = lyd_print_mem(&str, NODE, FORMAT, PARAM); \
if (_r) { \
fail_msg("Print err 0x%d; MSG: %s", _r, ly_err_last(_UC->ctx)->msg); \
} \
assert_string_equal(str, TEXT); \
free(str); \
}
/**
* @brief Compare two lyd_node structure. Macro print lyd_node structure into string and then compare string. Print function use these two parameters. LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK;
* @param[in] NODE_1 pointer to lyd_node
* @param[in] NODE_2 pointer to lyd_node
*/
#define CHECK_LYD(NODE_1, NODE_2) \
{ \
char *str1; \
char *str2; \
assert_int_equal(LY_SUCCESS, lyd_print_mem(&str1, NODE_1, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK)); \
assert_int_equal(LY_SUCCESS, lyd_print_mem(&str2, NODE_2, LYD_XML, LYD_PRINT_WITHSIBLINGS | LYD_PRINT_SHRINK)); \
assert_non_null(str1); \
assert_non_null(str2); \
assert_string_equal(str1, str2); \
free(str1); \
free(str2); \
}
/*
* SUPPORT MACROS
*/
/**
* @brief Internal macro witch assert that two given string are equal or are both null.
*
* @param[in] STRING string to check
* @param[in] TEXT string to compare
*/
#define CHECK_STRING(STRING, TEXT)\
if (TEXT == NULL) { \
assert_null(STRING); \
} else { \
assert_non_null(STRING); \
assert_string_equal(STRING, TEXT); \
}
/**
* @brief Internal macro witch assert that pointer is null when flag is 0.
*
* @param[in] POINTER pointer to check
* @param[in] FLAG 0 -> pointer is NULL, 1 -> pointer is not null
*/
#define CHECK_POINTER(POINTER, FLAG) \
assert_true(FLAG == 0 ? POINTER == NULL : POINTER != NULL)
/**
* @brief Internal macro check size of [sized array](@ref sizedarrays)'s
*
* @param[in] ARRAY pointer to [sized array](@ref sizedarrays)
* @param[in] SIZE expected [sized array](@ref sizedarrays) size of array
*/
#define CHECK_ARRAY(ARRAY, SIZE) \
assert_true((SIZE == 0) ? \
(ARRAY == NULL) : \
(ARRAY != NULL && SIZE == LY_ARRAY_COUNT(ARRAY)));
/*
* LIBYANG NODE CHECKING
*/
/**
* @brief check compileted type
*
* @param[in] NODE pointer to lysc_type value
* @param[in] TYPE expected type [LY_DATA_TYPE](@ref LY_DATA_TYPE)
* @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list
*/
#define CHECK_LYSC_TYPE(NODE, TYPE, EXTS) \
assert_non_null(NODE); \
assert_int_equal((NODE)->basetype, TYPE); \
CHECK_ARRAY((NODE)->exts, EXTS); \
assert_ptr_equal((NODE)->plugin, lyplg_type_plugin_find("", NULL, ly_data_type2str[TYPE]))
/**
* @brief check compileted numeric type
*
* @param[in] NODE pointer to lysc_type_num value
* @param[in] TYPE expected type [LY_DATA_TYPE](@ref LY_DATA_TYPE)
* @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list
* @warning only integer types INT, UINT, NUM
*/
#define CHECK_LYSC_TYPE_NUM(NODE, TYPE, EXTS, RANGE) \
CHECK_LYSC_TYPE(NODE, TYPE, EXTS);\
CHECK_POINTER((NODE)->range, RANGE)
/**
* @brief check compiled string type
*
* @param[in] NODE pointer to lysc_type_num value
* @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list
* @param[in] LENGTH 0 -> node dosnt have length limitation, 1 -> node have length limitation
* @param[in] PATTERNS expected number of patterns [sized array](@ref sizedarrays)
* @warning only integer types INT, UINT, NUM
*/
#define CHECK_LYSC_TYPE_STR(NODE, EXTS, LENGTH, PATTERNS) \
CHECK_LYSC_TYPE(NODE, LY_TYPE_STRING, EXTS); \
CHECK_POINTER((NODE)->length, LENGTH); \
CHECK_ARRAY((NODE)->patterns, PATTERNS)
/**
* @brief check compiled bits type
*
* @param[in] NODE pointer to lysc_type_num value
* @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list
* @param[in] BITS expected number of bits
* @warning only integer types INT, UINT, NUM
*/
#define CHECK_LYSC_TYPE_BITS(NODE, EXTS, BITS) \
CHECK_LYSC_TYPE(NODE, LY_TYPE_BITS, EXTS); \
CHECK_ARRAY((NODE)->bits, BITS)
#define CHECK_LYSC_TYPE_BITENUM_ITEM(NODE, POSITION, DSC, EXTS, FLAGS, NAME, REF)\
assert_non_null(NODE); \
assert_int_equal((NODE)->position, POSITION); \
CHECK_STRING((NODE)->dsc, DSC); \
CHECK_ARRAY((NODE)->exts, EXTS); \
assert_int_equal((NODE)->flags, FLAGS); \
CHECK_STRING((NODE)->name, NAME); \
CHECK_STRING((NODE)->ref, REF) \
/**
* @brief check range
*
* @param[in] NODE pointer to lysc_range value
* @param[in] DSC expected descriptin (string)
* @param[in] EAPPTAG expected string reprezenting error-app-tag value
* @param[in] EMSG expected string reprezenting error message
* @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list
* @param[in] PARTS expected [sized array](@ref sizedarrays) number of rang limitations
* @param[in] REF expected reference
*/
#define CHECK_LYSC_RANGE(NODE, DSC, EAPPTAG, EMSG, EXTS, PARTS, REF) \
assert_non_null(NODE); \
CHECK_STRING((NODE)->dsc, DSC); \
CHECK_STRING((NODE)->eapptag, EAPPTAG); \
CHECK_STRING((NODE)->emsg, EMSG); \
CHECK_ARRAY((NODE)->exts, EXTS); \
CHECK_ARRAY((NODE)->parts, PARTS); \
CHECK_STRING((NODE)->ref, REF)
/**
* @brief check pattern
*
* @param[in] NODE pointer to lysc_pattern value
* @param[in] DSC expected descriptin (string)
* @param[in] EAPPTAG expected string reprezenting error-app-tag value
* @param[in] EMSG expected string reprezenting error message
* @param[in] EEXPR expected string reprezenting original, not compiled, regular expression
* @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list
* @param[in] INVERTED if regular expression is inverted.
* @param[in] REF expected reference
*/
#define CHECK_LYSC_PATTERN(NODE, DSC, EAPPTAG, EMSG, EXPR, EXTS, INVERTED, REF) \
assert_non_null(NODE); \
assert_non_null((NODE)->code); \
CHECK_STRING((NODE)->dsc, DSC); \
CHECK_STRING((NODE)->eapptag, EAPPTAG); \
CHECK_STRING((NODE)->emsg, EMSG); \
CHECK_STRING((NODE)->expr, EXPR); \
CHECK_ARRAY((NODE)->exts, EXTS); \
assert_int_equal((NODE)->inverted, INVERTED); \
CHECK_STRING((NODE)->ref, REF)
/**
* @brief assert that lysp_action_inout structure members are correct
*
* @param[in] NODE pointer to lysp_action_inout variable
* @param[in] DATA 0 -> check if pointer to data is NULL, 1 -> check if pointer to data is not null
* @param[in] EXTS expected [sized array](@ref sizedarrays) size of extens list
* @param[in] GROUPINGS expected [sized array](@ref sizedarrays) size of grouping list
* @param[in] MUSTS expected [sized array](@ref sizedarrays) size of must restriction list
* @param[in] NODETYPE node type. LYS_INPUT or LYS_OUTPUT
* @param[in] PARENT 0 -> check if node is root, 1 -> check if node is not root
* @param[in] TYPEDEFS expected [sized array](@ref sizedarrays) size of typedefs list
*/
#define CHECK_LYSP_ACTION_INOUT(NODE, DATA, EXTS, GROUPINGS, MUSTS, NODETYPE, PARENT, TYPEDEFS) \
assert_non_null(NODE); \
CHECK_POINTER((NODE)->child, DATA); \
CHECK_ARRAY((NODE)->exts, EXTS); \
CHECK_POINTER((NODE)->groupings, GROUPINGS); \
CHECK_ARRAY((NODE)->musts, MUSTS); \
assert_int_equal((NODE)->nodetype, NODETYPE); \
CHECK_POINTER((NODE)->parent, PARENT); \
CHECK_ARRAY((NODE)->typedefs, TYPEDEFS);
/**
* @brief assert that lysp_action structure members are correct
*
* @param[in] NODE pointer to lysp_action variable
* @param[in] DSC expected description
* @param[in] EXTS expected [sized array](@ref sizedarrays) size of extension list
* @param[in] FLAGS expected [schema node flags](@ref snodeflags)
* @param[in] GROUPINGS expected [sized array](@ref sizedarrays) size of grouping list
* @param[in] IFFEATURES expected [sized array](@ref sizedarrays) size of if-feature expressions list
* @param[in] INPUT_* ::LYSP_ACTION_INOUT_CHECK
* @param[in] NAME expected name
* @param[in] NODETYPE node type. LYS_RPC or LYS_ACTION
* @param[in] OUTPUT_* ::LYSP_ACTION_INOUT_CHECK
* @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
* @param[in] REF expected reference
* @param[in] TYPEDEFS expected [sized array](@ref sizedarrays) size of list of typedefs
*/
#define CHECK_LYSP_ACTION(NODE, DSC, EXTS, FLAGS, GROUPINGS, IFFEATURES, \
INPUT_DATA, INPUT_EXTS, INPUT_GROUPINGS, INPUT_MUSTS, \
INPUT_PARENT, INPUT_TYPEDEFS, \
NAME, NODETYPE, \
OUTPUT_DATA, OUTPUT_EXTS, OUTPUT_GROUPINGS, OUTPUT_MUSTS, \
OUTPUT_PARENT, OUTPUT_TYPEDEFS, \
PARENT, REF, TYPEDEFS) \
assert_non_null(NODE); \
CHECK_STRING((NODE)->dsc, DSC); \
CHECK_ARRAY((NODE)->exts, EXTS); \
assert_int_equal((NODE)->flags, FLAGS); \
CHECK_POINTER((NODE)->groupings, GROUPINGS); \
CHECK_ARRAY((NODE)->iffeatures, IFFEATURES); \
CHECK_LYSP_ACTION_INOUT(&((NODE)->input), INPUT_DATA, INPUT_EXTS, INPUT_GROUPINGS, \
INPUT_MUSTS, LYS_INPUT, INPUT_PARENT, INPUT_TYPEDEFS); \
assert_string_equal((NODE)->name, NAME); \
assert_int_equal((NODE)->nodetype, NODETYPE); \
CHECK_LYSP_ACTION_INOUT(&((NODE)->output), OUTPUT_DATA, OUTPUT_EXTS, OUTPUT_GROUPINGS, \
OUTPUT_MUSTS, LYS_OUTPUT, OUTPUT_PARENT, OUTPUT_TYPEDEFS); \
CHECK_POINTER((NODE)->parent, PARENT); \
CHECK_STRING((NODE)->ref, REF); \
CHECK_ARRAY((NODE)->typedefs, TYPEDEFS) \
/**
* @brief assert that lysp_when structure members are correct
*
* @param[in] NODE pointer to lysp_when variable
* @param[in] COND expected string specifid condition
* @param[in] DSC expected string description statement
* @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of extension array
* @param[in] REF expected string reference
*/
#define CHECK_LYSP_WHEN(NODE, COND, DSC, EXTS, REF) \
assert_non_null(NODE); \
assert_string_equal((NODE)->cond, COND); \
CHECK_STRING((NODE)->dsc, DSC); \
CHECK_ARRAY((NODE)->exts, EXTS); \
if (REF == NULL) { \
assert_null((NODE)->ref); \
} else { \
assert_non_null((NODE)->ref); \
assert_string_equal((NODE)->ref, REF); \
}
/**
* @brief assert that lysp_restr structure members are correct
*
* @param[in] NODE pointer to lysp_restr variable
* @param[in] ARG_STR expected string. The restriction expression/value
* @param[in] DSC expected descrition
* @param[in] EAPPTAG expected string reprezenting error-app-tag value
* @param[in] EMSG expected string reprezenting error message
* @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of extension array
* @param[in] REF expected reference
*/
#define CHECK_LYSP_RESTR(NODE, ARG_STR, DSC, EAPPTAG, EMSG, EXTS, REF) \
assert_non_null(NODE); \
assert_non_null((NODE)->arg.mod); \
assert_string_equal((NODE)->arg.str, ARG_STR); \
CHECK_STRING((NODE)->dsc, DSC); \
CHECK_STRING((NODE)->eapptag, EAPPTAG); \
CHECK_STRING((NODE)->emsg, EMSG); \
CHECK_ARRAY((NODE)->exts, EXTS); \
CHECK_STRING((NODE)->ref, REF);
/**
* @brief assert that lysp_import structure members are correct
*
* @param[in] NODE pointer to lysp_import variable
* @param[in] DSC expected description or NULL
* @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of extensions
* @param[in] NAME expected name of imported module
* @param[in] PREFIX expected prefix for the data from the imported schema
* @param[in] REF expected reference
* @param[in] REV expected reprezenting date in format "11-10-2020"
*/
#define CHECK_LYSP_IMPORT(NODE, DSC, EXTS, NAME, PREFIX, REF, REV) \
assert_non_null(NODE); \
CHECK_STRING((NODE)->dsc, DSC); \
CHECK_ARRAY((NODE)->exts, EXTS); \
assert_string_equal((NODE)->name, NAME); \
assert_string_equal((NODE)->prefix, PREFIX); \
CHECK_STRING((NODE)->ref, REF); \
CHECK_STRING((NODE)->rev, REV); \
/**
* @brief assert that lysp_ext structure members are correct
*
* @param[in] NODE pointer to lysp_ext_instance variable
* @param[in] ARGNAME expected argument name
* @param[in] COMPILED 0 -> compiled data dosnt exists, 1 -> compiled data exists
* @param[in] DSC expected string reprezent description
* @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of extension instances
* @param[in] FLAGS expected LYS_STATUS_* and LYS_YINELEM_* values (@ref snodeflags)
* @param[in] NAME expected name
* @param[in] REF expected ref
*/
#define CHECK_LYSP_EXT(NODE, ARGNAME, COMPILED, DSC, EXTS, FLAGS, NAME, REF) \
assert_non_null(NODE); \
CHECK_STRING((NODE)->argname, ARGNAME); \
CHECK_POINTER((NODE)->compiled, COMPILED); \
CHECK_STRING((NODE)->dsc, DSC); \
CHECK_ARRAY((NODE)->exts, EXTS); \
assert_int_equal((NODE)->flags, FLAGS); \
assert_string_equal((NODE)->name, NAME); \
CHECK_STRING((NODE)->ref, REF);
/**
* @brief assert that lysp_ext_instance structure members are correct
*
* @param[in] NODE pointer to lysp_ext_instance variable
* @param[in] ARGUMENT expected optional value of the extension's argument
* @param[in] CHILD 0 -> node doesnt have child, 1 -> node have children
* @param[in] PARENT_STMT expected value identifying placement of the extension instance
* @param[in] PARENT_STMT_INDEX expected indentifi index
* @param[in] FORMAT expected format
*/
#define CHECK_LYSP_EXT_INSTANCE(NODE, ARGUMENT, CHILD, PARENT_STMT, PARENT_STMT_INDEX, NAME, FORMAT) \
assert_non_null(NODE); \
CHECK_STRING((NODE)->argument, ARGUMENT); \
CHECK_POINTER((NODE)->child, CHILD); \
assert_int_equal((NODE)->parent_stmt, PARENT_STMT); \
assert_int_equal((NODE)->parent_stmt_index, PARENT_STMT_INDEX); \
assert_string_equal((NODE)->name, NAME); \
assert_int_equal((NODE)->format, FORMAT);
/**
* @brief assert that lysp_stmt structure members are correct
*
* @param[in] NODE pointer to lysp_stmt variable
* @param[in] ARG expected statemet argumet
* @param[in] CHILD 0 -> node doesnt have child, 1 -> node have children
* @param[in] FLAGS expected statement flags, can be set to LYS_YIN_ATTR
* @param[in] KW expected numeric respresentation of the stmt value
* @param[in] NEXT 0 -> pointer is NULL, 1 -> pointer is not null
* @param[in] STMS expected identifier of the statement
*/
#define CHECK_LYSP_STMT(NODE, ARG, CHILD, FLAGS, KW, NEXT, STMT) \
assert_non_null(NODE); \
CHECK_STRING((NODE)->arg, ARG); \
CHECK_POINTER((NODE)->child, CHILD); \
assert_int_equal((NODE)->flags, FLAGS); \
assert_int_equal((NODE)->kw, KW); \
CHECK_POINTER((NODE)->next, NEXT); \
assert_string_equal((NODE)->stmt, STMT); \
/**
* @brief assert that lysp_type_enum structure members are correct
*
* @param[in] NODE pointer to lysp_type_enum variable
* @param[in] DSC expected description
* @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
* @param[in] FLAGS only LYS_STATUS_ and LYS_SET_VALUE values are allowed
* @param[in] IFFEATURES expected [sized array](@ref sizedarrays) size of list of the extension instances
* @param[in] NAME expected name
* @param[in] REF expected reference statement
* @param[in] VALUE expected enum's value or bit's position
*/
#define CHECK_LYSP_TYPE_ENUM(NODE, DSC, EXTS, FLAGS, IFFEATURES, NAME, REF, VALUE) \
assert_non_null(NODE); \
CHECK_STRING((NODE)->dsc, DSC); \
CHECK_ARRAY((NODE)->exts, EXTS); \
assert_int_equal((NODE)->flags, FLAGS); \
CHECK_ARRAY((NODE)->iffeatures, IFFEATURES); \
CHECK_STRING((NODE)->name, NAME); \
CHECK_STRING((NODE)->ref, REF); \
assert_int_equal(VALUE, (NODE)->value);
/**
* @brief assert that lysp_type_enum structure members are correct
*
* @param[in] NODE pointer to lysp_type variable
* @param[in] BASES expected [sized array](@ref sizedarrays) size of list of indentifiers
* @param[in] BITS expected [sized array](@ref sizedarrays) size of list of bits
* @param[in] COMPILED 0 -> pointer to compiled type is null, 1 -> pointer to compilet type is valid
* @param[in] ENUMS expected [sized array](@ref sizedarrays) size of list of enums-stmts
* @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of extension instances
* @param[in] FLAGS expected flags
* @param[in] FRACTION_DIGITS expected number of fraction digits decimal64
* @param[in] LENGTH expected 0 -> there isnt any restriction on length, 1 -> type is restricted on length (string, binary)
* @param[in] NAME expected name of type
* @param[in] PATH 0 -> no pointer to parsed path, 1 -> pointer to parsed path is valid
* @param[in] PATTERNS expected [sized array](@ref sizedarrays) size of list of patterns for string
* @param[in] PMOD expected submodule where type is defined 0 -> pointer is null, 1 -> pointer is not null
* @param[in] RANGE expected [sized array](@ref sizedarrays) size of list of range restriction
* @param[in] REQUIRE_INSTANCE expected require instance flag
* @param[in] TYPES expected [sized array](@ref sizedarrays) size of list of sub-types
*/
#define CHECK_LYSP_TYPE(NODE, BASES, BITS, COMPILED, ENUMS, EXTS, FLAGS, FRACTIONS_DIGITS, \
LENGTH, NAME, PATH, PATTERNS, PMOD, RANGE, REQUIRE_INSTANCE, TYPES) \
assert_non_null(NODE);\
CHECK_ARRAY((NODE)->bases, BASES); \
CHECK_ARRAY((NODE)->bits, BITS); \
CHECK_POINTER((NODE)->compiled, COMPILED); \
CHECK_ARRAY((NODE)->enums, ENUMS); \
CHECK_ARRAY((NODE)->exts, EXTS); \
assert_int_equal((NODE)->flags, FLAGS); \
assert_int_equal((NODE)->fraction_digits, FRACTIONS_DIGITS); \
CHECK_POINTER((NODE)->length, LENGTH); \
CHECK_STRING((NODE)->name, NAME); \
CHECK_POINTER((NODE)->path, PATH); \
CHECK_ARRAY((NODE)->patterns, PATTERNS); \
CHECK_POINTER((NODE)->pmod, PMOD); \
CHECK_POINTER((NODE)->range, RANGE); \
assert_int_equal((NODE)->require_instance, REQUIRE_INSTANCE); \
CHECK_ARRAY((NODE)->types , TYPES)
/**
* @brief assert that lysp_node structure members are correct
*
* @param[in] NODE pointer to lysp_node variable
* @param[in] DSC expected description statement
* @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
* @param[in] FLAGS [schema node flags](@ref snodeflags)
* @param[in] IFFEATURES expected [sized array](@ref sizedarrays) size of list of the extension instances
* @param[in] NAME expected name
* @param[in] NEXT 0 pointer is null, 1 pointer is not null
* @param[in] NODETYPE node type LYS_UNKNOWN, LYS_CONTAINER, LYS_CHOICE, LYS_LEAF, LYS_LEAFLIST,
* LYS_LIST, LYS_ANYXML, LYS_ANYDATA, LYS_CASE, LYS_RPC, LYS_ACTION, LYS_NOTIF,
* LYS_USES, LYS_INPUT, LYS_OUTPUT, LYS_GROUPING, LYS_AUGMENT
* @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
* @param[in] REF expected reference statement
* @param[in] WHEN 0-> pointer is null, 1 -> pointer is not null
*/
#define CHECK_LYSP_NODE(NODE, DSC, EXTS, FLAGS, IFFEATURES, NAME, NEXT, NODETYPE, PARENT, REF, WHEN) \
assert_non_null(NODE); \
CHECK_STRING((NODE)->dsc, DSC); \
CHECK_ARRAY((NODE)->exts, EXTS); \
assert_int_equal((NODE)->flags, FLAGS); \
CHECK_ARRAY((NODE)->iffeatures, IFFEATURES); \
CHECK_STRING((NODE)->name, NAME); \
CHECK_POINTER((NODE)->next, NEXT); \
assert_int_equal((NODE)->nodetype, NODETYPE); \
CHECK_POINTER((NODE)->parent, PARENT); \
CHECK_STRING((NODE)->ref, REF); \
CHECK_POINTER(lysp_node_when((struct lysp_node *)NODE), WHEN);
/**
* @brief assert that lysp_node structure members are correct
*
* @param[in] NODE pointer to lysp_node variable
* @param[in] DSC expected description statement
* @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
* @param[in] FLAGS [schema node flags](@ref snodeflags)
* @param[in] IFFEATURES expected [sized array](@ref sizedarrays) size of list of the extension instances
* @param[in] NAME expected name
* @param[in] NEXT 0 pointer is null, 1 pointer is not null
* @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
* @param[in] REF expected reference statement
* @param[in] WHEN 0-> pointer is null, 1 -> pointer is not null
* @param[in] MUSTS expected [sized array](@ref sizedarrays) size of list of must restriction
* @param[in] UNITS expected string reprezenting units
* @param[in] DFLT 0-> node dosn't have default value. 1 -> node have default value
*/
#define CHECK_LYSP_NODE_LEAF(NODE, DSC, EXTS, FLAGS, IFFEATURES, NAME, NEXT, \
PARENT, REF, WHEN, MUSTS, UNITS, DFLT) \
CHECK_LYSP_NODE(NODE, DSC, EXTS, FLAGS, IFFEATURES, NAME, NEXT, LYS_LEAF, PARENT, REF, WHEN); \
CHECK_ARRAY((NODE)->musts, MUSTS); \
CHECK_STRING((NODE)->units, UNITS); \
CHECK_STRING((NODE)->dflt.str, DFLT);
/**
* @brief assert that lysc_notif structure members are correct
*
* @param[in] NODE pointer to lysp_notif variable
* @param[in] DATA 0 pointer is null, 1 pointer is not null
* @param[in] DSC expected description
* @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
* @param[in] FLAGS [schema node flags](@ref snodeflags)
* @param[in] MODULE 0 pointer is null, 1 pointer is not null
* @param[in] MUSTS expected [sized array](@ref sizedarrays) size of list of must restriction
* @param[in] NAME expected name
* @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
* @param[in] PRIV 0-> pointer is null, 1-> pointer is not null
* @param[in] REF expected reference
* @param[in] WHEN expected [sized array](@ref sizedarrays) size of list of pointers to when statements
*/
#define CHECK_LYSC_NOTIF(NODE, DATA, DSC, EXTS, FLAGS, MODULE, MUSTS, NAME, PARENT, PRIV, REF, WHEN) \
assert_non_null(NODE); \
CHECK_POINTER((NODE)->child, DATA); \
CHECK_STRING((NODE)->dsc, DSC); \
CHECK_ARRAY((NODE)->exts, EXTS); \
assert_int_equal((NODE)->flags, FLAGS); \
CHECK_POINTER((NODE)->module, MODULE); \
CHECK_ARRAY((NODE)->musts, MUSTS); \
assert_string_equal((NODE)->name, NAME); \
assert_int_equal((NODE)->nodetype, LYS_NOTIF); \
CHECK_POINTER((NODE)->parent, PARENT); \
CHECK_POINTER((NODE)->priv, PRIV); \
CHECK_STRING((NODE)->ref, REF); \
CHECK_ARRAY(lysc_node_when((const struct lysc_node *)NODE), WHEN);
/**
* @brief assert that lysc_action_inout structure members are correct
*
* @param[in] NODE pointer to lysp_notif variable
* @param[in] DATA 0 pointer is null, 1 pointer is not null
* @param[in] MUST expected [sized array](@ref sizedarrays) size of list of must restrictions
* @param[in] NODETYPE LYS_INPUT or LYS_OUTPUT
*/
#define CHECK_LYSC_ACTION_INOUT(NODE, DATA, MUST, NODETYPE) \
assert_non_null(NODE); \
CHECK_POINTER((NODE)->child, DATA); \
CHECK_ARRAY((NODE)->musts, MUST); \
assert_int_equal((NODE)->nodetype, NODETYPE);
/**
* @brief assert that lysc_action structure members are correct
*
* @param[in] NODE pointer to lysp_action variable
* @param[in] DSC string description statement
* @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
* @param[in] FLAGS [schema node flags](@ref snodeflags)
* @param[in] INPUT_DATA 0 pointer is null, 1 pointer is not null
* @param[in] INPUT_MUST expected [sized array](@ref sizedarrays) size of input list of must restrictions
* @param[in] INPUT_EXTS expected [sized array](@ref sizedarrays) size of the input extension instances of input
* @param[in] MODULE 0 pointer is null, 1 pointer is not null
* @param[in] NAME expected name
* @param[in] NODETYPE LYS_RPC, LYS_ACTION
* @param[in] OUTPUT_DATA 0 pointer is null, 1 pointer is not null
* @param[in] OUTPUT_MUST expected [sized array](@ref sizedarrays) size of output list of must restrictions
* @param[in] OUTPUT_EXTS expected [sized array](@ref sizedarrays) size of the output extension instances of input
* @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
* @param[in] PRIV 0-> pointer is null, 1-> pointer is not null
* @param[in] REF expected reference
* @param[in] WHEN expected [sized array](@ref sizedarrays) size of list of pointers to when statements
*/
#define CHECK_LYSC_ACTION(NODE, DSC, EXTS, FLAGS, INPUT_DATA, INPUT_MUST, INPUT_EXTS, MODULE, NAME, NODETYPE, \
OUTPUT_DATA, OUTPUT_MUST, OUTPUT_EXTS, PARENT, PRIV, REF, WHEN) \
assert_non_null(NODE); \
CHECK_STRING((NODE)->dsc, DSC); \
CHECK_ARRAY((NODE)->exts, EXTS); \
assert_int_equal((NODE)->flags, FLAGS); \
CHECK_LYSC_ACTION_INOUT(&(NODE)->input, INPUT_DATA, INPUT_MUST, LYS_INPUT); \
CHECK_ARRAY((NODE)->input.exts, INPUT_EXTS); \
CHECK_POINTER((NODE)->module, MODULE); \
assert_string_equal((NODE)->name, NAME); \
assert_int_equal((NODE)->nodetype, NODETYPE); \
CHECK_LYSC_ACTION_INOUT(&(NODE)->output, OUTPUT_DATA, OUTPUT_MUST, LYS_OUTPUT); \
CHECK_ARRAY((NODE)->output.exts, OUTPUT_EXTS); \
CHECK_POINTER((NODE)->parent, PARENT); \
CHECK_POINTER((NODE)->priv, PRIV); \
CHECK_STRING((NODE)->ref, REF); \
CHECK_ARRAY(lysc_node_when((const struct lysc_node *)NODE), WHEN);
/**
* @brief assert that lysc_node structure members are correct
*
* @param[in] NODE pointer to lysc_node variable
* @param[in] DSC expected description
* @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
* @param[in] FLAGS [schema node flags](@ref snodeflags)
* @param[in] MODULE 0 pointer is null, 1 pointer is not null
* @param[in] NAME expected name
* @param[in] NEXT 0 pointer is null, 1 pointer is not null
* @param[in] NODETYPE type of the node LYS_UNKNOWN, LYS_CONTAINER, LYS_CHOICE, LYS_LEAF,
* LYS_LEAFLIST, LYS_LIST, LYS_ANYXML, LYS_ANYDATA, LYS_CASE, LYS_RPC,
* LYS_ACTION, LYS_NOTIF, LYS_USES, LYS_INPUT, LYS_OUTPUT, LYS_GROUPING,
* LYS_AUGMENT
* @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
* @param[in] PRIV 0-> pointer is null, 1-> pointer is not null
* @param[in] REF expected reference
* @param[in] WHEN expected [sized array](@ref sizedarrays) size of list of pointers to when statements
*/
#define CHECK_LYSC_NODE(NODE, DSC, EXTS, FLAGS, MODULE, NAME, NEXT, NODETYPE, PARENT, PRIV, REF, WHEN) \
assert_non_null(NODE); \
CHECK_STRING((NODE)->dsc, DSC); \
CHECK_ARRAY((NODE)->exts, EXTS); \
assert_int_equal((NODE)->flags, FLAGS); \
CHECK_POINTER((NODE)->module, MODULE); \
assert_string_equal((NODE)->name, NAME); \
CHECK_POINTER((NODE)->next, NEXT); \
assert_int_equal((NODE)->nodetype, NODETYPE); \
CHECK_POINTER((NODE)->parent, PARENT); \
assert_non_null((NODE)->prev); \
CHECK_POINTER((NODE)->priv, PRIV); \
CHECK_STRING((NODE)->ref, REF); \
CHECK_ARRAY(lysc_node_when((const struct lysc_node *)NODE), WHEN);
/**
* @brief assert that lysc_node_leaf structure members are correct
*
* @param[in] NODE pointer to lysc_node variable
* @param[in] DSC expected description
* @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
* @param[in] FLAGS [schema node flags](@ref snodeflags)
* @param[in] MODULE 0 pointer is null, 1 pointer is not null
* @param[in] NAME expected name
* @param[in] NEXT 0 pointer is null, 1 pointer is not null
* @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
* @param[in] PRIV 0-> pointer is null, 1-> pointer is not null
* @param[in] REF expected reference
* @param[in] ACTIONS 1 if is set pointer to structure lysc_node_action other 0
* @param[in] CHILD 1 if is set pointer to child other 0
* @param[in] MAX possible maximum elements in list
* @param[in] MIN possible minimum elements in list
* @param[in] MUSTS [sized array](@ref sizedarrays) number of must node elements in array
* @param[in] NOTIFS 1 if is set pointer to any notifs node
* @param[in] UNIQUES [sized array](@ref sizedarrays) number of unique nodes element in array
* @param[in] WHEN [sized array](@ref sizedarrays) size of when node array
*/
#define CHECK_LYSC_NODE_LIST(NODE, DSC, EXTS, FLAGS, MODULE, NAME, NEXT, \
PARENT, PRIV, REF, ACTIONS, CHILD, MAX, MIN, MUSTS, NOTIFS, UNIQUES, WHEN) \
CHECK_LYSC_NODE(NODE, DSC, EXTS, FLAGS, MODULE, NAME, NEXT, LYS_LIST, PARENT, PRIV, REF, WHEN); \
CHECK_POINTER((NODE)->actions, ACTIONS); \
CHECK_POINTER((NODE)->child, CHILD); \
assert_int_equal((NODE)->max, MAX); \
assert_int_equal((NODE)->min, MIN); \
CHECK_ARRAY((NODE)->musts, MUSTS); \
CHECK_POINTER((NODE)->notifs, NOTIFS); \
CHECK_ARRAY((NODE)->uniques, UNIQUES); \
CHECK_ARRAY(lysc_node_when((const struct lysc_node *)NODE), WHEN)
/**
* @brief assert that lysc_node_leaf structure members are correct
*
* @param[in] NODE pointer to lysc_node variable
* @param[in] DSC expected description
* @param[in] EXTS expected [sized array](@ref sizedarrays) size of list of the extension instances
* @param[in] FLAGS [schema node flags](@ref snodeflags)
* @param[in] MODULE 0 pointer is null, 1 pointer is not null
* @param[in] NAME expected name
* @param[in] NEXT 0 pointer is null, 1 pointer is not null
* @param[in] PARENT 0-> check if node is root, 1-> check if node is not root
* @param[in] PRIV 0-> pointer is null, 1-> pointer is not null
* @param[in] REF expected reference
* @param[in] WHEN expected [sized array](@ref sizedarrays) size of list of pointers to when statements
* @param[in] MUSTS expected [sized array](@ref sizedarrays) size of list of must restriction
* @param[in] UNITS expected string reprezenting units
* @param[in] DFLT 0-> node dosn't have default value. 1 -> node have default value
*/
#define CHECK_LYSC_NODE_LEAF(NODE, DSC, EXTS, FLAGS, MODULE, NAME, NEXT, \
PARENT, PRIV, REF, WHEN, MUSTS, UNITS, DFLT) \
CHECK_LYSC_NODE(NODE, DSC, EXTS, FLAGS, MODULE, NAME, NEXT, LYS_LEAF, PARENT, PRIV, REF, WHEN); \
CHECK_ARRAY((NODE)->musts, MUSTS); \
assert_non_null((NODE)->type); \
CHECK_STRING((NODE)->units, UNITS); \
CHECK_POINTER((NODE)->dflt, DFLT);
/**
* @brief assert that lyd_meta structure members are correct
*
* @param[in] NODE pointer to lyd_meta variable
* @param[in] ANNOTATION 0 pointer is null, 1 pointer is not null
* @param[in] NAME expected name
* @param[in] NEXT 0 pointer is null, 1 pointer is not null
* @param[in] TYPE_VAL value type. EMPTY, UNION, BITS, INST, ENUM, INT8, INT16, UINT8, STRING, LEAFREF, DEC64, BINARY, BOOL, IDENT
* part of text reprezenting LY_DATA_TYPE.
* @param[in] ... ::CHECK_LYD_VALUE
*/
#define CHECK_LYD_META(NODE, ANNOTATION, NAME, NEXT, PARENT, TYPE_VAL, ...) \
assert_non_null(NODE); \
CHECK_POINTER((NODE)->annotation, ANNOTATION); \
assert_string_equal((NODE)->name, NAME); \
CHECK_POINTER((NODE)->next, NEXT); \
CHECK_POINTER((NODE)->parent, PARENT); \
CHECK_LYD_VALUE((NODE)->value, TYPE_VAL, __VA_ARGS__);
/**
* @brief assert that lyd_node_term structure members are correct
*
* @param[in] NODE pointer to lyd_node_term variable
* @param[in] FLAGS expected [data node flags](@ref dnodeflags)
* @param[in] META 0 -> meta is not prezent, 1 -> meta is prezent
* @param[in] NEXT 0 -> next node is not prezent, 1 -> next node is prezent
* @param[in] TYPE_VAL value type. EMPTY, UNION, BITS, INST, ENUM, INT8, INT16, UINT8, STRING, LEAFREF, DEC64, BINARY, BOOL, IDENT
* part of text reprezenting LY_DATA_TYPE.
* @param[in] ... ::CHECK_LYD_VALUE
*/
#define CHECK_LYD_NODE_TERM(NODE, FLAGS, META, NEXT, PARENT, SCHEMA, VALUE_TYPE, ...) \
assert_non_null(NODE); \
assert_int_equal((NODE)->flags, FLAGS); \
CHECK_POINTER((NODE)->meta, META); \
CHECK_POINTER((NODE)->next, NEXT); \
CHECK_POINTER((NODE)->parent, PARENT); \
assert_non_null((NODE)->prev); \
CHECK_POINTER((NODE)->schema, SCHEMA); \
CHECK_LYD_VALUE((NODE)->value, VALUE_TYPE, __VA_ARGS__);
/**
* @brief assert that lyd_node_any structure members are correct
*
* @param[in] NODE pointer to lyd_node_term variable
* @param[in] FLAGS expected [data node flags](@ref dnodeflags)
* @param[in] META 0 meta isnt present , 1 meta is present
* @param[in] PARENT 0 it is root node , 1 node have parent
* @param[in] VALUE_TYPE value type ::lyd_node_any.value
*/
#define CHECK_LYD_NODE_ANY(NODE, FLAGS, META, PARENT, VALUE_TYPE) \
assert_non_null(NODE); \
assert_int_equal((NODE)->flags, FLAGS); \
CHECK_POINTER((NODE)->meta, META); \
CHECK_POINTER((NODE)->meta, PARENT); \
assert_non_null((NODE)->prev); \
assert_non_null((NODE)->schema); \
assert_int_equal((NODE)->value_type, VALUE_TYPE);
/**
* @brief assert that lyd_node_opaq structure members are correct
*
* @param[in] NODE pointer to lyd_node_opaq variable
* @param[in] ATTR 0 if pointer is null ,1 if pointer is not null
* @param[in] CHILD 0 if pointer is null ,1 if pointer is not null
* @param[in] FORMAT LY_PREF_XML or LY_PREF_JSON
* @param[in] VAL_PREFS 0 if pointer is null ,1 if pointer is not null
* @param[in] NAME expected name
* @param[in] value expected orignal value
*/
#define CHECK_LYD_NODE_OPAQ(NODE, ATTR, CHILD, FORMAT, NAME, NEXT, PARENT, PREFIX, VAL_PREFS, VALUE) \
assert_non_null(NODE); \
CHECK_POINTER((NODE)->attr, ATTR); \
CHECK_POINTER((NODE)->child, CHILD); \
assert_ptr_equal((NODE)->ctx, UTEST_LYCTX); \
assert_int_equal((NODE)->flags, 0); \
assert_true((NODE)->format == FORMAT); \
assert_int_equal((NODE)->hash, 0); \
assert_string_equal((NODE)->name.name, NAME); \
assert_non_null((NODE)->prev); \
assert_null((NODE)->schema); \
CHECK_POINTER((NODE)->val_prefix_data, VAL_PREFS); \
assert_string_equal((NODE)->value, VALUE);
/**
* @brief assert that lyd_node_opaq structure members are correct
*
* @param[in] NODE pointer to lyd_node_opaq variable
* @param[in] CHILD 1 if node has children other 0
* @param[in] HILD_HT 1 if node has children hash table other 0
* @param[in] META 1 if node has metadata other 0
* @param[in] FLAGS expected flag
* @param[in] NEXT 1 if next node is present other 0
* @param[in] PARENT 1 if node has parent other 0
* @param[in] PRIV 1 if node has private data other 0
* @param[in] SCHEMA 1 if node has schema other 0
*/
#define CHECK_LYD_NODE_INNER(NODE, CHILD, CHILD_HT, META, FLAGS, NEXT, PARENT, PRIV, SCHEMA) \
assert_non_null(NODE); \
CHECK_POINTER((NODE)->child, CHILD); \
CHECK_POINTER((NODE)->children_ht, CHILD_HT); \
CHECK_POINTER((NODE)->meta, META); \
assert_int_equal((NODE)->flags, FLAGS); \
CHECK_POINTER((NODE)->parent, PARENT); \
assert_non_null((NODE)->prev); \
CHECK_POINTER((NODE)->next, NEXT); \
CHECK_POINTER((NODE)->priv, PRIV); \
CHECK_POINTER((NODE)->schema, SCHEMA)
/**
* @brief assert that lyd_value structure members are correct
*
* @param[in] NODE lyd_value
* @param[in] TYPE_VAL value type. EMPTY, UNION, BITS, INST, ENUM, INT8, INT16, UINT8, STRING, LEAFREF, DEC64, BINARY, BOOL, IDENT
* part of text reprezenting LY_DATA_TYPE.
* @param[in] ... Unspecified parameters. Type and numbers of parameters are specified
* by type of value. These parameters are passed to macro
* CHECK_LYD_VALUE_ ## TYPE_VAL.
*/
#define CHECK_LYD_VALUE(NODE, TYPE_VAL, ...) \
CHECK_LYD_VALUE_ ## TYPE_VAL (NODE, __VA_ARGS__);
/*
* LYD VALUES CHECKING SPECIALIZATION
*/
/**
* @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type EMPTY
* Example CHECK_LYD_VALUE(node->value, EMPTY, "");
*
* @param[in] NODE lyd_value variable
* @param[in] CANNONICAL_VAL expected cannonical value
*/
#define CHECK_LYD_VALUE_EMPTY(NODE, CANNONICAL_VAL) \
assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
assert_non_null((NODE).realtype); \
assert_int_equal((NODE).realtype->basetype, LY_TYPE_EMPTY);
/**
* @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type UNION
* Example CHECK_LYD_VALUE(node->value, UNION, "12", INT8, "12", 12);
* @warning type of subvalue cannot be UNION. Example of calling
*
* @param[in] NODE lyd_value variable
* @param[in] CANNONICAL_VAL expected cannonical value
* @param[in] TYPE_VAL value type. EMPTY, UNION, BITS, INST, ENUM, INT8, INT16, UINT8, STRING, LEAFREF, DEC64, BINARY, BOOL, IDENT
* @param[in] ... Unspecified parameters. Type and numbers of parameters are specified
* by type of value. These parameters are passed to macro
* CHECK_LYD_VALUE_ ## TYPE_VAL.
*/
#define CHECK_LYD_VALUE_UNION(NODE, CANNONICAL_VAL, TYPE_VAL, ...) \
assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
assert_non_null((NODE).realtype); \
assert_int_equal(LY_TYPE_UNION, (NODE).realtype->basetype); \
assert_non_null((NODE).subvalue); \
assert_non_null((NODE).subvalue->prefix_data); \
CHECK_LYD_VALUE_ ## TYPE_VAL ((NODE).subvalue->value, __VA_ARGS__)
/**
* @brief Internal macro. Get 1st variadic argument.
*/
#define _GETARG1(ARG1, ...) ARG1
/**
* @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type BITS
* Example arr[] = {"a", "b"}; CHECK_LYD_VALUE(node->value, BITS, "a b", arr);
*
* @param[in] NODE lyd_value variable
* @param[in] CANNONICAL_VAL expected cannonical value
* @param[in] VALUE expected array of bits names
*/
#define CHECK_LYD_VALUE_BITS(NODE, ...) \
assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
assert_string_equal((NODE)._canonical, _GETARG1(__VA_ARGS__, DUMMY)); \
assert_non_null((NODE).realtype); \
assert_int_equal(LY_TYPE_BITS, (NODE).realtype->basetype); \
{ \
const char *arr[] = { __VA_ARGS__ }; \
LY_ARRAY_COUNT_TYPE arr_size = (sizeof(arr) / sizeof(arr[0])) - 1; \
struct lyd_value_bits *_val; \
LYD_VALUE_GET(&(NODE), _val); \
assert_int_equal(arr_size, LY_ARRAY_COUNT(_val->items)); \
for (LY_ARRAY_COUNT_TYPE it = 0; it < arr_size; it++) { \
assert_string_equal(arr[it + 1], _val->items[it]->name); \
} \
}
/**
* @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type INST
*
* @param[in] NODE lyd_value variable
* @param[in] CANNONICAL_VAL expected cannonical value
* @param[in] VALUE expected array of enum ly_path_pred_type
* @brief Example enum arr[] = {0x0, 0x1}; CHECK_LYD_VALUE(node->value, INST, "test/d", arr);
*/
#define CHECK_LYD_VALUE_INST(NODE, CANNONICAL_VAL, VALUE) \
assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
assert_non_null((NODE).realtype); \
assert_int_equal(LY_TYPE_INST, (NODE).realtype->basetype); \
{ \
LY_ARRAY_COUNT_TYPE arr_size = sizeof(VALUE) / sizeof(VALUE[0]); \
assert_int_equal(arr_size, LY_ARRAY_COUNT((NODE).target)); \
for (LY_ARRAY_COUNT_TYPE it = 0; it < arr_size; it++) { \
assert_int_equal(VALUE[it], (NODE).target[it].pred_type); \
} \
}
/**
* @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type ENUM.
* Example CHECK_LYD_VALUE(node->value, ENUM, "item_name", "item_name");
*
* @param[in] NODE lyd_value variable
* @param[in] CANNONICAL_VAL expected cannonical value
* @param[in] VALUE expected enum item name
*/
#define CHECK_LYD_VALUE_ENUM(NODE, CANNONICAL_VAL, VALUE) \
assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
assert_non_null((NODE).realtype); \
assert_int_equal(LY_TYPE_ENUM, (NODE).realtype->basetype); \
assert_string_equal(VALUE, (NODE).enum_item->name);
/**
* @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type INT8
* Example CHECK_LYD_VALUE(node->value, INT8, "12", 12);
*
* @param[in] NODE lyd_value variable
* @param[in] CANNONICAL_VAL expected cannonical value
* @param[in] VALUE expected inteager value (-128 to 127).
*/
#define CHECK_LYD_VALUE_INT8(NODE, CANNONICAL_VAL, VALUE) \
assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
assert_non_null((NODE).realtype); \
assert_int_equal(LY_TYPE_INT8, (NODE).realtype->basetype); \
assert_int_equal(VALUE, (NODE).int8);
/**
* @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type INT16
* Example CHECK_LYD_VALUE(node->value, INT8, "12", 12);
*
* @param[in] NODE lyd_value variable
* @param[in] CANNONICAL_VAL expected cannonical value
* @param[in] VALUE expected inteager value.
*/
#define CHECK_LYD_VALUE_INT16(NODE, CANNONICAL_VAL, VALUE) \
assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
assert_non_null((NODE).realtype); \
assert_int_equal(LY_TYPE_INT16, (NODE).realtype->basetype); \
assert_int_equal(VALUE, (NODE).int16);
/**
* @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type UINT8.
* Example CHECK_LYD_VALUE(node->value, UINT8, "12", 12);
*
* @param[in] NODE lyd_value variable
* @param[in] CANNONICAL_VAL expected cannonical value
* @param[in] VALUE expected inteager (0 to 255).
*/
#define CHECK_LYD_VALUE_UINT8(NODE, CANNONICAL_VAL, VALUE) \
assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
assert_non_null((NODE).realtype); \
assert_int_equal(LY_TYPE_UINT8, (NODE).realtype->basetype); \
assert_int_equal(VALUE, (NODE).uint8);
/**
* @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type UINT32.
* Example CHECK_LYD_VALUE(node->value, UINT32, "12", 12);
*
* @param[in] NODE lyd_value variable
* @param[in] CANNONICAL_VAL expected cannonical value
* @param[in] VALUE expected inteager (0 to MAX_UINT32).
*/
#define CHECK_LYD_VALUE_UINT32(NODE, CANNONICAL_VAL, VALUE) \
assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
assert_non_null((NODE).realtype); \
assert_int_equal(LY_TYPE_UINT32, (NODE).realtype->basetype); \
assert_int_equal(VALUE, (NODE).uint32);
/**
* @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type STRING.
* Example CHECK_LYD_VALUE(node->value, STRING, "text");
*
* @param[in] NODE lyd_value variable
* @param[in] CANNONICAL_VAL expected cannonical value
*/
#define CHECK_LYD_VALUE_STRING(NODE, CANNONICAL_VAL) \
assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
assert_non_null((NODE).realtype); \
assert_int_equal(LY_TYPE_STRING, (NODE).realtype->basetype);
/**
* @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type LEAFREF
* Example CHECK_LYD_VALUE(node->value, LEAFREF, "");
*
* @param[in] NODE lyd_value variable
* @param[in] CANNONICAL_VAL expected cannonical value
*/
#define CHECK_LYD_VALUE_LEAFREF(NODE, CANNONICAL_VAL) \
assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
assert_non_null((NODE).realtype); \
assert_int_equal(LY_TYPE_LEAFREF, (NODE).realtype->basetype); \
assert_non_null((NODE).ptr)
/**
* @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type DEC64
* Example CHECK_LYD_VALUE(node->value, DEC64, "125", 125);
*
* @param[in] NODE lyd_value variable
* @param[in] CANNONICAL_VAL expected cannonical value
* @param[in] VALUE expected value 64bit inteager
*/
#define CHECK_LYD_VALUE_DEC64(NODE, CANNONICAL_VAL, VALUE) \
assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
assert_non_null((NODE).realtype); \
assert_int_equal(LY_TYPE_DEC64, (NODE).realtype->basetype); \
assert_int_equal(VALUE, (NODE).dec64);
/**
* @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type BINARY.
* Example CHECK_LYD_VALUE(node->value, BINARY, "aGVs\nbG8=");
*
* @param[in] NODE lyd_value variable
* @param[in] CANNONICAL_VAL expected cannonical value
* @param[in] VALUE expected value data
* @param[in] SIZE expected value data size
*/
#define CHECK_LYD_VALUE_BINARY(NODE, CANNONICAL_VAL, VALUE, SIZE) \
{ \
struct lyd_value_binary *_val; \
LYD_VALUE_GET(&(NODE), _val); \
assert_int_equal(_val->size, SIZE); \
assert_int_equal(0, memcmp(_val->data, VALUE, SIZE)); \
assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
assert_non_null((NODE).realtype); \
assert_int_equal(LY_TYPE_BINARY, (NODE).realtype->basetype); \
}
/**
* @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type BOOL.
* Example CHECK_LYD_VALUE(node->value, BOOL, "true", 1);
*
* @param[in] NODE lyd_value variable
* @param[in] CANNONICAL_VAL expected cannonical value
* @param[in] VALUE expected boolean value 0,1
*/
#define CHECK_LYD_VALUE_BOOL(NODE, CANNONICAL_VAL, VALUE) \
assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
assert_non_null((NODE).realtype); \
assert_int_equal(LY_TYPE_BOOL, (NODE).realtype->basetype); \
assert_int_equal(VALUE, (NODE).boolean);
/**
* @brief Internal macro. Assert that lyd_value structure members are correct. Lyd value is type IDENT.
* Example CHECK_LYD_VALUE(node->value, IDENT, "types:gigabit-ethernet", "gigabit-ethernet");
*
* @param[in] NODE lyd_value variable
* @param[in] CANNONICAL_VAL expected cannonical value
* @param[in] VALUE expected ident name
*/
#define CHECK_LYD_VALUE_IDENT(NODE, CANNONICAL_VAL, VALUE) \
assert_non_null((NODE).realtype->plugin->print(UTEST_LYCTX, &(NODE), LY_VALUE_CANON, NULL, NULL, NULL)); \
assert_string_equal((NODE)._canonical, CANNONICAL_VAL); \
assert_non_null((NODE).realtype); \
assert_int_equal(LY_TYPE_IDENT, (NODE).realtype->basetype); \
assert_string_equal(VALUE, (NODE).ident->name);
/**
* @brief Macro testing parser when parsing incorrect module;
*
* @param[in] DATA String storing the schema module representation.
* @param[in] FORMAT Schema format of the @p DATA
* @param[in] FEATURES Array of module's features to enable
* @param[in] RET_VAL ly_in_new_memory return error value
*/
#define UTEST_INVALID_MODULE(DATA, FORMAT, FEATURES, RET_VAL) \
{ \
struct lys_module *mod; \
assert_int_equal(LY_SUCCESS, ly_in_new_memory(DATA, &_UC->in)); \
assert_int_equal(RET_VAL, lys_parse(_UC->ctx, _UC->in, FORMAT, FEATURES, &mod)); \
assert_null(mod); \
} \
ly_in_free(_UC->in, 0); \
_UC->in = NULL; \
/**
* @brief Add module (from a string) into the used libyang context.
*
* @param[in] DATA String storing the schema module representation.
* @param[in] FORMAT Schema format of the @p DATA
* @param[in] FEATURES Array of module's features to enable
* @param[out] MOD Optional parameter as a pointer to variable to store the resulting module.
*/
#define UTEST_ADD_MODULE(DATA, FORMAT, FEATURES, MOD) \
assert_int_equal(LY_SUCCESS, ly_in_new_memory(DATA, &_UC->in)); \
{ \
LY_ERR __r = lys_parse(_UC->ctx, _UC->in, FORMAT, FEATURES, MOD); \
if (__r != LY_SUCCESS) { \
print_message("[ MSG ] Module parsing failed:\n"); \
for (struct ly_err_item *e = ly_err_first(_UC->ctx); e; e = e->next) { \
print_message("[ MSG ] \t%s Path %s\n", e->msg, e->path); \
} \
fail(); \
} \
} \
ly_in_free(_UC->in, 0); \
_UC->in = NULL
/**
* @brief Internal macro to compare error info record with the expected error message and path.
* If NULL is provided as MSG, no error info record (NULL) is expected.
*
* @param[in] ERR Error information record from libyang context.
* @param[in] MSG Expected error message.
* @param[in] PATH Expected error path.
*/
#define _CHECK_LOG_CTX(ERR, MSG, PATH) \
if (!MSG) { \
assert_null(ERR); \
} else { \
assert_non_null(ERR); \
CHECK_STRING((ERR)->msg, MSG); \
CHECK_STRING((ERR)->path, PATH); \
}
/**`
* @brief Internal macro to check the last libyang's context error.
*/
#define _CHECK_LOG_CTX1(MSG, PATH) \
_CHECK_LOG_CTX(ly_err_last(_UC->ctx), MSG, PATH)
/**
* @brief Internal macro to check the last two libyang's context error.
*/
#define _CHECK_LOG_CTX2(MSG1, PATH1, MSG2, PATH2) \
_CHECK_LOG_CTX(ly_err_last(_UC->ctx), MSG1, PATH1); \
_CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev, MSG2, PATH2)
/**
* @brief Internal macro to check the last three libyang's context error.
*/
#define _CHECK_LOG_CTX3(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3) \
_CHECK_LOG_CTX2(MSG1, PATH1, MSG2, PATH2); \
_CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev, MSG3, PATH3)
/**
* @brief Internal macro to check the last three libyang's context error.
*/
#define _CHECK_LOG_CTX4(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4) \
_CHECK_LOG_CTX3(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3); \
_CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev->prev, MSG4, PATH4)
/**
* @brief Internal macro to check the last three libyang's context error.
*/
#define _CHECK_LOG_CTX5(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5) \
_CHECK_LOG_CTX4(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4); \
_CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev->prev->prev, MSG5, PATH5)
/**
* @brief Internal macro to check the last three libyang's context error.
*/
#define _CHECK_LOG_CTX6(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5, MSG6, PATH6) \
_CHECK_LOG_CTX5(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5); \
_CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev->prev->prev->prev, MSG6, PATH6)
/**
* @brief Internal macro to check the last three libyang's context error.
*/
#define _CHECK_LOG_CTX7(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5, MSG6, PATH6, MSG7, PATH7) \
_CHECK_LOG_CTX6(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5, MSG6, PATH6); \
_CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev->prev->prev->prev->prev, MSG7, PATH7)
/**
* @brief Internal macro to check the last three libyang's context error.
*/
#define _CHECK_LOG_CTX8(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5, MSG6, PATH6, MSG7, PATH7, MSG8, PATH8) \
_CHECK_LOG_CTX7(MSG1, PATH1, MSG2, PATH2, MSG3, PATH3, MSG4, PATH4, MSG5, PATH5, MSG6, PATH6, MSG7, PATH7); \
_CHECK_LOG_CTX(ly_err_last(_UC->ctx)->prev->prev->prev->prev->prev->prev->prev, MSG8, PATH8)
/**
* @brief Internal helper macro to select _CHECK_LOG_CTX* macro according to the provided parameters.
*/
#define _GET_CHECK_LOG_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, NAME, ...) NAME
/**
* @brief Check expected error(s) in libyang context.
*
* Macro has variadic parameters expected to be provided in pairs of error message and error path starting
* from the latest error. Current limit is checking at most 3 last errors. After checking, macro cleans up
* all the errors from the libyang context.
*
* @param[in] MSG Expected error message.
* @param[in] PATH Expected error path.
*/
#define CHECK_LOG_CTX(...) \
_GET_CHECK_LOG_MACRO(__VA_ARGS__, _CHECK_LOG_CTX8, _INVAL, _CHECK_LOG_CTX7, _INVAL, \
_CHECK_LOG_CTX6, _INVAL, _CHECK_LOG_CTX5, _INVAL, _CHECK_LOG_CTX4, _INVAL, \
_CHECK_LOG_CTX3, _INVAL, _CHECK_LOG_CTX2, _INVAL, _CHECK_LOG_CTX1, DUMMY)(__VA_ARGS__); \
ly_err_clean(_UC->ctx, NULL)
/**
* @brief Check expected error in libyang context including error-app-tag.
*
* @param[in] MSG Expected error message.
* @param[in] PATH Expected error path.
* @param[in] APPTAG Expected error-app-tag.
*/
#define CHECK_LOG_CTX_APPTAG(MSG, PATH, APPTAG) \
if (!MSG) { \
assert_null(ly_err_last(_UC->ctx)); \
} else { \
assert_non_null(ly_err_last(_UC->ctx)); \
CHECK_STRING(ly_err_last(_UC->ctx)->msg, MSG); \
CHECK_STRING(ly_err_last(_UC->ctx)->path, PATH); \
CHECK_STRING(ly_err_last(_UC->ctx)->apptag, APPTAG); \
} \
ly_err_clean(_UC->ctx, NULL)
/**
* @brief Clean up the logging callback's storage.
*/
#define UTEST_LOG_CLEAN \
free(_UC->err_msg); \
free(_UC->err_path); \
_UC->err_msg = NULL; \
_UC->err_path = NULL;
/**
* @brief Check expected error directly logged via logging callback.
* Useful mainly for messages logged by functions without access to libyang context.
* @param[in] MSG Expected error message.
* @param[in] PATH Expected error path.
*/
#define CHECK_LOG(MSG, PATH) \
CHECK_STRING(_UC->err_msg, MSG); \
CHECK_STRING(_UC->err_path, PATH); \
UTEST_LOG_CLEAN
#ifdef _UTEST_MAIN_
/*
* Functions inlined into each C source file including this header with _UTEST_MAIN_ defined
*/
/**
* @brief Global variable holding the tests context to simplify access to it.
*/
struct utest_context *current_utest_context;
/* set to 0 to printing error messages to stderr instead of checking them in code */
#define ENABLE_LOGGER_CHECKING 1
/**
* @brief Logging callback for libyang.
*/
static void
_utest_logger(LY_LOG_LEVEL level, const char *msg, const char *path)
{
(void) level; /* unused */
if (ENABLE_LOGGER_CHECKING == 0) {
printf("\tERROR:\n\t\tMESSAGE: %s\n\t\tPATH: %s\n\t\tLEVEL: %i\n", msg, path, level);
} else {
free(current_utest_context->err_msg);
current_utest_context->err_msg = msg ? strdup(msg) : NULL;
free(current_utest_context->err_path);
current_utest_context->err_path = path ? strdup(path) : NULL;
}
}
/**
* @brief Generic utest's setup
*/
static int
utest_setup(void **state)
{
char *cur_tz;
/* setup the logger */
ly_set_log_clb(_utest_logger, 1);
ly_log_options(LY_LOLOG | LY_LOSTORE);
current_utest_context = calloc(1, sizeof *current_utest_context);
assert_non_null(current_utest_context);
*state = current_utest_context;
/* libyang context */
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0, ¤t_utest_context->ctx));
/* clean all errors from the setup - usually warnings regarding the plugins directories */
UTEST_LOG_CLEAN;
/* backup timezone, if any */
cur_tz = getenv("TZ");
if (cur_tz) {
current_utest_context->orig_tz = strdup(cur_tz);
}
/* set CET */
setenv("TZ", "CET+02:00", 1);
return 0;
}
/**
* @brief macro to include generic utest's setup into the test-specific setup.
*
* Place at the beginning of the test-specific setup
*/
#define UTEST_SETUP \
assert_int_equal(0, utest_setup(state))
/**
* @brief Generic utest's teardown
*/
static int
utest_teardown(void **state)
{
*state = NULL;
/* libyang context */
ly_ctx_destroy(current_utest_context->ctx);
if (current_utest_context->orig_tz) {
/* restore TZ */
setenv("TZ", current_utest_context->orig_tz, 1);
}
/* utest context */
ly_in_free(current_utest_context->in, 0);
free(current_utest_context->err_msg);
free(current_utest_context->err_path);
free(current_utest_context->orig_tz);
free(current_utest_context);
current_utest_context = NULL;
return 0;
}
/**
* @brief macro to include generic utest's teardown into the test-specific teardown.
*
* Place at the end of the test-specific teardown
*/
#define UTEST_TEARDOWN \
assert_int_equal(0, utest_teardown(state))
/**
* @brief Internal macro for utest setup with test-specific setup and teardown
*/
#define _UTEST_SETUP_TEARDOWN(FUNC, SETUP, TEARDOWN) \
cmocka_unit_test_setup_teardown(FUNC, SETUP, TEARDOWN)
/**
* @brief Internal macro for utest setup with test-specific setup and generic teardown
*/
#define _UTEST_SETUP(FUNC, SETUP) \
cmocka_unit_test_setup_teardown(FUNC, SETUP, utest_teardown)
/**
* @brief Internal macro for utest setup with generic setup and teardown
*/
#define _UTEST(FUNC) \
cmocka_unit_test_setup_teardown(FUNC, utest_setup, utest_teardown)
/**
* @brief Internal helper macro to select _UTEST* macro according to the provided parameters.
*/
#define _GET_UTEST_MACRO(_1, _2, _3, NAME, ...) NAME
/**
* @brief Macro to specify test function using utest environment. Macro has variadic parameters
* to provide test-specific setup/teardown functions:
*
* UTEST(test_func) - only implicit setup and teardown functions are used
* UTEST(test_func, setup) - implicit teardown but own setup
* UTEST(test_func, setup, teardown) - both setup and teardown are test-specific
*/
#define UTEST(...) \
_GET_UTEST_MACRO(__VA_ARGS__, _UTEST_SETUP_TEARDOWN, _UTEST_SETUP, _UTEST, DUMMY)(__VA_ARGS__)
#else /* _UTEST_MAIN_ */
extern struct utest_context *current_utest_context;
#endif /* _UTEST_MAIN_ */
#endif /* _UTESTS_H_ */
|