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*);
56 #define __thiscall __stdcall
58 #define __thiscall __cdecl
61 static basic_string_char* (__thiscall *p_basic_string_char_ctor)(basic_string_char*);
62 static basic_string_char* (__thiscall *p_basic_string_char_copy_ctor)(basic_string_char*, basic_string_char*);
63 static basic_string_char* (__thiscall *p_basic_string_char_ctor_cstr)(basic_string_char*, const char*);
64 static void (__thiscall *p_basic_string_char_dtor)(basic_string_char*);
65 static basic_string_char* (__thiscall *p_basic_string_char_erase)(basic_string_char*, size_t, size_t);
66 static basic_string_char* (__thiscall *p_basic_string_char_assign_cstr_len)(basic_string_char*, const char*, size_t);
67 static const char* (__thiscall *p_basic_string_char_cstr)(basic_string_char*);
68 static const char* (__thiscall *p_basic_string_char_data)(basic_string_char*);
69 static size_t (__thiscall *p_basic_string_char_size)(basic_string_char*);
70 static size_t (__thiscall *p_basic_string_char_capacity)(basic_string_char*);
71 static void (__thiscall *p_basic_string_char_swap)(basic_string_char*, basic_string_char*);
72 static basic_string_char* (__thiscall *p_basic_string_char_append)(basic_string_char*, basic_string_char*);
73 static basic_string_char* (__thiscall *p_basic_string_char_append_substr)(basic_string_char*, basic_string_char*, size_t, size_t);
74 static int (__thiscall *p_basic_string_char_compare_substr_substr)(basic_string_char*, size_t, size_t, basic_string_char*, size_t, size_t);
75 static int (__thiscall *p_basic_string_char_compare_substr_cstr_len)(basic_string_char*, size_t, size_t, const char*, size_t);
76 static size_t (__thiscall *p_basic_string_char_find_cstr_substr)(basic_string_char*, const char*, size_t, size_t);
77 static size_t (__thiscall *p_basic_string_char_rfind_cstr_substr)(basic_string_char*, const char*, size_t, size_t);
79 static size_t *p_basic_string_char_npos;
81 static basic_string_wchar* (__thiscall *p_basic_string_wchar_ctor)(basic_string_wchar*);
82 static basic_string_wchar* (__thiscall *p_basic_string_wchar_copy_ctor)(basic_string_wchar*, basic_string_wchar*);
83 static basic_string_wchar* (__thiscall *p_basic_string_wchar_ctor_cstr)(basic_string_wchar*, const wchar_t*);
84 static void (__thiscall *p_basic_string_wchar_dtor)(basic_string_wchar*);
85 static basic_string_wchar* (__thiscall *p_basic_string_wchar_erase)(basic_string_wchar*, size_t, size_t);
86 static basic_string_wchar* (__thiscall *p_basic_string_wchar_assign_cstr_len)(basic_string_wchar*, const wchar_t*, size_t);
87 static const wchar_t* (__thiscall *p_basic_string_wchar_cstr)(basic_string_wchar*);
88 static const wchar_t* (__thiscall *p_basic_string_wchar_data)(basic_string_wchar*);
89 static size_t (__thiscall *p_basic_string_wchar_size)(basic_string_wchar*);
90 static size_t (__thiscall *p_basic_string_wchar_capacity)(basic_string_wchar*);
91 static void (__thiscall *p_basic_string_wchar_swap)(basic_string_wchar*, basic_string_wchar*);
93 static int invalid_parameter = 0;
94 static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
95 const wchar_t *function, const wchar_t *file,
96 unsigned line, uintptr_t arg)
98 ok(expression == NULL, "expression is not NULL\n");
99 ok(function == NULL, "function is not NULL\n");
100 ok(file == NULL, "file is not NULL\n");
101 ok(line == 0, "line = %u\n", line);
102 ok(arg == 0, "arg = %lx\n", (UINT_PTR)arg);
106 /* Emulate a __thiscall */
109 #include "pshpack1.h"
110 struct thiscall_thunk
112 BYTE pop_eax; /* popl %eax (ret addr) */
113 BYTE pop_edx; /* popl %edx (func) */
114 BYTE pop_ecx; /* popl %ecx (this) */
115 BYTE push_eax; /* pushl %eax */
116 WORD jmp_edx; /* jmp *%edx */
120 static void * (WINAPI *call_thiscall_func1)( void *func, void *this );
121 static void * (WINAPI *call_thiscall_func2)( void *func, void *this, const void *a );
122 static void * (WINAPI *call_thiscall_func3)( void *func, void *this, const void *a, const void *b );
123 static void * (WINAPI *call_thiscall_func4)( void *func, void *this, const void *a, const void *b,
125 static void * (WINAPI *call_thiscall_func5)( void *func, void *this, const void *a, const void *b,
126 const void *c, const void *d );
127 static void * (WINAPI *call_thiscall_func6)( void *func, void *this, const void *a, const void *b,
128 const void *c, const void *d, const void *e );
130 static void init_thiscall_thunk(void)
132 struct thiscall_thunk *thunk = VirtualAlloc( NULL, sizeof(*thunk),
133 MEM_COMMIT, PAGE_EXECUTE_READWRITE );
134 thunk->pop_eax = 0x58; /* popl %eax */
135 thunk->pop_edx = 0x5a; /* popl %edx */
136 thunk->pop_ecx = 0x59; /* popl %ecx */
137 thunk->push_eax = 0x50; /* pushl %eax */
138 thunk->jmp_edx = 0xe2ff; /* jmp *%edx */
139 call_thiscall_func1 = (void *)thunk;
140 call_thiscall_func2 = (void *)thunk;
141 call_thiscall_func3 = (void *)thunk;
142 call_thiscall_func4 = (void *)thunk;
143 call_thiscall_func5 = (void *)thunk;
144 call_thiscall_func6 = (void *)thunk;
147 #define call_func1(func,_this) call_thiscall_func1(func,_this)
148 #define call_func2(func,_this,a) call_thiscall_func2(func,_this,(const void*)a)
149 #define call_func3(func,_this,a,b) call_thiscall_func3(func,_this,(const void*)a,(const void*)b)
150 #define call_func4(func,_this,a,b,c) call_thiscall_func4(func,_this,(const void*)a,\
151 (const void*)b,(const void*)c)
152 #define call_func5(func,_this,a,b,c,d) call_thiscall_func5(func,_this,(const void*)a,\
153 (const void*)b,(const void*)c,(const void*)d)
154 #define call_func6(func,_this,a,b,c,d,e) call_thiscall_func6(func,_this,(const void*)a,\
155 (const void*)b,(const void*)c,(const void*)d,(const void*)e)
159 #define init_thiscall_thunk()
160 #define call_func1(func,_this) func(_this)
161 #define call_func2(func,_this,a) func(_this,a)
162 #define call_func3(func,_this,a,b) func(_this,a,b)
163 #define call_func4(func,_this,a,b,c) func(_this,a,b,c)
164 #define call_func5(func,_this,a,b,c,d) func(_this,a,b,c,d)
165 #define call_func6(func,_this,a,b,c,d,e) func(_this,a,b,c,d,e)
167 #endif /* __i386__ */
169 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
170 #define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
171 static BOOL init(void)
173 HMODULE msvcr = LoadLibraryA("msvcr90.dll");
174 HMODULE msvcp = LoadLibraryA("msvcp90.dll");
175 if(!msvcr || !msvcp) {
176 win_skip("msvcp90.dll or msvcrt90.dll not installed\n");
180 p_set_invalid_parameter_handler = (void*)GetProcAddress(msvcr, "_set_invalid_parameter_handler");
181 if(!p_set_invalid_parameter_handler) {
182 win_skip("Error setting tests environment\n");
186 p_set_invalid_parameter_handler(test_invalid_parameter_handler);
188 if(sizeof(void*) == 8) { /* 64-bit initialization */
189 SET(p_basic_string_char_ctor,
190 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ");
191 SET(p_basic_string_char_copy_ctor,
192 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@AEBV01@@Z");
193 SET(p_basic_string_char_ctor_cstr,
194 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@PEBD@Z");
195 SET(p_basic_string_char_dtor,
196 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ");
197 SET(p_basic_string_char_erase,
198 "?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@_K0@Z");
199 SET(p_basic_string_char_assign_cstr_len,
200 "?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@PEBD_K@Z");
201 SET(p_basic_string_char_cstr,
202 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAPEBDXZ");
203 SET(p_basic_string_char_data,
204 "?data@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAPEBDXZ");
205 SET(p_basic_string_char_size,
206 "?size@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBA_KXZ");
207 SET(p_basic_string_char_capacity,
208 "?capacity@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBA_KXZ");
209 SET(p_basic_string_char_swap,
210 "?swap@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAXAEAV12@@Z");
211 SET(p_basic_string_char_append,
212 "?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@AEBV12@@Z");
213 SET(p_basic_string_char_append_substr,
214 "?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@AEBV12@_K1@Z");
215 SET(p_basic_string_char_compare_substr_substr,
216 "?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAH_K0AEBV12@00@Z");
217 SET(p_basic_string_char_compare_substr_cstr_len,
218 "?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAH_K0PEBD0@Z");
219 SET(p_basic_string_char_concatenate,
220 "??$?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");
221 SET(p_basic_string_char_concatenate_cstr,
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@PEBD@Z");
223 SET(p_basic_string_char_find_cstr_substr,
224 "?find@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBA_KPEBD_K1@Z");
225 SET(p_basic_string_char_rfind_cstr_substr,
226 "?rfind@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBA_KPEBD_K1@Z");
227 SET(p_basic_string_char_npos,
228 "?npos@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@2_KB");
230 SET(p_basic_string_wchar_ctor,
231 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@XZ");
232 SET(p_basic_string_wchar_copy_ctor,
233 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@AEBV01@@Z");
234 SET(p_basic_string_wchar_ctor_cstr,
235 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@PEB_W@Z");
236 SET(p_basic_string_wchar_dtor,
237 "??1?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAA@XZ");
238 SET(p_basic_string_wchar_erase,
239 "?erase@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAAEAV12@_K0@Z");
240 SET(p_basic_string_wchar_assign_cstr_len,
241 "?assign@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAAEAV12@PEB_W_K@Z");
242 SET(p_basic_string_wchar_cstr,
243 "?c_str@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBAPEB_WXZ");
244 SET(p_basic_string_wchar_data,
245 "?data@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBAPEB_WXZ");
246 SET(p_basic_string_wchar_size,
247 "?size@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBA_KXZ");
248 SET(p_basic_string_wchar_capacity,
249 "?capacity@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEBA_KXZ");
250 SET(p_basic_string_wchar_swap,
251 "?swap@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QEAAXAEAV12@@Z");
253 SET(p_basic_string_char_ctor,
254 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ");
255 SET(p_basic_string_char_copy_ctor,
256 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z");
257 SET(p_basic_string_char_ctor_cstr,
258 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z");
259 SET(p_basic_string_char_dtor,
260 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ");
261 SET(p_basic_string_char_erase,
262 "?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@II@Z");
263 SET(p_basic_string_char_assign_cstr_len,
264 "?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@PBDI@Z");
265 SET(p_basic_string_char_cstr,
266 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ");
267 SET(p_basic_string_char_data,
268 "?data@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ");
269 SET(p_basic_string_char_size,
270 "?size@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIXZ");
271 SET(p_basic_string_char_capacity,
272 "?capacity@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIXZ");
273 SET(p_basic_string_char_swap,
274 "?swap@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXAAV12@@Z");
275 SET(p_basic_string_char_append,
276 "?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@ABV12@@Z");
277 SET(p_basic_string_char_append_substr,
278 "?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@ABV12@II@Z");
279 SET(p_basic_string_char_compare_substr_substr,
280 "?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEHIIABV12@II@Z");
281 SET(p_basic_string_char_compare_substr_cstr_len,
282 "?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEHIIPBDI@Z");
283 SET(p_basic_string_char_concatenate,
284 "??$?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");
285 SET(p_basic_string_char_concatenate_cstr,
286 "??$?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");
287 SET(p_basic_string_char_find_cstr_substr,
288 "?find@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIPBDII@Z");
289 SET(p_basic_string_char_rfind_cstr_substr,
290 "?rfind@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIPBDII@Z");
291 SET(p_basic_string_char_npos,
292 "?npos@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@2IB");
294 SET(p_basic_string_wchar_ctor,
295 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@XZ");
296 SET(p_basic_string_wchar_copy_ctor,
297 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@ABV01@@Z");
298 SET(p_basic_string_wchar_ctor_cstr,
299 "??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@PB_W@Z");
300 SET(p_basic_string_wchar_dtor,
301 "??1?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@XZ");
302 SET(p_basic_string_wchar_erase,
303 "?erase@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEAAV12@II@Z");
304 SET(p_basic_string_wchar_assign_cstr_len,
305 "?assign@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEAAV12@PB_WI@Z");
306 SET(p_basic_string_wchar_cstr,
307 "?c_str@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEPB_WXZ");
308 SET(p_basic_string_wchar_data,
309 "?data@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEPB_WXZ");
310 SET(p_basic_string_wchar_size,
311 "?size@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEIXZ");
312 SET(p_basic_string_wchar_capacity,
313 "?capacity@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEIXZ");
314 SET(p_basic_string_wchar_swap,
315 "?swap@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAEXAAV12@@Z");
318 init_thiscall_thunk();
322 static void test_basic_string_char(void) {
323 basic_string_char str1, str2, *pstr;
325 size_t size, capacity;
327 call_func1(p_basic_string_char_ctor, &str1);
329 str = call_func1(p_basic_string_char_cstr, &str1);
330 ok(str != NULL, "str = NULL\n");
331 ok(*str == '\0', "*str = %c\n", *str);
332 str = call_func1(p_basic_string_char_data, &str1);
333 ok(str != NULL, "str = NULL\n");
334 ok(*str == '\0', "*str = %c\n", *str);
335 call_func1(p_basic_string_char_dtor, &str1);
337 pstr = call_func2(p_basic_string_char_ctor_cstr, &str1, "test");
338 ok(pstr == &str1, "pstr != &str1\n");
339 str = call_func1(p_basic_string_char_cstr, &str1);
340 ok(!memcmp(str, "test", 5), "str = %s\n", str);
341 str = call_func1(p_basic_string_char_data, &str1);
342 ok(!memcmp(str, "test", 5), "str = %s\n", str);
343 size = (size_t)call_func1(p_basic_string_char_size, &str1);
344 ok(size == 4, "size = %lu\n", (unsigned long)size);
345 capacity = (size_t)call_func1(p_basic_string_char_capacity, &str1);
346 ok(capacity >= size, "capacity = %lu < size = %lu\n", (unsigned long)capacity, (unsigned long)size);
348 pstr = call_func2(p_basic_string_char_copy_ctor, &str2, &str1);
349 ok(pstr == &str2, "pstr != &str2\n");
350 str = call_func1(p_basic_string_char_cstr, &str2);
351 ok(!memcmp(str, "test", 5), "str = %s\n", str);
352 str = call_func1(p_basic_string_char_data, &str2);
353 ok(!memcmp(str, "test", 5), "str = %s\n", str);
355 call_func3(p_basic_string_char_erase, &str2, 1, 2);
356 str = call_func1(p_basic_string_char_cstr, &str2);
357 ok(!memcmp(str, "tt", 3), "str = %s\n", str);
358 str = call_func1(p_basic_string_char_data, &str2);
359 ok(!memcmp(str, "tt", 3), "str = %s\n", str);
360 size = (size_t)call_func1(p_basic_string_char_size, &str1);
361 ok(size == 4, "size = %lu\n", (unsigned long)size);
362 capacity = (size_t)call_func1(p_basic_string_char_capacity, &str1);
363 ok(capacity >= size, "capacity = %lu < size = %lu\n", (unsigned long)capacity, (unsigned long)size);
365 call_func3(p_basic_string_char_erase, &str2, 1, 100);
366 str = call_func1(p_basic_string_char_cstr, &str2);
367 ok(!memcmp(str, "t", 2), "str = %s\n", str);
368 str = call_func1(p_basic_string_char_data, &str2);
369 ok(!memcmp(str, "t", 2), "str = %s\n", str);
370 size = (size_t)call_func1(p_basic_string_char_size, &str1);
371 ok(size == 4, "size = %lu\n", (unsigned long)size);
372 capacity = (size_t)call_func1(p_basic_string_char_capacity, &str1);
373 ok(capacity >= size, "capacity = %lu < size = %lu\n", (unsigned long)capacity, (unsigned long)size);
375 call_func3(p_basic_string_char_assign_cstr_len, &str2, "test", 4);
376 str = call_func1(p_basic_string_char_cstr, &str2);
377 ok(!memcmp(str, "test", 5), "str = %s\n", str);
378 str = call_func1(p_basic_string_char_data, &str2);
379 ok(!memcmp(str, "test", 5), "str = %s\n", str);
381 call_func3(p_basic_string_char_assign_cstr_len, &str2, (str+1), 2);
382 str = call_func1(p_basic_string_char_cstr, &str2);
383 ok(!memcmp(str, "es", 3), "str = %s\n", str);
384 str = call_func1(p_basic_string_char_data, &str2);
385 ok(!memcmp(str, "es", 3), "str = %s\n", str);
387 call_func1(p_basic_string_char_dtor, &str1);
388 call_func1(p_basic_string_char_dtor, &str2);
391 static void test_basic_string_char_swap(void) {
392 basic_string_char str1, str2;
393 char atmp1[32], atmp2[32];
395 /* Swap self, local */
396 strcpy(atmp1, "qwerty");
397 call_func2(p_basic_string_char_ctor_cstr, &str1, atmp1);
398 call_func2(p_basic_string_char_swap, &str1, &str1);
399 ok(strcmp(atmp1, (const char *) call_func1(p_basic_string_char_cstr, &str1)) == 0, "Invalid value of str1\n");
400 call_func2(p_basic_string_char_swap, &str1, &str1);
401 ok(strcmp(atmp1, (const char *) call_func1(p_basic_string_char_cstr, &str1)) == 0, "Invalid value of str1\n");
402 call_func1(p_basic_string_char_dtor, &str1);
404 /* str1 allocated, str2 local */
405 strcpy(atmp1, "qwerty12345678901234567890");
406 strcpy(atmp2, "asd");
407 call_func2(p_basic_string_char_ctor_cstr, &str1, atmp1);
408 call_func2(p_basic_string_char_ctor_cstr, &str2, atmp2);
409 call_func2(p_basic_string_char_swap, &str1, &str2);
410 ok(strcmp(atmp2, (const char *) call_func1(p_basic_string_char_cstr, &str1)) == 0, "Invalid value of str1\n");
411 ok(strcmp(atmp1, (const char *) call_func1(p_basic_string_char_cstr, &str2)) == 0, "Invalid value of str2\n");
412 call_func2(p_basic_string_char_swap, &str1, &str2);
413 ok(strcmp(atmp1, (const char *) call_func1(p_basic_string_char_cstr, &str1)) == 0, "Invalid value of str1\n");
414 ok(strcmp(atmp2, (const char *) call_func1(p_basic_string_char_cstr, &str2)) == 0, "Invalid value of str2\n");
415 call_func1(p_basic_string_char_dtor, &str1);
416 call_func1(p_basic_string_char_dtor, &str2);
419 static void test_basic_string_char_append(void) {
420 basic_string_char str1, str2;
423 call_func2(p_basic_string_char_ctor_cstr, &str1, "");
424 call_func2(p_basic_string_char_ctor_cstr, &str2, "append");
426 call_func2(p_basic_string_char_append, &str1, &str2);
427 str = call_func1(p_basic_string_char_cstr, &str1);
428 ok(!memcmp(str, "append", 7), "str = %s\n", str);
430 call_func4(p_basic_string_char_append_substr, &str1, &str2, 3, 1);
431 str = call_func1(p_basic_string_char_cstr, &str1);
432 ok(!memcmp(str, "appende", 8), "str = %s\n", str);
434 call_func4(p_basic_string_char_append_substr, &str1, &str2, 5, 100);
435 str = call_func1(p_basic_string_char_cstr, &str1);
436 ok(!memcmp(str, "appended", 9), "str = %s\n", str);
438 call_func4(p_basic_string_char_append_substr, &str1, &str2, 6, 100);
439 str = call_func1(p_basic_string_char_cstr, &str1);
440 ok(!memcmp(str, "appended", 9), "str = %s\n", str);
442 call_func1(p_basic_string_char_dtor, &str1);
443 call_func1(p_basic_string_char_dtor, &str2);
446 static void test_basic_string_char_compare(void) {
447 basic_string_char str1, str2;
450 call_func2(p_basic_string_char_ctor_cstr, &str1, "str1str");
451 call_func2(p_basic_string_char_ctor_cstr, &str2, "str9str");
453 ret = (int)call_func6(p_basic_string_char_compare_substr_substr,
454 &str1, 0, 3, &str2, 0, 3);
455 ok(ret == 0, "ret = %d\n", ret);
456 ret = (int)call_func6(p_basic_string_char_compare_substr_substr,
457 &str1, 4, 3, &str2, 4, 10);
458 ok(ret == 0, "ret = %d\n", ret);
459 ret = (int)call_func6(p_basic_string_char_compare_substr_substr,
460 &str1, 1, 3, &str2, 1, 4);
461 ok(ret == -1, "ret = %d\n", ret);
463 ret = (int)call_func5(p_basic_string_char_compare_substr_cstr_len,
464 &str1, 0, 1000, "str1str", 7);
465 ok(ret == 0, "ret = %d\n", ret);
466 ret = (int)call_func5(p_basic_string_char_compare_substr_cstr_len,
467 &str1, 1, 2, "tr", 2);
468 ok(ret == 0, "ret = %d\n", ret);
469 ret = (int)call_func5(p_basic_string_char_compare_substr_cstr_len,
470 &str1, 1, 0, "aaa", 0);
471 ok(ret == 0, "ret = %d\n", ret);
472 ret = (int)call_func5(p_basic_string_char_compare_substr_cstr_len,
473 &str1, 1, 0, "aaa", 1);
474 ok(ret == -1, "ret = %d\n", ret);
476 call_func1(p_basic_string_char_dtor, &str1);
477 call_func1(p_basic_string_char_dtor, &str2);
480 static void test_basic_string_char_concatenate(void) {
481 basic_string_char str, ret;
484 call_func2(p_basic_string_char_ctor_cstr, &str, "test ");
485 /* CDECL calling convention with return bigger than 8 bytes */
486 p_basic_string_char_concatenate(&ret, &str, &str);
487 cstr = call_func1(p_basic_string_char_cstr, &ret);
488 ok(cstr != NULL, "cstr = NULL\n");
489 ok(!strcmp(cstr, "test test "), "cstr = %s\n", cstr);
490 call_func1(p_basic_string_char_dtor, &ret);
492 p_basic_string_char_concatenate_cstr(&ret, &str, "passed");
493 cstr = call_func1(p_basic_string_char_cstr, &ret);
494 ok(cstr != NULL, "cstr = NULL\n");
495 ok(!strcmp(cstr, "test passed"), "cstr = %s\n", cstr);
496 call_func1(p_basic_string_char_dtor, &ret);
498 call_func1(p_basic_string_char_dtor, &str);
501 static void test_basic_string_char_find(void) {
502 static const char tmp[] = {'a','a','a','\0','b','b','b',0};
503 basic_string_char str;
506 call_func1(p_basic_string_char_ctor, &str);
507 call_func3(p_basic_string_char_assign_cstr_len, &str, tmp, 7);
508 ret = (size_t)call_func4(p_basic_string_char_find_cstr_substr, &str, "aaa", 0, 3);
509 ok(ret == 0, "ret = %lu\n", (unsigned long)ret);
510 ret = (size_t)call_func4(p_basic_string_char_find_cstr_substr, &str, "aaa", 1, 3);
511 ok(ret == -1, "ret = %lu\n", (unsigned long)ret);
512 ret = (size_t)call_func4(p_basic_string_char_find_cstr_substr, &str, "bbb", 0, 3);
513 ok(ret == 4, "ret = %lu\n", (unsigned long)ret);
514 call_func1(p_basic_string_char_dtor, &str);
517 static void test_basic_string_char_rfind(void) {
518 struct rfind_char_test {
527 basic_string_char str;
529 struct rfind_char_test tests[] = {
530 { "", "a", 0, 1, *p_basic_string_char_npos }, /* empty string */
531 { "a", "", 0, 0, 0 }, /* empty find */
532 { "aaa", "aaa", 0, 3, 0 }, /* simple case */
533 { "aaa", "a", 0, 1, 0 }, /* start of string */
534 { "aaa", "a", 2, 1, 2 }, /* end of string */
535 { "aaa", "a", *p_basic_string_char_npos, 1, 2 }, /* off == npos */
536 { "aaa", "z", 0, 1, *p_basic_string_char_npos } /* can't find */
539 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
540 call_func2(p_basic_string_char_ctor_cstr, &str, tests[i].str);
542 ret = (size_t)call_func4(p_basic_string_char_rfind_cstr_substr, &str,
543 tests[i].find, tests[i].pos, tests[i].len);
544 ok(ret == tests[i].ret, "str = '%s' find = '%s' ret = %lu\n",
545 tests[i].str, tests[i].find, (unsigned long)ret);
547 call_func1(p_basic_string_char_dtor, &str);
551 static void test_basic_string_wchar(void) {
552 static const wchar_t test[] = { 't','e','s','t',0 };
554 basic_string_wchar str1, str2, *pstr;
556 size_t size, capacity;
558 call_func1(p_basic_string_wchar_ctor, &str1);
560 str = call_func1(p_basic_string_wchar_cstr, &str1);
561 ok(str != NULL, "str = NULL\n");
562 ok(*str == '\0', "*str = %c\n", *str);
563 str = call_func1(p_basic_string_wchar_data, &str1);
564 ok(str != NULL, "str = NULL\n");
565 ok(*str == '\0', "*str = %c\n", *str);
566 call_func1(p_basic_string_wchar_dtor, &str1);
568 pstr = call_func2(p_basic_string_wchar_ctor_cstr, &str1, test);
569 ok(pstr == &str1, "pstr != &str1\n");
570 str = call_func1(p_basic_string_wchar_cstr, &str1);
571 ok(!memcmp(str, test, 5*sizeof(wchar_t)), "str = %s\n", wine_dbgstr_w(str));
572 str = call_func1(p_basic_string_wchar_data, &str1);
573 ok(!memcmp(str, test, 5*sizeof(wchar_t)), "str = %s\n", wine_dbgstr_w(str));
574 size = (size_t)call_func1(p_basic_string_wchar_size, &str1);
575 ok(size == 4, "size = %lu\n", (unsigned long)size);
576 capacity = (size_t)call_func1(p_basic_string_wchar_capacity, &str1);
577 ok(capacity >= size, "capacity = %lu < size = %lu\n", (unsigned long)capacity, (unsigned long)size);
579 memset(&str2, 0, sizeof(basic_string_wchar));
580 pstr = call_func2(p_basic_string_wchar_copy_ctor, &str2, &str1);
581 ok(pstr == &str2, "pstr != &str2\n");
582 str = call_func1(p_basic_string_wchar_cstr, &str2);
583 ok(!memcmp(str, test, 5*sizeof(wchar_t)), "str = %s\n", wine_dbgstr_w(str));
584 str = call_func1(p_basic_string_wchar_data, &str2);
585 ok(!memcmp(str, test, 5*sizeof(wchar_t)), "str = %s\n", wine_dbgstr_w(str));
587 call_func3(p_basic_string_wchar_erase, &str2, 1, 2);
588 str = call_func1(p_basic_string_wchar_cstr, &str2);
589 ok(str[0]=='t' && str[1]=='t' && str[2]=='\0', "str = %s\n", wine_dbgstr_w(str));
590 str = call_func1(p_basic_string_wchar_data, &str2);
591 ok(str[0]=='t' && str[1]=='t' && str[2]=='\0', "str = %s\n", wine_dbgstr_w(str));
592 size = (size_t)call_func1(p_basic_string_wchar_size, &str1);
593 ok(size == 4, "size = %lu\n", (unsigned long)size);
594 capacity = (size_t)call_func1(p_basic_string_wchar_capacity, &str1);
595 ok(capacity >= size, "capacity = %lu < size = %lu\n", (unsigned long)capacity, (unsigned long)size);
597 call_func3(p_basic_string_wchar_erase, &str2, 1, 100);
598 str = call_func1(p_basic_string_wchar_cstr, &str2);
599 ok(str[0]=='t' && str[1]=='\0', "str = %s\n", wine_dbgstr_w(str));
600 str = call_func1(p_basic_string_wchar_data, &str2);
601 ok(str[0]=='t' && str[1]=='\0', "str = %s\n", wine_dbgstr_w(str));
602 size = (size_t)call_func1(p_basic_string_wchar_size, &str1);
603 ok(size == 4, "size = %lu\n", (unsigned long)size);
604 capacity = (size_t)call_func1(p_basic_string_wchar_capacity, &str1);
605 ok(capacity >= size, "capacity = %lu < size = %lu\n", (unsigned long)capacity, (unsigned long)size);
607 call_func3(p_basic_string_wchar_assign_cstr_len, &str2, test, 4);
608 str = call_func1(p_basic_string_wchar_cstr, &str2);
609 ok(!memcmp(str, test, 5*sizeof(wchar_t)), "str = %s\n", wine_dbgstr_w(str));
610 str = call_func1(p_basic_string_wchar_data, &str2);
611 ok(!memcmp(str, test, 5*sizeof(wchar_t)), "str = %s\n", wine_dbgstr_w(str));
613 call_func3(p_basic_string_wchar_assign_cstr_len, &str2, (str+1), 2);
614 str = call_func1(p_basic_string_wchar_cstr, &str2);
615 ok(str[0]=='e' && str[1]=='s' && str[2]=='\0', "str = %s\n", wine_dbgstr_w(str));
616 str = call_func1(p_basic_string_wchar_data, &str2);
617 ok(str[0]=='e' && str[1]=='s' && str[2]=='\0', "str = %s\n", wine_dbgstr_w(str));
619 call_func1(p_basic_string_wchar_dtor, &str1);
620 call_func1(p_basic_string_wchar_dtor, &str2);
623 static void test_basic_string_wchar_swap(void) {
624 basic_string_wchar str1, str2;
625 wchar_t wtmp1[32], wtmp2[32];
627 /* Swap self, local */
628 mbstowcs(wtmp1, "qwerty", 32);
629 call_func2(p_basic_string_wchar_ctor_cstr, &str1, wtmp1);
630 call_func2(p_basic_string_wchar_swap, &str1, &str1);
631 ok(wcscmp(wtmp1, (const wchar_t *) call_func1(p_basic_string_wchar_cstr, &str1)) == 0, "Invalid value of str1\n");
632 call_func2(p_basic_string_wchar_swap, &str1, &str1);
633 ok(wcscmp(wtmp1, (const wchar_t *) call_func1(p_basic_string_wchar_cstr, &str1)) == 0, "Invalid value of str1\n");
634 call_func1(p_basic_string_wchar_dtor, &str1);
636 /* str1 allocated, str2 local */
637 mbstowcs(wtmp1, "qwerty12345678901234567890", 32);
638 mbstowcs(wtmp2, "asd", 32);
639 call_func2(p_basic_string_wchar_ctor_cstr, &str1, wtmp1);
640 call_func2(p_basic_string_wchar_ctor_cstr, &str2, wtmp2);
641 call_func2(p_basic_string_wchar_swap, &str1, &str2);
642 ok(wcscmp(wtmp2, (const wchar_t *) call_func1(p_basic_string_wchar_cstr, &str1)) == 0, "Invalid value of str1\n");
643 ok(wcscmp(wtmp1, (const wchar_t *) call_func1(p_basic_string_wchar_cstr, &str2)) == 0, "Invalid value of str2\n");
644 call_func2(p_basic_string_wchar_swap, &str1, &str2);
645 ok(wcscmp(wtmp1, (const wchar_t *) call_func1(p_basic_string_wchar_cstr, &str1)) == 0, "Invalid value of str1\n");
646 ok(wcscmp(wtmp2, (const wchar_t *) call_func1(p_basic_string_wchar_cstr, &str2)) == 0, "Invalid value of str2\n");
647 call_func1(p_basic_string_wchar_dtor, &str1);
648 call_func1(p_basic_string_wchar_dtor, &str2);
656 test_basic_string_char();
657 test_basic_string_char_swap();
658 test_basic_string_char_append();
659 test_basic_string_char_compare();
660 test_basic_string_char_concatenate();
661 test_basic_string_char_find();
662 test_basic_string_char_rfind();
663 test_basic_string_wchar();
664 test_basic_string_wchar_swap();
666 ok(!invalid_parameter, "invalid_parameter_handler was invoked too many times\n");