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 VOID (WINAPI *pStringTableDestroy)(HSTRING_TABLE);
44 static HSTRING_TABLE (WINAPI *pStringTableDuplicate)(HSTRING_TABLE hStringTable);
45 static HSTRING_TABLE (WINAPI *pStringTableInitialize)(VOID);
46 static DWORD (WINAPI *pStringTableLookUpString)(HSTRING_TABLE, LPWSTR, 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};
57 DWORD hstring, hString, hfoo; /* Handles pointing to our strings */
58 HANDLE table, table2; /* Handles pointing to our tables */
60 static void load_it_up(void)
62 hdll = LoadLibraryA("setupapi.dll");
66 pStringTableInitialize = (void*)GetProcAddress(hdll, "StringTableInitialize");
67 if (!pStringTableInitialize)
68 pStringTableInitialize = (void*)GetProcAddress(hdll, "pSetupStringTableInitialize");
70 pStringTableAddString = (void*)GetProcAddress(hdll, "StringTableAddString");
71 if (!pStringTableAddString)
72 pStringTableAddString = (void*)GetProcAddress(hdll, "pSetupStringTableAddString");
74 pStringTableDuplicate = (void*)GetProcAddress(hdll, "StringTableDuplicate");
75 if (!pStringTableDuplicate)
76 pStringTableDuplicate = (void*)GetProcAddress(hdll, "pSetupStringTableDuplicate");
78 pStringTableDestroy = (void*)GetProcAddress(hdll, "StringTableDestroy");
79 if (!pStringTableDestroy)
80 pStringTableDestroy = (void*)GetProcAddress(hdll, "pSetupStringTableDestroy");
82 pStringTableLookUpString = (void*)GetProcAddress(hdll, "StringTableLookUpString");
83 if (!pStringTableLookUpString)
84 pStringTableLookUpString = (void*)GetProcAddress(hdll, "pSetupStringTableLookUpString");
86 pStringTableStringFromId = (void*)GetProcAddress(hdll, "StringTableStringFromId");
87 if (!pStringTableStringFromId)
88 pStringTableStringFromId = (void*)GetProcAddress(hdll, "pSetupStringTableStringFromId");
91 static void test_StringTableInitialize(void)
93 table=pStringTableInitialize();
94 ok(table!=NULL,"Failed to Initialize String Table\n");
97 static void test_StringTableAddString(void)
101 /* case insensitive */
102 hstring=pStringTableAddString(table,string,0);
103 ok(hstring!=-1,"Failed to add string to String Table\n");
105 retval=pStringTableAddString(table,String,0);
106 ok(retval!=-1,"Failed to add String to String Table\n");
107 ok(hstring==retval,"string handle %x != String handle %x in String Table\n", hstring, retval);
109 hfoo=pStringTableAddString(table,foo,0);
110 ok(hfoo!=-1,"Failed to add foo to String Table\n");
111 ok(hfoo!=hstring,"foo and string share the same ID %x in String Table\n", hfoo);
114 hString=pStringTableAddString(table,String,ST_CASE_SENSITIVE_COMPARE);
115 ok(hstring!=hString,"String handle and string share same ID %x in Table\n", hstring);
118 static void test_StringTableDuplicate(void)
120 table2=pStringTableDuplicate(table);
121 ok(table2!=NULL,"Failed to duplicate String Table\n");
124 static void test_StringTableLookUpString(void)
126 DWORD retval, retval2;
128 /* case insensitive */
129 retval=pStringTableLookUpString(table,string,0);
130 ok(retval!=-1,"Failed find string in String Table 1\n");
132 "Lookup for string (%x) does not match previous handle (%x) in String Table 1\n",
135 retval=pStringTableLookUpString(table2,string,0);
136 ok(retval!=-1,"Failed find string in String Table 2\n");
138 retval=pStringTableLookUpString(table,String,0);
139 ok(retval!=-1,"Failed find String in String Table 1\n");
141 retval=pStringTableLookUpString(table2,String,0);
142 ok(retval!=-1,"Failed find String in String Table 2\n");
144 retval=pStringTableLookUpString(table,foo,0);
145 ok(retval!=-1,"Failed find foo in String Table 1\n");
147 "Lookup for foo (%x) does not match previous handle (%x) in String Table 1\n",
150 retval=pStringTableLookUpString(table2,foo,0);
151 ok(retval!=-1,"Failed find foo in String Table 2\n");
154 retval=pStringTableLookUpString(table,string,ST_CASE_SENSITIVE_COMPARE);
155 retval2=pStringTableLookUpString(table,String,ST_CASE_SENSITIVE_COMPARE);
156 ok(retval!=retval2,"Lookup of string equals String in Table 1\n");
158 "Lookup for String (%x) does not match previous handle (%x) in String Table 1\n",
162 static void test_StringTableStringFromId(void)
164 WCHAR *string2, *string3;
168 string2=pStringTableStringFromId(table,pStringTableLookUpString(table,string,0));
169 ok(string2!=NULL,"Failed to look up string by ID from String Table\n");
171 result=lstrcmpiW(string, string2);
172 ok(result==0,"StringID %p does not match requested StringID %p\n",string,string2);
174 /* This should never work */
175 string3=pStringTableStringFromId(table,0);
176 ok(string3!=NULL,"Failed to look up string by ID from String Table\n");
178 result=lstrcmpiW(string, string3);
179 ok(result!=0,"StringID %p matches requested StringID %p\n",string,string3);
182 START_TEST(stringtable)
186 test_StringTableInitialize();
187 test_StringTableAddString();
188 test_StringTableDuplicate();
189 test_StringTableLookUpString();
190 test_StringTableStringFromId();
192 /* assume we can always distroy */
193 pStringTableDestroy(table);
194 pStringTableDestroy(table2);