From: Robert Lippmann robert.lippmann.development@gmail.com
--- configure | 1 + configure.ac | 1 + dlls/powrprof/tests/Makefile.in | 5 ++ dlls/powrprof/tests/powersetting.c | 107 +++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 dlls/powrprof/tests/Makefile.in create mode 100644 dlls/powrprof/tests/powersetting.c
diff --git a/configure b/configure index ef7c99dd8e8..d249f566a4d 100755 --- a/configure +++ b/configure @@ -22718,6 +22718,7 @@ wine_fn_config_makefile dlls/pdh/tests enable_tests wine_fn_config_makefile dlls/photometadatahandler enable_photometadatahandler wine_fn_config_makefile dlls/pidgen enable_pidgen wine_fn_config_makefile dlls/powrprof enable_powrprof +wine_fn_config_makefile dlls/powrprof/tests enable_tests wine_fn_config_makefile dlls/printui enable_printui wine_fn_config_makefile dlls/prntvpt enable_prntvpt wine_fn_config_makefile dlls/prntvpt/tests enable_tests diff --git a/configure.ac b/configure.ac index 274591f5f53..fd552491c17 100644 --- a/configure.ac +++ b/configure.ac @@ -3011,6 +3011,7 @@ WINE_CONFIG_MAKEFILE(dlls/pdh/tests) WINE_CONFIG_MAKEFILE(dlls/photometadatahandler) WINE_CONFIG_MAKEFILE(dlls/pidgen) WINE_CONFIG_MAKEFILE(dlls/powrprof) +WINE_CONFIG_MAKEFILE(dlls/powrprof/tests) WINE_CONFIG_MAKEFILE(dlls/printui) WINE_CONFIG_MAKEFILE(dlls/prntvpt) WINE_CONFIG_MAKEFILE(dlls/prntvpt/tests) diff --git a/dlls/powrprof/tests/Makefile.in b/dlls/powrprof/tests/Makefile.in new file mode 100644 index 00000000000..e26fb91d878 --- /dev/null +++ b/dlls/powrprof/tests/Makefile.in @@ -0,0 +1,5 @@ +TESTDLL = powrprof.dll +IMPORTS = powrprof kernelbase ole32 advapi32 + +SOURCES = \ + powersetting.c diff --git a/dlls/powrprof/tests/powersetting.c b/dlls/powrprof/tests/powersetting.c new file mode 100644 index 00000000000..ce55239b226 --- /dev/null +++ b/dlls/powrprof/tests/powersetting.c @@ -0,0 +1,107 @@ +/* + * Tests for powersetting.c (powrprof.dll) + * + * Copyright 2025 Robert Lippmann + * + * 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 "initguid.h" +#include "guiddef.h" +#include "windows.h" +#include "winreg.h" +#include "objbase.h" +#include "powersetting.h" + +#include "wine/test.h" + + START_TEST(powersetting) + { + GUID *initial_powerprof = NULL, *new_powerprof = NULL, *tmp_powerprof = NULL; + WCHAR guid_string[40], guid_string2[40]; + HKEY tmp_key[] = { HKEY_CLASSES_ROOT, HKEY_CURRENT_CONFIG, HKEY_CURRENT_USER, + HKEY_DYN_DATA, HKEY_LOCAL_MACHINE, HKEY_PERFORMANCE_DATA, + HKEY_PERFORMANCE_NLSTEXT, HKEY_USERS }; + DWORD ret; + register int i; + + /* save initial power scheme to restore when test is finished */ + ret = PowerGetActiveScheme(NULL, &initial_powerprof); + ok(ret == ERROR_SUCCESS, "Retrieval of inital power scheme failed: %lu\n", ret); + StringFromGUID2(initial_powerprof,guid_string, sizeof(guid_string)); + + /* Windows can have additional power schemes, wine currently cannot */ + if(winetest_platform_is_wine) + { + ok((IsEqualGUID(initial_powerprof,&GUID_MAX_POWER_SAVINGS) || + IsEqualGUID(initial_powerprof,&GUID_TYPICAL_POWER_SAVINGS) || + IsEqualGUID(initial_powerprof,&GUID_MIN_POWER_SAVINGS)), + "Initial powerscheme GUID is invalid: %ls\n", guid_string); + } + /* not testing setting 2nd parameter to NULL since that's an + access violation on windows */ + + /* Win32 docs say that the first parameter of PowerGetActiveScheme should be NULL, + but Windows appears to ignore it rather than throw an error. + So, we'll test with all the predefined HKEYs to allow for regression in case + this changes. + */ + for (i = 0; i < ARRAYSIZE(tmp_key); i++) + { + ret = PowerGetActiveScheme(tmp_key[i], &new_powerprof); + ok(ret == ERROR_SUCCESS, "GetActivePowerScheme failed with HKEY %p\n", + tmp_key[i]); + LocalFree(new_powerprof); + } + + /* Test PowerSetActiveScheme with null */ + ret = PowerSetActiveScheme(NULL,NULL); + ok(ret == ERROR_INVALID_PARAMETER, "PowerSetActiveScheme incorrectly return error code %lu\n", ret); + + /* Try to actually change the power profile */ + if (IsEqualGUID(initial_powerprof, &GUID_MIN_POWER_SAVINGS)) + { + new_powerprof = (GUID *) & GUID_MAX_POWER_SAVINGS; + } + else + { + new_powerprof = (GUID *) & GUID_MIN_POWER_SAVINGS; + } + StringFromGUID2(new_powerprof,guid_string,sizeof(guid_string)); + ret = PowerSetActiveScheme(NULL, new_powerprof); + ok(ret == ERROR_SUCCESS, "PowerSetActiveScheme failed setting to valid power scheme %ls: %lu\n", guid_string, ret); + + /* now try to retrieve it */ + ret = PowerGetActiveScheme(NULL, &tmp_powerprof); + ok(ret == ERROR_SUCCESS, "Could not retrieve power scheme after setting it to %ls, code %lu\n", guid_string, ret); + StringFromGUID2(tmp_powerprof, guid_string2, sizeof(guid_string2)); + ok(IsEqualGUID(tmp_powerprof, new_powerprof), "Retrieved incorrect power profile after set: expected %ls, got %ls\n", + guid_string,guid_string2); + LocalFree(tmp_powerprof); + + /* try to set with non-NULL first parameter */ + for (i = 0; i < ARRAYSIZE(tmp_key); i++) + { + ret = PowerSetActiveScheme(tmp_key[i], new_powerprof); + ok(ret == ERROR_SUCCESS, "PowerSetActiveScheme failed with HKEY %p\n", + tmp_key[i]); + } + /* restore original power scheme */ + ret = PowerSetActiveScheme(NULL, initial_powerprof); + ok(ret == ERROR_SUCCESS, "Could not reset power scheme back to initial state, code: %lu\n", ret); + LocalFree(initial_powerprof); + + } + \ No newline at end of file