Search in sources :

Example 1 with CFMutableArrayRef

use of net.pms.util.jna.macos.corefoundation.CoreFoundation.CFMutableArrayRef in project UniversalMediaServer by UniversalMediaServer.

the class CoreFoundationTest method testCFArray.

/**
 * Tests {@link CFArrayRef} and {@link CFMutableArrayRef}.
 *
 * @throws Throwable if an error occurs during the test.
 */
@Test
public void testCFArray() {
    CFTypeRef[] cfTypeRefs = { CFStringRef.toCFStringRef("First array element"), CFStringRef.toCFStringRef("Second array element"), CFStringRef.toCFStringRef("Third array element"), CFStringRef.toCFStringRef("Fourth array element"), CFStringRef.toCFStringRef("Fifth array element") };
    CFTypeArrayRef typeArrayRef = new CFTypeArrayRef(cfTypeRefs);
    CFArrayRef cfArrayRef = CF.CFArrayCreate(null, typeArrayRef, typeArrayRef.getSize(), CoreFoundation.kCFTypeArrayCallBacks);
    assertEquals(5, CF.CFArrayGetCount(cfArrayRef));
    CFMutableArrayRef cfMutableArrayRef = CF.CFArrayCreateMutableCopy(null, 10, cfArrayRef);
    assertEquals(5, CF.CFArrayGetCount(cfMutableArrayRef));
    CFNumberRef cfNumberRef = CFNumberRef.toCFNumberRef(50);
    CF.CFArrayAppendValue(cfMutableArrayRef, cfNumberRef);
    assertEquals(6, CF.CFArrayGetCount(cfMutableArrayRef));
    assertEquals("Fourth array element", new CFStringRef(CF.CFArrayGetValueAtIndex(cfMutableArrayRef, 3)).toString());
    assertEquals("50", new CFNumberRef(CF.CFArrayGetValueAtIndex(cfMutableArrayRef, 5)).toString());
    CF.CFArrayInsertValueAtIndex(cfMutableArrayRef, 0, cfNumberRef);
    assertEquals(7, CF.CFArrayGetCount(cfMutableArrayRef));
    assertEquals("50", new CFNumberRef(CF.CFArrayGetValueAtIndex(cfMutableArrayRef, 0)).toString());
    CF.CFArrayExchangeValuesAtIndices(cfMutableArrayRef, 0, 2);
    assertEquals("50", new CFNumberRef(CF.CFArrayGetValueAtIndex(cfMutableArrayRef, 2)).toString());
    CF.CFArrayRemoveAllValues(cfMutableArrayRef);
    assertEquals(0, CF.CFArrayGetCount(cfMutableArrayRef));
    CF.CFRelease(cfNumberRef);
    CF.CFRelease(cfMutableArrayRef);
    CF.CFRelease(cfArrayRef);
    for (CFTypeRef ref : cfTypeRefs) {
        CF.CFRelease(ref);
    }
}
Also used : CFArrayRef(net.pms.util.jna.macos.corefoundation.CoreFoundation.CFArrayRef) CFStringRef(net.pms.util.jna.macos.corefoundation.CoreFoundation.CFStringRef) CFMutableArrayRef(net.pms.util.jna.macos.corefoundation.CoreFoundation.CFMutableArrayRef) CFTypeRef(net.pms.util.jna.macos.corefoundation.CoreFoundation.CFTypeRef) CFNumberRef(net.pms.util.jna.macos.corefoundation.CoreFoundation.CFNumberRef) Test(org.junit.Test)

Aggregations

CFArrayRef (net.pms.util.jna.macos.corefoundation.CoreFoundation.CFArrayRef)1 CFMutableArrayRef (net.pms.util.jna.macos.corefoundation.CoreFoundation.CFMutableArrayRef)1 CFNumberRef (net.pms.util.jna.macos.corefoundation.CoreFoundation.CFNumberRef)1 CFStringRef (net.pms.util.jna.macos.corefoundation.CoreFoundation.CFStringRef)1 CFTypeRef (net.pms.util.jna.macos.corefoundation.CoreFoundation.CFTypeRef)1 Test (org.junit.Test)1