home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_393 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  1.9 KB  |  65 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5. import unittest
  6. from ctypes import *
  7. structures = []
  8. byteswapped_structures = []
  9. if sys.byteorder == 'little':
  10.     SwappedStructure = BigEndianStructure
  11. else:
  12.     SwappedStructure = LittleEndianStructure
  13. for typ in [
  14.     c_short,
  15.     c_int,
  16.     c_long,
  17.     c_longlong,
  18.     c_float,
  19.     c_double,
  20.     c_ushort,
  21.     c_uint,
  22.     c_ulong,
  23.     c_ulonglong]:
  24.     
  25.     class X(Structure):
  26.         _pack_ = 1
  27.         _fields_ = [
  28.             ('pad', c_byte),
  29.             ('value', typ)]
  30.  
  31.     
  32.     class Y(SwappedStructure):
  33.         _pack_ = 1
  34.         _fields_ = [
  35.             ('pad', c_byte),
  36.             ('value', typ)]
  37.  
  38.     structures.append(X)
  39.     byteswapped_structures.append(Y)
  40.  
  41.  
  42. class TestStructures(unittest.TestCase):
  43.     
  44.     def test_native(self):
  45.         for typ in structures:
  46.             self.failUnlessEqual(typ.value.offset, 1)
  47.             o = typ()
  48.             o.value = 4
  49.             self.failUnlessEqual(o.value, 4)
  50.         
  51.  
  52.     
  53.     def test_swapped(self):
  54.         for typ in byteswapped_structures:
  55.             self.failUnlessEqual(typ.value.offset, 1)
  56.             o = typ()
  57.             o.value = 4
  58.             self.failUnlessEqual(o.value, 4)
  59.         
  60.  
  61.  
  62. if __name__ == '__main__':
  63.     unittest.main()
  64.  
  65.