FreeRDP
Loading...
Searching...
No Matches
TestGetSystemPowerStatus.c
1
2#include <winpr/crt.h>
3#include <winpr/error.h>
4#include <winpr/sysinfo.h>
5
6int TestGetSystemPowerStatus(int argc, char* argv[])
7{
8 SYSTEM_POWER_STATUS status = WINPR_C_ARRAY_INIT;
9
10 WINPR_UNUSED(argc);
11 WINPR_UNUSED(argv);
12
13 /* Battery/AC state is host-dependent (and entirely absent on CI runners), so this only
14 * checks that the call succeeds and fills in something - not what it reports. */
15 if (!GetSystemPowerStatus(&status))
16 {
17 printf("GetSystemPowerStatus failed, error=%" PRIu32 "\n", GetLastError());
18 return -1;
19 }
20
21 printf("SystemPowerStatus:\n");
22 printf("\tACLineStatus: %" PRIu8 "\n", status.ACLineStatus);
23 printf("\tBatteryFlag: 0x%02" PRIX8 "\n", status.BatteryFlag);
24 printf("\tBatteryLifePercent: %" PRIu8 "\n", status.BatteryLifePercent);
25 printf("\tBatteryLifeTime: %" PRIu32 "\n", status.BatteryLifeTime);
26 printf("\tBatteryFullLifeTime: %" PRIu32 "\n", status.BatteryFullLifeTime);
27 printf("\n");
28
29 if ((status.BatteryLifePercent != BATTERY_PERCENTAGE_UNKNOWN) &&
30 (status.BatteryLifePercent > 100))
31 {
32 printf("BatteryLifePercent out of range: %" PRIu8 "\n", status.BatteryLifePercent);
33 return -1;
34 }
35
36 return 0;
37}
mirrors the real Win32 SYSTEM_POWER_STATUS struct.
Definition sysinfo.h:368