Package org.rococoa

Examples of org.rococoa.ID


   
    @Test public void returnedNSObjectIsNotRetainedIfMethodImpliesWeOwnIt() {
  // This is difficult to unit test, as we cannot create FunctionResultContext's.
  // Instead we step back look at the results through Foundation.send, which
  // routes through the converter.
  ID idClass = Foundation.getClass("NSObject");
  assertRetainCount(1, Foundation.send(idClass, "alloc", NSObject.class)); // not in the pool, so just one for Java
    }
View Full Code Here


        // but JNA seems to interpret it properly
        assertEquals(null, converter.toNative(null, null));
    }
   
    @Test public void convertsReturnedIDToString() {
        ID helloID = Foundation.cfString("Hello"); // just leaks
       
        // We can cope with 64 bits on 64 and 32
        Number nativeValue = new Long(helloID.longValue());
        String converted = converter.fromNative(nativeValue, null);
        assertEquals("Hello", converted);

        // We must cope with 32 bits on 32-bit
        if (NativeLong.SIZE == 4) {
            nativeValue = new Integer(helloID.intValue());
            converted = converter.fromNative(nativeValue, null);
            assertEquals("Hello", converted);       
        }   
    }
View Full Code Here

    @Test
    public void testNilReturnValues() {
        NSDictionary dict = NSDictionary.dictionaryWithObjectsAndKeys(
                NSString.stringWithString("Value"), NSString.stringWithString("Key")
        );
        ID id = dict.objectForKey((ID) null);
        assertNull(id);
        NSObject nsObject = dict.objectForKey((NSObject) null);
        assertNull(nsObject);
    }
View Full Code Here

    @Test
    public void testReturnValues() {
        NSDictionary dict = NSDictionary.dictionaryWithObjectsAndKeys(
                NSString.stringWithString("Value"), NSString.stringWithString("Key")
        );
        ID id = dict.objectForKey(NSString.stringWithString("Key").id());
        assertNotNull(id);
        NSObject nsObject = dict.objectForKey(NSString.stringWithString("Key"));
        assertNotNull(nsObject);
    }
View Full Code Here

            public void callback(ObjCObjectByReference reference) {
                // Success
                count.countDown();
            }
        });
        final ID delegate = callback.id();
        shunt.testCallbackWithReference(delegate);
        assertEquals("Callback to delegate failed", 0, count.getCount());
        pool.drain();
    }
View Full Code Here

    public T fromNative(Object nativeValue, FromNativeContext context) {
        Number nativeValueAsNumber = (Number) nativeValue;
        if (nativeValueAsNumber == null) {
            return null;
        }
        ID id = ID.fromLong(nativeValueAsNumber.longValue());
        if (id.isNull()) {
            return null;
        }
        boolean shouldRetain = shouldRetainFor(context);       
        return Rococoa.wrap(id, javaType, shouldRetain);
    }
View Full Code Here

    public Object toNative(Object value, ToNativeContext context) {
        if (value == null) {
            return null;
        }
        ObjCObject valueAsNSObject = (ObjCObject) value;
        ID idToReturn = valueAsNSObject.id();
        return idToReturn.toNative();
    }
View Full Code Here

    private Throwable thrown;
   
    @Test public void drains() {
        AutoreleaseBatcher batcher = new AutoreleaseBatcher(1);
        ID idNSObject = Foundation.cfRetain(autoreleasedObject());
        assertRetainCount(2, idNSObject);
       
        batcher.operate();
        assertRetainCount(1, idNSObject);
    }
View Full Code Here

        assertRetainCount(1, idNSObject);
    }
   
    @Test public void batches() {
        AutoreleaseBatcher batcher = new AutoreleaseBatcher(2);
        ID idNSObject = Foundation.cfRetain(autoreleasedObject());
        assertRetainCount(2, idNSObject);

        batcher.operate();
        assertRetainCount(2, idNSObject);       
View Full Code Here

    }
   
    @Test public void resets() {
        AutoreleaseBatcher batcher = new AutoreleaseBatcher(1);
       
        ID idNSObject1 = Foundation.cfRetain(autoreleasedObject());
        assertRetainCount(2, idNSObject1);
        batcher.operate();
        assertRetainCount(1, idNSObject1);       

        ID idNSObject2 = Foundation.cfRetain(autoreleasedObject());
        assertRetainCount(2, idNSObject2);
        batcher.operate();
        assertRetainCount(1, idNSObject2);       
    }
View Full Code Here

TOP

Related Classes of org.rococoa.ID

Copyright © 2018 www.massapicom. 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.