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 static DWORD (WINAPI *pStringTableAddString)(HSTRING_TABLE, LPWSTR, DWORD);
38 static VOID (WINAPI *pStringTableDestroy)(HSTRING_TABLE);
39 static HSTRING_TABLE (WINAPI *pStringTableDuplicate)(HSTRING_TABLE hStringTable);
40 static HSTRING_TABLE (WINAPI *pStringTableInitialize)(VOID);
41 static DWORD (WINAPI *pStringTableLookUpString)(HSTRING_TABLE, LPWSTR, DWORD);
42 static LPWSTR (WINAPI *pStringTableStringFromId)(HSTRING_TABLE, DWORD);
44 static BOOL (WINAPI *pStringTableStringFromIdEx)(HSTRING_TABLE, DWORD, LPWSTR, LPDWORD);
45 static VOID (WINAPI *pStringTableTrim)(HSTRING_TABLE);
49 static WCHAR string[] = {'s','t','r','i','n','g',0};
50 static WCHAR String[] = {'S','t','r','i','n','g',0};
51 static WCHAR foo[] = {'f','o','o',0};
52 DWORD hstring, hString, hfoo; /* Handles pointing to our strings */
53 HANDLE table, table2; /* Handles pointing to our tables */
55 static void load_it_up(void)
57 hdll = LoadLibraryA("setupapi.dll");
61 pStringTableInitialize = (void*)GetProcAddress(hdll, "StringTableInitialize");
62 if (!pStringTableInitialize)
63 pStringTableInitialize = (void*)GetProcAddress(hdll, "pSetupStringTableInitialize");
65 pStringTableAddString = (void*)GetProcAddress(hdll, "StringTableAddString");
66 if (!pStringTableAddString)
67 pStringTableAddString = (void*)GetProcAddress(hdll, "pSetupStringTableAddString");
69 pStringTableDuplicate = (void*)GetProcAddress(hdll, "StringTableDuplicate");
70 if (!pStringTableDuplicate)
71 pStringTableDuplicate = (void*)GetProcAddress(hdll, "pSetupStringTableDuplicate");
73 pStringTableDestroy = (void*)GetProcAddress(hdll, "StringTableDestroy");
74 if (!pStringTableDestroy)
75 pStringTableDestroy = (void*)GetProcAddress(hdll, "pSetupStringTableDestroy");
77 pStringTableLookUpString = (void*)GetProcAddress(hdll, "StringTableLookUpString");
78 if (!pStringTableLookUpString)
79 pStringTableLookUpString = (void*)GetProcAddress(hdll, "pSetupStringTableLookUpString");
81 pStringTableStringFromId = (void*)GetProcAddress(hdll, "StringTableStringFromId");
82 if (!pStringTableStringFromId)
83 pStringTableStringFromId = (void*)GetProcAddress(hdll, "pSetupStringTableStringFromId");
86 static void test_StringTableInitialize(void)
88 table=pStringTableInitialize();
89 ok(table!=NULL,"Failed to Initialize String Table\n");
92 static void test_StringTableAddString(void)
96 /* case insensitive */
97 hstring=pStringTableAddString(table,string,0);
98 ok(hstring!=-1,"Failed to add string to String Table\n");
100 retval=pStringTableAddString(table,String,0);
101 ok(retval!=-1,"Failed to add String to String Table\n");
102 ok(hstring==retval,"string handle %x != String handle %x in String Table\n", hstring, retval);
104 hfoo=pStringTableAddString(table,foo,0);
105 ok(hfoo!=-1,"Failed to add foo to String Table\n");
106 ok(hfoo!=hstring,"foo and string share the same ID %x in String Table\n", hfoo);
109 hString=pStringTableAddString(table,String,ST_CASE_SENSITIVE_COMPARE);
110 ok(hstring!=hString,"String handle and string share same ID %x in Table\n", hstring);
113 static void test_StringTableDuplicate(void)
115 table2=pStringTableDuplicate(table);
116 ok(table2!=NULL,"Failed to duplicate String Table\n");
119 static void test_StringTableLookUpString(void)
121 DWORD retval, retval2;
123 /* case insensitive */
124 retval=pStringTableLookUpString(table,string,0);
125 ok(retval!=-1,"Failed find string in String Table 1\n");
127 "Lookup for string (%x) does not match previous handle (%x) in String Table 1\n",
130 retval=pStringTableLookUpString(table2,string,0);
131 ok(retval!=-1,"Failed find string in String Table 2\n");
133 retval=pStringTableLookUpString(table,String,0);
134 ok(retval!=-1,"Failed find String in String Table 1\n");
136 retval=pStringTableLookUpString(table2,String,0);
137 ok(retval!=-1,"Failed find String in String Table 2\n");
139 retval=pStringTableLookUpString(table,foo,0);
140 ok(retval!=-1,"Failed find foo in String Table 1\n");
142 "Lookup for foo (%x) does not match previous handle (%x) in String Table 1\n",
145 retval=pStringTableLookUpString(table2,foo,0);
146 ok(retval!=-1,"Failed find foo in String Table 2\n");
149 retval=pStringTableLookUpString(table,string,ST_CASE_SENSITIVE_COMPARE);
150 retval2=pStringTableLookUpString(table,String,ST_CASE_SENSITIVE_COMPARE);
151 ok(retval!=retval2,"Lookup of string equals String in Table 1\n");
153 "Lookup for String (%x) does not match previous handle (%x) in String Table 1\n",
157 static void test_StringTableStringFromId(void)
159 WCHAR *string2, *string3;
163 string2=pStringTableStringFromId(table,pStringTableLookUpString(table,string,0));
164 ok(string2!=NULL,"Failed to look up string by ID from String Table\n");
166 result=lstrcmpiW(string, string2);
167 ok(result==0,"StringID %p does not match requested StringID %p\n",string,string2);
169 /* This should never work */
170 string3=pStringTableStringFromId(table,0);
171 ok(string3!=NULL,"Failed to look up string by ID from String Table\n");
173 result=lstrcmpiW(string, string3);
174 ok(result!=0,"StringID %p matches requested StringID %p\n",string,string3);
177 START_TEST(stringtable)
181 test_StringTableInitialize();
182 test_StringTableAddString();
183 test_StringTableDuplicate();
184 test_StringTableLookUpString();
185 test_StringTableStringFromId();
187 /* assume we can always distroy */
188 pStringTableDestroy(table);
189 pStringTableDestroy(table2);