Commit 65b81beb authored by Francois Gouget's avatar Francois Gouget Committed by Alexandre Julliard

shell32/tests: Add FindExecutable() tests.

parent 2fa16067
......@@ -230,7 +230,7 @@ static void delete_test_association(const char* extension)
}
static void create_test_verb(const char* extension, const char* verb,
const char* cmdtail)
int rawcmd, const char* cmdtail)
{
HKEY hkey_shell, hkey_verb, hkey_cmd;
char shell[MAX_PATH];
......@@ -248,12 +248,19 @@ static void create_test_verb(const char* extension, const char* verb,
NULL, &hkey_cmd, NULL);
assert(rc==ERROR_SUCCESS);
cmd=malloc(strlen(argv0)+10+strlen(child_file)+2+strlen(cmdtail)+1);
sprintf(cmd,"%s shlexec \"%s\" %s", argv0, child_file, cmdtail);
rc=RegSetValueEx(hkey_cmd, NULL, 0, REG_SZ, (LPBYTE) cmd, strlen(cmd)+1);
assert(rc==ERROR_SUCCESS);
if (rawcmd)
{
rc=RegSetValueEx(hkey_cmd, NULL, 0, REG_SZ, (LPBYTE)cmdtail, strlen(cmdtail)+1);
}
else
{
cmd=malloc(strlen(argv0)+10+strlen(child_file)+2+strlen(cmdtail)+1);
sprintf(cmd,"%s shlexec \"%s\" %s", argv0, child_file, cmdtail);
rc=RegSetValueEx(hkey_cmd, NULL, 0, REG_SZ, (LPBYTE)cmd, strlen(cmd)+1);
assert(rc==ERROR_SUCCESS);
free(cmd);
}
free(cmd);
CloseHandle(hkey_shell);
CloseHandle(hkey_verb);
CloseHandle(hkey_cmd);
......@@ -470,6 +477,9 @@ static const char* testfiles[]=
"%s\\test file.shlexec.noassoc",
"%s\\test_shortcut_shlexec.lnk",
"%s\\test_shortcut_exe.lnk",
"%s\\test file.shl",
"%s\\test file.shlfoo",
"%s\\test file.sfe",
NULL
};
......@@ -484,28 +494,28 @@ typedef struct
static filename_tests_t filename_tests[]=
{
/* Test bad / nonexistent filenames */
{NULL, "%s\\nonexistent.shlexec", 0x1, ERROR_FILE_NOT_FOUND},
{NULL, "%s\\nonexistent.noassoc", 0x1, ERROR_FILE_NOT_FOUND},
{NULL, "%s\\nonexistent.shlexec", 0x11, SE_ERR_FNF},
{NULL, "%s\\nonexistent.noassoc", 0x11, SE_ERR_FNF},
/* Standard tests */
{NULL, "%s\\test file.shlexec", 0x0, 33},
{NULL, "%s\\test file.shlexec.", 0x0, 33},
{NULL, "%s\\%%nasty%% $file.shlexec", 0x0, 33},
{NULL, "%s/test file.shlexec", 0x0, 33},
{NULL, "%s\\test file.shlexec", 0x20, 33},
{NULL, "%s\\test file.shlexec.", 0x20, 33},
{NULL, "%s\\%%nasty%% $file.shlexec", 0x20, 33},
{NULL, "%s/test file.shlexec", 0x20, 33},
/* Test filenames with no association */
{NULL, "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC},
{NULL, "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC},
/* Test double extensions */
{NULL, "%s\\test file.noassoc.shlexec", 0x0, 33},
{NULL, "%s\\test file.noassoc.shlexec", 0x20, 33},
{NULL, "%s\\test file.shlexec.noassoc", 0x0, SE_ERR_NOASSOC},
/* Test alternate verbs */
{"LowerL", "%s\\nonexistent.shlexec", 0x1, ERROR_FILE_NOT_FOUND},
{"LowerL", "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC},
{"LowerL", "%s\\nonexistent.shlexec", 0x11, SE_ERR_FNF},
{"LowerL", "%s\\test file.noassoc", 0x0, SE_ERR_NOASSOC},
{"QuotedLowerL", "%s\\test file.shlexec", 0x0, 33},
{"QuotedUpperL", "%s\\test file.shlexec", 0x0, 33},
{"QuotedLowerL", "%s\\test file.shlexec", 0x20, 33},
{"QuotedUpperL", "%s\\test file.shlexec", 0x20, 33},
{NULL, NULL, 0}
};
......@@ -673,6 +683,110 @@ static void test_filename(void)
}
}
static void test_find_executable(void)
{
char filename[MAX_PATH];
char command[MAX_PATH];
const filename_tests_t* test;
int rc;
create_test_association(".sfe");
create_test_verb(".sfe", "Open", 1, "%1");
/* Don't test FindExecutable(..., NULL), it always crashes */
strcpy(command, "your word");
rc=(int)FindExecutableA(NULL, NULL, command);
ok(rc == SE_ERR_FNF || rc > 32, "FindExecutable(NULL) returned %d\n", rc);
ok(strcmp(command, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command);
strcpy(command, "your word");
rc=(int)FindExecutableA(tmpdir, NULL, command);
todo_wine ok(rc == SE_ERR_FNF || rc > 32, "FindExecutable(NULL) returned %d\n", rc);
ok(strcmp(command, "your word") != 0, "FindExecutable(NULL) returned command=[%s]\n", command);
sprintf(filename, "%s\\test file.sfe", tmpdir);
rc=(int)FindExecutableA(filename, NULL, command);
ok(rc > 32, "FindExecutable(%s) returned %d\n", filename, rc);
/* Depending on the platform, command could be '%1' or 'test file.sfe' */
rc=(int)FindExecutableA("test file.sfe", tmpdir, command);
ok(rc > 32, "FindExecutable(%s) returned %d\n", filename, rc);
rc=(int)FindExecutableA("test file.sfe", NULL, command);
todo_wine ok(rc == SE_ERR_FNF, "FindExecutable(%s) returned %d\n", filename, rc);
delete_test_association(".sfe");
create_test_association(".shl");
create_test_verb(".shl", "Open", 0, "Open");
sprintf(filename, "%s\\test file.shl", tmpdir);
rc=(int)FindExecutableA(filename, NULL, command);
ok(rc > 32, "FindExecutable(%s) returned %d\n", filename, rc);
sprintf(filename, "%s\\test file.shlfoo", tmpdir);
rc=(int)FindExecutableA(filename, NULL, command);
delete_test_association(".shl");
if (rc > 32)
{
/* On Windows XP and 2003 FindExecutable() is completely broken.
* Probably what it does is convert the filename to 8.3 format,
* which as a side effect converts the '.shlfoo' extension to '.shl',
* and then tries to find an association for '.shl'. This means it
* will normally fail on most extensions with more than 3 characters,
* like '.mpeg', etc.
* Also it means we cannot do any other test.
*/
trace("FindExecutable() is broken -> skipping 4+ character extension tests\n");
return;
}
test=filename_tests;
while (test->basename)
{
sprintf(filename, test->basename, tmpdir);
if (strchr(filename, '/'))
{
char* c;
c=filename;
while (*c)
{
if (*c=='\\')
*c='/';
c++;
}
}
rc=(int)FindExecutableA(filename, NULL, command);
if (rc > 32)
rc=33;
if ((test->todo & 0x10)==0)
{
ok(rc==test->rc, "FindExecutable(%s) failed: rc=%d\n", filename, rc);
}
else todo_wine
{
ok(rc==test->rc, "FindExecutable(%s) failed: rc=%d\n", filename, rc);
}
if (rc > 32)
{
if ((test->todo & 0x20)==0)
{
ok(strcmp(command, argv0) == 0, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
filename, command, argv0);
}
else todo_wine
{
ok(strcmp(command, argv0) == 0, "FindExecutable(%s) returned command='%s' instead of '%s'\n",
filename, command, argv0);
}
}
test++;
}
}
static filename_tests_t lnk_tests[]=
{
......@@ -939,12 +1053,12 @@ static void init_test(void)
/* Create a basic association suitable for most tests */
create_test_association(".shlexec");
create_test_verb(".shlexec", "Open", "Open \"%1\"");
create_test_verb(".shlexec", "NoQuotes", "NoQuotes %1");
create_test_verb(".shlexec", "LowerL", "LowerL %l");
create_test_verb(".shlexec", "QuotedLowerL", "QuotedLowerL \"%l\"");
create_test_verb(".shlexec", "UpperL", "UpperL %L");
create_test_verb(".shlexec", "QuotedUpperL", "QuotedUpperL \"%L\"");
create_test_verb(".shlexec", "Open", 0, "Open \"%1\"");
create_test_verb(".shlexec", "NoQuotes", 0, "NoQuotes %1");
create_test_verb(".shlexec", "LowerL", 0, "LowerL %l");
create_test_verb(".shlexec", "QuotedLowerL", 0, "QuotedLowerL \"%l\"");
create_test_verb(".shlexec", "UpperL", 0, "UpperL %L");
create_test_verb(".shlexec", "QuotedUpperL", 0, "QuotedUpperL \"%L\"");
}
static void cleanup_test(void)
......@@ -983,6 +1097,7 @@ START_TEST(shlexec)
init_test();
test_filename();
test_find_executable();
test_lnks();
test_exes();
test_exes_long();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment