Zac Brown wrote: > Add tests for SHGetNewLinkInfo[AW] > > Tests pass on Windows 2000, Windows XP and Windows Server 2003. > > Changes: > * Add initial tests for SHGetNewLinkInfo[AW] to shell32/tests/shellord.c > * Add shell32/tests/shellord.c > * Update shell32/tests/Makefile.in > > > ------------------------------------------------------------------------ > > --- > dlls/shell32/tests/Makefile.in | 1 + > dlls/shell32/tests/shellord.c | 379 > ++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 380 insertions(+), 0 deletions(-) > create mode 100644 dlls/shell32/tests/shellord.c > > diff --git a/dlls/shell32/tests/Makefile.in b/dlls/shell32/tests/Makefile.in > index 088499f..316dd72 100644 > --- a/dlls/shell32/tests/Makefile.in > +++ b/dlls/shell32/tests/Makefile.in > @@ -8,6 +8,7 @@ IMPORTS = uuid shell32 ole32 oleaut32 user32 advapi32 > kernel32 > CTESTS = \ > generated.c \ > shelllink.c \ > + shellord.c \ > shellpath.c \ > shfldr_special.c \ > shlexec.c \ > diff --git a/dlls/shell32/tests/shellord.c b/dlls/shell32/tests/shellord.c > new file mode 100644 > index 0000000..f5ae1bd > --- /dev/null > +++ b/dlls/shell32/tests/shellord.c > @@ -0,0 +1,379 @@ > +/* > + * Unit tests for shellord.c > + * > + * Copyright 2008 Google (Zac Brown) > + * > + * 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 > + * > + */ > + > +#define COBJMACROS > + > +#include <stdio.h> > + > +#include <windows.h> > +#include "shlguid.h" > +#include "shobjidl.h" > +#include "shlobj.h" > +#include "wine/test.h" > + > +#include "shell32_test.h" > + > +static BOOL (WINAPI *pSHGetNewLinkInfoA) (LPCSTR pszLinkTo, > + LPCSTR pszDir, > + LPSTR pszName, > + BOOL *pfMustCopy, > + UINT uFlags); > +static LPITEMIDLIST (WINAPI *pSHSimpleIDListFromPath) (LPCSTR lpszPath); > + > +typedef struct > +{ > + UINT flags; > + const char* expected_str_1; > + const char* expected_str_2; > + const char* expected_str_3; > + BOOL use_full_path; > + BOOL todo_str_check; > + BOOL skip_crash; > +} getlink_test_t, *lp_getlink_test_t; > + > + > +static const getlink_test_t getlink_tests[] = { > + { > + 0, > + "testfile.lnk", > + "testfile.lnk", > + "testfile.txt.lnk", > + TRUE, > + TRUE, > + FALSE > + }, > + { > + SHGNLI_PIDL, > + "testfile.lnk", > + "testfile.lnk", > + "testfile.txt.lnk", > + TRUE, > + TRUE, > + FALSE > + }, > + { > + SHGNLI_NOUNIQUE, > + "testfile.lnk", > + "testfile.lnk", > + "testfile.txt.lnk", > + FALSE, > + TRUE, > + FALSE > + }, > + { > + SHGNLI_PREFIXNAME, > + "Shortcut to testfile.lnk", > + "Shortcut to testfile.lnk", > + "Shortcut to testfile.txt.lnk", > + TRUE, > + TRUE, > + TRUE > + }, > + { > + SHGNLI_NOLNK, > + "testfile", > + "testfile.lnk", > + "testfile.txt (2)", > + TRUE, > + TRUE, > + FALSE > + }, > + { > + SHGNLI_PIDL | SHGNLI_NOUNIQUE, > + "testfile.lnk", > + "testfile.lnk", > + "testfile.txt.lnk", > + FALSE, > + TRUE, > + FALSE > + }, > + { > + SHGNLI_PIDL | SHGNLI_PREFIXNAME, > + "Shortcut to testfile.lnk", > + "Shortcut to testfile.lnk", > + "Shortcut to testfile.txt.lnk", > + TRUE, > + TRUE, > + TRUE > + }, > + { > + SHGNLI_PIDL | SHGNLI_NOLNK, > + "testfile", > + "testfile.lnk", > + "testfile.txt (2)", > + TRUE, > + TRUE, > + TRUE > + }, > + { > + SHGNLI_NOUNIQUE | SHGNLI_PREFIXNAME, > + "Shortcut () to testfile.lnk", > + "Shortcut () to testfile.lnk", > + "Shortcut () to testfile.txt.lnk", > + FALSE, > + TRUE, > + FALSE > + }, > + { > + SHGNLI_NOUNIQUE | SHGNLI_NOLNK, > + "testfile", > + "testfile.lnk", > + "testfile.txt", > + FALSE, > + TRUE, > + FALSE > + }, > + { > + SHGNLI_PREFIXNAME | SHGNLI_NOLNK, > + "Shortcut to testfile", > + "Shortcut to testfile.lnk", > + "Shortcut to testfile.txt", > + TRUE, > + TRUE, > + TRUE > + }, > + { > + SHGNLI_PIDL | SHGNLI_NOUNIQUE | SHGNLI_PREFIXNAME, > + "Shortcut () to testfile.lnk", > + "Shortcut () to testfile.lnk", > + "Shortcut () to testfile.txt.lnk", > + FALSE, > + TRUE, > + FALSE > + }, > + { > + SHGNLI_PIDL | SHGNLI_PREFIXNAME | SHGNLI_NOLNK, > + "Shortcut to testfile", > + "Shortcut to testfile.lnk", > + "Shortcut to testfile.txt", > + TRUE, > + TRUE, > + TRUE > + }, > + { > + SHGNLI_NOUNIQUE | SHGNLI_PREFIXNAME | SHGNLI_NOLNK, > + "Shortcut () to testfile", > + "Shortcut () to testfile.lnk", > + "Shortcut () to testfile.txt", > + FALSE, > + TRUE, > + FALSE > + }, > + { > + SHGNLI_PIDL | SHGNLI_NOUNIQUE | SHGNLI_PREFIXNAME | SHGNLI_NOLNK, > + "Shortcut () to testfile", > + "Shortcut () to testfile.lnk", > + "Shortcut () to testfile.txt", > + FALSE, > + TRUE, > + FALSE > + } > +}; > + > +static void test_SHGetNewLinkInfo (void) > +{ > + FILE *testfile_handle; > + LPCSTR testfile_name = "testfile.txt"; > + LPSTR shortcut_pidl, shortcut_ptr; > + CHAR shortcut_target[MAX_PATH]; > + CHAR shortcut_dir[MAX_PATH]; > + CHAR shortcut_name[MAX_PATH]; > + WCHAR shortcut_targetW[MAX_PATH]; > + UINT flags; > + BOOL ret; > + unsigned int index; > + BOOL pfMustCopy; > + > + lp_getlink_test_t test_ptr; > + CHAR tmp_buf1[MAX_PATH]; > + CHAR tmp_buf2[MAX_PATH]; > + CHAR tmp_buf3[MAX_PATH]; > + > + testfile_handle = fopen (testfile_name, "w"); > + if (!testfile_handle || !GetCurrentDirectory (sizeof(shortcut_dir), > shortcut_dir) || > + !GetFullPathName (testfile_name, sizeof(shortcut_target), > shortcut_target, NULL)) > + { > + skip ("Failed to create a test file or get the current working > directory.\n"); > + goto cleanup; > + } > + ok (fclose(testfile_handle) == 0, "Could not close testfile.txt.\n"); > + > + MultiByteToWideChar(CP_ACP, 0, shortcut_target, -1, shortcut_targetW, > MAX_PATH); > + > + /* Get the PIDL of the path */ > + shortcut_pidl = (LPSTR)pSHSimpleIDListFromPath > ((LPCVOID)shortcut_targetW); > + ok (shortcut_pidl != NULL, "SHSimpleIDListFromPath failed.\n"); > + if (shortcut_pidl == NULL) > + goto cleanup; > + > + for (index = 0; index < sizeof(getlink_tests)/sizeof(getlink_tests[0]); > index++) > + { > + test_ptr = &getlink_tests[index]; > + flags = getlink_tests[index].flags; > + > + if (flags & SHGNLI_PIDL) > + shortcut_ptr = shortcut_pidl; > + else > + shortcut_ptr = shortcut_target; > + > + /* Test with all NULL/0 values except for pfMustCopy */ > + ret = SHGetNewLinkInfoA (NULL, NULL, NULL, &pfMustCopy, flags); > + ok (ret == FALSE, "Expected return value of FALSE.\n"); > + todo_wine ok(pfMustCopy == FALSE, "Expected pfMustCopy to be > FALSE.\n"); > + > + /* Test with valid target, NULL shortcut directory and name buffers > */ > + if (test_ptr->skip_crash == FALSE) > + { > + ret = SHGetNewLinkInfoA (shortcut_ptr, NULL, NULL, &pfMustCopy, > flags); > + ok (ret == FALSE, "Expected return value of FALSE.\n"); > + todo_wine ok (pfMustCopy == FALSE, "Expected pfMustCopy to be > FALSE.\n"); > + } > + > + /* Test with valid shortcut directory, NULL target and name buffers > */ > + ret = SHGetNewLinkInfoA (NULL, shortcut_dir, NULL, &pfMustCopy, > flags); > + ok (ret == FALSE, "Expected return value of FALSE.\n"); > + todo_wine ok (pfMustCopy == FALSE, "Expected pfMustCopy to be > FALSE.\n"); > + > + /* Test with valid shortcut name and NULL target, shortcut directory > buffers */ > + ret = SHGetNewLinkInfoA (NULL, NULL, shortcut_name, &pfMustCopy, > flags); > + ok (ret == FALSE, "Expected return value of FALSE.\n"); > + todo_wine ok (pfMustCopy == FALSE, "Expected pfMustCopy to be > FALSE.\n"); > + > + /* Test with valid shortcut directory and name, NULL shortcut target > buffer */ > + ret = SHGetNewLinkInfoA (NULL, shortcut_dir, shortcut_name, > &pfMustCopy, flags); > + ok (ret == FALSE, "Expected return value of FALSE.\n"); > + todo_wine ok (pfMustCopy == FALSE, "Expected pfMustCopy to be > FALSE.\n"); > + > + /* Test with valid shortcut target and name, NULL shortcut directory > buffer */ > + if (test_ptr->skip_crash == FALSE) > + { > + memset (shortcut_name, 0, MAX_PATH); > + ret = SHGetNewLinkInfoA (shortcut_ptr, NULL, shortcut_name, > &pfMustCopy, flags); > + todo_wine > + { > + ok (ret == TRUE, "Expected return value of TRUE.\n"); > + ok (pfMustCopy == FALSE, "Expected pfMustCopy to be > FALSE.\n"); > + } > + > + lstrcpyA (tmp_buf1, test_ptr->expected_str_1); > + lstrcpyA (tmp_buf2, test_ptr->expected_str_2); > + lstrcpyA (tmp_buf3, test_ptr->expected_str_3); > + > + if (test_ptr->todo_str_check) > + { > + todo_wine > + ok (lstrcmpA (shortcut_name, tmp_buf1) == 0 || > + lstrcmpA (shortcut_name, tmp_buf2) == 0 || > + lstrcmpA (shortcut_name, tmp_buf3) == 0, > + "Returned shortcut did not match expected, got: > %s\n", > + shortcut_name); > + } > + else > + { > + ok (lstrcmpA (shortcut_name, tmp_buf1) == 0 || > + lstrcmpA (shortcut_name, tmp_buf2) == 0 || > + lstrcmpA (shortcut_name, tmp_buf3) == 0, > + "Returned shortcut did not match expected, got: %s\n", > + shortcut_name); > + } > + } > + > + /* Test with valid shortcut directory, target, name buffers */ > + memset (shortcut_name, 0, MAX_PATH); > + ret = SHGetNewLinkInfoA (shortcut_ptr, shortcut_dir, shortcut_name, > &pfMustCopy, flags); > + todo_wine > + { > + ok (ret == TRUE, "Expected return value of TRUE.\n"); > + ok (pfMustCopy == FALSE, "Expected pfMustCopy to be FALSE.\n"); > + } > + > + if (test_ptr->use_full_path == TRUE && shortcut_dir != NULL) > + { > + lstrcpyA (tmp_buf1, shortcut_dir); > + lstrcatA (tmp_buf1, "\\"); > + lstrcpyA (tmp_buf2, tmp_buf1); > + lstrcpyA (tmp_buf3, tmp_buf1); > + > + lstrcatA (tmp_buf1, test_ptr->expected_str_1); > + lstrcatA (tmp_buf2, test_ptr->expected_str_2); > + lstrcatA (tmp_buf3, test_ptr->expected_str_3); > + } > + else > + { > + lstrcpyA (tmp_buf1, test_ptr->expected_str_1); > + lstrcpyA (tmp_buf2, test_ptr->expected_str_2); > + lstrcpyA (tmp_buf3, test_ptr->expected_str_3); > + } > + > + if (test_ptr->todo_str_check) > + { > + todo_wine > + ok (lstrcmpA (shortcut_name, tmp_buf1) == 0 || > + lstrcmpA (shortcut_name, tmp_buf2) == 0 || > + lstrcmpA (shortcut_name, tmp_buf3) == 0, > + "Returned shortcut did not match expected, got: %s\n", > + shortcut_name); > + } > + else > + { > + ok (lstrcmpA (shortcut_name, tmp_buf1) == 0 || > + lstrcmpA (shortcut_name, tmp_buf2) == 0 || > + lstrcmpA (shortcut_name, tmp_buf3) == 0, > + "Returned shortcut did not match expected, got: %s\n", > + shortcut_name); > + } > + } > + > + cleanup: > + ret = DeleteFileA (shortcut_target); > + ok (ret == TRUE, "Failed to delete %s\n", shortcut_target); > +} > + > + > +START_TEST(shellord) > +{ > + HRESULT r; > + HMODULE hmod = GetModuleHandleA("shell32.dll"); > + > + pSHGetNewLinkInfoA = (void *) GetProcAddress(hmod, (LPSTR)179); > + pSHSimpleIDListFromPath = (void *) GetProcAddress(hmod, (LPSTR)162); > + > + if (!pSHSimpleIDListFromPath) > + { > + skip("Unable to get process address for SHSimpleIDListFromPath.\n"); > + return; > + } > + if (!pSHGetNewLinkInfoA) > + { > + skip("Unable to get process address for SHGetNewLinkInfoA.\n"); > + return; > + } > + > + > + r = CoInitialize(NULL); > + ok (SUCCEEDED(r), "CoInitialize failed (0x%08x)\n", r); > + if (!SUCCEEDED(r)) > + return; > + > + test_SHGetNewLinkInfo(); > + > + CoUninitialize(); > +} > > > ------------------------------------------------------------------------ > >
Ignore this patch, will resend a fixed one later.