clixon/test/test_json.sh
Olof hagsand e7b60619da * Pushed tag to 4.0.1.PRE
* Restconf RFC 8040 increased feature compliance
  * Cache-Control: no-cache added in HTTP responses (RFC Section 5.5)
  * Restconf monitoring capabilities (RFC Section 9.1)
* Added support for Yang extensions
  * New plugin callback: ca_extension
  * Main backend example includes example code on how to implement a Yang extension in a plugin.
* JSON changes
  * Non-pretty-print output removed all extra spaces.
    * Example: `{"nacm-example:x": 42}` --> {"nacm-example:x":42}`
  * Empty JSON container changed from `null` to `{}`.
    * Empty list and leafs remain as `null`
* Removed unnecessary configure dependencies
  * libnsl, libcrypt, libm, if_vlan,...
* pseudo-plugin added, to enable callbacks also for main programs. Useful for extensions
* Yang Unique statements with multiple schema identifiers did not work on some platforms due to memory error.
2019-07-23 22:11:14 +02:00

85 lines
2.1 KiB
Bash
Executable file

#!/bin/bash
# Test: JSON parser tests. See RFC7951
# - Multi-line + pretty-print
# - Empty values
# Note that members should not be quoted. See test_restconf2.sh for typed
#PROG="valgrind --leak-check=full --show-leak-kinds=all ../util/clixon_util_json"
# Magic line must be first in script (see README.md)
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
: ${clixon_util_json:=clixon_util_json}
fyang=$dir/json.yang
cat <<EOF > $fyang
module json{
prefix ex;
namespace "urn:example:clixon";
leaf a{
type int32;
}
container c{
leaf a{
type int32;
}
leaf s{
type string;
}
}
}
EOF
new "test params: -y $fyang"
# No yang
new "json parse to xml"
expecteofx "$clixon_util_json" 0 '{"foo": -23}' "<foo>-23</foo>"
new "json parse to json" # should be {"foo": -23}
expecteofx "$clixon_util_json -j" 0 '{"foo": -23}' '{"foo":"-23"}'
new "json parse list xml"
expecteofx "$clixon_util_json" 0 '{"a":[0,1,2,3]}' "<a>0</a><a>1</a><a>2</a><a>3</a>"
new "json parse list json" # should be {"a":[0,1,2,3]}
expecteofx "$clixon_util_json -j" 0 '{"a":[0,1,2,3]}' '{"a":"0"}{"a":"1"}{"a":"2"}{"a":"3"}'
# Multi-line JOSN not pretty-print
JSON='{"json:c":{"a":42,"s":"string"}}'
# Same with pretty-print
JSONP='{
"json:c": {
"a": 42,
"s": "string"
}
}'
new "json no pp in/out"
expecteofx "$clixon_util_json -jy $fyang" 0 "$JSON" "$JSON"
new "json pp in/out"
expecteofeq "$clixon_util_json -jpy $fyang" 0 "$JSONP" "$JSONP"
new "json pp in/ no pp out"
expecteofeq "$clixon_util_json -jy $fyang" 0 "$JSONP" "$JSON"
new "json no pp in/ pp out"
expecteofeq "$clixon_util_json -jpy $fyang" 0 "$JSON" "$JSONP"
JSON='{"json:a":-23}'
new "json leaf back to json"
expecteofx "$clixon_util_json -j -y $fyang" 0 "$JSON" "$JSON"
JSON='{"json:c":{"a":937}}'
new "json parse container back to json"
expecteofx "$clixon_util_json -j -y $fyang" 0 "$JSON" "$JSON"
# This should work
if false; then
JSON='{"json:c": {"s": "<![CDATA[ z > x & x < y ]]>"}}'
new "json parse cdata xml"
expecteofx "$clixon_util_json -j -y $fyang" 0 "$JSON" "$JSON"
fi
rm -rf $dir