Ronald Oussoren avatar Ronald Oussoren committed e718fcd

Finish tests for bridgesupport parser, still need to test the public API

Comments (0)

Files changed (4)

pyobjc-core/Lib/objc/_bridgesupport.py

                 _, d = self.xml_to_arg(al, False, True)
                 if "type" not in d:
                     # Ignore functions without type info
-                    print "ignore", name, d
                     return
                 siglist.append(d["type"])
 
                 _, d = self.xml_to_arg(al, False, False)
                 if "type" not in d:
                     # Ignore functions without type info
-                    print "ignore2", name, d
                     return
                 siglist[0] = d["type"]
                 meta["retval"] = d
                 pass
 
             else:
-                self.values[name] = value
-                objc.registerStructAlias(typestr, value)
-                _structConvenience(name, value)
+                self.structs.append((name, typestr, value))
+                return
 
-        self.structs.append((name, typestr))
+        self.structs.append((name, typestr, None))
 
 
     def do_string_constant(self, node):
         for name, typestr in prs.opaque:
             globals[name] = objc.createOpaquePointerType(name, typestr)
 
-        for name, typestr in prs.structs:
-            globals[name] = value = objc.createStructType(name, typestr, None)
-            _structConvenience(name, value)
-            # XXX: new metadata should also use structConvenience!
+        for name, typestr, alias in prs.structs:
+            if alias is not None:
+                globals[name] = alias
+                objc.createStructAlias(name, typestr, alias)
+            else:
+                globals[name] = value = objc.createStructType(name, typestr, None)
 
         for name, method_list in prs.informal_protocols:
             proto = objc.informal_protocol(name, method_list)

pyobjc-core/Modules/objc/selector.m

  * This one can be allocated from python code.
  */
 
