Examples of NSNotificationCenter


Examples of ns.foundation.NSNotificationCenter

      userInfo = notification.userInfo();
    }
  }
 
  public void testDefaultCenter() {
    NSNotificationCenter nc = NSNotificationCenter.defaultCenter();
    assertNotNull(nc);
  }
View Full Code Here

Examples of ns.foundation.NSNotificationCenter

    NSNotificationCenter nc = NSNotificationCenter.defaultCenter();
    assertNotNull(nc);
  }

  public void testAddObserver() {
    NSNotificationCenter nc = NSNotificationCenter.defaultCenter();
    TestObserver observer = new TestObserver();
    nc.addObserver(observer, new NSSelector<Void>("invoked", new Class[] { NSNotification.class }), "test", null);
    try {
      nc.addObserver(observer, new NSSelector<Void>("invoked", new Class[] { Object.class }), "test", null);
      fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    }
  }
View Full Code Here

Examples of ns.foundation.NSNotificationCenter

    } catch (IllegalArgumentException e) {
    }
  }

  public void testPostNotificationNSNotification() {
    NSNotificationCenter nc = NSNotificationCenter.defaultCenter();
    TestObserver observer = new TestObserver();
    nc.addObserver(observer, new NSSelector<Void>("invoked", new Class[] { NSNotification.class }), "test", null);
    NSNotification notification = new NSNotification("test", null);
    nc.postNotification(notification);
    assertTrue(observer.invoked);
  }
View Full Code Here

Examples of ns.foundation.NSNotificationCenter

    nc.postNotification(notification);
    assertTrue(observer.invoked);
  }

  public void testPostNotificationStringObject() {
    NSNotificationCenter nc = NSNotificationCenter.defaultCenter();
    TestObserver observer = new TestObserver();
    nc.addObserver(observer, new NSSelector<Void>("invoked", new Class[] { NSNotification.class }), "test", null);
    nc.postNotification("test", this);
    assertTrue(observer.invoked);
  }
View Full Code Here

Examples of ns.foundation.NSNotificationCenter

    nc.postNotification("test", this);
    assertTrue(observer.invoked);
  }

  public void testPostNotificationStringObjectNSDictionaryOfStringObject() {
    NSNotificationCenter nc = NSNotificationCenter.defaultCenter();
    TestObserver observer = new TestObserver();
    nc.addObserver(observer, new NSSelector<Void>("invoked", new Class[] { NSNotification.class }), "test", null);
    NSDictionary<String, Object> userInfo = new NSDictionary<String, Object>("value", "key");
    nc.postNotification("test", this, userInfo);
    assertTrue(observer.invoked);
    assertEquals(userInfo, observer.userInfo);
  }
View Full Code Here

Examples of ns.foundation.NSNotificationCenter

    assertTrue(observer.invoked);
    assertEquals(userInfo, observer.userInfo);
  }

  public void testRemoveObserverObject() {
    NSNotificationCenter nc = NSNotificationCenter.defaultCenter();
    TestObserver observer = new TestObserver();
    nc.addObserver(observer, new NSSelector<Void>("invoked", new Class[] { NSNotification.class }), "test", null);
    nc.removeObserver(observer);
    nc.postNotification("test", this);
    assertFalse(observer.invoked);
  }
View Full Code Here

Examples of ns.foundation.NSNotificationCenter

    nc.postNotification("test", this);
    assertFalse(observer.invoked);
  }

  public void testRemoveObserverObjectStringObject() {
    NSNotificationCenter nc = NSNotificationCenter.defaultCenter();
    TestObserver observer1 = new TestObserver();
    TestObserver observer2 = new TestObserver();
    nc.addObserver(observer1, new NSSelector<Void>("invoked", new Class[] { NSNotification.class }), "test", null);
    nc.addObserver(observer2, new NSSelector<Void>("invoked", new Class[] { NSNotification.class }), "test", null);
    nc.removeObserver(observer2, "test", null);
    nc.postNotification("test", this);
    assertTrue(observer1.invoked);
    assertFalse(observer2.invoked);
  }
View Full Code Here

Examples of org.rococoa.cocoa.foundation.NSNotificationCenter

        Foundation.sendReturnsVoid(proxy2.id(), "testTakesIDReturnsID:", ID.fromLong(43));
        assertEquals(ID.fromLong(43), implementor2.arg);       
    }   
   
    @Test public void testNotifications() {
        NSNotificationCenter notificationCentre = NSNotificationCenter.CLASS.defaultCenter();
        final ID observer = proxy.id();
        notificationCentre.addObserver_selector_name_object(
                observer,
                Foundation.selector("notify:"),
                "MyNotification",
                null);

        NSNotification notification = NSNotification.CLASS.notificationWithName_object("MyNotification", null);
       
        assertNull(implementor.arg);
        notificationCentre.postNotification(notification);            
        assertEquals(notification, implementor.arg);
        notificationCentre.removeObserver(observer);
    }
View Full Code Here

Examples of org.rococoa.cocoa.foundation.NSNotificationCenter

        notificationCentre.removeObserver(observer);
    }
   
    @Test public void testMemoryManagement() {
        // we were autorelease'ing the proxy - so that this failed
        NSNotificationCenter notificationCentre = NSNotificationCenter.CLASS.defaultCenter();
        final ID observer = proxy.id();
        notificationCentre.addObserver_selector_name_object(
                observer,
                Foundation.selector("notify:"),
                "MyNotification",
                null);
        pool.drain();
        pool = NSAutoreleasePool.new_();

        NSNotification notification = NSNotification.CLASS.notificationWithName_object("MyNotification", null);       
        notificationCentre.postNotification(notification);
        notificationCentre.removeObserver(observer);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.