Ejemplo n.º 1
0
    def test_objcinstance_can_produce_objcprotocol(self):
        """Creating an ObjCInstance for a protocol pointer gives an ObjCProtocol."""

        example_protocol_ptr = libobjc.objc_getProtocol(b'ExampleProtocol')
        ExampleProtocol = ObjCInstance(example_protocol_ptr)
        self.assertEqual(ExampleProtocol, ObjCProtocol('ExampleProtocol'))
        self.assertIsInstance(ExampleProtocol, ObjCProtocol)
Ejemplo n.º 2
0
    def test_objcinstance_can_produce_objcmetaclass(self):
        """Creating an ObjCInstance for a metaclass pointer gives an ObjCMetaClass."""

        examplemeta_ptr = libobjc.objc_getMetaClass(b"Example")
        ExampleMeta = ObjCInstance(examplemeta_ptr)
        self.assertEqual(ExampleMeta, ObjCMetaClass("Example"))
        self.assertIsInstance(ExampleMeta, ObjCMetaClass)
Ejemplo n.º 3
0
    def test_objcinstance_can_produce_objcclass(self):
        """Creating an ObjCInstance for a class pointer gives an ObjCClass."""

        example_ptr = libobjc.objc_getClass(b"Example")
        Example = ObjCInstance(example_ptr)
        self.assertEqual(Example, ObjCClass("Example"))
        self.assertIsInstance(Example, ObjCClass)
Ejemplo n.º 4
0
    def test_class_ivars(self):
        """An Objective-C class can have instance variables."""

        class Ivars(NSObject):
            object = objc_ivar(objc_id)
            int = objc_ivar(c_int)
            rect = objc_ivar(NSRect)

        ivars = Ivars.alloc().init()

        set_ivar(ivars, 'object', at('foo').ptr)
        set_ivar(ivars, 'int', c_int(12345))
        set_ivar(ivars, 'rect', NSMakeRect(12, 34, 56, 78))

        s = ObjCInstance(get_ivar(ivars, 'object'))
        self.assertEqual(str(s), 'foo')

        i = get_ivar(ivars, 'int')
        self.assertEqual(i.value, 12345)

        r = get_ivar(ivars, 'rect')
        self.assertEqual(r.origin.x, 12)
        self.assertEqual(r.origin.y, 34)
        self.assertEqual(r.size.width, 56)
        self.assertEqual(r.size.height, 78)
Ejemplo n.º 5
0
    def test_no_convert_return(self):
        Example = ObjCClass("Example")
        example = Example.alloc().init()

        res = example.toString(convert_result=False)
        self.assertNotIsInstance(res, ObjCInstance)
        self.assertEqual(str(ObjCInstance(res)), "This is an ObjC Example object")
Ejemplo n.º 6
0
    def test_method_varargs_send(self):
        """A variadic method can be called using send_message."""

        NSString = ObjCClass('NSString')
        formatted = send_message(
            NSString,
            'stringWithFormat:',
            at('This is a %@ with %@'),
            varargs=[at('string'), at('placeholders')],
            restype=objc_id,
            argtypes=[objc_id],
        )
        self.assertEqual(str(ObjCInstance(formatted)), 'This is a string with placeholders')