Commits

Bob Ippolito committed 519bc73

test for bug #836247

  • Participants
  • Parent commits 6a9eeeb

Comments (0)

Files changed (3)

pyobjc/Lib/objc/test/test_classandinst.py

+import unittest
+import objc
+from testclassandinst import PyObjC_TestClassAndInstance
+
+class TestClassAndInstance(unittest.TestCase):
+    def testClassAndInstance(self):
+        self.assertEquals(PyObjC_TestClassAndInstance.isInstance(), objc.NO)
+        self.assertEquals(PyObjC_TestClassAndInstance.alloc().init().isInstance(), objc.YES)
+
+if __name__ == '__main__':
+    unittest.main()

pyobjc/Lib/objc/test/testclassandinst.m

+/*
+ * XXX: PyObjC_TestClassAndInstance is a class that can't be created
+ *      from Python but ends up in some fun places like NSWindow
+ */
+
+#include <Python.h>
+#include <pyobjc-api.h>
+
+#import <Foundation/Foundation.h>
+
+#ifndef GNU_RUNTIME
+#include <objc/objc-runtime.h>
+#endif
+
+@interface PyObjC_TestClassAndInstance: NSObject
+{
+}
+
++ (BOOL)isInstance;
+- (BOOL)isInstance;
+@end
+
+@implementation PyObjC_TestClassAndInstance
++(BOOL)isInstance
+{
+	return NO;
+}
+-(BOOL)isInstance
+{
+	return YES;
+}
+@end
+
+/* Python glue */
+void inittestclassandinst(void);
+static PyMethodDef no_methods[] = {
+	{ 0, 0, 0, 0 }
+};
+
+void inittestclassandinst(void)
+{
+	PyObject* m;
+
+	m = Py_InitModule4("testclassandinst", no_methods, 
+		NULL, NULL, PYTHON_API_VERSION);
+	if (!m) return;
+
+	if (PyObjC_ImportAPI(m) < 0) return;
+
+	PyModule_AddObject(m, "PyObjC_TestClassAndInstance", 
+		PyObjCClass_New([PyObjC_TestClassAndInstance class]));
+}
               ["Lib/objc/test/testbndl2.m"],
               extra_compile_args=["-IModules/objc" ] + CFLAGS,
               extra_link_args=OBJC_LDFLAGS),
+    Extension("objc.test.testclassandinst",
+              ["Lib/objc/test/testclassandinst.m"],
+              extra_compile_args=["-IModules/objc" ] + CFLAGS,
+              extra_link_args=OBJC_LDFLAGS),
     ]
 
 if gs_root is None: