1212    function_type ,
1313    int_type ,
1414    pointer_type ,
15+     sizeof ,
1516    struct_type ,
1617    typedef_type ,
1718    union_type ,
@@ -43,6 +44,7 @@ def test_int(self):
4344        self .assertNotEqual (t , int_type ('int' , 4 , False ))
4445
4546        self .assertEqual (repr (t ), "int_type(name='int', size=4, is_signed=True)" )
47+         self .assertEqual (sizeof (t ), 4 )
4648
4749        self .assertRaises (TypeError , int_type , None , 4 , True )
4850
@@ -62,6 +64,7 @@ def test_bool(self):
6264        self .assertNotEqual (t , bool_type ('_Bool' , 2 ))
6365
6466        self .assertEqual (repr (t ), "bool_type(name='_Bool', size=1)" )
67+         self .assertEqual (sizeof (t ), 1 )
6568
6669        self .assertRaises (TypeError , bool_type , None , 1 )
6770
@@ -78,6 +81,7 @@ def test_float(self):
7881        self .assertNotEqual (t , float_type ('float' , 8 ))
7982
8083        self .assertEqual (repr (t ), "float_type(name='float', size=4)" )
84+         self .assertEqual (sizeof (t ), 4 )
8185
8286        self .assertRaises (TypeError , float_type , None , 4 )
8387
@@ -96,6 +100,7 @@ def test_complex(self):
96100        self .assertNotEqual (t , complex_type ('double _Complex' , 16 , float_type ('float' , 4 )))
97101
98102        self .assertEqual (repr (t ), "complex_type(name='double _Complex', size=16, type=float_type(name='double', size=8))" )
103+         self .assertEqual (sizeof (t ), 16 )
99104
100105        self .assertRaises (TypeError , complex_type , None , 16 , float_type ('double' , 8 ))
101106        self .assertRaises (TypeError , complex_type , 'double _Complex' , 16 , None )
@@ -161,6 +166,7 @@ def test_struct(self):
161166        self .assertNotEqual (t , struct_type ('point' ))
162167
163168        self .assertEqual (repr (t ), "struct_type(tag='point', size=8, members=((int_type(name='int', size=4, is_signed=True), 'x', 0, 0), (int_type(name='int', size=4, is_signed=True), 'y', 32, 0)))" )
169+         self .assertEqual (sizeof (t ), 8 )
164170
165171        t  =  struct_type (None , 8 , (
166172            (int_type ('int' , 4 , True ), 'x' , 0 ),
@@ -287,6 +293,7 @@ def test_union(self):
287293        self .assertNotEqual (t , union_type ('option' ))
288294
289295        self .assertEqual (repr (t ), "union_type(tag='option', size=4, members=((int_type(name='int', size=4, is_signed=True), 'x', 0, 0), (int_type(name='unsigned int', size=4, is_signed=False), 'y', 0, 0)))" )
296+         self .assertEqual (sizeof (t ), 4 )
290297
291298        t  =  union_type (None , 4 , (
292299            (int_type ('int' , 4 , True ), 'x' ),
@@ -399,6 +406,7 @@ def test_enum(self):
399406
400407        self .assertEqual (repr (t ),
401408                         "enum_type(tag='color', type=int_type(name='unsigned int', size=4, is_signed=False), enumerators=(('RED', 0), ('GREEN', 1), ('BLUE', 2)))" )
409+         self .assertEqual (sizeof (t ), 4 )
402410
403411        t  =  enum_type ('color' , None , None )
404412        self .assertEqual (t .kind , TypeKind .ENUM )
@@ -477,6 +485,7 @@ def test_typedef(self):
477485            'INT' , int_type ('int' , 4 , True , Qualifiers .CONST )))
478486
479487        self .assertEqual (repr (t ), "typedef_type(name='INT', type=int_type(name='int', size=4, is_signed=True))" )
488+         self .assertEqual (sizeof (t ), 4 )
480489
481490        t  =  typedef_type ('VOID' , void_type ())
482491        self .assertFalse (t .is_complete ())
@@ -511,6 +520,7 @@ def test_pointer(self):
511520        self .assertNotEqual (t , pointer_type (8 , void_type (Qualifiers .CONST )))
512521
513522        self .assertEqual (repr (t ), "pointer_type(size=8, type=int_type(name='int', size=4, is_signed=True))" )
523+         self .assertEqual (sizeof (t ), 8 )
514524
515525        self .assertRaises (TypeError , pointer_type , None ,
516526                          int_type ('int' , 4 , True ))
@@ -535,6 +545,7 @@ def test_array(self):
535545        self .assertNotEqual (t , array_type (10 , void_type (Qualifiers .CONST )))
536546
537547        self .assertEqual (repr (t ), "array_type(length=10, type=int_type(name='int', size=4, is_signed=True))" )
548+         self .assertEqual (sizeof (t ), 40 )
538549
539550        t  =  array_type (0 , int_type ('int' , 4 , True ))
540551        self .assertEqual (t .kind , TypeKind .ARRAY )
@@ -584,6 +595,7 @@ def test_function(self):
584595            void_type (), ((int_type ('int' , 4 , True ), 'n' ),), True ))
585596
586597        self .assertEqual (repr (t ), "function_type(type=void_type(), parameters=((int_type(name='int', size=4, is_signed=True), 'n'),), is_variadic=False)" )
598+         self .assertRaises (TypeError , sizeof , t )
587599
588600        self .assertFalse (function_type (void_type (), (), False ).is_variadic )
589601        self .assertTrue (function_type (void_type (), (), True ).is_variadic )
0 commit comments