From 85465588b18fef9c4712f864f512e00741e2d4f2 Mon Sep 17 00:00:00 2001 From: Ole Troan Date: Tue, 30 Apr 2019 10:04:36 +0200 Subject: 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 --- .../python/vpp_papi/tests/test_vpp_serializer.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/vpp-api/python/vpp_papi/tests') 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): -- cgit 1.2.3-korg