use of net.pms.util.jna.macos.corefoundation.CoreFoundation.CFDictionaryRef in project UniversalMediaServer by UniversalMediaServer.
the class CoreFoundationTest method testCFDictionary.
/**
* Tests {@link CFDictionaryRef} and {@link CFMutableDictionaryRef}.
*
* @throws Throwable if an error occurs during the test.
*/
@Test
public void testCFDictionary() throws Throwable {
CFStringRef cfStringRef = CFStringRef.toCFStringRef("Test");
CFNumberRef cfNumberRef = CFNumberRef.toCFNumberRef(4.3);
CFMutableDictionaryRef mutableDictionaryRef = IOKit.INSTANCE.IOServiceMatching("IOHIDSystem");
assertTrue(CF.CFDictionaryGetCount(mutableDictionaryRef) > 0);
long l = CF.CFDictionaryGetCount(mutableDictionaryRef);
CF.CFDictionaryAddValue(mutableDictionaryRef, cfNumberRef, cfStringRef);
assertEquals(l + 1, CF.CFDictionaryGetCount(mutableDictionaryRef));
assertTrue(CF.CFDictionaryContainsKey(mutableDictionaryRef, cfNumberRef));
assertTrue(CF.CFDictionaryContainsValue(mutableDictionaryRef, cfStringRef));
CFDictionaryRef dictionaryRef = CF.CFDictionaryCreateCopy(CoreFoundation.ALLOCATOR, mutableDictionaryRef);
CFTypeArrayRef keys = new CFTypeArrayRef(CF.CFDictionaryGetCount(dictionaryRef));
CFTypeArrayRef values = new CFTypeArrayRef(CF.CFDictionaryGetCount(dictionaryRef));
CF.CFDictionaryGetKeysAndValues(dictionaryRef, keys, values);
assertTrue(Arrays.asList(keys.getArray()).contains(cfNumberRef));
assertTrue(Arrays.asList(values.getArray()).contains(cfStringRef));
CF.CFDictionaryRemoveValue(mutableDictionaryRef, cfNumberRef);
assertEquals(l, CF.CFDictionaryGetCount(mutableDictionaryRef));
PointerByReference pointerRef = new PointerByReference();
assertTrue(CF.CFDictionaryGetValueIfPresent(dictionaryRef, cfNumberRef, pointerRef));
CFStringRef cfStringRef2 = new CFStringRef(pointerRef.getValue());
assertTrue(cfStringRef.compareTo(cfStringRef2) == CFComparisonResult.kCFCompareEqualTo);
assertEquals(cfStringRef.toString(), cfStringRef2.toString());
assertEquals(cfStringRef, cfStringRef2);
// Don't release cfStringRef2 as it's actually the same CFStringRef instance as cfStringRef
CF.CFRelease(dictionaryRef);
CF.CFRelease(mutableDictionaryRef);
CF.CFRelease(cfNumberRef);
CF.CFRelease(cfStringRef);
}
use of net.pms.util.jna.macos.corefoundation.CoreFoundation.CFDictionaryRef in project UniversalMediaServer by UniversalMediaServer.
the class IOKitTest method testIOKit.
/**
* Tests some {@link IOKit} mappings.
*
* @throws Throwable if an error occurs during the test.
*/
@Test
public void testIOKit() throws Throwable {
CFDictionaryRef dictionaryRef = IO.IOServiceMatching("IOHIDSystem");
IOIteratorTRef iteratorRef = new IOIteratorTRef(true);
assertEquals(DefaultKernReturnT.SUCCESS, IO.IOServiceGetMatchingServices(IOKit.kIOMasterPortDefault, dictionaryRef, iteratorRef));
IOIteratorT iterator = iteratorRef.getValue();
IONameT name = new IONameT(true);
assertEquals(DefaultKernReturnT.SUCCESS, IO.IOObjectGetClass(iterator, name));
assertEquals("IOUserIterator", name.getString(StandardCharsets.UTF_8));
IOObjectT object = IO.IOIteratorNext(iterator);
assertEquals(DefaultKernReturnT.SUCCESS, IO.IOObjectGetClass(object, name));
assertEquals("IOHIDSystem", name.getString(StandardCharsets.UTF_8));
IORegistryEntryT registryEntry = IORegistryEntryT.toIORegistryT(object);
CFMutableDictionaryRefByReference dictionaryRefRef = new CFMutableDictionaryRefByReference();
assertEquals(DefaultKernReturnT.SUCCESS, IO.IORegistryEntryCreateCFProperties(registryEntry, dictionaryRefRef, CoreFoundation.ALLOCATOR, 0));
CFStringRef key = CFStringRef.toCFStringRef("IOClass");
assertTrue(CF.CFDictionaryContainsKey(dictionaryRefRef.getCFMutableDictionaryRef(), key));
CFStringRef value = new CFStringRef(CF.CFDictionaryGetValue(dictionaryRefRef.getCFMutableDictionaryRef(), key));
assertEquals("IOHIDSystem", value.toString());
CF.CFRelease(key);
key = CFStringRef.toCFStringRef("IOProviderClass");
value = new CFStringRef(CF.CFDictionaryGetValue(dictionaryRefRef.getCFMutableDictionaryRef(), key));
assertEquals("IOResources", value.toString());
CF.CFRelease(key);
IO.IOObjectRelease(object);
object = IO.IOIteratorNext(iterator);
assertEquals(0, object.intValue());
assertTrue(IO.IOIteratorIsValid(iterator));
IO.IOObjectRelease(iterator);
CF.CFRelease(dictionaryRefRef.getCFMutableDictionaryRef());
}
Aggregations