diff -r ab162f925761 Lib/ctypes/test/test_structures.py --- a/Lib/ctypes/test/test_structures.py Mon Jul 11 01:39:35 2011 +0200 +++ b/Lib/ctypes/test/test_structures.py Mon Jul 11 18:30:29 2011 -0700 @@ -439,5 +439,34 @@ else: self.fail("AttributeError not raised") +# ensure _other_endian function from _endian.py works on Structure types +# check both BigEndianStructure and LittleEndianStructure to make sure +# we hit _other_endian regardless of machine endianness +class TestNestedStructures(unittest.TestCase): + # helper function declares nested structures with given endianness + def define_structures(self, endianness): + class NestedStructure(endianness): + _fields_ = [("spam", c_long), + ("eggs", c_long)] + + class TestStructure(endianness): + _fields_ = [("menu", NestedStructure)] + + # test defining little endian nested structures + def test_little_endian_nested(self): + try: + self.define_structures(LittleEndianStructure) + except: + # no exception should be thrown + self.fail("Defining nested LittleEndianStructure failed") + + # test defining big endian nested structure + def test_big_endian_nested(self): + try: + self.define_structures(BigEndianStructure) + except: + # no exception should be thrown + self.fail("Defining nested BigEndianStructure failed") + if __name__ == '__main__': unittest.main()