def testTypedefMarshal(self): """Test generation of marshaling code for typedefs.""" marshalled_types = set(['int']) typedef = structure_generator.Typedef('int', 'INT') typedef2 = structure_generator.Typedef('INT', 'INT2') typemap = {'INT': typedef} out_file = StringIO.StringIO() typedef2.OutputMarshalImpl(out_file, marshalled_types, typemap) self.assertIn('INT', marshalled_types) self.assertIn('INT2', marshalled_types) out_file.close()
def testConstantTypeMarshal(self): """Test generation of marshaling code for constant types.""" marshalled_types = set(['int']) typedef = structure_generator.Typedef('int', 'UINT16') constant = structure_generator.ConstantType('UINT16', 'TPM_TYPE') constant.valid_values.append('VALUE0') constant.valid_values.append('VALUE1') typemap = {'UINT16': typedef} out_file = StringIO.StringIO() constant.OutputMarshalImpl(out_file, marshalled_types, typemap) self.assertIn('UINT16', marshalled_types) self.assertIn('TPM_TYPE', marshalled_types) out_file.close()
def testUnionMarshal(self): """Test generation of marshaling code for unions.""" marshalled_types = set(['int']) union = structure_generator.Union('TPMU_SYM_MODE') union.AddField(structure_generator.Field('UINT16', 'aes', None)) union.AddField(structure_generator.Field('UINT16', 'SM4', None)) typedef = structure_generator.Typedef('int', 'UINT16') typemap = {'UINT16': typedef} out_file = StringIO.StringIO() union.OutputMarshalImpl(out_file, marshalled_types, typemap) self.assertIn('UINT16', marshalled_types) self.assertIn('TPMU_SYM_MODE', marshalled_types) out_file.close()
def testAttributeStructureMarshal(self): """Test generation of marshaling code for attribute structures.""" marshalled_types = set(['int']) typedef = structure_generator.Typedef('int', 'UINT16') attributeStruct = structure_generator.AttributeStructure( 'UINT16', 'TPM_TYPE') attributeStruct.reserved.append('4_7') attributeStruct.reserved.append('1') typemap = {'UINT16': typedef} out_file = StringIO.StringIO() attributeStruct.OutputMarshalImpl(out_file, marshalled_types, typemap) self.assertIn('UINT16', marshalled_types) self.assertIn('TPM_TYPE', marshalled_types) out_file.close()
def testInterfacemarshal(self): """test generation of marshaling code for interfaces.""" marshalled_types = set(['int']) typedef = structure_generator.Typedef('int', 'UINT16') interface = structure_generator.Interface('UINT16', 'TPM_TYPE') interface.conditional = 'TPM_VALUE_NULL' interface.bounds.append(('TPM_MIN', 'TPM_MAX')) interface.valid_values.append('VALUE0') interface.valid_values.append('VALUE1') typemap = {'UINT16': typedef} out_file = StringIO.StringIO() interface.OutputMarshalImpl(out_file, marshalled_types, typemap) self.assertIn('UINT16', marshalled_types) self.assertIn('TPM_TYPE', marshalled_types) out_file.close()
def testStructMarshal(self): """Test generation of marshaling code for structures.""" marshalled_types = set(['int']) struct = structure_generator.Structure('TEST_STRUCT') struct.AddField( structure_generator.Field('UINT16', 'type', None, False)) struct.AddField( structure_generator.Field('TPMI_TYPE', 'interfaceField0', 'TRUE', False)) struct.AddField( structure_generator.Field('TPMI_TYPE', 'interfaceField1', 'FALSE', False)) struct.AddField( structure_generator.Field('TPMU_SYM_MODE', 'unionField', 'type', False)) struct.AddField( structure_generator.Field('UINT16', 'arrayField', 'MAX_VALUE', True)) typedef = structure_generator.Typedef('int', 'UINT16') interface = structure_generator.Interface('UINT16', 'TPMI_TYPE') # Choose TPMU_SYM_MODE because it exists in selectors definition and it # has few fields. union = structure_generator.Union('TPMU_SYM_MODE') union.AddField(structure_generator.Field('UINT16', 'aes', None)) union.AddField(structure_generator.Field('UINT16', 'SM4', None)) typemap = { 'UINT16': typedef, 'TPMI_TYPE': interface, 'TPMU_SYM_MODE': union } out_file = StringIO.StringIO() struct.OutputMarshalImpl(out_file, marshalled_types, typemap) self.assertIn('UINT16', marshalled_types) self.assertIn('TPMI_TYPE', marshalled_types) self.assertIn('TPMU_SYM_MODE', marshalled_types) self.assertIn('TEST_STRUCT', marshalled_types) out_file.close()