2 * Unit test suite for StringTable functions
4 * Copyright 2005 Steven Edwards for ReactOS
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.
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.
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
22 * Add test for StringTableStringFromIdEx
34 #include "wine/test.h"
37 DECLARE_HANDLE(HSTRING_TABLE
);
39 /* Flags for StringTableAddString and StringTableLookUpString */
40 #define ST_CASE_SENSITIVE_COMPARE 0x00000001
42 static DWORD (WINAPI
*pStringTableAddString
)(HSTRING_TABLE
, LPWSTR
, DWORD
);
43 static DWORD (WINAPI
*pStringTableAddStringEx
)(HSTRING_TABLE
, LPWSTR
, DWORD
, LPVOID
, DWORD
);
44 static VOID (WINAPI
*pStringTableDestroy
)(HSTRING_TABLE
);
45 static HSTRING_TABLE (WINAPI
*pStringTableDuplicate
)(HSTRING_TABLE hStringTable
);
46 static HSTRING_TABLE (WINAPI
*pStringTableInitialize
)(VOID
);
47 static HSTRING_TABLE (WINAPI
*pStringTableInitializeEx
)(DWORD
, DWORD
);
48 static DWORD (WINAPI
*pStringTableLookUpString
)(HSTRING_TABLE
, LPWSTR
, DWORD
);
49 static DWORD (WINAPI
*pStringTableLookUpStringEx
)(HSTRING_TABLE
, LPWSTR
, DWORD
, LPVOID
, DWORD
);
50 static LPWSTR (WINAPI
*pStringTableStringFromId
)(HSTRING_TABLE
, DWORD
);
52 static BOOL (WINAPI
*pStringTableStringFromIdEx
)(HSTRING_TABLE
, DWORD
, LPWSTR
, LPDWORD
);
53 static VOID (WINAPI
*pStringTableTrim
)(HSTRING_TABLE
);
57 static WCHAR string
[] = {'s','t','r','i','n','g',0};
58 static WCHAR String
[] = {'S','t','r','i','n','g',0};
59 static WCHAR foo
[] = {'f','o','o',0};
61 static void load_it_up(void)
63 hdll
= GetModuleHandleA("setupapi.dll");
65 pStringTableInitialize
= (void*)GetProcAddress(hdll
, "StringTableInitialize");
66 if (!pStringTableInitialize
)
67 pStringTableInitialize
= (void*)GetProcAddress(hdll
, "pSetupStringTableInitialize");
69 pStringTableInitializeEx
= (void*)GetProcAddress(hdll
, "StringTableInitializeEx");
70 if (!pStringTableInitializeEx
)
71 pStringTableInitializeEx
= (void*)GetProcAddress(hdll
, "pSetupStringTableInitializeEx");
73 pStringTableAddString
= (void*)GetProcAddress(hdll
, "StringTableAddString");
74 if (!pStringTableAddString
)
75 pStringTableAddString
= (void*)GetProcAddress(hdll
, "pSetupStringTableAddString");
77 pStringTableAddStringEx
= (void*)GetProcAddress(hdll
, "StringTableAddStringEx");
78 if (!pStringTableAddStringEx
)
79 pStringTableAddStringEx
= (void*)GetProcAddress(hdll
, "pSetupStringTableAddStringEx");
81 pStringTableDuplicate
= (void*)GetProcAddress(hdll
, "StringTableDuplicate");
82 if (!pStringTableDuplicate
)
83 pStringTableDuplicate
= (void*)GetProcAddress(hdll
, "pSetupStringTableDuplicate");
85 pStringTableDestroy
= (void*)GetProcAddress(hdll
, "StringTableDestroy");
86 if (!pStringTableDestroy
)
87 pStringTableDestroy
= (void*)GetProcAddress(hdll
, "pSetupStringTableDestroy");
89 pStringTableLookUpString
= (void*)GetProcAddress(hdll
, "StringTableLookUpString");
90 if (!pStringTableLookUpString
)
91 pStringTableLookUpString
= (void*)GetProcAddress(hdll
, "pSetupStringTableLookUpString");
93 pStringTableLookUpStringEx
= (void*)GetProcAddress(hdll
, "StringTableLookUpStringEx");
94 if (!pStringTableLookUpStringEx
)
95 pStringTableLookUpStringEx
= (void*)GetProcAddress(hdll
, "pSetupStringTableLookUpStringEx");
97 pStringTableStringFromId
= (void*)GetProcAddress(hdll
, "StringTableStringFromId");
98 if (!pStringTableStringFromId
)
99 pStringTableStringFromId
= (void*)GetProcAddress(hdll
, "pSetupStringTableStringFromId");
102 static void test_StringTableAddString(void)
104 DWORD retval
, hstring
, hString
, hfoo
;
107 table
= pStringTableInitialize();
108 ok(table
!= NULL
, "failed to initialize string table\n");
110 /* case insensitive */
111 hstring
=pStringTableAddString(table
,string
,0);
112 ok(hstring
!=-1,"Failed to add string to String Table\n");
114 retval
=pStringTableAddString(table
,String
,0);
115 ok(retval
!=-1,"Failed to add String to String Table\n");
116 ok(hstring
==retval
,"string handle %x != String handle %x in String Table\n", hstring
, retval
);
118 hfoo
=pStringTableAddString(table
,foo
,0);
119 ok(hfoo
!=-1,"Failed to add foo to String Table\n");
120 ok(hfoo
!=hstring
,"foo and string share the same ID %x in String Table\n", hfoo
);
123 hString
=pStringTableAddString(table
,String
,ST_CASE_SENSITIVE_COMPARE
);
124 ok(hstring
!=hString
,"String handle and string share same ID %x in Table\n", hstring
);
126 pStringTableDestroy(table
);
129 static void test_StringTableAddStringEx(void)
131 DWORD retval
, hstring
, hString
, hfoo
;
134 table
= pStringTableInitialize();
135 ok(table
!= NULL
,"Failed to Initialize String Table\n");
137 /* case insensitive */
138 hstring
= pStringTableAddStringEx(table
, string
, 0, NULL
, 0);
139 ok(hstring
!= ~0u, "Failed to add string to String Table\n");
141 retval
= pStringTableAddStringEx(table
, String
, 0, NULL
, 0);
142 ok(retval
!= ~0u, "Failed to add String to String Table\n");
143 ok(hstring
== retval
, "string handle %x != String handle %x in String Table\n", hstring
, retval
);
145 hfoo
= pStringTableAddStringEx(table
, foo
, 0, NULL
, 0);
146 ok(hfoo
!= ~0u, "Failed to add foo to String Table\n");
147 ok(hfoo
!= hstring
, "foo and string share the same ID %x in String Table\n", hfoo
);
150 hString
= pStringTableAddStringEx(table
, String
, ST_CASE_SENSITIVE_COMPARE
, NULL
, 0);
151 ok(hstring
!= hString
, "String handle and string share same ID %x in Table\n", hstring
);
153 pStringTableDestroy(table
);
156 static void test_StringTableDuplicate(void)
158 HANDLE table
, table2
;
160 table
= pStringTableInitialize();
161 ok(table
!= NULL
,"Failed to Initialize String Table\n");
163 table2
=pStringTableDuplicate(table
);
164 ok(table2
!=NULL
,"Failed to duplicate String Table\n");
166 pStringTableDestroy(table
);
167 pStringTableDestroy(table2
);
170 static void test_StringTableLookUpString(void)
172 DWORD retval
, retval2
, hstring
, hString
, hfoo
;
173 HANDLE table
, table2
;
175 table
= pStringTableInitialize();
176 ok(table
!= NULL
,"failed to initialize string table\n");
178 hstring
= pStringTableAddString(table
, string
, 0);
179 ok(hstring
!= ~0u, "failed to add 'string' to string table\n");
181 hString
= pStringTableAddString(table
, String
, 0);
182 ok(hString
!= ~0u,"failed to add 'String' to string table\n");
184 hfoo
= pStringTableAddString(table
, foo
, 0);
185 ok(hfoo
!= ~0u, "failed to add 'foo' to string table\n");
187 table2
= pStringTableDuplicate(table
);
188 ok(table2
!= NULL
, "Failed to duplicate String Table\n");
190 /* case insensitive */
191 retval
=pStringTableLookUpString(table
,string
,0);
192 ok(retval
!=-1,"Failed find string in String Table 1\n");
194 "Lookup for string (%x) does not match previous handle (%x) in String Table 1\n",
197 retval
=pStringTableLookUpString(table2
,string
,0);
198 ok(retval
!=-1,"Failed find string in String Table 2\n");
200 retval
=pStringTableLookUpString(table
,String
,0);
201 ok(retval
!=-1,"Failed find String in String Table 1\n");
203 retval
=pStringTableLookUpString(table2
,String
,0);
204 ok(retval
!=-1,"Failed find String in String Table 2\n");
206 retval
=pStringTableLookUpString(table
,foo
,0);
207 ok(retval
!=-1,"Failed find foo in String Table 1\n");
209 "Lookup for foo (%x) does not match previous handle (%x) in String Table 1\n",
212 retval
=pStringTableLookUpString(table2
,foo
,0);
213 ok(retval
!=-1,"Failed find foo in String Table 2\n");
216 retval
=pStringTableLookUpString(table
,string
,ST_CASE_SENSITIVE_COMPARE
);
217 retval2
=pStringTableLookUpString(table
,String
,ST_CASE_SENSITIVE_COMPARE
);
218 ok(retval
!=retval2
,"Lookup of string equals String in Table 1\n");
220 "Lookup for String (%x) does not match previous handle (%x) in String Table 1\n",
223 pStringTableDestroy(table
);
224 pStringTableDestroy(table2
);
227 static void test_StringTableLookUpStringEx(void)
229 static WCHAR uilevel
[] = {'U','I','L','E','V','E','L',0};
230 DWORD retval
, retval2
, hstring
, hString
, hfoo
, data
;
231 HANDLE table
, table2
;
234 table
= pStringTableInitialize();
235 ok(table
!= NULL
,"Failed to Initialize String Table\n");
237 hstring
= pStringTableAddString(table
, string
, 0);
238 ok(hstring
!= ~0u, "failed to add 'string' to string table\n");
240 hString
= pStringTableAddString(table
, String
, 0);
241 ok(hString
!= ~0u,"failed to add 'String' to string table\n");
243 hfoo
= pStringTableAddString(table
, foo
, 0);
244 ok(hfoo
!= ~0u, "failed to add 'foo' to string table\n");
246 table2
= pStringTableDuplicate(table
);
247 ok(table2
!= NULL
, "Failed to duplicate String Table\n");
249 /* case insensitive */
250 retval
= pStringTableLookUpStringEx(table
, string
, 0, NULL
, 0);
251 ok(retval
!= ~0u, "Failed find string in String Table 1\n");
252 ok(retval
== hstring
,
253 "Lookup for string (%x) does not match previous handle (%x) in String Table 1\n",
256 retval
= pStringTableLookUpStringEx(table2
, string
, 0, NULL
, 0);
257 ok(retval
!= ~0u, "Failed find string in String Table 2\n");
259 retval
= pStringTableLookUpStringEx(table
, String
, 0, NULL
, 0);
260 ok(retval
!= ~0u, "Failed find String in String Table 1\n");
262 retval
= pStringTableLookUpStringEx(table2
, String
, 0, NULL
, 0);
263 ok(retval
!= ~0u, "Failed find String in String Table 2\n");
265 retval
=pStringTableLookUpStringEx(table
, foo
, 0, NULL
, 0);
266 ok(retval
!= ~0u, "Failed find foo in String Table 1\n");
268 "Lookup for foo (%x) does not match previous handle (%x) in String Table 1\n",
271 retval
= pStringTableLookUpStringEx(table2
, foo
, 0, NULL
, 0);
272 ok(retval
!= ~0u, "Failed find foo in String Table 2\n");
275 retval
= pStringTableLookUpStringEx(table
, string
,ST_CASE_SENSITIVE_COMPARE
, NULL
, 0);
276 retval2
= pStringTableLookUpStringEx(table
, String
, ST_CASE_SENSITIVE_COMPARE
, NULL
, 0);
277 ok(retval
!= retval2
, "Lookup of string equals String in Table 1\n");
278 ok(retval
== hString
,
279 "Lookup for String (%x) does not match previous handle (%x) in String Table 1\n",
282 pStringTableDestroy(table
);
284 table
= pStringTableInitializeEx(0x1000, 0);
285 ok(table
!= NULL
, "failed to initialize string table\n");
288 retval
= pStringTableAddStringEx(table
, uilevel
, 0x5, &data
, sizeof(data
));
289 ok(retval
!= ~0u, "failed to add 'UILEVEL' to string table\n");
291 memset(buffer
, 0x55, sizeof(buffer
));
292 retval
= pStringTableLookUpStringEx(table
, uilevel
, ST_CASE_SENSITIVE_COMPARE
, buffer
, 0);
293 ok(retval
!= ~0u, "failed find 'UILEVEL' in string table\n");
294 ok(memcmp(buffer
, &data
, 4), "unexpected data\n");
296 memset(buffer
, 0x55, sizeof(buffer
));
297 retval
= pStringTableLookUpStringEx(table
, uilevel
, ST_CASE_SENSITIVE_COMPARE
, buffer
, 2);
298 ok(retval
!= ~0u, "failed find 'UILEVEL' in string table\n");
299 ok(!memcmp(buffer
, &data
, 2), "unexpected data\n");
301 memset(buffer
, 0x55, sizeof(buffer
));
302 retval
= pStringTableLookUpStringEx(table
, uilevel
, ST_CASE_SENSITIVE_COMPARE
, buffer
, sizeof(buffer
));
303 ok(retval
!= ~0u, "failed find 'UILEVEL' in string table\n");
304 ok(!memcmp(buffer
, &data
, 4), "unexpected data\n");
306 pStringTableDestroy(table
);
307 pStringTableDestroy(table2
);
310 static void test_StringTableStringFromId(void)
317 table
= pStringTableInitialize();
318 ok(table
!= NULL
,"Failed to Initialize String Table\n");
320 hstring
= pStringTableAddString(table
, string
, 0);
321 ok(hstring
!= ~0u,"failed to add 'string' to string table\n");
324 string2
=pStringTableStringFromId(table
,pStringTableLookUpString(table
,string
,0));
325 ok(string2
!=NULL
,"Failed to look up string by ID from String Table\n");
327 result
=lstrcmpiW(string
, string2
);
328 ok(result
==0,"StringID %p does not match requested StringID %p\n",string
,string2
);
330 pStringTableDestroy(table
);
333 START_TEST(stringtable
)
337 test_StringTableAddString();
338 test_StringTableAddStringEx();
339 test_StringTableDuplicate();
340 test_StringTableLookUpString();
341 test_StringTableLookUpStringEx();
342 test_StringTableStringFromId();