IShellFolder::CompareIDs partially undocumented take 2

Vitaliy Margolen wine-patch at kievinfo.com
Sat Sep 4 22:48:41 CDT 2004


Since my previous patch wasn't excepted here it is again. This time with more fixes
and tests.
Also it _is_ documented that CompareIDs returns result in lower 16 bits. And this function
returns only -1/0/1 as a result.

Vitaliy Margolen

changelog:
  dlls/shell32/shlfolder.c
    IShellFolder::CompareIDs - return only -1/0/1 in lower 16 bit.
-------------- next part --------------
Index: dlls/shell32/shlfolder.c
===================================================================
RCS file: /home/wine/wine/dlls/shell32/shlfolder.c,v
retrieving revision 1.88
diff -u -r1.88 shlfolder.c
--- dlls/shell32/shlfolder.c	15 Apr 2004 04:55:54 -0000	1.88
+++ dlls/shell32/shlfolder.c	5 Sep 2004 03:34:17 -0000
@@ -429,24 +429,30 @@
     BOOL isEmpty2 = _ILIsDesktop (pidl2);
 
     if (isEmpty1 && isEmpty2)
-	return 0;
+	return (WORD)0;
     if (isEmpty1)
-	return -1;
+	return (WORD)-1;
     if (isEmpty2)
-	return 1;
+	return (WORD)0;
 
     /* test for different types. Sort order is the PT_* constant */
     type1 = _ILGetDataPointer (pidl1)->type;
     type2 = _ILGetDataPointer (pidl2)->type;
-    if (type1 != type2)
-	return (type1 - type2);
+    if (type1 < type2) {
+	return (WORD)-1;
+    } else if (type1 > type2) {
+	return (WORD)1;
+    }
 
     /* test for name of pidl */
     _ILSimpleGetText (pidl1, szTemp1, MAX_PATH);
     _ILSimpleGetText (pidl2, szTemp2, MAX_PATH);
     nReturn = strcasecmp (szTemp1, szTemp2);
-    if (nReturn != 0)
-	return nReturn;
+    if (nReturn < 0) {
+	return (WORD)-1;
+    } else if (nReturn > 0) {
+	return (WORD)1;
+    }
 
     /* test of complex pidls */
     firstpidl = ILCloneFirst (pidl1);
