Пример #1
0
    def test_objcclass_instancecheck(self):
        """isinstance works with an ObjCClass as the second argument."""

        NSArray = ObjCClass('NSArray')
        NSString = ObjCClass('NSString')

        self.assertIsInstance(NSObject.new(), NSObject)
        self.assertIsInstance(at(''), NSString)
        self.assertIsInstance(at(''), NSObject)
        self.assertIsInstance(NSObject, NSObject)
        self.assertIsInstance(NSObject, NSObject.objc_class)

        self.assertNotIsInstance(object(), NSObject)
        self.assertNotIsInstance(NSObject.new(), NSString)
        self.assertNotIsInstance(NSArray.array, NSString)
Пример #2
0
    def test_objcclass_instancecheck(self):
        """isinstance works with an ObjCClass as the second argument."""

        NSArray = ObjCClass('NSArray')
        NSString = ObjCClass('NSString')

        self.assertIsInstance(NSObject.new(), NSObject)
        self.assertIsInstance(at(''), NSString)
        self.assertIsInstance(at(''), NSObject)
        self.assertIsInstance(NSObject, NSObject)
        self.assertIsInstance(NSObject, NSObject.objc_class)

        self.assertNotIsInstance(object(), NSObject)
        self.assertNotIsInstance(NSObject.new(), NSString)
        self.assertNotIsInstance(NSArray.array, NSString)
Пример #3
0
    def test_objcprotocol_requires_protocol(self):
        """ObjCProtocol only accepts protocol pointers."""

        random_obj = NSObject.alloc().init()
        with self.assertRaises(ValueError):
            ObjCProtocol(random_obj.ptr)
        random_obj.release()
Пример #4
0
    def test_objcclass_requires_class(self):
        """ObjCClass only accepts class pointers."""

        random_obj = NSObject.alloc().init()
        with self.assertRaises(ValueError):
            ObjCClass(random_obj.ptr)
        random_obj.release()
Пример #5
0
    def test_objcprotocol_requires_protocol(self):
        """ObjCProtocol only accepts protocol pointers."""

        random_obj = NSObject.alloc().init()
        with self.assertRaises(ValueError):
            ObjCProtocol(random_obj.ptr)
        random_obj.release()
Пример #6
0
    def test_objcclass_requires_class(self):
        """ObjCClass only accepts class pointers."""

        random_obj = NSObject.alloc().init()
        with self.assertRaises(ValueError):
            ObjCClass(random_obj.ptr)
        random_obj.release()
Пример #7
0
    def test_objcmetaclass_requires_metaclass(self):
        """ObjCMetaClass only accepts metaclass pointers."""

        random_obj = NSObject.alloc().init()
        with self.assertRaises(ValueError):
            ObjCMetaClass(random_obj.ptr)

        with self.assertRaises(ValueError):
            ObjCMetaClass(NSObject.ptr)
Пример #8
0
    def test_objcprotocol_instancecheck(self):
        """isinstance works with an ObjCProtocol as the second argument."""

        NSCoding = ObjCProtocol('NSCoding')
        NSSecureCoding = ObjCProtocol('NSSecureCoding')

        self.assertIsInstance(at(''), NSSecureCoding)
        self.assertIsInstance(at(''), NSCoding)

        self.assertNotIsInstance(object(), NSSecureCoding)
        self.assertNotIsInstance(NSObject.new(), NSSecureCoding)
Пример #9
0
    def test_objcprotocol_instancecheck(self):
        """isinstance works with an ObjCProtocol as the second argument."""

        NSCoding = ObjCProtocol('NSCoding')
        NSSecureCoding = ObjCProtocol('NSSecureCoding')

        self.assertIsInstance(at(''), NSSecureCoding)
        self.assertIsInstance(at(''), NSCoding)

        self.assertNotIsInstance(object(), NSSecureCoding)
        self.assertNotIsInstance(NSObject.new(), NSSecureCoding)
Пример #10
0
    def test_objcinstance_release_owned(self):

        # Create an object which we own.
        obj = NSObject.alloc().init()

        # Check that it is marked for release.
        self.assertTrue(obj._needs_release)

        # Explicitly release the object.
        obj.release()

        # Check that we no longer need to release it.
        self.assertFalse(obj._needs_release)

        # Delete it and make sure that we don't segfault on garbage collection.
        del obj
        gc.collect()
Пример #11
0
    def test_objcclass_subclasscheck(self):
        """issubclass works with an ObjCClass as the second argument."""

        NSArray = ObjCClass('NSArray')
        NSString = ObjCClass('NSString')

        self.assertTrue(issubclass(NSObject, NSObject))
        self.assertTrue(issubclass(NSString, NSObject))
        self.assertTrue(issubclass(NSObject.objc_class, NSObject))
        self.assertTrue(issubclass(NSObject.objc_class, NSObject.objc_class))

        self.assertFalse(issubclass(NSObject, NSString))
        self.assertFalse(issubclass(NSArray, NSString))

        with self.assertRaises(TypeError):
            issubclass(object(), NSObject)
        with self.assertRaises(TypeError):
            issubclass(object, NSObject)
        with self.assertRaises(TypeError):
            issubclass(NSObject.new(), NSObject)
        with self.assertRaises(TypeError):
            issubclass(NSObjectProtocol, NSObject)
Пример #12
0
    def test_objcclass_subclasscheck(self):
        """issubclass works with an ObjCClass as the second argument."""

        NSArray = ObjCClass('NSArray')
        NSString = ObjCClass('NSString')

        self.assertTrue(issubclass(NSObject, NSObject))
        self.assertTrue(issubclass(NSString, NSObject))
        self.assertTrue(issubclass(NSObject.objc_class, NSObject))
        self.assertTrue(issubclass(NSObject.objc_class, NSObject.objc_class))

        self.assertFalse(issubclass(NSObject, NSString))
        self.assertFalse(issubclass(NSArray, NSString))

        with self.assertRaises(TypeError):
            issubclass(object(), NSObject)
        with self.assertRaises(TypeError):
            issubclass(object, NSObject)
        with self.assertRaises(TypeError):
            issubclass(NSObject.new(), NSObject)
        with self.assertRaises(TypeError):
            issubclass(NSObjectProtocol, NSObject)
Пример #13
0
    def test_objcprotocol_subclasscheck(self):
        """issubclass works with an ObjCProtocol as the second argument."""

        NSString = ObjCClass('NSString')
        NSCopying = ObjCProtocol('NSCopying')
        NSCoding = ObjCProtocol('NSCoding')
        NSSecureCoding = ObjCProtocol('NSSecureCoding')

        self.assertTrue(issubclass(NSObject, NSObjectProtocol))
        self.assertTrue(issubclass(NSString, NSObjectProtocol))
        self.assertTrue(issubclass(NSSecureCoding, NSSecureCoding))
        self.assertTrue(issubclass(NSSecureCoding, NSCoding))

        self.assertFalse(issubclass(NSObject, NSSecureCoding))
        self.assertFalse(issubclass(NSCoding, NSSecureCoding))
        self.assertFalse(issubclass(NSCopying, NSSecureCoding))

        with self.assertRaises(TypeError):
            issubclass(object(), NSSecureCoding)
        with self.assertRaises(TypeError):
            issubclass(object, NSSecureCoding)
        with self.assertRaises(TypeError):
            issubclass(NSObject.new(), NSSecureCoding)
Пример #14
0
    def test_objcprotocol_subclasscheck(self):
        """issubclass works with an ObjCProtocol as the second argument."""

        NSString = ObjCClass('NSString')
        NSCopying = ObjCProtocol('NSCopying')
        NSCoding = ObjCProtocol('NSCoding')
        NSSecureCoding = ObjCProtocol('NSSecureCoding')

        self.assertTrue(issubclass(NSObject, NSObjectProtocol))
        self.assertTrue(issubclass(NSString, NSObjectProtocol))
        self.assertTrue(issubclass(NSSecureCoding, NSSecureCoding))
        self.assertTrue(issubclass(NSSecureCoding, NSCoding))

        self.assertFalse(issubclass(NSObject, NSSecureCoding))
        self.assertFalse(issubclass(NSCoding, NSSecureCoding))
        self.assertFalse(issubclass(NSCopying, NSSecureCoding))

        with self.assertRaises(TypeError):
            issubclass(object(), NSSecureCoding)
        with self.assertRaises(TypeError):
            issubclass(object, NSSecureCoding)
        with self.assertRaises(TypeError):
            issubclass(NSObject.new(), NSSecureCoding)