ReactOS 0.4.15-dev-7961-gdcf9eb0
stringtable.c
Go to the documentation of this file.
1/*
2 * Unit test suite for StringTable functions
3 *
4 * Copyright 2005 Steven Edwards for ReactOS
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20/*
21 * TODO:
22 * Add test for StringTableStringFromIdEx
23 */
24
25#include <stdarg.h>
26
27#include "windef.h"
28#include "winbase.h"
29#include "wingdi.h"
30#include "winuser.h"
31#include "winreg.h"
32#include "winnls.h"
33#include "setupapi.h"
34
35#include "wine/test.h"
36
37
38//DECLARE_HANDLE(HSTRING_TABLE);
39
40/* Flags for StringTableAddString and StringTableLookUpString */
41#define ST_CASE_SENSITIVE_COMPARE 0x00000001
42
43static DWORD (WINAPI *pStringTableAddString)(HSTRING_TABLE, LPWSTR, DWORD);
44static DWORD (WINAPI *pStringTableAddStringEx)(HSTRING_TABLE, LPWSTR, DWORD, LPVOID, DWORD);
45static VOID (WINAPI *pStringTableDestroy)(HSTRING_TABLE);
46static HSTRING_TABLE (WINAPI *pStringTableDuplicate)(HSTRING_TABLE hStringTable);
47static HSTRING_TABLE (WINAPI *pStringTableInitialize)(VOID);
48static HSTRING_TABLE (WINAPI *pStringTableInitializeEx)(DWORD, DWORD);
49static DWORD (WINAPI *pStringTableLookUpString)(HSTRING_TABLE, LPWSTR, DWORD);
50static DWORD (WINAPI *pStringTableLookUpStringEx)(HSTRING_TABLE, LPWSTR, DWORD, LPVOID, DWORD);
51static LPWSTR (WINAPI *pStringTableStringFromId)(HSTRING_TABLE, DWORD);
52static BOOL (WINAPI *pStringTableGetExtraData)(HSTRING_TABLE, ULONG, void*, ULONG);
53
54static WCHAR string[] = {'s','t','r','i','n','g',0};
55static WCHAR String[] = {'S','t','r','i','n','g',0};
56static WCHAR foo[] = {'f','o','o',0};
57
58static void load_it_up(void)
59{
60 HMODULE hdll = GetModuleHandleA("setupapi.dll");
61
62#define X(f) if (!(p##f = (void*)GetProcAddress(hdll, #f))) \
63 p##f = (void*)GetProcAddress(hdll, "pSetup"#f);
64 X(StringTableInitialize);
65 X(StringTableInitializeEx);
66 X(StringTableAddString);
67 X(StringTableAddStringEx);
68 X(StringTableDuplicate);
69 X(StringTableDestroy);
70 X(StringTableLookUpString);
71 X(StringTableLookUpStringEx);
72 X(StringTableStringFromId);
73 X(StringTableGetExtraData);
74#undef X
75}
76
78{
79 DWORD retval, hstring, hString, hfoo;
81
82 table = pStringTableInitialize();
83 ok(table != NULL, "failed to initialize string table\n");
84
85 /* case insensitive */
86 hstring=pStringTableAddString(table,string,0);
87 ok(hstring!=-1,"Failed to add string to String Table\n");
88
89 retval=pStringTableAddString(table,String,0);
90 ok(retval!=-1,"Failed to add String to String Table\n");
91 ok(hstring==retval,"string handle %x != String handle %x in String Table\n", hstring, retval);
92
93 hfoo=pStringTableAddString(table,foo,0);
94 ok(hfoo!=-1,"Failed to add foo to String Table\n");
95 ok(hfoo!=hstring,"foo and string share the same ID %x in String Table\n", hfoo);
96
97 /* case sensitive */
98 hString=pStringTableAddString(table,String,ST_CASE_SENSITIVE_COMPARE);
99 ok(hstring!=hString,"String handle and string share same ID %x in Table\n", hstring);
100
101 pStringTableDestroy(table);
102}
103
105{
106 DWORD retval, hstring, hString, hfoo, extra;
108 BOOL ret;
109
110 table = pStringTableInitialize();
111 ok(table != NULL,"Failed to Initialize String Table\n");
112
113 /* case insensitive */
114 hstring = pStringTableAddStringEx(table, string, 0, NULL, 0);
115 ok(hstring != -1, "Failed to add string to String Table\n");
116
117 retval = pStringTableAddStringEx(table, String, 0, NULL, 0);
118 ok(retval != -1, "Failed to add String to String Table\n");
119 ok(hstring == retval, "string handle %x != String handle %x in String Table\n", hstring, retval);
120
121 hfoo = pStringTableAddStringEx(table, foo, 0, NULL, 0);
122 ok(hfoo != -1, "Failed to add foo to String Table\n");
123 ok(hfoo != hstring, "foo and string share the same ID %x in String Table\n", hfoo);
124
125 /* case sensitive */
126 hString = pStringTableAddStringEx(table, String, ST_CASE_SENSITIVE_COMPARE, NULL, 0);
127 ok(hstring != hString, "String handle and string share same ID %x in Table\n", hstring);
128
129 pStringTableDestroy(table);
130
131 /* set same string twice but with different extra */
132 table = pStringTableInitializeEx(4, 0);
133 ok(table != NULL, "Failed to Initialize String Table\n");
134
135 extra = 10;
136 hstring = pStringTableAddStringEx(table, string, 0, &extra, 4);
137 ok(hstring != -1, "failed to add string, %d\n", hstring);
138
139 extra = 0;
140 ret = pStringTableGetExtraData(table, hstring, &extra, 4);
141 ok(ret && extra == 10, "got %d, extra %d\n", ret, extra);
142
143 extra = 11;
144 hstring = pStringTableAddStringEx(table, string, 0, &extra, 4);
145 ok(hstring != -1, "failed to add string, %d\n", hstring);
146
147 extra = 0;
148 ret = pStringTableGetExtraData(table, hstring, &extra, 4);
149 ok(ret && extra == 10, "got %d, extra %d\n", ret, extra);
150
151 pStringTableDestroy(table);
152}
153
155{
156 HSTRING_TABLE table, table2;
157
158 table = pStringTableInitialize();
159 ok(table != NULL,"Failed to Initialize String Table\n");
160
161 table2=pStringTableDuplicate(table);
162 ok(table2!=NULL,"Failed to duplicate String Table\n");
163
164 pStringTableDestroy(table);
165 pStringTableDestroy(table2);
166}
167
169{
170 DWORD retval, retval2, hstring, hString, hfoo;
171 HSTRING_TABLE table, table2;
172
173 table = pStringTableInitialize();
174 ok(table != NULL,"failed to initialize string table\n");
175
176 hstring = pStringTableAddString(table, string, 0);
177 ok(hstring != ~0u, "failed to add 'string' to string table\n");
178
179 hString = pStringTableAddString(table, String, 0);
180 ok(hString != ~0u,"failed to add 'String' to string table\n");
181
182 hfoo = pStringTableAddString(table, foo, 0);
183 ok(hfoo != ~0u, "failed to add 'foo' to string table\n");
184
185 table2 = pStringTableDuplicate(table);
186 ok(table2 != NULL, "Failed to duplicate String Table\n");
187
188 /* case insensitive */
189 retval=pStringTableLookUpString(table,string,0);
190 ok(retval!=-1,"Failed find string in String Table 1\n");
191 ok(retval==hstring,
192 "Lookup for string (%x) does not match previous handle (%x) in String Table 1\n",
193 retval, hstring);
194
195 retval=pStringTableLookUpString(table2,string,0);
196 ok(retval!=-1,"Failed find string in String Table 2\n");
197
198 retval=pStringTableLookUpString(table,String,0);
199 ok(retval!=-1,"Failed find String in String Table 1\n");
200
201 retval=pStringTableLookUpString(table2,String,0);
202 ok(retval!=-1,"Failed find String in String Table 2\n");
203
204 retval=pStringTableLookUpString(table,foo,0);
205 ok(retval!=-1,"Failed find foo in String Table 1\n");
206 ok(retval==hfoo,
207 "Lookup for foo (%x) does not match previous handle (%x) in String Table 1\n",
208 retval, hfoo);
209
210 retval=pStringTableLookUpString(table2,foo,0);
211 ok(retval!=-1,"Failed find foo in String Table 2\n");
212
213 /* case sensitive */
214 retval=pStringTableLookUpString(table,string,ST_CASE_SENSITIVE_COMPARE);
215 retval2=pStringTableLookUpString(table,String,ST_CASE_SENSITIVE_COMPARE);
216 ok(retval!=retval2,"Lookup of string equals String in Table 1\n");
217 ok(retval==hString,
218 "Lookup for String (%x) does not match previous handle (%x) in String Table 1\n",
219 retval, hString);
220
221 pStringTableDestroy(table);
222 pStringTableDestroy(table2);
223}
224
226{
227 static WCHAR uilevel[] = {'U','I','L','E','V','E','L',0};
228 DWORD retval, retval2, hstring, hString, hfoo, data;
229 HSTRING_TABLE table, table2;
230 char buffer[4];
231
232 table = pStringTableInitialize();
233 ok(table != NULL,"Failed to Initialize String Table\n");
234
235 hstring = pStringTableAddString(table, string, 0);
236 ok(hstring != ~0u, "failed to add 'string' to string table\n");
237
238 hString = pStringTableAddString(table, String, 0);
239 ok(hString != ~0u,"failed to add 'String' to string table\n");
240
241 hfoo = pStringTableAddString(table, foo, 0);
242 ok(hfoo != ~0u, "failed to add 'foo' to string table\n");
243
244 table2 = pStringTableDuplicate(table);
245 ok(table2 != NULL, "Failed to duplicate String Table\n");
246
247 /* case insensitive */
248 retval = pStringTableLookUpStringEx(table, string, 0, NULL, 0);
249 ok(retval != ~0u, "Failed find string in String Table 1\n");
250 ok(retval == hstring,
251 "Lookup for string (%x) does not match previous handle (%x) in String Table 1\n",
252 retval, hstring);
253
254 retval = pStringTableLookUpStringEx(table2, string, 0, NULL, 0);
255 ok(retval != ~0u, "Failed find string in String Table 2\n");
256
257 retval = pStringTableLookUpStringEx(table, String, 0, NULL, 0);
258 ok(retval != ~0u, "Failed find String in String Table 1\n");
259
260 retval = pStringTableLookUpStringEx(table2, String, 0, NULL, 0);
261 ok(retval != ~0u, "Failed find String in String Table 2\n");
262
263 retval=pStringTableLookUpStringEx(table, foo, 0, NULL, 0);
264 ok(retval != ~0u, "Failed find foo in String Table 1\n");
265 ok(retval == hfoo,
266 "Lookup for foo (%x) does not match previous handle (%x) in String Table 1\n",
267 retval, hfoo);
268
269 retval = pStringTableLookUpStringEx(table2, foo, 0, NULL, 0);
270 ok(retval != ~0u, "Failed find foo in String Table 2\n");
271
272 /* case sensitive */
273 retval = pStringTableLookUpStringEx(table, string,ST_CASE_SENSITIVE_COMPARE, NULL, 0);
274 retval2 = pStringTableLookUpStringEx(table, String, ST_CASE_SENSITIVE_COMPARE, NULL, 0);
275 ok(retval != retval2, "Lookup of string equals String in Table 1\n");
276 ok(retval == hString,
277 "Lookup for String (%x) does not match previous handle (%x) in String Table 1\n",
278 retval, hString);
279
280 pStringTableDestroy(table);
281
282 table = pStringTableInitializeEx(0x1000, 0);
283 ok(table != NULL, "failed to initialize string table\n");
284
285 data = 0xaaaaaaaa;
286 retval = pStringTableAddStringEx(table, uilevel, 0x5, &data, sizeof(data));
287 ok(retval != ~0u, "failed to add 'UILEVEL' to string table\n");
288
289 memset(buffer, 0x55, sizeof(buffer));
290 retval = pStringTableLookUpStringEx(table, uilevel, ST_CASE_SENSITIVE_COMPARE, buffer, 0);
291 ok(retval != ~0u, "failed find 'UILEVEL' in string table\n");
292 ok(memcmp(buffer, &data, 4), "unexpected data\n");
293
294 memset(buffer, 0x55, sizeof(buffer));
295 retval = pStringTableLookUpStringEx(table, uilevel, ST_CASE_SENSITIVE_COMPARE, buffer, 2);
296 ok(retval != ~0u, "failed find 'UILEVEL' in string table\n");
297 ok(!memcmp(buffer, &data, 2), "unexpected data\n");
298
299 memset(buffer, 0x55, sizeof(buffer));
300 retval = pStringTableLookUpStringEx(table, uilevel, ST_CASE_SENSITIVE_COMPARE, buffer, sizeof(buffer));
301 ok(retval != ~0u, "failed find 'UILEVEL' in string table\n");
302 ok(!memcmp(buffer, &data, 4), "unexpected data\n");
303
304 pStringTableDestroy(table);
305 pStringTableDestroy(table2);
306}
307
309{
311 WCHAR *string2;
312 DWORD id, id2;
313
314 table = pStringTableInitialize();
315 ok(table != NULL, "Failed to Initialize String Table\n");
316
317 id = pStringTableAddString(table, string, 0);
318 ok(id != -1, "failed to add 'string' to string table\n");
319
320 /* correct */
321 id2 = pStringTableLookUpString(table, string, 0);
322 ok(id2 == id, "got %d and %d\n", id2, id);
323
324 string2 = pStringTableStringFromId(table, id2);
325 ok(string2 != NULL, "failed to lookup string %d\n", id2);
326 ok(!lstrcmpiW(string, string2), "got %s, expected %s\n", wine_dbgstr_w(string2), wine_dbgstr_w(string));
327
328 pStringTableDestroy(table);
329}
330
332 char *data;
338};
339
340static void test_stringtable_layout(void)
341{
342 struct stringtable *ptr;
344
345 table = pStringTableInitialize();
346 ok(table != NULL,"failed to initialize string table\n");
347
348 ptr = (struct stringtable*)table;
349 ok(ptr->data != NULL, "got %p\n", ptr->data);
350 /* first data offset is right after bucket area */
351 ok(ptr->nextoffset == 509*sizeof(DWORD), "got %d\n", ptr->nextoffset);
352 ok(ptr->allocated != 0, "got %d\n", ptr->allocated);
353todo_wine {
354 ok(ptr->unk[0] != 0, "got %lx\n", ptr->unk[0]);
355 ok(ptr->unk[1] != 0, "got %lx\n", ptr->unk[1]);
356}
357 ok(ptr->max_extra_size == 0, "got %d\n", ptr->max_extra_size);
358 ok(ptr->lcid == GetThreadLocale(), "got %x, thread lcid %x\n", ptr->lcid, GetThreadLocale());
359
360 pStringTableDestroy(table);
361}
362
364{
365 load_it_up();
366
374}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define VOID
Definition: acefi.h:82
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint buffer
Definition: glext.h:5915
GLuint id
Definition: glext.h:5910
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
@ extra
Definition: id3.c:95
#define wine_dbgstr_w
Definition: kernel32.h:34
LCID WINAPI GetThreadLocale(void)
Definition: lang.c:1459
int WINAPI lstrcmpiW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:194
static PVOID ptr
Definition: dispmode.c:27
static CHAR string2[MAX_PATH]
Definition: automation.c:449
#define todo_wine
Definition: custom.c:79
static void test_StringTableAddString(void)
Definition: stringtable.c:77
static void test_stringtable_layout(void)
Definition: stringtable.c:340
#define X(f)
static void test_StringTableAddStringEx(void)
Definition: stringtable.c:104
static void test_StringTableLookUpStringEx(void)
Definition: stringtable.c:225
static LPWSTR
Definition: stringtable.c:43
static void load_it_up(void)
Definition: stringtable.c:58
static ULONG
Definition: stringtable.c:52
static DWORD
Definition: stringtable.c:43
static void test_StringTableLookUpString(void)
Definition: stringtable.c:168
#define ST_CASE_SENSITIVE_COMPARE
Definition: stringtable.c:41
static LPVOID
Definition: stringtable.c:44
static void test_StringTableDuplicate(void)
Definition: stringtable.c:154
static void test_StringTableStringFromId(void)
Definition: stringtable.c:308
#define BOOL
Definition: nt_native.h:43
DWORD LCID
Definition: nls.h:13
#define memset(x, y, z)
Definition: compat.h:39
PVOID HSTRING_TABLE
Definition: setupapi.h:674
static PVOID hdll
Definition: shimdbg.c:126
ULONG max_extra_size
Definition: stringtable.c:336
ULONG nextoffset
Definition: stringtable.c:333
DWORD_PTR unk[2]
Definition: stringtable.c:335
ULONG allocated
Definition: stringtable.c:334
char * data
Definition: stringtable.c:332
uint32_t DWORD_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
int ret
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
#define WINAPI
Definition: msvc.h:6
__wchar_t WCHAR
Definition: xmlstorage.h:180