2 * Unit tests for shell32 string operations
4 * Copyright 2004 Jon Griffiths
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define WINE_NOWINSOCK
32 #include "wine/test.h"
34 static HMODULE hShell32;
35 static HRESULT (WINAPI *pStrRetToStrNAW)(LPVOID,DWORD,LPSTRRET,const ITEMIDLIST *);
37 static WCHAR *CoDupStrW(const char* src)
39 INT len = MultiByteToWideChar(CP_ACP, 0, src, -1, NULL, 0);
40 WCHAR* szTemp = (WCHAR*)CoTaskMemAlloc(len * sizeof(WCHAR));
41 MultiByteToWideChar(CP_ACP, 0, src, -1, szTemp, len);
45 static inline int strcmpW(const WCHAR *str1, const WCHAR *str2)
47 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
51 static void test_StrRetToStringNA(void)
53 trace("StrRetToStringNAW is Ascii\n");
57 static void test_StrRetToStringNW(void)
59 static const WCHAR szTestW[] = { 'T','e','s','t','\0' };
65 trace("StrRetToStringNAW is Unicode\n");
67 strret.uType = STRRET_WSTR;
68 U(strret).pOleStr = CoDupStrW("Test");
69 memset(buff, 0xff, sizeof(buff));
70 ret = pStrRetToStrNAW(buff, sizeof(buff)/sizeof(WCHAR), &strret, NULL);
71 ok(ret == TRUE && !strcmpW(buff, szTestW),
72 "STRRET_WSTR: dup failed, ret=%d\n", ret);
74 strret.uType = STRRET_CSTR;
75 lstrcpyA(U(strret).cStr, "Test");
76 memset(buff, 0xff, sizeof(buff));
77 ret = pStrRetToStrNAW(buff, sizeof(buff)/sizeof(WCHAR), &strret, NULL);
78 ok(ret == TRUE && !strcmpW(buff, szTestW),
79 "STRRET_CSTR: dup failed, ret=%d\n", ret);
81 strret.uType = STRRET_OFFSET;
82 U(strret).uOffset = 1;
83 strcpy((char*)&iidl, " Test");
84 memset(buff, 0xff, sizeof(buff));
85 ret = pStrRetToStrNAW(buff, sizeof(buff)/sizeof(WCHAR), &strret, iidl);
86 ok(ret == TRUE && !strcmpW(buff, szTestW),
87 "STRRET_OFFSET: dup failed, ret=%d\n", ret);
89 /* The next test crashes on W2K, WinXP and W2K3, so we don't test. */
91 /* Invalid dest - should return FALSE, except NT4 does not, so we don't check. */
92 strret.uType = STRRET_WSTR;
93 U(strret).pOleStr = CoDupStrW("Test");
94 pStrRetToStrNAW(NULL, sizeof(buff)/sizeof(WCHAR), &strret, NULL);
95 trace("NULL dest: ret=%d\n", ret);
103 hShell32 = GetModuleHandleA("shell32.dll");
105 pStrRetToStrNAW = (void*)GetProcAddress(hShell32, (LPSTR)96);
108 if (!(GetVersion() & 0x80000000))
109 test_StrRetToStringNW();
111 test_StrRetToStringNA();