Debian Codegraph @

cpython27/Lib/ctypes/test/test_find.py

raw symbols SCIP
1 import unittest
2 import os.path
3 import sys
4 from test import test_support
5 from ctypes import *
6 from ctypes.util import find_library
7 from ctypes.test import is_resource_enabled
8
9 if sys.platform == "win32":
10 lib_gl = find_library("OpenGL32")
11 lib_glu = find_library("Glu32")
12 lib_gle = None
13 elif sys.platform == "darwin":
14 lib_gl = lib_glu = find_library("OpenGL")
15 lib_gle = None
16 else:
17 lib_gl = find_library("GL")
18 lib_glu = find_library("GLU")
19 lib_gle = find_library("gle")
20
21 ## print, for debugging
22 if is_resource_enabled("printing"):
23 if lib_gl or lib_glu or lib_gle:
24 print "OpenGL libraries:"
25 for item in (("GL", lib_gl),
26 ("GLU", lib_glu),
27 ("gle", lib_gle)):
28 print "\t", item
29
30
31 # On some systems, loading the OpenGL libraries needs the RTLD_GLOBAL mode.
32 class Test_OpenGL_libs(unittest.TestCase):
33 def setUp(self):
34 self.gl = self.glu = self.gle = None
35 if lib_gl:
36 try:
37 self.gl = CDLL(lib_gl, mode=RTLD_GLOBAL)
38 except OSError:
39 pass
40 if lib_glu:
41 try:
42 self.glu = CDLL(lib_glu, RTLD_GLOBAL)
43 except OSError:
44 pass
45 if lib_gle:
46 try:
47 self.gle = CDLL(lib_gle)
48 except OSError:
49 pass
50
51 def tearDown(self):
52 self.gl = self.glu = self.gle = None
53
54 @unittest.skipUnless(lib_gl, 'lib_gl not available')
55 def test_gl(self):
56 if self.gl:
57 self.gl.glClearIndex
58
59 @unittest.skipUnless(lib_glu, 'lib_glu not available')
60 def test_glu(self):
61 if self.glu:
62 self.glu.gluBeginCurve
63
64 @unittest.skipUnless(lib_gle, 'lib_gle not available')
65 def test_gle(self):
66 if self.gle:
67 self.gle.gleGetJoinStyle
68
69 def test_shell_injection(self):
70 result = find_library('; echo Hello shell > ' + test_support.TESTFN)
71 self.assertFalse(os.path.lexists(test_support.TESTFN))
72 self.assertIsNone(result)
73
74 if __name__ == "__main__":
75 unittest.main()