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 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063
|
/**
* @file test_tree_schema_compile.c
* @author Radek Krejci <rkrejci@cesnet.cz>
* @author Michal Vasko <mvasko@cesnet.cz>
* @brief unit tests for functions from parser_yang.c
*
* Copyright (c) 2018 - 2023 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
*/
#define _UTEST_MAIN_
#include "utests.h"
#include "in.h"
#include "ly_common.h"
#include "parser_internal.h"
#include "path.h"
#include "plugins_types.h"
#include "schema_compile.h"
#include "xpath.h"
static int
setup(void **state)
{
UTEST_SETUP;
assert_int_equal(LY_SUCCESS, ly_ctx_set_options(UTEST_LYCTX, LY_CTX_DISABLE_SEARCHDIRS));
return 0;
}
static void
test_imp_free_data(void *model_data, void *UNUSED(user_data))
{
free(model_data);
}
static LY_ERR
test_imp_clb(const char *mod_name, const char *UNUSED(mod_rev), const char *UNUSED(submod_name),
const char *UNUSED(sub_rev), void *user_data, LYS_INFORMAT *format,
const char **module_data, void (**free_module_data)(void *model_data, void *user_data))
{
char *nl;
if ((nl = strchr(user_data, '\n'))) {
/* more modules */
if (!strncmp((char *)user_data + 7, mod_name, strlen(mod_name))) {
*module_data = strndup(user_data, nl - (char *)user_data);
*format = LYS_IN_YANG;
*free_module_data = test_imp_free_data;
} else {
*module_data = strdup(nl + 1);
*format = LYS_IN_YANG;
*free_module_data = test_imp_free_data;
}
} else {
*module_data = user_data;
*format = LYS_IN_YANG;
*free_module_data = NULL;
}
return LY_SUCCESS;
}
static void
test_module(void **state)
{
const char *str, *feats[] = {"invalid", NULL};
struct ly_in *in;
struct lys_module *mod = NULL;
struct lysp_feature *f;
struct lysc_iffeature *iff;
struct lys_glob_unres unres = {0};
str = "module test {namespace urn:test; prefix t;"
"feature f1;feature f2 {if-feature f1;}}";
assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
assert_int_equal(LY_SUCCESS, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, &unres.creating, &mod));
lys_unres_glob_erase(&unres);
ly_in_free(in, 0);
assert_int_equal(0, mod->implemented);
assert_int_equal(LY_EINVAL, lys_set_implemented(mod, feats));
CHECK_LOG_CTX("Feature \"invalid\" not found in module \"test\".", NULL, 0);
assert_int_equal(LY_SUCCESS, lys_set_implemented(mod, NULL));
assert_non_null(mod->compiled);
assert_string_equal("test", mod->name);
assert_string_equal("urn:test", mod->ns);
assert_string_equal("t", mod->prefix);
/* features */
assert_non_null(mod->parsed->features);
assert_int_equal(2, LY_ARRAY_COUNT(mod->parsed->features));
f = &mod->parsed->features[1];
assert_non_null(f->iffeatures);
assert_int_equal(1, LY_ARRAY_COUNT(f->iffeatures));
iff = &f->iffeatures_c[0];
assert_non_null(iff->expr);
assert_non_null(iff->features);
assert_int_equal(1, LY_ARRAY_COUNT(iff->features));
assert_ptr_equal(&mod->parsed->features[0], iff->features[0]);
/* submodules cannot be compiled directly */
str = "submodule test {belongs-to xxx {prefix x;}}";
assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
assert_int_equal(LY_EINVAL, lys_parse_in(UTEST_LYCTX, in, LYS_IN_YANG, NULL, &unres.creating, NULL));
lys_unres_glob_erase(&unres);
ly_in_free(in, 0);
CHECK_LOG_CTX("Input data contains submodule which cannot be parsed directly without its main module.", NULL, 0);
/* data definition name collision in top level */
str = "module aa {namespace urn:aa;prefix aa; leaf a {type string;} container a{presence x;}}";
assert_int_equal(LY_SUCCESS, ly_in_new_memory(str, &in));
assert_int_equal(LY_EEXIST, lys_parse(UTEST_LYCTX, in, LYS_IN_YANG, NULL, &mod));
ly_in_free(in, 0);
CHECK_LOG_CTX("Duplicate identifier \"/aa:a\" of data definition/RPC/action/notification statement.", "/aa:a", 0);
}
static void
test_submodule(void **state)
{
char *str;
/* extension in a submodule */
str = "submodule a-submod {yang-version 1.1; belongs-to a-mod {prefix a;}"
" extension ext2 {argument arg;}"
" typedef INTERFACE_NAME {type string; a:ext2 \"interface\";}"
"}";
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, str);
str = "module a-mod {namespace urn:a-mod; prefix a; include a-submod;"
"identity baseid;"
"}";
UTEST_ADD_MODULE(str, LYS_IN_YANG, NULL, NULL);
}
static void
test_name_collisions(void **state)
{
const char *yang_data;
/* top-level */
yang_data = "module a {namespace urn:a;prefix a;"
" container c;"
" leaf a {type empty;}"
" leaf c {type empty;}"
"}";
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, yang_data, LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Duplicate identifier \"/a:c\" of data definition/RPC/action/notification statement.", "/a:c", 0);
yang_data = "module a {namespace urn:a;prefix a;"
" container c;"
" leaf a {type empty;}"
" notification c;"
"}";
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, yang_data, LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Duplicate identifier \"/a:c\" of data definition/RPC/action/notification statement.", "/a:c", 0);
yang_data = "module a {namespace urn:a;prefix a;"
" container c;"
" leaf a {type empty;}"
" rpc c;"
"}";
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, yang_data, LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Duplicate identifier \"/a:c\" of data definition/RPC/action/notification statement.", "/a:c", 0);
yang_data = "module a {namespace urn:a;prefix a;"
" container c;"
" leaf a {type empty;}"
" choice ch {"
" leaf c {type string;}"
" case c2 {"
" leaf aa {type empty;}"
" }"
" }"
"}";
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, yang_data, LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Duplicate identifier \"/a:c\" of data definition/RPC/action/notification statement.", "/a:ch/c/c", 0);
/* nested */
yang_data = "module a {namespace urn:a;prefix a;container c { list l {key \"k\"; leaf k {type string;}"
"leaf-list a {type string;}"
"container a;"
"}}}";
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, yang_data, LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Duplicate identifier \"/a:c/l/a\" of data definition/RPC/action/notification statement.", "/a:c/l/a", 0);
yang_data = "module a {yang-version 1.1;namespace urn:a;prefix a;container c { list l {key \"k\"; leaf k {type string;}"
"leaf-list a {type string;}"
"notification a;"
"}}}";
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, yang_data, LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Duplicate identifier \"/a:c/l/a\" of data definition/RPC/action/notification statement.", "/a:c/l/a", 0);
yang_data = "module a {yang-version 1.1;namespace urn:a;prefix a;container c { list l {key \"k\"; leaf k {type string;}"
"leaf-list a {type string;}"
"action a;"
"}}}";
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, yang_data, LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Duplicate identifier \"/a:c/l/a\" of data definition/RPC/action/notification statement.", "/a:c/l/a", 0);
/* grouping */
}
static void
test_node_container(void **state)
{
struct lys_module *mod;
struct lysc_node_container *cont;
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;container c;}", LYS_IN_YANG, &mod));
assert_non_null(mod->compiled);
assert_non_null((cont = (struct lysc_node_container *)mod->compiled->data));
assert_int_equal(LYS_CONTAINER, cont->nodetype);
assert_string_equal("c", cont->name);
assert_true(cont->flags & LYS_CONFIG_W);
assert_true(cont->flags & LYS_STATUS_CURR);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;container c {config false; status deprecated; container child;}}", LYS_IN_YANG, &mod));
assert_non_null(mod->compiled);
assert_non_null((cont = (struct lysc_node_container *)mod->compiled->data));
assert_true(cont->flags & LYS_CONFIG_R);
assert_true(cont->flags & LYS_STATUS_DEPRC);
assert_non_null((cont = (struct lysc_node_container *)cont->child));
assert_int_equal(LYS_CONTAINER, cont->nodetype);
assert_true(cont->flags & LYS_CONFIG_R);
assert_true(cont->flags & LYS_STATUS_DEPRC);
assert_string_equal("child", cont->name);
}
static void
test_node_leaflist(void **state)
{
struct lys_module *mod;
struct lysc_type *type;
struct lysc_node_leaflist *ll;
struct lysc_node_leaf *l;
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;"
"typedef mytype {type union {type leafref {path ../target;} type string;}}"
"leaf-list ll1 {type union {type decimal64 {fraction-digits 2;} type mytype;}}"
"leaf-list ll2 {type leafref {path ../target;}}"
"leaf target {type int8;}}",
LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
assert_int_equal(LY_TYPE_UNION, type->basetype);
assert_non_null(((struct lysc_type_union *)type)->types);
assert_int_equal(3, LY_ARRAY_COUNT(((struct lysc_type_union *)type)->types));
assert_int_equal(LY_TYPE_DEC64, ((struct lysc_type_union *)type)->types[0]->basetype);
assert_int_equal(LY_TYPE_LEAFREF, ((struct lysc_type_union *)type)->types[1]->basetype);
assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_union *)type)->types[2]->basetype);
assert_non_null(((struct lysc_type_leafref *)((struct lysc_type_union *)type)->types[1])->realtype);
assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_leafref *)((struct lysc_type_union *)type)->types[1])->realtype->basetype);
type = ((struct lysc_node_leaf *)mod->compiled->data->next)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
assert_non_null(((struct lysc_type_leafref *)type)->realtype);
assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_leafref *)type)->realtype->basetype);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {yang-version 1.1;namespace urn:c;prefix c;typedef mytype {type int8;default 10;}"
"leaf-list ll1 {type mytype;default 1; default 1; config false;}"
"leaf-list ll2 {type mytype; ordered-by user;}}", LYS_IN_YANG, &mod));
assert_non_null(mod->compiled);
assert_non_null((ll = (struct lysc_node_leaflist *)mod->compiled->data));
assert_non_null(ll->dflts);
assert_int_equal(2, LY_ARRAY_COUNT(ll->dflts));
assert_string_equal("1", ll->dflts[0].str);
assert_string_equal("1", ll->dflts[1].str);
assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_USER | LYS_SET_DFLT | LYS_SET_CONFIG, ll->flags);
assert_non_null((ll = (struct lysc_node_leaflist *)mod->compiled->data->next));
assert_non_null(ll->dflts);
assert_int_equal(1, LY_ARRAY_COUNT(ll->dflts));
assert_string_equal("10", ll->dflts[0].str);
assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_USER, ll->flags);
/* ordered-by is ignored (with verbose message) for state data, RPC/action output parameters and notification content */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {yang-version 1.1;namespace urn:d;prefix d;"
"leaf-list ll {config false; type string; ordered-by user;}}", LYS_IN_YANG, &mod));
assert_non_null(mod->compiled);
assert_non_null((ll = (struct lysc_node_leaflist *)mod->compiled->data));
assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_USER | LYS_SET_CONFIG, ll->flags);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {yang-version 1.1;namespace urn:e;prefix e;"
"rpc oper {output {leaf-list ll {type string; ordered-by user;}}}}", LYS_IN_YANG, &mod));
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {yang-version 1.1;namespace urn:f;prefix f;"
"notification event {leaf-list ll {type string; ordered-by user;}}}", LYS_IN_YANG, &mod));
/* forward reference in default */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module g {yang-version 1.1; namespace urn:g;prefix g;"
"leaf ref {type instance-identifier {require-instance true;} default \"/g:g[.='val']\";}"
"leaf-list g {type string;}}", LYS_IN_YANG, &mod));
assert_non_null(l = (struct lysc_node_leaf *)mod->compiled->data);
assert_string_equal("ref", l->name);
assert_non_null(l->dflt.str);
/* invalid */
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;leaf-list ll {type empty;}}",
LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Leaf-list of type \"empty\" is allowed only in YANG 1.1 modules.", "/aa:ll", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {yang-version 1.1;namespace urn:bb;prefix bb;leaf-list ll {type empty; default x;}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid default - value does not fit the type (Invalid empty value size 8 b.).", "/bb:ll", 0);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;"
"leaf-list ll {config false;type string; default one;default two;default one;}}", LYS_IN_YANG, &mod));
assert_non_null(mod->compiled);
assert_non_null((ll = (struct lysc_node_leaflist *)mod->compiled->data));
assert_non_null(ll->dflts);
assert_int_equal(3, LY_ARRAY_COUNT(ll->dflts));
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;"
"leaf-list ll {type string; default one;default two;default one;}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Configuration leaf-list has multiple defaults of the same value \"one\".", "/dd:ll", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;"
"leaf ref {type instance-identifier {require-instance true;} default \"/ee:g\";}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid default - value does not fit the type "
"(Invalid instance-identifier \"/ee:g\" value - semantic error: Not found node \"g\" in path.).", "/ee:ref", 0);
}
static void
test_node_list(void **state)
{
struct lys_module *mod;
struct lysc_node_list *list;
struct lysc_node *child;
struct ly_in *in;
const char *data =
"module a {namespace urn:a;prefix a;feature f;"
"list l1 {key \"x y\"; ordered-by user; leaf y{type string;if-feature f;} leaf x {type string; when 1;}}"
"list l2 {config false;leaf value {type string;}}}";
const char *feats[] = {"f", NULL};
assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
assert_int_equal(LY_SUCCESS, lys_parse(UTEST_LYCTX, in, LYS_IN_YANG, feats, &mod));
ly_in_free(in, 0);
list = (struct lysc_node_list *)mod->compiled->data;
assert_non_null(list);
assert_non_null(list->child);
assert_string_equal("x", list->child->name);
assert_true(list->child->flags & LYS_KEY);
assert_string_equal("y", list->child->next->name);
assert_true(list->child->next->flags & LYS_KEY);
assert_non_null(list->child);
assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR | LYS_ORDBY_USER, list->flags);
assert_true(list->child->flags & LYS_KEY);
assert_true(list->child->next->flags & LYS_KEY);
list = (struct lysc_node_list *)mod->compiled->data->next;
assert_non_null(list);
assert_non_null(list->child);
assert_false(list->child->flags & LYS_KEY);
assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_ORDBY_USER | LYS_SET_CONFIG | LYS_KEYLESS, list->flags);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;"
"list l {key a; unique \"a c/b:b\"; unique \"c/e d\";"
"leaf a {type string; default x;} leaf d {type string;config false;}"
"container c {leaf b {type string;}leaf e{type string;config false;}}}}",
LYS_IN_YANG, &mod));
list = (struct lysc_node_list *)mod->compiled->data;
assert_non_null(list);
assert_string_equal("l", list->name);
assert_string_equal("a", list->child->name);
assert_true(list->child->flags & LYS_KEY);
assert_null(((struct lysc_node_leaf *)list->child)->dflt.str);
assert_non_null(list->uniques);
assert_int_equal(2, LY_ARRAY_COUNT(list->uniques));
assert_int_equal(2, LY_ARRAY_COUNT(list->uniques[0]));
assert_string_equal("a", list->uniques[0][0]->name);
assert_true(list->uniques[0][0]->flags & LYS_UNIQUE);
assert_string_equal("b", list->uniques[0][1]->name);
assert_true(list->uniques[0][1]->flags & LYS_UNIQUE);
assert_int_equal(2, LY_ARRAY_COUNT(list->uniques[1]));
assert_string_equal("e", list->uniques[1][0]->name);
assert_true(list->uniques[1][0]->flags & LYS_UNIQUE);
assert_string_equal("d", list->uniques[1][1]->name);
assert_true(list->uniques[1][1]->flags & LYS_UNIQUE);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {yang-version 1.1;namespace urn:c;prefix c;"
"list l {key a;leaf a {type empty;}}}", LYS_IN_YANG, &mod));
list = (struct lysc_node_list *)mod->compiled->data;
assert_non_null(list);
assert_string_equal("l", list->name);
assert_string_equal("a", list->child->name);
assert_true(list->child->flags & LYS_KEY);
assert_int_equal(LY_TYPE_EMPTY, ((struct lysc_node_leaf *)list->child)->type->basetype);
/* keys order */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {yang-version 1.1;namespace urn:d;prefix d;"
"list l {key \"d b c\";leaf a {type string;} leaf b {type string;} leaf c {type string;} leaf d {type string;}}}", LYS_IN_YANG, &mod));
list = (struct lysc_node_list *)mod->compiled->data;
assert_non_null(list);
assert_string_equal("l", list->name);
assert_non_null(child = list->child);
assert_string_equal("d", child->name);
assert_true(child->flags & LYS_KEY);
assert_non_null(child = child->next);
assert_string_equal("b", child->name);
assert_true(child->flags & LYS_KEY);
assert_non_null(child = child->next);
assert_string_equal("c", child->name);
assert_true(child->flags & LYS_KEY);
assert_non_null(child = child->next);
assert_string_equal("a", child->name);
assert_false(child->flags & LYS_KEY);
/* invalid */
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;list l;}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Missing key in list representing configuration data.", "/aa:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {yang-version 1.1; namespace urn:bb;prefix bb;"
"list l {key x; leaf x {type string; when 1;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("List's key must not have any \"when\" statement.", "/bb:l/x", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;feature f;"
"list l {key x; leaf x {type string; if-feature f;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Key \"x\" is disabled.", "/cc:l/x", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd;"
"list l {key x; leaf x {type string; config false;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Key of a configuration list must not be a state leaf.", "/dd:l/x", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;"
"list l {config false;key x; leaf x {type string; config true;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Configuration node cannot be child of any state data node.", "/ee:l/x", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff;"
"list l {key x; leaf-list x {type string;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("The list's key \"x\" not found.", "/ff:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg;"
"list l {key x; unique y;leaf x {type string;} leaf-list y {type string;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Unique's descendant-schema-nodeid \"y\" refers to leaf-list node instead of a leaf.", "/gg:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:hh;prefix hh;"
"list l {key x; unique \"x y\";leaf x {type string;} leaf y {config false; type string;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Unique statement \"x y\" refers to leaves with different config type.", "/hh:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii {namespace urn:ii;prefix ii;"
"list l {key x; unique a:x;leaf x {type string;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid descendant-schema-nodeid value \"a:x\" - prefix \"a\" not defined in module \"ii\".", "/ii:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj {namespace urn:jj;prefix jj;"
"list l {key x; unique c/x;leaf x {type string;}container c {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid descendant-schema-nodeid value \"c/x\" - target node not found.", "/jj:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk {namespace urn:kk;prefix kk;"
"list l {key x; unique c^y;leaf x {type string;}container c {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid descendant-schema-nodeid value \"c^\" - missing \"/\" as node-identifier separator.", "/kk:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ll {namespace urn:ll;prefix ll;"
"list l {key \"x y x\";leaf x {type string;}leaf y {type string;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Duplicated key identifier \"x\".", "/ll:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm {namespace urn:mm;prefix mm;"
"list l {key x;leaf x {type empty;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("List key of the \"empty\" type is allowed only in YANG 1.1 modules.", "/mm:l/x", 0);
}
static void
test_node_choice(void **state)
{
struct lys_module *mod;
struct lysc_node_choice *ch;
struct lysc_node_case *cs;
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;feature f;"
"choice ch {default a:b; when \"true()\"; case a {leaf a1 {type string;}leaf a2 {type string;}}"
"leaf b {type string;}}}", LYS_IN_YANG, &mod));
ch = (struct lysc_node_choice *)mod->compiled->data;
assert_non_null(ch);
assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR, ch->flags);
assert_int_equal(1, LY_ARRAY_COUNT(ch->when));
assert_null(ch->when[0]->context);
cs = ch->cases;
assert_non_null(cs);
assert_string_equal("a", cs->name);
assert_ptr_equal(ch, cs->parent);
assert_non_null(cs->child);
assert_string_equal("a1", cs->child->name);
assert_non_null(cs->child->next);
assert_string_equal("a2", cs->child->next->name);
assert_ptr_equal(cs, cs->child->parent);
cs = (struct lysc_node_case *)cs->next;
assert_non_null(cs);
assert_string_equal("b", cs->name);
assert_int_equal(LYS_STATUS_CURR | LYS_SET_DFLT | LYS_CONFIG_W, cs->flags);
assert_ptr_equal(ch, cs->parent);
assert_non_null(cs->child);
assert_string_equal("b", cs->child->name);
assert_ptr_equal(cs, cs->child->parent);
assert_ptr_equal(ch->dflt, cs);
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;"
"choice ch {case a {leaf x {type string;}}leaf x {type string;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Duplicate identifier \"/aa:ch/a/x\" of data definition/RPC/action/notification statement.", "/aa:ch/x/x", 0);
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module aa2 {namespace urn:aa2;prefix aa;"
"choice ch {case a {leaf y {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Duplicate identifier \"/aa2:ch/a/y\" of data definition/RPC/action/notification statement.", "/aa2:ch/b/y", 0);
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;"
"choice ch {case a {leaf x {type string;}}leaf a {type string;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Duplicate identifier \"/bb:ch/a\" of case statement.", "/bb:ch/a", 0);
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module bb2 {namespace urn:bb2;prefix bb;"
"choice ch {case b {leaf x {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Duplicate identifier \"/bb2:ch/b\" of case statement.", "/bb2:ch/b", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ca {namespace urn:ca;prefix ca;"
"choice ch {default c;case a {leaf x {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Default case \"c\" not found.", "/ca:ch", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cb {namespace urn:cb;prefix cb; import a {prefix a;}"
"choice ch {default a:a;case a {leaf x {type string;}}case b {leaf y {type string;}}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Default case \"a:a\" not found.", "/cb:ch", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc;"
"choice ch {default a;case a {leaf x {mandatory true;type string;}}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Mandatory node \"x\" under the default case \"a\".", "/cc:ch", 0);
/* TODO check with mandatory nodes from augment placed into the case */
}
static void
test_node_anydata(void **state)
{
struct lys_module *mod;
struct lysc_node_anydata *any;
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1;namespace urn:a;prefix a;"
"anydata any {config false;mandatory true;}}", LYS_IN_YANG, &mod));
any = (struct lysc_node_anydata *)mod->compiled->data;
assert_non_null(any);
assert_int_equal(LYS_ANYDATA, any->nodetype);
assert_int_equal(LYS_CONFIG_R | LYS_STATUS_CURR | LYS_MAND_TRUE | LYS_SET_CONFIG, any->flags);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;"
"anyxml any;}", LYS_IN_YANG, &mod));
any = (struct lysc_node_anydata *)mod->compiled->data;
assert_non_null(any);
assert_int_equal(LYS_ANYXML, any->nodetype);
assert_int_equal(LYS_CONFIG_W | LYS_STATUS_CURR, any->flags);
/* invalid */
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;anydata any;}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Parsing module \"aa\" failed.", NULL, 0);
CHECK_LOG_CTX("Invalid keyword \"anydata\" as a child of \"module\" - the statement is allowed only in YANG 1.1 modules.",
NULL, 1);
}
static void
test_action(void **state)
{
struct lys_module *mod;
const struct lysc_node_action *rpc;
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;"
"rpc a {input {leaf x {type int8;} leaf y {type int8;}} output {leaf result {type int16;}}}}", LYS_IN_YANG, &mod));
rpc = mod->compiled->rpcs;
assert_non_null(rpc);
assert_null(rpc->next);
assert_int_equal(LYS_RPC, rpc->nodetype);
assert_int_equal(LYS_STATUS_CURR, rpc->flags);
assert_string_equal("a", rpc->name);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {yang-version 1.1; namespace urn:b;prefix b; container top {"
"action b {input {leaf x {type int8;} leaf y {type int8;}}"
"output {must \"result > 25\"; must \"/top\"; leaf result {type int16;}}}}"
"augment /top/b/output {leaf result2 {type string;}}}", LYS_IN_YANG, &mod));
rpc = lysc_node_actions(mod->compiled->data);
assert_non_null(rpc);
assert_null(rpc->next);
assert_int_equal(LYS_ACTION, rpc->nodetype);
assert_int_equal(LYS_STATUS_CURR, rpc->flags);
assert_string_equal("b", rpc->name);
assert_null(rpc->input.musts);
assert_int_equal(2, LY_ARRAY_COUNT(rpc->output.musts));
/* invalid */
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;container top {action x;}}",
LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Parsing module \"aa\" failed.", NULL, 0);
CHECK_LOG_CTX("Invalid keyword \"action\" as a child of \"container\" - the statement is allowed only in YANG 1.1 modules.",
NULL, 1);
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;leaf x{type string;} rpc x;}",
LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Duplicate identifier \"/bb:x\" of data definition/RPC/action/notification statement.", "/bb:x", 0);
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module cc {yang-version 1.1; namespace urn:cc;prefix cc;container c {leaf y {type string;} action y;}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Duplicate identifier \"/cc:c/y\" of data definition/RPC/action/notification statement.", "/cc:c/y", 0);
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module dd {yang-version 1.1; namespace urn:dd;prefix dd;container c {action z; action z;}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Duplicate identifier \"/dd:c/z\" of data definition/RPC/action/notification statement.", "/dd:c/z", 0);
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule eesub {belongs-to ee {prefix ee;} notification w;}");
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;include eesub; rpc w;}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Duplicate identifier \"/ee:w\" of data definition/RPC/action/notification statement.", "/ee:w", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {yang-version 1.1; namespace urn:ff;prefix ff; rpc test {input {container a {leaf b {type string;}}}}"
"augment /test/input/a {action invalid {input {leaf x {type string;}}}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Action \"invalid\" is placed inside another RPC/action.", "/ff:{augment='/test/input/a'}/invalid", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {yang-version 1.1; namespace urn:gg;prefix gg; notification test {container a {leaf b {type string;}}}"
"augment /test/a {action invalid {input {leaf x {type string;}}}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Action \"invalid\" is placed inside notification.", "/gg:{augment='/test/a'}/invalid", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {yang-version 1.1; namespace urn:hh;prefix hh; notification test {container a {uses grp;}}"
"grouping grp {action invalid {input {leaf x {type string;}}}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Action \"invalid\" is placed inside notification.", "/hh:test/a/{uses='grp'}/invalid", 0);
}
static void
test_notification(void **state)
{
struct lys_module *mod;
const struct lysc_node_notif *notif;
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;"
"notification a1 {leaf x {type int8;}} notification a2;}", LYS_IN_YANG, &mod));
notif = mod->compiled->notifs;
assert_non_null(notif);
assert_non_null(notif->next);
assert_null(notif->next->next);
assert_int_equal(LYS_NOTIF, notif->nodetype);
assert_int_equal(LYS_STATUS_CURR, notif->flags);
assert_string_equal("a1", notif->name);
assert_non_null(notif->child);
assert_string_equal("x", notif->child->name);
notif = notif->next;
assert_int_equal(LYS_NOTIF, notif->nodetype);
assert_int_equal(LYS_STATUS_CURR, notif->flags);
assert_string_equal("a2", notif->name);
assert_null(notif->child);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {yang-version 1.1; namespace urn:b;prefix b; container top {"
"notification b1 {leaf x {type int8;}} notification b2 {must \"/top\";}}}", LYS_IN_YANG, &mod));
notif = lysc_node_notifs(mod->compiled->data);
assert_non_null(notif);
assert_non_null(notif->next);
assert_null(notif->next->next);
assert_int_equal(LYS_NOTIF, notif->nodetype);
assert_int_equal(LYS_STATUS_CURR, notif->flags);
assert_string_equal("b1", notif->name);
assert_non_null(notif->child);
assert_string_equal("x", notif->child->name);
notif = notif->next;
assert_int_equal(LYS_NOTIF, notif->nodetype);
assert_int_equal(LYS_STATUS_CURR, notif->flags);
assert_string_equal("b2", notif->name);
assert_null(notif->child);
assert_int_equal(1, LY_ARRAY_COUNT(notif->musts));
/* invalid */
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;container top {notification x;}}",
LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Parsing module \"aa\" failed.", NULL, 0);
CHECK_LOG_CTX("Invalid keyword \"notification\" as a child of \"container\" - the statement is allowed only in YANG 1.1 modules.",
NULL, 1);
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;leaf x{type string;} notification x;}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Duplicate identifier \"/bb:x\" of data definition/RPC/action/notification statement.", "/bb:x", 0);
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module cc {yang-version 1.1; namespace urn:cc;prefix cc;container c {leaf y {type string;} notification y;}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Duplicate identifier \"/cc:c/y\" of data definition/RPC/action/notification statement.", "/cc:c/y", 0);
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module dd {yang-version 1.1; namespace urn:dd;prefix dd;container c {notification z; notification z;}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Duplicate identifier \"/dd:c/z\" of data definition/RPC/action/notification statement.", "/dd:c/z", 0);
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule eesub {belongs-to ee {prefix ee;} rpc w;}");
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;include eesub; notification w;}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Duplicate identifier \"/ee:w\" of data definition/RPC/action/notification statement.", "/ee:w", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {yang-version 1.1; namespace urn:ff;prefix ff; rpc test {input {container a {leaf b {type string;}}}}"
"augment /test/input/a {notification invalid {leaf x {type string;}}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Notification \"invalid\" is placed inside RPC/action.", "/ff:{augment='/test/input/a'}/invalid", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {yang-version 1.1; namespace urn:gg;prefix gg; notification test {container a {leaf b {type string;}}}"
"augment /test/a {notification invalid {leaf x {type string;}}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Notification \"invalid\" is placed inside another notification.", "/gg:{augment='/test/a'}/invalid", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {yang-version 1.1; namespace urn:hh;prefix hh; rpc test {input {container a {uses grp;}}}"
"grouping grp {notification invalid {leaf x {type string;}}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Notification \"invalid\" is placed inside RPC/action.", "/hh:test/input/a/{uses='grp'}/invalid", 0);
}
/**
* actually the same as length restriction (tested in test_type_length()), so just check the correct handling in appropriate types,
* do not test the expression itself
*/
static void
test_type_range(void **state)
{
struct lys_module *mod;
struct lysc_type *type;
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;leaf l {type int16 {range min..10|max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_INT16, type->basetype);
assert_non_null(((struct lysc_type_num *)type)->range);
assert_non_null(((struct lysc_type_num *)type)->range->parts);
assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_num *)type)->range->parts));
assert_int_equal(-32768, ((struct lysc_type_num *)type)->range->parts[0].min_64);
assert_int_equal(10, ((struct lysc_type_num *)type)->range->parts[0].max_64);
assert_int_equal(32767, ((struct lysc_type_num *)type)->range->parts[1].min_64);
assert_int_equal(32767, ((struct lysc_type_num *)type)->range->parts[1].max_64);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c;leaf l {type int32 {range min..10|max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_INT32, type->basetype);
assert_non_null(((struct lysc_type_num *)type)->range);
assert_non_null(((struct lysc_type_num *)type)->range->parts);
assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_num *)type)->range->parts));
assert_int_equal(INT64_C(-2147483648), ((struct lysc_type_num *)type)->range->parts[0].min_64);
assert_int_equal(10, ((struct lysc_type_num *)type)->range->parts[0].max_64);
assert_int_equal(INT64_C(2147483647), ((struct lysc_type_num *)type)->range->parts[1].min_64);
assert_int_equal(INT64_C(2147483647), ((struct lysc_type_num *)type)->range->parts[1].max_64);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d;leaf l {type int64 {range min..10|max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_INT64, type->basetype);
assert_non_null(((struct lysc_type_num *)type)->range);
assert_non_null(((struct lysc_type_num *)type)->range->parts);
assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_num *)type)->range->parts));
assert_int_equal(INT64_C(-9223372036854775807) - INT64_C(1), ((struct lysc_type_num *)type)->range->parts[0].min_64);
assert_int_equal(10, ((struct lysc_type_num *)type)->range->parts[0].max_64);
assert_int_equal(INT64_C(9223372036854775807), ((struct lysc_type_num *)type)->range->parts[1].min_64);
assert_int_equal(INT64_C(9223372036854775807), ((struct lysc_type_num *)type)->range->parts[1].max_64);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {namespace urn:e;prefix e;leaf l {type uint8 {range min..10|max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_UINT8, type->basetype);
assert_non_null(((struct lysc_type_num *)type)->range);
assert_non_null(((struct lysc_type_num *)type)->range->parts);
assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_num *)type)->range->parts));
assert_int_equal(0, ((struct lysc_type_num *)type)->range->parts[0].min_u64);
assert_int_equal(10, ((struct lysc_type_num *)type)->range->parts[0].max_u64);
assert_int_equal(255, ((struct lysc_type_num *)type)->range->parts[1].min_u64);
assert_int_equal(255, ((struct lysc_type_num *)type)->range->parts[1].max_u64);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {namespace urn:f;prefix f;leaf l {type uint16 {range min..10|max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_UINT16, type->basetype);
assert_non_null(((struct lysc_type_num *)type)->range);
assert_non_null(((struct lysc_type_num *)type)->range->parts);
assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_num *)type)->range->parts));
assert_int_equal(0, ((struct lysc_type_num *)type)->range->parts[0].min_u64);
assert_int_equal(10, ((struct lysc_type_num *)type)->range->parts[0].max_u64);
assert_int_equal(65535, ((struct lysc_type_num *)type)->range->parts[1].min_u64);
assert_int_equal(65535, ((struct lysc_type_num *)type)->range->parts[1].max_u64);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module g {namespace urn:g;prefix g;leaf l {type uint32 {range min..10|max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_UINT32, type->basetype);
assert_non_null(((struct lysc_type_num *)type)->range);
assert_non_null(((struct lysc_type_num *)type)->range->parts);
assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_num *)type)->range->parts));
assert_int_equal(0, ((struct lysc_type_num *)type)->range->parts[0].min_u64);
assert_int_equal(10, ((struct lysc_type_num *)type)->range->parts[0].max_u64);
assert_int_equal(UINT64_C(4294967295), ((struct lysc_type_num *)type)->range->parts[1].min_u64);
assert_int_equal(UINT64_C(4294967295), ((struct lysc_type_num *)type)->range->parts[1].max_u64);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module h {namespace urn:h;prefix h;leaf l {type uint64 {range min..10|max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_UINT64, type->basetype);
assert_non_null(((struct lysc_type_num *)type)->range);
assert_non_null(((struct lysc_type_num *)type)->range->parts);
assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_num *)type)->range->parts));
assert_int_equal(0, ((struct lysc_type_num *)type)->range->parts[0].min_u64);
assert_int_equal(10, ((struct lysc_type_num *)type)->range->parts[0].max_u64);
assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_num *)type)->range->parts[1].min_u64);
assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_num *)type)->range->parts[1].max_u64);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module i {namespace urn:i;prefix i;typedef mytype {type uint8 {range 10..100;}}"
"typedef mytype2 {type mytype;} leaf l {type mytype2;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(3, type->refcount);
assert_int_equal(LY_TYPE_UINT8, type->basetype);
assert_non_null(((struct lysc_type_num *)type)->range);
assert_non_null(((struct lysc_type_num *)type)->range->parts);
assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_num *)type)->range->parts));
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module j {namespace urn:j;prefix j;"
"typedef mytype {type uint8 {range 1..100{description \"one to hundred\";reference A;}}}"
"leaf l {type mytype {range 1..10 {description \"one to ten\";reference B;}}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
assert_int_equal(LY_TYPE_UINT8, type->basetype);
assert_non_null(((struct lysc_type_num *)type)->range);
assert_string_equal("one to ten", ((struct lysc_type_num *)type)->range->dsc);
assert_string_equal("B", ((struct lysc_type_num *)type)->range->ref);
assert_non_null(((struct lysc_type_num *)type)->range->parts);
assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_num *)type)->range->parts));
assert_int_equal(1, ((struct lysc_type_num *)type)->range->parts[0].min_u64);
assert_int_equal(10, ((struct lysc_type_num *)type)->range->parts[0].max_u64);
}
static void
test_type_length(void **state)
{
struct lys_module *mod;
struct lysc_type *type;
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;leaf l {type binary {length min {error-app-tag errortag;error-message error;}}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_bin *)type)->length);
assert_non_null(((struct lysc_type_bin *)type)->length->parts);
assert_string_equal("errortag", ((struct lysc_type_bin *)type)->length->eapptag);
assert_string_equal("error", ((struct lysc_type_bin *)type)->length->emsg);
assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_bin *)type)->length->parts));
assert_int_equal(0, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
assert_int_equal(0, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;leaf l {type binary {length max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_bin *)type)->length);
assert_non_null(((struct lysc_type_bin *)type)->length->parts);
assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_bin *)type)->length->parts));
assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c;leaf l {type binary {length min..max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_bin *)type)->length);
assert_non_null(((struct lysc_type_bin *)type)->length->parts);
assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_bin *)type)->length->parts));
assert_int_equal(0, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
assert_int_equal(UINT64_C(18446744073709551615), ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d;leaf l {type binary {length 5;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_bin *)type)->length);
assert_non_null(((struct lysc_type_bin *)type)->length->parts);
assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_bin *)type)->length->parts));
assert_int_equal(5, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
assert_int_equal(5, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {namespace urn:e;prefix e;leaf l {type binary {length 1..10;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_bin *)type)->length);
assert_non_null(((struct lysc_type_bin *)type)->length->parts);
assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_bin *)type)->length->parts));
assert_int_equal(1, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
assert_int_equal(10, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {namespace urn:f;prefix f;leaf l {type binary {length 1..10|20..30;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_bin *)type)->length);
assert_non_null(((struct lysc_type_bin *)type)->length->parts);
assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_bin *)type)->length->parts));
assert_int_equal(1, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
assert_int_equal(10, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
assert_int_equal(20, ((struct lysc_type_bin *)type)->length->parts[1].min_u64);
assert_int_equal(30, ((struct lysc_type_bin *)type)->length->parts[1].max_u64);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module g {namespace urn:g;prefix g;leaf l {type binary {length \"16 | 32\";}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_bin *)type)->length);
assert_non_null(((struct lysc_type_bin *)type)->length->parts);
assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_bin *)type)->length->parts));
assert_int_equal(16, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
assert_int_equal(16, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
assert_int_equal(32, ((struct lysc_type_bin *)type)->length->parts[1].min_u64);
assert_int_equal(32, ((struct lysc_type_bin *)type)->length->parts[1].max_u64);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module h {namespace urn:h;prefix h;typedef mytype {type binary {length 10;}}"
"leaf l {type mytype {length \"10\";}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_bin *)type)->length);
assert_non_null(((struct lysc_type_bin *)type)->length->parts);
assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_bin *)type)->length->parts));
assert_int_equal(10, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
assert_int_equal(10, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module i {namespace urn:i;prefix i;typedef mytype {type binary {length 10..100;}}"
"leaf l {type mytype {length \"50\";}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_bin *)type)->length);
assert_non_null(((struct lysc_type_bin *)type)->length->parts);
assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_bin *)type)->length->parts));
assert_int_equal(50, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
assert_int_equal(50, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module j {namespace urn:j;prefix j;typedef mytype {type binary {length 10..100;}}"
"leaf l {type mytype {length \"10..30|60..100\";}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_bin *)type)->length);
assert_non_null(((struct lysc_type_bin *)type)->length->parts);
assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_bin *)type)->length->parts));
assert_int_equal(10, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
assert_int_equal(30, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
assert_int_equal(60, ((struct lysc_type_bin *)type)->length->parts[1].min_u64);
assert_int_equal(100, ((struct lysc_type_bin *)type)->length->parts[1].max_u64);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module k {namespace urn:k;prefix k;typedef mytype {type binary {length 10..100;}}"
"leaf l {type mytype {length \"10..80\";}}leaf ll {type mytype;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
assert_non_null(((struct lysc_type_bin *)type)->length);
assert_non_null(((struct lysc_type_bin *)type)->length->parts);
assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_bin *)type)->length->parts));
assert_int_equal(10, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
assert_int_equal(80, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
type = ((struct lysc_node_leaf *)mod->compiled->data->next)->type;
assert_non_null(type);
assert_int_equal(2, type->refcount);
assert_non_null(((struct lysc_type_bin *)type)->length);
assert_non_null(((struct lysc_type_bin *)type)->length->parts);
assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_bin *)type)->length->parts));
assert_int_equal(10, ((struct lysc_type_bin *)type)->length->parts[0].min_u64);
assert_int_equal(100, ((struct lysc_type_bin *)type)->length->parts[0].max_u64);
/* invalid values */
assert_int_equal(LY_EDENIED, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;leaf l {type binary {length -10;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid length restriction - value \"-10\" does not fit the type limitations.", "/aa:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;leaf l {type binary {length 18446744073709551616;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid length restriction - invalid value \"18446744073709551616\".", "/bb:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc;leaf l {type binary {length \"max .. 10\";}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid length restriction - unexpected data after max keyword (.. 10).", "/cc:l", 0);
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd;leaf l {type binary {length 50..10;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid length restriction - values are not in ascending order (10).", "/dd:l", 0);
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;leaf l {type binary {length \"50 | 10\";}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid length restriction - values are not in ascending order (10).", "/ee:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff;leaf l {type binary {length \"x\";}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid length restriction - unexpected data (x).", "/ff:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg;leaf l {type binary {length \"50 | min\";}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid length restriction - unexpected data before min keyword (50 | ).", "/gg:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:hh;prefix hh;leaf l {type binary {length \"| 50\";}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid length restriction - unexpected beginning of the expression (| 50).", "/hh:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii {namespace urn:ii;prefix ii;leaf l {type binary {length \"10 ..\";}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid length restriction - unexpected end of the expression after \"..\" (10 ..).", "/ii:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj {namespace urn:jj;prefix jj;leaf l {type binary {length \".. 10\";}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid length restriction - unexpected \"..\" without a lower bound.", "/jj:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk {namespace urn:kk;prefix kk;leaf l {type binary {length \"10 |\";}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid length restriction - unexpected end of the expression (10 |).", "/kk:l", 0);
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module kl {namespace urn:kl;prefix kl;leaf l {type binary {length \"10..20 | 15..30\";}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid length restriction - values are not in ascending order (15).", "/kl:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ll {namespace urn:ll;prefix ll;typedef mytype {type binary {length 10;}}"
"leaf l {type mytype {length 11;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid length restriction - the derived restriction (11) is not equally or more limiting.", "/ll:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm {namespace urn:mm;prefix mm;typedef mytype {type binary {length 10..100;}}"
"leaf l {type mytype {length 1..11;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid length restriction - the derived restriction (1..11) is not equally or more limiting.", "/mm:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module nn {namespace urn:nn;prefix nn;typedef mytype {type binary {length 10..100;}}"
"leaf l {type mytype {length 20..110;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid length restriction - the derived restriction (20..110) is not equally or more limiting.",
"/nn:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module oo {namespace urn:oo;prefix oo;typedef mytype {type binary {length 10..100;}}"
"leaf l {type mytype {length 20..30|110..120;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid length restriction - the derived restriction (20..30|110..120) is not equally or more limiting.",
"/oo:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module pp {namespace urn:pp;prefix pp;typedef mytype {type binary {length 10..11;}}"
"leaf l {type mytype {length 15;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid length restriction - the derived restriction (15) is not equally or more limiting.", "/pp:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module qq {namespace urn:qq;prefix qq;typedef mytype {type binary {length 10..20|30..40;}}"
"leaf l {type mytype {length 15..35;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid length restriction - the derived restriction (15..35) is not equally or more limiting.", "/qq:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module rr {namespace urn:rr;prefix rr;typedef mytype {type binary {length 10;}}"
"leaf l {type mytype {length 10..35;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid length restriction - the derived restriction (10..35) is not equally or more limiting.", "/rr:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ss {namespace urn:ss;prefix ss;leaf l {type binary {pattern '[0-9]*';}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid type restrictions for binary type.", "/ss:l", 0);
}
static void
test_type_pattern(void **state)
{
struct lys_module *mod;
struct lysc_type *type;
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1; namespace urn:a;prefix a;leaf l {type string {"
"pattern .* {error-app-tag errortag;error-message error;}"
"pattern [0-9].*[0-9] {modifier invert-match;}}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_non_null(((struct lysc_type_str *)type)->patterns);
assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_str *)type)->patterns));
assert_string_equal("errortag", ((struct lysc_type_str *)type)->patterns[0]->eapptag);
assert_string_equal("error", ((struct lysc_type_str *)type)->patterns[0]->emsg);
assert_string_equal(".*", ((struct lysc_type_str *)type)->patterns[0]->expr);
assert_int_equal(0, ((struct lysc_type_str *)type)->patterns[0]->inverted);
assert_null(((struct lysc_type_str *)type)->patterns[1]->eapptag);
assert_null(((struct lysc_type_str *)type)->patterns[1]->emsg);
assert_string_equal("[0-9].*[0-9]", ((struct lysc_type_str *)type)->patterns[1]->expr);
assert_int_equal(1, ((struct lysc_type_str *)type)->patterns[1]->inverted);
/* TODO check some data "^Å™$" */
}
static void
test_type_enum(void **state)
{
struct lys_module *mod;
struct lysc_type *type;
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1; namespace urn:a;prefix a;feature f; leaf l {type enumeration {"
"enum automin; enum min {value -2147483648;}enum one {if-feature f; value 1;}"
"enum two; enum seven {value 7;}enum eight;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_ENUM, type->basetype);
assert_non_null(((struct lysc_type_enum *)type)->enums);
assert_int_equal(5, LY_ARRAY_COUNT(((struct lysc_type_enum *)type)->enums));
assert_string_equal("automin", ((struct lysc_type_enum *)type)->enums[0].name);
assert_int_equal(0, ((struct lysc_type_enum *)type)->enums[0].value);
assert_string_equal("min", ((struct lysc_type_enum *)type)->enums[1].name);
assert_int_equal(INT64_C(-2147483648), ((struct lysc_type_enum *)type)->enums[1].value);
assert_string_equal("two", ((struct lysc_type_enum *)type)->enums[2].name);
assert_int_equal(2, ((struct lysc_type_enum *)type)->enums[2].value);
assert_string_equal("seven", ((struct lysc_type_enum *)type)->enums[3].name);
assert_int_equal(7, ((struct lysc_type_enum *)type)->enums[3].value);
assert_string_equal("eight", ((struct lysc_type_enum *)type)->enums[4].name);
assert_int_equal(8, ((struct lysc_type_enum *)type)->enums[4].value);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {yang-version 1.1; namespace urn:b;prefix b;feature f; typedef mytype {type enumeration {"
"enum 11; enum min {value -2147483648;}enum x$&;"
"enum two; enum seven {value 7;}enum eight;}} leaf l { type mytype {enum seven;enum eight;}}}",
LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_ENUM, type->basetype);
assert_non_null(((struct lysc_type_enum *)type)->enums);
assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_enum *)type)->enums));
assert_string_equal("seven", ((struct lysc_type_enum *)type)->enums[0].name);
assert_int_equal(7, ((struct lysc_type_enum *)type)->enums[0].value);
assert_string_equal("eight", ((struct lysc_type_enum *)type)->enums[1].name);
assert_int_equal(8, ((struct lysc_type_enum *)type)->enums[1].value);
const char *new_module = "module moc_c {yang-version 1.1; namespace urn:moc_c;prefix moc_c;feature f; typedef mytype {type enumeration {"
"enum first{value -270;} enum second; enum third {value -400;} enum fourth;}} leaf l { type mytype;}}";
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, new_module, LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_ENUM, type->basetype);
assert_non_null(((struct lysc_type_enum *)type)->enums);
assert_int_equal(4, LY_ARRAY_COUNT(((struct lysc_type_enum *)type)->enums));
assert_string_equal("first", ((struct lysc_type_enum *)type)->enums[0].name);
assert_int_equal(-270, ((struct lysc_type_enum *)type)->enums[0].value);
assert_string_equal("second", ((struct lysc_type_enum *)type)->enums[1].name);
assert_int_equal(-269, ((struct lysc_type_enum *)type)->enums[1].value);
assert_string_equal("third", ((struct lysc_type_enum *)type)->enums[2].name);
assert_int_equal(-400, ((struct lysc_type_enum *)type)->enums[2].value);
assert_string_equal("fourth", ((struct lysc_type_enum *)type)->enums[3].name);
assert_int_equal(-268, ((struct lysc_type_enum *)type)->enums[3].value);
new_module = "module moc_d {yang-version 1.1; namespace urn:moc_d;prefix moc_d;feature f; typedef mytype {type enumeration {"
"enum first; enum second;}} leaf l { type mytype;}}";
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, new_module, LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_ENUM, type->basetype);
assert_non_null(((struct lysc_type_enum *)type)->enums);
assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_enum *)type)->enums));
assert_string_equal("first", ((struct lysc_type_enum *)type)->enums[0].name);
assert_int_equal(0, ((struct lysc_type_enum *)type)->enums[0].value);
assert_string_equal("second", ((struct lysc_type_enum *)type)->enums[1].name);
assert_int_equal(1, ((struct lysc_type_enum *)type)->enums[1].value);
/* invalid cases */
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; feature f; leaf l {type enumeration {"
"enum one {if-feature f;}}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Parsing module \"aa\" failed.", NULL, 0);
CHECK_LOG_CTX("Invalid keyword \"if-feature\" as a child of \"enum\" - the statement is allowed only in YANG 1.1 modules.",
NULL, 1);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
"enum one {value -2147483649;}}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Parsing module \"aa\" failed.", NULL, 0);
CHECK_LOG_CTX("Invalid value \"-2147483649\" of \"value\".", NULL, 1);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
"enum one {value 2147483648;}}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Parsing module \"aa\" failed.", NULL, 0);
CHECK_LOG_CTX("Invalid value \"2147483648\" of \"value\".", NULL, 1);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
"enum one; enum one;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Parsing module \"aa\" failed.", NULL, 0);
CHECK_LOG_CTX("Duplicate identifier \"one\" of enum statement.", NULL, 1);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
"enum '';}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Parsing module \"aa\" failed.", NULL, 0);
CHECK_LOG_CTX("Enum name must not be zero-length.", NULL, 1);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
"enum ' x';}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Parsing module \"aa\" failed.", NULL, 0);
CHECK_LOG_CTX("Enum name must not have any leading or trailing whitespaces (\" x\").", NULL, 1);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
"enum 'x ';}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Parsing module \"aa\" failed.", NULL, 0);
CHECK_LOG_CTX("Enum name must not have any leading or trailing whitespaces (\"x \").", NULL, 1);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type enumeration {"
"enum 'inva\nlid';}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Control characters in enum name should be avoided (\"inva\nlid\", character number 5).", NULL, 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb; leaf l {type enumeration;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Missing enum substatement for enumeration type.", "/bb:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {yang-version 1.1;namespace urn:cc;prefix cc;typedef mytype {type enumeration {enum one;}}"
"leaf l {type mytype {enum two;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid enumeration - derived type adds new item \"two\".", "/cc:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {yang-version 1.1;namespace urn:dd;prefix dd;typedef mytype {type enumeration {enum one;}}"
"leaf l {type mytype {enum one {value 1;}}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid enumeration - value of the item \"one\" has changed from 0 to 1 in the derived type.", "/dd:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;leaf l {type enumeration {enum x {value 2147483647;}enum y;}}}",
LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid enumeration - it is not possible to auto-assign enum value for \"y\" since the highest value is already 2147483647.",
"/ee:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff;leaf l {type enumeration {enum x {value 1;}enum y {value 1;}}}}",
LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid enumeration - value 1 collide in items \"y\" and \"x\".", "/ff:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg;typedef mytype {type enumeration;}"
"leaf l {type mytype {enum one;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Missing enum substatement for enumeration type mytype.", "/gg:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:hh;prefix hh; typedef mytype {type enumeration {enum one;}}"
"leaf l {type mytype {enum one;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Enumeration type can be subtyped only in YANG 1.1 modules.", "/hh:l", 0);
}
static void
test_type_dec64(void **state)
{
struct lys_module *mod;
struct lysc_type *type;
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;leaf l {type decimal64 {"
"fraction-digits 2;range min..max;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_DEC64, type->basetype);
assert_int_equal(2, ((struct lysc_type_dec *)type)->fraction_digits);
assert_non_null(((struct lysc_type_dec *)type)->range);
assert_non_null(((struct lysc_type_dec *)type)->range->parts);
assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_dec *)type)->range->parts));
assert_int_equal(INT64_C(-9223372036854775807) - INT64_C(1), ((struct lysc_type_dec *)type)->range->parts[0].min_64);
assert_int_equal(INT64_C(9223372036854775807), ((struct lysc_type_dec *)type)->range->parts[0].max_64);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;typedef mytype {type decimal64 {"
"fraction-digits 2;range '3.14 | 5.1 | 10';}}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_DEC64, type->basetype);
assert_int_equal(2, ((struct lysc_type_dec *)type)->fraction_digits);
assert_non_null(((struct lysc_type_dec *)type)->range);
assert_non_null(((struct lysc_type_dec *)type)->range->parts);
assert_int_equal(3, LY_ARRAY_COUNT(((struct lysc_type_dec *)type)->range->parts));
assert_int_equal(314, ((struct lysc_type_dec *)type)->range->parts[0].min_64);
assert_int_equal(314, ((struct lysc_type_dec *)type)->range->parts[0].max_64);
assert_int_equal(510, ((struct lysc_type_dec *)type)->range->parts[1].min_64);
assert_int_equal(510, ((struct lysc_type_dec *)type)->range->parts[1].max_64);
assert_int_equal(1000, ((struct lysc_type_dec *)type)->range->parts[2].min_64);
assert_int_equal(1000, ((struct lysc_type_dec *)type)->range->parts[2].max_64);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c;typedef mytype {type decimal64 {"
"fraction-digits 2;range '1 .. 65535';}}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_int_equal(LY_TYPE_DEC64, type->basetype);
assert_int_equal(2, ((struct lysc_type_dec *)type)->fraction_digits);
assert_non_null(((struct lysc_type_dec *)type)->range);
assert_non_null(((struct lysc_type_dec *)type)->range->parts);
assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_dec *)type)->range->parts));
assert_int_equal(100, ((struct lysc_type_dec *)type)->range->parts[0].min_64);
assert_int_equal(6553500, ((struct lysc_type_dec *)type)->range->parts[0].max_64);
/* invalid cases */
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits 0;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Parsing module \"aa\" failed.", NULL, 0);
CHECK_LOG_CTX("Invalid value \"0\" of \"fraction-digits\".", NULL, 1);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits -1;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Parsing module \"aa\" failed.", NULL, 0);
CHECK_LOG_CTX("Invalid value \"-1\" of \"fraction-digits\".", NULL, 1);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64 {fraction-digits 19;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Parsing module \"aa\" failed.", NULL, 0);
CHECK_LOG_CTX("Value \"19\" is out of \"fraction-digits\" bounds.", NULL, 1);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type decimal64;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Missing fraction-digits substatement for decimal64 type.", "/aa:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ab {namespace urn:ab;prefix ab; typedef mytype {type decimal64;}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Missing fraction-digits substatement for decimal64 type mytype.", "/ab:l", 0);
assert_int_equal(LY_EINVAL, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb; leaf l {type decimal64 {fraction-digits 2;"
"range '3.142';}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Range boundary \"3.142\" of decimal64 type exceeds defined number (2) of fraction digits.", "/bb:l", 0);
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc; leaf l {type decimal64 {fraction-digits 2;"
"range '4 | 3.14';}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid range restriction - values are not in ascending order (3.14).", "/cc:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd; typedef mytype {type decimal64 {fraction-digits 2;}}"
"leaf l {type mytype {fraction-digits 3;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid fraction-digits substatement for type not directly derived from decimal64 built-in type.", "/dd:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module de {namespace urn:de;prefix de; typedef mytype {type decimal64 {fraction-digits 2;}}"
"typedef mytype2 {type mytype {fraction-digits 3;}}leaf l {type mytype2;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid fraction-digits substatement for type \"mytype2\" not directly derived from decimal64 built-in type.",
"/de:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;typedef mytype {type decimal64 {"
"fraction-digits 18;range '-10 .. 0';}}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid range restriction - invalid value \"-10000000000000000000\".", "/ee:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;typedef mytype {type decimal64 {"
"fraction-digits 18;range '0 .. 10';}}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid range restriction - invalid value \"10000000000000000000\".", "/ee:l", 0);
}
static void
test_type_instanceid(void **state)
{
struct lys_module *mod;
struct lysc_type *type;
char *str;
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;typedef mytype {type instance-identifier {require-instance false;}}"
"leaf l1 {type instance-identifier {require-instance true;}}"
"leaf l2 {type mytype;} leaf l3 {type instance-identifier;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_INST, type->basetype);
assert_int_equal(1, ((struct lysc_type_instanceid *)type)->require_instance);
type = ((struct lysc_node_leaf *)mod->compiled->data->next)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_INST, type->basetype);
assert_int_equal(0, ((struct lysc_type_instanceid *)type)->require_instance);
type = ((struct lysc_node_leaf *)mod->compiled->data->next->next)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_INST, type->basetype);
assert_int_equal(1, ((struct lysc_type_instanceid *)type)->require_instance);
/* default value */
str = "module b1 {namespace urn:b1;prefix b1;"
"leaf l1 {type string;}}";
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, str);
ly_ctx_set_options(UTEST_LYCTX, LY_CTX_REF_IMPLEMENTED);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b2 {namespace urn:b2;prefix b2;"
"import b1 {prefix b1;}"
"leaf l1 {type instance-identifier; default \"/b1:l1\";}}", LYS_IN_YANG, NULL));
ly_ctx_set_options(UTEST_LYCTX, 0);
/* invalid cases */
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type instance-identifier {require-instance yes;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Parsing module \"aa\" failed.", NULL, 0);
CHECK_LOG_CTX("Invalid value \"yes\" of \"require-instance\".", NULL, 1);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type instance-identifier {fraction-digits 1;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid type restrictions for instance-identifier type.", "/aa:l", 0);
}
static ly_bool
identity_isderived(const struct lysc_ident *base, const char *der)
{
LY_ARRAY_COUNT_TYPE u;
LY_ARRAY_FOR(base->derived, u) {
if (!strcmp(base->derived[u]->name, der)) {
return 1;
}
if (identity_isderived(base->derived[u], der)) {
return 1;
}
}
return 0;
}
static ly_bool
contains_derived_identity(struct ly_ctx *ctx, char *module_name,
char *revision, char *identity_name, char *derived_name)
{
LY_ARRAY_COUNT_TYPE u = 0;
struct lys_module *mod;
struct lysc_ident *identity = NULL;
if (!(mod = ly_ctx_get_module(ctx, module_name, revision))) {
return 0;
}
LY_ARRAY_FOR(mod->identities, u) {
if (!strcmp(identity_name, mod->identities[u].name)) {
identity = &mod->identities[u];
break;
}
}
if (!identity) {
return 0;
}
return identity_isderived(identity, derived_name);
}
static void
test_identity(void **state)
{
char *str;
const char *feats[2] = {NULL, NULL};
struct lyd_node *tree;
const char *data;
#define RESET_CTX(CTX) \
ly_ctx_destroy(UTEST_LYCTX); \
assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &UTEST_LYCTX));
/* It does not matter whether the base identity is in implemented
* module or not.
*/
/* Implemented module's identity expand base identity located in unimplemented module. */
str = "module a {namespace urn:a; prefix a;"
"identity baseid;"
"identity id1 {base baseid;}"
"}";
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, str);
str = "module b {namespace urn:b; prefix b; import a {prefix a;}"
"identity id2 {base a:baseid;}"
"leaf lf {type identityref {base a:baseid;}}"
"}";
UTEST_ADD_MODULE(str, LYS_IN_YANG, NULL, NULL);
assert_true(contains_derived_identity(UTEST_LYCTX, "a", NULL, "baseid", "id2"));
data = "<lf xmlns=\"urn:b\">id2</lf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree);
lyd_free_tree(tree);
assert_true(contains_derived_identity(UTEST_LYCTX, "a", NULL, "baseid", "id1"));
data = "<lf xmlns=\"urn:b\" xmlns:ids=\"urn:a\">ids:id1</lf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
CHECK_LOG_CTX("Invalid identityref \"ids:id1\" value - identity found in non-implemented module \"a\".", "/b:lf", 1);
assert_non_null(ly_ctx_get_module(UTEST_LYCTX, "a", NULL));
assert_false(contains_derived_identity(UTEST_LYCTX, "a", NULL, "baseid", "id3"));
data = "<lf xmlns=\"urn:b\" xmlns:ids=\"urn:a\">ids:id3</lf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
RESET_CTX(UTEST_LYCTX);
/* Unimplemented module (c) expand base identity located in unimplemented module. */
str = "module a {namespace urn:a; prefix a;"
"identity baseid;"
"identity id1 {base baseid;}"
"}\n"
"module c {namespace urn:c; prefix c; import a {prefix a;}"
"identity id3 {base a:baseid;}"
"}";
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, str);
str = "module b {namespace urn:b; prefix b; import a {prefix a;} import c {prefix c;}"
"identity id2 {base a:baseid;}"
"leaf lf {type identityref {base a:baseid;}}"
"}";
UTEST_ADD_MODULE(str, LYS_IN_YANG, NULL, NULL);
assert_true(contains_derived_identity(UTEST_LYCTX, "a", NULL, "baseid", "id2"));
data = "<lf xmlns=\"urn:b\">id2</lf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree);
lyd_free_tree(tree);
assert_true(contains_derived_identity(UTEST_LYCTX, "a", NULL, "baseid", "id1"));
data = "<lf xmlns=\"urn:b\" xmlns:ids=\"urn:a\">ids:id1</lf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
CHECK_LOG_CTX("Invalid identityref \"ids:id1\" value - identity found in non-implemented module \"a\".", "/b:lf", 1);
assert_true(contains_derived_identity(UTEST_LYCTX, "a", NULL, "baseid", "id3"));
data = "<lf xmlns=\"urn:b\" xmlns:ids=\"urn:c\">ids:id3</lf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
CHECK_LOG_CTX("Invalid identityref \"ids:id3\" value - identity found in non-implemented module \"c\".", "/b:lf", 1);
RESET_CTX(UTEST_LYCTX);
/* Unimplemented module expand base identity located in implemented module. */
str = "module b {namespace urn:b; prefix b;"
"identity baseid;"
"identity id2 {base baseid;}"
"leaf lf {type identityref {base baseid;}}"
"}";
UTEST_ADD_MODULE(str, LYS_IN_YANG, NULL, NULL);
str = "module a {namespace urn:a; prefix a; import b {prefix b;}"
"identity id1 {base b:baseid;}"
"}";
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, str);
/* load (but don't implement) module (a) into context by module (c) */
str = "module c {namespace urn:c; prefix c; import a {prefix a;}}";
UTEST_ADD_MODULE(str, LYS_IN_YANG, NULL, NULL);
assert_true(contains_derived_identity(UTEST_LYCTX, "b", NULL, "baseid", "id2"));
data = "<lf xmlns=\"urn:b\">id2</lf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree);
lyd_free_tree(tree);
assert_true(contains_derived_identity(UTEST_LYCTX, "b", NULL, "baseid", "id1"));
data = "<lf xmlns=\"urn:b\" xmlns:ids=\"urn:a\">ids:id1</lf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
CHECK_LOG_CTX("Invalid identityref \"ids:id1\" value - identity found in non-implemented module \"a\".", "/b:lf", 1);
RESET_CTX(UTEST_LYCTX);
/* Transitivity of derived identity through unimplemented module. */
str = "module a {namespace urn:a; prefix a;"
"identity baseid;"
"identity id1 {base baseid;}"
"}\n"
"module c {namespace urn:c; prefix c; import a {prefix a;}"
"identity id3 {base a:baseid;}"
"}";
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, str);
str = "module b {namespace urn:b; prefix b; import c {prefix c;} import a {prefix a;}"
"identity id2 {base c:id3;}"
"leaf lf {type identityref {base a:baseid;}}"
"}";
UTEST_ADD_MODULE(str, LYS_IN_YANG, NULL, NULL);
assert_true(contains_derived_identity(UTEST_LYCTX, "a", NULL, "baseid", "id2"));
data = "<lf xmlns=\"urn:b\">id2</lf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree);
lyd_free_tree(tree);
assert_true(contains_derived_identity(UTEST_LYCTX, "a", NULL, "baseid", "id1"));
data = "<lf xmlns=\"urn:b\">id1</lf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
assert_true(contains_derived_identity(UTEST_LYCTX, "a", NULL, "baseid", "id3"));
data = "<lf xmlns=\"urn:b\">id3</lf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, LYD_PARSE_STRICT, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
RESET_CTX(UTEST_LYCTX);
/* The base reference must not refer to a non-existent module,
* even if the module is not implemented.
*/
str = "module b {namespace urn:b; prefix b;"
"identity ident { base a:baseid;}"
"}";
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, str);
/* load (but don't implement) module (b) into context by module (c) */
str = "module c {namespace urn:c; prefix c; import b {prefix b;}}";
UTEST_INVALID_MODULE(str, LYS_IN_YANG, NULL, LY_EVALID);
RESET_CTX(UTEST_LYCTX);
/* Tests in which multiple revisions are available and the import
* does not specify an exact revision.
*/
/* The old revision was soon implemented
* and therefore its "baseid" is used.
*/
str = "module a {namespace urn:a; prefix a;"
"revision \"2014-05-08\";"
"identity baseid;"
"leaf alf { type identityref { base baseid;}}"
"}";
UTEST_ADD_MODULE(str, LYS_IN_YANG, NULL, NULL);
str = "module a {namespace urn:a; prefix a;"
"revision \"2015-05-08\";"
"identity baseid;"
"leaf alf { type identityref { base baseid;}}"
"}";
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, str);
str = "module b {namespace urn:b; prefix b;"
"import a {prefix a;}"
"identity baseref { base a:baseid;}"
"identity id1 { base baseref;}"
"identity id2 { base baseref;}"
"}";
UTEST_ADD_MODULE(str, LYS_IN_YANG, NULL, NULL);
assert_true(contains_derived_identity(UTEST_LYCTX, "a", "2014-05-08", "baseid", "baseref"));
assert_true(contains_derived_identity(UTEST_LYCTX, "a", "2014-05-08", "baseid", "id1"));
data = "<alf xmlns=\"urn:a\" xmlns:ids=\"urn:b\">ids:id1</alf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree);
lyd_free_tree(tree);
assert_true(contains_derived_identity(UTEST_LYCTX, "a", "2014-05-08", "baseid", "id2"));
data = "<alf xmlns=\"urn:a\" xmlns:ids=\"urn:b\">ids:id2</alf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree);
lyd_free_tree(tree);
RESET_CTX(UTEST_LYCTX);
/* Even if a newer revision has been implemented, the old and
* unimplemented one will be used because it has already been
* imported. Therefore, if the user wants to use multiple revisions,
* he must choose one and implement it as soon as possible.
*/
str = "module a {namespace urn:a; prefix a;"
"revision \"2014-05-08\";"
"identity baseid;"
"leaf alf { type identityref { base baseid;}}"
"}";
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, str);
str = "module b {namespace urn:b; prefix b;"
"import a {prefix a;}"
"identity baseref { base a:baseid;}"
"identity id1 { base baseref;}"
"identity id2 { base baseref;}"
"}";
UTEST_ADD_MODULE(str, LYS_IN_YANG, NULL, NULL);
str = "module a {namespace urn:a; prefix a;"
"revision \"2015-05-08\";"
"identity baseid;"
"leaf alf { type identityref { base baseid;}}"
"}";
ly_log_level(LY_LLVRB);
UTEST_ADD_MODULE(str, LYS_IN_YANG, NULL, NULL);
CHECK_LOG_LASTMSG("Implemented module \"a@2015-05-08\" was not and will not "
"be imported if the revision-date is missing in the import "
"statement. Instead, the revision \"2014-05-08\" is imported.");
ly_log_level(LY_LLWRN);
/* Data is inserted only to implemented revision. */
data = "<alf xmlns=\"urn:a\" xmlns:ids=\"urn:b\">ids:id1</alf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
data = "<alf xmlns=\"urn:a\" xmlns:ids=\"urn:b\">ids:id2</alf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
assert_true(contains_derived_identity(UTEST_LYCTX, "a", "2014-05-08", "baseid", "baseref"));
assert_false(contains_derived_identity(UTEST_LYCTX, "a", "2015-05-08", "baseid", "baseref"));
RESET_CTX(UTEST_LYCTX);
/* Identity testing with if-features. */
/* The if-feature has no effect if the module is imported. */
str = "module a {yang-version 1.1; namespace urn:a; prefix a;"
"feature f;"
"identity baseid { if-feature \"f\";}"
"}";
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, str);
str = "module b {namespace urn:b; prefix b; import a { prefix a;}"
"identity id1 { base a:baseid;}"
"leaf lf { type identityref { base a:baseid;}}"
"}";
UTEST_ADD_MODULE(str, LYS_IN_YANG, NULL, NULL);
assert_true(contains_derived_identity(UTEST_LYCTX, "a", NULL, "baseid", "id1"));
data = "<lf xmlns=\"urn:b\">id1</lf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree);
lyd_free_tree(tree);
RESET_CTX(UTEST_LYCTX);
/* Even if the identity in the implemented module is disabled,
* it can be used as a base.
*/
str = "module a {yang-version 1.1; namespace urn:a; prefix a;"
"feature f;"
"identity baseid { if-feature \"f\";}"
"}";
UTEST_ADD_MODULE(str, LYS_IN_YANG, NULL, NULL);
str = "module b {namespace urn:b; prefix b; import a { prefix a;}"
"identity id1 { base a:baseid;}"
"leaf lf { type identityref { base a:baseid;}}"
"}";
UTEST_ADD_MODULE(str, LYS_IN_YANG, NULL, NULL);
assert_true(contains_derived_identity(UTEST_LYCTX, "a", NULL, "baseid", "id1"));
data = "<lf xmlns=\"urn:b\">id1</lf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree);
lyd_free_tree(tree);
RESET_CTX(UTEST_LYCTX);
/* Identity derivation cannot be instantiated if it is disabled.
* Conversely, if the identity is enabled, it can be instantiated.
*/
str = "module a {namespace urn:a; prefix a;"
"identity baseid;"
"}";
UTEST_ADD_MODULE(str, LYS_IN_YANG, NULL, NULL);
str = "module b {yang-version 1.1; namespace urn:b; prefix b; import a { prefix a;}"
"feature f2;"
"feature f3;"
"identity id1 { base a:baseid;}"
"identity id2 { if-feature \"f2\"; base a:baseid;}"
"identity id3 { if-feature \"f3\"; base a:baseid;}"
"leaf lf { type identityref { base a:baseid;}}"
"}";
feats[0] = "f2";
UTEST_ADD_MODULE(str, LYS_IN_YANG, feats, NULL);
assert_true(contains_derived_identity(UTEST_LYCTX, "a", NULL, "baseid", "id1"));
data = "<lf xmlns=\"urn:b\">id1</lf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree);
lyd_free_tree(tree);
assert_true(contains_derived_identity(UTEST_LYCTX, "a", NULL, "baseid", "id2"));
data = "<lf xmlns=\"urn:b\">id2</lf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree);
lyd_free_tree(tree);
assert_true(contains_derived_identity(UTEST_LYCTX, "a", NULL, "baseid", "id3"));
data = "<lf xmlns=\"urn:b\">id3</lf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
CHECK_LOG_CTX("Invalid identityref \"id3\" value - identity is disabled by if-feature.", "/b:lf", 1);
RESET_CTX(UTEST_LYCTX);
/* The derived identities are enabled and disabled in submodule. */
str = "submodule asub {yang-version 1.1; belongs-to a {prefix a;}"
"feature f2;"
"feature f3;"
"identity id1 { base a:baseid;}"
"identity id2 { if-feature \"f2\"; base a:baseid;}"
"identity id3 { if-feature \"f3\"; base a:baseid;}"
"}";
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, str);
str = "module a {namespace urn:a; prefix a; include asub;"
"identity baseid;"
"}";
feats[0] = "f2";
UTEST_ADD_MODULE(str, LYS_IN_YANG, feats, NULL);
str = "module b {yang-version 1.1; namespace urn:b; prefix b; import a { prefix a;}"
"leaf lf { type identityref { base a:baseid;}}"
"}";
UTEST_ADD_MODULE(str, LYS_IN_YANG, NULL, NULL);
assert_true(contains_derived_identity(UTEST_LYCTX, "a", NULL, "baseid", "id1"));
data = "<lf xmlns=\"urn:b\" xmlns:ids=\"urn:a\">ids:id1</lf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree);
lyd_free_tree(tree);
assert_true(contains_derived_identity(UTEST_LYCTX, "a", NULL, "baseid", "id2"));
data = "<lf xmlns=\"urn:b\" xmlns:ids=\"urn:a\">ids:id2</lf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree);
lyd_free_tree(tree);
assert_true(contains_derived_identity(UTEST_LYCTX, "a", NULL, "baseid", "id3"));
data = "<lf xmlns=\"urn:b\" xmlns:ids=\"urn:a\">ids:id3</lf>";
CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
CHECK_LOG_CTX("Invalid identityref \"ids:id3\" value - identity is disabled by if-feature.", "/b:lf", 1);
RESET_CTX(UTEST_LYCTX);
#undef RESET_CTX
}
static void
test_type_identityref(void **state)
{
struct lys_module *mod;
struct lysc_type *type;
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1;namespace urn:a;prefix a;identity i; identity j; identity k {base i;}"
"typedef mytype {type identityref {base i;}}"
"leaf l1 {type mytype;} leaf l2 {type identityref {base a:k; base j;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_IDENT, type->basetype);
assert_non_null(((struct lysc_type_identityref *)type)->bases);
assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_identityref *)type)->bases));
assert_string_equal("i", ((struct lysc_type_identityref *)type)->bases[0]->name);
type = ((struct lysc_node_leaf *)mod->compiled->data->next)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_IDENT, type->basetype);
assert_non_null(((struct lysc_type_identityref *)type)->bases);
assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_identityref *)type)->bases));
assert_string_equal("k", ((struct lysc_type_identityref *)type)->bases[0]->name);
assert_string_equal("j", ((struct lysc_type_identityref *)type)->bases[1]->name);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {yang-version 1.1;namespace urn:b;prefix b;import a {prefix a;}"
"leaf l {type identityref {base a:k; base a:j;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_IDENT, type->basetype);
assert_non_null(((struct lysc_type_identityref *)type)->bases);
assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_identityref *)type)->bases));
assert_string_equal("k", ((struct lysc_type_identityref *)type)->bases[0]->name);
assert_string_equal("j", ((struct lysc_type_identityref *)type)->bases[1]->name);
/* invalid cases */
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; leaf l {type identityref;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Missing base substatement for identityref type.", "/aa:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb; typedef mytype {type identityref;}"
"leaf l {type mytype;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Missing base substatement for identityref type mytype.", "/bb:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc; identity i; typedef mytype {type identityref {base i;}}"
"leaf l {type mytype {base i;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid base substatement for the type not directly derived from identityref built-in type.",
"/cc:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd; identity i; typedef mytype {type identityref {base i;}}"
"typedef mytype2 {type mytype {base i;}}leaf l {type mytype2;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid base substatement for the type \"mytype2\" not directly derived from identityref built-in type.",
"/dd:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee; identity i; identity j;"
"leaf l {type identityref {base i;base j;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Multiple bases in identityref type are allowed only in YANG 1.1 modules.", "/ee:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff; identity i;leaf l {type identityref {base j;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Unable to find base (j) of identityref.", "/ff:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg;leaf l {type identityref {base x:j;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid prefix used for base (x:j) of identityref.", "/gg:l", 0);
}
static void
test_type_leafref(void **state)
{
char *str;
struct lys_module *mod;
struct lysc_type *type;
const char *path;
struct lyxp_expr *expr;
/* lys_path_parse() */
path = "invalid_path";
assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), 1, LY_PATH_BEGIN_EITHER,
LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
CHECK_LOG_CTX("Unexpected XPath token \"NameTest\" (\"invalid_path\"), expected \"..\".", NULL, 0);
path = "..";
assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), 1, LY_PATH_BEGIN_EITHER,
LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
CHECK_LOG_CTX("Unexpected XPath expression end.", NULL, 0);
path = "..[";
assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), 1, LY_PATH_BEGIN_EITHER,
LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
CHECK_LOG_CTX("Unexpected XPath token \"[\" (\"[\"), expected \"Operator(Path)\".", NULL, 0);
path = "../";
assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), 1, LY_PATH_BEGIN_EITHER,
LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
CHECK_LOG_CTX("Unexpected XPath expression end.", NULL, 0);
path = "/";
assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), 1, LY_PATH_BEGIN_EITHER,
LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
CHECK_LOG_CTX("Unexpected XPath expression end.", NULL, 0);
path = "../../pref:id/xxx[predicate]/invalid!!!";
assert_int_equal(LY_EVALID, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), 1, LY_PATH_BEGIN_EITHER,
LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
CHECK_LOG_CTX("Invalid character 0x21 ('!'), perhaps \"invalid\" is supposed to be a function call.", NULL, 0);
path = "/absolute/prefix:path";
assert_int_equal(LY_SUCCESS, ly_path_parse(UTEST_LYCTX, NULL, path, strlen(path), 1, LY_PATH_BEGIN_EITHER,
LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &expr));
assert_int_equal(4, expr->used);
assert_int_equal(LYXP_TOKEN_OPER_PATH, expr->tokens[0]);
assert_int_equal(LYXP_TOKEN_NAMETEST, expr->tokens[1]);
assert_int_equal(LYXP_TOKEN_OPER_PATH, expr->tokens[2]);
assert_int_equal(LYXP_TOKEN_NAMETEST, expr->tokens[3]);
lyxp_expr_free(expr);
/* complete leafref paths */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1;namespace urn:a;prefix a;"
"leaf ref1 {type leafref {path /a:target1;}} leaf ref2 {type leafref {path /a/target2; require-instance false;}}"
"leaf target1 {type string;}container a {leaf target2 {type uint8;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
assert_string_equal("/a:target1", ((struct lysc_type_leafref *)type)->path->expr);
assert_ptr_equal(mod, ly_resolve_prefix(UTEST_LYCTX, "a", 1, LY_VALUE_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes));
assert_non_null(((struct lysc_type_leafref *)type)->realtype);
assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_leafref *)type)->realtype->basetype);
assert_int_equal(1, ((struct lysc_type_leafref *)type)->require_instance);
type = ((struct lysc_node_leaf *)mod->compiled->data->next)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
assert_string_equal("/a/target2", ((struct lysc_type_leafref *)type)->path->expr);
assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_leafref *)type)->prefixes));
assert_non_null(((struct lysc_type_leafref *)type)->realtype);
assert_int_equal(LY_TYPE_UINT8, ((struct lysc_type_leafref *)type)->realtype->basetype);
assert_int_equal(0, ((struct lysc_type_leafref *)type)->require_instance);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b; typedef mytype {type leafref {path /b:target;}}"
"typedef mytype2 {type mytype;} typedef mytype3 {type leafref {path /target;}} leaf ref {type mytype2;}"
"leaf target {type leafref {path ../realtarget;}} leaf realtarget {type string;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
assert_string_equal("/b:target", ((struct lysc_type_leafref *)type)->path->expr);
assert_ptr_equal(mod, ly_resolve_prefix(UTEST_LYCTX, "b", 1, LY_VALUE_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes));
assert_non_null(((struct lysc_type_leafref *)type)->realtype);
assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_leafref *)type)->realtype->basetype);
assert_int_equal(1, ((struct lysc_type_leafref *)type)->require_instance);
/* prefixes are reversed to check using correct context of the path! */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {yang-version 1.1;namespace urn:c;prefix b; import b {prefix c;}"
"typedef mytype3 {type c:mytype {require-instance false;}}"
"leaf ref1 {type b:mytype3;}leaf ref2 {type c:mytype2;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
assert_string_equal("/b:target", ((struct lysc_type_leafref *)type)->path->expr);
assert_ptr_not_equal(mod, ly_resolve_prefix(UTEST_LYCTX, "b", 1, LY_VALUE_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes));
assert_non_null(((struct lysc_type_leafref *)type)->realtype);
assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_leafref *)type)->realtype->basetype);
assert_int_equal(0, ((struct lysc_type_leafref *)type)->require_instance);
type = ((struct lysc_node_leaf *)mod->compiled->data->next)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
assert_string_equal("/b:target", ((struct lysc_type_leafref *)type)->path->expr);
assert_ptr_not_equal(mod, ly_resolve_prefix(UTEST_LYCTX, "b", 1, LY_VALUE_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes));
assert_int_equal(1, ((struct lysc_type_leafref *)type)->require_instance);
/* non-prefixed nodes in path are supposed to be from the module where the leafref type is instantiated */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d; import b {prefix b;}"
"leaf ref {type b:mytype3;}leaf target {type int8;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
assert_string_equal("/target", ((struct lysc_type_leafref *)type)->path->expr);
assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_leafref *)type)->prefixes));
assert_non_null(((struct lysc_type_leafref *)type)->realtype);
assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_leafref *)type)->realtype->basetype);
assert_int_equal(1, ((struct lysc_type_leafref *)type)->require_instance);
/* conditional leafrefs */
str = "module e {yang-version 1.1;namespace urn:e;prefix e;feature f1;"
"leaf ref1 {type leafref {path /target;}}"
"leaf target {if-feature 'f1'; type boolean;}}";
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Target of leafref \"ref1\" cannot be referenced because it is disabled.", "/e:ref1", 0);
CHECK_LOG_CTX("Not found node \"target\" in path.", "/e:ref1", 0);
str = "module en {yang-version 1.1;namespace urn:en;prefix en;feature f1;"
"leaf ref1 {if-feature 'f1'; type leafref {path /target;}}"
"leaf target {type boolean;}}";
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, &mod));
str = "module e {yang-version 1.1;namespace urn:e;prefix e;feature f1;"
"leaf ref1 {if-feature 'f1'; type leafref {path /target;}}}";
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, str, LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Not found node \"target\" in path.", "/e:ref1", 0);
ly_ctx_set_options(UTEST_LYCTX, LY_CTX_REF_IMPLEMENTED);
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module cl {namespace urn:cl;prefix cl;feature f1;"
"leaf f {type string; if-feature 'f1';}"
"leaf g {type leafref {path \"/cl:f\";}}"
"leaf h {type uint16; default 1;}}");
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module im {namespace urn:im;prefix im;import cl {prefix cl;}"
"leaf ref {must \"/cl:h > 0\"; type uint16;}}", LYS_IN_YANG, &mod));
ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_REF_IMPLEMENTED);
CHECK_LOG_CTX("Target of leafref \"g\" cannot be referenced because it is disabled.", "/cl:g", 0);
CHECK_LOG_CTX("Not found node \"f\" in path.", "/cl:g", 0);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {namespace urn:f;prefix f;"
"list interface{key name;leaf name{type string;}list address {key ip;leaf ip {type string;}}}"
"container default-address{leaf ifname{type leafref{ path \"../../interface/name\";}}"
"leaf address {type leafref{ path \"../../interface[ name = current()/../ifname ]/address/ip\";}}}}",
LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)(*lysc_node_child_p(mod->compiled->data->prev))->prev)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
assert_string_equal("../../interface[ name = current()/../ifname ]/address/ip",
((struct lysc_type_leafref *)type)->path->expr);
assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_leafref *)type)->prefixes));
assert_non_null(((struct lysc_type_leafref *)type)->realtype);
assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_leafref *)type)->realtype->basetype);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module g {namespace urn:g;prefix g;"
"leaf source {type leafref {path \"/endpoint-parent[id=current()/../field]/endpoint/name\";}}"
"leaf field {type int32;}list endpoint-parent {key id;leaf id {type int32;}"
"list endpoint {key name;leaf name {type string;}}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
assert_string_equal("/endpoint-parent[id=current()/../field]/endpoint/name", ((struct lysc_type_leafref *)type)->path->expr);
assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_type_leafref *)type)->prefixes));
assert_non_null(((struct lysc_type_leafref *)type)->realtype);
assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_leafref *)type)->realtype->basetype);
/* leafref to imported (not yet implemented) module */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module h-imp {namespace urn:h-imp;prefix h-imp;"
"leaf l {type string;}}", LYS_IN_YANG, NULL));
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module h {namespace urn:h;prefix h;import h-imp {prefix hi;}"
"leaf h {type uint16;}}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module i {namespace urn:i;prefix i;import h {prefix h;}"
"leaf i {type leafref {path /h:h;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
assert_non_null(((struct lysc_type_leafref *)type)->realtype);
assert_int_equal(LY_TYPE_UINT16, ((struct lysc_type_leafref *)type)->realtype->basetype);
assert_non_null(mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "h"));
assert_int_equal(1, mod->implemented);
assert_non_null(mod->compiled->data);
assert_string_equal("h", mod->compiled->data->name);
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module j {namespace urn:j;prefix j; leaf j {type string;}}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module k {namespace urn:k;prefix k;import j {prefix j;}"
"leaf i {type leafref {path \"/ilist[name = current()/../j:j]/value\";}}"
"list ilist {key name; leaf name {type string;} leaf value {type uint16;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
assert_non_null(((struct lysc_type_leafref *)type)->realtype);
assert_int_equal(LY_TYPE_UINT16, ((struct lysc_type_leafref *)type)->realtype->basetype);
assert_non_null(mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "j"));
assert_int_equal(1, mod->implemented);
assert_non_null(mod->compiled->data);
assert_string_equal("j", mod->compiled->data->name);
/* leafref with a default value */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module l {namespace urn:l;prefix l;"
"leaf source {type leafref {path \"../target\";}default true;}"
"leaf target {type boolean;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
assert_int_equal(LY_TYPE_LEAFREF, type->basetype);
assert_string_equal("../target", ((struct lysc_type_leafref *)type)->path->expr);
assert_non_null(((struct lysc_type_leafref *)type)->realtype);
assert_int_equal(LY_TYPE_BOOL, ((struct lysc_type_leafref *)type)->realtype->basetype);
assert_non_null(((struct lysc_node_leaf *)mod->compiled->data)->dflt.str);
assert_string_equal(((struct lysc_node_leaf *)mod->compiled->data)->dflt.str, "true");
/* union reference */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module m {namespace urn:m;prefix m;"
"typedef s-ref {type union {type leafref {path '/str';}}}"
"leaf str {type string {length \"1..16\" {error-message \"Custom message\";}}}"
"leaf ref1 {type s-ref;}"
"leaf ref2 {type s-ref;}}", LYS_IN_YANG, NULL));
/* invalid paths */
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;container a {leaf target2 {type uint8;}}"
"leaf ref1 {type leafref {path ../a/invalid;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Not found node \"invalid\" in path.", "/aa:ref1", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;container a {leaf target2 {type uint8;}}"
"leaf ref1 {type leafref {path ../../toohigh;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Too many parent references in path.", "/bb:ref1", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc;container a {leaf target2 {type uint8;}}"
"leaf ref1 {type leafref {path /a:invalid;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("No module connected with the prefix \"a\" found (prefix format schema stored mapping).", "/cc:ref1", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd;leaf target1 {type string;}"
"container a {leaf target2 {type uint8;}} leaf ref1 {type leafref {"
"path '/a[target2 = current()/../target1]/target2';}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("List predicate defined for container \"a\" in path.", "/dd:ref1", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;\n container a {leaf target2 {type uint8;}}\n"
"leaf ref1 {type leafref {path /a!invalid;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Parsing module \"ee\" failed.", NULL, 0);
CHECK_LOG_CTX("Invalid character 0x21 ('!'), perhaps \"a\" is supposed to be a function call.", NULL, 3);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff;container a {leaf target2 {type uint8;}}"
"leaf ref1 {type leafref {path /a;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid leafref path \"/a\" - target node is container instead of leaf or leaf-list.", "/ff:ref1", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg;container a {leaf target2 {type uint8;"
"status deprecated;}} leaf ref1 {type leafref {path /a/target2;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("A current definition \"ref1\" is not allowed to reference deprecated definition \"target2\".",
"/gg:ref1", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:hh;prefix hh;"
"leaf ref1 {type leafref;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Missing path substatement for leafref type.", "/hh:ref1", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii {namespace urn:ii;prefix ii;typedef mytype {type leafref;}"
"leaf ref1 {type mytype;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Missing path substatement for leafref type mytype.", "/ii:ref1", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk {namespace urn:kk;prefix kk;"
"leaf ref {type leafref {path /target;}}leaf target {type string;config false;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid leafref path \"/target\" - target is supposed to represent configuration data (as the leafref does), but it does not.",
"/kk:ref", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ll {namespace urn:ll;prefix ll;"
"leaf ref {type leafref {path /target; require-instance true;}}leaf target {type string;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Leafref type can be restricted by require-instance statement only in YANG 1.1 modules.",
"/ll:ref", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm {namespace urn:mm;prefix mm;typedef mytype {type leafref {path /target;require-instance false;}}"
"leaf ref {type mytype;}leaf target {type string;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Leafref type \"mytype\" can be restricted by require-instance statement only in YANG 1.1 modules.",
"/mm:ref", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module nn {namespace urn:nn;prefix nn;\n"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}\n"
"leaf ifname{type leafref{ path \"../interface/name\";}}\n"
"leaf address {type leafref{\n path \"/interface[name is current()/../ifname]/ip\";}}}",
LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Parsing module \"nn\" failed.", NULL, 0);
CHECK_LOG_CTX("Invalid character 0x69 ('i'), perhaps \"name\" is supposed to be a function call.", NULL, 5);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module oo {namespace urn:oo;prefix oo;\n"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}\n"
"leaf ifname{type leafref{ path \"../interface/name\";}}\n"
"leaf address {type leafref{\n path \"/interface[name=current()/../ifname/ip\";}}}",
LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Parsing module \"oo\" failed.", NULL, 0);
CHECK_LOG_CTX("Unexpected XPath expression end.", NULL, 5);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module pp {namespace urn:pp;prefix pp;"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}"
"leaf ifname{type leafref{ path \"../interface/name\";}}"
"leaf address {type leafref{ path \"/interface[x:name=current()/../ifname]/ip\";}}}",
LYS_IN_YANG, &mod));
CHECK_LOG_CTX("No module connected with the prefix \"x\" found (prefix format schema stored mapping).", "/pp:address", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module qq {namespace urn:qq;prefix qq;"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}"
"leaf ifname{type leafref{ path \"../interface/name\";}}"
"leaf address {type leafref{ path \"/interface[id=current()/../ifname]/ip\";}}}",
LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Not found node \"id\" in path.", "/qq:address", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module rr {namespace urn:rr;prefix rr;\n"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}\n"
"leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}\n"
"leaf address {type leafref{ path \"/interface[name=current() / .. / ifname][name=current()/../test]/ip\";}}}",
LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Parsing module \"rr\" failed.", NULL, 0);
CHECK_LOG_CTX("Duplicate predicate key \"name\" in path.", NULL, 4);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ss {namespace urn:ss;prefix ss;\n"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}\n"
"leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}\n"
"leaf address {type leafref{ path \"/interface[name = ../ifname]/ip\";}}}",
LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Parsing module \"ss\" failed.", NULL, 0);
CHECK_LOG_CTX("Unexpected XPath token \"..\" (\"../ifname]/ip\"), expected \"FunctionName\".", NULL, 4);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module tt {namespace urn:tt;prefix tt;\n"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}\n"
"leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}\n"
"leaf address {type leafref{ path \"/interface[name = current()../ifname]/ip\";}}}",
LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Parsing module \"tt\" failed.", NULL, 0);
CHECK_LOG_CTX("Unexpected XPath token \"..\" (\"../ifname]/ip\"), expected \"Operator(Path)\".", NULL, 4);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module uu {namespace urn:uu;prefix uu;\n"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}\n"
"leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}\n"
"leaf address {type leafref{ path \"/interface[name = current()/..ifname]/ip\";}}}",
LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Parsing module \"uu\" failed.", NULL, 0);
CHECK_LOG_CTX("Invalid character 'i'[31] of expression '/interface[name = current()/..ifname]/ip'.", NULL, 4);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module vv {namespace urn:vv;prefix vv;\n"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}\n"
"leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}\n"
"leaf address {type leafref{ path \"/interface[name = current()/ifname]/ip\";}}}",
LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Parsing module \"vv\" failed.", NULL, 0);
CHECK_LOG_CTX("Unexpected XPath token \"NameTest\" (\"ifname]/ip\"), expected \"..\".", NULL, 4);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ww {namespace urn:ww;prefix ww;\n"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}\n"
"leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}\n"
"leaf address {type leafref{ path \"/interface[name = current()/../]/ip\";}}}",
LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Parsing module \"ww\" failed.", NULL, 0);
CHECK_LOG_CTX("Unexpected XPath token \"]\" (\"]/ip\"), expected \"NameTest\".", NULL, 4);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module xx {namespace urn:xx;prefix xx;\n"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}\n"
"leaf ifname{type leafref{ path \"../interface/name\";}}leaf test{type string;}\n"
"leaf address {type leafref{ path \"/interface[name = current()/../#node]/ip\";}}}",
LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Parsing module \"xx\" failed.", NULL, 0);
CHECK_LOG_CTX("Invalid character '#'[32] of expression '/interface[name = current()/../#node]/ip'.", NULL, 4);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module yy {namespace urn:yy;prefix yy;\n"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}\n"
"leaf ifname{type leafref{ path \"../interface/name\";}}\n"
"leaf address {type leafref{ path \"/interface[name=current()/../x:ifname]/ip\";}}}",
LYS_IN_YANG, &mod));
CHECK_LOG_CTX("No module connected with the prefix \"x\" found (prefix format schema stored mapping).", "/yy:address", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module zz {namespace urn:zz;prefix zz;\n"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}\n"
"leaf ifname{type leafref{ path \"../interface/name\";}}\n"
"leaf address {type leafref{ path \"/interface[name=current()/../xxx]/ip\";}}}",
LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Not found node \"xxx\" in path.", "/zz:address", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module zza {namespace urn:zza;prefix zza;\n"
"list interface{key name;leaf name{type string;}leaf ip {type string;}}\n"
"leaf ifname{type leafref{ path \"../interface/name\";}}container c;\n"
"leaf address {type leafref{ path \"/interface[name=current()/../c]/ip\";}}}",
LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Leaf expected instead of container \"c\" in leafref predicate in path.", "/zza:address", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module zzb {namespace urn:zzb;prefix zzb;\n"
"list interface{key name;leaf name{type string;}leaf ip {type string;}container c;}\n"
"leaf ifname{type leafref{ path \"../interface/name\";}}\n"
"leaf address {type leafref{ path \"/interface[c=current()/../ifname]/ip\";}}}",
LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Key expected instead of container \"c\" in path.", "/zzb:address", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module zzc {namespace urn:zzc;prefix zzc;\n"
"leaf source {type leafref {path \"../target\";}default true;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Not found node \"target\" in path.", "/zzc:source", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module zzd {namespace urn:zzd;prefix zzd;\n"
"leaf source {type leafref {path \"../target\";}default true;}\n"
"leaf target {type uint8;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid default - value does not fit the type (Invalid type uint8 value \"true\".).", "/zzd:source", 0);
/* circular chain */
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aaa {namespace urn:aaa;prefix aaa;\n"
"leaf ref1 {type leafref {path /ref2;}}\n"
"leaf ref2 {type leafref {path /ref3;}}\n"
"leaf ref3 {type leafref {path /ref4;}}\n"
"leaf ref4 {type leafref {path /ref1;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid leafref path \"/ref1\" - circular chain of leafrefs detected.", "/aaa:ref4", 0);
}
static void
test_type_empty(void **state)
{
/* invalid */
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;"
"leaf l {type empty; default x;}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid default - value does not fit the type (Invalid empty value size 8 b.).", "/aa:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;typedef mytype {type empty; default x;}"
"leaf l {type mytype;}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Invalid type \"mytype\" - \"empty\" type must not have a default value (x).", "/bb:l", 0);
}
static void
test_type_union(void **state)
{
struct lys_module *mod;
struct lysc_type *type;
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {yang-version 1.1;namespace urn:a;prefix a; typedef mybasetype {type string;}"
"typedef mytype {type union {type int8; type mybasetype;}}"
"leaf l {type mytype;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(2, type->refcount);
assert_int_equal(LY_TYPE_UNION, type->basetype);
assert_non_null(((struct lysc_type_union *)type)->types);
assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_union *)type)->types));
assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_union *)type)->types[0]->basetype);
assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_union *)type)->types[1]->basetype);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {yang-version 1.1;namespace urn:b;prefix b; typedef mybasetype {type string;}"
"typedef mytype {type union {type int8; type mybasetype;}}"
"leaf l {type union {type decimal64 {fraction-digits 2;} type mytype;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
assert_int_equal(LY_TYPE_UNION, type->basetype);
assert_non_null(((struct lysc_type_union *)type)->types);
assert_int_equal(3, LY_ARRAY_COUNT(((struct lysc_type_union *)type)->types));
assert_int_equal(LY_TYPE_DEC64, ((struct lysc_type_union *)type)->types[0]->basetype);
assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_union *)type)->types[1]->basetype);
assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_union *)type)->types[2]->basetype);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {yang-version 1.1;namespace urn:c;prefix c; typedef mybasetype {type string;}"
"typedef mytype {type union {type leafref {path ../target;} type mybasetype;}}"
"leaf l {type union {type decimal64 {fraction-digits 2;} type mytype;}}"
"leaf target {type leafref {path ../realtarget;}} leaf realtarget {type int8;}}",
LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
assert_int_equal(LY_TYPE_UNION, type->basetype);
assert_non_null(((struct lysc_type_union *)type)->types);
assert_int_equal(3, LY_ARRAY_COUNT(((struct lysc_type_union *)type)->types));
assert_int_equal(LY_TYPE_DEC64, ((struct lysc_type_union *)type)->types[0]->basetype);
assert_int_equal(LY_TYPE_LEAFREF, ((struct lysc_type_union *)type)->types[1]->basetype);
assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_union *)type)->types[2]->basetype);
assert_non_null(((struct lysc_type_leafref *)((struct lysc_type_union *)type)->types[1])->realtype);
assert_int_equal(LY_TYPE_INT8, ((struct lysc_type_leafref *)((struct lysc_type_union *)type)->types[1])->realtype->basetype);
/* invalid unions */
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;typedef mytype {type union;}"
"leaf l {type mytype;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Missing type substatement for union type mytype.", "/aa:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;leaf l {type union;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Missing type substatement for union type.", "/bb:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc;typedef mytype {type union{type int8; type string;}}"
"leaf l {type mytype {type string;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid type substatement for the type not directly derived from union built-in type.", "/cc:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd;typedef mytype {type union{type int8; type string;}}"
"typedef mytype2 {type mytype {type string;}}leaf l {type mytype2;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid type substatement for the type \"mytype2\" not directly derived from union built-in type.",
"/dd:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;typedef mytype {type union{type mytype; type string;}}"
"leaf l {type mytype;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid \"mytype\" type reference - circular chain of types detected.", "/ee:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ef {namespace urn:ef;prefix ef;typedef mytype {type mytype2;}"
"typedef mytype2 {type mytype;} leaf l {type mytype;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid \"mytype\" type reference - circular chain of types detected.", "/ef:l", 0);
}
static void
test_type_dflt(void **state)
{
struct lys_module *mod;
struct lysc_type *type;
struct lysc_node_leaf *leaf;
/* default is not inherited from union's types */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a; typedef mybasetype {type string;default hello;units xxx;}"
"leaf l {type union {type decimal64 {fraction-digits 2;} type mybasetype;}}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(1, type->refcount);
assert_int_equal(LY_TYPE_UNION, type->basetype);
assert_non_null(((struct lysc_type_union *)type)->types);
assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_type_union *)type)->types));
assert_int_equal(LY_TYPE_DEC64, ((struct lysc_type_union *)type)->types[0]->basetype);
assert_int_equal(LY_TYPE_STRING, ((struct lysc_type_union *)type)->types[1]->basetype);
assert_null(((struct lysc_node_leaf *)mod->compiled->data)->dflt.str);
assert_null(((struct lysc_node_leaf *)mod->compiled->data)->units);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b; typedef mybasetype {type string;default hello;units xxx;}"
"leaf l {type mybasetype;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_STRING, type->basetype);
assert_non_null(leaf = (struct lysc_node_leaf *)mod->compiled->data);
assert_string_equal("hello", leaf->dflt.str);
assert_string_equal("xxx", leaf->units);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c; typedef mybasetype {type string;default hello;units xxx;}"
"leaf l {type mybasetype; default goodbye;units yyy;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_STRING, type->basetype);
leaf = (struct lysc_node_leaf *)mod->compiled->data;
assert_string_equal("goodbye", leaf->dflt.str);
assert_string_equal("yyy", leaf->units);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d; typedef mybasetype {type string;default hello;units xxx;}"
"typedef mytype {type mybasetype;}leaf l1 {type mytype; default goodbye;units yyy;}"
"leaf l2 {type mytype;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_STRING, type->basetype);
leaf = (struct lysc_node_leaf *)mod->compiled->data;
assert_string_equal("goodbye", leaf->dflt.str);
assert_string_equal("yyy", leaf->units);
type = ((struct lysc_node_leaf *)mod->compiled->data->next)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_STRING, type->basetype);
leaf = (struct lysc_node_leaf *)mod->compiled->data->next;
assert_string_equal("hello", leaf->dflt.str);
assert_string_equal("xxx", leaf->units);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {namespace urn:e;prefix e; typedef mybasetype {type string;}"
"typedef mytype {type mybasetype; default hello;units xxx;}leaf l {type mytype;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_STRING, type->basetype);
leaf = (struct lysc_node_leaf *)mod->compiled->data;
assert_string_equal("hello", leaf->dflt.str);
assert_string_equal("xxx", leaf->units);
/* mandatory leaf does not takes default value from type */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {namespace urn:f;prefix f;typedef mytype {type string; default hello;units xxx;}"
"leaf l {type mytype; mandatory true;}}", LYS_IN_YANG, &mod));
type = ((struct lysc_node_leaf *)mod->compiled->data)->type;
assert_non_null(type);
assert_int_equal(LY_TYPE_STRING, type->basetype);
assert_null(((struct lysc_node_leaf *)mod->compiled->data)->dflt.str);
assert_string_equal("xxx", ((struct lysc_node_leaf *)mod->compiled->data)->units);
}
static void
test_type_exts(void **state)
{
const char *schema1, *schema2, *schema3, *schema4;
struct lys_module *mod;
const struct lysc_node *snode;
struct lysc_type *type;
struct lysc_type_union *type_u;
schema1 = "module my-extensions {\n"
" namespace \"urn:my-extensions\";\n"
" prefix my-ext;\n"
"\n"
" extension shortdesc {\n"
" argument shortdsc;\n"
" }\n"
"}\n";
schema2 = "module module-inet {\n"
" yang-version 1.1;\n"
" namespace \"urn:module-inet\";\n"
" prefix mod-inet;\n"
"\n"
" import ietf-inet-types {\n"
" prefix inet;\n"
" }\n"
"\n"
" import my-extensions {\n"
" prefix my-ext;\n"
" }\n"
"\n"
" typedef domain-name {\n"
" type inet:domain-name {\n"
" my-ext:shortdesc \"<host-name>\";\n"
" }\n"
" }\n"
"\n"
" typedef ipv4-address {\n"
" type inet:ipv4-address-no-zone {\n"
" my-ext:shortdesc \"<A.B.C.D>\";\n"
" }\n"
" }\n"
" typedef my-enum {\n"
" type enumeration {\n"
" enum one;\n"
" enum two;\n"
" enum three;\n"
" }\n"
" }\n"
"}\n";
schema3 = "module module-a {\n"
" yang-version 1.1;\n"
" namespace \"urn:module-a\";\n"
" prefix mod-a;\n"
"\n"
" import module-inet {\n"
" prefix mod-inet;\n"
" }\n"
"\n"
" import my-extensions {\n"
" prefix my-ext;\n"
" }\n"
"\n"
" typedef server-address {\n"
" type union {\n"
" type mod-inet:ipv4-address {\n"
" my-ext:shortdesc \"<ipv4-address>\";\n"
" }\n"
" type mod-inet:domain-name {\n"
" my-ext:shortdesc \"<fqdn>\";\n"
" }\n"
" }\n"
" }\n"
"}\n";
schema4 = "module main-module {\n"
" yang-version 1.1;\n"
" namespace \"urn:main-module\";\n"
" prefix main;\n"
"\n"
" import module-a {\n"
" prefix mod-a;\n"
" }\n"
"\n"
" import module-inet {\n"
" prefix mod-inet;\n"
" }\n"
"\n"
" import my-extensions {\n"
" prefix my-ext;\n"
" }\n"
"\n"
" container config {\n"
" leaf server {\n"
" type mod-a:server-address {\n"
" my-ext:shortdesc \"<server-address>\";\n"
" }\n"
" }\n"
"\n"
" leaf hostname {\n"
" type union {\n"
" type mod-inet:domain-name;\n"
" type string;\n"
" }\n"
" }\n"
" }\n"
"\n"
" leaf my-leaf {\n"
" type mod-inet:my-enum {\n"
" my-ext:shortdesc \"my enum\";\n"
" }\n"
" }\n"
"}\n";
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, schema1, LYS_IN_YANG, NULL));
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, schema2, LYS_IN_YANG, NULL));
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, schema3, LYS_IN_YANG, NULL));
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, schema4, LYS_IN_YANG, &mod));
/* server */
snode = lys_find_path(UTEST_LYCTX, NULL, "/main-module:config/server", 0);
assert_non_null(snode);
type = ((struct lysc_node_leaf *)snode)->type;
assert_int_equal(LY_ARRAY_COUNT(type->exts), 1);
assert_string_equal(type->exts[0].argument, "<server-address>");
type_u = (struct lysc_type_union *)type;
assert_int_equal(LY_ARRAY_COUNT(type_u->types), 2);
type = type_u->types[0];
assert_int_equal(LY_ARRAY_COUNT(type->exts), 2);
assert_string_equal(type->exts[0].argument, "<A.B.C.D>");
assert_string_equal(type->exts[1].argument, "<ipv4-address>");
type = type_u->types[1];
assert_int_equal(LY_ARRAY_COUNT(type->exts), 2);
assert_string_equal(type->exts[0].argument, "<host-name>");
assert_string_equal(type->exts[1].argument, "<fqdn>");
/* hostname */
snode = lys_find_path(UTEST_LYCTX, NULL, "/main-module:config/hostname", 0);
assert_non_null(snode);
type = ((struct lysc_node_leaf *)snode)->type;
assert_int_equal(LY_ARRAY_COUNT(type->exts), 0);
type_u = (struct lysc_type_union *)type;
assert_int_equal(LY_ARRAY_COUNT(type_u->types), 2);
type = type_u->types[0];
assert_int_equal(LY_ARRAY_COUNT(type->exts), 1);
assert_string_equal(type->exts[0].argument, "<host-name>");
type = type_u->types[1];
assert_int_equal(LY_ARRAY_COUNT(type->exts), 0);
}
static void
test_status(void **state)
{
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;"
"container c {status deprecated; leaf l {status current; type string;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Status \"current\" of \"l\" is in conflict with \"deprecated\" status of parent \"c\".", "/aa:c/l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;"
"container c {status obsolete; leaf l {status current; type string;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Status \"current\" of \"l\" is in conflict with \"obsolete\" status of parent \"c\".", "/bb:c/l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc;"
"container c {status obsolete; leaf l {status deprecated; type string;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Status \"deprecated\" of \"l\" is in conflict with \"obsolete\" status of parent \"c\".", "/cc:c/l", 0);
/* just a warning */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:dd;prefix d;"
"container c {leaf l {status obsolete; type string;}}"
"container d {leaf m {when \"../../c/l\"; type string;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("When condition \"../../c/l\" may be referencing deprecated node \"l\".", NULL, 0);
}
static void
test_grouping(void **state)
{
/* result ok, but a warning about not used locally scoped grouping printed */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a; grouping grp1 {leaf a1 {type string;}}"
"container a {leaf x {type string;} grouping grp2 {leaf a2 {type string;}}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Locally scoped grouping \"grp2\" not used.", NULL, 0);
/* result ok - when statement or leafref target must be checked only at the place where the grouping is really instantiated */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b; grouping grp {"
"leaf ref {type leafref {path \"../name\";}}"
"leaf cond {type string; when \"../name = 'specialone'\";}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX(NULL, NULL, 0);
/* invalid - error in a non-instantiated grouping */
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;"
"grouping grp {leaf x {type leafref;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Missing path substatement for leafref type.", "/aa:{grouping='grp'}/x", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;"
"container a {grouping grp {leaf x {type leafref;}}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Missing path substatement for leafref type.", "/aa:a/{grouping='grp'}/x", 0);
CHECK_LOG_CTX("Locally scoped grouping \"grp\" not used.", NULL, 0);
/* config check */
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module z1 {namespace urn:z1;prefix z1;"
"container root;}\n"
"module z2 {namespace urn:z2;prefix z2;"
"grouping leafs_group {"
" leaf name {type string; config true;}"
" leaf value {type uint32; config true;}"
"}}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module z3 {namespace urn:z3;prefix z3;"
"import z1 {prefix z1;} import z2 {prefix z2;}"
"grouping grp_a_top {leaf a1 {type int8;}}"
"grouping list_group {"
" list mylist {key \"name\"; unique \"value\"; uses z2:leafs_group;}"
"}"
"augment /z1:root { uses list_group;} }", LYS_IN_YANG, NULL));
/* identity */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module y1 {namespace urn:y1;prefix y1;"
"identity base_identity;"
"identity id1 {base \"base_identity\";}"
"grouping attrs_group {"
" leaf name {type identityref {base \"base_identity\";} default \"id1\";}"
"}}", LYS_IN_YANG, NULL));
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module y2 {namespace urn:y2;prefix y2;"
"import y1 {prefix y1;}"
"container root {uses y1:attrs_group;}}", LYS_IN_YANG, NULL));
}
static void
test_uses(void **state)
{
struct lys_module *mod;
const struct lysc_node *parent, *child;
const struct lysc_node_container *cont;
const struct lysc_node_leaf *leaf;
const struct lysc_node_choice *choice;
const struct lysc_node_case *cs;
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module grp {namespace urn:grp;prefix g; typedef mytype {type string;} feature f;"
"grouping grp {leaf x {type mytype;} leaf y {type string; if-feature f;}}}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a {namespace urn:a;prefix a;import grp {prefix g;}"
"grouping grp_a_top {leaf a1 {type int8;}}"
"container a {uses grp_a; uses grp_a_top; uses g:grp; grouping grp_a {leaf a2 {type uint8;}}}}", LYS_IN_YANG, &mod));
assert_non_null((parent = mod->compiled->data));
assert_int_equal(LYS_CONTAINER, parent->nodetype);
assert_non_null((child = ((struct lysc_node_container *)parent)->child));
assert_string_equal("a2", child->name);
assert_ptr_equal(mod, child->module);
assert_non_null((child = child->next));
assert_string_equal("a1", child->name);
assert_ptr_equal(mod, child->module);
assert_non_null((child = child->next));
assert_string_equal("x", child->name);
assert_ptr_equal(mod, child->module);
assert_null((child = child->next));
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule bsub {belongs-to b {prefix b;} grouping grp {leaf b {when 1; type string;} leaf c {type string;}}}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;include bsub;uses grp {when 2;}}", LYS_IN_YANG, &mod));
assert_non_null(mod->compiled->data);
leaf = (struct lysc_node_leaf *)mod->compiled->data;
assert_int_equal(LYS_LEAF, leaf->nodetype);
assert_string_equal("b", leaf->name);
assert_int_equal(2, LY_ARRAY_COUNT(leaf->when));
assert_int_equal(1, leaf->when[0]->refcount);
assert_non_null(leaf->when[0]->context);
assert_string_equal("b", leaf->when[0]->context->name);
assert_int_equal(2, leaf->when[1]->refcount);
assert_null(leaf->when[1]->context);
leaf = (struct lysc_node_leaf *)leaf->next;
assert_int_equal(LYS_LEAF, leaf->nodetype);
assert_string_equal("c", leaf->name);
assert_int_equal(1, LY_ARRAY_COUNT(leaf->when));
assert_int_equal(2, leaf->when[0]->refcount);
assert_null(leaf->when[0]->context);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c;"
"grouping grp {leaf l {type string;}leaf k {type string;}}"
"uses grp {status deprecated;}}", LYS_IN_YANG, &mod));
assert_int_equal(LYS_LEAF, mod->compiled->data->nodetype);
assert_string_equal("l", mod->compiled->data->name);
assert_true(LYS_STATUS_DEPRC & mod->compiled->data->flags);
assert_int_equal(LYS_LEAF, mod->compiled->data->next->nodetype);
assert_string_equal("k", mod->compiled->data->next->name);
CHECK_LOG_CTX(NULL, NULL, 0); /* no warning about inheriting deprecated flag from uses */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d; grouping grp {container g;}"
"container top {uses grp {augment g {leaf x {type int8;}}}}}", LYS_IN_YANG, &mod));
assert_non_null(mod->compiled->data);
assert_non_null(child = lysc_node_child(mod->compiled->data));
assert_string_equal("g", child->name);
assert_non_null(child = lysc_node_child(child));
assert_string_equal("x", child->name);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {yang-version 1.1;namespace urn:e;prefix e; grouping grp {action g { description \"super g\";}}"
"container top {action e; uses grp {refine g {description \"ultra g\";}}}}", LYS_IN_YANG, &mod));
assert_non_null(mod->compiled->data);
cont = (const struct lysc_node_container *)mod->compiled->data;
assert_non_null(cont->actions);
assert_non_null(cont->actions->next);
assert_null(cont->actions->next->next);
assert_string_equal("e", cont->actions->next->name);
assert_string_equal("g", cont->actions->name);
assert_string_equal("ultra g", cont->actions->dsc);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {yang-version 1.1;namespace urn:f;prefix f; grouping grp {notification g { description \"super g\";}}"
"container top {notification f; uses grp {refine g {description \"ultra g\";}}}}", LYS_IN_YANG, &mod));
assert_non_null(mod->compiled->data);
cont = (const struct lysc_node_container *)mod->compiled->data;
assert_non_null(cont->notifs);
assert_non_null(cont->notifs->next);
assert_null(cont->notifs->next->next);
assert_string_equal("f", cont->notifs->next->name);
assert_string_equal("g", cont->notifs->name);
assert_string_equal("ultra g", cont->notifs->dsc);
/* empty grouping */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module g {namespace urn:g;prefix g; grouping grp; uses grp;}", LYS_IN_YANG, &mod));
assert_null(mod->compiled->data);
/* choice in uses */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module h {yang-version 1.1;namespace urn:h;prefix h; grouping grp {choice gch {case gc1 { leaf y { type string;}} case gc2 {leaf z {type string;}}}}"
"choice ch {case one { leaf x {type string;}} case two { uses grp;}}}", LYS_IN_YANG, &mod));
assert_non_null(mod->compiled->data);
choice = (const struct lysc_node_choice *)mod->compiled->data;
assert_string_equal("ch", choice->name);
cs = choice->cases;
assert_non_null(cs);
assert_string_equal("one", cs->name);
assert_non_null(cs->child);
assert_string_equal("x", cs->child->name);
cs = (struct lysc_node_case *)cs->next;
assert_non_null(cs);
assert_string_equal("two", cs->name);
assert_non_null(cs->child);
assert_string_equal("gch", cs->child->name);
/* top-level uses with augment and refine */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module i {namespace urn:i;prefix i; grouping grp {container g;}"
"uses grp {augment g {leaf x {type int8;}} refine g {description \"dsc\";}}}",
LYS_IN_YANG, &mod));
assert_non_null(mod->compiled->data);
child = mod->compiled->data;
assert_string_equal("g", child->name);
cont = (const struct lysc_node_container *)child;
assert_string_equal("dsc", cont->dsc);
assert_non_null(child = lysc_node_child(child));
assert_string_equal("x", child->name);
/* unique */
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module j {namespace urn:j;prefix j;"
"grouping grp {list l {key \"k\"; unique \"l\"; leaf k {type string;} leaf l {type string;}}}}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module k {namespace urn:k;prefix k;import j {prefix j;}"
"container a {uses j:grp;}}", LYS_IN_YANG, NULL));
/* if-features */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module l {namespace urn:l;prefix l;"
"feature f;"
"grouping grp {container g; leaf l{type string;}}"
"uses grp {if-feature f;}}",
LYS_IN_YANG, &mod));
assert_null(mod->compiled->data);
/* invalid */
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;uses missinggrp;}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Grouping \"missinggrp\" referenced by a uses statement not found.", "/aa:{uses='missinggrp'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;uses grp;"
"grouping grp {leaf a{type string;}uses grp1;}"
"grouping grp1 {leaf b {type string;}uses grp2;}"
"grouping grp2 {leaf c {type string;}uses grp;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Grouping \"grp\" references itself through a uses statement.",
"/bb:{uses='grp'}/{uses='grp1'}/{uses='grp2'}/{uses='grp'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc;uses a:missingprefix;}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid prefix used for grouping \"a:missingprefix\" reference.", "/cc:{uses='a:missingprefix'}", 0);
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd;grouping grp{leaf a{type string;}}"
"leaf a {type string;}uses grp;}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Duplicate identifier \"/dd:a\" of data definition/RPC/action/notification statement.",
"/dd:{uses='grp'}/dd:a", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;grouping grp {leaf l {type string; status deprecated;}}"
"uses grp {status obsolete;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Inherited schema-only status \"obsolete\" is in conflict with \"deprecated\" status of \"l\".",
"/ee:{uses='grp'}/ee:l", 0);
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff;grouping grp {leaf l {type string;}}"
"leaf l {type int8;}uses grp;}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Duplicate identifier \"/ff:l\" of data definition/RPC/action/notification statement.",
"/ff:{uses='grp'}/ff:l", 0);
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module fg {namespace urn:fg;prefix fg;grouping grp {leaf m {type string;}}"
"uses grp;leaf m {type int8;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Duplicate identifier \"/fg:m\" of data definition/RPC/action/notification statement.", "/fg:m", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg; grouping grp {container g;}"
"leaf g {type string;}"
"container top {uses grp {augment /g {leaf x {type int8;}}}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid descendant-schema-nodeid value \"/g\" - name test expected instead of \"/\".",
"/gg:top/{uses='grp'}/{augment='/g'}", 0);
assert_int_equal(LY_ENOTFOUND, lys_parse_mem(UTEST_LYCTX, "module hh {yang-version 1.1;namespace urn:hh;prefix hh;"
"grouping grp {notification g { description \"super g\";}}"
"container top {notification h; uses grp {refine h {description \"ultra h\";}}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Refine(s) target node \"h\" in grouping \"grp\" was not found.", "/hh:top/{uses='grp'}", 0);
assert_int_equal(LY_ENOTFOUND, lys_parse_mem(UTEST_LYCTX, "module ii {yang-version 1.1;namespace urn:ii;prefix ii;"
"grouping grp {action g { description \"super g\";}}"
"container top {action i; uses grp {refine i {description \"ultra i\";}}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Refine(s) target node \"i\" in grouping \"grp\" was not found.", "/ii:top/{uses='grp'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj {yang-version 1.1;namespace urn:jj;prefix jj;"
"grouping grp {leaf j { when \"1\"; type invalid;}}"
"container top {uses grp;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Referenced type \"invalid\" not found.", "/jj:top/{uses='grp'}/j", 0);
}
static void
test_refine(void **state)
{
struct lys_module *mod;
struct lysc_node *parent, *child;
struct lysc_node_leaf *leaf;
struct lysc_node_leaflist *llist;
struct ly_in *in;
const char *data, *feats1[] = {"f", NULL}, *feats2[] = {"fa", NULL};
data = "module grp {yang-version 1.1;namespace urn:grp;prefix g; feature f;typedef mytype {type string; default cheers!;}"
"grouping grp {container c {leaf l {type mytype; default goodbye;}"
"leaf-list ll {type mytype; default goodbye; max-elements 6;}"
"choice ch {default ca; leaf ca {type int8;}leaf cb{type uint8;}}"
"leaf x {type mytype; mandatory true; must 1;}"
"anydata a {mandatory false; if-feature f; description original; reference original;}"
"container c {config false; leaf l {type string;}}}}}";
assert_int_equal(LY_SUCCESS, ly_in_new_memory(data, &in));
assert_int_equal(LY_SUCCESS, lys_parse(UTEST_LYCTX, in, LYS_IN_YANG, feats1, NULL));
data = "module a {yang-version 1.1;namespace urn:a;prefix a;import grp {prefix g;}feature fa;"
"uses g:grp {refine c/l {default hello; config false;}"
"refine c/ll {default hello;default world;}"
"refine c/ch {default cb;config true; if-feature fa;}"
"refine c/x {mandatory false; must ../ll;description refined; reference refined;}"
"refine c/a {mandatory true; must 1; description refined; reference refined;}"
"refine c/ll {max-elements 5;}"
"refine c/c {config true;presence indispensable;}}}";
ly_in_memory(in, data);
assert_int_equal(LY_SUCCESS, lys_parse(UTEST_LYCTX, in, LYS_IN_YANG, feats2, &mod));
ly_in_free(in, 0);
assert_non_null((parent = mod->compiled->data));
assert_int_equal(LYS_CONTAINER, parent->nodetype);
assert_string_equal("c", parent->name);
assert_non_null((leaf = (struct lysc_node_leaf *)((struct lysc_node_container *)parent)->child));
assert_int_equal(LYS_LEAF, leaf->nodetype);
assert_string_equal("l", leaf->name);
assert_string_equal("hello", leaf->dflt.str);
assert_int_equal(LYS_CONFIG_R, leaf->flags & LYS_CONFIG_MASK);
assert_non_null(llist = (struct lysc_node_leaflist *)leaf->next);
assert_int_equal(LYS_LEAFLIST, llist->nodetype);
assert_string_equal("ll", llist->name);
assert_int_equal(2, LY_ARRAY_COUNT(llist->dflts));
assert_string_equal("hello", llist->dflts[0].str);
assert_string_equal("world", llist->dflts[1].str);
assert_int_equal(5, llist->max);
assert_non_null(child = llist->next);
assert_int_equal(LYS_CHOICE, child->nodetype);
assert_string_equal("ch", child->name);
assert_string_equal("cb", ((struct lysc_node_choice *)child)->dflt->name);
assert_true(LYS_SET_DFLT & ((struct lysc_node_choice *)child)->dflt->flags);
assert_false(LYS_SET_DFLT & ((struct lysc_node_choice *)child)->cases[0].flags);
assert_non_null(leaf = (struct lysc_node_leaf *)child->next);
assert_int_equal(LYS_LEAF, leaf->nodetype);
assert_string_equal("x", leaf->name);
assert_false(LYS_MAND_TRUE & leaf->flags);
assert_string_equal("cheers!", leaf->dflt.str);
assert_non_null(leaf->musts);
assert_int_equal(2, LY_ARRAY_COUNT(leaf->musts));
assert_string_equal("refined", leaf->dsc);
assert_string_equal("refined", leaf->ref);
assert_non_null(child = leaf->next);
assert_int_equal(LYS_ANYDATA, child->nodetype);
assert_string_equal("a", child->name);
assert_true(LYS_MAND_TRUE & child->flags);
assert_non_null(((struct lysc_node_anydata *)child)->musts);
assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_node_anydata *)child)->musts));
assert_string_equal("refined", child->dsc);
assert_string_equal("refined", child->ref);
assert_non_null(child = child->next);
assert_int_equal(LYS_CONTAINER, child->nodetype);
assert_string_equal("c", child->name);
assert_true(LYS_PRESENCE & child->flags);
assert_true(LYS_CONFIG_W & child->flags);
assert_true(LYS_CONFIG_W & ((struct lysc_node_container *)child)->child->flags);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {yang-version 1.1;namespace urn:b;prefix b;import grp {prefix g;}"
"uses g:grp {status deprecated; refine c/x {default hello; mandatory false;}}}", LYS_IN_YANG, &mod));
assert_non_null((leaf = (struct lysc_node_leaf *)((struct lysc_node_container *)mod->compiled->data)->child->prev->prev->prev));
assert_int_equal(LYS_LEAF, leaf->nodetype);
assert_string_equal("x", leaf->name);
assert_false(LYS_MAND_TRUE & leaf->flags);
assert_string_equal("hello", leaf->dflt.str);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c;"
"grouping alg {leaf alg2 {type bits {"
"bit ftp;bit h323-q931;bit h323-ras;bit pptp;bit rtsp;bit sip-tcp;bit sip-udp;bit tftp;bit dns-udp;}}}"
"container conf {uses alg {refine alg2 {default \"dns-udp\";}}}}", LYS_IN_YANG, &mod));
/* invalid */
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa;import grp {prefix g;}"
"uses g:grp {refine c {default hello;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid refine of container node - it is not possible to replace \"default\" property.",
"/aa:{uses='g:grp'}/aa:c/{refine='c'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;import grp {prefix g;}"
"uses g:grp {refine c/l {default hello; default world;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid refine of leaf with too many (2) default properties.", "/bb:{uses='g:grp'}/bb:c/l/{refine='c/l'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc;import grp {prefix g;}"
"uses g:grp {refine c/ll {default hello; default world;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid refine of default in leaf-list - the default statement is allowed only in YANG 1.1 modules.",
"/cc:{uses='g:grp'}/cc:c/ll/{refine='c/ll'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd;import grp {prefix g;}"
"uses g:grp {refine c/ll {mandatory true;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid refine of leaf-list node - it is not possible to replace \"mandatory\" property.",
"/dd:{uses='g:grp'}/dd:c/ll/{refine='c/ll'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee;import grp {prefix g;}"
"uses g:grp {refine c/l {mandatory true;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/ee:{uses='g:grp'}/ee:c/l", 0);
CHECK_LOG_CTX("Invalid mandatory leaf with a default value.", "/ee:{uses='g:grp'}/ee:c/l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ef {namespace urn:ef;prefix ef;import grp {prefix g;}"
"uses g:grp {refine c/ch {mandatory true;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/ef:{uses='g:grp'}/ef:c/ch", 0);
CHECK_LOG_CTX("Invalid mandatory choice with a default case.", "/ef:{uses='g:grp'}/ef:c/ch", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff;import grp {prefix g;}"
"uses g:grp {refine c/ch/ca/ca {mandatory true;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Mandatory node \"ca\" under the default case \"ca\".", "/ff:{uses='g:grp'}/ff:c/ch", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg;import grp {prefix g;}"
"uses g:grp {refine c/x {default hello;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/gg:{uses='g:grp'}/gg:c/x", 0);
CHECK_LOG_CTX("Invalid mandatory leaf with a default value.", "/gg:{uses='g:grp'}/gg:c/x", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:hh;prefix hh;import grp {prefix g;}"
"uses g:grp {refine c/c/l {config true;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/hh:{uses='g:grp'}/hh:c/c/l", 0);
CHECK_LOG_CTX("Configuration node cannot be child of any state data node.", "/hh:{uses='g:grp'}/hh:c/c/l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii {namespace urn:ii;prefix ii;grouping grp {leaf l {type string; status deprecated;}}"
"uses grp {status obsolete;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Inherited schema-only status \"obsolete\" is in conflict with \"deprecated\" status of \"l\".",
"/ii:{uses='grp'}/ii:l", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj {namespace urn:jj;prefix jj;import grp {prefix g;}"
"uses g:grp {refine c/x {presence nonsence;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid refine of leaf node - it is not possible to replace \"presence\" property.",
"/jj:{uses='g:grp'}/jj:c/x/{refine='c/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk {namespace urn:kk;prefix kk;import grp {prefix g;}"
"uses g:grp {refine c/ch {must 1;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid refine of choice node - it is not possible to add \"must\" property.",
"/kk:{uses='g:grp'}/kk:c/ch/{refine='c/ch'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ll {namespace urn:ll;prefix ll;import grp {prefix g;}"
"uses g:grp {refine c/x {min-elements 1;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid refine of leaf node - it is not possible to replace \"min-elements\" property.",
"/ll:{uses='g:grp'}/ll:c/x/{refine='c/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm {namespace urn:mm;prefix mm;import grp {prefix g;}"
"uses g:grp {refine c/ll {min-elements 1;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/mm:{uses='g:grp'}/mm:c/ll", 0);
CHECK_LOG_CTX("The default statement is present on leaf-list with a nonzero min-elements.", "/mm:{uses='g:grp'}/mm:c/ll", 0);
}
static void
test_augment(void **state)
{
struct lys_module *mod;
const struct lysc_node *node;
const struct lysc_node_choice *ch;
const struct lysc_node_case *c;
const struct lysc_node_container *cont;
const struct lysc_node_action *rpc;
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module a {namespace urn:a;prefix a; typedef atype {type string;}"
"container top {leaf a {type string;}}}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;import a {prefix a;}"
"leaf b {type a:atype;}}", LYS_IN_YANG, &mod));
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module c {namespace urn:c;prefix c; import a {prefix a;}"
"augment /a:top { container c {leaf c {type a:atype;}}}}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d;import a {prefix a;} import c {prefix c;}"
"augment /a:top/c:c { leaf d {type a:atype;} leaf c {type string;}}}", LYS_IN_YANG, &mod));
assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "a")));
assert_non_null(ly_ctx_get_module_implemented(UTEST_LYCTX, "b"));
assert_non_null(ly_ctx_get_module_implemented(UTEST_LYCTX, "c"));
assert_non_null(ly_ctx_get_module_implemented(UTEST_LYCTX, "d"));
assert_non_null(node = mod->compiled->data);
assert_string_equal(node->name, "top");
assert_non_null(node = lysc_node_child(node));
assert_string_equal(node->name, "a");
assert_non_null(node = node->next);
assert_string_equal(node->name, "c");
assert_non_null(node = lysc_node_child(node));
assert_string_equal(node->name, "c");
assert_non_null(node = node->next);
assert_string_equal(node->name, "d");
assert_non_null(node = node->next);
assert_string_equal(node->name, "c");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module e {namespace urn:e;prefix e;choice ch {leaf a {type string;}}"
"augment /ch/c {when 1; leaf lc2 {type uint16;}}"
"augment /ch { when 1; leaf b {type int8;} case c {leaf lc1 {type uint8;}}}}", LYS_IN_YANG, &mod));
assert_non_null((ch = (const struct lysc_node_choice *)mod->compiled->data));
assert_null(mod->compiled->data->next);
assert_string_equal("ch", ch->name);
assert_non_null(c = (const struct lysc_node_case *)ch->cases);
assert_string_equal("a", c->name);
assert_null(c->when);
assert_string_equal("a", c->child->name);
assert_non_null(c = (const struct lysc_node_case *)c->next);
assert_string_equal("b", c->name);
assert_non_null(c->when);
assert_string_equal("b", c->child->name);
assert_non_null(c = (const struct lysc_node_case *)c->next);
assert_string_equal("c", c->name);
assert_non_null(c->when);
assert_string_equal("lc1", ((const struct lysc_node_case *)c)->child->name);
assert_null(lysc_node_when(((const struct lysc_node_case *)c)->child));
assert_string_equal("lc2", ((const struct lysc_node_case *)c)->child->next->name);
assert_non_null(lysc_node_when(((const struct lysc_node_case *)c)->child->next));
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {namespace urn:f;prefix f;grouping g {leaf a {type string;}}"
"container c;"
"augment /c {uses g;}}", LYS_IN_YANG, &mod));
assert_non_null(node = lysc_node_child(mod->compiled->data));
assert_string_equal(node->name, "a");
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule gsub {belongs-to g {prefix g;}"
"augment /c {container sub;}}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module g {namespace urn:g;prefix g;include gsub; container c;"
"augment /c/sub {leaf main {type string;}}}", LYS_IN_YANG, &mod));
assert_non_null(mod->compiled->data);
assert_string_equal("c", mod->compiled->data->name);
assert_non_null(node = ((struct lysc_node_container *)mod->compiled->data)->child);
assert_string_equal("sub", node->name);
assert_non_null(node = ((struct lysc_node_container *)node)->child);
assert_string_equal("main", node->name);
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module himp {namespace urn:hi;prefix hi;container top; rpc func;}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module h {namespace urn:h;prefix h;import himp {prefix hi;}container top;"
"augment /hi:top {container p {presence XXX; leaf x {mandatory true;type string;}}}"
"augment /hi:top {list ll {key x;leaf x {type string;}leaf y {mandatory true; type string;}}}"
"augment /hi:top {leaf l {type string; mandatory true; config false;}}"
"augment /top {leaf l {type string; mandatory true;}}}", LYS_IN_YANG, &mod));
assert_non_null(node = mod->compiled->data);
assert_non_null(node = ((struct lysc_node_container *)node)->child);
assert_string_equal("l", node->name);
assert_true(node->flags & LYS_MAND_TRUE);
assert_non_null(mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "himp"));
assert_non_null(node = mod->compiled->data);
assert_non_null(node = ((struct lysc_node_container *)node)->child);
assert_string_equal("p", node->name);
assert_non_null(node = node->next);
assert_string_equal("l", node->name);
assert_true(node->flags & LYS_CONFIG_R);
assert_non_null(node = node->next);
assert_string_equal("ll", node->name);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module i {namespace urn:i;prefix i;import himp {prefix hi;}"
"augment /hi:func/hi:input {leaf x {type string;}}"
"augment /hi:func/hi:output {leaf y {type string;}}}", LYS_IN_YANG, NULL));
assert_non_null(mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "himp"));
assert_non_null(rpc = mod->compiled->rpcs);
assert_null(rpc->next);
assert_non_null(rpc->input.child);
assert_string_equal("x", rpc->input.child->name);
assert_null(rpc->input.child->next);
assert_non_null(rpc->output.child);
assert_string_equal("y", rpc->output.child->name);
assert_null(rpc->output.child->next);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module j {namespace urn:j;prefix j;yang-version 1.1; container root;"
"grouping grp {notification grp-notif;}"
"augment /root {uses grp;}}", LYS_IN_YANG, &mod));
assert_non_null(cont = (const struct lysc_node_container *)mod->compiled->data);
assert_null(cont->child);
assert_non_null(cont->notifs);
assert_null(cont->notifs->next);
ly_ctx_set_module_imp_clb(UTEST_LYCTX, NULL, NULL);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module k {namespace urn:k; prefix k;yang-version 1.1;"
"feature f;"
"container c {if-feature f; leaf a {type string;}}}", LYS_IN_YANG, &mod));
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module l {namespace urn:l; prefix l; yang-version 1.1;"
"import k {prefix k;}"
"augment /k:c {leaf b {type string;}}"
"leaf c {when \"/k:c/l:b\"; type string;}}", LYS_IN_YANG, NULL));
/* no xpath warning expected */
CHECK_LOG_CTX(NULL, NULL, 0);
assert_null(mod->compiled->data);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module m {namespace urn:m;prefix m;yang-version 1.1;"
"feature f;"
"container root{container cont{if-feature f;}}"
"augment /root/cont {if-feature f; leaf l{type string;}}}", LYS_IN_YANG, &mod));
assert_non_null(cont = (const struct lysc_node_container *)mod->compiled->data);
assert_null(cont->child);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; container c {leaf a {type string;}}"
"augment /x/ {leaf a {type int8;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid absolute-schema-nodeid value \"/x/\" - unexpected end of expression.", "/aa:{augment='/x/'}", 0);
assert_int_equal(LY_ENOTFOUND, lys_parse_mem(UTEST_LYCTX, "module aa {namespace urn:aa;prefix aa; container c {leaf a {type string;}}"
"augment /x {leaf a {type int8;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Augment target node \"/x\" from module \"aa\" was not found.", "/aa:{augment='/x'}", 0);
assert_int_equal(LY_EEXIST, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb; container c {leaf a {type string;}}"
"augment /c {leaf a {type int8;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Duplicate identifier \"/bb:c/a\" of data definition/RPC/action/notification statement.", "/bb:{augment='/c'}/a", 0);
assert_int_equal(LY_ENOTFOUND, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc; container c {leaf a {type string;}}"
"augment /c/a {leaf a {type int8;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Augment target node \"/c/a\" from module \"cc\" was not found.", "/cc:{augment='/c/a'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd {namespace urn:dd;prefix dd; container c {leaf a {type string;}}"
"augment /c {case b {leaf d {type int8;}}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid augment of container node which is not allowed to contain case node \"b\".", "/dd:{augment='/c'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {namespace urn:ee;prefix ee; import himp {prefix hi;}"
"augment /hi:top {container c {leaf d {mandatory true; type int8;}}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid augment adding mandatory node \"c\" without making it conditional via when statement.",
"/ee:{augment='/hi:top'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff {namespace urn:ff;prefix ff; container top;"
"augment ../top {leaf x {type int8;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid absolute-schema-nodeid value \"../top\" - \"/\" expected instead of \"..\".", "/ff:{augment='../top'}", 0);
assert_int_equal(LY_ENOTFOUND, lys_parse_mem(UTEST_LYCTX, "module gg {namespace urn:gg;prefix gg; rpc func;"
"augment /func {leaf x {type int8;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Augment target node \"/func\" from module \"gg\" was not found.", "/gg:{augment='/func'}", 0);
assert_int_equal(LY_ENOTFOUND, lys_parse_mem(UTEST_LYCTX, "module hh {namespace urn:hh;prefix hh;import himp {prefix hi;}"
"augment /hi:func/input {leaf x {type string;}}"
"augment /hi:func/output {leaf y {type string;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Augment target node \"/hi:func/input\" from module \"hh\" was not found.", "/hh:{augment='/hi:func/input'}", 0);
CHECK_LOG_CTX("Augment target node \"/hi:func/output\" from module \"hh\" was not found.", "/hh:{augment='/hi:func/output'}", 0);
}
static void
test_deviation(void **state)
{
struct lys_module *mod;
const struct lysc_node *node;
const struct lysc_node_list *list;
const struct lysc_node_leaflist *llist;
const struct lysc_node_leaf *leaf;
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module a {namespace urn:a;prefix a;"
"container top {leaf a {type string;} leaf b {type string;} leaf c {type string;}}"
"choice ch {default c; case b {leaf b{type string;}} case a {leaf a{type string;} leaf x {type string;}}"
" case c {leaf c{type string;}}}"
"rpc func1 { input { leaf x {type int8;}} output {leaf y {type int8;}}}"
"rpc func2;}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module b {namespace urn:b;prefix b;import a {prefix a;}"
"deviation /a:top/a:b {deviate not-supported;}"
"deviation /a:ch/a:a/a:x {deviate not-supported;}"
"deviation /a:ch/a:c {deviate not-supported;}"
"deviation /a:ch/a:b {deviate not-supported;}"
"deviation /a:ch/a:a/a:a {deviate not-supported;}"
"deviation /a:ch {deviate replace {default a;}}"
"deviation /a:func1/a:input {deviate not-supported;}"
"deviation /a:func1/a:output {deviate not-supported;}"
"deviation /a:func2 {deviate not-supported;}}", LYS_IN_YANG, NULL));
assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "a")));
assert_non_null(node = mod->compiled->data);
assert_string_equal(node->name, "top");
assert_non_null(node = lysc_node_child(node));
assert_string_equal(node->name, "a");
assert_non_null(node = node->next);
assert_string_equal(node->name, "c");
assert_null(node = node->next);
assert_non_null(node = mod->compiled->data->next);
assert_string_equal("ch", node->name);
assert_non_null(((struct lysc_node_choice *)node)->dflt);
assert_non_null(((struct lysc_node_choice *)node)->cases);
assert_null(((struct lysc_node_choice *)node)->cases->next);
assert_non_null(mod->compiled->rpcs);
assert_null(mod->compiled->rpcs->next);
assert_null(mod->compiled->rpcs->input.child);
assert_null(mod->compiled->rpcs->output.child);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module c {namespace urn:c;prefix c; typedef mytype {type string; units kilometers;}"
"leaf c1 {type mytype;} leaf c2 {type mytype; units meters;} leaf c3 {type mytype; units meters;}"
"deviation /c1 {deviate add {units meters;}}"
"deviation /c2 {deviate delete {units meters;}}"
"deviation /c3 {deviate replace {units centimeters;}}}", LYS_IN_YANG, &mod));
assert_non_null(node = mod->compiled->data);
assert_string_equal("c1", node->name);
assert_string_equal("meters", ((struct lysc_node_leaf *)node)->units);
assert_non_null(node = node->next);
assert_string_equal("c2", node->name);
assert_string_equal("kilometers", ((struct lysc_node_leaf *)node)->units);
assert_non_null(node = node->next);
assert_string_equal("c3", node->name);
assert_string_equal("centimeters", ((struct lysc_node_leaf *)node)->units);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module d {namespace urn:d;prefix d; leaf c1 {type string; must 1;}"
"container c2 {presence yes; must 1; must 2;} leaf c3 {type string; must 1; must 3;}"
"deviation /c1 {deviate add {must 3;}}"
"deviation /c2 {deviate delete {must 2;}}"
"deviation /c3 {deviate delete {must 3; must 1;}}}", LYS_IN_YANG, &mod));
assert_non_null(node = mod->compiled->data);
assert_string_equal("c1", node->name);
assert_int_equal(2, LY_ARRAY_COUNT(((struct lysc_node_leaf *)node)->musts));
assert_string_equal("3", ((struct lysc_node_leaf *)node)->musts[1].cond->expr);
assert_non_null(node = node->next);
assert_string_equal("c2", node->name);
assert_int_equal(1, LY_ARRAY_COUNT(((struct lysc_node_container *)node)->musts));
assert_string_equal("1", ((struct lysc_node_container *)node)->musts[0].cond->expr);
assert_non_null(node = node->next);
assert_string_equal("c3", node->name);
assert_null(((struct lysc_node_leaf *)node)->musts);
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module e {yang-version 1.1; namespace urn:e;prefix e; typedef mytype {type string; default nothing;}"
"choice a {default aa;leaf aa {type string;} leaf ab {type string;} leaf ac {type string; mandatory true;}}"
"choice b {default ba;leaf ba {type string;} leaf bb {type string;}}"
"leaf c {default hello; type string;}"
"leaf-list d {default hello; default world; type string;}"
"leaf c2 {type mytype;} leaf-list d2 {type mytype;}}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module f {yang-version 1.1; namespace urn:f;prefix f;import e {prefix x;}"
"deviation /x:a {deviate delete {default aa;}}"
"deviation /x:b {deviate delete {default ba;}}"
"deviation /x:c {deviate delete {default hello;}}"
"deviation /x:d {deviate delete {default world;}}}", LYS_IN_YANG, NULL));
assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "e")));
assert_non_null(node = mod->compiled->data);
assert_null(((struct lysc_node_choice *)node)->dflt);
assert_non_null(node = node->next);
assert_null(((struct lysc_node_choice *)node)->dflt);
assert_non_null(leaf = (struct lysc_node_leaf *)node->next);
assert_null(leaf->dflt.str);
assert_non_null(llist = (struct lysc_node_leaflist *)leaf->next);
assert_int_equal(1, LY_ARRAY_COUNT(llist->dflts));
assert_string_equal("hello", llist->dflts[0].str);
assert_non_null(leaf = (struct lysc_node_leaf *)llist->next);
assert_string_equal("nothing", leaf->dflt.str);
assert_non_null(llist = (struct lysc_node_leaflist *)leaf->next);
assert_int_equal(1, LY_ARRAY_COUNT(llist->dflts));
assert_string_equal("nothing", llist->dflts[0].str);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module g {yang-version 1.1; namespace urn:g;prefix g;import e {prefix x;}"
"deviation /x:b {deviate add {default x:ba;}}"
"deviation /x:c {deviate add {default bye;}}"
"deviation /x:d {deviate add {default all; default people;}}"
"deviation /x:c2 {deviate add {default hi; must 1;}}"
"deviation /x:d2 {deviate add {default hi; default all;}}}", LYS_IN_YANG, NULL));
assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "e")));
assert_non_null(node = mod->compiled->data);
assert_null(((struct lysc_node_choice *)node)->dflt);
assert_non_null(node = node->next);
assert_non_null(((struct lysc_node_choice *)node)->dflt);
assert_string_equal("ba", ((struct lysc_node_choice *)node)->dflt->name);
assert_non_null(leaf = (struct lysc_node_leaf *)node->next);
assert_string_equal("bye", leaf->dflt.str);
assert_non_null(llist = (struct lysc_node_leaflist *)leaf->next);
assert_int_equal(3, LY_ARRAY_COUNT(llist->dflts));
assert_string_equal("hello", llist->dflts[0].str);
assert_string_equal("all", llist->dflts[1].str);
assert_string_equal("people", llist->dflts[2].str);
assert_non_null(leaf = (struct lysc_node_leaf *)llist->next);
assert_string_equal("hi", leaf->dflt.str);
assert_int_equal(1, LY_ARRAY_COUNT(leaf->musts));
assert_int_equal(1, LY_ARRAY_COUNT(leaf->musts[0].prefixes));
assert_non_null(llist = (struct lysc_node_leaflist *)leaf->next);
assert_int_equal(2, LY_ARRAY_COUNT(llist->dflts));
assert_string_equal("hi", llist->dflts[0].str);
assert_string_equal("all", llist->dflts[1].str);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module h {yang-version 1.1; namespace urn:h;prefix h;import e {prefix x;}"
"deviation /x:b {deviate replace {default x:ba;}}"
"deviation /x:c {deviate replace {default hello;}}}", LYS_IN_YANG, NULL));
assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "e")));
assert_non_null(node = mod->compiled->data);
assert_null(((struct lysc_node_choice *)node)->dflt);
assert_non_null(node = node->next);
assert_non_null(((struct lysc_node_choice *)node)->dflt);
assert_string_equal("ba", ((struct lysc_node_choice *)node)->dflt->name);
assert_non_null(leaf = (struct lysc_node_leaf *)node->next);
assert_string_equal("hello", leaf->dflt.str);
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module i {namespace urn:i;prefix i;"
"list l1 {key a; leaf a {type string;} leaf b {type string;} leaf c {type string;}}"
"list l2 {key a; unique \"b c\"; unique \"d\"; leaf a {type string;} leaf b {type string;}"
" leaf c {type string;} leaf d {type string;}}}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module j {namespace urn:j;prefix j;import i {prefix i;}"
"augment /i:l1 {leaf j_c {type string;}}"
"deviation /i:l1 {deviate add {unique \"b j:j_c\"; }}"
"deviation /i:l1 {deviate add {unique \"i:c\";}}"
"deviation /i:l2 {deviate delete {unique \"d\"; unique \"b c\";}}}", LYS_IN_YANG, NULL));
assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "i")));
assert_non_null(list = (struct lysc_node_list *)mod->compiled->data);
assert_string_equal("l1", list->name);
assert_int_equal(2, LY_ARRAY_COUNT(list->uniques));
assert_int_equal(2, LY_ARRAY_COUNT(list->uniques[0]));
assert_string_equal("b", list->uniques[0][0]->name);
assert_string_equal("j_c", list->uniques[0][1]->name);
assert_int_equal(1, LY_ARRAY_COUNT(list->uniques[1]));
assert_string_equal("c", list->uniques[1][0]->name);
assert_non_null(list = (struct lysc_node_list *)list->next);
assert_string_equal("l2", list->name);
assert_null(list->uniques);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module k {namespace urn:k;prefix k; leaf a {type string;}"
"container top {leaf x {type string;} leaf y {type string; config false;}}"
"deviation /a {deviate add {config false; }}"
"deviation /top {deviate add {config false;}}}", LYS_IN_YANG, &mod));
assert_non_null(node = mod->compiled->data);
assert_string_equal("a", node->name);
assert_true(node->flags & LYS_CONFIG_R);
assert_non_null(node = node->next);
assert_string_equal("top", node->name);
assert_true(node->flags & LYS_CONFIG_R);
assert_non_null(node = lysc_node_child(node));
assert_string_equal("x", node->name);
assert_true(node->flags & LYS_CONFIG_R);
assert_non_null(node = node->next);
assert_string_equal("y", node->name);
assert_true(node->flags & LYS_CONFIG_R);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module l {namespace urn:l;prefix l; leaf a {config false; type string;}"
"container top {leaf x {type string;}}"
"deviation /a {deviate replace {config true;}}"
"deviation /top {deviate replace {config false;}}}", LYS_IN_YANG, &mod));
assert_non_null(node = mod->compiled->data);
assert_string_equal("a", node->name);
assert_true(node->flags & LYS_CONFIG_W);
assert_non_null(node = node->next);
assert_string_equal("top", node->name);
assert_true(node->flags & LYS_CONFIG_R);
assert_non_null(node = lysc_node_child(node));
assert_string_equal("x", node->name);
assert_true(node->flags & LYS_CONFIG_R);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module m {namespace urn:m;prefix m;"
"container a {leaf a {type string;}}"
"container b {leaf b {mandatory true; type string;}}"
"deviation /a/a {deviate add {mandatory true;}}"
"deviation /b/b {deviate replace {mandatory false;}}}", LYS_IN_YANG, &mod));
assert_non_null(node = mod->compiled->data);
assert_string_equal("a", node->name);
assert_true((node->flags & LYS_MAND_MASK) == LYS_MAND_TRUE);
assert_true((lysc_node_child(node)->flags & LYS_MAND_MASK) == LYS_MAND_TRUE);
assert_non_null(node = node->next);
assert_string_equal("b", node->name);
assert_false(node->flags & LYS_MAND_MASK); /* just unset on container */
assert_true((lysc_node_child(node)->flags & LYS_MAND_MASK) == LYS_MAND_FALSE);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module n {yang-version 1.1; namespace urn:n;prefix n;"
"leaf a {default test; type string;}"
"leaf b {mandatory true; type string;}"
"deviation /a {deviate add {mandatory true;} deviate delete {default test;}}"
"deviation /b {deviate add {default test;} deviate replace {mandatory false;}}}", LYS_IN_YANG, &mod));
assert_non_null(node = mod->compiled->data);
assert_string_equal("a", node->name);
assert_null(((struct lysc_node_leaf *)node)->dflt.str);
assert_true((node->flags & LYS_MAND_MASK) == LYS_MAND_TRUE);
assert_non_null(node = node->next);
assert_string_equal("b", node->name);
assert_non_null(((struct lysc_node_leaf *)node)->dflt.str);
assert_true((node->flags & LYS_MAND_MASK) == LYS_MAND_FALSE);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module o {namespace urn:o;prefix o;"
"leaf-list a {type string;}"
"list b {config false;}"
"leaf-list c {min-elements 1; max-elements 10; type string;}"
"list d {min-elements 10; max-elements 100; config false;}"
"deviation /a {deviate add {min-elements 1; max-elements 10;}}"
"deviation /b {deviate add {min-elements 10; max-elements 100;}}"
"deviation /c {deviate replace {min-elements 10; max-elements 100;}}"
"deviation /d {deviate replace {min-elements 1; max-elements 10;}}}", LYS_IN_YANG, &mod));
assert_non_null(node = mod->compiled->data);
assert_string_equal("a", node->name);
assert_int_equal(1, ((struct lysc_node_leaflist *)node)->min);
assert_int_equal(10, ((struct lysc_node_leaflist *)node)->max);
assert_non_null(node = node->next);
assert_string_equal("b", node->name);
assert_int_equal(10, ((struct lysc_node_list *)node)->min);
assert_int_equal(100, ((struct lysc_node_list *)node)->max);
assert_non_null(node = node->next);
assert_string_equal("c", node->name);
assert_int_equal(10, ((struct lysc_node_leaflist *)node)->min);
assert_int_equal(100, ((struct lysc_node_leaflist *)node)->max);
assert_non_null(node = node->next);
assert_string_equal("d", node->name);
assert_int_equal(1, ((struct lysc_node_list *)node)->min);
assert_int_equal(10, ((struct lysc_node_list *)node)->max);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module p {yang-version 1.1; namespace urn:p;prefix p; typedef mytype {type int8; default 1;}"
"leaf a {type string; default 10;} leaf-list b {type string;}"
"deviation /a {deviate replace {type mytype;}}"
"deviation /b {deviate replace {type mytype;}}}", LYS_IN_YANG, &mod));
assert_non_null(leaf = (struct lysc_node_leaf *)mod->compiled->data);
assert_string_equal("a", leaf->name);
assert_int_equal(LY_TYPE_INT8, leaf->type->basetype);
assert_string_equal("10", leaf->dflt.str);
assert_non_null(llist = (struct lysc_node_leaflist *)leaf->next);
assert_string_equal("b", llist->name);
assert_int_equal(LY_TYPE_INT8, llist->type->basetype);
assert_int_equal(1, LY_ARRAY_COUNT(llist->dflts));
assert_string_equal("1", llist->dflts[0].str);
/* instance-identifiers with NULL canonical are changed to string types with a canonical value equal to the original value */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module q {yang-version 1.1; namespace urn:q;prefix q; import e {prefix e;}"
"leaf q {type instance-identifier; default \"/e:d2[.='a']\";}"
"leaf-list ql {type instance-identifier; default \"/e:d[.='b']\"; default \"/e:d2[.='c']\";}}", LYS_IN_YANG, &mod));
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module qdev {yang-version 1.1; namespace urn:qdev;prefix qd; import q {prefix q;}"
"deviation /q:q { deviate replace {type string;}}"
"deviation /q:ql { deviate replace {type string;}}}", LYS_IN_YANG, NULL));
assert_non_null(leaf = (struct lysc_node_leaf *)mod->compiled->data);
assert_string_equal("/e:d2[.='a']", leaf->dflt.str);
assert_non_null(llist = (struct lysc_node_leaflist *)leaf->next);
assert_int_equal(2, LY_ARRAY_COUNT(llist->dflts));
assert_string_equal("/e:d[.='b']", llist->dflts[0].str);
assert_string_equal("/e:d2[.='c']", llist->dflts[1].str);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module r {yang-version 1.1; namespace urn:r;prefix r;"
"typedef mytype {type uint8; default 200;}"
"leaf r {type mytype;} leaf-list lr {type mytype;}"
"deviation /r:r {deviate replace {type string;}}"
"deviation /r:lr {deviate replace {type string;}}}", LYS_IN_YANG, &mod));
assert_non_null(leaf = (struct lysc_node_leaf *)mod->compiled->data);
assert_string_equal("r", leaf->name);
assert_null(leaf->dflt.str);
assert_non_null(llist = (struct lysc_node_leaflist *)leaf->next);
assert_string_equal("lr", llist->name);
assert_null(llist->dflts);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module s {yang-version 1.1; namespace urn:s;prefix s;"
"leaf s {type instance-identifier {require-instance true;} default /s:x;}"
"leaf x {type string;} leaf y {type string;}"
"deviation /s:s {deviate replace {default /s:y;}}}", LYS_IN_YANG, &mod));
assert_non_null(leaf = (struct lysc_node_leaf *)mod->compiled->data);
assert_string_equal("s", leaf->name);
assert_string_equal("/s:y", leaf->dflt.str);
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module t {namespace urn:t;prefix t;"
"leaf l {type string;}}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module u {namespace urn:u;prefix u;import t {prefix t;}"
"identity ident;"
"deviation /t:l {deviate replace {type identityref {base ident;}}}"
"}", LYS_IN_YANG, NULL));
assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "t")));
assert_non_null(leaf = (struct lysc_node_leaf *)mod->compiled->data);
assert_string_equal("l", leaf->name);
assert_int_equal(LY_TYPE_IDENT, leaf->type->basetype);
assert_string_equal("ident", ((struct lysc_type_identityref *)leaf->type)->bases[0]->name);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module v {namespace urn:v;prefix v;"
"identity ident; identity ident2 { base ident; }"
"}", LYS_IN_YANG, NULL));
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "submodule w-sub { belongs-to w { prefix w; }"
"import v { prefix v_pref; }"
"leaf l { type string; default \"v_pref:ident2\"; }"
"}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module w {namespace urn:w;prefix w;"
"include w-sub;"
"}", LYS_IN_YANG, &mod));
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module x {namespace urn:x;prefix x;"
"import w { prefix w_pref; } import v { prefix v_pref; }"
"deviation /w_pref:l { deviate replace { type identityref { base v_pref:ident; } } }"
"}", LYS_IN_YANG, NULL));
assert_non_null(leaf = (struct lysc_node_leaf *)mod->compiled->data);
assert_string_equal("l", leaf->name);
assert_int_equal(LY_TYPE_IDENT, leaf->type->basetype);
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module y {namespace urn:y;prefix y;"
"leaf l1 {type string;}"
"leaf l2 {type string;}"
"}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module z {namespace urn:z;prefix z;"
"import y {prefix y;}"
"deviation \"/y:l1\" {deviate replace {type leafref {path \"/l2\";}}}"
"deviation \"/y:l2\" {deviate replace {type leafref {path \"/z:al2\";}}}"
"leaf al2 {type string;}"
"}", LYS_IN_YANG, NULL));
assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "y")));
assert_non_null(leaf = (struct lysc_node_leaf *)mod->compiled->data);
assert_string_equal("l1", leaf->name);
assert_int_equal(LY_TYPE_LEAFREF, leaf->type->basetype);
leaf = (struct lysc_node_leaf *)leaf->next;
assert_string_equal("l2", leaf->name);
assert_int_equal(LY_TYPE_LEAFREF, leaf->type->basetype);
/* complex dependencies */
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module m-base {namespace urn:m-base;prefix mb;"
"container cont {leaf l {type string;} leaf l2 {type string;}}}", LYS_IN_YANG, NULL));
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module m-base-aug {namespace urn:m-base-aug;prefix mba;"
"import m-base {prefix mb;}"
"augment /mb:cont {leaf l {type string;} leaf l2 {type string;}}"
"container cont2 {leaf l {type string;}}}"
"\n"
"module m-base-aug2 {namespace urn:m-base-aug2;prefix mba2;"
"import m-base {prefix mb;} import m-base-aug {prefix mba;}"
"augment /mb:cont {leaf augl1 {type string;}}"
"augment /mba:cont2 {leaf augl2 {type string;}}}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module m-dev {namespace urn:m-dev;prefix md;"
"import m-base-aug {prefix mba;} import m-base-aug2 {prefix mba2;}"
"deviation /mba:cont2/mba2:augl2 {deviate not-supported;}}", LYS_IN_YANG, NULL));
assert_non_null((mod = ly_ctx_get_module_implemented(UTEST_LYCTX, "m-base-aug")));
node = mod->compiled->data;
assert_string_equal(node->name, "cont2");
assert_non_null(node = lysc_node_child(node));
assert_string_equal(node->name, "l");
assert_null(node->next);
/* default identity referencing deprecated */
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module a1-imp {namespace urn:a1-imp;prefix a1i;"
"identity id-base;"
"identity id1 {base id-base; status deprecated;}"
"leaf l {type identityref {base \"id-base\";}}"
"}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a1 {namespace urn:a1;prefix a1;"
"import a1-imp {prefix a1i;}"
"deviation \"/a1i:l\" {deviate add {default \"a1i:id1\";}}"
"}", LYS_IN_YANG, NULL));
/* default instance-identifier referencing deprecated */
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module a2-imp {namespace urn:a2-imp;prefix a2i;"
"leaf l {type instance-identifier;}"
"leaf k {type string; status deprecated;}"
"}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a2 {namespace urn:a2;prefix a2;"
"import a2-imp {prefix a2i;}"
"deviation \"/a2i:l\" {deviate add {default \"/a2i:k\";}}"
"}", LYS_IN_YANG, NULL));
/* must referencing deprecated */
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module a3-imp {namespace urn:a3-imp;prefix a3i;"
"leaf l {type string;}"
"leaf k {type string; status deprecated;}"
"}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a3 {namespace urn:a3;prefix a3;"
"import a3-imp {prefix a3i;}"
"deviation \"/a3i:l\" {deviate add {must \"string-length(/a3i:k) > 0\";}}"
"}", LYS_IN_YANG, NULL));
/* type leafref referencing deprecated */
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module a4-imp {namespace urn:a4-imp;prefix a4i;"
"leaf l {type string;}"
"leaf k {type string; status deprecated;}"
"}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a4 {namespace urn:a4;prefix a4;"
"import a4-imp {prefix a4i;}"
"deviation \"/a4i:l\" {deviate replace {type leafref {path \"/a4i:k\";}}}"
"}", LYS_IN_YANG, NULL));
/* unique referencing deprecated */
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb, "module a5-imp {namespace urn:a5-imp;prefix a5i;"
"list l1 {key \"k\";"
" leaf k {type string;}"
" leaf l {type string; status deprecated;}"
"}}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module a5 {namespace urn:a5;prefix a5;"
"import a5-imp {prefix a5i;}"
"deviation \"/a5i:l1\" {deviate add {unique \"a5i:l\";}}"
"}", LYS_IN_YANG, NULL));
assert_int_equal(LY_ENOTFOUND, lys_parse_mem(UTEST_LYCTX, "module aa1 {namespace urn:aa1;prefix aa1;import a {prefix a;}"
"deviation /a:top/a:z {deviate not-supported;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Deviation(s) target node \"/a:top/a:z\" from module \"aa1\" was not found.",
"/a:{deviation='/a:top/a:z'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module aa2 {namespace urn:aa2;prefix aa2;import a {prefix a;}"
"deviation /a:top/a:a {deviate not-supported;}"
"deviation /a:top/a:a {deviate add {default error;}}}", LYS_IN_YANG, NULL));
CHECK_LOG_CTX("Multiple deviations of \"/a:top/a:a\" with one of them being \"not-supported\".",
"/aa2:{deviation='/a:top/a:a'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module bb {namespace urn:bb;prefix bb;import a {prefix a;}"
"deviation a:top/a:a {deviate not-supported;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid absolute-schema-nodeid value \"a:top/a:a\" - \"/\" expected instead of \"a:top\".",
"/bb:{deviation='a:top/a:a'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cc {namespace urn:cc;prefix cc; container c;"
"deviation /c {deviate add {units meters;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation of container node - it is not possible to add \"units\" property.",
"/cc:{deviation='/c'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module cd {namespace urn:cd;prefix cd; leaf c {type string; units centimeters;}"
"deviation /c {deviate add {units meters;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation adding \"units\" property which already exists (with value \"centimeters\").",
"/cd:{deviation='/c'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd1 {namespace urn:dd1;prefix dd1; container c;"
"deviation /c {deviate delete {units meters;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation of container node - it is not possible to delete \"units\" property.",
"/dd1:{deviation='/c'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd2 {namespace urn:dd2;prefix dd2; leaf c {type string;}"
"deviation /c {deviate delete {units meters;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation deleting \"units\" property \"meters\" which is not present.",
"/dd2:{deviation='/c'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module dd3 {namespace urn:dd3;prefix dd3; leaf c {type string; units centimeters;}"
"deviation /c {deviate delete {units meters;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation deleting \"units\" property \"meters\" which does not match the target's property value \"centimeters\".",
"/dd3:{deviation='/c'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee1 {namespace urn:ee1;prefix ee1; container c;"
"deviation /c {deviate replace {units meters;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation of container node - it is not possible to replace \"units\" property.",
"/ee1:{deviation='/c'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee2 {namespace urn:ee2;prefix ee2; leaf c {type string;}"
"deviation /c {deviate replace {units meters;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation replacing \"units\" property \"meters\" which is not present.",
"/ee2:{deviation='/c'}", 0);
/* the default is already deleted in /e:a byt module f */
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff1 {namespace urn:ff1;prefix ff1; import e {prefix e;}"
"deviation /e:a {deviate delete {default x:aa;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation deleting \"default\" property \"x:aa\" which is not present.",
"/ff1:{deviation='/e:a'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff3 {namespace urn:ff3;prefix ff3; import e {prefix e;}"
"deviation /e:b {deviate delete {default e:b;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation deleting \"default\" property \"e:b\" which does not match the target's property value \"x:ba\".",
"/ff3:{deviation='/e:b'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff5 {namespace urn:ff5;prefix ff5; anyxml a;"
"deviation /a {deviate delete {default x;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation of anyxml node - it is not possible to delete \"default\" property.",
"/ff5:{deviation='/a'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff6 {namespace urn:ff6;prefix ff6; import e {prefix e;}"
"deviation /e:c {deviate delete {default hi;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation deleting \"default\" property \"hi\" which does not match the target's property value \"hello\".",
"/ff6:{deviation='/e:c'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ff7 {namespace urn:ff7;prefix ff7; import e {prefix e;}"
"deviation /e:d {deviate delete {default hi;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation deleting \"default\" property \"hi\" which does not match any of the target's property values.",
"/ff7:{deviation='/e:d'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg1 {namespace urn:gg1;prefix gg1; import e {prefix e;}"
"deviation /e:b {deviate add {default e:a;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation adding \"default\" property which already exists (with value \"x:ba\").",
"/gg1:{deviation='/e:b'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg2 {namespace urn:gg2;prefix gg2; import e {prefix e;}"
"deviation /e:a {deviate add {default x:a;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/e:a", 0);
CHECK_LOG_CTX("Default case prefix \"x\" not found in imports of \"gg2\".", "/e:a", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg3 {namespace urn:gg3;prefix gg3; import e {prefix e;}"
"deviation /e:a {deviate add {default a;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/e:a", 0);
CHECK_LOG_CTX("Default case \"a\" not found.", "/e:a", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg4 {namespace urn:gg4;prefix gg4; import e {prefix e;}"
"deviation /e:c {deviate add {default hi;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation adding \"default\" property which already exists (with value \"hello\").",
"/gg4:{deviation='/e:c'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg4 {namespace urn:gg4;prefix gg4; import e {prefix e;}"
"deviation /e:a {deviate add {default e:ac;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/e:a", 0);
CHECK_LOG_CTX("Mandatory node \"ac\" under the default case \"e:ac\".", "/e:a", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module gg5 {namespace urn:gg5;prefix gg5; leaf x {type string; mandatory true;}"
"deviation /x {deviate add {default error;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/gg5:{deviation='/x'}", 0);
CHECK_LOG_CTX("Invalid mandatory leaf with a default value.", "/gg5:{deviation='/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module hh1 {yang-version 1.1; namespace urn:hh1;prefix hh1; import e {prefix e;}"
"deviation /e:d {deviate replace {default hi;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation of leaf-list node - it is not possible to replace \"default\" property.",
"/hh1:{deviation='/e:d'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii1 {namespace urn:ii1;prefix ii1; import i {prefix i;}"
"deviation /i:l1 {deviate delete {unique x;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation deleting \"unique\" property \"x\" which does not match any of the target's property values.",
"/ii1:{deviation='/i:l1'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii2 {namespace urn:ii2;prefix ii2; import i {prefix i;} leaf x { type string;}"
"deviation /i:l2 {deviate delete {unique d;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation deleting \"unique\" property \"d\" which does not match any of the target's property values.",
"/ii2:{deviation='/i:l2'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii3 {namespace urn:ii3;prefix ii3; leaf x { type string;}"
"deviation /x {deviate delete {unique d;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation of leaf node - it is not possible to delete \"unique\" property.", "/ii3:{deviation='/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ii4 {namespace urn:ii4;prefix ii4; leaf x { type string;}"
"deviation /x {deviate add {unique d;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation of leaf node - it is not possible to add \"unique\" property.", "/ii4:{deviation='/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj1 {namespace urn:jj1;prefix jj1; choice ch {case a {leaf a{type string;}}}"
"deviation /ch/a {deviate add {config false;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation of case node - it is not possible to add \"config\" property.", "/jj1:{deviation='/ch/a'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj2 {namespace urn:jj2;prefix jj2; container top {config false; leaf x {type string;}}"
"deviation /top/x {deviate add {config true;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/jj2:{deviation='/top/x'}", 0);
CHECK_LOG_CTX("Configuration node cannot be child of any state data node.", "/jj2:{deviation='/top/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj4 {namespace urn:jj4;prefix jj4; choice ch {case a {leaf a{type string;}}}"
"deviation /ch/a {deviate replace {config false;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation of case node - it is not possible to replace \"config\" property.",
"/jj4:{deviation='/ch/a'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj5 {namespace urn:jj5;prefix jj5; container top {leaf x {type string; config true;}}"
"deviation /top {deviate add {config false;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/jj5:top", 0);
CHECK_LOG_CTX("Configuration node cannot be child of any state data node.", "/jj5:top/x", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module jj6 {namespace urn:jj6;prefix jj6; leaf x {config false; type string;}"
"deviation /x {deviate add {config true;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation adding \"config\" property which already exists (with value \"config false\").",
"/jj6:{deviation='/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk1 {namespace urn:kk1;prefix kk1; container top {leaf a{type string;}}"
"deviation /top {deviate add {mandatory true;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation of container node - it is not possible to add \"mandatory\" property.",
"/kk1:{deviation='/top'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk2 {namespace urn:kk2;prefix kk2; container top {leaf a{type string;}}"
"deviation /top {deviate replace {mandatory true;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation of container node - it is not possible to replace \"mandatory\" property.",
"/kk2:{deviation='/top'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module kk4 {namespace urn:kk4;prefix kk4; leaf x {mandatory true; type string;}"
"deviation /x {deviate add {mandatory false;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation adding \"mandatory\" property which already exists (with value \"mandatory true\").",
"/kk4:{deviation='/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ll1 {namespace urn:ll1;prefix ll1; leaf x {default test; type string;}"
"deviation /x {deviate add {mandatory true;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/ll1:{deviation='/x'}", 0);
CHECK_LOG_CTX("Invalid mandatory leaf with a default value.", "/ll1:{deviation='/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ll2 {yang-version 1.1; namespace urn:ll2;prefix ll2; leaf-list x {default test; type string;}"
"deviation /x {deviate add {min-elements 1;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/ll2:{deviation='/x'}", 0);
CHECK_LOG_CTX("The default statement is present on leaf-list with a nonzero min-elements.", "/ll2:{deviation='/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ll2 {namespace urn:ll2;prefix ll2; choice ch {default a; leaf a {type string;} leaf b {type string;}}"
"deviation /ch {deviate add {mandatory true;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/ll2:ch", 0);
CHECK_LOG_CTX("Invalid mandatory choice with a default case.", "/ll2:ch", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm1 {namespace urn:mm1;prefix mm1; leaf-list x {min-elements 10; type string;}"
"deviation /x {deviate add {max-elements 5;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/mm1:{deviation='/x'}", 0);
CHECK_LOG_CTX("Leaf-list min-elements 10 is bigger than max-elements 5.", "/mm1:{deviation='/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm2 {namespace urn:mm2;prefix mm2; leaf-list x {max-elements 10; type string;}"
"deviation /x {deviate add {min-elements 20;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/mm2:{deviation='/x'}", 0);
CHECK_LOG_CTX("Leaf-list min-elements 20 is bigger than max-elements 10.", "/mm2:{deviation='/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm3 {namespace urn:mm3;prefix mm3; list x {min-elements 5; max-elements 10; config false;}"
"deviation /x {deviate replace {max-elements 1;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/mm3:{deviation='/x'}", 0);
CHECK_LOG_CTX("List min-elements 5 is bigger than max-elements 1.", "/mm3:{deviation='/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm4 {namespace urn:mm4;prefix mm4; list x {min-elements 5; max-elements 10; config false;}"
"deviation /x {deviate replace {min-elements 20;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/mm4:{deviation='/x'}", 0);
CHECK_LOG_CTX("List min-elements 20 is bigger than max-elements 10.", "/mm4:{deviation='/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm5 {namespace urn:mm5;prefix mm5; leaf-list x {type string; min-elements 5;}"
"deviation /x {deviate add {min-elements 1;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation adding \"min-elements\" property which already exists (with value \"5\").",
"/mm5:{deviation='/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm6 {namespace urn:mm6;prefix mm6; list x {config false; min-elements 5;}"
"deviation /x {deviate add {min-elements 1;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation adding \"min-elements\" property which already exists (with value \"5\").",
"/mm6:{deviation='/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm7 {namespace urn:mm7;prefix mm7; leaf-list x {type string; max-elements 5;}"
"deviation /x {deviate add {max-elements 1;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation adding \"max-elements\" property which already exists (with value \"5\").",
"/mm7:{deviation='/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module mm8 {namespace urn:mm8;prefix mm8; list x {config false; max-elements 5;}"
"deviation /x {deviate add {max-elements 1;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation adding \"max-elements\" property which already exists (with value \"5\").",
"/mm8:{deviation='/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module nn1 {namespace urn:nn1;prefix nn1; anyxml x;"
"deviation /x {deviate replace {type string;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid deviation of anyxml node - it is not possible to replace \"type\" property.", "/nn1:{deviation='/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module nn2 {namespace urn:nn2;prefix nn2; leaf-list x {type string;}"
"deviation /x {deviate replace {type empty;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Compilation of a deviated and/or refined node failed.", "/nn2:{deviation='/x'}", 0);
CHECK_LOG_CTX("Leaf-list of type \"empty\" is allowed only in YANG 1.1 modules.", "/nn2:{deviation='/x'}", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module oo1 {namespace urn:oo1;prefix oo1; leaf x {type uint16; default 300;}"
"deviation /x {deviate replace {type uint8;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid default - value does not fit the type "
"(Value \"300\" is out of type uint8 min/max bounds.).", "/oo1:x", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module oo2 {yang-version 1.1;namespace urn:oo2;prefix oo2; leaf-list x {type uint16; default 10; default 300;}"
"deviation /x {deviate replace {type uint8;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid default - value does not fit the type "
"(Value \"300\" is out of type uint8 min/max bounds.).", "/oo2:x", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module oo3 {namespace urn:oo3;prefix oo3; leaf x {type uint8;}"
"deviation /x {deviate add {default 300;}}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Invalid default - value does not fit the type "
"(Value \"300\" is out of type uint8 min/max bounds.).", "/oo3:x", 0);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX, "module pp {namespace urn:pp;prefix pp; leaf l { type leafref {path /c/x;}}"
"container c {leaf x {type string;} leaf y {type string;}}}", LYS_IN_YANG, &mod));
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module pp1 {namespace urn:pp1;prefix pp1; import pp {prefix pp;}"
"deviation /pp:c/pp:x {deviate not-supported;}}", LYS_IN_YANG, &mod));
CHECK_LOG_CTX("Target of leafref \"l\" cannot be referenced because it is disabled.", "/pp:l", 0);
CHECK_LOG_CTX("Not found node \"x\" in path.", "/pp:l", 0);
}
static void
test_when(void **state)
{
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX,
"module a {\n"
" namespace urn:a;\n"
" prefix a;\n"
" container cont {\n"
" leaf l {\n"
" when \"/cont/lst[val='25']\";\n"
" type empty;\n"
" }\n"
" list lst {\n"
" key \"k\";\n"
" leaf k {\n"
" type uint8;\n"
" }\n"
" leaf val {\n"
" when /cont2;\n"
" type int32;\n"
" }\n"
" }\n"
" }\n"
" container cont2 {\n"
" presence \"a\";\n"
" when ../cont/l;\n"
" }\n"
"}",
LYS_IN_YANG, NULL));
CHECK_LOG_CTX("When condition cyclic dependency on the node \"cont2\".", "/a:cont/lst/val", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX,
"module a {\n"
" namespace urn:a;\n"
" prefix a;\n"
" container cont {\n"
" leaf l {\n"
" when \"/cont/lst[val='25']\";\n"
" type empty;\n"
" }\n"
" list lst {\n"
" key \"k\";\n"
" leaf k {\n"
" type uint8;\n"
" }\n"
" leaf val {\n"
" when /cont2;\n"
" type int32;\n"
" }\n"
" }\n"
" }\n"
" container cont2 {\n"
" presence \"a\";\n"
" when ../cont/lst/val;\n"
" }\n"
"}",
LYS_IN_YANG, NULL));
CHECK_LOG_CTX("When condition cyclic dependency on the node \"cont2\".", "/a:cont/lst/val", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX,
"module a {\n"
" namespace urn:a;\n"
" prefix a;\n"
" leaf val {\n"
" type int64;\n"
" when \"../val='25'\";\n"
" }\n"
"}",
LYS_IN_YANG, NULL));
CHECK_LOG_CTX("When condition is accessing its own conditional node value.", "/a:val", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX,
"module a {\n"
" namespace urn:a;\n"
" prefix a;\n"
" grouping grp {\n"
" leaf val {\n"
" type int64;\n"
" }\n"
" }\n"
" uses grp {\n"
" when \"val='25'\";\n"
" }\n"
"}",
LYS_IN_YANG, NULL));
CHECK_LOG_CTX("When condition is accessing its own conditional node value.", "/a:val", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX,
"module a {\n"
" namespace urn:a;\n"
" prefix a;\n"
" augment /cont {\n"
" when \"val='25'\";\n"
" leaf val {\n"
" type int64;\n"
" }\n"
" }\n"
" container cont;\n"
"}",
LYS_IN_YANG, NULL));
CHECK_LOG_CTX("When condition is accessing its own conditional node value.", "/a:cont/val", 0);
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX,
"module a {\n"
" namespace urn:a;\n"
" prefix a;\n"
" augment /cont {\n"
" when \"aug-cont/aug-l\";\n"
" container aug-cont {\n"
" leaf aug-l {\n"
" type int64;\n"
" }\n"
" }\n"
" }\n"
" container cont;\n"
"}",
LYS_IN_YANG, NULL));
CHECK_LOG_CTX("When condition is accessing its own conditional node children.", "/a:cont/aug-cont", 0);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX,
"module b {\n"
" namespace urn:b;\n"
" prefix b;\n"
" container c {\n"
" list l {\n"
" key name;\n"
" leaf name {\n"
" type string;\n"
" }\n"
"\n"
" container cond-data {\n"
" when \"/c/l2[name = current()/../name]/val = 'value'\";\n"
" leaf cond-leaf {\n"
" type string;\n"
" default \"default_val\";\n"
" }\n"
" }\n"
" }\n"
" list l2 {\n"
" key name;\n"
" leaf name {\n"
" type string;\n"
" }\n"
"\n"
" container c2 {\n"
" leaf val {\n"
" type string;\n"
" }\n"
" }\n"
" }\n"
" }\n"
"}",
LYS_IN_YANG, NULL));
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb,
"module c1 {"
" namespace urn:c1;"
" prefix c1;"
" container my-container {"
" leaf my-type {"
" type string;"
" }"
" }"
"}\n"
"module c2 {"
" namespace \"urn:c2\";"
" prefix c2;"
" grouping my-group {"
" leaf my-leaf {"
" type string;"
" }"
" }"
"}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX,
"module c3 {"
" namespace \"urn:c3\";"
" prefix c3;"
" import c1 {"
" prefix c1;"
" }"
" import c2 {"
" prefix c2;"
" }"
" augment \"/c1:my-container\" {"
" uses c2:my-group {"
" when \"./c1:my-type = '42'\";"
" }"
" }"
"}",
LYS_IN_YANG, NULL));
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb,
"module d1 {"
" namespace urn:d1;"
" prefix d1;"
" container ifm {"
" container interfaces {"
" list interface {"
" key \"name\";"
" leaf name {"
" type string;"
" }"
" container ethernet {"
" container main-interface {"
" container l2-attribute {"
" when \"not(/d1:ifm/d1:interfaces/d1:interface/d1:trunk/d1:members/d1:member[d1:name=current()/../../../d1:name])\";"
" presence \"\";"
" }"
" }"
" }"
" container trunk {"
" container members {"
" list member {"
" key \"name\";"
" leaf name {"
" type string;"
" }"
" }"
" }"
" }"
" }"
" }"
" }"
"}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX,
"module d2 {"
" namespace \"urn:d2\";"
" prefix d2;"
" import d1 {"
" prefix d1;"
" }"
" augment \"/d1:ifm/d1:interfaces/d1:interface/d1:ethernet/d1:main-interface\" {"
" when \"not(d1:l2-attribute)\";"
" container extra-attribute {"
" presence \"\";"
" }"
" }"
"}",
LYS_IN_YANG, NULL));
}
static void
test_must(void **state)
{
/* "*" must not be restricted to any module */
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb,
"module a {"
" namespace urn:a;"
" prefix a;"
" container cont {"
" leaf l {"
" type empty;"
" }"
" list lst {"
" key \"k\";"
" leaf k {"
" type uint8;"
" }"
" }"
" }"
"}");
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX,
"module a-aug {"
" namespace urn:aa;"
" prefix aa;"
" import a {"
" prefix a;"
" }"
" augment /a:cont {"
" container cont2 {"
" must \"/a:cont/*/a:k\";"
" leaf aug {"
" type empty;"
" }"
" }"
" }"
"}",
LYS_IN_YANG, NULL));
/* no warnings */
CHECK_LOG_CTX(NULL, NULL, 0);
/* must referencing disabled leafref in another module */
ly_ctx_set_module_imp_clb(UTEST_LYCTX, test_imp_clb,
"module b-imp {"
" yang-version 1.1;"
" namespace \"urn:b-imp\";"
" prefix \"bi\";"
""
" feature feat;"
""
" grouping band-capabilities {"
" leaf band-number {"
" type uint16;"
" }"
""
" container sub-band-info {"
" when \"../band-number = '46'\";"
" if-feature \"bi:feat\";"
" leaf number-of-laa-scarriers {"
" type uint8;"
" }"
" }"
" }"
""
" container module-capability {"
" list band-capabilities {"
" key band-number;"
" config false;"
" uses band-capabilities;"
" }"
" container rw-sub-band-info {"
" if-feature \"bi:feat\";"
" leaf rw-number-of-laa-scarriers {"
" type leafref {"
" path \"/module-capability/band-capabilities/sub-band-info/number-of-laa-scarriers\";"
" require-instance false;"
" }"
" }"
" }"
" }"
"}");
ly_ctx_set_options(UTEST_LYCTX, LY_CTX_REF_IMPLEMENTED);
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX,
"module b {"
" yang-version 1.1;"
" namespace \"urn:b\";"
" prefix \"b\";"
""
" import b-imp {"
" prefix \"bi\";"
" }"
""
" container laa-config {"
" must \"number-of-laa-scarriers <= /bi:module-capability/bi:rw-sub-band-info/bi:rw-number-of-laa-scarriers\";"
" }"
"}",
LYS_IN_YANG, NULL));
ly_ctx_unset_options(UTEST_LYCTX, LY_CTX_REF_IMPLEMENTED);
CHECK_LOG_CTX("Schema node \"number-of-laa-scarriers\" not found; in expr \"number-of-laa-scarriers\" "
"with context node \"/b:laa-config\".", NULL, 0);
}
static void
test_unique_disabled(void **state)
{
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX,
"module list-unique {"
" namespace urn:lu;"
" prefix lu;"
" feature f;"
" list l {"
" key \"k\";"
" unique \"v\";"
" leaf k {"
" type string;"
" }"
" leaf v {"
" if-feature f;"
" type string;"
" }"
" }"
" list l2 {"
" key \"k\";"
" unique \"v1 v2\";"
" leaf k {"
" type string;"
" }"
" leaf v1 {"
" if-feature f;"
" type string;"
" }"
" leaf v2 {"
" type string;"
" }"
" }"
"}",
LYS_IN_YANG, NULL));
}
int
main(void)
{
const struct CMUnitTest tests[] = {
UTEST(test_module, setup),
UTEST(test_submodule, setup),
UTEST(test_name_collisions, setup),
UTEST(test_type_length, setup),
UTEST(test_type_range, setup),
UTEST(test_type_pattern, setup),
UTEST(test_type_enum, setup),
UTEST(test_type_dec64, setup),
UTEST(test_type_instanceid, setup),
UTEST(test_identity, setup),
UTEST(test_type_identityref, setup),
UTEST(test_type_leafref, setup),
UTEST(test_type_empty, setup),
UTEST(test_type_union, setup),
UTEST(test_type_dflt, setup),
UTEST(test_type_exts, setup),
UTEST(test_status, setup),
UTEST(test_node_container, setup),
UTEST(test_node_leaflist, setup),
UTEST(test_node_list, setup),
UTEST(test_node_choice, setup),
UTEST(test_node_anydata, setup),
UTEST(test_action, setup),
UTEST(test_notification, setup),
UTEST(test_grouping, setup),
UTEST(test_uses, setup),
UTEST(test_refine, setup),
UTEST(test_augment, setup),
UTEST(test_deviation, setup),
UTEST(test_when, setup),
UTEST(test_must, setup),
UTEST(test_unique_disabled, setup),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}
|