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 static void* (__cdecl *p_set_invalid_parameter_handler)(void*);
41 static basic_string_char* (WINAPI *p_basic_string_char_ctor)(void);
42 static basic_string_char* (WINAPI *p_basic_string_char_copy_ctor)(basic_string_char*);
43 static basic_string_char* (WINAPI *p_basic_string_char_ctor_cstr)(const char*);
44 static void (WINAPI *p_basic_string_char_dtor)(void);
45 static basic_string_char* (WINAPI *p_basic_string_char_erase)(size_t, size_t);
46 static basic_string_char* (WINAPI *p_basic_string_char_assign_cstr_len)(const char*, size_t);
47 static const char* (WINAPI *p_basic_string_char_cstr)(void);
49 static basic_string_char* (__cdecl *p_basic_string_char_ctor)(basic_string_char*);
50 static basic_string_char* (__cdecl *p_basic_string_char_copy_ctor)(basic_string_char*, basic_string_char*);
51 static basic_string_char* (__cdecl *p_basic_string_char_ctor_cstr)(basic_string_char*, const char*);
52 static void (__cdecl *p_basic_string_char_dtor)(basic_string_char*);
53 static basic_string_char* (__cdecl *p_basic_string_char_erase)(basic_string_char*, size_t, size_t);
54 static basic_string_char* (__cdecl *p_basic_string_char_assign_cstr_len)(basic_string_char*, const char*, size_t);
55 static const char* (__cdecl *p_basic_string_char_cstr)(basic_string_char*);
58 static int invalid_parameter = 0;
59 static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
60 const wchar_t *function, const wchar_t *file,
61 unsigned line, uintptr_t arg)
63 ok(expression == NULL, "expression is not NULL\n");
64 ok(function == NULL, "function is not NULL\n");
65 ok(file == NULL, "file is not NULL\n");
66 ok(line == 0, "line = %u\n", line);
67 ok(arg == 0, "arg = %lx\n", (UINT_PTR)arg);
71 /* Emulate a __thiscall */
74 static inline void* do_call_func1(void *func, void *_this)
76 volatile void* retval = 0;
88 static inline void* do_call_func2(void *func, void *_this, const void *arg)
90 volatile void* retval = 0;
100 return (void*)retval;
103 static inline void* do_call_func3(void *func, void *_this,
104 const void *arg1, const void *arg2)
106 volatile void* retval = 0;
117 return (void*)retval;
120 static void* do_call_func1(void *func, void *_this)
123 __asm__ __volatile__ (
125 : "=a" (ret), "=c" (dummy)
126 : "g" (func), "1" (_this)
132 static void* do_call_func2(void *func, void *_this, const void *arg)
135 __asm__ __volatile__ (
136 "pushl %3\n\tcall *%2"
137 : "=a" (ret), "=c" (dummy)
138 : "r" (func), "r" (arg), "1" (_this)
144 static void* do_call_func3(void *func, void *_this,
145 const void *arg1, const void *arg2)
148 __asm__ __volatile__ (
149 "pushl %4\n\tpushl %3\n\tcall *%2"
150 : "=a" (ret), "=c" (dummy)
151 : "r" (func), "r" (arg1), "r" (arg2), "1" (_this)
158 #define call_func1(func,_this) do_call_func1(func,_this)
159 #define call_func2(func,_this,a) do_call_func2(func,_this,(const void*)a)
160 #define call_func3(func,_this,a,b) do_call_func3(func,_this,(const void*)a,(const void*)b)
164 #define call_func1(func,_this) func(_this)
165 #define call_func2(func,_this,a) func(_this,a)
166 #define call_func3(func,_this,a,b) func(_this,a,b)
168 #endif /* __i386__ */
170 static BOOL init(void)
172 HMODULE msvcr = LoadLibraryA("msvcr90.dll");
173 HMODULE msvcp = LoadLibraryA("msvcp90.dll");
174 if(!msvcr || !msvcp) {
175 win_skip("msvcp90.dll or msvcrt90.dll not installed\n");
179 p_set_invalid_parameter_handler = (void*)GetProcAddress(msvcr, "_set_invalid_parameter_handler");
180 if(!p_set_invalid_parameter_handler) {
181 win_skip("Error setting tests environment\n");
185 p_set_invalid_parameter_handler(test_invalid_parameter_handler);
187 if(sizeof(void*) == 8) { /* 64-bit initialization */
188 p_basic_string_char_ctor = (void*)GetProcAddress(msvcp,
189 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ");
190 p_basic_string_char_copy_ctor = (void*)GetProcAddress(msvcp,
191 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@AEBV01@@Z");
192 p_basic_string_char_ctor_cstr = (void*)GetProcAddress(msvcp,
193 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@PEBD@Z");
194 p_basic_string_char_dtor = (void*)GetProcAddress(msvcp,
195 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ");
196 p_basic_string_char_erase = (void*)GetProcAddress(msvcp,
197 "?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@_K0@Z");
198 p_basic_string_char_assign_cstr_len = (void*)GetProcAddress(msvcp,
199 "?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAAEAV12@PEBD_K@Z");
200 p_basic_string_char_cstr = (void*)GetProcAddress(msvcp,
201 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAPEBDXZ");
203 p_basic_string_char_ctor = (void*)GetProcAddress(msvcp,
204 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ");
205 p_basic_string_char_copy_ctor = (void*)GetProcAddress(msvcp,
206 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z");
207 p_basic_string_char_ctor_cstr = (void*)GetProcAddress(msvcp,
208 "??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z");
209 p_basic_string_char_dtor = (void*)GetProcAddress(msvcp,
210 "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ");
211 p_basic_string_char_erase = (void*)GetProcAddress(msvcp,
212 "?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@II@Z");
213 p_basic_string_char_assign_cstr_len = (void*)GetProcAddress(msvcp,
214 "?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@PBDI@Z");
215 p_basic_string_char_cstr = (void*)GetProcAddress(msvcp,
216 "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ");
222 static void test_basic_string_char(void) {
223 basic_string_char str1, str2, *pstr;
226 if(!p_basic_string_char_ctor || !p_basic_string_char_copy_ctor
227 || !p_basic_string_char_ctor_cstr || !p_basic_string_char_dtor
228 || !p_basic_string_char_erase || !p_basic_string_char_assign_cstr_len
229 || !p_basic_string_char_cstr) {
230 win_skip("basic_string<char> unavailable\n");
234 call_func1(p_basic_string_char_ctor, &str1);
236 str = call_func1(p_basic_string_char_cstr, &str1);
237 ok(str != NULL, "str = NULL\n");
238 ok(*str == '\0', "*str = %c\n", *str);
239 call_func1(p_basic_string_char_dtor, &str1);
241 pstr = call_func2(p_basic_string_char_ctor_cstr, &str1, "test");
242 ok(pstr == &str1, "pstr != &str1\n");
243 str = call_func1(p_basic_string_char_cstr, &str1);
244 ok(!memcmp(str, "test", 5), "str = %s\n", str);
246 pstr = call_func2(p_basic_string_char_copy_ctor, &str2, &str1);
247 ok(pstr == &str2, "pstr != &str2\n");
248 str = call_func1(p_basic_string_char_cstr, &str2);
249 ok(!memcmp(str, "test", 5), "str = %s\n", str);
251 call_func3(p_basic_string_char_erase, &str2, 1, 2);
252 str = call_func1(p_basic_string_char_cstr, &str2);
253 ok(!memcmp(str, "tt", 3), "str = %s\n", str);
255 call_func3(p_basic_string_char_erase, &str2, 1, 100);
256 str = call_func1(p_basic_string_char_cstr, &str2);
257 ok(!memcmp(str, "t", 2), "str = %s\n", str);
259 call_func3(p_basic_string_char_assign_cstr_len, &str2, "test", 4);
260 str = call_func1(p_basic_string_char_cstr, &str2);
261 ok(!memcmp(str, "test", 5), "str = %s\n", str);
263 call_func3(p_basic_string_char_assign_cstr_len, &str2, (str+1), 2);
264 str = call_func1(p_basic_string_char_cstr, &str2);
265 ok(!memcmp(str, "es", 3), "str = %s\n", str);
267 call_func1(p_basic_string_char_dtor, &str1);
268 call_func1(p_basic_string_char_dtor, &str2);
276 test_basic_string_char();
278 ok(!invalid_parameter, "invalid_parameter_handler was invoked too many times\n");