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);
}
}
Aggregations