Package org.rococoa.cocoa.foundation

Examples of org.rococoa.cocoa.foundation.NSNumber$_Class


   
    @Test public void convertsReturnedIDToNSObjectSubclass() {
        FromNativeConverter converter = new ObjCObjectTypeConverter(NSNumber.class);
            // returning is based on declared type, see RococoaTypeMapper

  NSNumber number = Rococoa.create("NSNumber", NSNumber.class, "numberWithInt:", 45);

        // We can cope with 64 bits on 64 and 32
        Number nativeValue = new Long(number.id().longValue());
        NSNumber converted = (NSNumber) converter.fromNative(nativeValue, null);
        assertEquals(converted.id(), number.id());
        assertEquals(45, converted.intValue());       

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


    }
   
    @Test public void returnedNSObjectIsNormallyRetained() {
        FromNativeConverter converter = new ObjCObjectTypeConverter(NSNumber.class);

  NSNumber number = Rococoa.create("NSNumber", NSNumber.class, "numberWithInt:", 45);
  assertRetainCount(2, number); // one for the pool, one for Java

        NSNumber converted = (NSNumber) converter.fromNative(new Long(number.id().longValue()), null);
  assertRetainCount(3, converted); // now we have another Java alias
  assertRetainCount(3, number);
    }
View Full Code Here

        NSString value = Rococoa.cast(
                dictionary.objectForKey(NSString.stringWithString("string key")),
                NSString.class);
        assertEquals("string value", value.toString());
   
        NSNumber value2 = Rococoa.cast(
                dictionary.objectForKey("int key"),
                NSNumber.class);
        assertEquals(42, value2.intValue());
    }
View Full Code Here

        NSArray array = NSArray.CLASS.arrayWithObjects(
                NSNumber.CLASS.numberWithInt(42),
                NSNumber.CLASS.numberWithInt(64)
        );
        assertEquals(2, array.count());
        NSNumber second = Rococoa.cast(array.objectAtIndex(1), NSNumber.class);
        assertEquals(64, second.intValue());
    }
View Full Code Here

import org.rococoa.test.RococoaTestCase;

@SuppressWarnings("nls")
public class NSClassTest extends RococoaTestCase {
    @Test public void test() {
        NSNumber fortyTwo = NSNumber.CLASS.numberWithInt(42);
        ID idOfNSNumber = Foundation.getClass("NSNumber");
        ID idOfNSString = Foundation.getClass("NSString");
        assertTrue(fortyTwo.isKindOfClass(idOfNSNumber));
        assertFalse(fortyTwo.isKindOfClass(idOfNSString));
       
        assertTrue(fortyTwo.isKindOfClass(ObjCClass.CLASS.classWithName("NSNumber")));
        assertFalse(fortyTwo.isKindOfClass(ObjCClass.CLASS.classWithName("NSString")));
    }
View Full Code Here

@SuppressWarnings("nls")
public class RococoaTest extends RococoaTestCase {
       
    @Test public void testCreate() {
        NSNumber fortyTwo = NSNumber.CLASS.numberWithInt(42);
        assertEquals(42, fortyTwo.intValue());       
    }
View Full Code Here

        NSNumber fortyTwo = NSNumber.CLASS.numberWithInt(42);
        assertEquals(42, fortyTwo.intValue());       
    }
   
    @Test public void testEqualsWithAliases() {
        NSNumber fortyTwo = NSNumber.CLASS.numberWithInt(42);
        NSNumber fortyTwoAlias = Rococoa.wrap(fortyTwo.id(), NSNumber.class);
        NSNumber fortyThree = NSNumber.CLASS.numberWithInt(43);
        assertTrue(fortyTwo.equals(fortyTwoAlias));
        assertTrue(fortyTwoAlias.equals(fortyTwo));
        assertFalse(fortyTwo.equals(fortyThree));
        assertFalse(fortyTwo.equals(null));
    }
View Full Code Here

        assertFalse(s1.id().equals(s2.id()));
        assertEquals(s1, s2);
    }
  
    @Test public void testReturnTypes() {
        NSNumber e = NSNumber.CLASS.numberWithDouble(Math.E);
        assertEquals(2, e.intValue());
        assertEquals(2, e.longValue());
        assertEquals((float) Math.E, e.floatValue(), 0.001);
        assertEquals(Math.E, e.doubleValue(), 0.001);
    }
View Full Code Here

        assertEquals((float) Math.E, e.floatValue(), 0.001);
        assertEquals(Math.E, e.doubleValue(), 0.001);
    }
   
    @Test public void testPassOCObject() {
        NSNumber fortyTwo = NSNumber.CLASS.numberWithInt(42);   
        NSNumber e = NSNumber.CLASS.numberWithDouble(Math.E);
       
        assertEquals(-1, e.compare(fortyTwo));
        assertEquals(0, e.compare(e));
        assertEquals(1, fortyTwo.compare(e));
    }
View Full Code Here

        // we need to do this
        assertEquals(42, Rococoa.cast(returnAsObject, NSNumber.class).intValue());
    }
   
    @Test public void testToString() {
        NSNumber fortyTwo = NSNumber.CLASS.numberWithInt(42);
        assertEquals("42", fortyTwo.toString());       
    }
View Full Code Here

TOP

Related Classes of org.rococoa.cocoa.foundation.NSNumber$_Class

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.