[PATCH 3/4] kernel32/tests: Add tests for GetSystemPowerStatus

Alex Henrie alexhenrie24 at gmail.com
Sun Sep 22 16:12:11 CDT 2019


Signed-off-by: Alex Henrie <alexhenrie24 at gmail.com>
---
 dlls/kernel32/tests/Makefile.in |  1 +
 dlls/kernel32/tests/power.c     | 65 +++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+)
 create mode 100644 dlls/kernel32/tests/power.c

diff --git a/dlls/kernel32/tests/Makefile.in b/dlls/kernel32/tests/Makefile.in
index e06141d9f6..e9516603ce 100644
--- a/dlls/kernel32/tests/Makefile.in
+++ b/dlls/kernel32/tests/Makefile.in
@@ -25,6 +25,7 @@ SOURCES = \
 	module.c \
 	path.c \
 	pipe.c \
+	power.c \
 	process.c \
 	profile.c \
 	resource.c \
diff --git a/dlls/kernel32/tests/power.c b/dlls/kernel32/tests/power.c
new file mode 100644
index 0000000000..5dc5ef7657
--- /dev/null
+++ b/dlls/kernel32/tests/power.c
@@ -0,0 +1,65 @@
+/*
+ * Unit tests for power management functions
+ *
+ * Copyright (c) 2019 Alex Henrie
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "wine/test.h"
+
+void test_GetSystemPowerStatus(void)
+{
+    SYSTEM_POWER_STATUS ps;
+    BOOL ret;
+    BYTE capacity_flags, expected_capacity_flags;
+
+    if (0) /* crashes */
+        GetSystemPowerStatus(NULL);
+
+    ret = GetSystemPowerStatus(&ps);
+    ok(ret == TRUE, "expected TRUE\n");
+
+    ok(ps.ACLineStatus <= AC_LINE_BACKUP_POWER || ps.ACLineStatus == AC_LINE_UNKNOWN,
+       "got unexpected ACLineStatus 0x%02x\n", ps.ACLineStatus);
+
+    if (ps.BatteryFlag != BATTERY_FLAG_NO_BATTERY && ps.BatteryFlag != BATTERY_FLAG_UNKNOWN &&
+        ps.BatteryLifePercent != BATTERY_PERCENTAGE_UNKNOWN)
+    {
+        expected_capacity_flags = 0;
+        if (ps.BatteryLifePercent > 66)
+            expected_capacity_flags |= BATTERY_FLAG_HIGH;
+        if (ps.BatteryLifePercent < 33)
+            expected_capacity_flags |= BATTERY_FLAG_LOW;
+        if (ps.BatteryLifePercent < 5)
+            expected_capacity_flags |= BATTERY_FLAG_CRITICAL;
+        capacity_flags = (ps.BatteryFlag & ~BATTERY_FLAG_CHARGING);
+        ok(capacity_flags == expected_capacity_flags,
+           "expected %d%%-charged battery to have capacity flags 0x%02x, got 0x%02x",
+           ps.BatteryLifePercent, expected_capacity_flags, capacity_flags);
+    }
+    else
+    {
+        skip("no battery charge information\n");
+    }
+
+    ok(ps.SystemStatusFlag <= SYSTEM_STATUS_FLAG_POWER_SAVING_ON,
+       "got unexpected SystemStatusFlag 0x%02x\n", ps.SystemStatusFlag);
+}
+
+START_TEST(power)
+{
+    test_GetSystemPowerStatus();
+}
-- 
2.23.0




More information about the wine-devel mailing list