Add pidl test

Francois Gouget fgouget at codeweavers.com
Mon Jan 19 06:43:38 CST 2004


Changelog:

  * dlls/shell32/tests/Makefile.in,
    dlls/shell32/tests/pidl.c

    Francois Gouget <fgouget at codeweavers.com>
    Add some simple pidl tests.

-- 
Francois Gouget
fgouget at codeweavers.com

-------------- next part --------------
Index: dlls/shell32/tests/Makefile.in
===================================================================
RCS file: /home/cvs/wine/dlls/shell32/tests/Makefile.in,v
retrieving revision 1.2
diff -u -r1.2 Makefile.in
--- dlls/shell32/tests/Makefile.in	12 Nov 2002 01:13:10 -0000	1.2
+++ dlls/shell32/tests/Makefile.in	19 Jan 2004 12:05:53 -0000
@@ -4,7 +4,8 @@
 
 CTESTS = \
 	generated.c \
+	pidl.c \
 	shlfileop.c
 
 @MAKE_TEST_RULES@
--- /dev/null	2003-12-28 23:49:02.000000000 +0100
+++ dlls/shell32/tests/pidl.c	2004-01-19 13:02:56.000000000 +0100
@@ -0,0 +1,169 @@
+/*
+ * Unit test of the pidl functionality.
+ *
+ * Copyright 2004 Francois Gouget for CodeWeavers
+ *
+ * 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 <assert.h>
+
+#define COBJMACROS
+#include <shlobj.h>
+#include "wine/test.h"
+
+inline static BOOL SHELL_OsIsUnicode(void)
+{
+    /* if high-bit of version is 0, the SHELL APIs are Unicode */
+    return !(GetVersion() & 0x80000000);
+}
+
+static LPMALLOC pMalloc;
+static HRESULT (WINAPI *pSHILCreateFromPath)(LPCWSTR,LPITEMIDLIST*,DWORD*);
+static HRESULT (WINAPI *pSHGetSpecialFolderPathA)(HWND,LPCSTR,int,BOOL);
+
+void test_SHILCreateFromPath()
+{
+    char buffer[MAX_PATH];
+    char path[MAX_PATH];
+    WCHAR wpath[MAX_PATH];
+
+    HANDLE hfile;
+
+    LPITEMIDLIST pidl;
+    DWORD attributes;
+    HRESULT hr;
+
+    if (pSHILCreateFromPath==NULL)
+        return;
+
+    /* Test non existent file */
+    pidl=NULL;
+    attributes=0;
+    GetCurrentDirectory(sizeof(path),path);
+    strcpy(path,"\\non-existent.file");
+    if (SHELL_OsIsUnicode())
+    {
+        MultiByteToWideChar(CP_ACP,0,path,-1,wpath,sizeof(wpath)/sizeof(*wpath));
+        hr=pSHILCreateFromPath(wpath,&pidl,&attributes);
+    }
+    else
+    {
+        hr=pSHILCreateFromPath((LPWSTR)path,&pidl,&attributes);
+    }
+    ok(!SUCCEEDED(hr),"got hr=%lx\n",hr);
+    ok(pidl==NULL && attributes==0,"pidl=%p attributes==%lx\n",pidl,attributes);
+
+    /* Test absolute path */
+    GetCurrentDirectory(sizeof(path),path);
+    strcat(path,"\\test.file");
+    hfile=CreateFile(path,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
+    assert(hfile!=INVALID_HANDLE_VALUE);
+    CloseHandle(hfile);
+    if (SHELL_OsIsUnicode())
+    {
+        MultiByteToWideChar(CP_ACP,0,path,-1,wpath,sizeof(wpath)/sizeof(*wpath));
+        hr=pSHILCreateFromPath(wpath,&pidl,&attributes);
+    }
+    else
+    {
+        hr=pSHILCreateFromPath((LPWSTR)path,&pidl,&attributes);
+    }
+    ok(SUCCEEDED(hr),"SHILCreateFromPath failed: %lx\n",hr);
+    if (SUCCEEDED(hr))
+    {
+        BOOL rc;
+        rc=SHGetPathFromIDListA(pidl,buffer);
+        ok(rc,"SHGetPathFromIDListA failed\n");
+        if (rc)
+        {
+            ok(lstrcmpiA(path,buffer)==0,
+               "SHGetPathFromIDListA returned '%s' instead of '%s'\n",
+               buffer,path);
+        }
+        IMalloc_Free(pMalloc,pidl);
+    }
+
+    /* Test relative path (fails) */
+    pidl=NULL;
+    attributes=0;
+    strcpy(path,"test.file");
+    if (SHELL_OsIsUnicode())
+    {
+        MultiByteToWideChar(CP_ACP,0,path,-1,wpath,sizeof(wpath)/sizeof(*wpath));
+        hr=pSHILCreateFromPath(wpath,&pidl,&attributes);
+    }
+    else
+    {
+        hr=pSHILCreateFromPath((LPWSTR)path,&pidl,&attributes);
+    }
+    ok(!SUCCEEDED(hr),"got hr=%lx\n",hr);
+    ok(pidl==NULL && attributes==0,"pidl=%p attributes==%lx\n",pidl,attributes);
+
+    /* Cleanup */
+    DeleteFile(path);
+}
+
+void test_SHGetFolderLocation()
+{
+    HRESULT hr;
+    char path[MAX_PATH];
+    char ref[MAX_PATH];
+    int len;
+
+    if (pSHGetSpecialFolderPathA==NULL)
+        return;
+
+    hr=pSHGetSpecialFolderPathA(NULL,path,CSIDL_WINDOWS,0);
+    ok(SUCCEEDED(hr),"SHGetSpecialFolderPath(CSIDL_WINDOWS) failed %lx\n",hr);
+    /* Win98 returns success and path==""! */
+    if (SUCCEEDED(hr) && *path!='\0')
+    {
+        len=GetWindowsDirectory(ref,sizeof(ref));
+        assert(len<sizeof(ref));
+        ok(lstrcmpiA(path,ref)==0, "got '%s' for CSIDL_WINDOWS instead of '%s'\n",
+           path,ref);
+    }
+
+    hr=pSHGetSpecialFolderPathA(NULL,path,CSIDL_SYSTEM,0);
+    ok(SUCCEEDED(hr),"SHGetSpecialFolderPath(CSIDL_WINDOWS) failed %lx\n",hr);
+    /* Win98 returns success and path==""! */
+    if (SUCCEEDED(hr) && *path!='\0')
+    {
+        len=GetSystemDirectory(ref,sizeof(ref));
+        assert(len<sizeof(ref));
+        ok(lstrcmpiA(path,ref)==0, "got '%s' for CSIDL_SYSTEM instead of '%s'\n",
+           path,ref);
+    }
+}
+
+START_TEST(pidl)
+{
+    HINSTANCE hdll;
+    HRESULT hr;
+
+    hdll=GetModuleHandle("shell32.dll");
+    pSHILCreateFromPath=(void*)GetProcAddress(hdll,(char*)28);
+    pSHGetSpecialFolderPathA=(void*)GetProcAddress(hdll,"SHGetSpecialFolderPathA");
+
+    hr=SHGetMalloc(&pMalloc);
+    ok(SUCCEEDED(hr) && (pMalloc!=NULL),
+       "SHGetMalloc failed: hr=%lx pMalloc=%p\n", hr, pMalloc);
+
+    test_SHILCreateFromPath();
+    test_SHGetFolderLocation();
+
+    IMalloc_Release(pMalloc);
+}


More information about the wine-patches mailing list