@@ -459,11 +465,11 @@
     isEmpty2 = _ILIsDesktop (nextpidl2);
 
     if (isEmpty1 && isEmpty2) {
-	nReturn = 0;
+	nReturn = (WORD)0;
     } else if (isEmpty1) {
-	nReturn = -1;
+	nReturn = (WORD)-1;
     } else if (isEmpty2) {
-    	nReturn = 1;
+    	nReturn = (WORD)1;
     /* optimizing end */
     } else if (SUCCEEDED (IShellFolder_BindToObject (iface, firstpidl, NULL, &IID_IShellFolder, (LPVOID *) & psf))) {
 	nReturn = IShellFolder_CompareIDs (psf, lParam, nextpidl1, nextpidl2);
Index: dlls/shell32/tests/Makefile.in
===================================================================
RCS file: /home/wine/wine/dlls/shell32/tests/Makefile.in,v
retrieving revision 1.3
diff -u -r1.3 Makefile.in
--- dlls/shell32/tests/Makefile.in	10 Feb 2004 02:19:03 -0000	1.3
+++ dlls/shell32/tests/Makefile.in	5 Sep 2004 03:34:17 -0000
@@ -4,11 +4,13 @@
 VPATH     = @srcdir@
 TESTDLL   = shell32.dll
 IMPORTS   = shell32 ole32
+EXTRALIBS = -ldxguid -luuid
 
 CTESTS = \
 	generated.c \
 	shlfileop.c \
-	string.c
+	string.c \
+	ishellfolder.c
 
 @MAKE_TEST_RULES@
 
--- /dev/null	2003-12-16 03:57:18.000000000 -0700
+++ dlls/shell32/tests/ishellfolder.c	2004-09-04 21:29:33.000000000 -0600
@@ -0,0 +1,151 @@
+/*
+ * Unit test of the IShellFolder functions.
+ *
+ * Copyright 2004 Vitaliy Margolen
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "windef.h"
+#include "winbase.h"
+#include "wtypes.h"
+#include "shellapi.h"
+
+
+#include "shlguid.h"
+#include "shlobj.h"
+#include "shobjidl.h"
+
+
+#include "wine/unicode.h"
+#include "wine/test.h"
+#include "wine/debug.h"
+
+
+IMalloc *ppM;
+
+/* creates a file with the specified name for tests */
+void CreateTestFile(CHAR *name)
+{
+    HANDLE file;
+    DWORD written;
+
+    file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
+    if (file != INVALID_HANDLE_VALUE)
+    {
+	WriteFile(file, name, strlen(name), &written, NULL);
+	WriteFile(file, "\n", strlen("\n"), &written, NULL);
+	CloseHandle(file);
+    }
+}
+
+
+/* initializes the tests */
+void CreateFilesFolders(void)
+{
+    CreateDirectoryA(".\\testdir", NULL);
+    CreateDirectoryA(".\\testdir\\test.txt", NULL);
+    CreateTestFile  (".\\testdir\\test1.txt ");
+    CreateTestFile  (".\\testdir\\test2.txt ");
+    CreateTestFile  (".\\testdir\\test3.txt ");
+    CreateDirectoryA(".\\testdir\\testdir2 ", NULL);
+}
+
+/* cleans after tests */
+void Cleanup(void)
+{
+    DeleteFileA(".\\testdir\\test1.txt");
+    DeleteFileA(".\\testdir\\test2.txt");
+    DeleteFileA(".\\testdir\\test3.txt");
+    RemoveDirectoryA(".\\testdir\\test.txt");
+    RemoveDirectoryA(".\\testdir\\testdir2");
+    RemoveDirectoryA(".\\testdir");
+}
+
+
+/* perform test */
+void test_EnumObjects(IShellFolder *iFolder)
+{
+    IEnumIDList *iEnumList;
+    ITEMIDLIST *newPIDL, *(idlArr [5]);
+    ULONG NumPIDLs;
+    int i=0, j;
+    HRESULT nResult;
+
+    static const WORD iResults [5][5] =
+    {
+	{ 0,-1,-1,-1,-1},
+	{ 1, 0,-1,-1, 1},
+	{ 1, 1, 0,-1, 1},
+	{ 1, 1, 1, 0, 1},
+	{ 1,-1,-1,-1, 0}
+    };
+
+    if SUCCEEDED(IShellFolder_EnumObjects(iFolder, NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList))
+    {
+	while (IEnumIDList_Next(iEnumList, 1, &newPIDL, &NumPIDLs) == S_OK)
+	{
+	    idlArr[i++] = newPIDL;
+	}
+	/* This fails on windows */
+	/* IEnumIDList_Release(iEnumList); */
+    
+	for (i=0;i<5;i++) for (j=0;j<5;j++)
+	{
+	    nResult = IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]);
+	    ok(nResult == iResults[i][j], "Got %lx expected %x\n", nResult, iResults[i][j]);
+	}
+
+	for (i=0;i<5;i++)
+	    IMalloc_Free(ppM, idlArr[i]);
+    }
+}
+
+START_TEST(ishellfolder)
+{
+    ITEMIDLIST *newPIDL;
+    IShellFolder *IDesktopFolder, *testIShellFolder;
+    WCHAR cCurrDirW [MAX_PATH];
+    static const WCHAR cTestDirW[] = {'\\','t','e','s','t','d','i','r',0};
+
+    
+    GetCurrentDirectoryW(MAX_PATH, cCurrDirW);
+    strcatW(cCurrDirW, cTestDirW);
+
+    
+    if(!SUCCEEDED(SHGetMalloc(&ppM)))
+	return;
+
+    CreateFilesFolders();
+    SHGetDesktopFolder(&IDesktopFolder);
+
+    if (SUCCEEDED(IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0)))
+    {
+	if (SUCCEEDED(IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder)))
+	{
+	    test_EnumObjects(testIShellFolder);
+	    
+	    /* This fails on windows */
+	    /* IShellFolder_Release(newIShellFolder); */
+
+	    IMalloc_Free(ppM, newPIDL);
+	}
+    }
+
+    Cleanup();
+}


More information about the wine-patches mailing list