1616#include "utests.h"
1717
1818#include "in.h"
19- #include "ly_common.h"
20- #include "parser_internal.h"
21- #include "path.h"
2219#include "plugins_types.h"
23- #include "schema_compile.h"
24- #include "xpath.h"
2520
2621static int
2722setup (void * * state )
@@ -89,15 +84,13 @@ test_module(void **state)
8984 struct lys_module * mod = NULL ;
9085 struct lysp_feature * f ;
9186 struct lysc_iffeature * iff ;
92- struct lys_glob_unres unres = {0 };
9387
9488 str = "module test {namespace urn:test; prefix t;"
9589 "feature f1;feature f2 {if-feature f1;}}" ;
9690 assert_int_equal (LY_SUCCESS , ly_in_new_memory (str , & in ));
97- assert_int_equal (LY_SUCCESS , lys_parse_in (UTEST_LYCTX , in , LYS_IN_YANG , NULL , & unres .creating , & mod ));
98- lys_unres_glob_erase (& unres );
91+ assert_int_equal (LY_SUCCESS , lys_parse (UTEST_LYCTX , in , LYS_IN_YANG , NULL , & mod ));
9992 ly_in_free (in , 0 );
100- assert_int_equal (0 , mod -> implemented );
93+ assert_int_equal (1 , mod -> implemented );
10194 assert_int_equal (LY_EINVAL , lys_set_implemented (mod , feats ));
10295 CHECK_LOG_CTX ("Feature \"invalid\" not found in module \"test@<none>\"." , NULL , 0 );
10396 assert_int_equal (LY_SUCCESS , lys_set_implemented (mod , NULL ));
@@ -120,8 +113,7 @@ test_module(void **state)
120113 /* submodules cannot be compiled directly */
121114 str = "submodule test {belongs-to xxx {prefix x;}}" ;
122115 assert_int_equal (LY_SUCCESS , ly_in_new_memory (str , & in ));
123- assert_int_equal (LY_EINVAL , lys_parse_in (UTEST_LYCTX , in , LYS_IN_YANG , NULL , & unres .creating , NULL ));
124- lys_unres_glob_erase (& unres );
116+ assert_int_equal (LY_EINVAL , lys_parse (UTEST_LYCTX , in , LYS_IN_YANG , NULL , NULL ));
125117 ly_in_free (in , 0 );
126118 CHECK_LOG_CTX ("Input data contains submodule which cannot be parsed directly without its main module." , NULL , 0 );
127119
@@ -1701,49 +1693,31 @@ test_type_leafref(void **state)
17011693 char * str ;
17021694 struct lys_module * mod ;
17031695 struct lysc_type * type ;
1704- const char * path ;
1705- struct lyxp_expr * expr ;
1706-
1707- /* lys_path_parse() */
1708- path = "invalid_path" ;
1709- assert_int_equal (LY_EVALID , ly_path_parse (UTEST_LYCTX , NULL , path , strlen (path ), 1 , LY_PATH_BEGIN_EITHER ,
1710- LY_PATH_PREFIX_OPTIONAL , LY_PATH_PRED_LEAFREF , & expr ));
1711- CHECK_LOG_CTX ("Unexpected XPath token \"NameTest\" (\"invalid_path\"), expected \"..\"." , NULL , 0 );
1712-
1713- path = ".." ;
1714- assert_int_equal (LY_EVALID , ly_path_parse (UTEST_LYCTX , NULL , path , strlen (path ), 1 , LY_PATH_BEGIN_EITHER ,
1715- LY_PATH_PREFIX_OPTIONAL , LY_PATH_PRED_LEAFREF , & expr ));
1716- CHECK_LOG_CTX ("Unexpected XPath expression end." , NULL , 0 );
1717-
1718- path = "..[" ;
1719- assert_int_equal (LY_EVALID , ly_path_parse (UTEST_LYCTX , NULL , path , strlen (path ), 1 , LY_PATH_BEGIN_EITHER ,
1720- LY_PATH_PREFIX_OPTIONAL , LY_PATH_PRED_LEAFREF , & expr ));
1721- CHECK_LOG_CTX ("Unexpected XPath token \"[\" (\"[\"), expected \"Operator(Path)\"." , NULL , 0 );
1722-
1723- path = "../" ;
1724- assert_int_equal (LY_EVALID , ly_path_parse (UTEST_LYCTX , NULL , path , strlen (path ), 1 , LY_PATH_BEGIN_EITHER ,
1725- LY_PATH_PREFIX_OPTIONAL , LY_PATH_PRED_LEAFREF , & expr ));
1726- CHECK_LOG_CTX ("Unexpected XPath expression end." , NULL , 0 );
1727-
1728- path = "/" ;
1729- assert_int_equal (LY_EVALID , ly_path_parse (UTEST_LYCTX , NULL , path , strlen (path ), 1 , LY_PATH_BEGIN_EITHER ,
1730- LY_PATH_PREFIX_OPTIONAL , LY_PATH_PRED_LEAFREF , & expr ));
1731- CHECK_LOG_CTX ("Unexpected XPath expression end." , NULL , 0 );
1732-
1733- path = "../../pref:id/xxx[predicate]/invalid!!!" ;
1734- assert_int_equal (LY_EVALID , ly_path_parse (UTEST_LYCTX , NULL , path , strlen (path ), 1 , LY_PATH_BEGIN_EITHER ,
1735- LY_PATH_PREFIX_OPTIONAL , LY_PATH_PRED_LEAFREF , & expr ));
1736- CHECK_LOG_CTX ("Invalid character 0x21 ('!'), perhaps \"invalid\" is supposed to be a function call." , NULL , 0 );
1737-
1738- path = "/absolute/prefix:path" ;
1739- assert_int_equal (LY_SUCCESS , ly_path_parse (UTEST_LYCTX , NULL , path , strlen (path ), 1 , LY_PATH_BEGIN_EITHER ,
1740- LY_PATH_PREFIX_OPTIONAL , LY_PATH_PRED_LEAFREF , & expr ));
1741- assert_int_equal (4 , expr -> used );
1742- assert_int_equal (LYXP_TOKEN_OPER_PATH , expr -> tokens [0 ]);
1743- assert_int_equal (LYXP_TOKEN_NAMETEST , expr -> tokens [1 ]);
1744- assert_int_equal (LYXP_TOKEN_OPER_PATH , expr -> tokens [2 ]);
1745- assert_int_equal (LYXP_TOKEN_NAMETEST , expr -> tokens [3 ]);
1746- lyxp_expr_free (expr );
1696+ char yang [512 ];
1697+ size_t i ;
1698+ const char * invalid [] = {
1699+ "invalid_path" ,
1700+ "..[" ,
1701+ "../" ,
1702+ "/" ,
1703+ "../../pref:id/xxx[predicate]/invalid!!!"
1704+ };
1705+
1706+ /* 1. Test Invalid Paths */
1707+ for (i = 0 ; i < sizeof (invalid ) / sizeof (invalid [0 ]); ++ i ) {
1708+ snprintf (yang , sizeof (yang ), "module a {namespace urn:a;prefix a; leaf l { type leafref { path \"%s\"; } } }" , invalid [i ]);
1709+ assert_int_equal (LY_EVALID , lys_parse_mem (UTEST_LYCTX , yang , LYS_IN_YANG , NULL ));
1710+ UTEST_LOG_CTX_CLEAN ;
1711+ }
1712+
1713+ /* 2. Test Valid Path */
1714+ const char * valid_yang =
1715+ "module v {namespace urn:v; prefix prefix;"
1716+ " container absolute { leaf path { type string; } }"
1717+ " leaf l { type leafref { path \"/absolute/prefix:path\"; } }"
1718+ "}" ;
1719+
1720+ assert_int_equal (LY_SUCCESS , lys_parse_mem (UTEST_LYCTX , valid_yang , LYS_IN_YANG , NULL ));
17471721
17481722 /* complete leafref paths */
17491723 assert_int_equal (LY_SUCCESS , lys_parse_mem (UTEST_LYCTX , "module a {yang-version 1.1;namespace urn:a;prefix a;"
@@ -1752,15 +1726,14 @@ test_type_leafref(void **state)
17521726 type = ((struct lysc_node_leaf * )mod -> compiled -> data )-> type ;
17531727 assert_non_null (type );
17541728 assert_int_equal (LY_TYPE_LEAFREF , type -> basetype );
1755- assert_string_equal ("/a:target1" , ((struct lysc_type_leafref * )type )-> path -> expr );
1756- assert_ptr_equal (mod , ly_resolve_prefix (UTEST_LYCTX , "a" , 1 , LY_VALUE_SCHEMA_RESOLVED , ((struct lysc_type_leafref * )type )-> prefixes ));
1729+ assert_string_equal ("/a:target1" , lyxp_get_expr (((struct lysc_type_leafref * )type )-> path ));
17571730 assert_non_null (((struct lysc_type_leafref * )type )-> realtype );
17581731 assert_int_equal (LY_TYPE_STRING , ((struct lysc_type_leafref * )type )-> realtype -> basetype );
17591732 assert_int_equal (1 , ((struct lysc_type_leafref * )type )-> require_instance );
17601733 type = ((struct lysc_node_leaf * )mod -> compiled -> data -> next )-> type ;
17611734 assert_non_null (type );
17621735 assert_int_equal (LY_TYPE_LEAFREF , type -> basetype );
1763- assert_string_equal ("/a/target2" , (( struct lysc_type_leafref * )type )-> path -> expr );
1736+ assert_string_equal ("/a/target2" , lyxp_get_expr ((( struct lysc_type_leafref * )type )-> path ) );
17641737 assert_int_equal (1 , LY_ARRAY_COUNT (((struct lysc_type_leafref * )type )-> prefixes ));
17651738 assert_non_null (((struct lysc_type_leafref * )type )-> realtype );
17661739 assert_int_equal (LY_TYPE_UINT8 , ((struct lysc_type_leafref * )type )-> realtype -> basetype );
@@ -1773,8 +1746,7 @@ test_type_leafref(void **state)
17731746 assert_non_null (type );
17741747 assert_int_equal (1 , type -> refcount );
17751748 assert_int_equal (LY_TYPE_LEAFREF , type -> basetype );
1776- assert_string_equal ("/b:target" , ((struct lysc_type_leafref * )type )-> path -> expr );
1777- assert_ptr_equal (mod , ly_resolve_prefix (UTEST_LYCTX , "b" , 1 , LY_VALUE_SCHEMA_RESOLVED , ((struct lysc_type_leafref * )type )-> prefixes ));
1749+ assert_string_equal ("/b:target" , lyxp_get_expr (((struct lysc_type_leafref * )type )-> path ));
17781750 assert_non_null (((struct lysc_type_leafref * )type )-> realtype );
17791751 assert_int_equal (LY_TYPE_STRING , ((struct lysc_type_leafref * )type )-> realtype -> basetype );
17801752 assert_int_equal (1 , ((struct lysc_type_leafref * )type )-> require_instance );
@@ -1787,17 +1759,15 @@ test_type_leafref(void **state)
17871759 assert_non_null (type );
17881760 assert_int_equal (1 , type -> refcount );
17891761 assert_int_equal (LY_TYPE_LEAFREF , type -> basetype );
1790- assert_string_equal ("/b:target" , ((struct lysc_type_leafref * )type )-> path -> expr );
1791- assert_ptr_not_equal (mod , ly_resolve_prefix (UTEST_LYCTX , "b" , 1 , LY_VALUE_SCHEMA_RESOLVED , ((struct lysc_type_leafref * )type )-> prefixes ));
1762+ assert_string_equal ("/b:target" , lyxp_get_expr (((struct lysc_type_leafref * )type )-> path ));
17921763 assert_non_null (((struct lysc_type_leafref * )type )-> realtype );
17931764 assert_int_equal (LY_TYPE_STRING , ((struct lysc_type_leafref * )type )-> realtype -> basetype );
17941765 assert_int_equal (0 , ((struct lysc_type_leafref * )type )-> require_instance );
17951766 type = ((struct lysc_node_leaf * )mod -> compiled -> data -> next )-> type ;
17961767 assert_non_null (type );
17971768 assert_int_equal (1 , type -> refcount );
17981769 assert_int_equal (LY_TYPE_LEAFREF , type -> basetype );
1799- assert_string_equal ("/b:target" , ((struct lysc_type_leafref * )type )-> path -> expr );
1800- assert_ptr_not_equal (mod , ly_resolve_prefix (UTEST_LYCTX , "b" , 1 , LY_VALUE_SCHEMA_RESOLVED , ((struct lysc_type_leafref * )type )-> prefixes ));
1770+ assert_string_equal ("/b:target" , lyxp_get_expr (((struct lysc_type_leafref * )type )-> path ));
18011771 assert_int_equal (1 , ((struct lysc_type_leafref * )type )-> require_instance );
18021772
18031773 /* non-prefixed nodes in path are supposed to be from the module where the leafref type is instantiated */
@@ -1807,7 +1777,7 @@ test_type_leafref(void **state)
18071777 assert_non_null (type );
18081778 assert_int_equal (1 , type -> refcount );
18091779 assert_int_equal (LY_TYPE_LEAFREF , type -> basetype );
1810- assert_string_equal ("/target" , (( struct lysc_type_leafref * )type )-> path -> expr );
1780+ assert_string_equal ("/target" , lyxp_get_expr ((( struct lysc_type_leafref * )type )-> path ) );
18111781 assert_int_equal (1 , LY_ARRAY_COUNT (((struct lysc_type_leafref * )type )-> prefixes ));
18121782 assert_non_null (((struct lysc_type_leafref * )type )-> realtype );
18131783 assert_int_equal (LY_TYPE_INT8 , ((struct lysc_type_leafref * )type )-> realtype -> basetype );
@@ -1847,12 +1817,12 @@ test_type_leafref(void **state)
18471817 "container default-address{leaf ifname{type leafref{ path \"../../interface/name\";}}"
18481818 "leaf address {type leafref{ path \"../../interface[ name = current()/../ifname ]/address/ip\";}}}}" ,
18491819 LYS_IN_YANG , & mod ));
1850- type = ((struct lysc_node_leaf * )(* lysc_node_child_p (mod -> compiled -> data -> prev )) -> prev )-> type ;
1820+ type = ((struct lysc_node_leaf * )(lysc_node_child (mod -> compiled -> data -> prev )-> prev ) )-> type ;
18511821 assert_non_null (type );
18521822 assert_int_equal (1 , type -> refcount );
18531823 assert_int_equal (LY_TYPE_LEAFREF , type -> basetype );
18541824 assert_string_equal ("../../interface[ name = current()/../ifname ]/address/ip" ,
1855- (( struct lysc_type_leafref * )type )-> path -> expr );
1825+ lyxp_get_expr ((( struct lysc_type_leafref * )type )-> path ) );
18561826 assert_int_equal (1 , LY_ARRAY_COUNT (((struct lysc_type_leafref * )type )-> prefixes ));
18571827 assert_non_null (((struct lysc_type_leafref * )type )-> realtype );
18581828 assert_int_equal (LY_TYPE_STRING , ((struct lysc_type_leafref * )type )-> realtype -> basetype );
@@ -1865,7 +1835,7 @@ test_type_leafref(void **state)
18651835 assert_non_null (type );
18661836 assert_int_equal (1 , type -> refcount );
18671837 assert_int_equal (LY_TYPE_LEAFREF , type -> basetype );
1868- assert_string_equal ("/endpoint-parent[id=current()/../field]/endpoint/name" , (( struct lysc_type_leafref * )type )-> path -> expr );
1838+ assert_string_equal ("/endpoint-parent[id=current()/../field]/endpoint/name" , lyxp_get_expr ((( struct lysc_type_leafref * )type )-> path ) );
18691839 assert_int_equal (1 , LY_ARRAY_COUNT (((struct lysc_type_leafref * )type )-> prefixes ));
18701840 assert_non_null (((struct lysc_type_leafref * )type )-> realtype );
18711841 assert_int_equal (LY_TYPE_STRING , ((struct lysc_type_leafref * )type )-> realtype -> basetype );
@@ -1909,7 +1879,7 @@ test_type_leafref(void **state)
19091879 assert_non_null (type );
19101880 assert_int_equal (1 , type -> refcount );
19111881 assert_int_equal (LY_TYPE_LEAFREF , type -> basetype );
1912- assert_string_equal ("../target" , (( struct lysc_type_leafref * )type )-> path -> expr );
1882+ assert_string_equal ("../target" , lyxp_get_expr ((( struct lysc_type_leafref * )type )-> path ) );
19131883 assert_non_null (((struct lysc_type_leafref * )type )-> realtype );
19141884 assert_int_equal (LY_TYPE_BOOL , ((struct lysc_type_leafref * )type )-> realtype -> basetype );
19151885 assert_non_null (((struct lysc_node_leaf * )mod -> compiled -> data )-> dflt .str );
@@ -3133,11 +3103,11 @@ test_deviation(void **state)
31333103 assert_non_null (node = mod -> compiled -> data );
31343104 assert_string_equal ("c1" , node -> name );
31353105 assert_int_equal (2 , LY_ARRAY_COUNT (((struct lysc_node_leaf * )node )-> musts ));
3136- assert_string_equal ("3" , (( struct lysc_node_leaf * )node )-> musts [1 ].cond -> expr );
3106+ assert_string_equal ("3" , lyxp_get_expr ((( struct lysc_node_leaf * )node )-> musts [1 ].cond ) );
31373107 assert_non_null (node = node -> next );
31383108 assert_string_equal ("c2" , node -> name );
31393109 assert_int_equal (1 , LY_ARRAY_COUNT (((struct lysc_node_container * )node )-> musts ));
3140- assert_string_equal ("1" , (( struct lysc_node_container * )node )-> musts [0 ].cond -> expr );
3110+ assert_string_equal ("1" , lyxp_get_expr ((( struct lysc_node_container * )node )-> musts [0 ].cond ) );
31413111 assert_non_null (node = node -> next );
31423112 assert_string_equal ("c3" , node -> name );
31433113 assert_null (((struct lysc_node_leaf * )node )-> musts );
0 commit comments