override_default_pm_settings.c [plain text]
#include "PMtestLib.h"
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/pwr_mgt/IOPMLibPrivate.h>
#include <stdio.h>
#define overrideSetting kIOPMPrioritizeNetworkReachabilityOverSleepKey
int main(int argc, char *argv[])
{
int j = 1;
CFMutableDictionaryRef ov = NULL;
CFNumberRef overrideValue = NULL;
PMTestInitialize("Testing IOPMOverrideDefaultPMPreferences API", "com.appl.powermanagement.test");
PMTestLog("These tests must be run as root to exercise IOKit API, though they may PASS if not run as root.\n");
PMTestLog("Test #1 override setting with per-power source values.\n");
PMTestLog(" Overriding \"%s\" with value %d\n", overrideSetting, j);
ov = CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
overrideValue = CFNumberCreate(0, kCFNumberIntType, &j);
CFMutableDictionaryRef a, b, c;
a = CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
b = CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
c = CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(a, CFSTR(overrideSetting), overrideValue);
CFDictionarySetValue(b, CFSTR(overrideSetting), overrideValue);
CFDictionarySetValue(c, CFSTR(overrideSetting), overrideValue);
CFDictionarySetValue(ov, CFSTR(kIOPMACPowerKey), a);
CFDictionarySetValue(ov, CFSTR(kIOPMBatteryPowerKey), b);
CFDictionarySetValue(ov, CFSTR(kIOPMUPSPowerKey), c);
CFRelease(a);
CFRelease(b);
CFRelease(c);
IOPMOverrideDefaultPMPreferences(ov);
CFRelease(ov);
PMTestPass("Called IOPMOverrideDefaultPMPreferences - but this test does not check the output.");
PMTestLog("Test #2 override the setting globally (i.e. no different values across power sources).\n");
PMTestLog(" Overriding \"%s\" with value %d\n", overrideSetting, j);
CFMutableDictionaryRef ov2 = NULL;
ov2 = CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(ov, CFSTR(overrideSetting), overrideValue);
IOPMOverrideDefaultPMPreferences(ov2);
CFRelease(ov2);
PMTestPass("Called IOPMOverrideDefaultPMPreferences - but this test does not check the output.");
return 0;
};