[PyObjC-svn] r2586 - in trunk/pyobjc/pyobjc-framework-Quartz: . Lib/Quartz/CoreGraphics Modules PyObjCTest

[email protected] Tue, 17 Aug 2010 14:48:09 -0500
Newsgroups gmane.comp.python.pyobjc.cvs
Message-ID <[email protected]>
Author: ronaldoussoren
Date: Tue Aug 17 14:48:09 2010
New Revision: 2586

Log:
Improve test coverage and fix issues found by the added tests.

Quartz is now the only framework with some failing tests (all due to incomplete test cases)


Modified:
   trunk/pyobjc/pyobjc-framework-Quartz/Lib/Quartz/CoreGraphics/PyObjC.bridgesupport
   trunk/pyobjc/pyobjc-framework-Quartz/Modules/_coregraphics.m
   trunk/pyobjc/pyobjc-framework-Quartz/PyObjCTest/test_cgbitmapcontext.py
   trunk/pyobjc/pyobjc-framework-Quartz/PyObjCTest/test_cgcontext.py
   trunk/pyobjc/pyobjc-framework-Quartz/PyObjCTest/test_cgevent.py
   trunk/pyobjc/pyobjc-framework-Quartz/PyObjCTest/test_qcplugin.py
   trunk/pyobjc/pyobjc-framework-Quartz/setup.py

Modified: trunk/pyobjc/pyobjc-framework-Quartz/Lib/Quartz/CoreGraphics/PyObjC.bridgesupport
==============================================================================
--- trunk/pyobjc/pyobjc-framework-Quartz/Lib/Quartz/CoreGraphics/PyObjC.bridgesupport	(original)
+++ trunk/pyobjc/pyobjc-framework-Quartz/Lib/Quartz/CoreGraphics/PyObjC.bridgesupport	Tue Aug 17 14:48:09 2010
@@ -1365,7 +1365,7 @@
   </function>
   <function name='CGContextShowGlyphs'>
     <arg type='^{CGContext=}' />
-    <arg c_array_length_in_arg='1' type='^S' type_modifier='n' />
+    <arg c_array_length_in_arg='2' type='^S' type_modifier='n' />
     <arg type='L' type64='L' />
   </function>
   <function name='CGContextShowGlyphsAtPoint'>
@@ -1377,8 +1377,8 @@
   </function>
   <function name='CGContextShowGlyphsAtPositions'>
     <arg type='^{CGContext=}' />
-    <arg c_array_length_in_arg='3' type='^S' />
-    <arg c_array_length_in_arg='3' type='^{CGPoint=ff}' type64='^{CGPoint=dd}' />
+    <arg c_array_length_in_arg='3' type='^S' type_modifier='n' />
+    <arg c_array_length_in_arg='3' type='^{CGPoint=ff}' type64='^{CGPoint=dd}' type_modifier='n' />
     <arg type='L' type64='L' />
   </function>
   <function name='CGContextShowGlyphsWithAdvances'>

Modified: trunk/pyobjc/pyobjc-framework-Quartz/Modules/_coregraphics.m
==============================================================================
--- trunk/pyobjc/pyobjc-framework-Quartz/Modules/_coregraphics.m	(original)
+++ trunk/pyobjc/pyobjc-framework-Quartz/Modules/_coregraphics.m	Tue Aug 17 14:48:09 2010
@@ -334,6 +334,133 @@
 	return rv;
 }
 
