CopyPropertiesTester.c [plain text]
#include <CoreFoundation/CoreFoundation.h>
#include <SystemConfiguration/SCValidation.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/pwr_mgt/IOPMLibPrivate.h>
#include <IOKit/pwr_mgt/IOPMLib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include "PMTestLib.h"
int main()
{
IOReturn ret = 0;
IOPMAssertionID _id[10];
ret = PMTestInitialize("CopyPropertiesExerciser", "com.apple.iokit.powertesting");
if(kIOReturnSuccess != ret)
{
fprintf(stderr,"PMTestInitialize failed with IOReturn error code 0x%08x\n", ret);
exit(-1);
}
int i;
for (i=0; i<10; i++)
{
ret = IOPMAssertionCreate(kIOPMAssertionTypePreventUserIdleSystemSleep, kIOPMAssertionLevelOn, &_id[i]);
if (kIOReturnSuccess != ret) {
PMTestFail("IOPMAssertionCreateWithProperties returns non-success 0x%08x\n", ret);
exit(1);
}
}
CFDictionaryRef properties = NULL;
for (i=0; i<10; i++)
{
properties = IOPMAssertionCopyProperties(_id[i]);
if (!properties) {
PMTestFail("IOPMAssertionCopyProperties for id %ld return NULL\n", _id[i]);
exit(1);
}
if (!CFDictionaryContainsKey(properties, kIOPMAssertionNameKey)
|| !CFDictionaryContainsKey(properties, kIOPMAssertionTypeKey)
|| !CFDictionaryContainsKey(properties, kIOPMAssertionLevelKey))
{
CFShow(properties);
PMTestFail("IOPMAssertionCopyProperties doesn't contain required dictionary keys\n", _id[i]);
}
CFRelease(properties);
}
for (i=0; i<10; i++)
{
ret = IOPMAssertionRelease(_id[i]);
if (kIOReturnSuccess != ret) {
PMTestFail("IOPMAssertionRelease returns non-success 0x%08x\n", ret);
exit(1);
}
}
PMTestPass("Created a handful of assertions. Every one of them had properties.\n");
return 0;
}