Package org.rococoa.cocoa.foundation

Examples of org.rococoa.cocoa.foundation.NSObject$_class_


        int expectedFinalRetainCount = expectedAutorelease ?
          expectedInitialRetainCount - 1 : expectedInitialRetainCount;  
       
        NSAutoreleasePool pool = NSAutoreleasePool.new_();
       
        NSObject object = factory.create();       
        assertRetainCount(expectedInitialRetainCount, object);
       
        // aliasing should increase the retain count, as the alias also owns it
        NSObject alias = Rococoa.cast(object, NSObject.class);
        assertSame(object.id(), alias.id());
        assertRetainCount(expectedInitialRetainCount + 1, object);
        assertRetainCount(expectedInitialRetainCount + 1, alias);
       
        // wait until object has been GC'd
        WeakReference<Object> reference = new WeakReference<Object>(object);
View Full Code Here


    @Test public void convertsNSObjectAsArgumentToID() { 
  ToNativeConverter converter = new ObjCObjectTypeConverter(ObjCObject.class);
      // We treat all NSObject's equally in toNative, see RococoaTypeMapper
        assertEquals(primitiveTypeOfID, converter.nativeType());
       
  NSObject nsObject = Rococoa.create("NSObject", NSObject.class);

        Number nativeValue = (Number) converter.toNative(nsObject, null);
        assertEquals(primitiveTypeOfID, nativeValue.getClass());
        assertEquals(nsObject.id().longValue(), nativeValue.longValue());
    }
View Full Code Here

     @param type the subclass of <code>NSObject</code> that the value associated with <code>key</code> will be coerced to
     *  @return the value associated with the key coerced as into <code>type</code>
     *  @param <R> the type to return
     */
    public <R extends NSObject> R getValueAsType(E key, Class<R> type) {
        NSObject result = data.objectForKey(key.getNativeValue());
        return result == null ? null : Rococoa.cast(result, type);
    }   
View Full Code Here

        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

        public NSObject numberWithInt(int value);
    }

    @Test public void testDownCast() {
        // this is OK
        NSObject numberAsObject = NSNumber.CLASS.numberWithInt(42);
        assertEquals(42, ((NSNumber) numberAsObject).intValue());
       
        // but when defined return type is NSObject, we can't cast Java objects
        OddClass nsClass = Rococoa.createClass("NSNumber", OddClass.class);
        NSObject returnAsObject = nsClass.numberWithInt(42);
        try {
            ((NSNumber) returnAsObject).intValue();
            fail();
        } catch (ClassCastException expected) {}
       
View Full Code Here

    assertEquals(-2000, error.code().intValue());
    }

  @Test public void testAttributeForKey() throws Exception {
        QTMovie movie = loadMovie(testMovieFile);
        NSObject attribute = movie.attributeForKey(QTMovie.QTMovieTimeScaleAttribute);
       
        assertTrue(attribute.isKindOfClass(ObjCClass.CLASS.classWithName("NSNumber")));
        assertFalse(attribute.isKindOfClass(ObjCClass.CLASS.classWithName("NSString")));
       
        //need to cast 'rococoa style'
        assertEquals(testMovieTimeScale, Rococoa.cast(attribute, NSNumber.class).intValue());
    }
View Full Code Here

        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

        array.addObject(NSString.stringWithString("Hello"));
        array.addObject("Goodbye");
        assertEquals(2, array.count());
        assertEquals("(\n    Hello,\n    Goodbye\n)", array.description());
       
        NSObject first = array.objectAtIndex(0);
        assertEquals(NSString.stringWithString("Hello"), first);
       
        NSString firstAsString = Rococoa.cast(first, NSString.class);
        assertEquals("Hello", firstAsString.toString());
        assertEquals("Goodbye",
View Full Code Here

     @return the value asociated with the property
     *  @throws IllegalArgumentException if an error occurs while reading the property
     */
    public NSObject getProperty(SpeechProperty property) throws IllegalArgumentException {
         ObjCObjectByReference errorPtr = new ObjCObjectByReference();
         NSObject result = objectForProperty_error(property.getNativeValue(), errorPtr);
         NSError error = errorPtr.getValueAs(NSError.class);
         //objectForProperty:error isn't well documented, so be very conservative
         if ( result != null && !result.id().isNull() && (error == null || error.id().isNull() || error.code().intValue() == 0) ) {
             return result;
         } else {
             throw new IllegalArgumentException("Could not get property: " + property + ", error: " + error.localizedDescription());
         }
    }
View Full Code Here

TOP

Related Classes of org.rococoa.cocoa.foundation.NSObject$_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.