File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -303,6 +303,69 @@ class X(Structure):
303303 self .assertEqual (8 , alignment (X ))
304304 self .assertEqual (8 , sizeof (X ))
305305
306+ @unittest .skipIf (os .name == 'nt' , reason = 'Posix only' )
307+ def test_packed_posix (self ):
308+ test_cases = {
309+ (
310+ ("a" , c_uint8 , 4 ),
311+ ("b" , c_uint8 , 4 ),
312+ ): 1 ,
313+ (
314+ ("a" , c_uint8 , 1 ),
315+ ("b" , c_uint16 , 1 ),
316+ ("c" , c_uint32 , 1 ),
317+ ("d" , c_uint64 , 1 ),
318+ ): 1 ,
319+ (
320+ ("a" , c_uint8 , 8 ),
321+ ("b" , c_uint16 , 1 ),
322+ ("c" , c_uint32 , 1 ),
323+ ("d" , c_uint64 , 1 ),
324+ ): 2 ,
325+ (
326+ ("a" , c_uint32 , 9 ),
327+ ("b" , c_uint16 , 10 ),
328+ ("c" , c_uint32 , 25 ),
329+ ("d" , c_uint64 , 1 ),
330+ ): 6 ,
331+ (
332+ ("a" , c_uint32 , 9 ),
333+ ("b" , c_uint16 , 10 ),
334+ ("c" , c_uint32 , 25 ),
335+ ("d" , c_uint64 , 5 ),
336+ ): 7 ,
337+ (
338+ ("a" , c_uint16 ),
339+ ("b" , c_uint16 , 9 ),
340+ ("c" , c_uint16 , 1 ),
341+ ("d" , c_uint16 , 1 ),
342+ ("e" , c_uint16 , 1 ),
343+ ("f" , c_uint16 , 1 ),
344+ ("g" , c_uint16 , 3 ),
345+ ("h" , c_uint32 , 10 ),
346+ ("i" , c_uint32 , 20 ),
347+ ("j" , c_uint32 , 2 ),
348+ ): 8 ,
349+ (
350+ ("a" , c_uint16 , 9 ),
351+ ("b" , c_uint16 , 10 ),
352+ ("d" , c_uint16 ),
353+ ("c" , c_uint8 , 8 ),
354+ ): 6 ,
355+ (
356+ ("a" , c_uint32 , 9 ),
357+ ("b" , c_uint32 ),
358+ ("c" , c_uint32 , 8 ),
359+ ): 7 ,
360+ }
361+
362+ for fields , size in test_cases .items ():
363+ with self .subTest (fields = fields ):
364+ class X (Structure ):
365+ _pack_ = 1
366+ _fields_ = list (fields )
367+ self .assertEqual (sizeof (X ), size )
368+
306369 def test_gh_95496 (self ):
307370 for field_width in range (1 , 33 ):
308371 class TestStruct (Structure ):
You can’t perform that action at this time.
0 commit comments