ReactOS 0.4.15-dev-7924-g5949c20
string.c
Go to the documentation of this file.
1/*
2 * Unit tests for shell32 string operations
3 *
4 * Copyright 2004 Jon Griffiths
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include <stdarg.h>
22#include <stdio.h>
23
24#define WINE_NOWINSOCK
25#include "windef.h"
26#include "winbase.h"
27#include "wtypes.h"
28#include "shellapi.h"
29#include "shtypes.h"
30#include "objbase.h"
31
32#include "wine/test.h"
33
35static BOOL (WINAPI *pStrRetToStrNAW)(LPVOID,DWORD,LPSTRRET,const ITEMIDLIST *);
36
37static WCHAR *CoDupStrW(const char* src)
38{
40 WCHAR* szTemp = CoTaskMemAlloc(len * sizeof(WCHAR));
41 MultiByteToWideChar(CP_ACP, 0, src, -1, szTemp, len);
42 return szTemp;
43}
44
45static inline int strcmpW(const WCHAR *str1, const WCHAR *str2)
46{
47 while (*str1 && (*str1 == *str2)) { str1++; str2++; }
48 return *str1 - *str2;
49}
50
51static void test_StrRetToStringNA(void)
52{
53 trace("StrRetToStringNAW is Ascii\n");
54 /* FIXME */
55}
56
57static void test_StrRetToStringNW(void)
58{
59 static const WCHAR szTestW[] = { 'T','e','s','t','\0' };
60 ITEMIDLIST iidl[10];
61 WCHAR buff[128];
62 STRRET strret;
63 BOOL ret;
64
65 trace("StrRetToStringNAW is Unicode\n");
66
67 strret.uType = STRRET_WSTR;
68 U(strret).pOleStr = CoDupStrW("Test");
69 memset(buff, 0xff, sizeof(buff));
70 ret = pStrRetToStrNAW(buff, ARRAY_SIZE(buff), &strret, NULL);
71 ok(ret == TRUE && !strcmpW(buff, szTestW),
72 "STRRET_WSTR: dup failed, ret=%d\n", ret);
73
74 strret.uType = STRRET_CSTR;
75 lstrcpyA(U(strret).cStr, "Test");
76 memset(buff, 0xff, sizeof(buff));
77 ret = pStrRetToStrNAW(buff, ARRAY_SIZE(buff), &strret, NULL);
78 ok(ret == TRUE && !strcmpW(buff, szTestW),
79 "STRRET_CSTR: dup failed, ret=%d\n", ret);
80
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, ARRAY_SIZE(buff), &strret, iidl);
86 ok(ret == TRUE && !strcmpW(buff, szTestW),
87 "STRRET_OFFSET: dup failed, ret=%d\n", ret);
88
89 /* The next test crashes on W2K, WinXP and W2K3, so we don't test. */
90if (0)
91{
92 /* Invalid dest - should return FALSE, except NT4 does not, so we don't check. */
93 strret.uType = STRRET_WSTR;
94 U(strret).pOleStr = CoDupStrW("Test");
95 pStrRetToStrNAW(NULL, ARRAY_SIZE(buff), &strret, NULL);
96 trace("NULL dest: ret=%d\n", ret);
97}
98}
99
101{
102 CoInitialize(0);
103
104 hShell32 = GetModuleHandleA("shell32.dll");
105
106 pStrRetToStrNAW = (void*)GetProcAddress(hShell32, (LPSTR)96);
107 if (pStrRetToStrNAW)
108 {
109 if (!(GetVersion() & 0x80000000))
111 else
113 }
114
116}
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define ARRAY_SIZE(A)
Definition: main.h:33
#define U(x)
Definition: wordpad.c:45
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define CP_ACP
Definition: compat.h:109
#define GetProcAddress(x, y)
Definition: compat.h:753
#define MultiByteToWideChar
Definition: compat.h:110
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
static unsigned char buff[32768]
Definition: fatten.c:17
unsigned int BOOL
Definition: ntddk_ex.h:94
GLenum src
Definition: glext.h:6340
GLenum GLsizei len
Definition: glext.h:6722
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:426
LPSTR WINAPI lstrcpyA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:100
static const ITEMIDLIST *static WCHAR * CoDupStrW(const char *src)
Definition: string.c:37
static DWORD
Definition: string.c:35
static LPSTRRET
Definition: string.c:35
static void test_StrRetToStringNW(void)
Definition: string.c:57
static void test_StrRetToStringNA(void)
Definition: string.c:51
static HMODULE hShell32
Definition: string.c:34
#define BOOL
Definition: nt_native.h:43
#define LPVOID
Definition: nt_native.h:45
#define strcmpW(s1, s2)
Definition: unicode.h:38
DWORD WINAPI GetVersion()
Definition: redirtest.c:5
#define memset(x, y, z)
Definition: compat.h:39
@ STRRET_CSTR
Definition: shtypes.idl:87
@ STRRET_OFFSET
Definition: shtypes.idl:86
@ STRRET_WSTR
Definition: shtypes.idl:85
UINT uType
Definition: shtypes.idl:93
int32_t INT
Definition: typedefs.h:58
int ret
#define WINAPI
Definition: msvc.h:6
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180