Author: ronaldoussoren
Date: Tue Jan 27 01:01:04 2009
New Revision: 2047
Log:
Various small bugfixes
Modified:
trunk/pyobjc/pyobjc-core/Lib/PyObjCTools/TestSupport.py
trunk/pyobjc/pyobjc-core/Lib/objc/test/test_protocol.py
trunk/pyobjc/pyobjc-core/Modules/objc/bundle-variables.m
trunk/pyobjc/pyobjc-core/Modules/objc/class-builder.m
trunk/pyobjc/pyobjc-core/Modules/objc/libffi_support.m
trunk/pyobjc/pyobjc-core/Modules/objc/module.m
Modified: trunk/pyobjc/pyobjc-core/Lib/PyObjCTools/TestSupport.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/Lib/PyObjCTools/TestSupport.py (original)
+++ trunk/pyobjc/pyobjc-core/Lib/PyObjCTools/TestSupport.py Tue Jan 27 01:01:04 2009
@@ -10,6 +10,8 @@
import os as _os
import gc as _gc
import subprocess as _subprocess
+import sys as _sys
+import struct as _struct
# Have a way to disable the autorelease pool behaviour
_usepool = not _os.environ.get('PYOBJC_NO_AUTORELEASE')
@@ -17,6 +19,30 @@
_useleaks = False
_leaksVerbose = False
+def fourcc(v):
+ """
+ Decode four-character-code integer definition
+
+ (e.g. 'abcd')
+ """
+ return _struct.unpack('>i', v)[0]
+
+def cast_int(value):
+ """
+ Cast value to 32bit integer
+
+ Usage:
+ cast_int(1 << 31) == -1
+
+ (where as: 1 << 31 == 2147483648)
+ """
+ value = value & 0xffffffff
+ if value & 0x80000000:
+ value = ~value + 1 & 0xffffffff
+ return -value
+ else:
+ return value
+
_os_release = None
def os_release():
"""
@@ -31,6 +57,23 @@
v = pl['ProductVersion']
return '.'.join(v.split('.')[:2])
+def onlyOn32Bit(function):
+ """
+ Usage::
+
+ class Tests (unittest.TestCase):
+
+ @onlyOn32Bit
+ def test32BitOnly(self):
+ pass
+
+ The test runs only on 32-bit systems
+ """
+ if _sys.maxint > 2 ** 32:
+ return None
+ else:
+ return function
+
def min_os_level(release):
"""
@@ -48,13 +91,9 @@
else:
def decorator(function):
- def result(self):
- pass
-
- result.func_name = function.func_name
- return result
-
+ return None
+ return decorator
@@ -74,11 +113,149 @@
This also adds a number of useful assertion methods
"""
+ def failUnlessIsNone(self, value, message = None):
+ if value is not None:
+ sel.fail(message, "%r is not %r"%(value, test))
+
+ def failIfIsNone(self, value, message = None):
+ if value is None:
+ sel.fail(message, "%r is not %r"%(value, test))
+
+ def failUnlessArgIsCFRetained(self, method, argno, message = None):
+ if isinstance(method, objc.selector):
+ offset = 2
+ else:
+ offset = 0
+ info = method.__metadata__()
+ if not info['arguments'][argno+offset]['already_cfretained']:
+ self.fail(message or "%r is not cfretained"%(method,))
+
+ def failIfArgIsCFRetained(self, method, argno, message = None):
+ if isinstance(method, objc.selector):
+ offset = 2
+ else:
+ offset = 0
+ info = method.__metadata__()
+ if info['arguments'][argno+offset]['already_cfretained']:
+ self.fail(message or "%r is cfretained"%(method,))
+
+ def failUnlessResultIsCFRetained(self, method, message = None):
+ info = method.__metadata__()
+ if not info['retval']['already_cfretained']:
+ self.fail(message or "%r is not cfretained"%(method,))
+
+ def failIfResultIsCFRetained(self, method, message = None):
+ info = method.__metadata__()
+ if info['retval']['already_cfretained']:
+ self.fail(message or "%r is cfretained"%(method,))
+
+ def failUnlessResultIsRetained(self, method, message = None):
+ info = method.__metadata__()
+ if not info['retval']['already_retained']:
+ self.fail(message or "%r is not retained"%(method,))
+
+ def failIfResultIsRetained(self, method, message = None):
+ info = method.__metadata__()
+ if info['retval']['already_retained']:
+ self.fail(message or "%r is retained"%(method,))
+
+ def failUnlessResultHasType(self, method, tp, message=None):
+ info = method.__metadata__()
+ type = info['retval']['type']
+ if type != tp:
+ self.fail(message or "result of %r is not of type %r, but %r"%(
+ method, tp, type))
+
+ def failUnlessArgHasType(self, method, argno, tp, message=None):
+ if isinstance(method, objc.selector):
+ offset = 2
+ else:
+ offset = 0
+ info = method.__metadata__()
+ type = info['arguments'][argno+offset]['type']
+ if type != tp:
+ self.fail(message or "arg %d of %s is not of type %r, but %r"%(
+ argno, method, tp, type))
+
+ def failUnlessArgIsSEL(self, method, argno, sel_type, message=None):
+ if isinstance(method, objc.selector):
+ offset = 2
+ else:
+ offset = 0
+ info = method.__metadata__()
+ type = info['arguments'][argno+offset]['type']
+ if type != objc._C_SEL:
+ self.fail(message or "arg %d of %s is not of type SEL"%(
+ argno, method))
+
+ st = info['arguments'][argno+offset]['sel_of_type']
+ if st != sel_type:
+ self.fail(message or "arg %d of %s doesn't have sel_type %r"%(
+ argno, method, seltype))
+
+ def failUnlessResultIsBOOL(self, method, message=None):
+ info = method.__metadata__()
+ type = info['retval']['type']
+ if type != objc._C_NSBOOL:
+ self.fail(message or "result of %s is not of type BOOL"%(
+ method))
+
+ def failUnlessArgIsBOOL(self, method, argno, message=None):
+ if isinstance(method, objc.selector):
+ offset = 2
+ else:
+ offset = 0
+ info = method.__metadata__()
+ type = info['arguments'][argno+offset]['type']
+ if type != objc._C_NSBOOL:
+ self.fail(message or "arg %d of %s is not of type BOOL"%(
+ argno, method))
+
+ def failUnlessArgIsOut(self, method, argno, message=None):
+ if isinstance(method, objc.selector):
+ offset = 2
+ else:
+ offset = 0
+ info = method.__metadata__()
+ type = info['arguments'][argno+offset]['type']
+ if not type.startswith('o^'):
+ self.fail(message or "arg %d of %s is not an 'out' argument"%(
+ argno, method))
+
+ def failUnlessArgIsInOut(self, method, argno, message=None):
+ if isinstance(method, objc.selector):
+ offset = 2
+ else:
+ offset = 0
+ info = method.__metadata__()
+ type = info['arguments'][argno+offset]['type']
+ if not type.startswith('N^'):
+ self.fail(message or "arg %d of %s is not an 'inout' argument"%(
+ argno, method))
+
+ def failUnlessArgIsIn(self, method, argno, message=None):
+ if isinstance(method, objc.selector):
+ offset = 2
+ else:
+ offset = 0
+ info = method.__metadata__()
+ type = info['arguments'][argno+offset]['type']
+ if not type.startswith('n^'):
+ self.fail(message or "arg %d of %s is not an 'in' argument"%(
+ argno, method))
+
+
+ def failUnlessStartswith(self, value, check, message=None):
+ if not value.startswith(check):
+ self.fail(message or "not %r.startswith(%r)"%(value, check))
+
def failUnlessIsInstance(self, value, types, message=None):
- self.failUnless(isinstance(value, types), message)
+ if not isinstance(value, types):
+ self.fail(message or "%s is not an instance of %r"%(value, types))
def failIfIsInstance(self, value, types, message=None):
- self.failUnless(isinstance(value, types), message)
+ if isinstance(value, types):
+ self.fail(message or "%s is an instance of %r"%(value, types))
assertIsInstance = failUnlessIsInstance
Modified: trunk/pyobjc/pyobjc-core/Lib/objc/test/test_protocol.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/Lib/objc/test/test_protocol.py (original)
+++ trunk/pyobjc/pyobjc-core/Lib/objc/test/test_protocol.py Tue Jan 27 01:01:04 2009
@@ -243,5 +243,8 @@
# cause a warning when called.
self.assertEquals(1, 0)
+ def test_Missing(self):
+ self.fail("Implement test for class that doesn't implement a formal protocl, seems to be missing")
+
if __name__ == '__main__':
main()
Modified: trunk/pyobjc/pyobjc-core/Modules/objc/bundle-variables.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/bundle-variables.m (original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/bundle-variables.m Tue Jan 27 01:01:04 2009
@@ -10,6 +10,8 @@
#import <Foundation/NSBundle.h>
#import <Foundation/NSURL.h>
+#include <dlfcn.h>
+
static CFBundleRef
NSBundle2CFBundle(NSBundle* bundle)
{
Modified: trunk/pyobjc/pyobjc-core/Modules/objc/class-builder.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/class-builder.m (original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/class-builder.m Tue Jan 27 01:01:04 2009
@@ -787,18 +787,23 @@
}
}
}
+ if (PyErr_Occurred()) {
+ goto error_cleanup;
+ }
/* First round, count new instance-vars and check for overridden
* methods.
*/
for (i = 0; i < key_count; i++) {
key = PyList_GET_ITEM(key_list, i);
+#if 0
if (PyErr_Occurred()) {
PyErr_SetString(PyObjCExc_InternalError,
"PyObjCClass_BuildClass: "
"Cannot fetch key in keylist");
goto error_cleanup;
}
+#endif
value = PyDict_GetItem(class_dict, key);
if (value == NULL) {
Modified: trunk/pyobjc/pyobjc-core/Modules/objc/libffi_support.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/libffi_support.m (original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/libffi_support.m Tue Jan 27 01:01:04 2009
@@ -1279,10 +1279,21 @@
if (err == -1) {
if (res == Py_None) {
- PyErr_Format(PyExc_ValueError,
- "%s: returned None, expecting "
- "a value",
- sel_getName(*(SEL*)args[1]));
+ if (userdata->isMethod) {
+ PyErr_Format(PyExc_ValueError,
+ "%s: returned None, expecting "
+ "a value",
+ sel_getName(*(SEL*)args[1]));
+ } else {
+ PyObject* repr = PyObject_Repr(
+ userdata->callable);
+ PyErr_Format(PyExc_ValueError,
+ "%s: returned None, expecting "
+ "a value",
+ PyString_AsString(repr));
+ Py_XDECREF(repr);
+ }
+
}
Py_DECREF(res);
goto error;
@@ -1290,10 +1301,20 @@
}
} else {
if (res != Py_None) {
- PyErr_Format(PyExc_ValueError,
- "%s: did not return None, expecting "
- "void return value",
- sel_getName(*(SEL*)args[1]));
+ if (userdata->isMethod) {
+ PyErr_Format(PyExc_ValueError,
+ "%s: did not return None, expecting "
+ "void return value",
+ sel_getName(*(SEL*)args[1]));
+ } else {
+ PyObject* repr = PyObject_Repr(
+ userdata->callable);
+ PyErr_Format(PyExc_ValueError,
+ "%s: returned None, expecting "
+ "a value",
+ PyString_AsString(repr));
+ Py_XDECREF(repr);
+ }
goto error;
}
//*((int*)resp) = 0;
Modified: trunk/pyobjc/pyobjc-core/Modules/objc/module.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/module.m (original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/module.m Tue Jan 27 01:01:04 2009
@@ -10,6 +10,7 @@
#include <stddef.h>
#include <ctype.h>
#include <sys/socket.h>
+#include <netinet/in.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSBundle.h>
@@ -1915,6 +1916,15 @@
/* Add _C_CFTYPEID to avoid hardcoding this in our python code */
PyModule_AddStringConstant(m, "_C_CFTYPEID", @encode(CFTypeID));
+ /* Likewise for _C_NSInteger and _C_NSUInteger */
+ PyModule_AddStringConstant(m, "_C_NSInteger", @encode(NSInteger));
+ PyModule_AddStringConstant(m, "_C_NSUInteger", @encode(NSUInteger));
+ PyModule_AddStringConstant(m, "_C_CFIndex", @encode(CFIndex));
+
+
+ PyModule_AddIntConstant(m, "_size_sockaddr_ip4", sizeof(struct sockaddr_in));
+ PyModule_AddIntConstant(m, "_size_sockaddr_ip6", sizeof(struct sockaddr_in6));
+
PyModule_AddStringConstant(m, "__version__", OBJC_VERSION);
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.