2 * Copyright 2016 Daniel Lehman (Esri)
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
27 #include "wine/test.h"
29 typedef unsigned char MSVCRT_bool
;
34 } __std_exception_data
;
42 typedef struct _type_info_list
48 static void* (CDECL
*p_malloc
)(size_t);
49 static void (CDECL
*p___std_exception_copy
)(const __std_exception_data
*, __std_exception_data
*);
50 static void (CDECL
*p___std_exception_destroy
)(__std_exception_data
*);
51 static int (CDECL
*p___std_type_info_compare
)(const type_info140
*, const type_info140
*);
52 static const char* (CDECL
*p___std_type_info_name
)(type_info140
*, SLIST_HEADER
*);
53 static void (CDECL
*p___std_type_info_destroy_list
)(SLIST_HEADER
*);
54 static size_t (CDECL
*p___std_type_info_hash
)(type_info140
*);
57 static BOOL
init(void)
61 module
= LoadLibraryA("ucrtbase.dll");
64 win_skip("ucrtbase.dll not installed\n");
68 p_malloc
= (void*)GetProcAddress(module
, "malloc");
69 p___std_exception_copy
= (void*)GetProcAddress(module
, "__std_exception_copy");
70 p___std_exception_destroy
= (void*)GetProcAddress(module
, "__std_exception_destroy");
71 p___std_type_info_compare
= (void*)GetProcAddress(module
, "__std_type_info_compare");
72 p___std_type_info_name
= (void*)GetProcAddress(module
, "__std_type_info_name");
73 p___std_type_info_destroy_list
= (void*)GetProcAddress(module
, "__std_type_info_destroy_list");
74 p___std_type_info_hash
= (void*)GetProcAddress(module
, "__std_type_info_hash");
78 static void test___std_exception(void)
80 __std_exception_data src
;
81 __std_exception_data dst
;
83 if (0) /* crash on Windows */
85 p___std_exception_copy(NULL
, &src
);
86 p___std_exception_copy(&dst
, NULL
);
88 src
.what
= "invalid free";
90 p___std_exception_destroy(&src
);
91 p___std_exception_destroy(NULL
);
96 p___std_exception_copy(&src
, &dst
);
97 ok(dst
.what
== src
.what
, "expected what to be same, got src %p dst %p\n", src
.what
, dst
.what
);
98 ok(!dst
.dofree
, "expected 0, got %d\n", dst
.dofree
);
101 p___std_exception_copy(&src
, &dst
);
102 ok(dst
.what
!= src
.what
, "expected what to be different, got src %p dst %p\n", src
.what
, dst
.what
);
103 ok(dst
.dofree
== 1, "expected 1, got %d\n", dst
.dofree
);
105 p___std_exception_destroy(&dst
);
106 ok(!dst
.what
, "expected NULL, got %p\n", dst
.what
);
107 ok(!dst
.dofree
, "expected 0, got %d\n", dst
.dofree
);
111 p___std_exception_copy(&src
, &dst
);
112 ok(!dst
.what
, "dst.what != NULL\n");
113 ok(!dst
.dofree
, "dst.dofree != FALSE\n");
117 p___std_exception_copy(&src
, &dst
);
118 ok(!dst
.what
, "dst.what != NULL\n");
119 ok(!dst
.dofree
, "dst.dofree != FALSE\n");
122 static void test___std_type_info(void)
124 type_info140 ti1
= { NULL
, ".?AVa@@" };
125 type_info140 ti2
= { NULL
, ".?AVb@@" };
126 type_info140 ti3
= ti1
;
128 type_info_list
*elem
;
134 InitializeSListHead(&header
);
135 p___std_type_info_destroy_list(&header
);
137 elem
= p_malloc(sizeof(*elem
));
138 memset(elem
, 0, sizeof(*elem
));
139 InterlockedPushEntrySList(&header
, &elem
->entry
);
140 p___std_type_info_destroy_list(&header
);
141 ok(!InterlockedPopEntrySList(&header
), "list is not empty\n");
143 ret
= p___std_type_info_name(&ti1
, &header
);
144 ok(!strcmp(ret
, "class a"), "__std_type_info_name(&ti1) = %s\n", ret
);
145 ok(ti1
.name
== ret
, "ti1.name = %p, ret = %p\n", ti1
.name
, ret
);
147 p___std_type_info_destroy_list(&header
);
148 ok(!InterlockedPopEntrySList(&header
), "list is not empty\n");
149 ok(ti1
.name
== ret
, "ti1.name = %p, ret = %p\n", ti1
.name
, ret
);
152 eq
= p___std_type_info_compare(&ti1
, &ti1
);
153 ok(eq
== 0, "__std_type_info_compare(&ti1, &ti1) = %d\n", eq
);
155 eq
= p___std_type_info_compare(&ti1
, &ti2
);
156 ok(eq
== -1, "__std_type_info_compare(&ti1, &ti2) = %d\n", eq
);
158 eq
= p___std_type_info_compare(&ti1
, &ti3
);
159 ok(eq
== 0, "__std_type_info_compare(&ti1, &ti3) = %d\n", eq
);
164 hash1
= p___std_type_info_hash(&ti1
);
166 ok(hash1
== 0xcbf29ce44fd0bfc1, "hash = %p\n", (void*)hash1
);
168 ok(hash1
== 0x811c9dc5, "hash = %p\n", (void*)hash1
);
172 hash2
= p___std_type_info_hash(&ti1
);
173 ok(hash1
== hash2
, "hash1 != hash2 (first char not ignored)\n");
176 hash1
= p___std_type_info_hash(&ti1
);
178 ok(hash1
== 0xaf63bc4c29620a60, "hash = %p\n", (void*)hash1
);
180 ok(hash1
== 0x40c5b8c, "hash = %p\n", (void*)hash1
);
182 ok(hash1
!= hash2
, "hash1 == hash2 for different strings\n");
185 hash2
= p___std_type_info_hash(&ti1
);
186 ok(hash1
!= hash2
, "hash1 == hash2 for different strings\n");
188 hash1
= p___std_type_info_hash(&ti2
);
189 ok(hash1
!= hash2
, "hash1 == hash2 for different strings\n");
195 test___std_exception();
196 test___std_type_info();