[SHELL32_APITEST] Improve ShellExecCmdLine testcase more (#3736)

- Simplify code.
- Loose the condition of success.
- Add some missing tests.
- Close newly opened windows gracefully.
CORE-17351, CORE-16898, CORE-17612
This commit is contained in:
Katayama Hirofumi MZ 2021-06-11 08:09:18 +09:00 committed by GitHub
parent c2317d773e
commit afd349a93e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -244,200 +244,360 @@ SHELLEXECCMDLINE g_pShellExecCmdLine = NULL;
typedef struct TEST_ENTRY typedef struct TEST_ENTRY
{ {
INT lineno; INT lineno;
HRESULT hr; BOOL result;
BOOL bAllowNonExe; BOOL bAllowNonExe;
LPCWSTR pwszWindowClass;
LPCWSTR pwszCommand; LPCWSTR pwszCommand;
LPCWSTR pwszStartDir; LPCWSTR pwszStartDir;
} TEST_ENTRY; } TEST_ENTRY;
static const char s_testfile1[] = "Test File.txt"; static WCHAR s_sub_program[MAX_PATH];
static const char s_testfile2[] = "Test File.bat"; static WCHAR s_win_test_exe[MAX_PATH];
static WCHAR s_sys_bat_file[MAX_PATH];
static WCHAR s_cur_dir[MAX_PATH];
static const TEST_ENTRY s_entries[] = static BOOL
GetSubProgramPath(void)
{
GetModuleFileNameW(NULL, s_sub_program, _countof(s_sub_program));
PathRemoveFileSpecW(s_sub_program);
PathAppendW(s_sub_program, L"shell32_apitest_sub.exe");
if (!PathFileExistsW(s_sub_program))
{
PathRemoveFileSpecW(s_sub_program);
PathAppendW(s_sub_program, L"testdata\\shell32_apitest_sub.exe");
if (!PathFileExistsW(s_sub_program))
{
return FALSE;
}
}
return TRUE;
}
static const TEST_ENTRY s_entries_1[] =
{ {
// NULL // NULL
{ __LINE__, (HRESULT)0xDEADFACE, FALSE, NULL, NULL, NULL }, { __LINE__, 0xBADFACE, FALSE, NULL, NULL },
{ __LINE__, (HRESULT)0xDEADFACE, FALSE, NULL, NULL, L"." }, { __LINE__, 0xBADFACE, FALSE, NULL, L"." },
{ __LINE__, (HRESULT)0xDEADFACE, FALSE, NULL, NULL, L"system32" }, { __LINE__, 0xBADFACE, FALSE, NULL, L"system32" },
{ __LINE__, (HRESULT)0xDEADFACE, FALSE, NULL, NULL, L"C:\\Program Files" }, { __LINE__, 0xBADFACE, FALSE, NULL, L"C:\\Program Files" },
{ __LINE__, (HRESULT)0xDEADFACE, TRUE, NULL, NULL, NULL }, { __LINE__, 0xBADFACE, TRUE, NULL, NULL },
{ __LINE__, (HRESULT)0xDEADFACE, TRUE, NULL, NULL, L"." }, { __LINE__, 0xBADFACE, TRUE, NULL, L"." },
{ __LINE__, (HRESULT)0xDEADFACE, TRUE, NULL, NULL, L"system32" }, { __LINE__, 0xBADFACE, TRUE, NULL, L"system32" },
{ __LINE__, (HRESULT)0xDEADFACE, TRUE, NULL, NULL, L"C:\\Program Files" }, { __LINE__, 0xBADFACE, TRUE, NULL, L"C:\\Program Files" },
// notepad // notepad
{ __LINE__, S_OK, FALSE, L"Notepad", L"notepad", NULL }, { __LINE__, TRUE, FALSE, L"notepad", NULL },
{ __LINE__, S_OK, FALSE, L"Notepad", L"notepad", L"." }, { __LINE__, TRUE, FALSE, L"notepad", L"." },
{ __LINE__, S_OK, FALSE, L"Notepad", L"notepad", L"system32" }, { __LINE__, TRUE, FALSE, L"notepad", L"system32" },
{ __LINE__, S_OK, FALSE, L"Notepad", L"notepad", L"C:\\Program Files" }, { __LINE__, TRUE, FALSE, L"notepad", L"C:\\Program Files" },
{ __LINE__, S_OK, FALSE, L"Notepad", L"notepad \"Test File.txt\"", NULL }, { __LINE__, TRUE, FALSE, L"notepad \"Test File.txt\"", NULL },
{ __LINE__, S_OK, FALSE, L"Notepad", L"notepad \"Test File.txt\"", L"." }, { __LINE__, TRUE, FALSE, L"notepad \"Test File.txt\"", L"." },
{ __LINE__, S_OK, TRUE, L"Notepad", L"notepad", NULL }, { __LINE__, TRUE, TRUE, L"notepad", NULL },
{ __LINE__, S_OK, TRUE, L"Notepad", L"notepad", L"." }, { __LINE__, TRUE, TRUE, L"notepad", L"." },
{ __LINE__, S_OK, TRUE, L"Notepad", L"notepad", L"system32" }, { __LINE__, TRUE, TRUE, L"notepad", L"system32" },
{ __LINE__, S_OK, TRUE, L"Notepad", L"notepad", L"C:\\Program Files" }, { __LINE__, TRUE, TRUE, L"notepad", L"C:\\Program Files" },
{ __LINE__, S_OK, TRUE, L"Notepad", L"notepad \"Test File.txt\"", NULL }, { __LINE__, TRUE, TRUE, L"notepad \"Test File.txt\"", NULL },
{ __LINE__, S_OK, TRUE, L"Notepad", L"notepad \"Test File.txt\"", L"." }, { __LINE__, TRUE, TRUE, L"notepad \"Test File.txt\"", L"." },
// notepad.exe // notepad.exe
{ __LINE__, S_OK, FALSE, L"Notepad", L"notepad.exe", NULL }, { __LINE__, TRUE, FALSE, L"notepad.exe", NULL },
{ __LINE__, S_OK, FALSE, L"Notepad", L"notepad.exe", L"." }, { __LINE__, TRUE, FALSE, L"notepad.exe", L"." },
{ __LINE__, S_OK, FALSE, L"Notepad", L"notepad.exe", L"system32" }, { __LINE__, TRUE, FALSE, L"notepad.exe", L"system32" },
{ __LINE__, S_OK, FALSE, L"Notepad", L"notepad.exe", L"C:\\Program Files" }, { __LINE__, TRUE, FALSE, L"notepad.exe", L"C:\\Program Files" },
{ __LINE__, S_OK, FALSE, L"Notepad", L"notepad.exe \"Test File.txt\"", NULL }, { __LINE__, TRUE, FALSE, L"notepad.exe \"Test File.txt\"", NULL },
{ __LINE__, S_OK, FALSE, L"Notepad", L"notepad.exe \"Test File.txt\"", L"." }, { __LINE__, TRUE, FALSE, L"notepad.exe \"Test File.txt\"", L"." },
{ __LINE__, S_OK, TRUE, L"Notepad", L"notepad.exe", NULL }, { __LINE__, TRUE, TRUE, L"notepad.exe", NULL },
{ __LINE__, S_OK, TRUE, L"Notepad", L"notepad.exe", L"." }, { __LINE__, TRUE, TRUE, L"notepad.exe", L"." },
{ __LINE__, S_OK, TRUE, L"Notepad", L"notepad.exe", L"system32" }, { __LINE__, TRUE, TRUE, L"notepad.exe", L"system32" },
{ __LINE__, S_OK, TRUE, L"Notepad", L"notepad.exe", L"C:\\Program Files" }, { __LINE__, TRUE, TRUE, L"notepad.exe", L"C:\\Program Files" },
{ __LINE__, S_OK, TRUE, L"Notepad", L"notepad.exe \"Test File.txt\"", NULL }, { __LINE__, TRUE, TRUE, L"notepad.exe \"Test File.txt\"", NULL },
{ __LINE__, S_OK, TRUE, L"Notepad", L"notepad.exe \"Test File.txt\"", L"." }, { __LINE__, TRUE, TRUE, L"notepad.exe \"Test File.txt\"", L"." },
// C:\notepad.exe // C:\notepad.exe
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"C:\\notepad.exe", NULL }, { __LINE__, FALSE, FALSE, L"C:\\notepad.exe", NULL },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"C:\\notepad.exe", L"." }, { __LINE__, FALSE, FALSE, L"C:\\notepad.exe", L"." },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"C:\\notepad.exe", L"system32" }, { __LINE__, FALSE, FALSE, L"C:\\notepad.exe", L"system32" },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"C:\\notepad.exe", L"C:\\Program Files" }, { __LINE__, FALSE, FALSE, L"C:\\notepad.exe", L"C:\\Program Files" },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"C:\\notepad.exe \"Test File.txt\"", NULL }, { __LINE__, FALSE, FALSE, L"C:\\notepad.exe \"Test File.txt\"", NULL },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"C:\\notepad.exe \"Test File.txt\"", L"." }, { __LINE__, FALSE, FALSE, L"C:\\notepad.exe \"Test File.txt\"", L"." },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"C:\\notepad.exe", NULL }, { __LINE__, FALSE, TRUE, L"C:\\notepad.exe", NULL },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"C:\\notepad.exe", L"." }, { __LINE__, FALSE, TRUE, L"C:\\notepad.exe", L"." },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"C:\\notepad.exe", L"system32" }, { __LINE__, FALSE, TRUE, L"C:\\notepad.exe", L"system32" },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"C:\\notepad.exe", L"C:\\Program Files" }, { __LINE__, FALSE, TRUE, L"C:\\notepad.exe", L"C:\\Program Files" },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"C:\\notepad.exe \"Test File.txt\"", NULL }, { __LINE__, FALSE, TRUE, L"C:\\notepad.exe \"Test File.txt\"", NULL },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"C:\\notepad.exe \"Test File.txt\"", L"." }, { __LINE__, FALSE, TRUE, L"C:\\notepad.exe \"Test File.txt\"", L"." },
// "notepad" // "notepad"
{ __LINE__, S_OK, FALSE, L"Notepad", L"\"notepad\"", NULL }, { __LINE__, TRUE, FALSE, L"\"notepad\"", NULL },
{ __LINE__, S_OK, FALSE, L"Notepad", L"\"notepad\"", L"." }, { __LINE__, TRUE, FALSE, L"\"notepad\"", L"." },
{ __LINE__, S_OK, FALSE, L"Notepad", L"\"notepad\"", L"system32" }, { __LINE__, TRUE, FALSE, L"\"notepad\"", L"system32" },
{ __LINE__, S_OK, FALSE, L"Notepad", L"\"notepad\"", L"C:\\Program Files" }, { __LINE__, TRUE, FALSE, L"\"notepad\"", L"C:\\Program Files" },
{ __LINE__, S_OK, FALSE, L"Notepad", L"\"notepad\" \"Test File.txt\"", NULL }, { __LINE__, TRUE, FALSE, L"\"notepad\" \"Test File.txt\"", NULL },
{ __LINE__, S_OK, FALSE, L"Notepad", L"\"notepad\" \"Test File.txt\"", L"." }, { __LINE__, TRUE, FALSE, L"\"notepad\" \"Test File.txt\"", L"." },
{ __LINE__, S_OK, TRUE, L"Notepad", L"\"notepad\"", NULL }, { __LINE__, TRUE, TRUE, L"\"notepad\"", NULL },
{ __LINE__, S_OK, TRUE, L"Notepad", L"\"notepad\"", L"." }, { __LINE__, TRUE, TRUE, L"\"notepad\"", L"." },
{ __LINE__, S_OK, TRUE, L"Notepad", L"\"notepad\"", L"system32" }, { __LINE__, TRUE, TRUE, L"\"notepad\"", L"system32" },
{ __LINE__, S_OK, TRUE, L"Notepad", L"\"notepad\"", L"C:\\Program Files" }, { __LINE__, TRUE, TRUE, L"\"notepad\"", L"C:\\Program Files" },
{ __LINE__, S_OK, TRUE, L"Notepad", L"\"notepad\" \"Test File.txt\"", NULL }, { __LINE__, TRUE, TRUE, L"\"notepad\" \"Test File.txt\"", NULL },
{ __LINE__, S_OK, TRUE, L"Notepad", L"\"notepad\" \"Test File.txt\"", L"." }, { __LINE__, TRUE, TRUE, L"\"notepad\" \"Test File.txt\"", L"." },
// "notepad.exe" // "notepad.exe"
{ __LINE__, S_OK, FALSE, L"Notepad", L"\"notepad.exe\"", NULL }, { __LINE__, TRUE, FALSE, L"\"notepad.exe\"", NULL },
{ __LINE__, S_OK, FALSE, L"Notepad", L"\"notepad.exe\"", L"." }, { __LINE__, TRUE, FALSE, L"\"notepad.exe\"", L"." },
{ __LINE__, S_OK, FALSE, L"Notepad", L"\"notepad.exe\"", L"system32" }, { __LINE__, TRUE, FALSE, L"\"notepad.exe\"", L"system32" },
{ __LINE__, S_OK, FALSE, L"Notepad", L"\"notepad.exe\"", L"C:\\Program Files" }, { __LINE__, TRUE, FALSE, L"\"notepad.exe\"", L"C:\\Program Files" },
{ __LINE__, S_OK, FALSE, L"Notepad", L"\"notepad.exe\" \"Test File.txt\"", NULL }, { __LINE__, TRUE, FALSE, L"\"notepad.exe\" \"Test File.txt\"", NULL },
{ __LINE__, S_OK, FALSE, L"Notepad", L"\"notepad.exe\" \"Test File.txt\"", L"." }, { __LINE__, TRUE, FALSE, L"\"notepad.exe\" \"Test File.txt\"", L"." },
{ __LINE__, S_OK, TRUE, L"Notepad", L"\"notepad.exe\"", NULL }, { __LINE__, TRUE, TRUE, L"\"notepad.exe\"", NULL },
{ __LINE__, S_OK, TRUE, L"Notepad", L"\"notepad.exe\"", L"." }, { __LINE__, TRUE, TRUE, L"\"notepad.exe\"", L"." },
{ __LINE__, S_OK, TRUE, L"Notepad", L"\"notepad.exe\"", L"system32" }, { __LINE__, TRUE, TRUE, L"\"notepad.exe\"", L"system32" },
{ __LINE__, S_OK, TRUE, L"Notepad", L"\"notepad.exe\"", L"C:\\Program Files" }, { __LINE__, TRUE, TRUE, L"\"notepad.exe\"", L"C:\\Program Files" },
{ __LINE__, S_OK, TRUE, L"Notepad", L"\"notepad.exe\" \"Test File.txt\"", NULL }, { __LINE__, TRUE, TRUE, L"\"notepad.exe\" \"Test File.txt\"", NULL },
{ __LINE__, S_OK, TRUE, L"Notepad", L"\"notepad.exe\" \"Test File.txt\"", L"." }, { __LINE__, TRUE, TRUE, L"\"notepad.exe\" \"Test File.txt\"", L"." },
// test program
{ __LINE__, FALSE, FALSE, L"test program", NULL },
{ __LINE__, FALSE, FALSE, L"test program", L"." },
{ __LINE__, FALSE, FALSE, L"test program", L"system32" },
{ __LINE__, FALSE, FALSE, L"test program", L"C:\\Program Files" },
{ __LINE__, FALSE, FALSE, L"test program \"Test File.txt\"", NULL },
{ __LINE__, FALSE, FALSE, L"test program \"Test File.txt\"", L"." },
{ __LINE__, FALSE, TRUE, L"test program", NULL },
{ __LINE__, FALSE, TRUE, L"test program", L"." },
{ __LINE__, FALSE, TRUE, L"test program", L"system32" },
{ __LINE__, FALSE, TRUE, L"test program", L"C:\\Program Files" },
{ __LINE__, FALSE, TRUE, L"test program \"Test File.txt\"", NULL },
{ __LINE__, FALSE, TRUE, L"test program \"Test File.txt\"", L"." },
// test program.exe // test program.exe
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"test program.exe", NULL }, { __LINE__, FALSE, FALSE, L"test program.exe", NULL },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"test program.exe", L"." }, { __LINE__, FALSE, FALSE, L"test program.exe", L"." },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"test program.exe", L"system32" }, { __LINE__, FALSE, FALSE, L"test program.exe", L"system32" },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"test program.exe", L"C:\\Program Files" }, { __LINE__, FALSE, FALSE, L"test program.exe", L"C:\\Program Files" },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"test program.exe \"Test File.txt\"", NULL }, { __LINE__, FALSE, FALSE, L"test program.exe \"Test File.txt\"", NULL },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"test program.exe \"Test File.txt\"", L"." }, { __LINE__, FALSE, FALSE, L"test program.exe \"Test File.txt\"", L"." },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"test program.exe", NULL }, { __LINE__, FALSE, TRUE, L"test program.exe", NULL },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"test program.exe", L"." }, { __LINE__, FALSE, TRUE, L"test program.exe", L"." },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"test program.exe", L"system32" }, { __LINE__, FALSE, TRUE, L"test program.exe", L"system32" },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"test program.exe", L"C:\\Program Files" }, { __LINE__, FALSE, TRUE, L"test program.exe", L"C:\\Program Files" },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"test program.exe \"Test File.txt\"", NULL }, { __LINE__, FALSE, TRUE, L"test program.exe \"Test File.txt\"", NULL },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"test program.exe \"Test File.txt\"", L"." }, { __LINE__, FALSE, TRUE, L"test program.exe \"Test File.txt\"", L"." },
// test program.bat
{ __LINE__, FALSE, FALSE, L"test program.bat", NULL },
{ __LINE__, FALSE, FALSE, L"test program.bat", L"." },
{ __LINE__, FALSE, FALSE, L"test program.bat", L"system32" },
{ __LINE__, FALSE, FALSE, L"test program.bat", L"C:\\Program Files" },
{ __LINE__, FALSE, FALSE, L"test program.bat \"Test File.txt\"", NULL },
{ __LINE__, FALSE, FALSE, L"test program.bat \"Test File.txt\"", L"." },
{ __LINE__, FALSE, TRUE, L"test program.bat", NULL },
{ __LINE__, FALSE, TRUE, L"test program.bat", L"." },
{ __LINE__, FALSE, TRUE, L"test program.bat", L"system32" },
{ __LINE__, FALSE, TRUE, L"test program.bat", L"C:\\Program Files" },
{ __LINE__, FALSE, TRUE, L"test program.bat \"Test File.txt\"", NULL },
{ __LINE__, FALSE, TRUE, L"test program.bat \"Test File.txt\"", L"." },
// "test program" // "test program"
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"\"test program\"", NULL }, { __LINE__, FALSE, FALSE, L"\"test program\"", NULL },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"\"test program\"", L"." }, { __LINE__, FALSE, FALSE, L"\"test program\"", L"." },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"\"test program\"", L"system32" }, { __LINE__, FALSE, FALSE, L"\"test program\"", L"system32" },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"\"test program\"", L"C:\\Program Files" }, { __LINE__, FALSE, FALSE, L"\"test program\"", L"C:\\Program Files" },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"\"test program\" \"Test File.txt\"", NULL }, { __LINE__, FALSE, FALSE, L"\"test program\" \"Test File.txt\"", NULL },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"\"test program\" \"Test File.txt\"", L"." }, { __LINE__, FALSE, FALSE, L"\"test program\" \"Test File.txt\"", L"." },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"\"test program\"", NULL }, { __LINE__, FALSE, TRUE, L"\"test program\"", NULL },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"\"test program\"", L"." }, { __LINE__, FALSE, TRUE, L"\"test program\"", L"." },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"\"test program\"", L"system32" }, { __LINE__, FALSE, TRUE, L"\"test program\"", L"system32" },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"\"test program\"", L"C:\\Program Files" }, { __LINE__, FALSE, TRUE, L"\"test program\"", L"C:\\Program Files" },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"\"test program\" \"Test File.txt\"", NULL }, { __LINE__, FALSE, TRUE, L"\"test program\" \"Test File.txt\"", NULL },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"\"test program\" \"Test File.txt\"", L"." }, { __LINE__, FALSE, TRUE, L"\"test program\" \"Test File.txt\"", L"." },
// "test program.exe" // "test program.exe"
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"\"test program.exe\"", NULL }, { __LINE__, TRUE, FALSE, L"\"test program.exe\"", NULL },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"\"test program.exe\"", L"." }, { __LINE__, TRUE, FALSE, L"\"test program.exe\"", L"." },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"\"test program.exe\"", L"system32" }, { __LINE__, TRUE, FALSE, L"\"test program.exe\"", L"system32" },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"\"test program.exe\"", L"C:\\Program Files" }, { __LINE__, TRUE, FALSE, L"\"test program.exe\"", L"C:\\Program Files" },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"\"test program.exe\" \"Test File.txt\"", NULL }, { __LINE__, TRUE, FALSE, L"\"test program.exe\" \"Test File.txt\"", NULL },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"\"test program.exe\" \"Test File.txt\"", L"." }, { __LINE__, TRUE, FALSE, L"\"test program.exe\" \"Test File.txt\"", L"." },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"\"test program.exe\"", NULL }, { __LINE__, TRUE, TRUE, L"\"test program.exe\"", NULL },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"\"test program.exe\"", L"." }, { __LINE__, TRUE, TRUE, L"\"test program.exe\"", L"." },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"\"test program.exe\"", L"system32" }, { __LINE__, TRUE, TRUE, L"\"test program.exe\"", L"system32" },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"\"test program.exe\"", L"C:\\Program Files" }, { __LINE__, TRUE, TRUE, L"\"test program.exe\"", L"C:\\Program Files" },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"\"test program.exe\" \"Test File.txt\"", NULL }, { __LINE__, TRUE, TRUE, L"\"test program.exe\" \"Test File.txt\"", NULL },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"\"test program.exe\" \"Test File.txt\"", L"." }, { __LINE__, TRUE, TRUE, L"\"test program.exe\" \"Test File.txt\"", L"." },
// "test program.bat"
{ __LINE__, FALSE, FALSE, L"\"test program.bat\"", NULL },
{ __LINE__, FALSE, FALSE, L"\"test program.bat\"", L"." },
{ __LINE__, FALSE, FALSE, L"\"test program.bat\"", L"system32" },
{ __LINE__, FALSE, FALSE, L"\"test program.bat\"", L"C:\\Program Files" },
{ __LINE__, FALSE, FALSE, L"\"test program.bat\" \"Test File.txt\"", NULL },
{ __LINE__, FALSE, FALSE, L"\"test program.bat\" \"Test File.txt\"", L"." },
{ __LINE__, FALSE, TRUE, L"\"test program.bat\"", NULL },
{ __LINE__, FALSE, TRUE, L"\"test program.bat\"", L"." },
{ __LINE__, FALSE, TRUE, L"\"test program.bat\"", L"system32" },
{ __LINE__, FALSE, TRUE, L"\"test program.bat\"", L"C:\\Program Files" },
{ __LINE__, FALSE, TRUE, L"\"test program.bat\" \"Test File.txt\"", NULL },
{ __LINE__, FALSE, TRUE, L"\"test program.bat\" \"Test File.txt\"", L"." },
// invalid program // invalid program
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"invalid program", NULL }, { __LINE__, FALSE, FALSE, L"invalid program", NULL },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"invalid program", L"." }, { __LINE__, FALSE, FALSE, L"invalid program", L"." },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"invalid program", L"system32" }, { __LINE__, FALSE, FALSE, L"invalid program", L"system32" },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"invalid program", L"C:\\Program Files" }, { __LINE__, FALSE, FALSE, L"invalid program", L"C:\\Program Files" },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"invalid program \"Test File.txt\"", NULL }, { __LINE__, FALSE, FALSE, L"invalid program \"Test File.txt\"", NULL },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"invalid program \"Test File.txt\"", L"." }, { __LINE__, FALSE, FALSE, L"invalid program \"Test File.txt\"", L"." },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"invalid program", NULL }, { __LINE__, FALSE, TRUE, L"invalid program", NULL },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"invalid program", L"." }, { __LINE__, FALSE, TRUE, L"invalid program", L"." },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"invalid program", L"system32" }, { __LINE__, FALSE, TRUE, L"invalid program", L"system32" },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"invalid program", L"C:\\Program Files" }, { __LINE__, FALSE, TRUE, L"invalid program", L"C:\\Program Files" },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"invalid program \"Test File.txt\"", NULL }, { __LINE__, FALSE, TRUE, L"invalid program \"Test File.txt\"", NULL },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"invalid program \"Test File.txt\"", L"." }, { __LINE__, FALSE, TRUE, L"invalid program \"Test File.txt\"", L"." },
// \"invalid program.exe\" // \"invalid program.exe\"
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"\"invalid program.exe\"", NULL }, { __LINE__, FALSE, FALSE, L"\"invalid program.exe\"", NULL },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"\"invalid program.exe\"", L"." }, { __LINE__, FALSE, FALSE, L"\"invalid program.exe\"", L"." },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"\"invalid program.exe\"", L"system32" }, { __LINE__, FALSE, FALSE, L"\"invalid program.exe\"", L"system32" },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"\"invalid program.exe\"", L"C:\\Program Files" }, { __LINE__, FALSE, FALSE, L"\"invalid program.exe\"", L"C:\\Program Files" },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"\"invalid program.exe\" \"Test File.txt\"", NULL }, { __LINE__, FALSE, FALSE, L"\"invalid program.exe\" \"Test File.txt\"", NULL },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", L"\"invalid program.exe\" \"Test File.txt\"", L"." }, { __LINE__, FALSE, FALSE, L"\"invalid program.exe\" \"Test File.txt\"", L"." },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"\"invalid program.exe\"", NULL }, { __LINE__, FALSE, TRUE, L"\"invalid program.exe\"", NULL },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"\"invalid program.exe\"", L"." }, { __LINE__, FALSE, TRUE, L"\"invalid program.exe\"", L"." },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"\"invalid program.exe\"", L"system32" }, { __LINE__, FALSE, TRUE, L"\"invalid program.exe\"", L"system32" },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"\"invalid program.exe\"", L"C:\\Program Files" }, { __LINE__, FALSE, TRUE, L"\"invalid program.exe\"", L"C:\\Program Files" },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"\"invalid program.exe\" \"Test File.txt\"", NULL }, { __LINE__, FALSE, TRUE, L"\"invalid program.exe\" \"Test File.txt\"", NULL },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", L"\"invalid program.exe\" \"Test File.txt\"", L"." }, { __LINE__, FALSE, TRUE, L"\"invalid program.exe\" \"Test File.txt\"", L"." },
// My Documents // My Documents
{ __LINE__, S_OK, TRUE, NULL, L"::{450d8fba-ad25-11d0-98a8-0800361b1103}", NULL }, { __LINE__, TRUE, TRUE, L"::{450d8fba-ad25-11d0-98a8-0800361b1103}", NULL },
{ __LINE__, S_OK, TRUE, NULL, L"shell:::{450d8fba-ad25-11d0-98a8-0800361b1103}", NULL }, { __LINE__, TRUE, TRUE, L"shell:::{450d8fba-ad25-11d0-98a8-0800361b1103}", NULL },
// Control Panel
{ __LINE__, S_OK, TRUE, NULL, L"::{5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0}", NULL },
{ __LINE__, S_OK, TRUE, NULL, L"shell:::{5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0}", NULL },
// shell:sendto // shell:sendto
{ __LINE__, S_OK, TRUE, NULL, L"shell:sendto", NULL }, { __LINE__, TRUE, TRUE, L"shell:sendto", NULL },
// iexplore.exe
{ __LINE__, TRUE, FALSE, L"iexplore", NULL },
{ __LINE__, TRUE, FALSE, L"iexplore.exe", NULL },
{ __LINE__, TRUE, TRUE, L"iexplore", NULL },
{ __LINE__, TRUE, TRUE, L"iexplore.exe", NULL },
// https://google.com
{ __LINE__, TRUE, FALSE, L"https://google.com", NULL },
{ __LINE__, TRUE, TRUE, L"https://google.com", NULL },
// Test File 1.txt
{ __LINE__, FALSE, FALSE, L"Test File 1.txt", NULL },
{ __LINE__, FALSE, FALSE, L"Test File 1.txt", L"." },
{ __LINE__, FALSE, FALSE, L"Test File 1.txt", L"system32" },
{ __LINE__, FALSE, FALSE, L"Test File 1.txt", s_cur_dir },
{ __LINE__, FALSE, FALSE, L"\"Test File 1.txt\"", NULL },
{ __LINE__, FALSE, FALSE, L"\"Test File 1.txt\"", L"." },
{ __LINE__, FALSE, FALSE, L"\"Test File 1.txt\"", L"system32" },
{ __LINE__, FALSE, FALSE, L"\"Test File 1.txt\"", s_cur_dir },
{ __LINE__, FALSE, FALSE, L"\"Test File 1.txt\" \"Test File.txt\"", NULL },
{ __LINE__, FALSE, FALSE, L"\"Test File 1.txt\" \"Test File.txt\"", L"." },
{ __LINE__, FALSE, FALSE, L"\"Test File 1.txt\" \"Test File.txt\"", L"system32" },
{ __LINE__, FALSE, TRUE, L"Test File 1.txt", NULL },
{ __LINE__, TRUE, TRUE, L"Test File 1.txt", L"." },
{ __LINE__, FALSE, TRUE, L"Test File 1.txt", L"system32" },
{ __LINE__, TRUE, TRUE, L"Test File 1.txt", s_cur_dir },
{ __LINE__, FALSE, TRUE, L"\"Test File 1.txt\"", NULL },
{ __LINE__, TRUE, TRUE, L"\"Test File 1.txt\"", L"." },
{ __LINE__, TRUE, TRUE, L"\"Test File 1.txt\"", L"system32" },
{ __LINE__, TRUE, TRUE, L"\"Test File 1.txt\"", s_cur_dir },
{ __LINE__, FALSE, TRUE, L"\"Test File 1.txt\" \"Test File.txt\"", NULL },
{ __LINE__, TRUE, TRUE, L"\"Test File 1.txt\" \"Test File.txt\"", L"." },
{ __LINE__, TRUE, TRUE, L"\"Test File 1.txt\" \"Test File.txt\"", L"system32" },
{ __LINE__, TRUE, TRUE, L"\"Test File 1.txt\" \"Test File.txt\"", s_cur_dir },
// Test File 2.bat
{ __LINE__, FALSE, FALSE, L"Test File 2.bat", NULL },
{ __LINE__, FALSE, FALSE, L"Test File 2.bat", L"." },
{ __LINE__, FALSE, FALSE, L"Test File 2.bat", L"system32" },
{ __LINE__, FALSE, FALSE, L"Test File 2.bat", s_cur_dir },
{ __LINE__, FALSE, FALSE, L"\"Test File 2.bat\"", NULL },
{ __LINE__, FALSE, FALSE, L"\"Test File 2.bat\"", L"." },
{ __LINE__, FALSE, FALSE, L"\"Test File 2.bat\"", L"system32" },
{ __LINE__, FALSE, FALSE, L"\"Test File 2.bat\"", s_cur_dir },
{ __LINE__, FALSE, FALSE, L"\"Test File 2.bat\" \"Test File.txt\"", NULL },
{ __LINE__, FALSE, FALSE, L"\"Test File 2.bat\" \"Test File.txt\"", L"." },
{ __LINE__, FALSE, FALSE, L"\"Test File 2.bat\" \"Test File.txt\"", L"system32" },
{ __LINE__, FALSE, FALSE, L"\"Test File 2.bat\" \"Test File.txt\"", s_cur_dir },
{ __LINE__, FALSE, TRUE, L"Test File 2.bat", NULL },
{ __LINE__, FALSE, TRUE, L"Test File 2.bat", L"." },
{ __LINE__, FALSE, TRUE, L"Test File 2.bat", L"system32" },
{ __LINE__, FALSE, TRUE, L"Test File 2.bat", s_cur_dir },
{ __LINE__, FALSE, TRUE, L"\"Test File 2.bat\"", NULL },
{ __LINE__, FALSE, TRUE, L"\"Test File 2.bat\"", L"." },
{ __LINE__, FALSE, TRUE, L"\"Test File 2.bat\"", L"system32" },
{ __LINE__, FALSE, TRUE, L"\"Test File 2.bat\"", s_cur_dir },
{ __LINE__, FALSE, TRUE, L"\"Test File 2.bat\" \"Test File.txt\"", NULL },
{ __LINE__, FALSE, TRUE, L"\"Test File 2.bat\" \"Test File.txt\"", L"." },
{ __LINE__, FALSE, TRUE, L"\"Test File 2.bat\" \"Test File.txt\"", L"system32" },
{ __LINE__, FALSE, TRUE, L"\"Test File 2.bat\" \"Test File.txt\"", s_cur_dir },
}; };
static BOOL CloseAppWindows(LPCWSTR pwszWindowClass, BOOL bRetry, INT nCount = 10) static const TEST_ENTRY s_entries_2[] =
{ {
#define INTERVAL 100 // Test File 1.txt (with setting path)
BOOL bFound = FALSE; { __LINE__, FALSE, FALSE, L"Test File 1.txt", NULL },
for (INT i = 0; i < nCount; ++i) { __LINE__, FALSE, FALSE, L"Test File 1.txt", L"." },
{ __LINE__, FALSE, FALSE, L"Test File 1.txt", L"system32" },
{ __LINE__, FALSE, FALSE, L"Test File 1.txt", s_cur_dir },
{ __LINE__, FALSE, FALSE, L"\"Test File 1.txt\"", NULL },
{ __LINE__, FALSE, FALSE, L"\"Test File 1.txt\"", L"." },
{ __LINE__, FALSE, FALSE, L"\"Test File 1.txt\"", L"system32" },
{ __LINE__, FALSE, FALSE, L"\"Test File 1.txt\"", s_cur_dir },
{ __LINE__, FALSE, FALSE, L"\"Test File 1.txt\" \"Test File.txt\"", NULL },
{ __LINE__, FALSE, FALSE, L"\"Test File 1.txt\" \"Test File.txt\"", L"." },
{ __LINE__, FALSE, FALSE, L"\"Test File 1.txt\" \"Test File.txt\"", L"system32" },
{ __LINE__, FALSE, FALSE, L"\"Test File 1.txt\" \"Test File.txt\"", s_cur_dir },
{ __LINE__, FALSE, TRUE, L"Test File 1.txt", NULL },
{ __LINE__, TRUE, TRUE, L"Test File 1.txt", L"." },
{ __LINE__, FALSE, TRUE, L"Test File 1.txt", L"system32" },
{ __LINE__, TRUE, TRUE, L"Test File 1.txt", s_cur_dir },
{ __LINE__, TRUE, TRUE, L"\"Test File 1.txt\"", NULL },
{ __LINE__, TRUE, TRUE, L"\"Test File 1.txt\"", L"." },
{ __LINE__, TRUE, TRUE, L"\"Test File 1.txt\"", L"system32" },
{ __LINE__, TRUE, TRUE, L"\"Test File 1.txt\"", s_cur_dir },
{ __LINE__, TRUE, TRUE, L"\"Test File 1.txt\" \"Test File.txt\"", NULL },
{ __LINE__, TRUE, TRUE, L"\"Test File 1.txt\" \"Test File.txt\"", L"." },
{ __LINE__, TRUE, TRUE, L"\"Test File 1.txt\" \"Test File.txt\"", L"system32" },
{ __LINE__, TRUE, TRUE, L"\"Test File 1.txt\" \"Test File.txt\"", s_cur_dir },
// Test File 2.bat (with setting path)
{ __LINE__, FALSE, FALSE, L"Test File 2.bat", NULL },
{ __LINE__, FALSE, FALSE, L"Test File 2.bat", L"." },
{ __LINE__, FALSE, FALSE, L"Test File 2.bat", L"system32" },
{ __LINE__, FALSE, FALSE, L"Test File 2.bat", s_cur_dir },
{ __LINE__, FALSE, FALSE, L"\"Test File 2.bat\"", NULL },
{ __LINE__, FALSE, FALSE, L"\"Test File 2.bat\"", L"." },
{ __LINE__, FALSE, FALSE, L"\"Test File 2.bat\"", L"system32" },
{ __LINE__, FALSE, FALSE, L"\"Test File 2.bat\"", s_cur_dir },
{ __LINE__, FALSE, FALSE, L"\"Test File 2.bat\" \"Test File.txt\"", NULL },
{ __LINE__, FALSE, FALSE, L"\"Test File 2.bat\" \"Test File.txt\"", L"." },
{ __LINE__, FALSE, FALSE, L"\"Test File 2.bat\" \"Test File.txt\"", L"system32" },
{ __LINE__, FALSE, FALSE, L"\"Test File 2.bat\" \"Test File.txt\"", s_cur_dir },
{ __LINE__, FALSE, TRUE, L"Test File 2.bat", NULL },
{ __LINE__, FALSE, TRUE, L"Test File 2.bat", L"." },
{ __LINE__, FALSE, TRUE, L"Test File 2.bat", L"system32" },
{ __LINE__, FALSE, TRUE, L"Test File 2.bat", s_cur_dir },
{ __LINE__, FALSE, TRUE, L"\"Test File 2.bat\"", NULL },
{ __LINE__, FALSE, TRUE, L"\"Test File 2.bat\"", L"." },
{ __LINE__, FALSE, TRUE, L"\"Test File 2.bat\"", L"system32" },
{ __LINE__, FALSE, TRUE, L"\"Test File 2.bat\"", s_cur_dir },
{ __LINE__, FALSE, TRUE, L"\"Test File 2.bat\" \"Test File.txt\"", NULL },
{ __LINE__, FALSE, TRUE, L"\"Test File 2.bat\" \"Test File.txt\"", L"." },
{ __LINE__, FALSE, TRUE, L"\"Test File 2.bat\" \"Test File.txt\"", L"system32" },
{ __LINE__, FALSE, TRUE, L"\"Test File 2.bat\" \"Test File.txt\"", s_cur_dir },
};
typedef struct OPENWNDS
{ {
HWND hwnd = FindWindowW(pwszWindowClass, NULL); UINT count;
if (!hwnd) HWND *phwnd;
} OPENWNDS;
static OPENWNDS s_wi0 = { 0 }, s_wi1 = { 0 };
static BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{ {
if (!bRetry) OPENWNDS *info = (OPENWNDS *)lParam;
break; info->phwnd = (HWND *)realloc(info->phwnd, (info->count + 1) * sizeof(HWND));
Sleep(INTERVAL); if (!info->phwnd)
continue; return FALSE;
} info->phwnd[info->count] = hwnd;
bFound = TRUE; ++(info->count);
HWND hwndPopup = GetLastActivePopup(hwnd); return TRUE;
if (hwndPopup && hwnd != hwndPopup)
{
PostMessageW(hwndPopup, WM_COMMAND, IDCANCEL, 0);
PostMessageW(hwndPopup, WM_COMMAND, IDNO, 0);
PostMessageW(hwndPopup, WM_CLOSE, 0, 0);
}
PostMessageW(hwnd, WM_CLOSE, 0, 0);
Sleep(INTERVAL);
}
return bFound;
#undef INTERVAL
} }
static void DoEntry(const TEST_ENTRY *pEntry) static void DoEntry(const TEST_ENTRY *pEntry)
{ {
HRESULT hr; HRESULT hr;
DWORD dwSeclFlags; DWORD dwSeclFlags;
BOOL result;
if (pEntry->bAllowNonExe) if (pEntry->bAllowNonExe)
dwSeclFlags = SECL_NO_UI | SECL_ALLOW_NONEXE; dwSeclFlags = SECL_NO_UI | SECL_ALLOW_NONEXE;
@ -459,18 +619,37 @@ static void DoEntry(const TEST_ENTRY *pEntry)
} }
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{ {
hr = 0xDEADFACE; hr = 0xBADFACE;
} }
_SEH2_END; _SEH2_END;
ok(hr == pEntry->hr, "Line %d: hr expected 0x%lX, was 0x%lX\n", pEntry->lineno, pEntry->hr, hr); if (hr == 0xBADFACE)
result = hr;
else
result = (hr == S_OK);
if (SUCCEEDED(hr) && pEntry->pwszWindowClass) ok(result == pEntry->result, "Line %d: result expected %d, was %d\n",
pEntry->lineno, pEntry->result, result);
// close newly opened windows
EnumWindows(EnumWindowsProc, (LPARAM)&s_wi1);
for (UINT i1 = 0; i1 < s_wi1.count; ++i1)
{ {
BOOL bFound = CloseAppWindows(pEntry->pwszWindowClass, TRUE); BOOL bFound = FALSE;
ok(bFound, "Line %d: The window not found\n", pEntry->lineno); for (UINT i0 = 0; i0 < s_wi0.count; ++i0)
{
if (s_wi1.phwnd[i1] == s_wi0.phwnd[i0])
{
bFound = TRUE;
break;
} }
} }
if (!bFound)
PostMessageW(s_wi1.phwnd[i1], WM_CLOSE, 0, 0);
}
free(s_wi1.phwnd);
ZeroMemory(&s_wi1, sizeof(s_wi1));
}
START_TEST(ShellExecCmdLine) START_TEST(ShellExecCmdLine)
{ {
@ -493,92 +672,70 @@ START_TEST(ShellExecCmdLine)
} }
} }
CloseAppWindows(L"Notepad", FALSE); if (!GetSubProgramPath())
{
skip("shell32_apitest_sub.exe is not found\n");
return;
}
// s_testfile1 // record open windows
FILE *fp = fopen(s_testfile1, "wb"); if (!EnumWindows(EnumWindowsProc, (LPARAM)&s_wi0))
{
skip("EnumWindows failed\n");
free(s_wi0.phwnd);
return;
}
// s_win_test_exe
GetWindowsDirectoryW(s_win_test_exe, _countof(s_win_test_exe));
PathAppendW(s_win_test_exe, L"test program.exe");
BOOL ret = CopyFileW(s_sub_program, s_win_test_exe, FALSE);
if (!ret)
{
skip("Please retry with admin rights\n");
free(s_wi0.phwnd);
return;
}
FILE *fp;
// s_sys_bat_file
GetSystemDirectoryW(s_sys_bat_file, _countof(s_sys_bat_file));
PathAppendW(s_sys_bat_file, L"test program.bat");
fp = _wfopen(s_sys_bat_file, L"wb");
fclose(fp);
ok_int(PathFileExistsW(s_sys_bat_file), TRUE);
// "Test File 1.txt"
fp = fopen("Test File 1.txt", "wb");
ok(fp != NULL, "failed to create a test file\n"); ok(fp != NULL, "failed to create a test file\n");
fclose(fp); fclose(fp);
ok_int(PathFileExistsA("Test File 1.txt"), TRUE);
// s_testfile2 // "Test File 2.bat"
fp = fopen(s_testfile2, "wb"); fp = fopen("Test File 2.bat", "wb");
ok(fp != NULL, "failed to create a test file\n"); ok(fp != NULL, "failed to create a test file\n");
if (fp)
{
fprintf(fp, "echo OK\n");
}
fclose(fp); fclose(fp);
ok_int(PathFileExistsA("Test File 2.bat"), TRUE);
for (size_t i = 0; i < _countof(s_entries); ++i) // s_cur_dir
GetCurrentDirectoryW(_countof(s_cur_dir), s_cur_dir);
// do tests
for (size_t i = 0; i < _countof(s_entries_1); ++i)
{ {
DoEntry(&s_entries[i]); DoEntry(&s_entries_1[i]);
} }
SetEnvironmentVariableW(L"PATH", s_cur_dir);
WCHAR buf0[MAX_PATH]; for (size_t i = 0; i < _countof(s_entries_2); ++i)
WCHAR buf1[MAX_PATH];
WCHAR buf2[MAX_PATH];
TEST_ENTRY additionals[] =
{ {
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", buf0, NULL }, DoEntry(&s_entries_2[i]);
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", buf0, L"." },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", buf0, L"system32" },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", buf1, NULL },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", buf1, L"." },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", buf1, L"system32" },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", buf2, NULL },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", buf2, L"." },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, L"Notepad", buf2, L"system32" },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", buf0, NULL }, // FIXME
{ __LINE__, S_OK, TRUE, L"Notepad", buf0, L"." },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", buf0, L"system32" }, // FIXME
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", buf1, NULL }, // FIXME
{ __LINE__, S_OK, TRUE, L"Notepad", buf1, L"." },
{ __LINE__, S_OK, TRUE, L"Notepad", buf1, L"system32" },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, L"Notepad", buf2, NULL }, // FIXME
{ __LINE__, S_OK, TRUE, L"Notepad", buf2, L"." },
{ __LINE__, S_OK, TRUE, L"Notepad", buf2, L"system32" },
};
wsprintfW(buf0, L"%hs", s_testfile1);
wsprintfW(buf1, L"\"%hs\"", s_testfile1);
wsprintfW(buf2, L"\"%hs\" \"Test File.txt\"", s_testfile1);
for (size_t i = 0; i < _countof(additionals); ++i)
{
DoEntry(&additionals[i]);
}
TEST_ENTRY additionals2[] =
{
{ __LINE__, CO_E_APPNOTFOUND, FALSE, NULL, buf0, NULL },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, NULL, buf0, L"." },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, NULL, buf0, L"system32" },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, NULL, buf1, NULL },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, NULL, buf1, L"." },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, NULL, buf1, L"system32" },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, NULL, buf2, NULL },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, NULL, buf2, L"." },
{ __LINE__, CO_E_APPNOTFOUND, FALSE, NULL, buf2, L"system32" },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, NULL, buf0, NULL }, // FIXME
{ __LINE__, S_OK, TRUE, NULL, buf0, L"." },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, NULL, buf0, L"system32" }, // FIXME
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, NULL, buf1, NULL }, // FIXME
{ __LINE__, S_OK, TRUE, NULL, buf1, L"." },
{ __LINE__, S_OK, TRUE, NULL, buf1, L"system32" },
{ __LINE__, HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), TRUE, NULL, buf2, NULL }, // FIXME
{ __LINE__, S_OK, TRUE, NULL, buf2, L"." },
{ __LINE__, S_OK, TRUE, NULL, buf2, L"system32" },
};
wsprintfW(buf0, L"%hs", s_testfile2);
wsprintfW(buf1, L"\"%hs\"", s_testfile2);
wsprintfW(buf2, L"\"%hs\" \"Test File.txt\"", s_testfile2);
for (size_t i = 0; i < _countof(additionals2); ++i)
{
DoEntry(&additionals2[i]);
} }
// clean up // clean up
ok(DeleteFileA(s_testfile1), "failed to delete the test file\n"); ok(DeleteFileW(s_win_test_exe), "failed to delete the test file\n");
ok(DeleteFileA(s_testfile2), "failed to delete the test file\n"); ok(DeleteFileW(s_sys_bat_file), "failed to delete the test file\n");
CloseAppWindows(L"Notepad", FALSE); ok(DeleteFileA("Test File 1.txt"), "failed to delete the test file\n");
ok(DeleteFileA("Test File 2.bat"), "failed to delete the test file\n");
free(s_wi0.phwnd);
} }