From 6dec522af1e8dfb158e400c6aa7afd2d8abb3580 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 25 Jun 2019 16:40:04 +0200 Subject: [PATCH] Changed invalid number ranges outside type scope. --- CHANGELOG.md | 4 +-- lib/src/clixon_yang_type.c | 4 +-- test/test_type.sh | 4 +-- test/test_type_range.sh | 69 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 73 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f93f16b3..eb2fe361 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,8 +72,8 @@ * Error messages for invalid number ranges and string lengths have been uniformed and changed. * Error messages for invalid ranges are now on the form: ``` - Number 23 out of range: 1-10 - String length 23 out of range: 1-10 + Number 23 out of range: 1 - 10 + String length 23 out of range: 1 - 10 ``` * On validation callbacks, XML_FLAG_ADD is added to all nodes at startup validation, not just the top-level. This is the same behaviour as for steady-state validation. * All hash_ functions have been prefixed with `clicon_` to avoid name collision with other packages (frr) diff --git a/lib/src/clixon_yang_type.c b/lib/src/clixon_yang_type.c index 61c63d43..d548c75b 100644 --- a/lib/src/clixon_yang_type.c +++ b/lib/src/clixon_yang_type.c @@ -626,7 +626,7 @@ outofrange(cg_var *cv0, if (i>2) cprintf(cb, ", "); cv2cbuf(cv1, cb); - cprintf(cb, "-"); + cprintf(cb, " - "); cv2cbuf(cv2, cb); } if (reason && (*reason = strdup(cbuf_get(cb))) == NULL) @@ -675,7 +675,7 @@ outoflength(uint64_t u64, if (i>2) cprintf(cb, ", "); cv2cbuf(cv1, cb); - cprintf(cb, "-"); + cprintf(cb, " - "); cv2cbuf(cv2, cb); } if (reason && (*reason = strdup(cbuf_get(cb))) == NULL) diff --git a/test/test_type.sh b/test/test_type.sh index c2a37119..978cba77 100755 --- a/test/test_type.sh +++ b/test/test_type.sh @@ -407,7 +407,7 @@ EOF expectfn "$clixon_cli -1f $cfg -l o set num3 42" 0 '^$' new "cli range test num3 260 fail" - expectfn "$clixon_cli -1f $cfg -l o set num3 260" 255 '^CLI syntax error: "set num3 260": 260 is out of range\(type is uint8\)$' + expectfn "$clixon_cli -1f $cfg -l o set num3 260" 255 '^CLI syntax error: "set num3 260": Number 260 out of range: 0-255$' new "cli range test num3 -1 fail" expectfn "$clixon_cli -1f $cfg -l o set num3 -1" 255 "CLI syntax error:" @@ -416,7 +416,7 @@ EOF expecteof "$clixon_netconf -qf $cfg" 0 '260]]>]]>' "^]]>]]>$" new "netconf validate num3 260 fail" - expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" '^applicationbad-elementnum3error260 is out of range(type is uint8)]]>]]>$' + expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" '^applicationbad-elementnum3errorNumber 260 out of range: 0-255]]>]]>$' new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" diff --git a/test/test_type_range.sh b/test/test_type_range.sh index a6c030d0..efd55a60 100755 --- a/test/test_type_range.sh +++ b/test/test_type_range.sh @@ -73,6 +73,7 @@ module example{ length "1..10 | 14..20"; } } + /* here follows constrained ints */ leaf lint8 { type tint8; } @@ -103,6 +104,36 @@ module example{ leaf lstring { type tstring; } + /* here follows unlimited ints */ + leaf rint8 { + type int8; + } + leaf rint16 { + type int16; + } + leaf rint32 { + type int32; + } + leaf rint64 { + type int64; + } + leaf ruint8 { + type uint8; + } + leaf ruint16 { + type uint16; + } + leaf ruint32 { + type uint32; + } + leaf ruint64 { + type uint64; + } + leaf rdecimal64 { + type decimal64{ + fraction-digits 3; + } + } } EOF @@ -168,9 +199,9 @@ testrange(){ if [ $t = "string" ]; then # special case for string type error msg len=$(echo -n "$eval" | wc -c) - errmsg="String length $len out of range: 1$post-10$post, 14$post-20$post" + errmsg="String length $len out of range: 1$post - 10$post, 14$post - 20$post" else - errmsg="Number $eval$post out of range: 1$post-10$post, 14$post-20$post" + errmsg="Number $eval$post out of range: 1$post - 10$post, 14$post - 20$post" fi new "generated cli set $t leaf invalid" @@ -212,6 +243,29 @@ testrange(){ expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" } +# Type unlimited value range test. Only test invalid number out of range of type +# Parameters: 1: type (eg uint8) +# 2: val +# 3: post (eg .000 - special for decimal64, others should have "") +testunlimit(){ + t=$1 + val=$2 + rmin=$3 + rmax=$4 + post=$5 + + errmsg="Number $val$post out of range: $rmin$post - $rmax$post" + + new "Netconf set invalid $t leaf" + expecteof "$clixon_netconf -qf $cfg" 0 "$val]]>]]>" "^]]>]]>$" + + new "netconf validate invalid range" + expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^applicationbad-elementl$terror$errmsg]]>]]>$" + + new "discard" + expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" +} + if [ $BE -ne 0 ]; then new "kill old backend" sudo clixon_backend -zf $cfg @@ -227,6 +281,17 @@ fi new "test params: -f $cfg" +# Test all int types +testunlimit int8 300 -128 127 "" +testunlimit int16 73000 -32768 32767 "" +testunlimit int32 4900000000 -2147483648 2147483647 "" +testunlimit int64 49739274983274983274983274 -9223372036854775808 9223372036854775807 "" +testunlimit uint8 300 0 255 "" +testunlimit uint16 73000 0 65535 "" +testunlimit uint32 4900000000 0 4294967295 "" +testunlimit uint64 49739274983274983274983274 0 18446744073709551615 "" +#testunlimit decimal64 49739274983274983274983274 -9223372036854775808 9223372036854775807 ".000" + # Test all int types for t in int8 int16 int32 int64 uint8 uint16 uint32 uint64; do testrange $t 1 0 ""