API: Add support for limits to language.
[vpp.git] / src / vpp-api / python / vpp_papi / tests / test_vpp_serializer.py
index 4fbda2a..ec73347 100755 (executable)
@@ -3,12 +3,27 @@
 import unittest
 from vpp_papi.vpp_serializer import VPPType, VPPEnumType
 from vpp_papi.vpp_serializer import VPPUnionType, VPPMessage
-from vpp_papi.vpp_serializer import VPPTypeAlias
+from vpp_papi.vpp_serializer import VPPTypeAlias, VPPSerializerValueError
 from socket import inet_pton, AF_INET, AF_INET6
 import logging
 import sys
 from ipaddress import *
 
+class TestLimits(unittest.TestCase):
+    def test_limit(self):
+        limited_type = VPPType('limited_type_t',
+                               [['string', 'name', {'limit': 16}]])
+        unlimited_type = VPPType('limited_type_t',
+                                 [['string', 'name']])
+
+
+        b = limited_type.pack({'name':'foobar'})
+        self.assertEqual(len(b), 10)
+        b = unlimited_type.pack({'name':'foobar'})
+        self.assertEqual(len(b), 10)
+
+        with self.assertRaises(VPPSerializerValueError):
+            b = limited_type.pack({'name':'foobar'*3})
 
 class TestAddType(unittest.TestCase):