Search in sources :

Example 1 with CFDictionaryRef

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);
}
Also used : CFDictionaryRef(net.pms.util.jna.macos.corefoundation.CoreFoundation.CFDictionaryRef) CFMutableDictionaryRef(net.pms.util.jna.macos.corefoundation.CoreFoundation.CFMutableDictionaryRef) CFStringRef(net.pms.util.jna.macos.corefoundation.CoreFoundation.CFStringRef) PointerByReference(com.sun.jna.ptr.PointerByReference) CFNumberRef(net.pms.util.jna.macos.corefoundation.CoreFoundation.CFNumberRef) Test(org.junit.Test)

Example 2 with CFDictionaryRef

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());
}
Also used : CFDictionaryRef(net.pms.util.jna.macos.corefoundation.CoreFoundation.CFDictionaryRef) IOObjectT(net.pms.util.jna.macos.types.IOObjectT) IOIteratorTRef(net.pms.util.jna.macos.types.IOIteratorTRef) CFStringRef(net.pms.util.jna.macos.corefoundation.CoreFoundation.CFStringRef) IOIteratorT(net.pms.util.jna.macos.types.IOIteratorT) IORegistryEntryT(net.pms.util.jna.macos.types.IORegistryEntryT) CFMutableDictionaryRefByReference(net.pms.util.jna.macos.corefoundation.CoreFoundation.CFMutableDictionaryRefByReference) IONameT(net.pms.util.jna.macos.types.IONameT) Test(org.junit.Test)

Aggregations

CFDictionaryRef (net.pms.util.jna.macos.corefoundation.CoreFoundation.CFDictionaryRef)2 CFStringRef (net.pms.util.jna.macos.corefoundation.CoreFoundation.CFStringRef)2 Test (org.junit.Test)2 PointerByReference (com.sun.jna.ptr.PointerByReference)1 CFMutableDictionaryRef (net.pms.util.jna.macos.corefoundation.CoreFoundation.CFMutableDictionaryRef)1 CFMutableDictionaryRefByReference (net.pms.util.jna.macos.corefoundation.CoreFoundation.CFMutableDictionaryRefByReference)1 CFNumberRef (net.pms.util.jna.macos.corefoundation.CoreFoundation.CFNumberRef)1 IOIteratorT (net.pms.util.jna.macos.types.IOIteratorT)1 IOIteratorTRef (net.pms.util.jna.macos.types.IOIteratorTRef)1 IONameT (net.pms.util.jna.macos.types.IONameT)1 IOObjectT (net.pms.util.jna.macos.types.IOObjectT)1 IORegistryEntryT (net.pms.util.jna.macos.types.IORegistryEntryT)1