Calls to regedit.exe on user accounts wit standard privileges trigger a UAC prompt. Not responding to the prompt eventually causes a test timeout, so use registry API calls to determine if the tests are running with elevated privileges.
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/regedit/tests/regedit.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/programs/regedit/tests/regedit.c b/programs/regedit/tests/regedit.c index f9c12afb880..8c6e71907c0 100644 --- a/programs/regedit/tests/regedit.c +++ b/programs/regedit/tests/regedit.c @@ -3741,16 +3741,27 @@ static void test_export(void)
START_TEST(regedit) { - if(!exec_import_str("REGEDIT4\r\n\r\n")){ - win_skip("regedit not available, skipping regedit tests\n"); - return; - } + HKEY hkey; + LONG err;
- if (!run_regedit_exe("regedit.exe /s test.reg") && GetLastError() == ERROR_ELEVATION_REQUIRED) + /* Check if regedit.exe is running with elevated privileges */ + err = RegDeleteKeyA(HKEY_CLASSES_ROOT, KEY_BASE); + if (err == ERROR_ACCESS_DENIED) { win_skip("User is a non-elevated admin; skipping regedit tests.\n"); return; } + if (err == ERROR_FILE_NOT_FOUND) + { + if (RegCreateKeyExA(HKEY_CLASSES_ROOT, KEY_BASE, 0, NULL, REG_OPTION_NON_VOLATILE, + KEY_READ, NULL, &hkey, NULL)) + { + win_skip("User is a non-elevated admin; skipping regedit tests.\n"); + return; + } + RegCloseKey(hkey); + RegDeleteKeyA(HKEY_CLASSES_ROOT, KEY_BASE); + }
test_basic_import(); test_basic_import_unicode();
The tests only run if regedit.exe is started with elevated privileges. This is determined when the test suite is invoked.
Signed-off-by: Hugh McMaster hugh.mcmaster@outlook.com --- programs/regedit/tests/regedit.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-)
diff --git a/programs/regedit/tests/regedit.c b/programs/regedit/tests/regedit.c index 8c6e71907c0..0f58b6d85b8 100644 --- a/programs/regedit/tests/regedit.c +++ b/programs/regedit/tests/regedit.c @@ -1119,17 +1119,9 @@ static void test_basic_import_31(void) { HKEY hkey; DWORD dispos; - LONG lr;
- /* Check if regedit.exe is running with elevated privileges */ - lr = RegCreateKeyExA(HKEY_CLASSES_ROOT, KEY_BASE, 0, NULL, REG_OPTION_NON_VOLATILE, - KEY_READ|KEY_SET_VALUE, NULL, &hkey, &dispos); - if (lr == ERROR_ACCESS_DENIED) - { - win_skip("regedit.exe is not running with elevated privileges; " - "skipping Windows 3.1 import tests\n"); - return; - } + RegCreateKeyExA(HKEY_CLASSES_ROOT, KEY_BASE, 0, NULL, REG_OPTION_NON_VOLATILE, + KEY_READ|KEY_SET_VALUE, NULL, &hkey, &dispos);
if (dispos == REG_OPENED_EXISTING_KEY) delete_value(hkey, NULL); @@ -2226,17 +2218,13 @@ static void test_invalid_import_unicode(void) static void test_invalid_import_31(void) { HKEY hkey; - LONG lr; + DWORD dispos;
- /* Check if regedit.exe is running with elevated privileges */ - lr = RegCreateKeyExA(HKEY_CLASSES_ROOT, KEY_BASE, 0, NULL, REG_OPTION_NON_VOLATILE, - KEY_READ, NULL, &hkey, NULL); - if (lr == ERROR_ACCESS_DENIED) - { - win_skip("regedit.exe is not running with elevated privileges; " - "skipping Windows 3.1 invalid import tests\n"); - return; - } + RegCreateKeyExA(HKEY_CLASSES_ROOT, KEY_BASE, 0, NULL, REG_OPTION_NON_VOLATILE, + KEY_READ|KEY_SET_VALUE, NULL, &hkey, &dispos); + + if (dispos == REG_OPENED_EXISTING_KEY) + delete_value(hkey, NULL);
/* Test character validity at the start of the line */ exec_import_str("REGEDIT\r\n"