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
24 #include "wine/test.h"
26 /* basic_string<char, char_traits<char>, allocator<char>> */
27 #define BUF_SIZE_CHAR 16
28 typedef struct _basic_string_char
32 char buf[BUF_SIZE_CHAR];
39 /* basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>> */
40 #define BUF_SIZE_WCHAR 8
41 typedef struct _basic_string_wchar
45 wchar_t buf[BUF_SIZE_WCHAR];
52 static void* (__cdecl *p_set_invalid_parameter_handler)(void*);
53 static basic_string_char* (__cdecl *p_basic_string_char_concatenate)(basic_string_char*, const basic_string_char*, const basic_string_char*);
54 static basic_string_char* (__cdecl *p_basic_string_char_concatenate_cstr)(basic_string_char*, const basic_string_char*, const char*);
58 #define __thiscall __stdcall
60 #define __thiscall __cdecl
63 static basic_string_char* (__thiscall *p_basic_string_char_ctor)(basic_string_char*);
64 static basic_string_char* (__thiscall *p_basic_string_char_copy_ctor)(basic_string_char*, basic_string_char*);
65 static basic_string_char* (__thiscall *p_basic_string_char_ctor_cstr)(basic_string_char*, const char*);
66 static void (__thiscall *p_basic_string_char_dtor)(basic_string_char*);
67 static basic_string_char* (__thiscall *p_basic_string_char_erase)(basic_string_char*, size_t, size_t);
68 static basic_string_char* (__thiscall *p_basic_string_char_assign_cstr_len)(basic_string_char*, const char*, size_t);
69 static const char* (__thiscall *p_basic_string_char_cstr)(basic_string_char*);
70 static const char* (__thiscall *p_basic_string_char_data)(basic_string_char*);
71 static size_t (__thiscall *p_basic_string_char_size)(basic_string_char*);
72 static size_t (__thiscall *p_basic_string_char_capacity)(basic_string_char*);
73 static void (__thiscall *p_basic_string_char_swap)(basic_string_char*, basic_string_char*);
74 static basic_string_char* (__thiscall *p_basic_string_char_append)(basic_string_char*, basic_string_char*);
75 static basic_string_char* (__thiscall *p_basic_string_char_append_substr)(basic_string_char*, basic_string_char*, size_t, size_t);
76 static int (__thiscall *p_basic_string_char_compare_substr_substr)(basic_string_char*, size_t, size_t, basic_string_char*, size_t, size_t);
77 static int (__thiscall *p_basic_string_char_compare_substr_cstr_len)(basic_string_char*, size_t, size_t, const char*, size_t);
78 static size_t (__thiscall *p_basic_string_char_find_cstr_substr)(basic_string_char*, const char*, size_t, size_t);
79 static size_t (__thiscall *p_basic_string_char_rfind_cstr_substr)(basic_string_char*, const char*, size_t, size_t);
80 static basic_string_char* (__thiscall *p_basic_string_char_replace_cstr)(basic_string_char*, size_t, size_t, const char*);
82 static size_t *p_basic_string_char_npos;
84 static basic_string_wchar* (__thiscall *p_basic_string_wchar_ctor)(basic_string_wchar*);
85 static basic_string_wchar* (__thiscall *p_basic_string_wchar_copy_ctor)(basic_string_wchar*, basic_string_wchar*);
86 static basic_string_wchar* (__thiscall *p_basic_string_wchar_ctor_cstr)(basic_string_wchar*, const wchar_t*);
87 static void (__thiscall *p_basic_string_wchar_dtor)(basic_string_wchar*);
88 static basic_string_wchar* (__thiscall *p_basic_string_wchar_erase)(basic_string_wchar*, size_t, size_t);
89 static basic_string_wchar* (__thiscall *p_basic_string_wchar_assign_cstr_len)(basic_string_wchar*, const wchar_t*, size_t);
90 static const wchar_t* (__thiscall *p_basic_string_wchar_cstr)(basic_string_wchar*);
91 static const wchar_t* (__thiscall *p_basic_string_wchar_data)(basic_string_wchar*);
92 static size_t (__thiscall *p_basic_string_wchar_size)(basic_string_wchar*);
93 static size_t (__thiscall *p_basic_string_wchar_capacity)(basic_string_wchar*);
94 static void (__thiscall *p_basic_string_wchar_swap)(basic_string_wchar*, basic_string_wchar*);
96 static int invalid_parameter = 0;
97 static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
98 const wchar_t *function, const wchar_t *file,
99 unsigned line, uintptr_t arg)
101 ok(expression == NULL, "expression is not NULL\n");
102 ok(function == NULL, "function is not NULL\n");
103 ok(file == NULL, "file is not NULL\n");
104 ok(line == 0, "line = %u\n", line);
105 ok(arg == 0, "arg = %lx\n", (UINT_PTR)arg);
109 /* Emulate a __thiscall */
112 #include "pshpack1.h"
113 struct thiscall_thunk
115 BYTE pop_eax; /* popl %eax (ret addr) */
116 BYTE pop_edx; /* popl %edx (func) */
117 BYTE pop_ecx; /* popl %ecx (this) */
118 BYTE push_eax; /* pushl %eax */
119 WORD jmp_edx; /* jmp *%edx */
123 static void * (WINAPI *call_thiscall_func1)( void *func, void *this );
124 static void * (WINAPI *call_thiscall_func2)( void *func, void *this, const void *a );
125 static void * (WINAPI *call_thiscall_func3)( void *func, void *this, const void *a, const void *b );
126 static void * (WINAPI *call_thiscall_func4)( void *func, void *this, const void *a, const void *b,
128 static void * (WINAPI *call_thiscall_func5)( void *func, void *this, const void *a, const void *b,
129 const void *c, const void *d );
130 static void * (WINAPI *call_thiscall_func6)( void *func, void *this, const void *a, const void *b,
131 const void *c, const void *d, const void *e );
133 static void init_thiscall_thunk(void)
135 struct thiscall_thunk *thunk = VirtualAlloc( NULL, sizeof(*thunk),
136 MEM_COMMIT, PAGE_EXECUTE_READWRITE );
137 thunk->pop_eax = 0x58; /* popl %eax */
138 thunk->pop_edx = 0x5a; /* popl %edx */
139 thunk->pop_ecx = 0x59; /* popl %ecx */
140 thunk->push_eax = 0x50; /* pushl %eax */
141 thunk->jmp_edx = 0xe2ff; /* jmp *%edx */
142 call_thiscall_func1 = (void *)thunk;
143 call_thiscall_func2 = (void *)thunk;
144 call_thiscall_func3 = (void *)thunk;
145 call_thiscall_func4 = (void *)thunk;
146 call_thiscall_func5 = (void *)thunk;
147 call_thiscall_func6 = (void *)thunk;
150 #define call_func1(func,_this) call_thiscall_func1(func,_this)
151 #define call_func2(func,_this,a) call_thiscall_func2(func,_this,(const void*)a)
152 #define call_func3(func,_this,a,b) call_thiscall_func3(func,_this,(const void*)a,(const void*)b)
153 #define call_func4(func,_this,a,b,c) call_thiscall_func4(func,_this,(const void*)a,\
154 (const void*)b,(const void*)c)
155 #define call_func5(func,_this,a,b,c,d) call_thiscall_func5(func,_this,(const void*)a,\
156 (const void*)b,(const void*)c,(const void*)d)
157 #define call_func6(func,_this,a,b,c,d,e) call_thiscall_func6(func,_this,(const void*)a,\
158 (const void*)b,(const void*)c,(const void*)d,(const void*)e)
162 #define init_thiscall_thunk()
163 #define call_func1(func,_this) func(_this)
164 #define call_func2(func,_this,a) func(_this,a)
165 #define call_func3(func,_this,a,b) func(_this,a,b)
166 #define call_func4(func,_this,a,b,c) func(_this,a,b,c)
167 #define call_func5(func,_this,a,b,c,d) func(_this,a,b,c,d)
168 #define call_func6(func,_this,a,b,c,d,e) func(_this,a,b,c,d,e)
170 #endif /* __i386__ */
172 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
173 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
174 static BOOL init(void)
176 HMODULE msvcr = LoadLibraryA("msvcr90.dll");
177 HMODULE msvcp = LoadLibraryA("msvcp90.dll");
178 if(!msvcr || !msvcp) {
179 win_skip("msvcp90.dll or msvcrt90.dll not installed\n");
183 p_set_invalid_parameter_handler = (void*)GetProcAddress(msvcr, "_set_invalid_parameter_handler");
184 if(!p_set_invalid_parameter_handler) {
185 win_skip("Error setting tests environment\n");
189 p_set_invalid_parameter_handler(test_invalid_parameter_handler);
191 if(sizeof(void*) == 8) { /* 64-bit initialization */
192 SET(p_basic_string_char_ctor,
193 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ");
194 SET(p_basic_string_char_copy_ctor,
195 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@AEBV01@@Z");
196 SET(p_basic_string_char_ctor_cstr,
197 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@PEBD@Z");
198 SET(p_basic_string_char_dtor,
199 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ");
200 SET(p_basic_string_char_erase,
201 "?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@_K0@Z");
202 SET(p_basic_string_char_assign_cstr_len,
203 "?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@PEBD_K@Z");
204 SET(p_basic_string_char_cstr,
205 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAPEBDXZ");
206 SET(p_basic_string_char_data,
207 "?data@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAPEBDXZ");
208 SET(p_basic_string_char_size,
209 "?size@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBA_KXZ");
210 SET(p_basic_string_char_capacity,
211 "?capacity@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBA_KXZ");
212 SET(p_basic_string_char_swap,
213 "?swap@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAXAEAV12@@Z");
214 SET(p_basic_string_char_append,
215 "?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@AEBV12@@Z");
216 SET(p_basic_string_char_append_substr,
217 "?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@AEBV12@_K1@Z");
218 SET(p_basic_string_char_compare_substr_substr,
219 "?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAH_K0AEBV12@00@Z");
220 SET(p_basic_string_char_compare_substr_cstr_len,
221 "?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAH_K0PEBD0@Z");
222 SET(p_basic_string_char_concatenate,
223 "??$?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");
224 SET(p_basic_string_char_concatenate_cstr,
225 "??$?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");
226 SET(p_basic_string_char_find_cstr_substr,
227 "?find@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBA_KPEBD_K1@Z");
228 SET(p_basic_string_char_rfind_cstr_substr,
229 "?rfind@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBA_KPEBD_K1@Z");
230 SET(p_basic_string_char_replace_cstr,
231 "?replace@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@_K0PEBD@Z");
232 SET(p_basic_string_char_npos,
233 "?npos@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@2_KB");
235 SET(p_basic_string_wchar_ctor,
236 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@XZ");
237 SET(p_basic_string_wchar_copy_ctor,
238 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@AEBV01@@Z");
239 SET(p_basic_string_wchar_ctor_cstr,
240 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@PEB_W@Z");
241 SET(p_basic_string_wchar_dtor,
242 "??1?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@XZ");
243 SET(p_basic_string_wchar_erase,
244 "?erase@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAAEAV12@_K0@Z");
245 SET(p_basic_string_wchar_assign_cstr_len,
246 "?assign@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAAEAV12@PEB_W_K@Z");
247 SET(p_basic_string_wchar_cstr,
248 "?c_str@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBAPEB_WXZ");
249 SET(p_basic_string_wchar_data,
250 "?data@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBAPEB_WXZ");
251 SET(p_basic_string_wchar_size,
252 "?size@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBA_KXZ");
253 SET(p_basic_string_wchar_capacity,
254 "?capacity@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBA_KXZ");
255 SET(p_basic_string_wchar_swap,
256 "?swap@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAXAEAV12@@Z");
258 SET(p_basic_string_char_ctor,
259 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ");
260 SET(p_basic_string_char_copy_ctor,
261 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z");
262 SET(p_basic_string_char_ctor_cstr,
263 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z");
264 SET(p_basic_string_char_dtor,
265 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ");
266 SET(p_basic_string_char_erase,
267 "?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@II@Z");
268 SET(p_basic_string_char_assign_cstr_len,
269 "?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@PBDI@Z");
270 SET(p_basic_string_char_cstr,
271 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ");
272 SET(p_basic_string_char_data,
273 "?data@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ");
274 SET(p_basic_string_char_size,
275 "?size@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIXZ");
276 SET(p_basic_string_char_capacity,
277 "?capacity@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIXZ");
278 SET(p_basic_string_char_swap,
279 "?swap@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXAAV12@@Z");
280 SET(p_basic_string_char_append,
281 "?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@ABV12@@Z");
282 SET(p_basic_string_char_append_substr,
283 "?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@ABV12@II@Z");
284 SET(p_basic_string_char_compare_substr_substr,
285 "?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEHIIABV12@II@Z");
286 SET(p_basic_string_char_compare_substr_cstr_len,
287 "?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEHIIPBDI@Z");
288 SET(p_basic_string_char_concatenate,
289 "??$?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");
290 SET(p_basic_string_char_concatenate_cstr,
291 "??$?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");
292 SET(p_basic_string_char_find_cstr_substr,
293 "?find@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIPBDII@Z");
294 SET(p_basic_string_char_rfind_cstr_substr,
295 "?rfind@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIPBDII@Z");
296 SET(p_basic_string_char_replace_cstr,
297 "?replace@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@IIPBD@Z");
298 SET(p_basic_string_char_npos,
299 "?npos@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@2IB");
301 SET(p_basic_string_wchar_ctor,
302 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@XZ");
303 SET(p_basic_string_wchar_copy_ctor,
304 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@ABV01@@Z");
305 SET(p_basic_string_wchar_ctor_cstr,
306 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@PB_W@Z");
307 SET(p_basic_string_wchar_dtor,
308 "??1?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@XZ");
309 SET(p_basic_string_wchar_erase,
310 "?erase@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEAAV12@II@Z");
311 SET(p_basic_string_wchar_assign_cstr_len,
312 "?assign@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEAAV12@PB_WI@Z");
313 SET(p_basic_string_wchar_cstr,
314 "?c_str@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEPB_WXZ");
315 SET(p_basic_string_wchar_data,
316 "?data@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEPB_WXZ");
317 SET(p_basic_string_wchar_size,
318 "?size@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEIXZ");
319 SET(p_basic_string_wchar_capacity,
320 "?capacity@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEIXZ");
321 SET(p_basic_string_wchar_swap,
322 "?swap@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEXAAV12@@Z");
325 init_thiscall_thunk();
329 static void test_basic_string_char(void) {
330 basic_string_char str1, str2, *pstr;
332 size_t size, capacity;
334 call_func1(p_basic_string_char_ctor, &str1);
336 str = call_func1(p_basic_string_char_cstr, &str1);
337 ok(str != NULL, "str = NULL\n");
338 ok(*str == '\0', "*str = %c\n", *str);
339 str = call_func1(p_basic_string_char_data, &str1);
340 ok(str != NULL, "str = NULL\n");
341 ok(*str == '\0', "*str = %c\n", *str);
342 call_func1(p_basic_string_char_dtor, &str1);
344 pstr = call_func2(p_basic_string_char_ctor_cstr, &str1, "test");
345 ok(pstr == &str1, "pstr != &str1\n");
346 str = call_func1(p_basic_string_char_cstr, &str1);
347 ok(!memcmp(str, "test", 5), "str = %s\n", str);
348 str = call_func1(p_basic_string_char_data, &str1);
349 ok(!memcmp(str, "test", 5), "str = %s\n", str);
350 size = (size_t)call_func1(p_basic_string_char_size, &str1);
351 ok(size == 4, "size = %lu\n", (unsigned long)size);
352 capacity = (size_t)call_func1(p_basic_string_char_capacity, &str1);
353 ok(capacity >= size, "capacity = %lu < size = %lu\n", (unsigned long)capacity, (unsigned long)size);
355 pstr = call_func2(p_basic_string_char_copy_ctor, &str2, &str1);
356 ok(pstr == &str2, "pstr != &str2\n");
357 str = call_func1(p_basic_string_char_cstr, &str2);
358 ok(!memcmp(str, "test", 5), "str = %s\n", str);
359 str = call_func1(p_basic_string_char_data, &str2);
360 ok(!memcmp(str, "test", 5), "str = %s\n", str);
362 call_func3(p_basic_string_char_erase, &str2, 1, 2);
363 str = call_func1(p_basic_string_char_cstr, &str2);
364 ok(!memcmp(str, "tt", 3), "str = %s\n", str);
365 str = call_func1(p_basic_string_char_data, &str2);
366 ok(!memcmp(str, "tt", 3), "str = %s\n", str);
367 size = (size_t)call_func1(p_basic_string_char_size, &str1);
368 ok(size == 4, "size = %lu\n", (unsigned long)size);
369 capacity = (size_t)call_func1(p_basic_string_char_capacity, &str1);
370 ok(capacity >= size, "capacity = %lu < size = %lu\n", (unsigned long)capacity, (unsigned long)size);
372 call_func3(p_basic_string_char_erase, &str2, 1, 100);
373 str = call_func1(p_basic_string_char_cstr, &str2);
374 ok(!memcmp(str, "t", 2), "str = %s\n", str);
375 str = call_func1(p_basic_string_char_data, &str2);
376 ok(!memcmp(str, "t", 2), "str = %s\n", str);
377 size = (size_t)call_func1(p_basic_string_char_size, &str1);
378 ok(size == 4, "size = %lu\n", (unsigned long)size);
379 capacity = (size_t)call_func1(p_basic_string_char_capacity, &str1);
380 ok(capacity >= size, "capacity = %lu < size = %lu\n", (unsigned long)capacity, (unsigned long)size);
382 call_func3(p_basic_string_char_assign_cstr_len, &str2, "test", 4);
383 str = call_func1(p_basic_string_char_cstr, &str2);
384 ok(!memcmp(str, "test", 5), "str = %s\n", str);
385 str = call_func1(p_basic_string_char_data, &str2);
386 ok(!memcmp(str, "test", 5), "str = %s\n", str);
388 call_func3(p_basic_string_char_assign_cstr_len, &str2, (str+1), 2);
389 str = call_func1(p_basic_string_char_cstr, &str2);
390 ok(!memcmp(str, "es", 3), "str = %s\n", str);
391 str = call_func1(p_basic_string_char_data, &str2);
392 ok(!memcmp(str, "es", 3), "str = %s\n", str);
394 call_func1(p_basic_string_char_dtor, &str1);
395 call_func1(p_basic_string_char_dtor, &str2);
398 static void test_basic_string_char_swap(void) {
399 basic_string_char str1, str2;
400 char atmp1[32], atmp2[32];
402 /* Swap self, local */
403 strcpy(atmp1, "qwerty");
404 call_func2(p_basic_string_char_ctor_cstr, &str1, atmp1);
405 call_func2(p_basic_string_char_swap, &str1, &str1);
406 ok(strcmp(atmp1, (const char *) call_func1(p_basic_string_char_cstr, &str1)) == 0, "Invalid value of str1\n");
407 call_func2(p_basic_string_char_swap, &str1, &str1);
408 ok(strcmp(atmp1, (const char *) call_func1(p_basic_string_char_cstr, &str1)) == 0, "Invalid value of str1\n");
409 call_func1(p_basic_string_char_dtor, &str1);
411 /* str1 allocated, str2 local */
412 strcpy(atmp1, "qwerty12345678901234567890");
413 strcpy(atmp2, "asd");
414 call_func2(p_basic_string_char_ctor_cstr, &str1, atmp1);
415 call_func2(p_basic_string_char_ctor_cstr, &str2, atmp2);
416 call_func2(p_basic_string_char_swap, &str1, &str2);
417 ok(strcmp(atmp2, (const char *) call_func1(p_basic_string_char_cstr, &str1)) == 0, "Invalid value of str1\n");
418 ok(strcmp(atmp1, (const char *) call_func1(p_basic_string_char_cstr, &str2)) == 0, "Invalid value of str2\n");
419 call_func2(p_basic_string_char_swap, &str1, &str2);
420 ok(strcmp(atmp1, (const char *) call_func1(p_basic_string_char_cstr, &str1)) == 0, "Invalid value of str1\n");
421 ok(strcmp(atmp2, (const char *) call_func1(p_basic_string_char_cstr, &str2)) == 0, "Invalid value of str2\n");
422 call_func1(p_basic_string_char_dtor, &str1);
423 call_func1(p_basic_string_char_dtor, &str2);
426 static void test_basic_string_char_append(void) {
427 basic_string_char str1, str2;
430 call_func2(p_basic_string_char_ctor_cstr, &str1, "");
431 call_func2(p_basic_string_char_ctor_cstr, &str2, "append");
433 call_func2(p_basic_string_char_append, &str1, &str2);
434 str = call_func1(p_basic_string_char_cstr, &str1);
435 ok(!memcmp(str, "append", 7), "str = %s\n", str);
437 call_func4(p_basic_string_char_append_substr, &str1, &str2, 3, 1);
438 str = call_func1(p_basic_string_char_cstr, &str1);
439 ok(!memcmp(str, "appende", 8), "str = %s\n", str);
441 call_func4(p_basic_string_char_append_substr, &str1, &str2, 5, 100);
442 str = call_func1(p_basic_string_char_cstr, &str1);
443 ok(!memcmp(str, "appended", 9), "str = %s\n", str);
445 call_func4(p_basic_string_char_append_substr, &str1, &str2, 6, 100);
446 str = call_func1(p_basic_string_char_cstr, &str1);
447 ok(!memcmp(str, "appended", 9), "str = %s\n", str);
449 call_func1(p_basic_string_char_dtor, &str1);
450 call_func1(p_basic_string_char_dtor, &str2);
453 static void test_basic_string_char_compare(void) {
454 basic_string_char str1, str2, str3;
457 call_func2(p_basic_string_char_ctor_cstr, &str1, "str1str");
458 call_func2(p_basic_string_char_ctor_cstr, &str2, "str9str");
459 call_func2(p_basic_string_char_ctor_cstr, &str3, "splash.png");
461 ret = (int)call_func6(p_basic_string_char_compare_substr_substr,
462 &str1, 0, 3, &str2, 0, 3);
463 ok(ret == 0, "ret = %d\n", ret);
464 ret = (int)call_func6(p_basic_string_char_compare_substr_substr,
465 &str1, 4, 3, &str2, 4, 10);
466 ok(ret == 0, "ret = %d\n", ret);
467 ret = (int)call_func6(p_basic_string_char_compare_substr_substr,
468 &str1, 1, 3, &str2, 1, 4);
469 ok(ret == -1, "ret = %d\n", ret);
471 ret = (int)call_func5(p_basic_string_char_compare_substr_cstr_len,
472 &str1, 0, 1000, "str1str", 7);
473 ok(ret == 0, "ret = %d\n", ret);
474 ret = (int)call_func5(p_basic_string_char_compare_substr_cstr_len,
475 &str3, 6, UINT_MAX, ".png", 4);
476 ok(ret == 0, "ret = %d\n", ret);
477 ret = (int)call_func5(p_basic_string_char_compare_substr_cstr_len,
478 &str1, 1, 2, "tr", 2);
479 ok(ret == 0, "ret = %d\n", ret);
480 ret = (int)call_func5(p_basic_string_char_compare_substr_cstr_len,
481 &str1, 1, 0, "aaa", 0);
482 ok(ret == 0, "ret = %d\n", ret);
483 ret = (int)call_func5(p_basic_string_char_compare_substr_cstr_len,
484 &str1, 1, 0, "aaa", 1);
485 ok(ret == -1, "ret = %d\n", ret);
487 call_func1(p_basic_string_char_dtor, &str1);
488 call_func1(p_basic_string_char_dtor, &str2);
489 call_func1(p_basic_string_char_dtor, &str3);
492 static void test_basic_string_char_concatenate(void) {
493 basic_string_char str, ret;
496 call_func2(p_basic_string_char_ctor_cstr, &str, "test ");
497 /* CDECL calling convention with return bigger than 8 bytes */
498 p_basic_string_char_concatenate(&ret, &str, &str);
499 cstr = call_func1(p_basic_string_char_cstr, &ret);
500 ok(cstr != NULL, "cstr = NULL\n");
501 ok(!strcmp(cstr, "test test "), "cstr = %s\n", cstr);
502 call_func1(p_basic_string_char_dtor, &ret);
504 p_basic_string_char_concatenate_cstr(&ret, &str, "passed");
505 cstr = call_func1(p_basic_string_char_cstr, &ret);
506 ok(cstr != NULL, "cstr = NULL\n");
507 ok(!strcmp(cstr, "test passed"), "cstr = %s\n", cstr);
508 call_func1(p_basic_string_char_dtor, &ret);
510 call_func1(p_basic_string_char_dtor, &str);
513 static void test_basic_string_char_find(void) {
514 static const char tmp[] = {'a','a','a','\0','b','b','b',0};
515 basic_string_char str;
518 call_func1(p_basic_string_char_ctor, &str);
519 call_func3(p_basic_string_char_assign_cstr_len, &str, tmp, 7);
520 ret = (size_t)call_func4(p_basic_string_char_find_cstr_substr, &str, "aaa", 0, 3);
521 ok(ret == 0, "ret = %lu\n", (unsigned long)ret);
522 ret = (size_t)call_func4(p_basic_string_char_find_cstr_substr, &str, "aaa", 1, 3);
523 ok(ret == -1, "ret = %lu\n", (unsigned long)ret);
524 ret = (size_t)call_func4(p_basic_string_char_find_cstr_substr, &str, "bbb", 0, 3);
525 ok(ret == 4, "ret = %lu\n", (unsigned long)ret);
526 call_func1(p_basic_string_char_dtor, &str);
529 static void test_basic_string_char_rfind(void) {
530 struct rfind_char_test {
539 basic_string_char str;
541 struct rfind_char_test tests[] = {
542 { "", "a", 0, 1, *p_basic_string_char_npos }, /* empty string */
543 { "a", "", 0, 0, 0 }, /* empty find */
544 { "aaa", "aaa", 0, 3, 0 }, /* simple case */
545 { "aaa", "a", 0, 1, 0 }, /* start of string */
546 { "aaa", "a", 2, 1, 2 }, /* end of string */
547 { "aaa", "a", *p_basic_string_char_npos, 1, 2 }, /* off == npos */
548 { "aaa", "z", 0, 1, *p_basic_string_char_npos } /* can't find */
551 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
552 call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
554 ret = (size_t)call_func4(p_basic_string_char_rfind_cstr_substr, &str,
555 tests[i].find, tests[i].pos, tests[i].len);
556 ok(ret == tests[i].ret, "str = '%s' find = '%s' ret = %lu\n",
557 tests[i].str, tests[i].find, (unsigned long)ret);
559 call_func1(p_basic_string_char_dtor, &str);
563 static void test_basic_string_char_replace(void) {
564 struct replace_char_test {
573 basic_string_char str;
574 basic_string_char *ret;
575 struct replace_char_test tests[] = {
576 { "", 0, 0, "", "" }, /* empty string */
577 { "", 0, 10, "", "" }, /* empty string with invalid len */
579 { "ABCDEF", 0, 0, "", "ABCDEF" }, /* replace with empty string */
580 { "ABCDEF", 0, 0, "-", "-ABCDEF"}, /* replace with 0 len */
581 { "ABCDEF", 0, 1, "-", "-BCDEF" }, /* replace 1 at beginning */
582 { "ABCDEF", 0, 3, "-", "-DEF" }, /* replace 3 at beginning */
583 { "ABCDEF", 0, 42, "-", "-" }, /* replace whole string with invalid long len */
584 { "ABCDEF", 0, *p_basic_string_char_npos, "-", "-" }, /* replace whole string with npos */
586 { "ABCDEF", 5, 0, "", "ABCDEF" }, /* replace at end with empty string */
587 { "ABCDEF", 5, 0, "-", "ABCDE-F"}, /* replace at end with 0 len */
588 { "ABCDEF", 5, 1, "-", "ABCDE-" }, /* replace 1 at end */
589 { "ABCDEF", 5, 42, "-", "ABCDE-" }, /* replace end with invalid long len */
590 { "ABCDEF", 5, *p_basic_string_char_npos, "-", "ABCDE-" }, /* replace end with npos */
592 { "ABCDEF", 6, 0, "", "ABCDEF" }, /* replace after end with empty string */
593 { "ABCDEF", 6, 0, "-", "ABCDEF-"}, /* replace after end with 0 len */
594 { "ABCDEF", 6, 1, "-", "ABCDEF-" }, /* replace 1 after end */
595 { "ABCDEF", 6, 42, "-", "ABCDEF-" }, /* replace after end with invalid long len */
596 { "ABCDEF", 6, *p_basic_string_char_npos, "-", "ABCDEF-" }, /* replace after end with npos */
599 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
600 call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
602 ret = call_func4(p_basic_string_char_replace_cstr, &str, tests[i].off, tests[i].len, tests[i].replace);
603 ok(ret == &str, "str = %p ret = %p\n", ret, &str);
604 ok(strcmp(tests[i].ret, (const char *) call_func1(p_basic_string_char_cstr, ret)) == 0, "str = %s ret = %s\n",
605 tests[i].ret, (const char *) call_func1(p_basic_string_char_cstr, ret));
607 call_func1(p_basic_string_char_dtor, &str);
611 static void test_basic_string_wchar(void) {
612 static const wchar_t test[] = { 't','e','s','t',0 };
614 basic_string_wchar str1, str2, *pstr;
616 size_t size, capacity;
618 call_func1(p_basic_string_wchar_ctor, &str1);
620 str = call_func1(p_basic_string_wchar_cstr, &str1);
621 ok(str != NULL, "str = NULL\n");
622 ok(*str == '\0', "*str = %c\n", *str);
623 str = call_func1(p_basic_string_wchar_data, &str1);
624 ok(str != NULL, "str = NULL\n");
625 ok(*str == '\0', "*str = %c\n", *str);
626 call_func1(p_basic_string_wchar_dtor, &str1);
628 pstr = call_func2(p_basic_string_wchar_ctor_cstr, &str1, test);
629 ok(pstr == &str1, "pstr != &str1\n");
630 str = call_func1(p_basic_string_wchar_cstr, &str1);
631 ok(!memcmp(str, test, 5*sizeof(wchar_t)), "str = %s\n", wine_dbgstr_w(str));
632 str = call_func1(p_basic_string_wchar_data, &str1);
633 ok(!memcmp(str, test, 5*sizeof(wchar_t)), "str = %s\n", wine_dbgstr_w(str));
634 size = (size_t)call_func1(p_basic_string_wchar_size, &str1);
635 ok(size == 4, "size = %lu\n", (unsigned long)size);
636 capacity = (size_t)call_func1(p_basic_string_wchar_capacity, &str1);
637 ok(capacity >= size, "capacity = %lu < size = %lu\n", (unsigned long)capacity, (unsigned long)size);
639 memset(&str2, 0, sizeof(basic_string_wchar));
640 pstr = call_func2(p_basic_string_wchar_copy_ctor, &str2, &str1);
641 ok(pstr == &str2, "pstr != &str2\n");
642 str = call_func1(p_basic_string_wchar_cstr, &str2);
643 ok(!memcmp(str, test, 5*sizeof(wchar_t)), "str = %s\n", wine_dbgstr_w(str));
644 str = call_func1(p_basic_string_wchar_data, &str2);
645 ok(!memcmp(str, test, 5*sizeof(wchar_t)), "str = %s\n", wine_dbgstr_w(str));
647 call_func3(p_basic_string_wchar_erase, &str2, 1, 2);
648 str = call_func1(p_basic_string_wchar_cstr, &str2);
649 ok(str[0]=='t' && str[1]=='t' && str[2]=='\0', "str = %s\n", wine_dbgstr_w(str));
650 str = call_func1(p_basic_string_wchar_data, &str2);
651 ok(str[0]=='t' && str[1]=='t' && str[2]=='\0', "str = %s\n", wine_dbgstr_w(str));
652 size = (size_t)call_func1(p_basic_string_wchar_size, &str1);
653 ok(size == 4, "size = %lu\n", (unsigned long)size);
654 capacity = (size_t)call_func1(p_basic_string_wchar_capacity, &str1);
655 ok(capacity >= size, "capacity = %lu < size = %lu\n", (unsigned long)capacity, (unsigned long)size);
657 call_func3(p_basic_string_wchar_erase, &str2, 1, 100);
658 str = call_func1(p_basic_string_wchar_cstr, &str2);
659 ok(str[0]=='t' && str[1]=='\0', "str = %s\n", wine_dbgstr_w(str));
660 str = call_func1(p_basic_string_wchar_data, &str2);
661 ok(str[0]=='t' && str[1]=='\0', "str = %s\n", wine_dbgstr_w(str));
662 size = (size_t)call_func1(p_basic_string_wchar_size, &str1);
663 ok(size == 4, "size = %lu\n", (unsigned long)size);
664 capacity = (size_t)call_func1(p_basic_string_wchar_capacity, &str1);
665 ok(capacity >= size, "capacity = %lu < size = %lu\n", (unsigned long)capacity, (unsigned long)size);
667 call_func3(p_basic_string_wchar_assign_cstr_len, &str2, test, 4);
668 str = call_func1(p_basic_string_wchar_cstr, &str2);
669 ok(!memcmp(str, test, 5*sizeof(wchar_t)), "str = %s\n", wine_dbgstr_w(str));
670 str = call_func1(p_basic_string_wchar_data, &str2);
671 ok(!memcmp(str, test, 5*sizeof(wchar_t)), "str = %s\n", wine_dbgstr_w(str));
673 call_func3(p_basic_string_wchar_assign_cstr_len, &str2, (str+1), 2);
674 str = call_func1(p_basic_string_wchar_cstr, &str2);
675 ok(str[0]=='e' && str[1]=='s' && str[2]=='\0', "str = %s\n", wine_dbgstr_w(str));
676 str = call_func1(p_basic_string_wchar_data, &str2);
677 ok(str[0]=='e' && str[1]=='s' && str[2]=='\0', "str = %s\n", wine_dbgstr_w(str));
679 call_func1(p_basic_string_wchar_dtor, &str1);
680 call_func1(p_basic_string_wchar_dtor, &str2);
683 static void test_basic_string_wchar_swap(void) {
684 basic_string_wchar str1, str2;
685 wchar_t wtmp1[32], wtmp2[32];
687 /* Swap self, local */
688 mbstowcs(wtmp1, "qwerty", 32);
689 call_func2(p_basic_string_wchar_ctor_cstr, &str1, wtmp1);
690 call_func2(p_basic_string_wchar_swap, &str1, &str1);
691 ok(wcscmp(wtmp1, (const wchar_t *) call_func1(p_basic_string_wchar_cstr, &str1)) == 0, "Invalid value of str1\n");
692 call_func2(p_basic_string_wchar_swap, &str1, &str1);
693 ok(wcscmp(wtmp1, (const wchar_t *) call_func1(p_basic_string_wchar_cstr, &str1)) == 0, "Invalid value of str1\n");
694 call_func1(p_basic_string_wchar_dtor, &str1);
696 /* str1 allocated, str2 local */
697 mbstowcs(wtmp1, "qwerty12345678901234567890", 32);
698 mbstowcs(wtmp2, "asd", 32);
699 call_func2(p_basic_string_wchar_ctor_cstr, &str1, wtmp1);
700 call_func2(p_basic_string_wchar_ctor_cstr, &str2, wtmp2);
701 call_func2(p_basic_string_wchar_swap, &str1, &str2);
702 ok(wcscmp(wtmp2, (const wchar_t *) call_func1(p_basic_string_wchar_cstr, &str1)) == 0, "Invalid value of str1\n");
703 ok(wcscmp(wtmp1, (const wchar_t *) call_func1(p_basic_string_wchar_cstr, &str2)) == 0, "Invalid value of str2\n");
704 call_func2(p_basic_string_wchar_swap, &str1, &str2);
705 ok(wcscmp(wtmp1, (const wchar_t *) call_func1(p_basic_string_wchar_cstr, &str1)) == 0, "Invalid value of str1\n");
706 ok(wcscmp(wtmp2, (const wchar_t *) call_func1(p_basic_string_wchar_cstr, &str2)) == 0, "Invalid value of str2\n");
707 call_func1(p_basic_string_wchar_dtor, &str1);
708 call_func1(p_basic_string_wchar_dtor, &str2);
716 test_basic_string_char();
717 test_basic_string_char_swap();
718 test_basic_string_char_append();
719 test_basic_string_char_compare();
720 test_basic_string_char_concatenate();
721 test_basic_string_char_find();
722 test_basic_string_char_rfind();
723 test_basic_string_char_replace();
724 test_basic_string_wchar();
725 test_basic_string_wchar_swap();
727 ok(!invalid_parameter, "invalid_parameter_handler was invoked too many times\n");