Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes
ctypes.test.test_loading.LoaderTest Class Reference
Collaboration diagram for ctypes.test.test_loading.LoaderTest:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_load
def test_load_version
def test_find
def test_load_library
def test_load_ordinal_functions
def test_1703286_A
def test_1703286_B

Static Public Attributes

string unknowndll = "xxrandomnamexx"

Detailed Description

Definition at line 20 of file test_loading.py.


Member Function Documentation

Definition at line 78 of file test_loading.py.

00078 
00079         def test_1703286_A(self):
00080             from _ctypes import LoadLibrary, FreeLibrary
00081             # On winXP 64-bit, advapi32 loads at an address that does
00082             # NOT fit into a 32-bit integer.  FreeLibrary must be able
00083             # to accept this address.
00084 
00085             # These are tests for http://www.python.org/sf/1703286
00086             handle = LoadLibrary("advapi32")
00087             FreeLibrary(handle)

Definition at line 88 of file test_loading.py.

00088 
00089         def test_1703286_B(self):
00090             # Since on winXP 64-bit advapi32 loads like described
00091             # above, the (arbitrarily selected) CloseEventLog function
00092             # also has a high address.  'call_function' should accept
00093             # addresses so large.
00094             from _ctypes import call_function
00095             advapi32 = windll.advapi32
00096             # Calling CloseEventLog with a NULL argument should fail,
00097             # but the call should not segfault or so.
00098             self.assertEqual(0, advapi32.CloseEventLog(None))
00099             windll.kernel32.GetProcAddress.argtypes = c_void_p, c_char_p
00100             windll.kernel32.GetProcAddress.restype = c_void_p
00101             proc = windll.kernel32.GetProcAddress(advapi32._handle, b"CloseEventLog")
00102             self.assertTrue(proc)
00103             # This is the real test: call the function via 'call_function'
00104             self.assertEqual(0, call_function(proc, (None,)))

Here is the call graph for this function:

Definition at line 37 of file test_loading.py.

00037 
00038     def test_find(self):
00039         for name in ("c", "m"):
00040             lib = find_library(name)
00041             if lib:
00042                 cdll.LoadLibrary(lib)
00043                 CDLL(lib)

Here is the call graph for this function:

Definition at line 25 of file test_loading.py.

00025 
00026         def test_load(self):
00027             CDLL(libc_name)
00028             CDLL(os.path.basename(libc_name))
00029             self.assertRaises(OSError, CDLL, self.unknowndll)

Here is the call graph for this function:

Definition at line 45 of file test_loading.py.

00045 
00046         def test_load_library(self):
00047             self.assertFalse(libc_name is None)
00048             if is_resource_enabled("printing"):
00049                 print(find_library("kernel32"))
00050                 print(find_library("user32"))
00051 
00052             if os.name == "nt":
00053                 windll.kernel32.GetModuleHandleW
00054                 windll["kernel32"].GetModuleHandleW
00055                 windll.LoadLibrary("kernel32").GetModuleHandleW
00056                 WinDLL("kernel32").GetModuleHandleW
00057             elif os.name == "ce":
00058                 windll.coredll.GetModuleHandleW
00059                 windll["coredll"].GetModuleHandleW
00060                 windll.LoadLibrary("coredll").GetModuleHandleW
00061                 WinDLL("coredll").GetModuleHandleW

Here is the call graph for this function:

Definition at line 62 of file test_loading.py.

00062 
00063         def test_load_ordinal_functions(self):
00064             import _ctypes_test
00065             dll = WinDLL(_ctypes_test.__file__)
00066             # We load the same function both via ordinal and name
00067             func_ord = dll[2]
00068             func_name = dll.GetString
00069             # addressof gets the address where the function pointer is stored
00070             a_ord = addressof(func_ord)
00071             a_name = addressof(func_name)
00072             f_ord_addr = c_void_p.from_address(a_ord).value
00073             f_name_addr = c_void_p.from_address(a_name).value
00074             self.assertEqual(hex(f_ord_addr), hex(f_name_addr))
00075 
00076             self.assertRaises(AttributeError, dll.__getitem__, 1234)

Here is the call graph for this function:

Definition at line 31 of file test_loading.py.

00031 
00032         def test_load_version(self):
00033             cdll.LoadLibrary("libc.so.6")
00034             # linux uses version, libc 9 should not exist
00035             self.assertRaises(OSError, cdll.LoadLibrary, "libc.so.9")
00036             self.assertRaises(OSError, cdll.LoadLibrary, self.unknowndll)

Here is the call graph for this function:


Member Data Documentation

Definition at line 22 of file test_loading.py.


The documentation for this class was generated from the following file: