From 2311776300deda3dd6a2d5eca7962ca81fa7301e Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Wed, 25 Oct 2023 16:47:12 -0400 Subject: [PATCH] CSA data model parser: default integer types to say `signed` (#30005) * Fix py mapping of types * Add unit test * Remove sint mapping as it does not seem to be a thing --- .../data_model_xml/handlers/parsing.py | 16 ++++---- .../matter_idl/test_data_model_xml.py | 38 +++++++++++++++++++ 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/scripts/py_matter_idl/matter_idl/data_model_xml/handlers/parsing.py b/scripts/py_matter_idl/matter_idl/data_model_xml/handlers/parsing.py index fc1631080c3a7e..c2753d4221cab4 100644 --- a/scripts/py_matter_idl/matter_idl/data_model_xml/handlers/parsing.py +++ b/scripts/py_matter_idl/matter_idl/data_model_xml/handlers/parsing.py @@ -69,14 +69,14 @@ def ParseOptionalInt(value: str) -> Optional[int]: "uint48": "int48u", "uint52": "int52u", "uint64": "int64u", - # signed - "sint8": "int8s", - "sint16": "int16s", - "sint24": "int24s", - "sint32": "int32s", - "sint48": "int48s", - "sint52": "int52s", - "sint64": "int64s", + # signed (map to what zapxml/matter currently has) + "int8": "int8s", + "int16": "int16s", + "int24": "int24s", + "int32": "int32s", + "int48": "int48s", + "int52": "int52s", + "int64": "int64s", # other "bool": "boolean", "string": "char_string", diff --git a/scripts/py_matter_idl/matter_idl/test_data_model_xml.py b/scripts/py_matter_idl/matter_idl/test_data_model_xml.py index 7f4ba3153214de..ec2f0cae33c990 100755 --- a/scripts/py_matter_idl/matter_idl/test_data_model_xml.py +++ b/scripts/py_matter_idl/matter_idl/test_data_model_xml.py @@ -72,6 +72,44 @@ def testBasicInput(self): self.assertEqual(xml_idl, expected_idl) + def testSignedTypes(self): + + xml_idl = XmlToIdl(''' + + + + + + + + + + + + + + + + + ''') + + expected_idl = IdlTextToIdl(''' + client cluster Test = 123 { + readonly attribute int16s first = 0; + readonly attribute int16s second = 1; + readonly attribute int32u third = 2; + + readonly attribute attrib_id attributeList[] = 65531; + readonly attribute event_id eventList[] = 65530; + readonly attribute command_id acceptedCommandList[] = 65529; + readonly attribute command_id generatedCommandList[] = 65528; + readonly attribute bitmap32 featureMap = 65532; + readonly attribute int16u clusterRevision = 65533; + } + ''') + + self.assertEqual(xml_idl, expected_idl) + def testEnumRange(self): # Check heuristic for enum ranges