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
);
53 static WCHAR string
[] = {'s','t','r','i','n','g',0};
54 static WCHAR String
[] = {'S','t','r','i','n','g',0};
55 static WCHAR foo
[] = {'f','o','o',0};
57 static void load_it_up(void)
59 hdll
= GetModuleHandleA("setupapi.dll");
61 pStringTableInitialize
= (void*)GetProcAddress(hdll
, "StringTableInitialize");
62 if (!pStringTableInitialize
)
63 pStringTableInitialize
= (void*)GetProcAddress(hdll
, "pSetupStringTableInitialize");
65 pStringTableInitializeEx
= (void*)GetProcAddress(hdll
, "StringTableInitializeEx");
66 if (!pStringTableInitializeEx
)
67 pStringTableInitializeEx
= (void*)GetProcAddress(hdll
, "pSetupStringTableInitializeEx");
69 pStringTableAddString
= (void*)GetProcAddress(hdll
, "StringTableAddString");
70 if (!pStringTableAddString
)
71 pStringTableAddString
= (void*)GetProcAddress(hdll
, "pSetupStringTableAddString");
73 pStringTableAddStringEx
= (void*)GetProcAddress(hdll
, "StringTableAddStringEx");
74 if (!pStringTableAddStringEx
)
75 pStringTableAddStringEx
= (void*)GetProcAddress(hdll
, "pSetupStringTableAddStringEx");
77 pStringTableDuplicate
= (void*)GetProcAddress(hdll
, "StringTableDuplicate");
78 if (!pStringTableDuplicate
)
79 pStringTableDuplicate
= (void*)GetProcAddress(hdll
, "pSetupStringTableDuplicate");
81 pStringTableDestroy
= (void*)GetProcAddress(hdll
, "StringTableDestroy");
82 if (!pStringTableDestroy
)
83 pStringTableDestroy
= (void*)GetProcAddress(hdll
, "pSetupStringTableDestroy");
85 pStringTableLookUpString
= (void*)GetProcAddress(hdll
, "StringTableLookUpString");
86 if (!pStringTableLookUpString
)
87 pStringTableLookUpString
= (void*)GetProcAddress(hdll
, "pSetupStringTableLookUpString");
89 pStringTableLookUpStringEx
= (void*)GetProcAddress(hdll
, "StringTableLookUpStringEx");
90 if (!pStringTableLookUpStringEx
)
91 pStringTableLookUpStringEx
= (void*)GetProcAddress(hdll
, "pSetupStringTableLookUpStringEx");
93 pStringTableStringFromId
= (void*)GetProcAddress(hdll
, "StringTableStringFromId");
94 if (!pStringTableStringFromId
)
95 pStringTableStringFromId
= (void*)GetProcAddress(hdll
, "pSetupStringTableStringFromId");
98 static void test_StringTableAddString(void)
100 DWORD retval
, hstring
, hString
, hfoo
;
103 table
= pStringTableInitialize();
104 ok(table
!= NULL
, "failed to initialize string table\n");
106 /* case insensitive */
107 hstring
=pStringTableAddString(table
,string
,0);
108 ok(hstring
!=-1,"Failed to add string to String Table\n");
110 retval
=pStringTableAddString(table
,String
,0);
111 ok(retval
!=-1,"Failed to add String to String Table\n");
112 ok(hstring
==retval
,"string handle %x != String handle %x in String Table\n", hstring
, retval
);
114 hfoo
=pStringTableAddString(table
,foo
,0);
115 ok(hfoo
!=-1,"Failed to add foo to String Table\n");
116 ok(hfoo
!=hstring
,"foo and string share the same ID %x in String Table\n", hfoo
);
119 hString
=pStringTableAddString(table
,String
,ST_CASE_SENSITIVE_COMPARE
);
120 ok(hstring
!=hString
,"String handle and string share same ID %x in Table\n", hstring
);
122 pStringTableDestroy(table
);
125 static void test_StringTableAddStringEx(void)
127 DWORD retval
, hstring
, hString
, hfoo
;
130 table
= pStringTableInitialize();
131 ok(table
!= NULL
,"Failed to Initialize String Table\n");
133 /* case insensitive */
134 hstring
= pStringTableAddStringEx(table
, string
, 0, NULL
, 0);
135 ok(hstring
!= ~0u, "Failed to add string to String Table\n");
137 retval
= pStringTableAddStringEx(table
, String
, 0, NULL
, 0);
138 ok(retval
!= ~0u, "Failed to add String to String Table\n");
139 ok(hstring
== retval
, "string handle %x != String handle %x in String Table\n", hstring
, retval
);
141 hfoo
= pStringTableAddStringEx(table
, foo
, 0, NULL
, 0);
142 ok(hfoo
!= ~0u, "Failed to add foo to String Table\n");
143 ok(hfoo
!= hstring
, "foo and string share the same ID %x in String Table\n", hfoo
);
146 hString
= pStringTableAddStringEx(table
, String
, ST_CASE_SENSITIVE_COMPARE
, NULL
, 0);
147 ok(hstring
!= hString
, "String handle and string share same ID %x in Table\n", hstring
);
149 pStringTableDestroy(table
);
152 static void test_StringTableDuplicate(void)
154 HANDLE table
, table2
;
156 table
= pStringTableInitialize();
157 ok(table
!= NULL
,"Failed to Initialize String Table\n");
159 table2
=pStringTableDuplicate(table
);
160 ok(table2
!=NULL
,"Failed to duplicate String Table\n");
162 pStringTableDestroy(table
);
163 pStringTableDestroy(table2
);
166 static void test_StringTableLookUpString(void)
168 DWORD retval
, retval2
, hstring
, hString
, hfoo
;
169 HANDLE table
, table2
;
171 table
= pStringTableInitialize();
172 ok(table
!= NULL
,"failed to initialize string table\n");
174 hstring
= pStringTableAddString(table
, string
, 0);
175 ok(hstring
!= ~0u, "failed to add 'string' to string table\n");
177 hString
= pStringTableAddString(table
, String
, 0);
178 ok(hString
!= ~0u,"failed to add 'String' to string table\n");
180 hfoo
= pStringTableAddString(table
, foo
, 0);
181 ok(hfoo
!= ~0u, "failed to add 'foo' to string table\n");
183 table2
= pStringTableDuplicate(table
);
184 ok(table2
!= NULL
, "Failed to duplicate String Table\n");
186 /* case insensitive */
187 retval
=pStringTableLookUpString(table
,string
,0);
188 ok(retval
!=-1,"Failed find string in String Table 1\n");
190 "Lookup for string (%x) does not match previous handle (%x) in String Table 1\n",
193 retval
=pStringTableLookUpString(table2
,string
,0);
194 ok(retval
!=-1,"Failed find string in String Table 2\n");
196 retval
=pStringTableLookUpString(table
,String
,0);
197 ok(retval
!=-1,"Failed find String in String Table 1\n");
199 retval
=pStringTableLookUpString(table2
,String
,0);
200 ok(retval
!=-1,"Failed find String in String Table 2\n");
202 retval
=pStringTableLookUpString(table
,foo
,0);
203 ok(retval
!=-1,"Failed find foo in String Table 1\n");
205 "Lookup for foo (%x) does not match previous handle (%x) in String Table 1\n",
208 retval
=pStringTableLookUpString(table2
,foo
,0);
209 ok(retval
!=-1,"Failed find foo in String Table 2\n");
212 retval
=pStringTableLookUpString(table
,string
,ST_CASE_SENSITIVE_COMPARE
);
213 retval2
=pStringTableLookUpString(table
,String
,ST_CASE_SENSITIVE_COMPARE
);
214 ok(retval
!=retval2
,"Lookup of string equals String in Table 1\n");
216 "Lookup for String (%x) does not match previous handle (%x) in String Table 1\n",
219 pStringTableDestroy(table
);
220 pStringTableDestroy(table2
);
223 static void test_StringTableLookUpStringEx(void)
225 static WCHAR uilevel
[] = {'U','I','L','E','V','E','L',0};
226 DWORD retval
, retval2
, hstring
, hString
, hfoo
, data
;
227 HANDLE table
, table2
;
230 table
= pStringTableInitialize();
231 ok(table
!= NULL
,"Failed to Initialize String Table\n");
233 hstring
= pStringTableAddString(table
, string
, 0);
234 ok(hstring
!= ~0u, "failed to add 'string' to string table\n");
236 hString
= pStringTableAddString(table
, String
, 0);
237 ok(hString
!= ~0u,"failed to add 'String' to string table\n");
239 hfoo
= pStringTableAddString(table
, foo
, 0);
240 ok(hfoo
!= ~0u, "failed to add 'foo' to string table\n");
242 table2
= pStringTableDuplicate(table
);
243 ok(table2
!= NULL
, "Failed to duplicate String Table\n");
245 /* case insensitive */
246 retval
= pStringTableLookUpStringEx(table
, string
, 0, NULL
, 0);
247 ok(retval
!= ~0u, "Failed find string in String Table 1\n");
248 ok(retval
== hstring
,
249 "Lookup for string (%x) does not match previous handle (%x) in String Table 1\n",
252 retval
= pStringTableLookUpStringEx(table2
, string
, 0, NULL
, 0);
253 ok(retval
!= ~0u, "Failed find string in String Table 2\n");
255 retval
= pStringTableLookUpStringEx(table
, String
, 0, NULL
, 0);
256 ok(retval
!= ~0u, "Failed find String in String Table 1\n");
258 retval
= pStringTableLookUpStringEx(table2
, String
, 0, NULL
, 0);
259 ok(retval
!= ~0u, "Failed find String in String Table 2\n");
261 retval
=pStringTableLookUpStringEx(table
, foo
, 0, NULL
, 0);
262 ok(retval
!= ~0u, "Failed find foo in String Table 1\n");
264 "Lookup for foo (%x) does not match previous handle (%x) in String Table 1\n",
267 retval
= pStringTableLookUpStringEx(table2
, foo
, 0, NULL
, 0);
268 ok(retval
!= ~0u, "Failed find foo in String Table 2\n");
271 retval
= pStringTableLookUpStringEx(table
, string
,ST_CASE_SENSITIVE_COMPARE
, NULL
, 0);
272 retval2
= pStringTableLookUpStringEx(table
, String
, ST_CASE_SENSITIVE_COMPARE
, NULL
, 0);
273 ok(retval
!= retval2
, "Lookup of string equals String in Table 1\n");
274 ok(retval
== hString
,
275 "Lookup for String (%x) does not match previous handle (%x) in String Table 1\n",
278 pStringTableDestroy(table
);
280 table
= pStringTableInitializeEx(0x1000, 0);
281 ok(table
!= NULL
, "failed to initialize string table\n");
284 retval
= pStringTableAddStringEx(table
, uilevel
, 0x5, &data
, sizeof(data
));
285 ok(retval
!= ~0u, "failed to add 'UILEVEL' to string table\n");
287 memset(buffer
, 0x55, sizeof(buffer
));
288 retval
= pStringTableLookUpStringEx(table
, uilevel
, ST_CASE_SENSITIVE_COMPARE
, buffer
, 0);
289 ok(retval
!= ~0u, "failed find 'UILEVEL' in string table\n");
290 ok(memcmp(buffer
, &data
, 4), "unexpected data\n");
292 memset(buffer
, 0x55, sizeof(buffer
));
293 retval
= pStringTableLookUpStringEx(table
, uilevel
, ST_CASE_SENSITIVE_COMPARE
, buffer
, 2);
294 ok(retval
!= ~0u, "failed find 'UILEVEL' in string table\n");
295 ok(!memcmp(buffer
, &data
, 2), "unexpected data\n");
297 memset(buffer
, 0x55, sizeof(buffer
));
298 retval
= pStringTableLookUpStringEx(table
, uilevel
, ST_CASE_SENSITIVE_COMPARE
, buffer
, sizeof(buffer
));
299 ok(retval
!= ~0u, "failed find 'UILEVEL' in string table\n");
300 ok(!memcmp(buffer
, &data
, 4), "unexpected data\n");
302 pStringTableDestroy(table
);
303 pStringTableDestroy(table2
);
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();