Back to index

python3.2  3.2.2
Public Member Functions
ctypes.test.test_errno.Test Class Reference

List of all members.

Public Member Functions

def test_open
def test_GetLastError

Detailed Description

Definition at line 9 of file test_errno.py.


Member Function Documentation

Definition at line 49 of file test_errno.py.

00049 
00050     def test_GetLastError(self):
00051         dll = WinDLL("kernel32", use_last_error=True)
00052         GetModuleHandle = dll.GetModuleHandleA
00053         GetModuleHandle.argtypes = [c_wchar_p]
00054 
00055         self.assertEqual(0, GetModuleHandle("foo"))
00056         self.assertEqual(get_last_error(), 126)
00057 
00058         self.assertEqual(set_last_error(32), 126)
00059         self.assertEqual(get_last_error(), 32)
00060 
00061         def _worker():
00062             set_last_error(0)
00063 
00064             dll = WinDLL("kernel32", use_last_error=False)
00065             GetModuleHandle = dll.GetModuleHandleW
00066             GetModuleHandle.argtypes = [c_wchar_p]
00067             GetModuleHandle("bar")
00068 
00069             self.assertEqual(get_last_error(), 0)
00070 
00071         t = threading.Thread(target=_worker)
00072         t.start()
00073         t.join()
00074 
00075         self.assertEqual(get_last_error(), 32)
00076 
00077         set_last_error(0)

Here is the call graph for this function:

Definition at line 10 of file test_errno.py.

00010 
00011     def test_open(self):
00012         libc_name = find_library("c")
00013         if libc_name is None:
00014             raise unittest.SkipTest("Unable to find C library")
00015         libc = CDLL(libc_name, use_errno=True)
00016         if os.name == "nt":
00017             libc_open = libc._open
00018         else:
00019             libc_open = libc.open
00020 
00021         libc_open.argtypes = c_char_p, c_int
00022 
00023         self.assertEqual(libc_open(b"", 0), -1)
00024         self.assertEqual(get_errno(), errno.ENOENT)
00025 
00026         self.assertEqual(set_errno(32), errno.ENOENT)
00027         self.assertEqual(get_errno(), 32)
00028 
00029         if threading:
00030             def _worker():
00031                 set_errno(0)
00032 
00033                 libc = CDLL(libc_name, use_errno=False)
00034                 if os.name == "nt":
00035                     libc_open = libc._open
00036                 else:
00037                     libc_open = libc.open
00038                 libc_open.argtypes = c_char_p, c_int
00039                 self.assertEqual(libc_open(b"", 0), -1)
00040                 self.assertEqual(get_errno(), 0)
00041 
00042             t = threading.Thread(target=_worker)
00043             t.start()
00044             t.join()
00045 
00046             self.assertEqual(get_errno(), 32)
00047             set_errno(0)

Here is the call graph for this function:


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