Commits

Ronald Oussoren committed b849861

Some additional unittests that were added while looking for the OutlineEdit
problem. All of them pass :-(

Comments (0)

Files changed (3)

Lib/objc/test/test_regr.py

 import unittest
+from objc.test import structargs
 
-import objc
+import objc, sys
+import Foundation
 
 NSObject = objc.lookUpClass('NSObject')
 
+class ReturnAStruct (NSObject):
+    def someRectWithRect_(self, ((x, y), (h, w))):
+        return ((x,y),(h,w))
+    someRectWithRect_ = objc.selector(someRectWithRect_,
+            signature='{_NSRect={_NSPoint=ff}{_NSSize=ff}}@:{_NSRect={_NSPoint=ff}{_NSSize=ff}}')
+
 class TestRegressions(unittest.TestCase):
     def testNSObjectRespondsToCommonMethods(self):
         self.assert_(NSObject.pyobjc_classMethods.respondsToSelector_('alloc'))
         v = o.compP_aRect_anOp_((1,2), ((3,4),(5,6)), 7)
         self.assertEquals(v, u"aP:{1, 2} aR:{{3, 4}, {5, 6}} anO:7")
 
+    def testStructReturnPy(self):
+        from objc.test.structargs import StructArgClass
+        o = ReturnAStruct.alloc().init()
+        p = StructArgClass.alloc().init()
+
+        v = p.someRectWithObject_X_Y_H_W_(o, 1, 2, 3, 4)
+        self.assert_(isinstance(v, Foundation.NSRect))
+        self.assertEquals(v, ((1,2),(3,4)))
+
+    def testStructReturn(self):
+        from objc.test.structargs import StructArgClass
+        o = StructArgClass.alloc().init()
+
+        v = o.someRect()
+        self.assertEquals(v, ((1,2),(3,4)))
+
+
     def testInitialize(self):
         calls=[]
         class InitializeTestClass (NSObject):
         o = InitializeTestClass.new()
         self.assertEquals(len(calls), 1)
 
+    if sys.byteorder == 'little':
+        # i386 has specific stack alignment requirements.
+
+        class AlignmentTestClass(NSObject):
+            def testWithObject_(self, obj):
+                return obj.stackPtr()
+
+
+        def testStackPtr(self):
+            o = structargs.StructArgClass.alloc().init()
+
+            self.assertEquals(o.stackPtr() % 16, 0)
+            self.assertEquals(o.stackPtr() % 16, 0)
+            self.assertEquals(o.stackPtr() % 16, 0)
+
+            p = self.AlignmentTestClass.alloc().init()
+            self.assertEquals(p.testWithObject_(o) % 16, o.stackPtr() % 16)
+
 if __name__ == '__main__':
     unittest.main()

Modules/objc/test/ctests.m

 	    sizeof(struct Struct4), PyObjCRT_SizeOfType(@encode(struct Struct4)),
 	    "%d");
 
+	ASSERT_EQUALS(
+	    sizeof(NSRect), PyObjCRT_SizeOfType(@encode(NSRect)), "%d");
+
 END_UNITTEST
 
 BEGIN_UNITTEST(StructAlign)
 	ASSERT(r != -1);
 END_UNITTEST
 
+BEGIN_UNITTEST(FillNSRect)
+
+	struct output {
+		unsigned int before;
+		NSRect rect;
+		unsigned int after;
+	};
+
+
+	PyObject* input;
+	PyObject* v;
+	PyObject* t;
+	struct output output;
+	int r;
+
+	output.before = 0xDEADBEEF;
+	output.after = 0xBEEFDEAD;
+
+	input = PyTuple_New(2);
+	FAIL_IF(input == NULL);
+
+	v= PyTuple_New(2);
+	PyTuple_SET_ITEM(v, 0, PyInt_FromLong(10));
+	PyTuple_SET_ITEM(v, 1, PyInt_FromLong(11));
+
+	t= PyTuple_New(2);
+	PyTuple_SET_ITEM(t, 0, PyInt_FromLong(20));
+	PyTuple_SET_ITEM(t, 1, PyInt_FromLong(21));
+
+	PyTuple_SET_ITEM(input, 0, v);
+	PyTuple_SET_ITEM(input, 1, t);
+	
+	r = PyObjC_PythonToObjC(@encode(struct NSRect), input, &output.rect);
+	FAIL_IF(r < 0);
+
+	Py_DECREF(input);
+
+	ASSERT_EQUALS(output.rect.origin.x, 10, "%d");
+	ASSERT_EQUALS(output.rect.origin.y, 11, "%d");
+	ASSERT_EQUALS(output.rect.size.width, 20, "%d");
+	ASSERT_EQUALS(output.rect.size.height, 21, "%d");
+	ASSERT_EQUALS(output.before, 0xDEADBEAF, "%d");
+	ASSERT_EQUALS(output.after, 0xBEAFDEAD, "%d");
+
+END_UNITTEST
+
 static PyMethodDef unittest_methods[] = {
 	TESTDEF(CheckNSInvoke),
 

Modules/objc/test/structargs.m

 }
 -(NSString*)compP:(NSPoint)aPoint aRect:(NSRect)aRect anOp:(int)op;
 -(unsigned)stackPtr;
+-(NSRect)someRect;
+-(NSRect)someRectWithRect:(NSRect)rect;
+-(NSRect)someRectWithX:(int)x Y:(int)y H:(int)h W:(int)w;
+-(NSRect)someRectWithObject:(StructArgClass*)o X:(int)x Y:(int)y H:(int)h W:(int)w;
 @end
 
 @implementation StructArgClass
+-(NSRect)someRectWithRect:(NSRect)rect
+{
+	return rect;
+}
+
+-(NSRect)someRectWithX:(int)x Y:(int)y H:(int)h W:(int)w
+{
+	return NSMakeRect(x, y, h, w);
+}
+
+-(NSRect)someRectWithObject:(StructArgClass*)o X:(int)x Y:(int)y H:(int)h W:(int)w
+{
+	return [o someRectWithRect:NSMakeRect(x, y, h, w)];
+}
+
+-(NSRect)someRect
+{
+	NSRect retval = NSMakeRect(1,2,3,4);
+	return retval;
+}
+
+
 -(NSString*)compP:(NSPoint)aPoint aRect:(NSRect)aRect anOp:(int)op
 {
 	return [NSString stringWithFormat:@"aP:%@ aR:%@ %anO:%d",