Ejemplo n.º 1
0
    def testGetSet(self):
        o = NSObject.alloc().init()

        key1 = "key1"
        self.assertEqual(objc.getAssociatedObject(o, key1), None)
        objc.setAssociatedObject(o, key1, "foo")
        self.assertEqual(objc.getAssociatedObject(o, key1), "foo")
        objc.setAssociatedObject(o, key1, None)
        self.assertEqual(objc.getAssociatedObject(o, key1), None)
Ejemplo n.º 2
0
    def testGetSet(self):
        o = NSObject.alloc().init()

        key1 = "key1"
        self.assertEqual(objc.getAssociatedObject(o, key1), None)
        objc.setAssociatedObject(o, key1, "foo")
        self.assertEqual(objc.getAssociatedObject(o, key1), "foo")
        objc.setAssociatedObject(o, key1, None)
        self.assertEqual(objc.getAssociatedObject(o, key1), None)
Ejemplo n.º 3
0
    def testKeysAreIdentityBased(self):
        o = NSObject.alloc().init()

        key1 = "key1"
        key2 = "key11"[:-1]
        self.assertIsNot(key1, key2)

        self.assertEqual(objc.getAssociatedObject(o, key1), None)
        self.assertEqual(objc.getAssociatedObject(o, key2), None)

        objc.setAssociatedObject(o, key1, "foo")

        self.assertEqual(objc.getAssociatedObject(o, key1), "foo")
        self.assertEqual(objc.getAssociatedObject(o, key2), None)
Ejemplo n.º 4
0
    def testKeysAreIdentityBased(self):
        o = NSObject.alloc().init()

        key1 = "key1"
        key2 = "key11"[:-1]
        self.assertIsNot(key1, key2)

        self.assertEqual(objc.getAssociatedObject(o, key1), None)
        self.assertEqual(objc.getAssociatedObject(o, key2), None)

        objc.setAssociatedObject(o, key1, "foo")

        self.assertEqual(objc.getAssociatedObject(o, key1), "foo")
        self.assertEqual(objc.getAssociatedObject(o, key2), None)
Ejemplo n.º 5
0
    def testPolicy(self):
        o = NSObject.alloc().init()
        key1 = "key1"
        key2 = "key11"[:-1]
        self.assertIsNot(key1, key2)

        value = OC_AssocSneakyCopy.alloc().init()

        self.assertEqual(objc.getAssociatedObject(o, key1), None)
        self.assertEqual(objc.getAssociatedObject(o, key2), None)

        objc.setAssociatedObject(o, key1, value, objc.OBJC_ASSOCIATION_RETAIN)
        objc.setAssociatedObject(o, key2, value, objc.OBJC_ASSOCIATION_COPY)

        self.assertEqual(objc.getAssociatedObject(o, key1), value)
        self.assertEqual(objc.getAssociatedObject(o, key2), "<copy!>")
Ejemplo n.º 6
0
    def testPolicy(self):
        o = NSObject.alloc().init()
        key1 = "key1"
        key2 = "key11"[:-1]
        self.assertIsNot(key1, key2)

        value = OC_AssocSneakyCopy.alloc().init()

        self.assertEqual(objc.getAssociatedObject(o, key1), None)
        self.assertEqual(objc.getAssociatedObject(o, key2), None)

        objc.setAssociatedObject(o, key1, value, objc.OBJC_ASSOCIATION_RETAIN)
        objc.setAssociatedObject(o, key2, value, objc.OBJC_ASSOCIATION_COPY)

        self.assertEqual(objc.getAssociatedObject(o, key1), value)
        self.assertEqual(objc.getAssociatedObject(o, key2),  "<copy!>")
Ejemplo n.º 7
0
    def testClearing(self):

        o = NSObject.alloc().init()

        key1 = "key1"
        key2 = "key11"[:-1]
        self.assertIsNot(key1, key2)

        self.assertEqual(objc.getAssociatedObject(o, key1), None)
        self.assertEqual(objc.getAssociatedObject(o, key2), None)

        objc.setAssociatedObject(o, key1, "foo")
        objc.setAssociatedObject(o, key2, "bar")

        self.assertEqual(objc.getAssociatedObject(o, key1), "foo")
        self.assertEqual(objc.getAssociatedObject(o, key2), "bar")

        objc.removeAssociatedObjects(o)

        self.assertEqual(objc.getAssociatedObject(o, key1), None)
        self.assertEqual(objc.getAssociatedObject(o, key2), None)
Ejemplo n.º 8
0
    def testClearing(self):

        o = NSObject.alloc().init()

        key1 = "key1"
        key2 = "key11"[:-1]
        self.assertIsNot(key1, key2)

        self.assertEqual(objc.getAssociatedObject(o, key1), None)
        self.assertEqual(objc.getAssociatedObject(o, key2), None)

        objc.setAssociatedObject(o, key1, "foo")
        objc.setAssociatedObject(o, key2, "bar")

        self.assertEqual(objc.getAssociatedObject(o, key1), "foo")
        self.assertEqual(objc.getAssociatedObject(o, key2), "bar")

        objc.removeAssociatedObjects(o)

        self.assertEqual(objc.getAssociatedObject(o, key1), None)
        self.assertEqual(objc.getAssociatedObject(o, key2), None)