32
32
# -bob
33
33
34
34
from ctypes .macholib .dyld import dyld_find
35
+ from ctypes .macholib .dylib import dylib_info
36
+ from ctypes .macholib .framework import framework_info
35
37
36
38
def find_lib (name ):
37
39
possible = ['lib' + name + '.dylib' , name + '.dylib' , name + '.framework/' + name ]
@@ -42,9 +44,20 @@ def find_lib(name):
42
44
pass
43
45
raise ValueError ("%s not found" % (name ,))
44
46
47
+
48
+ def d (location = None , name = None , shortname = None , version = None , suffix = None ):
49
+ return {'location' : location , 'name' : name , 'shortname' : shortname ,
50
+ 'version' : version , 'suffix' : suffix }
51
+
52
+
45
53
class MachOTest (unittest .TestCase ):
46
54
@unittest .skipUnless (sys .platform == "darwin" , 'OSX-specific test' )
47
55
def test_find (self ):
56
+ self .assertEqual (dyld_find ('libSystem.dylib' ),
57
+ '/usr/lib/libSystem.dylib' )
58
+ self .assertEqual (dyld_find ('System.framework/System' ),
59
+ '/System/Library/Frameworks/System.framework/System' )
60
+
48
61
# On Mac OS 11, system dylibs are only present in the shared cache,
49
62
# so symlinks like libpthread.dylib -> libSystem.B.dylib will not
50
63
# be resolved by dyld_find
@@ -62,5 +75,36 @@ def test_find(self):
62
75
('/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit' ,
63
76
'/System/Library/Frameworks/IOKit.framework/IOKit' ))
64
77
78
+ @unittest .skipUnless (sys .platform == "darwin" , 'OSX-specific test' )
79
+ def test_info (self ):
80
+ self .assertIsNone (dylib_info ('completely/invalid' ))
81
+ self .assertIsNone (dylib_info ('completely/invalide_debug' ))
82
+ self .assertEqual (dylib_info ('P/Foo.dylib' ), d ('P' , 'Foo.dylib' , 'Foo' ))
83
+ self .assertEqual (dylib_info ('P/Foo_debug.dylib' ),
84
+ d ('P' , 'Foo_debug.dylib' , 'Foo' , suffix = 'debug' ))
85
+ self .assertEqual (dylib_info ('P/Foo.A.dylib' ),
86
+ d ('P' , 'Foo.A.dylib' , 'Foo' , 'A' ))
87
+ self .assertEqual (dylib_info ('P/Foo_debug.A.dylib' ),
88
+ d ('P' , 'Foo_debug.A.dylib' , 'Foo_debug' , 'A' ))
89
+ self .assertEqual (dylib_info ('P/Foo.A_debug.dylib' ),
90
+ d ('P' , 'Foo.A_debug.dylib' , 'Foo' , 'A' , 'debug' ))
91
+
92
+ @unittest .skipUnless (sys .platform == "darwin" , 'OSX-specific test' )
93
+ def test_framework_info (self ):
94
+ self .assertIsNone (framework_info ('completely/invalid' ))
95
+ self .assertIsNone (framework_info ('completely/invalid/_debug' ))
96
+ self .assertIsNone (framework_info ('P/F.framework' ))
97
+ self .assertIsNone (framework_info ('P/F.framework/_debug' ))
98
+ self .assertEqual (framework_info ('P/F.framework/F' ),
99
+ d ('P' , 'F.framework/F' , 'F' ))
100
+ self .assertEqual (framework_info ('P/F.framework/F_debug' ),
101
+ d ('P' , 'F.framework/F_debug' , 'F' , suffix = 'debug' ))
102
+ self .assertIsNone (framework_info ('P/F.framework/Versions' ))
103
+ self .assertIsNone (framework_info ('P/F.framework/Versions/A' ))
104
+ self .assertEqual (framework_info ('P/F.framework/Versions/A/F' ),
105
+ d ('P' , 'F.framework/Versions/A/F' , 'F' , 'A' ))
106
+ self .assertEqual (framework_info ('P/F.framework/Versions/A/F_debug' ),
107
+ d ('P' , 'F.framework/Versions/A/F_debug' , 'F' , 'A' , 'debug' ))
108
+
65
109
if __name__ == "__main__" :
66
110
unittest .main ()
0 commit comments