2 * Copyright 2010 Piotr Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/test.h"
25 /* basic_string<char, char_traits<char>, allocator<char>> */
26 #define BUF_SIZE_CHAR 16
27 typedef struct _basic_string_char
31 char buf
[BUF_SIZE_CHAR
];
38 /* basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>> */
39 #define BUF_SIZE_WCHAR 8
40 typedef struct _basic_string_wchar
44 wchar_t buf
[BUF_SIZE_WCHAR
];
51 static void* (__cdecl
*p_set_invalid_parameter_handler
)(void*);
52 static basic_string_char
* (__cdecl
*p_basic_string_char_concatenate
)(basic_string_char
*, const basic_string_char
*, const basic_string_char
*);
53 static basic_string_char
* (__cdecl
*p_basic_string_char_concatenate_cstr
)(basic_string_char
*, const basic_string_char
*, const char*);
57 #define __thiscall __stdcall
59 #define __thiscall __cdecl
62 static basic_string_char
* (__thiscall
*p_basic_string_char_ctor
)(basic_string_char
*);
63 static basic_string_char
* (__thiscall
*p_basic_string_char_copy_ctor
)(basic_string_char
*, basic_string_char
*);
64 static basic_string_char
* (__thiscall
*p_basic_string_char_ctor_cstr
)(basic_string_char
*, const char*);
65 static void (__thiscall
*p_basic_string_char_dtor
)(basic_string_char
*);
66 static basic_string_char
* (__thiscall
*p_basic_string_char_erase
)(basic_string_char
*, size_t, size_t);
67 static basic_string_char
* (__thiscall
*p_basic_string_char_assign_cstr_len
)(basic_string_char
*, const char*, size_t);
68 static const char* (__thiscall
*p_basic_string_char_cstr
)(basic_string_char
*);
69 static const char* (__thiscall
*p_basic_string_char_data
)(basic_string_char
*);
70 static size_t (__thiscall
*p_basic_string_char_size
)(basic_string_char
*);
71 static size_t (__thiscall
*p_basic_string_char_capacity
)(basic_string_char
*);
72 static void (__thiscall
*p_basic_string_char_swap
)(basic_string_char
*, basic_string_char
*);
73 static basic_string_char
* (__thiscall
*p_basic_string_char_append
)(basic_string_char
*, basic_string_char
*);
74 static basic_string_char
* (__thiscall
*p_basic_string_char_append_substr
)(basic_string_char
*, basic_string_char
*, size_t, size_t);
75 static int (__thiscall
*p_basic_string_char_compare_substr_substr
)(basic_string_char
*, size_t, size_t, basic_string_char
*, size_t, size_t);
76 static int (__thiscall
*p_basic_string_char_compare_substr_cstr_len
)(basic_string_char
*, size_t, size_t, const char*, size_t);
77 static size_t (__thiscall
*p_basic_string_char_find_cstr_substr
)(basic_string_char
*, const char*, size_t, size_t);
78 static size_t (__thiscall
*p_basic_string_char_rfind_cstr_substr
)(basic_string_char
*, const char*, size_t, size_t);
79 static basic_string_char
* (__thiscall
*p_basic_string_char_replace_cstr
)(basic_string_char
*, size_t, size_t, const char*);
81 static size_t *p_basic_string_char_npos
;
83 static basic_string_wchar
* (__thiscall
*p_basic_string_wchar_ctor
)(basic_string_wchar
*);
84 static basic_string_wchar
* (__thiscall
*p_basic_string_wchar_copy_ctor
)(basic_string_wchar
*, basic_string_wchar
*);
85 static basic_string_wchar
* (__thiscall
*p_basic_string_wchar_ctor_cstr
)(basic_string_wchar
*, const wchar_t*);
86 static void (__thiscall
*p_basic_string_wchar_dtor
)(basic_string_wchar
*);
87 static basic_string_wchar
* (__thiscall
*p_basic_string_wchar_erase
)(basic_string_wchar
*, size_t, size_t);
88 static basic_string_wchar
* (__thiscall
*p_basic_string_wchar_assign_cstr_len
)(basic_string_wchar
*, const wchar_t*, size_t);
89 static const wchar_t* (__thiscall
*p_basic_string_wchar_cstr
)(basic_string_wchar
*);
90 static const wchar_t* (__thiscall
*p_basic_string_wchar_data
)(basic_string_wchar
*);
91 static size_t (__thiscall
*p_basic_string_wchar_size
)(basic_string_wchar
*);
92 static size_t (__thiscall
*p_basic_string_wchar_capacity
)(basic_string_wchar
*);
93 static void (__thiscall
*p_basic_string_wchar_swap
)(basic_string_wchar
*, basic_string_wchar
*);
95 static int invalid_parameter
= 0;
96 static void __cdecl
test_invalid_parameter_handler(const wchar_t *expression
,
97 const wchar_t *function
, const wchar_t *file
,
98 unsigned line
, uintptr_t arg
)
100 ok(expression
== NULL
, "expression is not NULL\n");
101 ok(function
== NULL
, "function is not NULL\n");
102 ok(file
== NULL
, "file is not NULL\n");
103 ok(line
== 0, "line = %u\n", line
);
104 ok(arg
== 0, "arg = %lx\n", (UINT_PTR
)arg
);
108 /* Emulate a __thiscall */
111 #include "pshpack1.h"
112 struct thiscall_thunk
114 BYTE pop_eax
; /* popl %eax (ret addr) */
115 BYTE pop_edx
; /* popl %edx (func) */
116 BYTE pop_ecx
; /* popl %ecx (this) */
117 BYTE push_eax
; /* pushl %eax */
118 WORD jmp_edx
; /* jmp *%edx */
122 static void * (WINAPI
*call_thiscall_func1
)( void *func
, void *this );
123 static void * (WINAPI
*call_thiscall_func2
)( void *func
, void *this, const void *a
);
124 static void * (WINAPI
*call_thiscall_func3
)( void *func
, void *this, const void *a
, const void *b
);
125 static void * (WINAPI
*call_thiscall_func4
)( void *func
, void *this, const void *a
, const void *b
,
127 static void * (WINAPI
*call_thiscall_func5
)( void *func
, void *this, const void *a
, const void *b
,
128 const void *c
, const void *d
);
129 static void * (WINAPI
*call_thiscall_func6
)( void *func
, void *this, const void *a
, const void *b
,
130 const void *c
, const void *d
, const void *e
);
132 static void init_thiscall_thunk(void)
134 struct thiscall_thunk
*thunk
= VirtualAlloc( NULL
, sizeof(*thunk
),
135 MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
136 thunk
->pop_eax
= 0x58; /* popl %eax */
137 thunk
->pop_edx
= 0x5a; /* popl %edx */
138 thunk
->pop_ecx
= 0x59; /* popl %ecx */
139 thunk
->push_eax
= 0x50; /* pushl %eax */
140 thunk
->jmp_edx
= 0xe2ff; /* jmp *%edx */
141 call_thiscall_func1
= (void *)thunk
;
142 call_thiscall_func2
= (void *)thunk
;
143 call_thiscall_func3
= (void *)thunk
;
144 call_thiscall_func4
= (void *)thunk
;
145 call_thiscall_func5
= (void *)thunk
;
146 call_thiscall_func6
= (void *)thunk
;
149 #define call_func1(func,_this) call_thiscall_func1(func,_this)
150 #define call_func2(func,_this,a) call_thiscall_func2(func,_this,(const void*)a)
151 #define call_func3(func,_this,a,b) call_thiscall_func3(func,_this,(const void*)a,(const void*)b)
152 #define call_func4(func,_this,a,b,c) call_thiscall_func4(func,_this,(const void*)a,\
153 (const void*)b,(const void*)c)
154 #define call_func5(func,_this,a,b,c,d) call_thiscall_func5(func,_this,(const void*)a,\
155 (const void*)b,(const void*)c,(const void*)d)
156 #define call_func6(func,_this,a,b,c,d,e) call_thiscall_func6(func,_this,(const void*)a,\
157 (const void*)b,(const void*)c,(const void*)d,(const void*)e)
161 #define init_thiscall_thunk()
162 #define call_func1(func,_this) func(_this)
163 #define call_func2(func,_this,a) func(_this,a)
164 #define call_func3(func,_this,a,b) func(_this,a,b)
165 #define call_func4(func,_this,a,b,c) func(_this,a,b,c)
166 #define call_func5(func,_this,a,b,c,d) func(_this,a,b,c,d)
167 #define call_func6(func,_this,a,b,c,d,e) func(_this,a,b,c,d,e)
169 #endif /* __i386__ */
171 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
172 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
173 static BOOL
init(void)
175 HMODULE msvcr
= LoadLibraryA("msvcr90.dll");
176 HMODULE msvcp
= LoadLibraryA("msvcp90.dll");
177 if(!msvcr
|| !msvcp
) {
178 win_skip("msvcp90.dll or msvcrt90.dll not installed\n");
182 p_set_invalid_parameter_handler
= (void*)GetProcAddress(msvcr
, "_set_invalid_parameter_handler");
183 if(!p_set_invalid_parameter_handler
) {
184 win_skip("Error setting tests environment\n");
188 p_set_invalid_parameter_handler(test_invalid_parameter_handler
);
190 if(sizeof(void*) == 8) { /* 64-bit initialization */
191 SET(p_basic_string_char_ctor
,
192 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ");
193 SET(p_basic_string_char_copy_ctor
,
194 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@AEBV01@@Z");
195 SET(p_basic_string_char_ctor_cstr
,
196 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@PEBD@Z");
197 SET(p_basic_string_char_dtor
,
198 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ");
199 SET(p_basic_string_char_erase
,
200 "?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@_K0@Z");
201 SET(p_basic_string_char_assign_cstr_len
,
202 "?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@PEBD_K@Z");
203 SET(p_basic_string_char_cstr
,
204 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAPEBDXZ");
205 SET(p_basic_string_char_data
,
206 "?data@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAPEBDXZ");
207 SET(p_basic_string_char_size
,
208 "?size@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBA_KXZ");
209 SET(p_basic_string_char_capacity
,
210 "?capacity@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBA_KXZ");
211 SET(p_basic_string_char_swap
,
212 "?swap@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAXAEAV12@@Z");
213 SET(p_basic_string_char_append
,
214 "?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@AEBV12@@Z");
215 SET(p_basic_string_char_append_substr
,
216 "?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@AEBV12@_K1@Z");
217 SET(p_basic_string_char_compare_substr_substr
,
218 "?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAH_K0AEBV12@00@Z");
219 SET(p_basic_string_char_compare_substr_cstr_len
,
220 "?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAH_K0PEBD0@Z");
221 SET(p_basic_string_char_concatenate
,
222 "??$?HDU?$char_traits@D@std@@V?$allocator@D@1@@std@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@AEBV10@0@Z");
223 SET(p_basic_string_char_concatenate_cstr
,
224 "??$?HDU?$char_traits@D@std@@V?$allocator@D@1@@std@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@AEBV10@PEBD@Z");
225 SET(p_basic_string_char_find_cstr_substr
,
226 "?find@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBA_KPEBD_K1@Z");
227 SET(p_basic_string_char_rfind_cstr_substr
,
228 "?rfind@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBA_KPEBD_K1@Z");
229 SET(p_basic_string_char_replace_cstr
,
230 "?replace@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@_K0PEBD@Z");
231 SET(p_basic_string_char_npos
,
232 "?npos@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@2_KB");
234 SET(p_basic_string_wchar_ctor
,
235 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@XZ");
236 SET(p_basic_string_wchar_copy_ctor
,
237 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@AEBV01@@Z");
238 SET(p_basic_string_wchar_ctor_cstr
,
239 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@PEB_W@Z");
240 SET(p_basic_string_wchar_dtor
,
241 "??1?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@XZ");
242 SET(p_basic_string_wchar_erase
,
243 "?erase@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAAEAV12@_K0@Z");
244 SET(p_basic_string_wchar_assign_cstr_len
,
245 "?assign@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAAEAV12@PEB_W_K@Z");
246 SET(p_basic_string_wchar_cstr
,
247 "?c_str@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBAPEB_WXZ");
248 SET(p_basic_string_wchar_data
,
249 "?data@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBAPEB_WXZ");
250 SET(p_basic_string_wchar_size
,
251 "?size@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBA_KXZ");
252 SET(p_basic_string_wchar_capacity
,
253 "?capacity@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBA_KXZ");
254 SET(p_basic_string_wchar_swap
,
255 "?swap@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAXAEAV12@@Z");
257 SET(p_basic_string_char_ctor
,
258 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ");
259 SET(p_basic_string_char_copy_ctor
,
260 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z");
261 SET(p_basic_string_char_ctor_cstr
,
262 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z");
263 SET(p_basic_string_char_dtor
,
264 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ");
265 SET(p_basic_string_char_erase
,
266 "?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@II@Z");
267 SET(p_basic_string_char_assign_cstr_len
,
268 "?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@PBDI@Z");
269 SET(p_basic_string_char_cstr
,
270 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ");
271 SET(p_basic_string_char_data
,
272 "?data@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ");
273 SET(p_basic_string_char_size
,
274 "?size@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIXZ");
275 SET(p_basic_string_char_capacity
,
276 "?capacity@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIXZ");
277 SET(p_basic_string_char_swap
,
278 "?swap@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXAAV12@@Z");
279 SET(p_basic_string_char_append
,
280 "?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@ABV12@@Z");
281 SET(p_basic_string_char_append_substr
,
282 "?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@ABV12@II@Z");
283 SET(p_basic_string_char_compare_substr_substr
,
284 "?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEHIIABV12@II@Z");
285 SET(p_basic_string_char_compare_substr_cstr_len
,
286 "?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEHIIPBDI@Z");
287 SET(p_basic_string_char_concatenate
,
288 "??$?HDU?$char_traits@D@std@@V?$allocator@D@1@@std@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@ABV10@0@Z");
289 SET(p_basic_string_char_concatenate_cstr
,
290 "??$?HDU?$char_traits@D@std@@V?$allocator@D@1@@std@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@ABV10@PBD@Z");
291 SET(p_basic_string_char_find_cstr_substr
,
292 "?find@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIPBDII@Z");
293 SET(p_basic_string_char_rfind_cstr_substr
,
294 "?rfind@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIPBDII@Z");
295 SET(p_basic_string_char_replace_cstr
,
296 "?replace@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@IIPBD@Z");
297 SET(p_basic_string_char_npos
,
298 "?npos@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@2IB");
300 SET(p_basic_string_wchar_ctor
,
301 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@XZ");
302 SET(p_basic_string_wchar_copy_ctor
,
303 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@ABV01@@Z");
304 SET(p_basic_string_wchar_ctor_cstr
,
305 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@PB_W@Z");
306 SET(p_basic_string_wchar_dtor
,
307 "??1?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@XZ");
308 SET(p_basic_string_wchar_erase
,
309 "?erase@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEAAV12@II@Z");
310 SET(p_basic_string_wchar_assign_cstr_len
,
311 "?assign@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEAAV12@PB_WI@Z");
312 SET(p_basic_string_wchar_cstr
,
313 "?c_str@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEPB_WXZ");
314 SET(p_basic_string_wchar_data
,
315 "?data@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEPB_WXZ");
316 SET(p_basic_string_wchar_size
,
317 "?size@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEIXZ");
318 SET(p_basic_string_wchar_capacity
,
319 "?capacity@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEIXZ");
320 SET(p_basic_string_wchar_swap
,
321 "?swap@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEXAAV12@@Z");
324 init_thiscall_thunk();
328 static void test_basic_string_char(void) {
329 basic_string_char str1
, str2
, *pstr
;
331 size_t size
, capacity
;
333 call_func1(p_basic_string_char_ctor
, &str1
);
335 str
= call_func1(p_basic_string_char_cstr
, &str1
);
336 ok(str
!= NULL
, "str = NULL\n");
337 ok(*str
== '\0', "*str = %c\n", *str
);
338 str
= call_func1(p_basic_string_char_data
, &str1
);
339 ok(str
!= NULL
, "str = NULL\n");
340 ok(*str
== '\0', "*str = %c\n", *str
);
341 call_func1(p_basic_string_char_dtor
, &str1
);
343 pstr
= call_func2(p_basic_string_char_ctor_cstr
, &str1
, "test");
344 ok(pstr
== &str1
, "pstr != &str1\n");
345 str
= call_func1(p_basic_string_char_cstr
, &str1
);
346 ok(!memcmp(str
, "test", 5), "str = %s\n", str
);
347 str
= call_func1(p_basic_string_char_data
, &str1
);
348 ok(!memcmp(str
, "test", 5), "str = %s\n", str
);
349 size
= (size_t)call_func1(p_basic_string_char_size
, &str1
);
350 ok(size
== 4, "size = %lu\n", (unsigned long)size
);
351 capacity
= (size_t)call_func1(p_basic_string_char_capacity
, &str1
);
352 ok(capacity
>= size
, "capacity = %lu < size = %lu\n", (unsigned long)capacity
, (unsigned long)size
);
354 pstr
= call_func2(p_basic_string_char_copy_ctor
, &str2
, &str1
);
355 ok(pstr
== &str2
, "pstr != &str2\n");
356 str
= call_func1(p_basic_string_char_cstr
, &str2
);
357 ok(!memcmp(str
, "test", 5), "str = %s\n", str
);
358 str
= call_func1(p_basic_string_char_data
, &str2
);
359 ok(!memcmp(str
, "test", 5), "str = %s\n", str
);
361 call_func3(p_basic_string_char_erase
, &str2
, 1, 2);
362 str
= call_func1(p_basic_string_char_cstr
, &str2
);
363 ok(!memcmp(str
, "tt", 3), "str = %s\n", str
);
364 str
= call_func1(p_basic_string_char_data
, &str2
);
365 ok(!memcmp(str
, "tt", 3), "str = %s\n", str
);
366 size
= (size_t)call_func1(p_basic_string_char_size
, &str1
);
367 ok(size
== 4, "size = %lu\n", (unsigned long)size
);
368 capacity
= (size_t)call_func1(p_basic_string_char_capacity
, &str1
);
369 ok(capacity
>= size
, "capacity = %lu < size = %lu\n", (unsigned long)capacity
, (unsigned long)size
);
371 call_func3(p_basic_string_char_erase
, &str2
, 1, 100);
372 str
= call_func1(p_basic_string_char_cstr
, &str2
);
373 ok(!memcmp(str
, "t", 2), "str = %s\n", str
);
374 str
= call_func1(p_basic_string_char_data
, &str2
);
375 ok(!memcmp(str
, "t", 2), "str = %s\n", str
);
376 size
= (size_t)call_func1(p_basic_string_char_size
, &str1
);
377 ok(size
== 4, "size = %lu\n", (unsigned long)size
);
378 capacity
= (size_t)call_func1(p_basic_string_char_capacity
, &str1
);
379 ok(capacity
>= size
, "capacity = %lu < size = %lu\n", (unsigned long)capacity
, (unsigned long)size
);
381 call_func3(p_basic_string_char_assign_cstr_len
, &str2
, "test", 4);
382 str
= call_func1(p_basic_string_char_cstr
, &str2
);
383 ok(!memcmp(str
, "test", 5), "str = %s\n", str
);
384 str
= call_func1(p_basic_string_char_data
, &str2
);
385 ok(!memcmp(str
, "test", 5), "str = %s\n", str
);
387 call_func3(p_basic_string_char_assign_cstr_len
, &str2
, (str
+1), 2);
388 str
= call_func1(p_basic_string_char_cstr
, &str2
);
389 ok(!memcmp(str
, "es", 3), "str = %s\n", str
);
390 str
= call_func1(p_basic_string_char_data
, &str2
);
391 ok(!memcmp(str
, "es", 3), "str = %s\n", str
);
393 call_func1(p_basic_string_char_dtor
, &str1
);
394 call_func1(p_basic_string_char_dtor
, &str2
);
397 static void test_basic_string_char_swap(void) {
398 basic_string_char str1
, str2
;
399 char atmp1
[32], atmp2
[32];
401 /* Swap self, local */
402 strcpy(atmp1
, "qwerty");
403 call_func2(p_basic_string_char_ctor_cstr
, &str1
, atmp1
);
404 call_func2(p_basic_string_char_swap
, &str1
, &str1
);
405 ok(strcmp(atmp1
, (const char *) call_func1(p_basic_string_char_cstr
, &str1
)) == 0, "Invalid value of str1\n");
406 call_func2(p_basic_string_char_swap
, &str1
, &str1
);
407 ok(strcmp(atmp1
, (const char *) call_func1(p_basic_string_char_cstr
, &str1
)) == 0, "Invalid value of str1\n");
408 call_func1(p_basic_string_char_dtor
, &str1
);
410 /* str1 allocated, str2 local */
411 strcpy(atmp1
, "qwerty12345678901234567890");
412 strcpy(atmp2
, "asd");
413 call_func2(p_basic_string_char_ctor_cstr
, &str1
, atmp1
);
414 call_func2(p_basic_string_char_ctor_cstr
, &str2
, atmp2
);
415 call_func2(p_basic_string_char_swap
, &str1
, &str2
);
416 ok(strcmp(atmp2
, (const char *) call_func1(p_basic_string_char_cstr
, &str1
)) == 0, "Invalid value of str1\n");
417 ok(strcmp(atmp1
, (const char *) call_func1(p_basic_string_char_cstr
, &str2
)) == 0, "Invalid value of str2\n");
418 call_func2(p_basic_string_char_swap
, &str1
, &str2
);
419 ok(strcmp(atmp1
, (const char *) call_func1(p_basic_string_char_cstr
, &str1
)) == 0, "Invalid value of str1\n");
420 ok(strcmp(atmp2
, (const char *) call_func1(p_basic_string_char_cstr
, &str2
)) == 0, "Invalid value of str2\n");
421 call_func1(p_basic_string_char_dtor
, &str1
);
422 call_func1(p_basic_string_char_dtor
, &str2
);
425 static void test_basic_string_char_append(void) {
426 basic_string_char str1
, str2
;
429 call_func2(p_basic_string_char_ctor_cstr
, &str1
, "");
430 call_func2(p_basic_string_char_ctor_cstr
, &str2
, "append");
432 call_func2(p_basic_string_char_append
, &str1
, &str2
);
433 str
= call_func1(p_basic_string_char_cstr
, &str1
);
434 ok(!memcmp(str
, "append", 7), "str = %s\n", str
);
436 call_func4(p_basic_string_char_append_substr
, &str1
, &str2
, 3, 1);
437 str
= call_func1(p_basic_string_char_cstr
, &str1
);
438 ok(!memcmp(str
, "appende", 8), "str = %s\n", str
);
440 call_func4(p_basic_string_char_append_substr
, &str1
, &str2
, 5, 100);
441 str
= call_func1(p_basic_string_char_cstr
, &str1
);
442 ok(!memcmp(str
, "appended", 9), "str = %s\n", str
);
444 call_func4(p_basic_string_char_append_substr
, &str1
, &str2
, 6, 100);
445 str
= call_func1(p_basic_string_char_cstr
, &str1
);
446 ok(!memcmp(str
, "appended", 9), "str = %s\n", str
);
448 call_func1(p_basic_string_char_dtor
, &str1
);
449 call_func1(p_basic_string_char_dtor
, &str2
);
452 static void test_basic_string_char_compare(void) {
453 basic_string_char str1
, str2
;
456 call_func2(p_basic_string_char_ctor_cstr
, &str1
, "str1str");
457 call_func2(p_basic_string_char_ctor_cstr
, &str2
, "str9str");
459 ret
= (int)call_func6(p_basic_string_char_compare_substr_substr
,
460 &str1
, 0, 3, &str2
, 0, 3);
461 ok(ret
== 0, "ret = %d\n", ret
);
462 ret
= (int)call_func6(p_basic_string_char_compare_substr_substr
,
463 &str1
, 4, 3, &str2
, 4, 10);
464 ok(ret
== 0, "ret = %d\n", ret
);
465 ret
= (int)call_func6(p_basic_string_char_compare_substr_substr
,
466 &str1
, 1, 3, &str2
, 1, 4);
467 ok(ret
== -1, "ret = %d\n", ret
);
469 ret
= (int)call_func5(p_basic_string_char_compare_substr_cstr_len
,
470 &str1
, 0, 1000, "str1str", 7);
471 ok(ret
== 0, "ret = %d\n", ret
);
472 ret
= (int)call_func5(p_basic_string_char_compare_substr_cstr_len
,
473 &str1
, 1, 2, "tr", 2);
474 ok(ret
== 0, "ret = %d\n", ret
);
475 ret
= (int)call_func5(p_basic_string_char_compare_substr_cstr_len
,
476 &str1
, 1, 0, "aaa", 0);
477 ok(ret
== 0, "ret = %d\n", ret
);
478 ret
= (int)call_func5(p_basic_string_char_compare_substr_cstr_len
,
479 &str1
, 1, 0, "aaa", 1);
480 ok(ret
== -1, "ret = %d\n", ret
);
482 call_func1(p_basic_string_char_dtor
, &str1
);
483 call_func1(p_basic_string_char_dtor
, &str2
);
486 static void test_basic_string_char_concatenate(void) {
487 basic_string_char str
, ret
;
490 call_func2(p_basic_string_char_ctor_cstr
, &str
, "test ");
491 /* CDECL calling convention with return bigger than 8 bytes */
492 p_basic_string_char_concatenate(&ret
, &str
, &str
);
493 cstr
= call_func1(p_basic_string_char_cstr
, &ret
);
494 ok(cstr
!= NULL
, "cstr = NULL\n");
495 ok(!strcmp(cstr
, "test test "), "cstr = %s\n", cstr
);
496 call_func1(p_basic_string_char_dtor
, &ret
);
498 p_basic_string_char_concatenate_cstr(&ret
, &str
, "passed");
499 cstr
= call_func1(p_basic_string_char_cstr
, &ret
);
500 ok(cstr
!= NULL
, "cstr = NULL\n");
501 ok(!strcmp(cstr
, "test passed"), "cstr = %s\n", cstr
);
502 call_func1(p_basic_string_char_dtor
, &ret
);
504 call_func1(p_basic_string_char_dtor
, &str
);
507 static void test_basic_string_char_find(void) {
508 static const char tmp
[] = {'a','a','a','\0','b','b','b',0};
509 basic_string_char str
;
512 call_func1(p_basic_string_char_ctor
, &str
);
513 call_func3(p_basic_string_char_assign_cstr_len
, &str
, tmp
, 7);
514 ret
= (size_t)call_func4(p_basic_string_char_find_cstr_substr
, &str
, "aaa", 0, 3);
515 ok(ret
== 0, "ret = %lu\n", (unsigned long)ret
);
516 ret
= (size_t)call_func4(p_basic_string_char_find_cstr_substr
, &str
, "aaa", 1, 3);
517 ok(ret
== -1, "ret = %lu\n", (unsigned long)ret
);
518 ret
= (size_t)call_func4(p_basic_string_char_find_cstr_substr
, &str
, "bbb", 0, 3);
519 ok(ret
== 4, "ret = %lu\n", (unsigned long)ret
);
520 call_func1(p_basic_string_char_dtor
, &str
);
523 static void test_basic_string_char_rfind(void) {
524 struct rfind_char_test
{
533 basic_string_char str
;
535 struct rfind_char_test tests
[] = {
536 { "", "a", 0, 1, *p_basic_string_char_npos
}, /* empty string */
537 { "a", "", 0, 0, 0 }, /* empty find */
538 { "aaa", "aaa", 0, 3, 0 }, /* simple case */
539 { "aaa", "a", 0, 1, 0 }, /* start of string */
540 { "aaa", "a", 2, 1, 2 }, /* end of string */
541 { "aaa", "a", *p_basic_string_char_npos
, 1, 2 }, /* off == npos */
542 { "aaa", "z", 0, 1, *p_basic_string_char_npos
} /* can't find */
545 for(i
=0; i
<sizeof(tests
)/sizeof(tests
[0]); i
++) {
546 call_func2(p_basic_string_char_ctor_cstr
, &str
, tests
[i
].str
);
548 ret
= (size_t)call_func4(p_basic_string_char_rfind_cstr_substr
, &str
,
549 tests
[i
].find
, tests
[i
].pos
, tests
[i
].len
);
550 ok(ret
== tests
[i
].ret
, "str = '%s' find = '%s' ret = %lu\n",
551 tests
[i
].str
, tests
[i
].find
, (unsigned long)ret
);
553 call_func1(p_basic_string_char_dtor
, &str
);
557 static void test_basic_string_char_replace(void) {
558 struct replace_char_test
{
567 basic_string_char str
;
568 basic_string_char
*ret
;
569 struct replace_char_test tests
[] = {
570 { "", 0, 0, "", "" }, /* empty string */
571 { "", 0, 10, "", "" }, /* empty string with invalid len */
573 { "ABCDEF", 0, 0, "", "ABCDEF" }, /* replace with empty string */
574 { "ABCDEF", 0, 0, "-", "-ABCDEF"}, /* replace with 0 len */
575 { "ABCDEF", 0, 1, "-", "-BCDEF" }, /* replace 1 at beginning */
576 { "ABCDEF", 0, 3, "-", "-DEF" }, /* replace 3 at beginning */
577 { "ABCDEF", 0, 42, "-", "-" }, /* replace whole string with invalid long len */
578 { "ABCDEF", 0, *p_basic_string_char_npos
, "-", "-" }, /* replace whole string with npos */
580 { "ABCDEF", 5, 0, "", "ABCDEF" }, /* replace at end with empty string */
581 { "ABCDEF", 5, 0, "-", "ABCDE-F"}, /* replace at end with 0 len */
582 { "ABCDEF", 5, 1, "-", "ABCDE-" }, /* replace 1 at end */
583 { "ABCDEF", 5, 42, "-", "ABCDE-" }, /* replace end with invalid long len */
584 { "ABCDEF", 5, *p_basic_string_char_npos
, "-", "ABCDE-" }, /* replace end with npos */
586 { "ABCDEF", 6, 0, "", "ABCDEF" }, /* replace after end with empty string */
587 { "ABCDEF", 6, 0, "-", "ABCDEF-"}, /* replace after end with 0 len */
588 { "ABCDEF", 6, 1, "-", "ABCDEF-" }, /* replace 1 after end */
589 { "ABCDEF", 6, 42, "-", "ABCDEF-" }, /* replace after end with invalid long len */
590 { "ABCDEF", 6, *p_basic_string_char_npos
, "-", "ABCDEF-" }, /* replace after end with npos */
593 for(i
=0; i
<sizeof(tests
)/sizeof(tests
[0]); i
++) {
594 call_func2(p_basic_string_char_ctor_cstr
, &str
, tests
[i
].str
);
596 ret
= call_func4(p_basic_string_char_replace_cstr
, &str
, tests
[i
].off
, tests
[i
].len
, tests
[i
].replace
);
597 ok(ret
== &str
, "str = %p ret = %p\n", ret
, &str
);
598 ok(strcmp(tests
[i
].ret
, (const char *) call_func1(p_basic_string_char_cstr
, ret
)) == 0, "str = %s ret = %s\n",
599 tests
[i
].ret
, (const char *) call_func1(p_basic_string_char_cstr
, ret
));
601 call_func1(p_basic_string_char_dtor
, &str
);
605 static void test_basic_string_wchar(void) {
606 static const wchar_t test
[] = { 't','e','s','t',0 };
608 basic_string_wchar str1
, str2
, *pstr
;
610 size_t size
, capacity
;
612 call_func1(p_basic_string_wchar_ctor
, &str1
);
614 str
= call_func1(p_basic_string_wchar_cstr
, &str1
);
615 ok(str
!= NULL
, "str = NULL\n");
616 ok(*str
== '\0', "*str = %c\n", *str
);
617 str
= call_func1(p_basic_string_wchar_data
, &str1
);
618 ok(str
!= NULL
, "str = NULL\n");
619 ok(*str
== '\0', "*str = %c\n", *str
);
620 call_func1(p_basic_string_wchar_dtor
, &str1
);
622 pstr
= call_func2(p_basic_string_wchar_ctor_cstr
, &str1
, test
);
623 ok(pstr
== &str1
, "pstr != &str1\n");
624 str
= call_func1(p_basic_string_wchar_cstr
, &str1
);
625 ok(!memcmp(str
, test
, 5*sizeof(wchar_t)), "str = %s\n", wine_dbgstr_w(str
));
626 str
= call_func1(p_basic_string_wchar_data
, &str1
);
627 ok(!memcmp(str
, test
, 5*sizeof(wchar_t)), "str = %s\n", wine_dbgstr_w(str
));
628 size
= (size_t)call_func1(p_basic_string_wchar_size
, &str1
);
629 ok(size
== 4, "size = %lu\n", (unsigned long)size
);
630 capacity
= (size_t)call_func1(p_basic_string_wchar_capacity
, &str1
);
631 ok(capacity
>= size
, "capacity = %lu < size = %lu\n", (unsigned long)capacity
, (unsigned long)size
);
633 memset(&str2
, 0, sizeof(basic_string_wchar
));
634 pstr
= call_func2(p_basic_string_wchar_copy_ctor
, &str2
, &str1
);
635 ok(pstr
== &str2
, "pstr != &str2\n");
636 str
= call_func1(p_basic_string_wchar_cstr
, &str2
);
637 ok(!memcmp(str
, test
, 5*sizeof(wchar_t)), "str = %s\n", wine_dbgstr_w(str
));
638 str
= call_func1(p_basic_string_wchar_data
, &str2
);
639 ok(!memcmp(str
, test
, 5*sizeof(wchar_t)), "str = %s\n", wine_dbgstr_w(str
));
641 call_func3(p_basic_string_wchar_erase
, &str2
, 1, 2);
642 str
= call_func1(p_basic_string_wchar_cstr
, &str2
);
643 ok(str
[0]=='t' && str
[1]=='t' && str
[2]=='\0', "str = %s\n", wine_dbgstr_w(str
));
644 str
= call_func1(p_basic_string_wchar_data
, &str2
);
645 ok(str
[0]=='t' && str
[1]=='t' && str
[2]=='\0', "str = %s\n", wine_dbgstr_w(str
));
646 size
= (size_t)call_func1(p_basic_string_wchar_size
, &str1
);
647 ok(size
== 4, "size = %lu\n", (unsigned long)size
);
648 capacity
= (size_t)call_func1(p_basic_string_wchar_capacity
, &str1
);
649 ok(capacity
>= size
, "capacity = %lu < size = %lu\n", (unsigned long)capacity
, (unsigned long)size
);
651 call_func3(p_basic_string_wchar_erase
, &str2
, 1, 100);
652 str
= call_func1(p_basic_string_wchar_cstr
, &str2
);
653 ok(str
[0]=='t' && str
[1]=='\0', "str = %s\n", wine_dbgstr_w(str
));
654 str
= call_func1(p_basic_string_wchar_data
, &str2
);
655 ok(str
[0]=='t' && str
[1]=='\0', "str = %s\n", wine_dbgstr_w(str
));
656 size
= (size_t)call_func1(p_basic_string_wchar_size
, &str1
);
657 ok(size
== 4, "size = %lu\n", (unsigned long)size
);
658 capacity
= (size_t)call_func1(p_basic_string_wchar_capacity
, &str1
);
659 ok(capacity
>= size
, "capacity = %lu < size = %lu\n", (unsigned long)capacity
, (unsigned long)size
);
661 call_func3(p_basic_string_wchar_assign_cstr_len
, &str2
, test
, 4);
662 str
= call_func1(p_basic_string_wchar_cstr
, &str2
);
663 ok(!memcmp(str
, test
, 5*sizeof(wchar_t)), "str = %s\n", wine_dbgstr_w(str
));
664 str
= call_func1(p_basic_string_wchar_data
, &str2
);
665 ok(!memcmp(str
, test
, 5*sizeof(wchar_t)), "str = %s\n", wine_dbgstr_w(str
));
667 call_func3(p_basic_string_wchar_assign_cstr_len
, &str2
, (str
+1), 2);
668 str
= call_func1(p_basic_string_wchar_cstr
, &str2
);
669 ok(str
[0]=='e' && str
[1]=='s' && str
[2]=='\0', "str = %s\n", wine_dbgstr_w(str
));
670 str
= call_func1(p_basic_string_wchar_data
, &str2
);
671 ok(str
[0]=='e' && str
[1]=='s' && str
[2]=='\0', "str = %s\n", wine_dbgstr_w(str
));
673 call_func1(p_basic_string_wchar_dtor
, &str1
);
674 call_func1(p_basic_string_wchar_dtor
, &str2
);
677 static void test_basic_string_wchar_swap(void) {
678 basic_string_wchar str1
, str2
;
679 wchar_t wtmp1
[32], wtmp2
[32];
681 /* Swap self, local */
682 mbstowcs(wtmp1
, "qwerty", 32);
683 call_func2(p_basic_string_wchar_ctor_cstr
, &str1
, wtmp1
);
684 call_func2(p_basic_string_wchar_swap
, &str1
, &str1
);
685 ok(wcscmp(wtmp1
, (const wchar_t *) call_func1(p_basic_string_wchar_cstr
, &str1
)) == 0, "Invalid value of str1\n");
686 call_func2(p_basic_string_wchar_swap
, &str1
, &str1
);
687 ok(wcscmp(wtmp1
, (const wchar_t *) call_func1(p_basic_string_wchar_cstr
, &str1
)) == 0, "Invalid value of str1\n");
688 call_func1(p_basic_string_wchar_dtor
, &str1
);
690 /* str1 allocated, str2 local */
691 mbstowcs(wtmp1
, "qwerty12345678901234567890", 32);
692 mbstowcs(wtmp2
, "asd", 32);
693 call_func2(p_basic_string_wchar_ctor_cstr
, &str1
, wtmp1
);
694 call_func2(p_basic_string_wchar_ctor_cstr
, &str2
, wtmp2
);
695 call_func2(p_basic_string_wchar_swap
, &str1
, &str2
);
696 ok(wcscmp(wtmp2
, (const wchar_t *) call_func1(p_basic_string_wchar_cstr
, &str1
)) == 0, "Invalid value of str1\n");
697 ok(wcscmp(wtmp1
, (const wchar_t *) call_func1(p_basic_string_wchar_cstr
, &str2
)) == 0, "Invalid value of str2\n");
698 call_func2(p_basic_string_wchar_swap
, &str1
, &str2
);
699 ok(wcscmp(wtmp1
, (const wchar_t *) call_func1(p_basic_string_wchar_cstr
, &str1
)) == 0, "Invalid value of str1\n");
700 ok(wcscmp(wtmp2
, (const wchar_t *) call_func1(p_basic_string_wchar_cstr
, &str2
)) == 0, "Invalid value of str2\n");
701 call_func1(p_basic_string_wchar_dtor
, &str1
);
702 call_func1(p_basic_string_wchar_dtor
, &str2
);
710 test_basic_string_char();
711 test_basic_string_char_swap();
712 test_basic_string_char_append();
713 test_basic_string_char_compare();
714 test_basic_string_char_concatenate();
715 test_basic_string_char_find();
716 test_basic_string_char_rfind();
717 test_basic_string_char_replace();
718 test_basic_string_wchar();
719 test_basic_string_wchar_swap();
721 ok(!invalid_parameter
, "invalid_parameter_handler was invoked too many times\n");