def test_bool(self): t = bool_type('_Bool', 1) self.assertEqual(t.kind, TypeKind.BOOL) self.assertEqual(t.primitive, PrimitiveType.C_BOOL) self.assertEqual(t.name, '_Bool') self.assertEqual(t.size, 1) self.assertTrue(t.is_complete()) self.assertEqual(t, bool_type('_Bool', 1)) self.assertNotEqual(t, bool_type('bool', 1)) self.assertNotEqual(t, bool_type('_Bool', 2)) self.assertEqual(repr(t), "bool_type(name='_Bool', size=1)") self.assertRaises(TypeError, bool_type, None, 1)
def test_bool(self): t = bool_type("_Bool", 1) self.assertEqual(t.kind, TypeKind.BOOL) self.assertEqual(t.primitive, PrimitiveType.C_BOOL) self.assertEqual(t.language, DEFAULT_LANGUAGE) self.assertEqual(t.name, "_Bool") self.assertEqual(t.size, 1) self.assertTrue(t.is_complete()) self.assertEqual(t, bool_type("_Bool", 1)) self.assertNotEqual(t, bool_type("bool", 1)) self.assertNotEqual(t, bool_type("_Bool", 2)) self.assertEqual(repr(t), "bool_type(name='_Bool', size=1)") self.assertEqual(sizeof(t), 1) self.assertRaises(TypeError, bool_type, None, 1)
def test_default_primitive_types(self): def spellings(tokens, num_optional=0): for i in range(len(tokens) - num_optional, len(tokens) + 1): for perm in itertools.permutations(tokens[:i]): yield " ".join(perm) for word_size in [8, 4]: prog = mock_program( MOCK_PLATFORM if word_size == 8 else MOCK_32BIT_PLATFORM ) self.assertEqual(prog.type("_Bool"), bool_type("_Bool", 1)) self.assertEqual(prog.type("char"), int_type("char", 1, True)) for spelling in spellings(["signed", "char"]): self.assertEqual(prog.type(spelling), int_type("signed char", 1, True)) for spelling in spellings(["unsigned", "char"]): self.assertEqual( prog.type(spelling), int_type("unsigned char", 1, False) ) for spelling in spellings(["short", "signed", "int"], 2): self.assertEqual(prog.type(spelling), int_type("short", 2, True)) for spelling in spellings(["short", "unsigned", "int"], 1): self.assertEqual( prog.type(spelling), int_type("unsigned short", 2, False) ) for spelling in spellings(["int", "signed"], 1): self.assertEqual(prog.type(spelling), int_type("int", 4, True)) for spelling in spellings(["unsigned", "int"]): self.assertEqual( prog.type(spelling), int_type("unsigned int", 4, False) ) for spelling in spellings(["long", "signed", "int"], 2): self.assertEqual(prog.type(spelling), int_type("long", word_size, True)) for spelling in spellings(["long", "unsigned", "int"], 1): self.assertEqual( prog.type(spelling), int_type("unsigned long", word_size, False) ) for spelling in spellings(["long", "long", "signed", "int"], 2): self.assertEqual(prog.type(spelling), int_type("long long", 8, True)) for spelling in spellings(["long", "long", "unsigned", "int"], 1): self.assertEqual( prog.type(spelling), int_type("unsigned long long", 8, False) ) self.assertEqual(prog.type("float"), float_type("float", 4)) self.assertEqual(prog.type("double"), float_type("double", 8)) for spelling in spellings(["long", "double"]): self.assertEqual(prog.type(spelling), float_type("long double", 16)) self.assertEqual( prog.type("size_t"), typedef_type("size_t", int_type("unsigned long", word_size, False)), ) self.assertEqual( prog.type("ptrdiff_t"), typedef_type("ptrdiff_t", int_type("long", word_size, True)), )
def test_default_primitive_types(self): def spellings(tokens, num_optional=0): for i in range(len(tokens) - num_optional, len(tokens) + 1): for perm in itertools.permutations(tokens[:i]): yield ' '.join(perm) for word_size in [8, 4]: prog = mock_program(MOCK_ARCH if word_size == 8 else MOCK_32BIT_ARCH) self.assertEqual(prog.type('_Bool'), bool_type('_Bool', 1)) self.assertEqual(prog.type('char'), int_type('char', 1, True)) for spelling in spellings(['signed', 'char']): self.assertEqual(prog.type(spelling), int_type('signed char', 1, True)) for spelling in spellings(['unsigned', 'char']): self.assertEqual(prog.type(spelling), int_type('unsigned char', 1, False)) for spelling in spellings(['short', 'signed', 'int'], 2): self.assertEqual(prog.type(spelling), int_type('short', 2, True)) for spelling in spellings(['short', 'unsigned', 'int'], 1): self.assertEqual(prog.type(spelling), int_type('unsigned short', 2, False)) for spelling in spellings(['int', 'signed'], 1): self.assertEqual(prog.type(spelling), int_type('int', 4, True)) for spelling in spellings(['unsigned', 'int']): self.assertEqual(prog.type(spelling), int_type('unsigned int', 4, False)) for spelling in spellings(['long', 'signed', 'int'], 2): self.assertEqual(prog.type(spelling), int_type('long', word_size, True)) for spelling in spellings(['long', 'unsigned', 'int'], 1): self.assertEqual(prog.type(spelling), int_type('unsigned long', word_size, False)) for spelling in spellings(['long', 'long', 'signed', 'int'], 2): self.assertEqual(prog.type(spelling), int_type('long long', 8, True)) for spelling in spellings(['long', 'long', 'unsigned', 'int'], 1): self.assertEqual(prog.type(spelling), int_type('unsigned long long', 8, False)) self.assertEqual(prog.type('float'), float_type('float', 4)) self.assertEqual(prog.type('double'), float_type('double', 8)) for spelling in spellings(['long', 'double']): self.assertEqual(prog.type(spelling), float_type('long double', 16)) self.assertEqual( prog.type('size_t'), typedef_type('size_t', int_type('unsigned long', word_size, False))) self.assertEqual( prog.type('ptrdiff_t'), typedef_type('ptrdiff_t', int_type('long', word_size, True)))
def test_typedef(self): self.assertQualifiedTypeName( "bool", False, typedef_type, "bool", bool_type("_Bool", 1) )
def test_typedef(self): self.assertQualifiedTypeName('bool', False, typedef_type, 'bool', bool_type('_Bool', 1))