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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import unittest
  5. from ctypes import *
  6.  
  7. class MyInt(c_int):
  8.     
  9.     def __cmp__(self, other):
  10.         if type(other) != MyInt:
  11.             return -1
  12.         return cmp(self.value, other.value)
  13.  
  14.     
  15.     def __hash__(self):
  16.         return hash(self.value)
  17.  
  18.  
  19.  
  20. class Test(unittest.TestCase):
  21.     
  22.     def test_compare(self):
  23.         self.failUnlessEqual(MyInt(3), MyInt(3))
  24.         self.failIfEqual(MyInt(42), MyInt(43))
  25.  
  26.     
  27.     def test_ignore_retval(self):
  28.         proto = CFUNCTYPE(None)
  29.         
  30.         def func():
  31.             return (1, 'abc', None)
  32.  
  33.         cb = proto(func)
  34.         self.failUnlessEqual(None, cb())
  35.  
  36.     
  37.     def test_int_callback(self):
  38.         args = []
  39.         
  40.         def func(arg):
  41.             args.append(arg)
  42.             return arg
  43.  
  44.         cb = CFUNCTYPE(None, MyInt)(func)
  45.         self.failUnlessEqual(None, cb(42))
  46.         self.failUnlessEqual(type(args[-1]), MyInt)
  47.         cb = CFUNCTYPE(c_int, c_int)(func)
  48.         self.failUnlessEqual(42, cb(42))
  49.         self.failUnlessEqual(type(args[-1]), int)
  50.  
  51.     
  52.     def test_int_struct(self):
  53.         
  54.         class X(Structure):
  55.             _fields_ = [
  56.                 ('x', MyInt)]
  57.  
  58.         self.failUnlessEqual(X().x, MyInt())
  59.         s = X()
  60.         s.x = MyInt(42)
  61.         self.failUnlessEqual(s.x, MyInt(42))
  62.  
  63.  
  64. if __name__ == '__main__':
  65.     unittest.main()
  66.  
  67.