+#if PyObjC_BUILD_RELEASE >= 1006
+static void
+m_releasecallback(void* releaseInfo, void* data)
+{
+	PyObject* py_data = (PyObject*)releaseInfo;
+
+	PyGILState_STATE   state = PyGILState_Ensure();
+
+	if (PyTuple_GET_ITEM(releaseInfo, 0) != Py_None) {
+		PyObject* r = PyObject_CallFunction(
+			PyTuple_GET_ITEM(py_data, 0), "OO",
+			PyTuple_GET_ITEM(py_data, 1),
+			PyTuple_GET_ITEM(py_data, 2));
+		Py_XDECREF(r);
+	}
+
+	Py_DECREF(py_data);
+
+	if (PyErr_Occurred()) {
+		PyObjCErr_ToObjCWithGILState(&state);
+	}
+	PyGILState_Release(state);
+
+}
+
+static PyObject*
+m_CGBitmapContextCreateWithData(PyObject* self __attribute__((__unused__)), 
+		PyObject* args)
+{
+	PyObject* py_data;
+	PyObject* py_width;
+	PyObject* py_height;
+	PyObject* py_bitsPerComponent;
+	PyObject* py_bytesPerRow;
+	PyObject* py_colorSpace;
+	PyObject* py_bitmapInfo;
+	PyObject* py_releaseCallback;
+	PyObject* py_releaseInfo;
+
+	void*	data;
+	size_t  width;
+	size_t  height;
+	size_t  bitsPerComponent;
+	size_t  bytesPerRow;
+	CGColorSpaceRef colorSpace;
+	CGBitmapInfo bitmapInfo;
+
+	if (!PyArg_ParseTuple(args, "OOOOOOOOO", 
+		&py_data, &py_width, &py_height, &py_bitsPerComponent, 
+		&py_bytesPerRow, &py_colorSpace, &py_bitmapInfo,
+		&py_releaseCallback, &py_releaseInfo
+		)) {
+		return NULL;
+	}
+
+	if (PyObjC_PythonToObjC(@encode(size_t), py_width, &width) == -1) {
+		return NULL;
+	}
+	if (PyObjC_PythonToObjC(@encode(size_t), py_height, &height) == -1) {
+		return NULL;
+	}
+	if (PyObjC_PythonToObjC(@encode(size_t), py_bitsPerComponent, &bitsPerComponent) == -1) {
+		return NULL;
+	}
+	if (PyObjC_PythonToObjC(@encode(size_t), py_bytesPerRow, &bytesPerRow) == -1) {
+		return NULL;
+	}
+	if (PyObjC_PythonToObjC(@encode(CGColorSpaceRef), py_colorSpace, &colorSpace) == -1) {
+		return NULL;
+	}
+	if (PyObjC_PythonToObjC(@encode(CGBitmapInfo), py_bitmapInfo, &bitmapInfo) == -1) {
+		return NULL;
+	}
+
+	if (py_data == Py_None) {
+		data = NULL;
+
+	} else if (PyUnicode_Check(py_data)) {
+		PyErr_SetString(PyExc_TypeError, "Cannot use Unicode as backing store");
+		return NULL;
+
+	} else {
+		Py_ssize_t size;
+
+		if (PyObject_AsWriteBuffer(py_data, &data, &size) == -1) {
+			return NULL;
+		}
+	}
+
+	PyObject* releaseInfo = PyTuple_New(3);
+	if (releaseInfo == NULL) {
+		return NULL;
+	}
+	PyTuple_SET_ITEM(releaseInfo, 0, py_releaseCallback);
+	Py_INCREF(py_releaseCallback);
+	PyTuple_SET_ITEM(releaseInfo, 1, py_releaseInfo);
+	Py_INCREF(py_releaseInfo);
+	PyTuple_SET_ITEM(releaseInfo, 2, py_data);
+	Py_INCREF(py_data);
+
+
+	CGContextRef ctx = NULL;
+	PyObjC_DURING
+		ctx = CGBitmapContextCreateWithData(data, width, height, bitsPerComponent, bytesPerRow, colorSpace, bitmapInfo, m_releasecallback, releaseInfo);
+
+	PyObjC_HANDLER
+		ctx = NULL;
+		PyObjCErr_FromObjC(localException);
+	PyObjC_ENDHANDLER
+
+	if (ctx == NULL && PyErr_Occurred()) {
+		Py_DECREF(releaseInfo);
+		return NULL;
+	}
+
+	if (ctx == NULL)  {
+		Py_DECREF(releaseInfo);
+		Py_INCREF(Py_None);
+		return Py_None;
+	}
+
+	PyObject* rv = PyObjC_ObjCToPython(@encode(CGContextRef), &ctx);
+	CFRelease(ctx);
+	return rv;
+}
+#endif
+
 
 static PyMethodDef mod_methods[] = {
 #if PyObjC_BUILD_RELEASE >= 1005
@@ -368,6 +495,14 @@
 		METH_VARARGS,
 		NULL
 	},
+#if PyObjC_BUILD_RELEASE >= 1006
+	{
+		"CGBitmapContextCreateWithData",
+		(PyCFunction)m_CGBitmapContextCreateWithData,
+		METH_VARARGS,
+		NULL
+	},
+#endif
 
 
 	{ 0, 0, 0, }

