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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from ctypes import *
  5. import sys
  6. import unittest
  7. import os
  8. from ctypes.util import find_library
  9. from ctypes.test import is_resource_enabled
  10. libc_name = None
  11. if os.name == 'nt':
  12.     libc_name = find_library('c')
  13. elif os.name == 'ce':
  14.     libc_name = 'coredll'
  15. elif sys.platform == 'cygwin':
  16.     libc_name = 'cygwin1.dll'
  17. else:
  18.     libc_name = find_library('c')
  19. if is_resource_enabled('printing'):
  20.     print 'libc_name is', libc_name
  21.  
  22.  
  23. class LoaderTest(unittest.TestCase):
  24.     unknowndll = 'xxrandomnamexx'
  25.     if libc_name is not None:
  26.         
  27.         def test_load(self):
  28.             CDLL(libc_name)
  29.             CDLL(os.path.basename(libc_name))
  30.             self.assertRaises(OSError, CDLL, self.unknowndll)
  31.  
  32.     
  33.     if libc_name is not None and os.path.basename(libc_name) == 'libc.so.6':
  34.         
  35.         def test_load_version(self):
  36.             cdll.LoadLibrary('libc.so.6')
  37.             self.assertRaises(OSError, cdll.LoadLibrary, 'libc.so.9')
  38.             self.assertRaises(OSError, cdll.LoadLibrary, self.unknowndll)
  39.  
  40.     
  41.     
  42.     def test_find(self):
  43.         for name in ('c', 'm'):
  44.             lib = find_library(name)
  45.             if lib:
  46.                 cdll.LoadLibrary(lib)
  47.                 CDLL(lib)
  48.                 continue
  49.         
  50.  
  51.     if os.name in ('nt', 'ce'):
  52.         
  53.         def test_load_library(self):
  54.             self.failIf(libc_name is None)
  55.             if is_resource_enabled('printing'):
  56.                 print find_library('kernel32')
  57.                 print find_library('user32')
  58.             
  59.             if os.name == 'nt':
  60.                 windll.kernel32.GetModuleHandleW
  61.                 windll['kernel32'].GetModuleHandleW
  62.                 windll.LoadLibrary('kernel32').GetModuleHandleW
  63.                 WinDLL('kernel32').GetModuleHandleW
  64.             elif os.name == 'ce':
  65.                 windll.coredll.GetModuleHandleW
  66.                 windll['coredll'].GetModuleHandleW
  67.                 windll.LoadLibrary('coredll').GetModuleHandleW
  68.                 WinDLL('coredll').GetModuleHandleW
  69.             
  70.  
  71.         
  72.         def test_load_ordinal_functions(self):
  73.             import _ctypes_test
  74.             dll = WinDLL(_ctypes_test.__file__)
  75.             func_ord = dll[2]
  76.             func_name = dll.GetString
  77.             a_ord = addressof(func_ord)
  78.             a_name = addressof(func_name)
  79.             f_ord_addr = c_void_p.from_address(a_ord).value
  80.             f_name_addr = c_void_p.from_address(a_name).value
  81.             self.failUnlessEqual(hex(f_ord_addr), hex(f_name_addr))
  82.             self.failUnlessRaises(AttributeError, dll.__getitem__, 1234)
  83.  
  84.     
  85.     if os.name == 'nt':
  86.         
  87.         def test_1703286_A(self):
  88.             LoadLibrary = LoadLibrary
  89.             FreeLibrary = FreeLibrary
  90.             import _ctypes
  91.             handle = LoadLibrary('advapi32')
  92.             FreeLibrary(handle)
  93.  
  94.         
  95.         def test_1703286_B(self):
  96.             call_function = call_function
  97.             import _ctypes
  98.             advapi32 = windll.advapi32
  99.             self.failUnlessEqual(0, advapi32.CloseEventLog(None))
  100.             windll.kernel32.GetProcAddress.argtypes = (c_void_p, c_char_p)
  101.             windll.kernel32.GetProcAddress.restype = c_void_p
  102.             proc = windll.kernel32.GetProcAddress(advapi32._handle, 'CloseEventLog')
  103.             self.failUnless(proc)
  104.             self.failUnlessEqual(0, call_function(proc, (None,)))
  105.  
  106.     
  107.  
  108. if __name__ == '__main__':
  109.     unittest.main()
  110.  
  111.