API: Add support for "defaults"
[vpp.git] / src / vpp-api / python / vpp_papi / tests / test_vpp_serializer.py
index ec73347..74a0a62 100755 (executable)
@@ -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):