Modified: trunk/pyobjc/pyobjc-framework-Quartz/PyObjCTest/test_cgbitmapcontext.py
==============================================================================
--- trunk/pyobjc/pyobjc-framework-Quartz/PyObjCTest/test_cgbitmapcontext.py	(original)
+++ trunk/pyobjc/pyobjc-framework-Quartz/PyObjCTest/test_cgbitmapcontext.py	Tue Aug 17 14:48:09 2010
@@ -35,7 +35,23 @@
 
 
     def testFunctions106_(self):
-        self.fail("CGBitmapContextCreateWithData: manual wrapper")
+        bytes_val = array.array('B', (0 for i in xrange(100*80*4)))
+        ctx = CGBitmapContextCreateWithData(bytes_val, 100, 80, 8, 400, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast, None, None)
+        self.assertIsInstance(ctx, CGContextRef)
+        del ctx
+
+        list = []
+        release_info = object()
+        def callback(info, data):
+            list.append((info, data))
+
+        ctx = CGBitmapContextCreateWithData(bytes_val, 100, 80, 8, 400, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast, callback, release_info)
+        self.assertIsInstance(ctx, CGContextRef)
+        del ctx
+
+        self.assertEquals(len(list), 1)
+        self.assertIs(list[0][0], release_info)
+        self.assertIs(list[0][1], bytes_val)
 
 
 if __name__ == "__main__":

Modified: trunk/pyobjc/pyobjc-framework-Quartz/PyObjCTest/test_cgcontext.py
==============================================================================
--- trunk/pyobjc/pyobjc-framework-Quartz/PyObjCTest/test_cgcontext.py	(original)
+++ trunk/pyobjc/pyobjc-framework-Quartz/PyObjCTest/test_cgcontext.py	Tue Aug 17 14:48:09 2010
@@ -413,13 +413,32 @@
             if os.path.exists("/tmp/pyobjc.test.pdf"):
                 os.unlink("/tmp/pyobjc.test.pdf")
 
-    def testMissing(self):
-        self.fail("CGContextShowGlyphsAtPositions")
-        self.fail("CGContextShowGlyphs")
-        self.fail("CGContextShowGlyphsAtPoint")
-        self.fail("CGContextShowGlyphsWithAdvances")
-        self.fail("CGContextDrawPDFPage")
-        self.fail("CGContextDrawPDFDocument")
+    def testGlyphFunctions(self):
+        self.assertArgHasType(CGContextShowGlyphsAtPositions, 1, 'n^S')
+        self.assertArgSizeInArg(CGContextShowGlyphsAtPositions, 1, 3)
+        self.assertArgHasType(CGContextShowGlyphsAtPositions, 2, 'n^' + CGPoint.__typestr__)
+        self.assertArgSizeInArg(CGContextShowGlyphsAtPositions, 2, 3)
+
+        self.assertArgHasType(CGContextShowGlyphs, 1, 'n^S')
+        self.assertArgSizeInArg(CGContextShowGlyphs, 1, 2)
+
+        self.assertArgHasType(CGContextShowGlyphsAtPoint, 1, objc._C_CGFloat)
+        self.assertArgHasType(CGContextShowGlyphsAtPoint, 2, objc._C_CGFloat)
+        self.assertArgHasType(CGContextShowGlyphsAtPoint, 3, 'n^S')
+        self.assertArgSizeInArg(CGContextShowGlyphsAtPoint, 3, 4)
+
+        self.assertArgHasType(CGContextShowGlyphsWithAdvances, 1, 'n^S')
+        self.assertArgSizeInArg(CGContextShowGlyphsWithAdvances, 1, 3)
+        self.assertArgHasType(CGContextShowGlyphsWithAdvances, 2, 'n^' + CGSize.__typestr__)
+        self.assertArgSizeInArg(CGContextShowGlyphsWithAdvances, 2, 3)
+
+        self.assertArgHasType(CGContextDrawPDFPage, 0, '^{CGContext=}')
+        self.assertArgHasType(CGContextDrawPDFPage, 1, '^{CGPDFPage=}')
+
+        self.assertArgHasType(CGContextDrawPDFDocument, 0, '^{CGContext=}')
+        self.assertArgHasType(CGContextDrawPDFDocument, 1, CGRect.__typestr__)
+        self.assertArgHasType(CGContextDrawPDFDocument, 2, '^{CGPDFDocument=}')
+        self.assertArgHasType(CGContextDrawPDFDocument, 3, objc._C_INT)
 
 
     @min_os_level('10.5')

