misc.c 44.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright 2010 Piotr Caban for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include <stdio.h>
20
#include <locale.h>
21
#include <wctype.h>
22
#include <math.h>
23
#include <float.h>
24
#include <errno.h>
25 26 27 28 29

#include <windef.h>
#include <winbase.h>
#include "wine/test.h"

30 31 32 33 34 35 36
static inline float __port_ind(void)
{
        static const unsigned __ind_bytes = 0xffc00000;
            return *(const float *)&__ind_bytes;
}
#define IND __port_ind()

37 38
typedef double LDOUBLE;  /* long double is just a double */

39 40 41 42 43 44 45
typedef struct {
    LCID handle;
    unsigned page;
    short *table;
    int delfl;
} MSVCP__Ctypevec;

46 47 48 49 50
typedef struct {
    LCID handle;
    unsigned page;
} MSVCP__Collvec;

51 52 53 54 55 56 57 58 59 60 61 62 63
/* basic_string<char, char_traits<char>, allocator<char>> */
#define BUF_SIZE_CHAR 16
typedef struct
{
    void *allocator;
    union {
        char buf[BUF_SIZE_CHAR];
        char *ptr;
    } data;
    size_t size;
    size_t res;
} basic_string_char;

64 65 66 67 68 69
/* class complex<float> */
typedef struct {
    float real;
    float imag;
} complex_float;

70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
typedef struct {
    void *vtable;
    size_t refs;
} locale_facet;

typedef unsigned char MSVCP_bool;

typedef struct _locale__Locimp {
    locale_facet facet;
    locale_facet **facetvec;
    size_t facet_cnt;
    int catmask;
    MSVCP_bool transparent;
    basic_string_char name;
} locale__Locimp;

86
static void* (__cdecl *p_set_invalid_parameter_handler)(void*);
87
static _locale_t (__cdecl *p__get_current_locale)(void);
88
static void (__cdecl *p__free_locale)(_locale_t);
89
static void  (__cdecl *p_free)(void*);
90
static int * (__cdecl *p_errno)(void);
91 92 93 94 95

static void (__cdecl *p_char_assign)(void*, const void*);
static void (__cdecl *p_wchar_assign)(void*, const void*);
static void (__cdecl *p_short_assign)(void*, const void*);

96 97 98 99
static BYTE (__cdecl *p_char_eq)(const void*, const void*);
static BYTE (__cdecl *p_wchar_eq)(const void*, const void*);
static BYTE (__cdecl *p_short_eq)(const void*, const void*);

100
static char* (__cdecl *p_Copy_s)(char*, size_t, const char*, size_t);
101

102
static unsigned short (__cdecl *p_wctype)(const char*);
103
static MSVCP__Ctypevec* (__cdecl *p__Getctype)(MSVCP__Ctypevec*);
104
static /*MSVCP__Collvec*/ULONGLONG (__cdecl *p__Getcoll)(void);
105 106
static wctrans_t (__cdecl *p_wctrans)(const char*);
static wint_t (__cdecl *p_towctrans)(wint_t, wctrans_t);
107
static void (__cdecl *p_locale__Locimp__Locimp_Addfac)(locale__Locimp*,locale_facet*,size_t);
108
static size_t (__cdecl *p__Strxfrm)(char*, char*, const char*, const char*, const MSVCP__Collvec*);
109

110
#undef __thiscall
111
#ifdef __i386__
112
#define __thiscall __stdcall
113
#else
114
#define __thiscall __cdecl
115 116
#endif

117 118 119 120 121 122 123
static char* (__thiscall *p_char_address)(void*, char*);
static void* (__thiscall *p_char_ctor)(void*);
static void (__thiscall *p_char_deallocate)(void*, char*, size_t);
static char* (__thiscall *p_char_allocate)(void*, size_t);
static void (__thiscall *p_char_construct)(void*, char*, const char*);
static size_t (__thiscall *p_char_max_size)(void*);

124 125
static void* (__thiscall *p_collate_char_ctor_refs)(void*, size_t);
static int (__thiscall *p_collate_char_compare)(const void*, const char*,
126
        const char*, const char*, const char*);
127 128 129 130
static void (__thiscall *p_collate_char_dtor)(void*);
static void* (__thiscall *p_numpunct_char_ctor)(void*);
static basic_string_char* (__thiscall *p_numpunct_char_falsename)(void*,basic_string_char*);
static void (__thiscall *p_numpunct_char_dtor)(void*);
131 132
static void (__thiscall *p_basic_string_char_dtor)(basic_string_char*);
static const char* (__thiscall *p_basic_string_char_cstr)(basic_string_char*);
133

134 135 136 137 138
static const int *basic_ostringstream_char_vbtable;
static /*basic_ostringstream_char*/void* (__thiscall *p_basic_ostringstream_char_ctor_mode)(
        /*basic_ostringstream_char*/void*, int, /*MSVCP_bool*/int);
static void (__thiscall *p_basic_ostringstream_char_dtor)(/*basic_ostringstream_char*/void*);
static void (__thiscall *p_basic_ostringstream_char_vbase_dtor)(/*basic_ostringstream_char*/void*);
139
static void (__thiscall *p_basic_ios_char_dtor)(/*basic_ios_char*/void*);
140

141 142 143 144
static BOOL (__cdecl *p_std_Ctraits_float__Isnan)(float);
static BOOL (__cdecl *p_std_Ctraits_double__Isnan)(double);
static BOOL (__cdecl *p_std_Ctraits_long_double__Isnan)(LDOUBLE);

145 146 147
static complex_float* (__thiscall *p_complex_float_ctor)(complex_float*, const float*, const float*);
static complex_float* (__cdecl *p_complex_float_add)(complex_float*, const complex_float*, const complex_float*);
static complex_float* (__cdecl *p_complex_float_div)(complex_float*, const complex_float*, const complex_float*);
148
static float (__cdecl *p_complex_float__Fabs)(const complex_float*, int*);
149
static complex_float* (__cdecl *p_complex_float_tan)(complex_float*, const complex_float*);
150
static complex_float* (__cdecl *p_complex_float_tanh)(complex_float*, const complex_float*);
151
static complex_float* (__cdecl *p_complex_float_log10)(complex_float*, const complex_float*);
152
static complex_float* (__cdecl *p_complex_float_sqrt)(complex_float*, const complex_float*);
153 154 155
static complex_float* (__cdecl *p_complex_float_pow_ci)(complex_float*, const complex_float*, int);
static complex_float* (__cdecl *p_complex_float_pow_fc)(complex_float*, const float*, const complex_float*);
static complex_float* (__cdecl *p_complex_float_pow_cf)(complex_float*, const complex_float*, const float*);
156

157 158
static void (CDECL **p_Raise_handler)(const void*);

159 160 161 162 163 164 165 166 167 168 169 170 171
static int invalid_parameter = 0;
static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
        const wchar_t *function, const wchar_t *file,
        unsigned line, uintptr_t arg)
{
    ok(expression == NULL, "expression is not NULL\n");
    ok(function == NULL, "function is not NULL\n");
    ok(file == NULL, "file is not NULL\n");
    ok(line == 0, "line = %u\n", line);
    ok(arg == 0, "arg = %lx\n", (UINT_PTR)arg);
    invalid_parameter++;
}

172 173 174
/* Emulate a __thiscall */
#ifdef __i386__

175 176
#include "pshpack1.h"
struct thiscall_thunk
177
{
178 179 180 181 182 183 184 185 186 187 188
    BYTE pop_eax;    /* popl  %eax (ret addr) */
    BYTE pop_edx;    /* popl  %edx (func) */
    BYTE pop_ecx;    /* popl  %ecx (this) */
    BYTE push_eax;   /* pushl %eax */
    WORD jmp_edx;    /* jmp  *%edx */
};
#include "poppack.h"

