@@ -38,6 +38,14 @@ const char *glob_schema =
3838 "}"
3939 "}" ;
4040
41+ const char * mount_schema =
42+ "module mount {yang-version 1.1;namespace \"urn:mount\";prefix \"m\";"
43+ "container root {"
44+ " leaf l1 { type string; must \"/m:root/l1 = 'valid'\"; }"
45+ " leaf l2 { type instance-identifier; }"
46+ "}"
47+ "}" ;
48+
4149static int
4250setup (void * * state )
4351{
@@ -46,6 +54,7 @@ setup(void **state)
4654
4755 assert_int_equal (LY_SUCCESS , ly_ctx_set_searchdir (UTEST_LYCTX , TESTS_DIR_MODULES_YANG ));
4856 assert_int_equal (LY_SUCCESS , lys_parse_mem (UTEST_LYCTX , glob_schema , LYS_IN_YANG , NULL ));
57+ assert_int_equal (LY_SUCCESS , lys_parse_mem (UTEST_LYCTX , mount_schema , LYS_IN_YANG , NULL ));
4958 assert_non_null (ly_ctx_load_module (UTEST_LYCTX , "iana-if-type" , NULL , NULL ));
5059
5160 return 0 ;
@@ -1785,6 +1794,98 @@ test_lys_getnext(void **state)
17851794 assert_null (node );
17861795}
17871796
1797+ static void
1798+ test_xpath (void * * state )
1799+ {
1800+ const char * xml ;
1801+ struct lyd_node * data ;
1802+
1803+ ly_ctx_set_ext_data_clb (UTEST_LYCTX , test_ext_data_clb ,
1804+ "<yang-library xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
1805+ " xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores\">"
1806+ " <module-set>"
1807+ " <name>test-set</name>"
1808+ " <module>"
1809+ " <name>ietf-datastores</name>"
1810+ " <revision>2018-02-14</revision>"
1811+ " <namespace>urn:ietf:params:xml:ns:yang:ietf-datastores</namespace>"
1812+ " </module>"
1813+ " <module>"
1814+ " <name>ietf-yang-library</name>"
1815+ " <revision>2019-01-04</revision>"
1816+ " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-library</namespace>"
1817+ " </module>"
1818+ " <module>"
1819+ " <name>ietf-yang-schema-mount</name>"
1820+ " <revision>2019-01-14</revision>"
1821+ " <namespace>urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount</namespace>"
1822+ " </module>"
1823+ " <module>"
1824+ " <name>mount</name>"
1825+ " <namespace>urn:mount</namespace>"
1826+ " </module>"
1827+ " </module-set>"
1828+ " <schema>"
1829+ " <name>test-schema</name>"
1830+ " <module-set>test-set</module-set>"
1831+ " </schema>"
1832+ " <datastore>"
1833+ " <name>ds:running</name>"
1834+ " <schema>test-schema</schema>"
1835+ " </datastore>"
1836+ " <datastore>"
1837+ " <name>ds:operational</name>"
1838+ " <schema>test-schema</schema>"
1839+ " </datastore>"
1840+ " <content-id>1</content-id>"
1841+ "</yang-library>"
1842+ "<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\">"
1843+ " <module-set-id>1</module-set-id>"
1844+ "</modules-state>"
1845+ "<schema-mounts xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-schema-mount\">"
1846+ " <mount-point>"
1847+ " <module>sm</module>"
1848+ " <label>root</label>"
1849+ " <shared-schema/>"
1850+ " </mount-point>"
1851+ "</schema-mounts>" );
1852+
1853+ /* false must */
1854+ xml =
1855+ "<root xmlns=\"urn:sm\">\n"
1856+ " <root xmlns=\"urn:mount\">\n"
1857+ " <l1>invalid</l1>\n"
1858+ " </root>\n"
1859+ "</root>\n" ;
1860+ CHECK_PARSE_LYD_PARAM (xml , LYD_XML , LYD_PARSE_STRICT , LYD_VALIDATE_PRESENT , LY_EVALID , data );
1861+ CHECK_LOG_CTX ("Ext plugin \"ly2 schema mount v1\": "
1862+ "Must condition \"/m:root/l1 = 'valid'\" not satisfied." ,
1863+ "/mount:root/l1" , 0 );
1864+
1865+ /* non-existing instance-identifier */
1866+ xml =
1867+ "<root xmlns=\"urn:sm\">\n"
1868+ " <root xmlns=\"urn:mount\">\n"
1869+ " <l1>valid</l1>\n"
1870+ " <l2 xmlns:m=\"urn:mount\">/m:root/m:l3</l2>\n"
1871+ " </root>\n"
1872+ "</root>\n" ;
1873+ CHECK_PARSE_LYD_PARAM (xml , LYD_XML , LYD_PARSE_STRICT , LYD_VALIDATE_PRESENT , LY_EVALID , data );
1874+ CHECK_LOG_CTX ("Invalid instance-identifier \"/m:root/m:l3\" value - semantic error: Not found node \"l3\" in path." ,
1875+ "/mount:root/l2" , 4 );
1876+
1877+ /* valid */
1878+ xml =
1879+ "<root xmlns=\"urn:sm\">\n"
1880+ " <root xmlns=\"urn:mount\">\n"
1881+ " <l1>valid</l1>\n"
1882+ " <l2 xmlns:m=\"urn:mount\">/m:root/m:l1</l2>\n"
1883+ " </root>\n"
1884+ "</root>\n" ;
1885+ CHECK_PARSE_LYD_PARAM (xml , LYD_XML , LYD_PARSE_STRICT , LYD_VALIDATE_PRESENT , LY_SUCCESS , data );
1886+ lyd_free_siblings (data );
1887+ }
1888+
17881889int
17891890main (void )
17901891{
@@ -1798,6 +1899,7 @@ main(void)
17981899 UTEST (test_parse_config , setup ),
17991900 UTEST (test_new , setup ),
18001901 UTEST (test_lys_getnext , setup ),
1902+ UTEST (test_xpath , setup ),
18011903 };
18021904
18031905 return cmocka_run_group_tests (tests , NULL , NULL );
0 commit comments