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
23 static HMODULE hShell32
;
24 static BOOL (WINAPI
*pStrRetToStrNAW
)(LPVOID
,DWORD
,LPSTRRET
,const ITEMIDLIST
*);
26 static WCHAR
*CoDupStrW(const char* src
)
28 INT len
= MultiByteToWideChar(CP_ACP
, 0, src
, -1, NULL
, 0);
29 WCHAR
* szTemp
= CoTaskMemAlloc(len
* sizeof(WCHAR
));
30 MultiByteToWideChar(CP_ACP
, 0, src
, -1, szTemp
, len
);
34 static inline int strcmpW(const WCHAR
*str1
, const WCHAR
*str2
)
36 while (*str1
&& (*str1
== *str2
)) { str1
++; str2
++; }
40 static void test_StrRetToStringNA(void)
42 trace("StrRetToStringNAW is Ascii\n");
46 static void test_StrRetToStringNW(void)
48 static const WCHAR szTestW
[] = { 'T','e','s','t','\0' };
54 trace("StrRetToStringNAW is Unicode\n");
56 strret
.uType
= STRRET_WSTR
;
57 U(strret
).pOleStr
= CoDupStrW("Test");
58 memset(buff
, 0xff, sizeof(buff
));
59 ret
= pStrRetToStrNAW(buff
, sizeof(buff
)/sizeof(WCHAR
), &strret
, NULL
);
60 ok(ret
== TRUE
&& !strcmpW(buff
, szTestW
),
61 "STRRET_WSTR: dup failed, ret=%d\n", ret
);
63 strret
.uType
= STRRET_CSTR
;
64 lstrcpyA(U(strret
).cStr
, "Test");
65 memset(buff
, 0xff, sizeof(buff
));
66 ret
= pStrRetToStrNAW(buff
, sizeof(buff
)/sizeof(WCHAR
), &strret
, NULL
);
67 ok(ret
== TRUE
&& !strcmpW(buff
, szTestW
),
68 "STRRET_CSTR: dup failed, ret=%d\n", ret
);
70 strret
.uType
= STRRET_OFFSET
;
71 U(strret
).uOffset
= 1;
72 strcpy((char*)&iidl
, " Test");
73 memset(buff
, 0xff, sizeof(buff
));
74 ret
= pStrRetToStrNAW(buff
, sizeof(buff
)/sizeof(WCHAR
), &strret
, iidl
);
75 ok(ret
== TRUE
&& !strcmpW(buff
, szTestW
),
76 "STRRET_OFFSET: dup failed, ret=%d\n", ret
);
78 /* The next test crashes on W2K, WinXP and W2K3, so we don't test. */
81 /* Invalid dest - should return FALSE, except NT4 does not, so we don't check. */
82 strret
.uType
= STRRET_WSTR
;
83 U(strret
).pOleStr
= CoDupStrW("Test");
84 pStrRetToStrNAW(NULL
, sizeof(buff
)/sizeof(WCHAR
), &strret
, NULL
);
85 trace("NULL dest: ret=%d\n", ret
);
93 hShell32
= GetModuleHandleA("shell32.dll");
95 pStrRetToStrNAW
= (void*)GetProcAddress(hShell32
, (LPSTR
)96);
98 if (!(GetVersion() & 0x80000000))
99 test_StrRetToStringNW();
101 test_StrRetToStringNA();