wined3d: Remove stray '\' at end of lines.
[wine] / dlls / setupapi / tests / stringtable.c
1 /*
2  * Unit test suite for StringTable functions
3  *
4  * Copyright 2005 Steven Edwards for ReactOS
5  *
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.
10  *
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.
15  *
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
19  */
20 /* 
21  * TODO:
22  * Add test for StringTableStringFromIdEx
23  */
24
25 #include <stdarg.h>
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "winreg.h"
32 #include "setupapi.h"
33
34 #include "wine/test.h"
35
36
37 DECLARE_HANDLE(HSTRING_TABLE);
38
39 /* Flags for StringTableAddString and StringTableLookUpString */
40 #define ST_CASE_SENSITIVE_COMPARE       0x00000001
41
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);
48 #if 0
49 static BOOL     (WINAPI *pStringTableStringFromIdEx)(HSTRING_TABLE, DWORD, LPWSTR, LPDWORD);
50 static VOID     (WINAPI *pStringTableTrim)(HSTRING_TABLE);
51 #endif
52
53 HMODULE hdll;
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 */
59
60 static void load_it_up(void)
61 {
62     hdll = LoadLibraryA("setupapi.dll");
63     if (!hdll)
64         return;
65
66     pStringTableInitialize = (void*)GetProcAddress(hdll, "StringTableInitialize");
67     if (!pStringTableInitialize)
68         pStringTableInitialize = (void*)GetProcAddress(hdll, "pSetupStringTableInitialize");
69
70     pStringTableAddString = (void*)GetProcAddress(hdll, "StringTableAddString");
71     if (!pStringTableAddString)
72         pStringTableAddString = (void*)GetProcAddress(hdll, "pSetupStringTableAddString");
73
74     pStringTableDuplicate = (void*)GetProcAddress(hdll, "StringTableDuplicate");
75     if (!pStringTableDuplicate)
76         pStringTableDuplicate = (void*)GetProcAddress(hdll, "pSetupStringTableDuplicate");
77
78     pStringTableDestroy = (void*)GetProcAddress(hdll, "StringTableDestroy");
79     if (!pStringTableDestroy)
80         pStringTableDestroy = (void*)GetProcAddress(hdll, "pSetupStringTableDestroy");
81
82     pStringTableLookUpString = (void*)GetProcAddress(hdll, "StringTableLookUpString");
83     if (!pStringTableLookUpString)
84         pStringTableLookUpString = (void*)GetProcAddress(hdll, "pSetupStringTableLookUpString");
85
86     pStringTableStringFromId = (void*)GetProcAddress(hdll, "StringTableStringFromId");
87     if (!pStringTableStringFromId)
88         pStringTableStringFromId = (void*)GetProcAddress(hdll, "pSetupStringTableStringFromId");
89 }
90
91 static void test_StringTableInitialize(void)
92 {
93     table=pStringTableInitialize();
94     ok(table!=NULL,"Failed to Initialize String Table\n");
95 }
96
97 static void test_StringTableAddString(void)
98 {
99     DWORD retval;
100
101     /* case insensitive */
102     hstring=pStringTableAddString(table,string,0);
103     ok(hstring!=-1,"Failed to add string to String Table\n");
104     
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);        
108     
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);            
112     
113     /* case sensitive */    
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);        
116 }
117
118 static void test_StringTableDuplicate(void)
119 {
120     table2=pStringTableDuplicate(table);
121     ok(table2!=NULL,"Failed to duplicate String Table\n");
122 }
123
124 static void test_StringTableLookUpString(void)
125 {   
126     DWORD retval, retval2;
127     
128     /* case insensitive */
129     retval=pStringTableLookUpString(table,string,0);
130     ok(retval!=-1,"Failed find string in String Table 1\n");
131     ok(retval==hstring,
132         "Lookup for string (%x) does not match previous handle (%x) in String Table 1\n",
133         retval, hstring);    
134
135     retval=pStringTableLookUpString(table2,string,0);
136     ok(retval!=-1,"Failed find string in String Table 2\n");
137     
138     retval=pStringTableLookUpString(table,String,0);
139     ok(retval!=-1,"Failed find String in String Table 1\n");
140
141     retval=pStringTableLookUpString(table2,String,0);
142     ok(retval!=-1,"Failed find String in String Table 2\n");    
143     
144     retval=pStringTableLookUpString(table,foo,0);
145     ok(retval!=-1,"Failed find foo in String Table 1\n");    
146     ok(retval==hfoo,
147         "Lookup for foo (%x) does not match previous handle (%x) in String Table 1\n",
148         retval, hfoo);        
149     
150     retval=pStringTableLookUpString(table2,foo,0);
151     ok(retval!=-1,"Failed find foo in String Table 2\n");    
152     
153     /* case sensitive */
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");
157     ok(retval2==hString,
158         "Lookup for String (%x) does not match previous handle (%x) in String Table 1\n",
159         retval, hString);        
160 }
161
162 static void test_StringTableStringFromId(void)
163 {
164     WCHAR *string2, *string3;
165     int result;
166
167     /* correct */
168     string2=pStringTableStringFromId(table,pStringTableLookUpString(table,string,0));
169     ok(string2!=NULL,"Failed to look up string by ID from String Table\n");
170     
171     result=lstrcmpiW(string, string2);
172     ok(result==0,"StringID %p does not match requested StringID %p\n",string,string2);
173
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");
177
178     result=lstrcmpiW(string, string3);
179     ok(result!=0,"StringID %p matches requested StringID %p\n",string,string3);
180 }
181
182 START_TEST(stringtable)
183 {
184     load_it_up();
185
186     test_StringTableInitialize();
187     test_StringTableAddString();
188     test_StringTableDuplicate();
189     test_StringTableLookUpString();
190     test_StringTableStringFromId();
191
192     /* assume we can always distroy */
193     pStringTableDestroy(table);
194     pStringTableDestroy(table2);
195
196     FreeLibrary(hdll);
197 }