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"
36 /* Flags for StringTableAddString and StringTableLookUpString */
37 #define ST_CASE_SENSITIVE_COMPARE 0x00000001
39 static DWORD (WINAPI
*pStringTableAddString
)(HSTRING_TABLE
, LPWSTR
, DWORD
);
40 static DWORD (WINAPI
*pStringTableAddStringEx
)(HSTRING_TABLE
, LPWSTR
, DWORD
, LPVOID
, DWORD
);
41 static VOID (WINAPI
*pStringTableDestroy
)(HSTRING_TABLE
);
42 static HSTRING_TABLE (WINAPI
*pStringTableDuplicate
)(HSTRING_TABLE hStringTable
);
43 static HSTRING_TABLE (WINAPI
*pStringTableInitialize
)(VOID
);
44 static HSTRING_TABLE (WINAPI
*pStringTableInitializeEx
)(DWORD
, DWORD
);
45 static DWORD (WINAPI
*pStringTableLookUpString
)(HSTRING_TABLE
, LPWSTR
, DWORD
);
46 static DWORD (WINAPI
*pStringTableLookUpStringEx
)(HSTRING_TABLE
, LPWSTR
, DWORD
, LPVOID
, DWORD
);
47 static LPWSTR (WINAPI
*pStringTableStringFromId
)(HSTRING_TABLE
, DWORD
);
49 static BOOL (WINAPI
*pStringTableStringFromIdEx
)(HSTRING_TABLE
, DWORD
, LPWSTR
, LPDWORD
);
50 static VOID (WINAPI
*pStringTableTrim
)(HSTRING_TABLE
);
54 static WCHAR string
[] = {'s','t','r','i','n','g',0};
55 static WCHAR String
[] = {'S','t','r','i','n','g',0};
56 static WCHAR foo
[] = {'f','o','o',0};
58 static void load_it_up(void)
60 hdll
= GetModuleHandleA("setupapi.dll");
62 pStringTableInitialize
= (void*)GetProcAddress(hdll
, "StringTableInitialize");
63 if (!pStringTableInitialize
)
64 pStringTableInitialize
= (void*)GetProcAddress(hdll
, "pSetupStringTableInitialize");
66 pStringTableInitializeEx
= (void*)GetProcAddress(hdll
, "StringTableInitializeEx");
67 if (!pStringTableInitializeEx
)
68 pStringTableInitializeEx
= (void*)GetProcAddress(hdll
, "pSetupStringTableInitializeEx");
70 pStringTableAddString
= (void*)GetProcAddress(hdll
, "StringTableAddString");
71 if (!pStringTableAddString
)
72 pStringTableAddString
= (void*)GetProcAddress(hdll
, "pSetupStringTableAddString");
74 pStringTableAddStringEx
= (void*)GetProcAddress(hdll
, "StringTableAddStringEx");
75 if (!pStringTableAddStringEx
)
76 pStringTableAddStringEx
= (void*)GetProcAddress(hdll
, "pSetupStringTableAddStringEx");
78 pStringTableDuplicate
= (void*)GetProcAddress(hdll
, "StringTableDuplicate");
79 if (!pStringTableDuplicate
)
80 pStringTableDuplicate
= (void*)GetProcAddress(hdll
, "pSetupStringTableDuplicate");
82 pStringTableDestroy
= (void*)GetProcAddress(hdll
, "StringTableDestroy");
83 if (!pStringTableDestroy
)
84 pStringTableDestroy
= (void*)GetProcAddress(hdll
, "pSetupStringTableDestroy");
86 pStringTableLookUpString
= (void*)GetProcAddress(hdll
, "StringTableLookUpString");
87 if (!pStringTableLookUpString
)
88 pStringTableLookUpString
= (void*)GetProcAddress(hdll
, "pSetupStringTableLookUpString");
90 pStringTableLookUpStringEx
= (void*)GetProcAddress(hdll
, "StringTableLookUpStringEx");
91 if (!pStringTableLookUpStringEx
)
92 pStringTableLookUpStringEx
= (void*)GetProcAddress(hdll
, "pSetupStringTableLookUpStringEx");
94 pStringTableStringFromId
= (void*)GetProcAddress(hdll
, "StringTableStringFromId");
95 if (!pStringTableStringFromId
)
96 pStringTableStringFromId
= (void*)GetProcAddress(hdll
, "pSetupStringTableStringFromId");
99 static void test_StringTableAddString(void)
101 DWORD retval
, hstring
, hString
, hfoo
;
104 table
= pStringTableInitialize();
105 ok(table
!= NULL
, "failed to initialize string table\n");
107 /* case insensitive */
108 hstring
=pStringTableAddString(table
,string
,0);
109 ok(hstring
!=-1,"Failed to add string to String Table\n");
111 retval
=pStringTableAddString(table
,String
,0);
112 ok(retval
!=-1,"Failed to add String to String Table\n");
113 ok(hstring
==retval
,"string handle %x != String handle %x in String Table\n", hstring
, retval
);
115 hfoo
=pStringTableAddString(table
,foo
,0);
116 ok(hfoo
!=-1,"Failed to add foo to String Table\n");
117 ok(hfoo
!=hstring
,"foo and string share the same ID %x in String Table\n", hfoo
);
120 hString
=pStringTableAddString(table
,String
,ST_CASE_SENSITIVE_COMPARE
);
121 ok(hstring
!=hString
,"String handle and string share same ID %x in Table\n", hstring
);
123 pStringTableDestroy(table
);
126 static void test_StringTableAddStringEx(void)
128 DWORD retval
, hstring
, hString
, hfoo
;
131 table
= pStringTableInitialize();
132 ok(table
!= NULL
,"Failed to Initialize String Table\n");
134 /* case insensitive */
135 hstring
= pStringTableAddStringEx(table
, string
, 0, NULL
, 0);
136 ok(hstring
!= ~0u, "Failed to add string to String Table\n");
138 retval
= pStringTableAddStringEx(table
, String
, 0, NULL
, 0);
139 ok(retval
!= ~0u, "Failed to add String to String Table\n");
140 ok(hstring
== retval
, "string handle %x != String handle %x in String Table\n", hstring
, retval
);
142 hfoo
= pStringTableAddStringEx(table
, foo
, 0, NULL
, 0);
143 ok(hfoo
!= ~0u, "Failed to add foo to String Table\n");
144 ok(hfoo
!= hstring
, "foo and string share the same ID %x in String Table\n", hfoo
);
147 hString
= pStringTableAddStringEx(table
, String
, ST_CASE_SENSITIVE_COMPARE
, NULL
, 0);
148 ok(hstring
!= hString
, "String handle and string share same ID %x in Table\n", hstring
);
150 pStringTableDestroy(table
);
153 static void test_StringTableDuplicate(void)
155 HANDLE table
, table2
;
157 table
= pStringTableInitialize();
158 ok(table
!= NULL
,"Failed to Initialize String Table\n");
160 table2
=pStringTableDuplicate(table
);
161 ok(table2
!=NULL
,"Failed to duplicate String Table\n");
163 pStringTableDestroy(table
);
164 pStringTableDestroy(table2
);
167 static void test_StringTableLookUpString(void)
169 DWORD retval
, retval2
, hstring
, hString
, hfoo
;
170 HANDLE table
, table2
;
172 table
= pStringTableInitialize();
173 ok(table
!= NULL
,"failed to initialize string table\n");
175 hstring
= pStringTableAddString(table
, string
, 0);
176 ok(hstring
!= ~0u, "failed to add 'string' to string table\n");
178 hString
= pStringTableAddString(table
, String
, 0);
179 ok(hString
!= ~0u,"failed to add 'String' to string table\n");
181 hfoo
= pStringTableAddString(table
, foo
, 0);
182 ok(hfoo
!= ~0u, "failed to add 'foo' to string table\n");
184 table2
= pStringTableDuplicate(table
);
185 ok(table2
!= NULL
, "Failed to duplicate String Table\n");
187 /* case insensitive */
188 retval
=pStringTableLookUpString(table
,string
,0);
189 ok(retval
!=-1,"Failed find string in String Table 1\n");
191 "Lookup for string (%x) does not match previous handle (%x) in String Table 1\n",
194 retval
=pStringTableLookUpString(table2
,string
,0);
195 ok(retval
!=-1,"Failed find string in String Table 2\n");
197 retval
=pStringTableLookUpString(table
,String
,0);
198 ok(retval
!=-1,"Failed find String in String Table 1\n");
200 retval
=pStringTableLookUpString(table2
,String
,0);
201 ok(retval
!=-1,"Failed find String in String Table 2\n");
203 retval
=pStringTableLookUpString(table
,foo
,0);
204 ok(retval
!=-1,"Failed find foo in String Table 1\n");
206 "Lookup for foo (%x) does not match previous handle (%x) in String Table 1\n",
209 retval
=pStringTableLookUpString(table2
,foo
,0);
210 ok(retval
!=-1,"Failed find foo in String Table 2\n");
213 retval
=pStringTableLookUpString(table
,string
,ST_CASE_SENSITIVE_COMPARE
);
214 retval2
=pStringTableLookUpString(table
,String
,ST_CASE_SENSITIVE_COMPARE
);
215 ok(retval
!=retval2
,"Lookup of string equals String in Table 1\n");
217 "Lookup for String (%x) does not match previous handle (%x) in String Table 1\n",
220 pStringTableDestroy(table
);
221 pStringTableDestroy(table2
);
224 static void test_StringTableLookUpStringEx(void)
226 static WCHAR uilevel
[] = {'U','I','L','E','V','E','L',0};
227 DWORD retval
, retval2
, hstring
, hString
, hfoo
, data
;
228 HANDLE table
, table2
;
231 table
= pStringTableInitialize();
232 ok(table
!= NULL
,"Failed to Initialize String Table\n");
234 hstring
= pStringTableAddString(table
, string
, 0);
235 ok(hstring
!= ~0u, "failed to add 'string' to string table\n");
237 hString
= pStringTableAddString(table
, String
, 0);
238 ok(hString
!= ~0u,"failed to add 'String' to string table\n");
240 hfoo
= pStringTableAddString(table
, foo
, 0);
241 ok(hfoo
!= ~0u, "failed to add 'foo' to string table\n");
243 table2
= pStringTableDuplicate(table
);
244 ok(table2
!= NULL
, "Failed to duplicate String Table\n");
246 /* case insensitive */
247 retval
= pStringTableLookUpStringEx(table
, string
, 0, NULL
, 0);
248 ok(retval
!= ~0u, "Failed find string in String Table 1\n");
249 ok(retval
== hstring
,
250 "Lookup for string (%x) does not match previous handle (%x) in String Table 1\n",
253 retval
= pStringTableLookUpStringEx(table2
, string
, 0, NULL
, 0);
254 ok(retval
!= ~0u, "Failed find string in String Table 2\n");
256 retval
= pStringTableLookUpStringEx(table
, String
, 0, NULL
, 0);
257 ok(retval
!= ~0u, "Failed find String in String Table 1\n");
259 retval
= pStringTableLookUpStringEx(table2
, String
, 0, NULL
, 0);
260 ok(retval
!= ~0u, "Failed find String in String Table 2\n");
262 retval
=pStringTableLookUpStringEx(table
, foo
, 0, NULL
, 0);
263 ok(retval
!= ~0u, "Failed find foo in String Table 1\n");
265 "Lookup for foo (%x) does not match previous handle (%x) in String Table 1\n",
268 retval
= pStringTableLookUpStringEx(table2
, foo
, 0, NULL
, 0);
269 ok(retval
!= ~0u, "Failed find foo in String Table 2\n");
272 retval
= pStringTableLookUpStringEx(table
, string
,ST_CASE_SENSITIVE_COMPARE
, NULL
, 0);
273 retval2
= pStringTableLookUpStringEx(table
, String
, ST_CASE_SENSITIVE_COMPARE
, NULL
, 0);
274 ok(retval
!= retval2
, "Lookup of string equals String in Table 1\n");
275 ok(retval
== hString
,
276 "Lookup for String (%x) does not match previous handle (%x) in String Table 1\n",
279 pStringTableDestroy(table
);
281 table
= pStringTableInitializeEx(0x1000, 0);
282 ok(table
!= NULL
, "failed to initialize string table\n");
285 retval
= pStringTableAddStringEx(table
, uilevel
, 0x5, &data
, sizeof(data
));
286 ok(retval
!= ~0u, "failed to add 'UILEVEL' to string table\n");
288 memset(buffer
, 0x55, sizeof(buffer
));
289 retval
= pStringTableLookUpStringEx(table
, uilevel
, ST_CASE_SENSITIVE_COMPARE
, buffer
, 0);
290 ok(retval
!= ~0u, "failed find 'UILEVEL' in string table\n");
291 ok(memcmp(buffer
, &data
, 4), "unexpected data\n");
293 memset(buffer
, 0x55, sizeof(buffer
));
294 retval
= pStringTableLookUpStringEx(table
, uilevel
, ST_CASE_SENSITIVE_COMPARE
, buffer
, 2);
295 ok(retval
!= ~0u, "failed find 'UILEVEL' in string table\n");
296 ok(!memcmp(buffer
, &data
, 2), "unexpected data\n");
298 memset(buffer
, 0x55, sizeof(buffer
));
299 retval
= pStringTableLookUpStringEx(table
, uilevel
, ST_CASE_SENSITIVE_COMPARE
, buffer
, sizeof(buffer
));
300 ok(retval
!= ~0u, "failed find 'UILEVEL' in string table\n");
301 ok(!memcmp(buffer
, &data
, 4), "unexpected data\n");
303 pStringTableDestroy(table
);
306 static void test_StringTableStringFromId(void)
313 table
= pStringTableInitialize();
314 ok(table
!= NULL
,"Failed to Initialize String Table\n");
316 hstring
= pStringTableAddString(table
, string
, 0);
317 ok(hstring
!= ~0u,"failed to add 'string' to string table\n");
320 string2
=pStringTableStringFromId(table
,pStringTableLookUpString(table
,string
,0));
321 ok(string2
!=NULL
,"Failed to look up string by ID from String Table\n");
323 result
=lstrcmpiW(string
, string2
);
324 ok(result
==0,"StringID %p does not match requested StringID %p\n",string
,string2
);
326 pStringTableDestroy(table
);
329 START_TEST(stringtable
)
333 test_StringTableAddString();
334 test_StringTableAddStringEx();
335 test_StringTableDuplicate();
336 test_StringTableLookUpString();
337 test_StringTableLookUpStringEx();
338 test_StringTableStringFromId();