Commits

Ronald Oussoren committed b4bb502

Actually load a bridgesupport file when testing, uses a new proces for the test to avoid contaminating the test environment (and the test itself)

  • Participants
  • Parent commits 1713eaf

Comments (0)

Files changed (3)

File pyobjc-core/Doc/metadata/manual.rst

 API description
 ---------------
 
-For now see :doc:`the main API description </lib/module-objc>` for the
+For now see :doc:`the main API description </api/module-objc>` for the
 functions that are used to load metadata.
 
 The contains of the metadata dictionary argument for 

File pyobjc-core/PyObjCTest/helper_bridgesupport.py

+import sys
+
+sys.path.insert(0, sys.argv[1])
+
+import objc
+if not objc.__file__.startswith(sys.argv[1]):
+    print("Loaded objc from unexpected path")
+    sys.exit(1)
+
+try:
+    unicode
+except NameError:
+    unicode = str
+
+passed = True
+g = {}
+objc.initFrameworkWrapper("AddressBook",
+        "/System/Library/Frameworks/AddressBook.framework",
+        "com.apple.AddressBook.framework", 
+        g, scan_classes=False)
+
+if 'ABAddPropertiesAndTypes' not in g:
+    print("Cannot find 'ABAddPropertiesAndTypes'")
+    passed = False
+
+else:
+    func = g['ABAddPropertiesAndTypes']
+    if not isinstance(func, objc.function):
+        print("'ABAddPropertiesAndTypes' not an objc.function")
+        passed = False
+
+    else:
+        if func.__metadata__() != {
+            'retval': {
+                'already_retained': False, 
+                'already_cfretained': False,
+                'type': 'q' if sys.maxint > 2**32 else 'l', 
+            }, 
+            'arguments': (
+                {
+                    'null_accepted': True, 
+                    'already_retained': False, 
+                    'already_cfretained': False,
+                    'type': '^{__ABAddressBookRef=}', 
+                }, 
+                {
+                    'null_accepted': True, 
+                    'already_retained': False, 
+                    'already_cfretained': False,
+                    'type': '^{__CFString=}', 
+                }, {
+                    'null_accepted': True, 
+                    'already_retained': False, 
+                    'already_cfretained': False,
+                    'type': '^{__CFDictionary=}', 
+                }
+            ), 
+            'variadic': False
+            }:
+
+            print("Unexpected metadata for 'ABAddPropertiesAndTypes'")
+            passed = False
+
+if 'ABAddressBookErrorDomain' not in g:
+    print("'ABAddressBookErrorDomain' not found")
+    passed = False
+
+elif not isinstance(g['ABAddressBookErrorDomain'], unicode):
+    print("'ABAddressBookErrorDomain' not a string")
+    passed = False
+
+if 'ABAddRecordsError' not in g:
+    print("'ABAddRecordsError' not found")
+    passed = False
+
+elif g['ABAddRecordsError'] != 1001:
+    print("'ABAddRecordsError' has wrong value")
+    passed = False
+
+if 'NSObject' in g:
+    print("No scan_classes, but 'NSObject' found")
+    passed = False
+
+if 'ABAddressBook' in g:
+    print("No scan_classes, but 'ABAddressBook' found")
+    passed = False
+
+g = {}
+objc.initFrameworkWrapper("AddressBook",
+        "/System/Library/Frameworks/AddressBook.framework",
+        "com.apple.AddressBook.framework", 
+        g, scan_classes=True)
+
+if 'ABAddressBook' not in g:
+    print("'ABAddressBook' not found")
+    passed = False
+
+elif not isinstance(g['ABAddressBook'], objc.objc_class):
+    print("'ABAddressBook' not a class")
+    passed = False
+
+else:
+    m = g['ABAddressBook'].addRecord_.__metadata__()
+    if m['retval']['type'] != objc._C_NSBOOL:
+        print("'ABAddressBook' -addRecord: metadata not processed")
+        passed = False
+
+if passed:
+    sys.exit(0)
+else:
+    sys.exit(1)

File pyobjc-core/PyObjCTest/test_bridgesupport.py

 import sys
 import imp
 import ctypes
+import objc
+import subprocess
 
 import xml.etree.ElementTree as ET 
 
             self.assertEqual(bridgesupport._libraries[-1]._name, '/usr/lib/libxml2.dylib')
             
 
-    def test_real_loader(self):
-        # Use the real API in a subprocess and verify
-        # that the metadata is properly loaded
-        # (use subset of Foundation and CoreFoundation)
-        self.fail()
-
 
 class TestInitFrameworkWrapper (TestCase):
     def test_calls_parse_helper(self):
             # 7. Cannot load bundle (should look for bridgesupport)
 
             # 8. Use the 'frameworkResourceName' parameter
+            self.fail()
 
 
     def test_real_loader(self):
-        # Load framework in subprocess and verify that
-        # the right metadata is loaded.
-        self.fail()
+        script = os.path.join(os.path.dirname(__file__), 'helper_bridgesupport.py')
+        path_elem = os.path.dirname(objc.__file__)
+
+        if sys.byteorder == 'big':
+            if sys.maxsize < 2**32:
+                arch = '-ppc'
+            else:
+                arch = '-ppc64'
+
+        else:
+            if sys.maxsize < 2**32:
+                arch = '-i386'
+            else:
+                arch = '-x86_64'
+
+        p = subprocess.Popen([
+            '/usr/bin/arch', arch,
+            sys.executable, script, path_elem], stdout=subprocess.PIPE)
+        stdout, _ = p.communicate()
+        if p.returncode != 0:
+            self.fail("Selftest failed: %r" % stdout)
 
 class TestMisc (TestCase):
     def test_struct_alias(self):