コード例 #1
0
    def testAddObserverAnySenderAndPostithObject(self):
        nc = NotificationCenter()
        nc.addObserver(observer=self,
                       method=self.handle,
                       notificationName=TestNotificationName.test)
        nc.postNotification(notificationName=TestNotificationName.test,
                            notifyingObject=self)
        self.assertTrue(self.notificationReceived)

        nc.removeObserver(self)
コード例 #2
0
 def testAddObserverWrongNotification(self):
     nc = NotificationCenter()
     nc.addObserver(observer=self,
                    method=self.handle,
                    notificationName=TestNotificationName.wrong)
     nc.postNotification(notificationName=TestNotificationName.test,
                         notifyingObject=self,
                         userInfo="1234")
     self.assertFalse(self.notificationReceived)
     self.assertNotEqual(self.postedUserInfo, "1234")
     nc.removeObserver(self)
コード例 #3
0
 def testAddObserverAnySenderAndPostWithUserInfo(self):
     nc = NotificationCenter()
     nc.addObserver(observer=self,
                    method=self.handle,
                    notificationName=TestNotificationName.test)
     nc.postNotification(notificationName=TestNotificationName.test,
                         notifyingObject=self,
                         userInfo="1234")
     self.assertTrue(self.notificationReceived)
     self.assertEqual(self.postedUserInfo, "1234")
     nc.removeObserver(self)
コード例 #4
0
 def testAddObserverWrongSender(self):
     someObject = NotificationCenter()
     nc = NotificationCenter()
     nc.addObserver(self,
                    method=self.handle,
                    notificationName=TestNotificationName.test,
                    observedObject=someObject)
     nc.postNotification(notificationName=TestNotificationName.test,
                         notifyingObject=self,
                         userInfo="1234")
     self.assertFalse(self.notificationReceived)
     self.assertNotEqual(self.postedUserInfo, "1234")
     nc.removeObserver(self)
     self.assertEqual(nc.observersCount(), 0)
コード例 #5
0
 def testSingletonCanPost(self):
     nc = NotificationCenter()
     nc.postNotification(TestNotificationName.test, self)