@@ -1894,23 +1894,30 @@ static void
18941894test_compiled_print (void * * state )
18951895{
18961896 int size , fd ;
1897- void * mem , * mem_end , * printed_ctx_mem ;
1897+ void * mem , * mem_end ;
18981898 struct lyd_node * tree = NULL ;
18991899 struct ly_ctx * printed_ctx = NULL ;
1900+ struct lys_module * mod = NULL ;
1901+ const char * yang , * xml ;
1902+ struct lysc_ext_instance * ext ;
1903+ const char * features [] = {"feat" , NULL };
19001904
1901- /* recreate the context, get rid of all the plugins and use builtin/static only */
1905+ /* recreate the context, using builtin/static plugins only */
19021906 ly_ctx_destroy (UTEST_LYCTX );
19031907 assert_int_equal (LY_SUCCESS , ly_ctx_new (NULL , LY_CTX_BUILTIN_PLUGINS_ONLY | LY_CTX_STATIC_PLUGINS_ONLY , & UTEST_LYCTX ));
19041908
1905- /* load another module */
1906- assert_int_equal (LY_SUCCESS , lys_parse_mem (UTEST_LYCTX , "module c {yang-version 1.1; namespace urn:c;prefix c;"
1909+ /* load the base module */
1910+ yang = "module m1 {yang-version 1.1; namespace urn:m1;prefix m1;"
1911+ "import ietf-yang-metadata {prefix md;}"
1912+ "identity baseid;"
1913+ "identity id1 {base baseid;}"
19071914 "feature feat;"
1908- "feature feat2; "
1915+ "container root { "
19091916 "leaf a {type instance-identifier;}"
1910- "leaf b {type boolean; must \"/a\";}"
1911- "leaf c {type binary; when \"/c: b = 'true'\";}"
1917+ "leaf b {type boolean; must \"/m1:root/ a\";}"
1918+ "leaf c {type binary; when \"/m1:root/ b = 'true'\";}"
19121919 "leaf d {type decimal64 {fraction-digits 2;}}"
1913- "leaf-list e {type instance-identifier; default \"/c: a\"; default \"/c: b\"; default \"/c :c\";}"
1920+ "leaf-list e {type instance-identifier; default \"/m1:root/m1: a\"; default \"/m1:root/m1: b\"; default \"/m1:root/m1 :c\";}"
19141921 "anydata f;"
19151922 "list g {"
19161923 " key a;"
@@ -1922,12 +1929,48 @@ test_compiled_print(void **state)
19221929 " leaf d {type empty;}"
19231930 " leaf e {type int8;}"
19241931 "}"
1932+ "}"
19251933 "rpc h {"
19261934 " input {leaf a {type string;}}"
19271935 "}"
1928- "}" , LYS_IN_YANG , NULL ));
1936+ "md:annotation i {"
1937+ " description \"test\";"
1938+ " if-feature feat;"
1939+ " reference \"test\";"
1940+ " status \"current\";"
1941+ " type uint8;"
1942+ " units meters;"
1943+ "}"
1944+ "}" ;
1945+ UTEST_ADD_MODULE (yang , LYS_IN_YANG , features , NULL );
1946+
1947+ /* load an augment of the base module */
1948+ yang = "module m2 {namespace urn:m2;prefix m2;"
1949+ "import m1 {prefix m1;}"
1950+ "identity id2 {base m1:baseid;}"
1951+ "grouping leaf_group {leaf a {type identityref {base m1:baseid;}}}"
1952+ "augment /m1:root {uses leaf_group;}}" ;
1953+ assert_int_equal (LY_SUCCESS , lys_parse_mem (UTEST_LYCTX , yang , LYS_IN_YANG , NULL ));
1954+
1955+ /* load a structure extension module */
1956+ yang = "module m3 {yang-version 1.1; namespace urn:m3; prefix m3;"
1957+ "import ietf-yang-structure-ext {prefix sx;}"
1958+ "sx:structure struct { container a { leaf b { type string;}}}}" ;
1959+ UTEST_ADD_MODULE (yang , LYS_IN_YANG , NULL , & mod );
1960+
1961+ /* load a structure augment extension module */
1962+ yang = "module m4 {yang-version 1.1; namespace urn:m4; prefix m4;"
1963+ "import ietf-yang-structure-ext {prefix sx;}"
1964+ "import m3 {prefix m3;}"
1965+ "sx:augment-structure \"/m3:struct/m3:a\" {"
1966+ " leaf c {type uint32;}"
1967+ "}}" ;
1968+ UTEST_ADD_MODULE (yang , LYS_IN_YANG , NULL , NULL );
1969+
1970+ /* get the structure extension */
1971+ assert_non_null (ext = & mod -> compiled -> exts [0 ]);
19291972
1930- /* get the size */
1973+ /* get the size of the compiled ctx */
19311974 size = ly_ctx_compiled_size (UTEST_LYCTX );
19321975
19331976 /* prepare the shared memory segment */
@@ -1937,31 +1980,57 @@ test_compiled_print(void **state)
19371980 mem = mmap (NULL , size , PROT_READ | PROT_WRITE , MAP_SHARED , fd , 0 );
19381981 assert_ptr_not_equal (mem , MAP_FAILED );
19391982
1940- /* print the context */
1983+ /* print the context into the shared memory */
19411984 assert_int_equal (LY_SUCCESS , ly_ctx_compiled_print (UTEST_LYCTX , mem , & mem_end ));
19421985 assert_int_equal ((char * )mem_end - (char * )mem , size );
19431986
1944- /* remap the region and parse the context from mem */
1945- munmap (mem , size );
1987+ /* create a new printed ctx from this address */
1988+ assert_int_equal (LY_SUCCESS , ly_ctx_new_printed (mem , & printed_ctx ));
1989+
1990+ /* try to parse data with the printed ctx */
1991+ xml = "<root xmlns=\"urn:m1\">\n"
1992+ " <a xmlns:m1=\"urn:m1\">/m1:root/m1:b</a>\n"
1993+ " <b>true</b>\n"
1994+ " <c>Zm9vYmFy</c>\n"
1995+ " <d xmlns:m1=\"urn:m1\" m1:i=\"4\">123.45</d>\n"
1996+ " <e xmlns:m1=\"urn:m1\">/m1:root/m1:a</e>\n"
1997+ " <e xmlns:m1=\"urn:m1\">/m1:root/m1:b</e>\n"
1998+ " <e xmlns:m1=\"urn:m1\">/m1:root/m1:c</e>\n"
1999+ " <f>\n"
2000+ " <custom-data>\n"
2001+ " <item>abc</item>\n"
2002+ " </custom-data>\n"
2003+ " </f>\n"
2004+ " <g>\n"
2005+ " <a>key</a>\n"
2006+ " <b>unique</b>\n"
2007+ " <c>123</c>\n"
2008+ " <d/>\n"
2009+ " <e>-10</e>\n"
2010+ " </g>\n"
2011+ " <a xmlns=\"urn:m2\" xmlns:m1=\"urn:m1\">m1:id1</a>\n"
2012+ "</root>\n" ;
2013+ assert_int_equal (LY_SUCCESS , lyd_parse_data_mem (printed_ctx , xml ,
2014+ LYD_XML , LYD_PARSE_STRICT , LYD_VALIDATE_PRESENT , & tree ));
2015+
2016+ CHECK_LYD_STRING_PARAM (tree , xml , LYD_XML , 0 );
2017+ lyd_free_all (tree );
19462018
1947- /* mmap the same address again */
1948- printed_ctx_mem = mmap (mem , size , PROT_READ , MAP_PRIVATE | MAP_FIXED_NOREPLACE , fd , 0 );
1949- assert_ptr_not_equal (printed_ctx_mem , MAP_FAILED );
2019+ /* parse structure extension data with the printed ctx */
2020+ xml = "<a xmlns=\"urn:m3\">\n"
2021+ " <b>abc</b>\n"
2022+ " <c xmlns=\"urn:m4\">24</c>\n"
2023+ "</a>\n" ;
2024+ assert_int_equal (LY_SUCCESS , ly_in_new_memory (xml , & UTEST_IN ));
2025+ assert_int_equal (LY_SUCCESS , lyd_parse_ext_data (ext , NULL , UTEST_IN , LYD_XML , LYD_PARSE_STRICT , LYD_VALIDATE_PRESENT , & tree ));
19502026
1951- /* create a new printed ctx from this address */
1952- assert_int_equal (LY_SUCCESS , ly_ctx_new_printed (printed_ctx_mem , & printed_ctx ));
2027+ CHECK_LYD_STRING_PARAM (tree , xml , LYD_XML , 0 );
19532028
1954- /* try to parse data with it */
1955- assert_int_equal (LY_SUCCESS , lyd_parse_data_mem (printed_ctx ,
1956- "<a xmlns=\"urn:c\" xmlns:c=\"urn:c\">/c:b</a>"
1957- "<b xmlns=\"urn:c\">true</b>"
1958- "<c xmlns=\"urn:c\">ahoi</c>" ,
1959- LYD_XML , 0 , LYD_VALIDATE_PRESENT , & tree ));
2029+ lyd_free_all (tree );
19602030
19612031 /* cleanup */
1962- lyd_free_all (tree );
19632032 ly_ctx_destroy (printed_ctx );
1964- munmap (printed_ctx_mem , size );
2033+ munmap (mem , size );
19652034 close (fd );
19662035 shm_unlink ("/ly_test_schema_ctx" );
19672036}
0 commit comments