summaryrefslogtreecommitdiffstats
path: root/src/vpp-api/python/vpp_papi/tests
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2019-04-30 10:04:36 +0200
committerPaul Vinciguerra <pvinci@vinciconsulting.com>2019-06-07 10:38:35 +0000
commit85465588b18fef9c4712f864f512e00741e2d4f2 (patch)
treed5914b37782edfa7d85a2366e080ca97bc7ece1f /src/vpp-api/python/vpp_papi/tests
parent8dbfb433619011b649b1b511ad88969a7f909861 (diff)
API: Add support for "defaults"
Add support in the API language for specifying a field default. Add default support in Python binding. define foo { u16 mtu [default = 1500]; }; This is client side only. I.e. if the mtu argument is not passed to the foo function, the client language binding will set it default to 1500. Change-Id: I5df43f3cd87cb300b40ca38e15dcab25b40e424a Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/vpp-api/python/vpp_papi/tests')
-rwxr-xr-xsrc/vpp-api/python/vpp_papi/tests/test_vpp_serializer.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/vpp-api/python/vpp_papi/tests/test_vpp_serializer.py b/src/vpp-api/python/vpp_papi/tests/test_vpp_serializer.py
index ec7334712ab..74a0a62c021 100755
--- a/src/vpp-api/python/vpp_papi/tests/test_vpp_serializer.py
+++ b/src/vpp-api/python/vpp_papi/tests/test_vpp_serializer.py
@@ -9,6 +9,7 @@ import logging
import sys
from ipaddress import *
+
class TestLimits(unittest.TestCase):
def test_limit(self):
limited_type = VPPType('limited_type_t',
@@ -16,14 +17,27 @@ class TestLimits(unittest.TestCase):
unlimited_type = VPPType('limited_type_t',
[['string', 'name']])
-
- b = limited_type.pack({'name':'foobar'})
+ b = limited_type.pack({'name': 'foobar'})
self.assertEqual(len(b), 10)
- b = unlimited_type.pack({'name':'foobar'})
+ b = unlimited_type.pack({'name': 'foobar'})
self.assertEqual(len(b), 10)
with self.assertRaises(VPPSerializerValueError):
- b = limited_type.pack({'name':'foobar'*3})
+ b = limited_type.pack({'name': 'foobar'*3})
+
+
+class TestDefaults(unittest.TestCase):
+ def test_defaults(self):
+ default_type = VPPType('default_type_t',
+ [['u16', 'mtu', {'default': 1500, 'limit': 0}]])
+
+ b = default_type.pack({})
+ self.assertEqual(len(b), 2)
+
+ nt, size = default_type.unpack(b)
+ self.assertEqual(len(b), size)
+ self.assertEqual(nt.mtu, 1500)
+
class TestAddType(unittest.TestCase):