Search in sources :

Example 1 with IOObjectT

use of net.pms.util.jna.macos.types.IOObjectT 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)1 CFMutableDictionaryRefByReference (net.pms.util.jna.macos.corefoundation.CoreFoundation.CFMutableDictionaryRefByReference)1 CFStringRef (net.pms.util.jna.macos.corefoundation.CoreFoundation.CFStringRef)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 Test (org.junit.Test)1