aboutsummaryrefslogtreecommitdiffstats
path: root/src/vpp-api/python/vpp_papi/tests
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2019-10-22 14:01:53 +0200
committerDamjan Marion <dmarion@me.com>2019-10-23 07:47:19 +0000
commit40dc4b35e3d946efbc5c2b8b0af5e52d67b7fe6c (patch)
tree2edb78cde19a3ca4b2ae8a9ae58428a1a21caced /src/vpp-api/python/vpp_papi/tests
parentd6ae4bf13a7819d64d128d196d491af4700fa948 (diff)
papi: fix default handling
The BaseTypers object were reused, so a default for anyother mesage would be inherited in new messages. Type: fix Fixes: 85465588b18fef9c4712f864f512e00741e2d4f2 Change-Id: Ie1efb85a76b088653eb9ea4b88540c98b6b0aad0 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.py31
1 files changed, 30 insertions, 1 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 9ac3e78224c..5221034da6c 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
@@ -66,14 +66,43 @@ class TestDefaults(unittest.TestCase):
def test_defaults(self):
default_type = VPPType('default_type_t',
[['u16', 'mtu', {'default': 1500, 'limit': 0}]])
+ without_default_type = VPPType('without_default_type_t',
+ [['u16', 'mtu']])
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)
+ # distinguish between parameter 0 and parameter not passed
+ b = default_type.pack({'mtu': 0})
+ self.assertEqual(len(b), 2)
+ nt, size = default_type.unpack(b)
+ self.assertEqual(len(b), size)
+ self.assertEqual(nt.mtu, 0)
+
+ # Ensure that basetypes does not inherit default
+ b = without_default_type.pack({})
+ self.assertEqual(len(b), 2)
+ nt, size = default_type.unpack(b)
+ self.assertEqual(len(b), size)
+ self.assertEqual(nt.mtu, 0)
+
+ # default enum type
+ VPPEnumType('vl_api_enum_t', [["ADDRESS_IP4", 0],
+ ["ADDRESS_IP6", 1],
+ {"enumtype": "u32"}])
+
+ default_with_enum = VPPType('default_enum_type_t',
+ [['u16', 'mtu'], ['vl_api_enum_t',
+ 'e', {'default': 1}]])
+
+ b = default_with_enum.pack({})
+ self.assertEqual(len(b), 6)
+ nt, size = default_with_enum.unpack(b)
+ self.assertEqual(len(b), size)
+ self.assertEqual(nt.e, 1)
class TestAddType(unittest.TestCase):