+static PyObject* pysel_richcompare(PyObject* a, PyObject* b, int op)
+{
+	if (op == Py_EQ || op == Py_NE) {
+		if (PyObjCPythonSelector_Check(a) && PyObjCPythonSelector_Check(b)) {
+			PyObjCPythonSelector* sel_a = (PyObjCPythonSelector*)a;
+			PyObjCPythonSelector* sel_b = (PyObjCPythonSelector*)b;
+			int same = 1;
+			int r;
+
+			if (sel_a->sel_selector != sel_b->sel_selector) {
+				same = 0;
+			}
+			if (sel_a->sel_class != sel_b->sel_class) {
+				same = 0;
+			}
+			if (sel_a->sel_self != sel_b->sel_self) {
+				same = 0;
+			}
+			r = PyObject_RichCompareBool(
+					sel_a->callable, 
+					sel_b->callable, Py_EQ);
+			if (r == -1) {
+				return NULL;
+			}
+			if (!r) {
+				same = 0;
+			}
+
+			if ((op == Py_EQ && !same) || (op == Py_NE && same)) {
+				Py_INCREF(Py_False);
+				return Py_False;
+			} else {
+				Py_INCREF(Py_False);
+				return Py_True;
+			}
+
+		} else {
+			if (op == Py_EQ) {
+				Py_INCREF(Py_False);
+				return Py_False;
+			} else {
+				Py_INCREF(Py_False);
+				return Py_True;
+			}
+		}
+	} else {
+		PyErr_SetString(PyExc_TypeError, "Cannot use '<', '<=', '>=' and '>' with objc.selector");
+		return NULL;
+	}
+}
+
 static PyObject*
 pysel_repr(PyObject* _self)
 {
  	0,					/* tp_doc */
  	0,					/* tp_traverse */
  	0,					/* tp_clear */
-	0,					/* tp_richcompare */
+	pysel_richcompare,			/* tp_richcompare */
 	0,					/* tp_weaklistoffset */
 	0,					/* tp_iter */
 	0,					/* tp_iternext */

pyobjc-core/NEWS.txt

    Version 2.5 is currently in development and hasn't been released
    yet.
 
+- Added implementation of '==' and '!=' for selectors defined in Python
+  that is slightly smarter than the default (identity based) implementation
+  in Python. 
+
+  This is mostly done for the PyObjC unittests and shouldn't affect user
+  code.
+
 - Issue #22: Reimplement support for bridgesupport files
 
   This reintroduces ``objc.parseBridgeSupport`` and 

pyobjc-core/PyObjCTest/test_bridgesupport.py

   <!-- TODO: type rewriting (_C_BOOL, _C_NSBOOL)-->
   <informal_protocol/><!-- ignore -->
   <informal_protocol name='protocol1' />
-  <informal_protocol name='protocol1' >
+  <informal_protocol name='protocol2' >
     <method selector='selector1' type='v@:f' type64='v@:d' />
     <method selector='selector2' type='v@:f' type64='v@:d' classmethod='false' />
     <method selector='selector3' type='v@:f' type64='v@:d' classmethod='true' />
     <method selector='selector4' type='v@:f' type64='v@:d' variadic='true' /><!-- 'variadic' is ignored -->
     <method selector='selector5' /><!-- ignore: no type -->
     <method selector='selector6' type64='v@:@' /><!-- ignore 32-bit -->
-    <method selector='selector7' type='v@:f' type64='v@:d' class_method='false' /><!-- manpage: class_method, pyobjc 2.3: classmethod -->
-    <method selector='selector8' type='v@:f' type64='v@:d' class_method='true' />
+    <method selector='selector7' type='v@:f' class_method='false' /><!-- manpage: class_method, pyobjc 2.3: classmethod -->
+    <method selector='selector8' type='v@:f' class_method='true' />
   </informal_protocol>
   <struct/><!-- ignore -->
   <struct type='{foo=dd}' /><!--ignore-->
   <struct name='struct5' type='{struct3=@@}' alias='module2.struct'/>
   <struct name='struct6' type='{struct6=BB}' /><!-- _C_NSBOOL -->
   <struct name='struct7' type='{struct7=Z@}' /><!-- _C_BOOL -->
+  <struct name='struct8' type='{struct8=@@}' alias='sys.maxsize'/><!-- _C_BOOL -->
 </signatures>
 """
 
             ('function14', b':', '', { 'retval': {'type': b':', 'sel_of_type': b'v@:f', 'c_array_of_fixed_length': 4 }}),
             ('function15', b':', '', { 'retval': {'type': b':', 'sel_of_type': b'v@:f' if sys.maxsize < 2**32 else b'v@:d' }}),
             ('function16', b'i', '', { 'retval': {'type': b'i', 
-                'null_accepted': False, 'already_retained': True, 'c_array_length_in_result': True }}),
+                'null_accepted': False, 'already_retained': True, }}),
             ('function17', b'i', '', { 'retval': {'type': b'i', 
                 'already_cfretained': True, 'c_array_delimited_by_null': True, 'c_array_of_variable_length': True,
                 'printf_format': True, 'free_result': True }}),
                 'retval': { 'type': b'q' },
                 'arguments': {
                     0:  { 'type': b'f' },
-                    1:  { 'type': b'f' }
+                    1:  { 'type': b'd' }
                 }
             }),
-            ('function27', b'vfd', '', { 
+            ('function27', b'vdd', '', { 
                 'arguments': {
-                    0:  { 'type': b'f' },
+                    0:  { 'type': b'd' },
                     1:  { 'type': b'd' }
                 }
             }),
                     0:  { 'type': b'd' },
                 }
             }),
-            ('function30', b'vf' if sys.maxsize < 2**32 else b'vd' , { 
+            ('function30', b'vf' if sys.maxsize < 2**32 else b'vd' , '', { 
                 'arguments': {
                     0:  { 'type': b'f' if sys.maxsize < 2**32 else b'd'  },
                 }
                     0:  { 'type': b'@', 'null_accepted': False, 'already_retained': True, 'c_array_length_in_result': True }
                 }
             }),
-            ('function35', b'v@', '', { 
+            ('function36', b'v@', '', { 
                 'arguments': {
                     0:  { 'type': b'@', 'c_array_delimited_by_null': True, 'already_cfretained': True, 'c_array_of_variable_length': True,
                         'printf_format': True, 'free_result': True }
                 }
             }),
             ('function41', b'v?', '', { 
-                'type': b'?',
-                'callable_retained': False,
-                'callable': {
-                    'retval': { 'type': b'v' },
-                    'arguments': {
-                        0: { 'type': b'@' },
-                        1: { 'type': b'd' }
+                'arguments': {
+                    0: {
+                        'type': b'?',
+                        'callable_retained': False,
+                        'callable': {
+                            'retval': { 'type': b'v' },
+                            'arguments': {
+                                0: { 'type': b'@' },
+                                1: { 'type': b'd' }
+                            }
+                        }
                     }
                 }
             }),
-            ('function42', b'v?', '', { 
-                'type': b'?',
-                'callable_retained': False,
-                'callable': {
-                    'retval': { 'type': b'v' },
-                    'arguments': {
-                        0: { 'type': b'^v' },
-                        1: { 'type': b'@' },
-                        2: { 'type': b'd' }
+            ('function42', b'v@?', '', { 
+                'arguments': {
+                    0: {
+                        'type': b'@?',
+                        'callable_retained': False,
+                        'callable': {
+                            'retval': { 'type': b'v' },
+                            'arguments': {
+                                0: { 'type': b'^v' },
+                                1: { 'type': b'@' },
+                                2: { 'type': b'd' }
+                            }
+                        }
                     }
                 }
             }),
-            ('function43', b'v?', '', { 
-                'type': b'?',
-                'callable_retained': True,
-                'callable': {
-                    'retval': { 'type': b'v' },
-                    'arguments': {
-                        0: { 'type': b'@' },
-                        1: { 'type': b'd' }
+            ('function43', b'v?', '', {
+                'arguments': {
+                    0: { 
+                        'type': b'?',
+                        'callable_retained': True,
+                        'callable': {
+                            'retval': { 'type': b'v' },
+                            'arguments': {
+                                0: { 'type': b'@' },
+                                1: { 'type': b'd' }
+                            }
+                        }
                     }
                 }
             }),
-            ('function44', b'v?', '', { 
-                'type': b'?',
-                'callable_retained': True,
-                'callable': {
-                    'retval': { 'type': b'v' },
-                    'arguments': {
-                        0: { 'type': b'^v' },
-                        1: { 'type': b'@' },
-                        2: { 'type': b'd' }
+            ('function44', b'v@?', '', {
+                'arguments': {
+                    0: { 
+                        'type': b'@?',
+                        'callable_retained': True,
+                        'callable': {
+                            'retval': { 'type': b'v' },
+                            'arguments': {
+                                0: { 'type': b'^v' },
+                                1: { 'type': b'@' },
+                                2: { 'type': b'd' }
+                            }
+                        }
                     }
                 }
             }),
         ]
 
+        self.maxDiff = None
+        if sys.maxsize <= 2**32:
+            all_protocols = [
+                ('protocol2', [
+                    objc.selector(None, b'selector1', b'v@:f' if sys.maxsize < 2**32 else b'v@:d'),
+                    objc.selector(None, b'selector2', b'v@:f' if sys.maxint < 2 **32 else b'v@:d'),
+                    objc.selector(None, b'selector3', b'v@:f' if sys.maxint < 2 **32 else b'v@:d', isClassMethod=True),
+                    objc.selector(None, b'selector4', b'v@:f' if sys.maxint < 2 **32 else b'v@:d'),
+                    objc. selector(None, b'selector7', b'v@:f'),
+                    objc.selector(None, b'selector8', b'v@:f', isClassMethod=True),
+                ]),
+            ]
+        else:
+            all_protocols = [
+                ('protocol2', [
+                    objc.selector(None, b'selector1', b'v@:f' if sys.maxsize < 2**32 else b'v@:d'),
+                    objc.selector(None, b'selector2', b'v@:f' if sys.maxint < 2 **32 else b'v@:d'),
+                    objc.selector(None, b'selector3', b'v@:f' if sys.maxint < 2 **32 else b'v@:d', isClassMethod=True),
+                    objc.selector(None, b'selector4', b'v@:f' if sys.maxint < 2 **32 else b'v@:d'),
+                    objc.selector(None, b'selector6', b'v@:@'),
+                    objc. selector(None, b'selector7', b'v@:f'),
+                    objc.selector(None, b'selector8', b'v@:f', isClassMethod=True),
+                ]),
+            ]
+
+        all_structs = [
+            ('struct3', b'{struct3=@@}', None),
+            ('struct4', b'{struct3=ff}' if sys.maxsize < 2**32 else b'{struct4=dd}', None),
+            ('struct5', b'{struct3=@@}', None),
+            ('struct6', b'{struct6=ZZ}', None),
+            ('struct7', b'{struct7=B@}', None),
+            ('struct8', b'{struct8=@@}', sys.maxsize),
+        ]
+
+
         self.assertItemsEqual(prs.constants,    all_constants)
         self.assertEqual(prs.values,            all_values)
         self.assertItemsEqual(prs.opaque,       all_opaque)
         self.assertItemsEqual(prs.func_aliases, all_func_aliases)
         self.assertItemsEqual(prs.cftypes,      all_cftypes)
-
-        self.maxDiff = None
         self.assertItemsEqual(prs.functions,    all_functions)
-
-        self.maxDiff = None
         self.assertEqual(prs.meta,              all_methods)
-        self.fail("validate the metadata from TEST_XML")
-
-
-
-        '''
-  <!-- TODO: type rewriting (_C_BOOL, _C_NSBOOL)-->
-  <informal_protocol/><!-- ignore -->
-  <informal_protocol name='protocol1' />
-  <informal_protocol name='protocol1' >
-    <method selector='selector1' type='v@:f' type64='v@:d' />
-    <method selector='selector2' type='v@:f' type64='v@:d' classmethod='false' />
-    <method selector='selector3' type='v@:f' type64='v@:d' classmethod='true' />
-    <method selector='selector4' type='v@:f' type64='v@:d' variadic='true' /><!-- 'variadic' is ignored -->
-    <method selector='selector5' /><!-- ignore: no type -->
-    <method selector='selector6' type64='v@:@' /><!-- ignore 32-bit -->
-    <method selector='selector7' type='v@:f' type64='v@:d' class_method='false' /><!-- manpage: class_method, pyobjc 2.3: classmethod -->
-    <method selector='selector8' type='v@:f' type64='v@:d' class_method='true' />
-  </informal_protocol>
-  <struct/><!-- ignore -->
-  <struct type='{foo=dd}' /><!--ignore-->
-  <struct name='struct1' /><!-- ignore -->
-  <struct name='struct2' alias='module.struct3' /><!-- ignore -->
-  <struct name='struct3' type='{struct3=@@}' />
-  <struct name='struct4' type='{struct3=ff}' type64='{struct4=dd}' />
-  <struct name='struct5' type='{struct3=@@}' alias='module2.struct'/>
-  <struct name='struct6' type='{struct6=BB}' /><!-- _C_NSBOOL -->
-  <struct name='struct7' type='{struct7=Z@}' /><!-- _C_BOOL -->
-</signatures>
-'''
+        self.assertItemsEqual(prs.informal_protocols,    all_protocols)
+        self.assertItemsEqual(prs.structs,      all_structs)
 
     def assertIsIdentifier(self, value):
         m = IDENTIFIER.match(value)
 
             self.assertEqual(len(objc.splitSignature(typestr)), 1)
 
-        for name, typestr in prs.structs:
+        for name, typestr, alias in prs.structs:
             self.assertIsInstance(name, basestring)
             self.assertIsInstance(typestr, bytes)
-
             self.assertEqual(len(objc.splitSignature(typestr)), 1)
 
         for name in prs.values:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.