static void * (WINAPI *call_thiscall_func1)( void *func, void *this );
static void * (WINAPI *call_thiscall_func2)( void *func, void *this, const void *a );
static void * (WINAPI *call_thiscall_func3)( void *func, void *this, const void *a, const void *b );
189 190
static void * (WINAPI *call_thiscall_func5)( void *func, void *this, const void *a, const void *b,
        const void *c, const void *d );
191 192

static void init_thiscall_thunk(void)
193
{
194 195 196 197 198 199 200 201 202 203
    struct thiscall_thunk *thunk = VirtualAlloc( NULL, sizeof(*thunk),
                                                 MEM_COMMIT, PAGE_EXECUTE_READWRITE );
    thunk->pop_eax  = 0x58;   /* popl  %eax */
    thunk->pop_edx  = 0x5a;   /* popl  %edx */
    thunk->pop_ecx  = 0x59;   /* popl  %ecx */
    thunk->push_eax = 0x50;   /* pushl %eax */
    thunk->jmp_edx  = 0xe2ff; /* jmp  *%edx */
    call_thiscall_func1 = (void *)thunk;
    call_thiscall_func2 = (void *)thunk;
    call_thiscall_func3 = (void *)thunk;
204
    call_thiscall_func5 = (void *)thunk;
205 206
}

207
#define call_func1(func,_this) call_thiscall_func1(func,_this)
208 209 210 211
#define call_func2(func,_this,a) call_thiscall_func2(func,_this,(const void*)(a))
#define call_func3(func,_this,a,b) call_thiscall_func3(func,_this,(const void*)(a),(const void*)(b))
#define call_func5(func,_this,a,b,c,d) call_thiscall_func5(func,_this,(const void*)(a),(const void*)(b), \
        (const void*)(c), (const void *)(d))
212 213 214

#else

215
#define init_thiscall_thunk()
216 217 218
#define call_func1(func,_this) func(_this)
#define call_func2(func,_this,a) func(_this,a)
#define call_func3(func,_this,a,b) func(_this,a,b)
219
#define call_func5(func,_this,a,b,c,d) func(_this,a,b,c,d)
220 221 222

#endif /* __i386__ */

223
static HMODULE msvcr, msvcp;
224 225
#define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
#define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
226 227
static BOOL init(void)
{
228 229
    msvcr = LoadLibraryA("msvcr90.dll");
    msvcp = LoadLibraryA("msvcp90.dll");
230 231 232 233 234 235
    if(!msvcr || !msvcp) {
        win_skip("msvcp90.dll or msvcrt90.dll not installed\n");
        return FALSE;
    }

    p_set_invalid_parameter_handler = (void*)GetProcAddress(msvcr, "_set_invalid_parameter_handler");
236
    p__get_current_locale = (void*)GetProcAddress(msvcr, "_get_current_locale");
237
    p__free_locale = (void*)GetProcAddress(msvcr, "_free_locale");
238
    p_free = (void*)GetProcAddress(msvcr, "free");
239 240
    p_errno = (void*)GetProcAddress(msvcr, "_errno");
    if(!p_set_invalid_parameter_handler || !p__get_current_locale || !p__free_locale || !p_free || !p_errno) {
241 242 243 244 245 246
        win_skip("Error setting tests environment\n");
        return FALSE;
    }

    p_set_invalid_parameter_handler(test_invalid_parameter_handler);

247
    SET(p_wctype, "wctype");
248
    SET(p__Getctype, "_Getctype");
249
    SET(p__Getcoll, "_Getcoll");
250 251
    SET(p_wctrans, "wctrans");
    SET(p_towctrans, "towctrans");
252
    SET(p__Strxfrm, "_Strxfrm");
253
    SET(basic_ostringstream_char_vbtable, "??_8?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@7B@");
254 255 256 257 258

    SET(p_std_Ctraits_float__Isnan, "?_Isnan@?$_Ctraits@M@std@@SA_NM@Z");
    SET(p_std_Ctraits_double__Isnan, "?_Isnan@?$_Ctraits@N@std@@SA_NN@Z");
    SET(p_std_Ctraits_long_double__Isnan, "?_Isnan@?$_Ctraits@O@std@@SA_NO@Z");

259
    if(sizeof(void*) == 8) { /* 64-bit initialization */
260 261
        SET(p_locale__Locimp__Locimp_Addfac,
                "?_Locimp_Addfac@_Locimp@locale@std@@CAXPEAV123@PEAVfacet@23@_K@Z");
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
        SET(p_char_assign, "?assign@?$char_traits@D@std@@SAXAEADAEBD@Z");
        SET(p_wchar_assign, "?assign@?$char_traits@_W@std@@SAXAEA_WAEB_W@Z");
        SET(p_short_assign, "?assign@?$char_traits@G@std@@SAXAEAGAEBG@Z");

        SET(p_char_eq, "?eq@?$char_traits@D@std@@SA_NAEBD0@Z");
        SET(p_wchar_eq, "?eq@?$char_traits@_W@std@@SA_NAEB_W0@Z");
        SET(p_short_eq, "?eq@?$char_traits@G@std@@SA_NAEBG0@Z");

        SET(p_Copy_s, "?_Copy_s@?$char_traits@D@std@@SAPEADPEAD_KPEBD1@Z");

        SET(p_char_address, "?address@?$allocator@D@std@@QEBAPEADAEAD@Z");
        SET(p_char_ctor, "??0?$allocator@D@std@@QEAA@XZ");
        SET(p_char_deallocate, "?deallocate@?$allocator@D@std@@QEAAXPEAD_K@Z");
        SET(p_char_allocate, "?allocate@?$allocator@D@std@@QEAAPEAD_K@Z");
        SET(p_char_construct, "?construct@?$allocator@D@std@@QEAAXPEADAEBD@Z");
        SET(p_char_max_size, "?max_size@?$allocator@D@std@@QEBA_KXZ");
278 279 280 281

        SET(p_collate_char_ctor_refs, "??0?$collate@D@std@@QEAA@_K@Z");
        SET(p_collate_char_compare, "?compare@?$collate@D@std@@QEBAHPEBD000@Z");
        SET(p_collate_char_dtor, "??1?$collate@D@std@@MEAA@XZ");
282 283 284 285 286 287 288
        SET(p_numpunct_char_ctor, "??_F?$numpunct@D@std@@QEAAXXZ");
        SET(p_numpunct_char_falsename, "?falsename@?$numpunct@D@std@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ");
        SET(p_numpunct_char_dtor, "??1?$numpunct@D@std@@MEAA@XZ");
        SET(p_basic_string_char_dtor,
                "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@XZ");
        SET(p_basic_string_char_cstr,
                "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEBAPEBDXZ");
289 290 291 292 293 294 295

        SET(p_basic_ostringstream_char_ctor_mode,
                "??0?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAA@H@Z");
        SET(p_basic_ostringstream_char_dtor,
                "??1?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@UEAA@XZ");
        SET(p_basic_ostringstream_char_vbase_dtor,
                "??_D?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QEAAXXZ");
296 297
        SET(p_basic_ios_char_dtor,
                "??1?$basic_ios@DU?$char_traits@D@std@@@std@@UEAA@XZ");
298 299 300 301 302 303 304

        SET(p_complex_float_ctor,
                "??0?$complex@M@std@@QEAA@AEBM0@Z");
        SET(p_complex_float_add,
                "??$?HM@std@@YA?AV?$complex@M@0@AEBV10@0@Z");
        SET(p_complex_float_div,
                "??$?KM@std@@YA?AV?$complex@M@0@AEBV10@0@Z");
305 306
        SET(p_complex_float__Fabs,
                "??$_Fabs@M@std@@YAMAEBV?$complex@M@0@PEAH@Z");
307 308
        SET(p_complex_float_tan,
                "??$tan@M@std@@YA?AV?$complex@M@0@AEBV10@@Z");
309 310
        SET(p_complex_float_tanh,
                "??$tanh@M@std@@YA?AV?$complex@M@0@AEBV10@@Z");
311 312
        SET(p_complex_float_log10,
                "??$log10@M@std@@YA?AV?$complex@M@0@AEBV10@@Z");
313 314
        SET(p_complex_float_sqrt,
                "??$sqrt@M@std@@YA?AV?$complex@M@0@AEBV10@@Z");
315 316 317 318 319 320
        SET(p_complex_float_pow_ci,
                "??$pow@M@std@@YA?AV?$complex@M@0@AEBV10@H@Z");
        SET(p_complex_float_pow_fc,
                "??$pow@M@std@@YA?AV?$complex@M@0@AEBMAEBV10@@Z");
        SET(p_complex_float_pow_cf,
                "??$pow@M@std@@YA?AV?$complex@M@0@AEBV10@AEBM@Z");
321 322
        SET(p_Raise_handler,
                "?_Raise_handler@std@@3P6AXAEBVexception@stdext@@@ZEA");
323
    } else {
324 325
        SET(p_locale__Locimp__Locimp_Addfac,
                "?_Locimp_Addfac@_Locimp@locale@std@@CAXPAV123@PAVfacet@23@I@Z");
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
#ifdef __arm__
        SET(p_char_assign, "?assign@?$char_traits@D@std@@SAXAADABD@Z");
        SET(p_wchar_assign, "?assign@?$char_traits@_W@std@@SAXAA_WAB_W@Z");
        SET(p_short_assign, "?assign@?$char_traits@G@std@@SAXAAGABG@Z");

        SET(p_char_eq, "?eq@?$char_traits@D@std@@SA_NABD0@Z");
        SET(p_wchar_eq, "?eq@?$char_traits@_W@std@@SA_NAB_W0@Z");
        SET(p_short_eq, "?eq@?$char_traits@G@std@@SA_NABG0@Z");

        SET(p_Copy_s, "?_Copy_s@?$char_traits@D@std@@SAPADPADIPBDI@Z");

        SET(p_char_address, "?address@?$allocator@D@std@@QBEPADAAD@Z");
        SET(p_char_ctor, "??0?$allocator@D@std@@QAE@XZ");
        SET(p_char_deallocate, "?deallocate@?$allocator@D@std@@QAEXPADI@Z");
        SET(p_char_allocate, "?allocate@?$allocator@D@std@@QAEPADI@Z");
        SET(p_char_construct, "?construct@?$allocator@D@std@@QAEXPADABD@Z");
        SET(p_char_max_size, "?max_size@?$allocator@D@std@@QBEIXZ");

        SET(p_collate_char_ctor_refs, "??0?$collate@D@std@@QAE@I@Z");
        SET(p_collate_char_compare, "?compare@?$collate@D@std@@QBEHPBD000@Z");
        SET(p_collate_char_dtor, "??1?$collate@D@std@@MAE@XZ");
        SET(p_numpunct_char_ctor, "??_F?$numpunct@D@std@@QAEXXZ");
        SET(p_numpunct_char_falsename, "?falsename@?$numpunct@D@std@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ");
        SET(p_numpunct_char_dtor, "??1?$numpunct@D@std@@MAE@XZ");
        SET(p_basic_string_char_dtor,
                "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ");
        SET(p_basic_string_char_cstr,
                "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ");

        SET(p_basic_ostringstream_char_ctor_mode,
                "??0?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@H@Z");
        SET(p_basic_ostringstream_char_dtor,
                "??1?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@UAE@XZ");
        SET(p_basic_ostringstream_char_vbase_dtor,
                "??_D?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXXZ");
        SET(p_basic_ios_char_dtor,
                "??1?$basic_ios@DU?$char_traits@D@std@@@std@@UAA@XZ");

        SET(p_complex_float_ctor,
                "??0?$complex@M@std@@QAE@ABM0@Z");
        SET(p_complex_float_add,
                "??$?HM@std@@YA?AV?$complex@M@0@ABV10@0@Z");
        SET(p_complex_float_div,
                "??$?KM@std@@YA?AV?$complex@M@0@ABV10@0@Z");
        SET(p_complex_float__Fabs,
                "??$_Fabs@M@std@@YAMABV?$complex@M@0@PAH@Z");
        SET(p_complex_float_tan,
                "??$tan@M@std@@YA?AV?$complex@M@0@ABV10@@Z");
        SET(p_complex_float_tanh,
                "??$tanh@M@std@@YA?AV?$complex@M@0@ABV10@@Z");
        SET(p_complex_float_log10,
                "??$log10@M@std@@YA?AV?$complex@M@0@ABV10@@Z");
        SET(p_complex_float_sqrt,
                "??$sqrt@M@std@@YA?AV?$complex@M@0@ABV10@@Z");
380 381 382 383 384 385
        SET(p_complex_float_pow_ci,
                "??$pow@M@std@@YA?AV?$complex@M@0@ABV10@H@Z");
        SET(p_complex_float_pow_fc,
                "??$pow@M@std@@YA?AV?$complex@M@0@ABMABV10@@Z");
        SET(p_complex_float_pow_cf,
                "??$pow@M@std@@YA?AV?$complex@M@0@ABV10@ABM@Z");
386
#else
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
        SET(p_char_assign, "?assign@?$char_traits@D@std@@SAXAADABD@Z");
        SET(p_wchar_assign, "?assign@?$char_traits@_W@std@@SAXAA_WAB_W@Z");
        SET(p_short_assign, "?assign@?$char_traits@G@std@@SAXAAGABG@Z");

        SET(p_char_eq, "?eq@?$char_traits@D@std@@SA_NABD0@Z");
        SET(p_wchar_eq, "?eq@?$char_traits@_W@std@@SA_NAB_W0@Z");
        SET(p_short_eq, "?eq@?$char_traits@G@std@@SA_NABG0@Z");

        SET(p_Copy_s, "?_Copy_s@?$char_traits@D@std@@SAPADPADIPBDI@Z");

        SET(p_char_address, "?address@?$allocator@D@std@@QBEPADAAD@Z");
        SET(p_char_ctor, "??0?$allocator@D@std@@QAE@XZ");
        SET(p_char_deallocate, "?deallocate@?$allocator@D@std@@QAEXPADI@Z");
        SET(p_char_allocate, "?allocate@?$allocator@D@std@@QAEPADI@Z");
        SET(p_char_construct, "?construct@?$allocator@D@std@@QAEXPADABD@Z");
        SET(p_char_max_size, "?max_size@?$allocator@D@std@@QBEIXZ");
403 404 405 406

        SET(p_collate_char_ctor_refs, "??0?$collate@D@std@@QAE@I@Z");
        SET(p_collate_char_compare, "?compare@?$collate@D@std@@QBEHPBD000@Z");
        SET(p_collate_char_dtor, "??1?$collate@D@std@@MAE@XZ");
407 408 409 410 411 412 413
        SET(p_numpunct_char_ctor, "??_F?$numpunct@D@std@@QAEXXZ");
        SET(p_numpunct_char_falsename, "?falsename@?$numpunct@D@std@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ");
        SET(p_numpunct_char_dtor, "??1?$numpunct@D@std@@MAE@XZ");
        SET(p_basic_string_char_dtor,
                "??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ");
        SET(p_basic_string_char_cstr,
                "?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ");
414 415 416 417 418 419 420

        SET(p_basic_ostringstream_char_ctor_mode,
                "??0?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@H@Z");
        SET(p_basic_ostringstream_char_dtor,
                "??1?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@UAE@XZ");
        SET(p_basic_ostringstream_char_vbase_dtor,
                "??_D?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXXZ");
421 422
        SET(p_basic_ios_char_dtor,
                "??1?$basic_ios@DU?$char_traits@D@std@@@std@@UAE@XZ");
423 424 425 426 427 428 429

        SET(p_complex_float_ctor,
                "??0?$complex@M@std@@QAE@ABM0@Z");
        SET(p_complex_float_add,
                "??$?HM@std@@YA?AV?$complex@M@0@ABV10@0@Z");
        SET(p_complex_float_div,
                "??$?KM@std@@YA?AV?$complex@M@0@ABV10@0@Z");
430 431
        SET(p_complex_float__Fabs,
                "??$_Fabs@M@std@@YAMABV?$complex@M@0@PAH@Z");
432 433
        SET(p_complex_float_tan,
                "??$tan@M@std@@YA?AV?$complex@M@0@ABV10@@Z");
434 435
        SET(p_complex_float_tanh,
                "??$tanh@M@std@@YA?AV?$complex@M@0@ABV10@@Z");
436 437
        SET(p_complex_float_log10,
                "??$log10@M@std@@YA?AV?$complex@M@0@ABV10@@Z");
438 439
        SET(p_complex_float_sqrt,
                "??$sqrt@M@std@@YA?AV?$complex@M@0@ABV10@@Z");
440 441 442 443 444 445
        SET(p_complex_float_pow_ci,
                "??$pow@M@std@@YA?AV?$complex@M@0@ABV10@H@Z");
        SET(p_complex_float_pow_fc,
                "??$pow@M@std@@YA?AV?$complex@M@0@ABMABV10@@Z");
        SET(p_complex_float_pow_cf,
                "??$pow@M@std@@YA?AV?$complex@M@0@ABV10@ABM@Z");
446 447
        SET(p_Raise_handler,
                "?_Raise_handler@std@@3P6AXABVexception@stdext@@@ZA");
448
#endif
449
    }
450

451
    init_thiscall_thunk();
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477
    return TRUE;
}

static void test_assign(void)
{
    const char in[] = "abc";
    char out[4];

    out[1] = '#';
    p_char_assign(out, in);
    ok(out[0] == in[0], "out[0] = %c\n", out[0]);
    ok(out[1] == '#', "out[1] = %c\n", out[1]);

    out[2] = '#';
    p_wchar_assign(out, in);
    ok(*((char*)out)==in[0] && *((char*)out+1)==in[1],
            "out[0] = %d, out[1] = %d\n", (int)out[0], (int)out[1]);
    ok(out[2] == '#', "out[2] = %c\n", out[2]);

    out[2] = '#';
    p_short_assign(out, in);
    ok(*((char*)out)==in[0] && *((char*)out+1)==in[1],
            "out[0] = %d, out[1] = %d\n", (int)out[0], (int)out[1]);
    ok(out[2] == '#', "out[2] = %c\n", out[2]);
}

478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
static void test_equal(void)
{
    static const char in1[] = "abc";
    static const char in2[] = "ab";
    static const char in3[] = "a";
    static const char in4[] = "b";
    BYTE ret;

    ret = p_char_eq(in1, in2);
    ok(ret == TRUE, "ret = %d\n", (int)ret);
    ret = p_char_eq(in1, in3);
    ok(ret == TRUE, "ret = %d\n", (int)ret);
    ret = p_char_eq(in1, in4);
    ok(ret == FALSE, "ret = %d\n", (int)ret);

    ret = p_wchar_eq(in1, in2);
    ok(ret == TRUE, "ret = %d\n", (int)ret);
    ret = p_wchar_eq(in1, in3);
    ok(ret == FALSE, "ret = %d\n", (int)ret);
    ret = p_wchar_eq(in1, in4);
    ok(ret == FALSE, "ret = %d\n", (int)ret);

    ret = p_short_eq(in1, in2);
    ok(ret == TRUE, "ret = %d\n", (int)ret);
    ret = p_short_eq(in1, in3);
    ok(ret == FALSE, "ret = %d\n", (int)ret);
    ret = p_short_eq(in1, in4);
    ok(ret == FALSE, "ret = %d\n", (int)ret);
}

508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
static void test_Copy_s(void)
{
    static const char src[] = "abcd";
    char dest[32], *ret;

    dest[4] = '#';
    dest[5] = '\0';
    ret = p_Copy_s(dest, 4, src, 4);
    ok(ret == dest, "ret != dest\n");
    ok(dest[4] == '#', "dest[4] != '#'\n");
    ok(!memcmp(dest, src, sizeof(char[4])), "dest = %s\n", dest);

    ret = p_Copy_s(dest, 32, src, 4);
    ok(ret == dest, "ret != dest\n");
    ok(dest[4] == '#', "dest[4] != '#'\n");
    ok(!memcmp(dest, src, sizeof(char[4])), "dest = %s\n", dest);

525
    *p_errno() = 0xdeadbeef;
526 527 528 529 530 531 532
    dest[0] = '#';
    ret = p_Copy_s(dest, 3, src, 4);
    ok(ret == dest, "ret != dest\n");
    ok(dest[0] == '\0', "dest[0] != 0\n");
    ok(invalid_parameter==1, "invalid_parameter = %d\n",
            invalid_parameter);
    invalid_parameter = 0;
533
    ok(*p_errno() == ERANGE, "errno = %d\n", *p_errno());
534

535
    *p_errno() = 0xdeadbeef;
536 537 538 539
    p_Copy_s(NULL, 32, src, 4);
    ok(invalid_parameter==1, "invalid_parameter = %d\n",
            invalid_parameter);
    invalid_parameter = 0;
540
    ok(*p_errno() == EINVAL, "errno = %d\n", *p_errno());
541

542
    *p_errno() = 0xdeadbeef;
543 544 545 546
    p_Copy_s(dest, 32, NULL, 4);
    ok(invalid_parameter==1, "invalid_parameter = %d\n",
            invalid_parameter);
    invalid_parameter = 0;
547
    ok(*p_errno() == EINVAL, "errno = %d\n", *p_errno());
548 549
}

550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
static void test_wctype(void)
{
    static const struct {
        const char *name;
        unsigned short mask;
    } properties[] = {
        { "alnum",  0x107 },
        { "alpha",  0x103 },
        { "cntrl",  0x020 },
        { "digit",  0x004 },
        { "graph",  0x117 },
        { "lower",  0x002 },
        { "print",  0x157 },
        { "punct",  0x010 },
        { "space",  0x008 },
        { "upper",  0x001 },
        { "xdigit", 0x080 },
        { "ALNUM",  0x000 },
        { "Alnum",  0x000 },
        { "",  0x000 }
    };
    int i, ret;

573
    for(i=0; i<ARRAY_SIZE(properties); i++) {
574 575 576 577 578
        ret = p_wctype(properties[i].name);
        ok(properties[i].mask == ret, "%d - Expected %x, got %x\n", i, properties[i].mask, ret);
    }
}

579 580 581
static void test__Getctype(void)
{
    MSVCP__Ctypevec ret;
582
    _locale_t locale;
583

584
    ok(p__Getctype(&ret) == &ret, "__Getctype returned incorrect pointer\n");
585 586 587 588 589 590
    ok(ret.handle == 0, "ret.handle = %d\n", ret.handle);
    ok(ret.page == 0, "ret.page = %d\n", ret.page);
    ok(ret.delfl == 1, "ret.delfl = %d\n", ret.delfl);
    ok(ret.table[0] == 32, "ret.table[0] = %d\n", ret.table[0]);
    p_free(ret.table);

591 592 593
    locale = p__get_current_locale();
    locale->locinfo->lc_handle[LC_COLLATE] = 0x1234567;
    p__free_locale(locale);
594 595
    ok(p__Getctype(&ret) == &ret, "__Getctype returned incorrect pointer\n");
    ok(ret.handle == 0x1234567, "ret.handle = %d\n", ret.handle);
596 597 598 599 600 601
    ok(ret.page == 0, "ret.page = %d\n", ret.page);
    ok(ret.delfl == 1, "ret.delfl = %d\n", ret.delfl);
    ok(ret.table[0] == 32, "ret.table[0] = %d\n", ret.table[0]);
    p_free(ret.table);
}

602 603 604
static void test__Getcoll(void)
{
    ULONGLONG (__cdecl *p__Getcoll_arg)(MSVCP__Collvec*);
605
    _locale_t locale;
606 607 608 609 610 611

    union {
        MSVCP__Collvec collvec;
        ULONGLONG ull;
    }ret;

612 613 614
    locale = p__get_current_locale();
    locale->locinfo->lc_handle[LC_COLLATE] = 0x7654321;
    p__free_locale(locale);
615 616 617 618 619 620 621 622 623 624 625
    ret.ull = 0;
    p__Getcoll_arg = (void*)p__Getcoll;
    p__Getcoll_arg(&ret.collvec);
    ok(ret.collvec.handle == 0, "ret.handle = %x\n", ret.collvec.handle);
    ok(ret.collvec.page == 0, "ret.page = %x\n", ret.collvec.page);

    ret.ull = p__Getcoll();
    ok(ret.collvec.handle == 0x7654321, "ret.collvec.handle = %x\n", ret.collvec.handle);
    ok(ret.collvec.page == 0, "ret.page = %x\n", ret.collvec.page);
}

626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
static void test_towctrans(void)
{
    wchar_t ret;

    ret = p_wctrans("tolower");
    ok(ret == 2, "wctrans returned %d, expected 2\n", ret);
    ret = p_wctrans("toupper");
    ok(ret == 1, "wctrans returned %d, expected 1\n", ret);
    ret = p_wctrans("toLower");
    ok(ret == 0, "wctrans returned %d, expected 0\n", ret);
    ret = p_wctrans("");
    ok(ret == 0, "wctrans returned %d, expected 0\n", ret);
    if(0) { /* crashes on windows */
        ret = p_wctrans(NULL);
        ok(ret == 0, "wctrans returned %d, expected 0\n", ret);
    }

    ret = p_towctrans('t', 2);
    ok(ret == 't', "towctrans('t', 2) returned %c, expected t\n", ret);
    ret = p_towctrans('T', 2);
    ok(ret == 't', "towctrans('T', 2) returned %c, expected t\n", ret);
    ret = p_towctrans('T', 0);
    ok(ret == 't', "towctrans('T', 0) returned %c, expected t\n", ret);
    ret = p_towctrans('T', 3);
    ok(ret == 't', "towctrans('T', 3) returned %c, expected t\n", ret);
    ret = p_towctrans('t', 1);
    ok(ret == 'T', "towctrans('t', 1) returned %c, expected T\n", ret);
    ret = p_towctrans('T', 1);
    ok(ret == 'T', "towctrans('T', 1) returned %c, expected T\n", ret);
}

657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687
static void test_allocator_char(void)
{
    void *allocator = (void*)0xdeadbeef;
    char *ptr;
    char val;
    unsigned int size;

    allocator = call_func1(p_char_ctor, allocator);
    ok(allocator == (void*)0xdeadbeef, "allocator = %p\n", allocator);

    ptr = call_func2(p_char_address, NULL, (void*)0xdeadbeef);
    ok(ptr == (void*)0xdeadbeef, "incorrect address (%p)\n", ptr);

    ptr = NULL;
    ptr = call_func2(p_char_allocate, allocator, 10);
    ok(ptr != NULL, "Memory allocation failed\n");

    ptr[0] = ptr[1] = '#';
    val = 'a';
    call_func3(p_char_construct, allocator, ptr, &val);
    val = 'b';
    call_func3(p_char_construct, allocator, (ptr+1), &val);
    ok(ptr[0] == 'a', "ptr[0] = %c\n", ptr[0]);
    ok(ptr[1] == 'b', "ptr[1] = %c\n", ptr[1]);

    call_func3(p_char_deallocate, allocator, ptr, -1);

    size = (unsigned int)call_func1(p_char_max_size, allocator);
    ok(size == (unsigned int)0xffffffff, "size = %x\n", size);
}

688 689
static void test_virtual_call(void)
{
690 691
    BYTE this[256];
    basic_string_char bstr;
692
    _locale_t locale;
693
    const char *p;
694 695 696 697
    char str1[] = "test";
    char str2[] = "TEST";
    int ret;

698 699 700
    locale = p__get_current_locale();
    locale->locinfo->lc_handle[LC_COLLATE] = 1;
    p__free_locale(locale);
701 702
    call_func2(p_collate_char_ctor_refs, this, 0);
    ret = (int)call_func5(p_collate_char_compare, this, str1, str1+4, str1, str1+4);
703
    ok(ret == 0, "collate<char>::compare returned %d\n", ret);
704
    ret = (int)call_func5(p_collate_char_compare, this, str2, str2+4, str1, str1+4);
705
    ok(ret == 1, "collate<char>::compare returned %d\n", ret);
706
    ret = (int)call_func5(p_collate_char_compare, this, str1, str1+3, str1, str1+4);
707
    ok(ret == -1, "collate<char>::compare returned %d\n", ret);
708 709 710 711 712 713 714 715
    call_func1(p_collate_char_dtor, this);

    call_func1(p_numpunct_char_ctor, this);
    call_func2(p_numpunct_char_falsename, this, &bstr);
    p = call_func1(p_basic_string_char_cstr, &bstr);
    ok(!strcmp(p, "false"), "numpunct<char>::falsename returned %s\n", p);
    call_func1(p_basic_string_char_dtor, &bstr);
    call_func1(p_numpunct_char_dtor, this);
716 717
}

718 719 720 721 722 723 724
static void test_virtual_base_dtors(void)
{
    char this[512];

    call_func3(p_basic_ostringstream_char_ctor_mode, this, 0, 1);
    call_func1(p_basic_ostringstream_char_vbase_dtor, this);

725
    /* this test uses vbtable set by earlier test */
726 727
    call_func3(p_basic_ostringstream_char_ctor_mode, this, 0, 0);
    call_func1(p_basic_ostringstream_char_dtor, this+basic_ostringstream_char_vbtable[1]);
728
    call_func1(p_basic_ios_char_dtor, this+((int**)this)[0][1]);
729 730
}

731 732 733 734 735 736 737 738
static BOOL almost_eq(float f1, float f2)
{
    f1 = (f1-f2)/f1;
    if(f1 < 0)
        f1 = -f1;
    return f1 < 0.0001;
}

739 740 741 742 743 744 745
static void test_Ctraits_math_functions(void)
{
    BYTE ret;

    ret = p_std_Ctraits_float__Isnan(0.0);
    ok(ret == FALSE, "ret = %d\n", ret);

746
    ret = p_std_Ctraits_float__Isnan(INFINITY);
747 748
    ok(ret == FALSE, "ret = %d\n", ret);

749
    ret = p_std_Ctraits_float__Isnan(-INFINITY);
750 751
    ok(ret == FALSE, "ret = %d\n", ret);

752
    ret = p_std_Ctraits_float__Isnan(IND);
753 754
    ok(ret == TRUE, "ret = %d\n", ret);

755
    ret = p_std_Ctraits_float__Isnan(NAN);
756 757
    ok(ret == TRUE, "ret = %d\n", ret);

758
    ret = p_std_Ctraits_double__Isnan(INFINITY);
759 760
    ok(ret == FALSE, "ret = %d\n", ret);

761
    ret = p_std_Ctraits_double__Isnan(IND);
762 763
    ok(ret == TRUE, "ret = %d\n", ret);

764 765 766 767
    ret = p_std_Ctraits_double__Isnan(NAN);
    ok(ret == TRUE, "ret = %d\n", ret);

    ret = p_std_Ctraits_long_double__Isnan(INFINITY);
768 769
    ok(ret == FALSE, "ret = %d\n", ret);

770 771 772 773
    ret = p_std_Ctraits_long_double__Isnan(IND);
    ok(ret == TRUE, "ret = %d\n", ret);

    ret = p_std_Ctraits_long_double__Isnan(NAN);
774 775 776
    ok(ret == TRUE, "ret = %d\n", ret);
}

777 778 779 780
static void test_complex(void)
{
    complex_float c1, c2, c3;
    float f1, f2;
781
    int scale;
782
    int r;
783 784 785 786 787 788 789

    f1 = 1;
    f2 = 2;
    call_func3(p_complex_float_ctor, &c1, &f1, &f2);
    ok(c1.real == 1, "c1.real = %f\n", c1.real);
    ok(c1.imag == 2, "c1.imag = %f\n", c1.imag);

790 791 792 793
    f1 = p_complex_float__Fabs(&c1, &scale);
    ok(almost_eq(f1, 0.559017), "abs(1+2i) = %f\n", f1);
    ok(scale == 2, "scale = %d\n", scale);

794 795 796 797 798 799
    f1 = -1;
    f2 = 1;
    call_func3(p_complex_float_ctor, &c2, &f1, &f2);
    ok(c2.real == -1, "c2.real = %f\n", c1.real);
    ok(c2.imag == 1, "c2.imag = %f\n", c1.imag);

800 801 802 803
    f1 = p_complex_float__Fabs(&c2, &scale);
    ok(almost_eq(f1, 0.353553), "abs(1-1i) = %f\n", f1);
    ok(scale == 2, "scale = %d\n", scale);

804 805 806 807
    p_complex_float_add(&c3, &c1, &c2);
    ok(c3.real == 0, "c3.real = %f\n", c3.real);
    ok(c3.imag == 3, "c3.imag = %f\n", c3.imag);

808 809 810 811
    f1 = p_complex_float__Fabs(&c3, &scale);
    ok(almost_eq(f1, 0.75), "abs(0+3i) = %f\n", f1);
    ok(scale == 2, "scale = %d\n", scale);

812 813 814 815
    p_complex_float_add(&c2, &c1, &c3);
    ok(c2.real == 1, "c2.real = %f\n", c1.real);
    ok(c2.imag == 5, "c2.imag = %f\n", c1.imag);

816 817 818 819
    f1 = p_complex_float__Fabs(&c3, &scale);
    ok(almost_eq(f1, 0.75), "abs(1+5i) = %f\n", f1);
    ok(scale == 2, "scale = %d\n", scale);

820 821 822 823 824 825 826 827 828 829 830 831
    /* (1+5i) / (0+3i) */
    p_complex_float_div(&c1, &c2, &c3);
    ok(almost_eq(c1.real, 1.666667), "c1.real = %f\n", c1.real);
    ok(almost_eq(c1.imag, -0.33333), "c1.imag = %f\n", c1.imag);

    /* (1+5i) / (2+0i) */
    c3.real = 2;
    c3.imag = 0;
    p_complex_float_div(&c1, &c2, &c3);
    ok(almost_eq(c1.real, 0.5), "c1.real = %f\n", c1.real);
    ok(almost_eq(c1.imag, 2.5), "c1.imag = %f\n", c1.imag);

832 833 834 835
    f1 = p_complex_float__Fabs(&c1, &scale);
    ok(almost_eq(f1, 0.637377), "abs(0.5+2.5i) = %f\n", f1);
    ok(scale == 2, "scale = %d\n", scale);

836 837 838 839 840 841
    /* (1+5i) / 0 */
    c3.real = 0;
    p_complex_float_div(&c1, &c2, &c3);
    ok(_isnan(c1.real), "c1.real = %f\n", c1.real);
    ok(_isnan(c1.imag), "c1.imag = %f\n", c1.imag);

842 843 844 845
    f1 = p_complex_float__Fabs(&c1, &scale);
    ok(_isnan(f1), "abs(NaN+NaNi) = %f\n", f1);
    ok(scale == 0, "scale = %d\n", scale);

846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861
    /* (1+5i) / (NaN-2i) */
    c1.imag = -2;
    p_complex_float_div(&c3, &c2, &c1);
    ok(_isnan(c3.real), "c3.real = %f\n", c3.real);
    ok(_isnan(c3.imag), "c3.imag = %f\n", c3.imag);

    /* (NaN-2i) / (1+0i) */
    c2.imag = 0;
    p_complex_float_div(&c3, &c1, &c2);
    ok(_isnan(c3.real), "c3.real = %f\n", c3.real);
    ok(_isnan(c3.imag), "c3.imag = %f\n", c3.imag);

    /* (1+0i) + (NaN-2i) */
    p_complex_float_add(&c3, &c2, &c1);
    ok(_isnan(c3.real), "c3.real = %f\n", c3.real);
    ok(c3.imag == -2, "c3.imag = %f\n", c3.imag);
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894

    f1 = p_complex_float__Fabs(&c3, &scale);
    ok(_isnan(f1), "abs(NaN-2i) = %f\n", f1);
    ok(scale == 0, "scale = %d\n", scale);

    c3.real = 1000;
    f1 = p_complex_float__Fabs(&c3, &scale);
    ok(almost_eq(f1, 250.000504), "abs(1000-2i) = %f\n", f1);
    ok(scale == 2, "scale = %d\n", scale);

    c3.real = 0.1;
    c3.imag = 0.1;
    f1 = p_complex_float__Fabs(&c3, &scale);
    ok(almost_eq(f1, 0.565685), "abs(0.1+0.1i) = %f\n", f1);
    ok(scale == -2, "scale = %d\n", scale);

    c3.real = 1;
    c3.imag = 0;
    f1 = p_complex_float__Fabs(&c3, &scale);
    ok(almost_eq(f1, 0.25), "abs(1+0i) = %f\n", f1);
    ok(scale == 2, "scale = %d\n", scale);

    c3.real = 0.99;
    c3.imag = 0;
    f1 = p_complex_float__Fabs(&c3, &scale);
    ok(almost_eq(f1, 3.96), "abs(0.99+0i) = %f\n", f1);
    ok(scale == -2, "scale = %d\n", scale);

    c3.real = 0;
    c3.imag = 0;
    f1 = p_complex_float__Fabs(&c3, &scale);
    ok(f1 == 0, "abs(0+0i) = %f\n", f1);
    ok(scale == 0, "scale = %d\n", scale);
895 896 897

    c1.real = 0;
    c1.imag = 0;
898 899
    r = 3;
    f1 = 3.312;
900 901 902
    p_complex_float_tan(&c2, &c1);
    ok(c2.real == 0, "c2.real = %f\n", c2.real);
    ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
903 904 905
    p_complex_float_tanh(&c2, &c1);
    ok(c2.real == 0, "c2.real = %f\n", c2.real);
    ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
906 907 908
    p_complex_float_log10(&c2, &c1);
    ok(c2.real < -FLT_MAX /* c2.real == -inf */, "c2.real = %f\n", c2.real);
    ok(c2.imag == 0, "c2.imag = %g\n", c2.imag);
909 910 911
    p_complex_float_sqrt(&c2, &c1);
    ok(c2.real == 0, "c2.real = %f\n", c2.real);
    ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
912 913 914 915 916 917 918 919 920
    p_complex_float_pow_ci(&c2, &c1, r);
    ok(c2.real == 0, "c2.real = %f\n", c2.real);
    ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
    p_complex_float_pow_fc(&c2, &f1, &c1);
    ok(c2.real == 1, "c2.real = %f\n", c2.real);
    ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
    p_complex_float_pow_cf(&c2, &c1, &f1);
    ok(c2.real == 0, "c2.real = %f\n", c2.real);
    ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
921 922 923 924 925 926

    c1.real = 3.14159/2;
    c1.imag = 0;
    p_complex_float_tan(&c2, &c1);
    ok(almost_eq(c2.real, 788906.062500), "c2.real = %f\n", c2.real);
    ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
927 928 929
    p_complex_float_tanh(&c2, &c1);
    ok(almost_eq(c2.real, 0.917152), "c2.real = %f\n", c2.real);
    ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
930 931 932
    p_complex_float_log10(&c2, &c1);
    ok(almost_eq(c2.real, 0.196120), "c2.real = %f\n", c2.real);
    ok(c2.imag == 0, "c2.imag = %g\n", c2.imag);
933 934 935
    p_complex_float_sqrt(&c2, &c1);
    ok(almost_eq(c2.real, 1.253314), "c2.real = %f\n", c2.real);
    ok(c2.imag == 0, "c2.imag = %g\n", c2.imag);
936 937 938 939 940 941 942 943 944 945 946 947 948 949
    p_complex_float_pow_ci(&c2, &c1, r);
    ok(almost_eq(c2.real, 3.875775), "c2.real = %f\n", c2.real);
    ok(c2.imag == 0, "c2.imag = %g\n", c2.imag);
    r = -r;
    p_complex_float_pow_ci(&c2, &c1, r);
    ok(almost_eq(c2.real, 0.258013), "c2.real = %f\n", c2.real);
    ok(c2.imag == 0, "c2.imag = %g\n", c2.imag);
    r = -r;
    p_complex_float_pow_fc(&c2, &f1, &c1);
    ok(almost_eq(c2.real, 6.560778), "c2.real = %f\n", c2.real);
    ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
    p_complex_float_pow_cf(&c2, &c1, &f1);
    ok(almost_eq(c2.real, 4.462188), "c2.real = %f\n", c2.real);
    ok(c2.imag == 0, "c2.imag = %f\n", c2.imag);
950 951 952 953 954 955

    c1.real = 7.12;
    c1.imag = 0.17;
    p_complex_float_tan(&c2, &c1);
    ok(almost_eq(c2.real, 1.040818), "c2.real = %f\n", c2.real);
    ok(almost_eq(c2.imag, 0.362651), "c2.imag = %f\n", c2.imag);
956 957 958
    p_complex_float_tanh(&c2, &c1);
    ok(almost_eq(c2.real, 0.999999), "c2.real = %f\n", c2.real);
    ok(almost_eq(c2.imag, 4.3627e-7), "c2.imag = %g\n", c2.imag);
959 960 961
    p_complex_float_log10(&c2, &c1);
    ok(almost_eq(c2.real, 0.852604), "c2.real = %f\n", c2.real);
    ok(almost_eq(c2.imag, 0.0103674), "c2.imag = %g\n", c2.imag);
962 963 964
    p_complex_float_sqrt(&c2, &c1);
    ok(almost_eq(c2.real, 2.668523), "c2.real = %f\n", c2.real);
    ok(almost_eq(c2.imag, 0.0318528), "c2.imag = %g\n", c2.imag);
965 966 967 968 969 970 971 972 973 974 975 976 977 978
    p_complex_float_pow_ci(&c2, &c1, r);
    ok(almost_eq(c2.real, 360.326782), "c2.real = %f\n", c2.real);
    ok(almost_eq(c2.imag, 25.849230), "c2.imag = %g\n", c2.imag);
    r = -r;
    p_complex_float_pow_ci(&c2, &c1, r);
    ok(almost_eq(c2.real, 0.002761), "c2.real = %f\n", c2.real);
    ok(almost_eq(c2.imag, -0.000198073), "c2.imag = %g\n", c2.imag);
    r = -r;
    p_complex_float_pow_fc(&c2, &f1, &c1);
    ok(almost_eq(c2.real, 4942.879395), "c2.real = %f\n", c2.real);
    ok(almost_eq(c2.imag, 1020.427368), "c2.imag = %g\n", c2.imag);
    p_complex_float_pow_cf(&c2, &c1, &f1);
    ok(almost_eq(c2.real, 664.453918), "c2.real = %f\n", c2.real);
    ok(almost_eq(c2.imag, 52.643879), "c2.imag = %g\n", c2.imag);
979 980 981 982 983 984 985 986 987

    c1.real = 0.14;
    c1.imag = 0.19;
    p_complex_float_tan(&c2, &c1);
    ok(almost_eq(c2.real, 0.135859), "c2.real = %f\n", c2.real);
    ok(almost_eq(c2.imag, 0.191341), "c2.imag = %f\n", c2.imag);
    p_complex_float_tanh(&c2, &c1);
    ok(almost_eq(c2.real, 0.144134), "c2.real = %f\n", c2.real);
    ok(almost_eq(c2.imag, 0.188464), "c2.imag = %f\n", c2.imag);
988 989 990
    p_complex_float_log10(&c2, &c1);
    ok(almost_eq(c2.real, -0.627072), "c2.real = %f\n", c2.real);
    ok(almost_eq(c2.imag, 0.4064), "c2.imag = %g\n", c2.imag);
991 992 993
    p_complex_float_sqrt(&c2, &c1);
    ok(almost_eq(c2.real, 0.433595), "c2.real = %f\n", c2.real);
    ok(almost_eq(c2.imag, 0.219099), "c2.imag = %g\n", c2.imag);
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006
    p_complex_float_pow_ci(&c2, &c1, r);
    ok(almost_eq(c2.real, -0.012418), "c2.real = %f\n", c2.real);
    ok(almost_eq(c2.imag, 0.004313), "c2.imag = %g\n", c2.imag);
    r = -r;
    p_complex_float_pow_ci(&c2, &c1, r);
    ok(almost_eq(c2.real, -71.859810), "c2.real = %f\n", c2.real);
    ok(almost_eq(c2.imag, -24.958229), "c2.imag = %g\n", c2.imag);
    p_complex_float_pow_fc(&c2, &f1, &c1);
    ok(almost_eq(c2.real, 1.152052), "c2.real = %f\n", c2.real);
    ok(almost_eq(c2.imag, 0.266751), "c2.imag = %g\n", c2.imag);
    p_complex_float_pow_cf(&c2, &c1, &f1);
    ok(almost_eq(c2.real, -0.008370), "c2.real = %f\n", c2.real);
    ok(almost_eq(c2.imag, 0.00035447), "c2.imag = %g\n", c2.imag);
1007 1008
}

1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
static struct {
    int value[2];
    const char* export_name;
} vbtable_size_exports_list[] = {
    {{0x5c, 0xa8}, "??_8?$basic_fstream@DU?$char_traits@D@std@@@std@@7B?$basic_istream@DU?$char_traits@D@std@@@1@@"},
    {{0x54, 0x98}, "??_8?$basic_fstream@DU?$char_traits@D@std@@@std@@7B?$basic_ostream@DU?$char_traits@D@std@@@1@@"},
    {{0x5c, 0xa8}, "??_8?$basic_fstream@GU?$char_traits@G@std@@@std@@7B?$basic_istream@GU?$char_traits@G@std@@@1@@"},
    {{0x54, 0x98}, "??_8?$basic_fstream@GU?$char_traits@G@std@@@std@@7B?$basic_ostream@GU?$char_traits@G@std@@@1@@"},
    {{0x5c, 0xa8}, "??_8?$basic_fstream@_WU?$char_traits@_W@std@@@std@@7B?$basic_istream@_WU?$char_traits@_W@std@@@1@@"},
    {{0x54, 0x98}, "??_8?$basic_fstream@_WU?$char_traits@_W@std@@@std@@7B?$basic_ostream@_WU?$char_traits@_W@std@@@1@@"},
    {{0x58, 0xa0}, "??_8?$basic_ifstream@DU?$char_traits@D@std@@@std@@7B@"},
    {{0x58, 0xa0}, "??_8?$basic_ifstream@GU?$char_traits@G@std@@@std@@7B@"},
    {{0x58, 0xa0}, "??_8?$basic_ifstream@_WU?$char_traits@_W@std@@@std@@7B@"},
    {{ 0xc, 0x18}, "??_8?$basic_iostream@DU?$char_traits@D@std@@@std@@7B?$basic_istream@DU?$char_traits@D@std@@@1@@"},
    {{ 0x4,  0x8}, "??_8?$basic_iostream@DU?$char_traits@D@std@@@std@@7B?$basic_ostream@DU?$char_traits@D@std@@@1@@"},
    {{ 0xc, 0x18}, "??_8?$basic_iostream@GU?$char_traits@G@std@@@std@@7B?$basic_istream@GU?$char_traits@G@std@@@1@@"},
    {{ 0x4,  0x8}, "??_8?$basic_iostream@GU?$char_traits@G@std@@@std@@7B?$basic_ostream@GU?$char_traits@G@std@@@1@@"},
    {{ 0xc, 0x18}, "??_8?$basic_iostream@_WU?$char_traits@_W@std@@@std@@7B?$basic_istream@_WU?$char_traits@_W@std@@@1@@"},
    {{ 0x4,  0x8}, "??_8?$basic_iostream@_WU?$char_traits@_W@std@@@std@@7B?$basic_ostream@_WU?$char_traits@_W@std@@@1@@"},
    {{ 0x8, 0x10}, "??_8?$basic_istream@DU?$char_traits@D@std@@@std@@7B@"},
    {{ 0x8, 0x10}, "??_8?$basic_istream@GU?$char_traits@G@std@@@std@@7B@"},
    {{ 0x8, 0x10}, "??_8?$basic_istream@_WU?$char_traits@_W@std@@@std@@7B@"},
    {{0x50, 0x90}, "??_8?$basic_istringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@7B@"},
    {{0x50, 0x90}, "??_8?$basic_istringstream@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@7B@"},
    {{0x50, 0x90}, "??_8?$basic_istringstream@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@7B@"},
    {{0x54, 0x98}, "??_8?$basic_ofstream@DU?$char_traits@D@std@@@std@@7B@"},
    {{0x54, 0x98}, "??_8?$basic_ofstream@GU?$char_traits@G@std@@@std@@7B@"},
    {{0x54, 0x98}, "??_8?$basic_ofstream@_WU?$char_traits@_W@std@@@std@@7B@"},
    {{ 0x4,  0x8}, "??_8?$basic_ostream@DU?$char_traits@D@std@@@std@@7B@"},
    {{ 0x4,  0x8}, "??_8?$basic_ostream@GU?$char_traits@G@std@@@std@@7B@"},
    {{ 0x4,  0x8}, "??_8?$basic_ostream@_WU?$char_traits@_W@std@@@std@@7B@"},
    {{0x4c, 0x88}, "??_8?$basic_ostringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@7B@"},
    {{0x4c, 0x88}, "??_8?$basic_ostringstream@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@7B@"},
    {{0x4c, 0x88}, "??_8?$basic_ostringstream@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@7B@"},
    {{0x54, 0x98}, "??_8?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@7B?$basic_istream@DU?$char_traits@D@std@@@1@@"},
    {{0x4c, 0x88}, "??_8?$basic_stringstream@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@7B?$basic_ostream@DU?$char_traits@D@std@@@1@@"},
    {{0x54, 0x98}, "??_8?$basic_stringstream@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@7B?$basic_istream@GU?$char_traits@G@std@@@1@@"},
    {{0x4c, 0x88}, "??_8?$basic_stringstream@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@7B?$basic_ostream@GU?$char_traits@G@std@@@1@@"},
    {{0x54, 0x98}, "??_8?$basic_stringstream@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@7B?$basic_istream@_WU?$char_traits@_W@std@@@1@@"},
    {{0x4c, 0x88}, "??_8?$basic_stringstream@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@7B?$basic_ostream@_WU?$char_traits@_W@std@@@1@@"},
    {{ 0x0,  0x0}, 0}
};

static void test_vbtable_size_exports(void)
{
    int i;
    const int *p_vbtable;
    int arch_idx = (sizeof(void*) == 8);

    for (i = 0; vbtable_size_exports_list[i].export_name; i++)
    {
        SET(p_vbtable, vbtable_size_exports_list[i].export_name);

        ok(p_vbtable[0] == 0, "vbtable[0] wrong, got 0x%x\n", p_vbtable[0]);
        ok(p_vbtable[1] == vbtable_size_exports_list[i].value[arch_idx],
                "%d: %s[1] wrong, got 0x%x\n", i, vbtable_size_exports_list[i].export_name, p_vbtable[1]);
    }
}

1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080


static void test_locale__Locimp__Locimp_Addfac(void)
{
    locale__Locimp locimp;
    locale_facet facet;

    memset(&locimp, 0, sizeof(locimp));
    memset(&facet, 0, sizeof(facet));
    p_locale__Locimp__Locimp_Addfac(&locimp, &facet, 1);
    ok(locimp.facet_cnt == 40, "locimp.facet_cnt = %d\n", (int)locimp.facet_cnt);
}

1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092
static void CDECL raise_handler(const void *except)
{
    ok(0, "unexpected call\n");
}

static void test_raise_handler(void)
{
    ok(!*p_Raise_handler, "_Raise_handler = %p\n", *p_Raise_handler);
    *p_Raise_handler = raise_handler;
    *p_Raise_handler = NULL;
}

1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
static void test__Strxfrm(void)
{
    const char in[] = "abc";

    MSVCP__Collvec coll;
    char out[64];
    size_t ret;

    memset(&coll, 0, sizeof(coll));

    out[0] = 'z';
    ret = p__Strxfrm(out, out + 1, in, in + 2, &coll);
    ok(ret == 2, "ret = %d\n", (int)ret);
    ok(out[0] == 'z', "out[0] = %x\n", out[0]);

    ret = p__Strxfrm(out, out + sizeof(out), in, in + 4, &coll);
    ok(ret == 4, "ret = %d\n", (int)ret);
    ok(!strcmp(in, out), "out = %s\n", out);
}

1113 1114 1115 1116 1117 1118
START_TEST(misc)
{
    if(!init())
        return;

    test_assign();
1119
    test_equal();
1120
    test_Copy_s();
1121
    test_wctype();
1122
    test__Getctype();
1123
    test__Getcoll();
1124
    test_towctrans();
1125
    test_virtual_call();
1126
    test_virtual_base_dtors();
1127
    test_allocator_char();
1128
    test_Ctraits_math_functions();
1129
    test_complex();
1130
    test_vbtable_size_exports();
1131
    test_locale__Locimp__Locimp_Addfac();
1132
    test_raise_handler();
1133
    test__Strxfrm();
1134

1135
    ok(!invalid_parameter, "invalid_parameter_handler was invoked too many times\n");
1136 1137 1138

    FreeLibrary(msvcr);
    FreeLibrary(msvcp);
1139
}