diff --git a/lib/src/clixon_xpath.c b/lib/src/clixon_xpath.c index 1557e5db..1a122f56 100644 --- a/lib/src/clixon_xpath.c +++ b/lib/src/clixon_xpath.c @@ -795,7 +795,7 @@ xpath_vec(cxobj *xcur, goto done; } va_end(ap); - *vec=NULL; + *vec = NULL; *veclen = 0; if (xpath_vec_ctx(xcur, nsc, xpath, 0, &xr) < 0) goto done; diff --git a/test/test_netconf_filter.sh b/test/test_netconf_filter.sh index 71cf0683..fccb8d98 100755 --- a/test/test_netconf_filter.sh +++ b/test/test_netconf_filter.sh @@ -65,6 +65,20 @@ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " new "netconf commit" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" +new "given key show key" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "1" + +new "given key show value" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "11" + +# XXX Bug, see https://github.com/clicon/clixon/issues/414 +#new "given value show key" +#expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "1" + +# OK, see motivation of case (2) in https://github.com/clicon/clixon/issues/414 +new "given value show value" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "11" + new "wrong filter type" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "1" "" "operation-failedapplicatioerrorfilter type not supportedtype" diff --git a/test/test_xpath.sh b/test/test_xpath.sh index 9d1dbbc1..044c15c4 100755 --- a/test/test_xpath.sh +++ b/test/test_xpath.sh @@ -4,6 +4,10 @@ # - /aaa/bbb/comment, where "comment" is nodetype # - //b*, combinations of // and "*" # For more (outdated info): https://github.com/clicon/clixon/issues/54 +# Test has three parts: +# - Only XML no YANG +# - negative tests with YANG +# - simple key/value test with YANG # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi @@ -17,6 +21,9 @@ xml3=$dir/xml3.xml xml4=$dir/xml4.xml xmlfn=$dir/xmlfn.xml +fyang=$dir/clixon-example.yang + + cat < $xml @@ -120,6 +127,25 @@ cat < $xmlfn EOF +cat < $fyang +module clixon-example { + yang-version 1.1; + namespace "urn:example:clixon"; + prefix ex; + container table{ + list parameter{ + key name; + leaf name{ + type string; + } + leaf value{ + type string; + } + } + } +} +EOF + new "xpath not(aaa)" expectpart "$($clixon_util_xpath -D $DBG -f $xml -p "not(aaa)")" 0 "bool:false" @@ -325,6 +351,7 @@ expectpart "$($clixon_util_xpath -D $DBG -f $xmlfn -p "root/count/node[99=ancest new "xpath functions as ncname: functioname:count" expectpart "$($clixon_util_xpath -D $DBG -f $xmlfn -p "root/node/ancestor[73=count]")" 0 "73" +# PART 2 # Negative tests from fuzz crashes cat < $dir/1.xml @@ -340,56 +367,88 @@ cat < $dir/1.xpath EOF new "negative xpath 1" -expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y /usr/local/share/clixon/clixon-example@${CLIXON_EXAMPLE_REV}.yang -Y /usr/local/share/clixon < $dir/1.xpath)" 0 "bool:false" +expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "bool:false" cat < $dir/1.xpath ter='x'/ex:table[exmeter='x'] EOF new "negative xpath 2" -expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y /usr/local/share/clixon/clixon-example@${CLIXON_EXAMPLE_REV}.yang -Y /usr/local/share/clixon < $dir/1.xpath)" 0 "bool:false" +expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "bool:false" cat < $dir/1.xpath /ex:table $dir/1.xpath 7/ex:table['x'] EOF new "negative xpath 4" -expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y /usr/local/share/clixon/clixon-example@${CLIXON_EXAMPLE_REV}.yang -Y /usr/local/share/clixon < $dir/1.xpath)" 0 "number:7" +expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "number:7" cat < $dir/1.xpath />meter*//ter EOF new "negative xpath 5" -expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y /usr/local/share/clixon/clixon-example@${CLIXON_EXAMPLE_REV}.yang -Y /usr/local/share/clixon < $dir/1.xpath)" 0 "bool:false" +expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "bool:false" cat < $dir/1.xpath 7=/ ter EOF new "negative xpath 6" -expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y /usr/local/share/clixon/clixon-example@${CLIXON_EXAMPLE_REV}.yang -Y /usr/local/share/clixon < $dir/1.xpath)" 0 "bool:false" +expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "bool:false" cat < $dir/1.xpath /=7 ter EOF new "negative xpath 7" -#expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y /usr/local/share/clixon/clixon-example@${CLIXON_EXAMPLE_REV}.yang -Y /usr/local/share/clixon < $dir/1.xpath)" 0 "bool:false" +#expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "bool:false" cat < $dir/1.xpath *<-9**** EOF new "negative xpath 8" -expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y /usr/local/share/clixon/clixon-example@${CLIXON_EXAMPLE_REV}.yang -Y /usr/local/share/clixon < $dir/1.xpath)" 0 "bool:false" +expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "bool:false" + +# PART 3 + + +cat < $dir/1.xpath +/table/parameter[name='x']/name +EOF + +new "given key show key" +expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "x" + +cat < $dir/1.xpath +/table/parameter[name='x']/value +EOF + +new "given key show value" +expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "42" + +cat < $dir/1.xpath +/table/parameter[value='42']/name +EOF + +new "given value show key" +expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "x" + + +cat < $dir/1.xpath +/table/parameter[value='42']/value +EOF + +new "given value show value" +expectpart "$($clixon_util_xpath -D $DBG -f $dir/1.xml -n ex:urn:example:clixon -y $fyang < $dir/1.xpath)" 0 "42" rm -rf $dir