msvcp90/tests: Added char_traits assign tests.
[wine] / dlls / msvcp90 / tests / misc.c
1 /*
2  * Copyright 2010 Piotr Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #include <stdio.h>
20
21 #include <windef.h>
22 #include <winbase.h>
23 #include "wine/test.h"
24
25 static void* (__cdecl *p_set_invalid_parameter_handler)(void*);
26
27 static void (__cdecl *p_char_assign)(void*, const void*);
28 static void (__cdecl *p_wchar_assign)(void*, const void*);
29 static void (__cdecl *p_short_assign)(void*, const void*);
30
31 static int invalid_parameter = 0;
32 static void __cdecl test_invalid_parameter_handler(const wchar_t *expression,
33         const wchar_t *function, const wchar_t *file,
34         unsigned line, uintptr_t arg)
35 {
36     ok(expression == NULL, "expression is not NULL\n");
37     ok(function == NULL, "function is not NULL\n");
38     ok(file == NULL, "file is not NULL\n");
39     ok(line == 0, "line = %u\n", line);
40     ok(arg == 0, "arg = %lx\n", (UINT_PTR)arg);
41     invalid_parameter++;
42 }
43
44 static BOOL init(void)
45 {
46     HMODULE msvcr = LoadLibraryA("msvcr90.dll");
47     HMODULE msvcp = LoadLibraryA("msvcp90.dll");
48     if(!msvcr || !msvcp) {
49         win_skip("msvcp90.dll or msvcrt90.dll not installed\n");
50         return FALSE;
51     }
52
53     p_set_invalid_parameter_handler = (void*)GetProcAddress(msvcr, "_set_invalid_parameter_handler");
54     if(!p_set_invalid_parameter_handler) {
55         win_skip("Error setting tests environment\n");
56         return FALSE;
57     }
58
59     p_set_invalid_parameter_handler(test_invalid_parameter_handler);
60
61     p_char_assign = (void*)GetProcAddress(msvcp, "?assign@?$char_traits@D@std@@SAXAADABD@Z");
62     p_wchar_assign = (void*)GetProcAddress(msvcp, "?assign@?$char_traits@_W@std@@SAXAA_WAB_W@Z");
63     p_short_assign = (void*)GetProcAddress(msvcp, "?assign@?$char_traits@G@std@@SAXAAGABG@Z");
64
65     return TRUE;
66 }
67
68 static void test_assign(void)
69 {
70     const char in[] = "abc";
71     char out[4];
72
73     if(!p_char_assign || !p_wchar_assign || !p_short_assign) {
74         win_skip("assign tests skipped\n");
75         return;
76     }
77
78     out[1] = '#';
79     p_char_assign(out, in);
80     ok(out[0] == in[0], "out[0] = %c\n", out[0]);
81     ok(out[1] == '#', "out[1] = %c\n", out[1]);
82
83     out[2] = '#';
84     p_wchar_assign(out, in);
85     ok(*((char*)out)==in[0] && *((char*)out+1)==in[1],
86             "out[0] = %d, out[1] = %d\n", (int)out[0], (int)out[1]);
87     ok(out[2] == '#', "out[2] = %c\n", out[2]);
88
89     out[2] = '#';
90     p_short_assign(out, in);
91     ok(*((char*)out)==in[0] && *((char*)out+1)==in[1],
92             "out[0] = %d, out[1] = %d\n", (int)out[0], (int)out[1]);
93     ok(out[2] == '#', "out[2] = %c\n", out[2]);
94 }
95
96 START_TEST(misc)
97 {
98     if(!init())
99         return;
100
101     test_assign();
102
103     ok(!invalid_parameter, "invalid_parameter_handler was invoked too many times\n");
104 }