Modified: trunk/pyobjc/pyobjc-framework-Quartz/PyObjCTest/test_cgevent.py
==============================================================================
--- trunk/pyobjc/pyobjc-framework-Quartz/PyObjCTest/test_cgevent.py	(original)
+++ trunk/pyobjc/pyobjc-framework-Quartz/PyObjCTest/test_cgevent.py	Tue Aug 17 14:48:09 2010
@@ -7,7 +7,7 @@
         self.assertIsCFType(CGEventRef)
         self.assertIsCFType(CGEventSourceRef)
 
-    def testMissing(self):
+    def testEventFunctions(self):
         evt = CGEventCreateMouseEvent(None, kCGEventLeftMouseDown, (80, 90), kCGMouseButtonLeft)
         self.assertIsInstance(evt, CGEventRef)
 
@@ -61,13 +61,33 @@
 
         CGEventSetDoubleValueField(evt, kCGMouseEventPressure, 42.5)
 
+        self.assertArgHasType(CGEventTapEnable, 0, '^{__CFMachPort=}')
+        self.assertArgHasType(CGEventTapEnable, 1, objc._C_BOOL)
+
+        self.assertResultHasType(CGEventTapIsEnabled, objc._C_BOOL)
+        self.assertArgHasType(CGEventTapIsEnabled, 0, '^{__CFMachPort=}')
+
+        self.assertArgHasType(CGEventTapPostEvent, 0, '^{__CGEventTapProxy=}')
+        self.assertArgHasType(CGEventTapPostEvent, 1, '^{__CGEvent=}')
+
+        self.assertResultHasType(CGGetEventTapList, objc._C_INT)
+        self.assertArgHasType(CGGetEventTapList, 0, objc._C_UINT)
+        self.assertArgHasType(CGGetEventTapList, 1, 'o^' + CGEventTapInformation.__typestr__)
+        self.assertArgSizeInArg(CGGetEventTapList, 1, (0, 2))
+        self.assertArgHasType(CGGetEventTapList, 2, 'o^' + objc._C_UINT)
+
+        self.assertResultHasType(CGEventPost, objc._C_VOID)
+        self.assertArgHasType(CGEventPost, 0, objc._C_UINT)
+        self.assertArgHasType(CGEventPost, 1, '^{__CGEvent=}')
+
+        self.assertResultHasType(CGEventPostToPSN, objc._C_VOID)
+        self.assertArgHasType(CGEventPostToPSN, 0, 'n^{ProcessSerialNumber=II}')
+        self.assertArgHasType(CGEventPostToPSN, 1, '^{__CGEvent=}')
+
+
+    @expectedFailure
+    def testMissing(self):
         self.fail("CGEventTapCreateForPSN")
-        self.fail("CGEventTapEnable")
-        self.fail("CGEventTapIsEnabled")
-        self.fail("CGEventTapPostEvent")
-        self.fail("CGGetEventTapList")
-        self.fail("CGEventPost")
-        self.fail("CGEventPostToPSN")
 
 
     def testFunctions(self):

Modified: trunk/pyobjc/pyobjc-framework-Quartz/PyObjCTest/test_qcplugin.py
==============================================================================
--- trunk/pyobjc/pyobjc-framework-Quartz/PyObjCTest/test_qcplugin.py	(original)
+++ trunk/pyobjc/pyobjc-framework-Quartz/PyObjCTest/test_qcplugin.py	Tue Aug 17 14:48:09 2010
@@ -2,7 +2,6 @@
 from PyObjCTools.TestSupport import *
 from Quartz.QuartzComposer import *
 
-
 class TestQCPlugIn (TestCase):
     @min_os_level('10.5')
     def testConstants10_5(self):
@@ -52,6 +51,7 @@
         self.assertResultIsBOOL(QCPlugIn.setValue_forOutputKey_)
         self.assertResultIsBOOL(QCPlugIn.loadPlugInAtPath_)
 
+    @expectedFailure
     def testProtocols(self):
         self.fail("Test interface for QCPlugInContext")
 

Modified: trunk/pyobjc/pyobjc-framework-Quartz/setup.py
==============================================================================
--- trunk/pyobjc/pyobjc-framework-Quartz/setup.py	(original)
+++ trunk/pyobjc/pyobjc-framework-Quartz/setup.py	Tue Aug 17 14:48:09 2010
@@ -32,6 +32,15 @@
 
 WARNING: Running the unittests will change your display settings during the
 testrun, which will probably mess up your window layout.
+
+NEWS
+====
+
+2.4
+---
+
+* Add wrapper for ``CGBitmapContextCreateWithData``
+
 '''
 
 from pyobjc_setup import setup, Extension

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev