Skip to content

Commit

Permalink
CSA data model parser: default integer types to say signed (#30005)
Browse files Browse the repository at this point in the history
* Fix py mapping of types

* Add unit test

* Remove sint mapping as it does not seem to be a thing
  • Loading branch information
andy31415 authored and pull[bot] committed Nov 18, 2023
1 parent 592d4f0 commit 2311776
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
38 changes: 38 additions & 0 deletions scripts/py_matter_idl/matter_idl/test_data_model_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,44 @@ def testBasicInput(self):

self.assertEqual(xml_idl, expected_idl)

def testSignedTypes(self):

xml_idl = XmlToIdl('''
<cluster id="123" name="Test" revision="1">
<attributes>
<attribute id="0x0000" name="First" type="int16">
<access read="true" readPrivilege="view"/>
<mandatoryConform/>
</attribute>
<attribute id="0x0001" name="Second" type="int16s">
<access read="true" readPrivilege="view"/>
<mandatoryConform/>
</attribute>
<attribute id="0x0002" name="Third" type="int32u">
<access read="true" readPrivilege="view"/>
<mandatoryConform/>
</attribute>
</attributes>
</cluster>
''')

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

Expand Down

0 comments on commit 2311776

Please sign in to comment.