dinput: Move SetEventNotification and associated event into base class.
[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 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);
43 #if 0
44 static BOOL     (WINAPI *pStringTableStringFromIdEx)(HSTRING_TABLE, DWORD, LPWSTR, LPDWORD);
45 static VOID     (WINAPI *pStringTableTrim)(HSTRING_TABLE);
46 #endif
47
48 HMODULE hdll;
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 */
54
55 static void load_it_up(void)
56 {
57     hdll = LoadLibraryA("setupapi.dll");
58     if (!hdll)
59         return;
60
61     pStringTableInitialize = (void*)GetProcAddress(hdll, "StringTableInitialize");
62     if (!pStringTableInitialize)
63         pStringTableInitialize = (void*)GetProcAddress(hdll, "pSetupStringTableInitialize");
64
65     pStringTableAddString = (void*)GetProcAddress(hdll, "StringTableAddString");
66     if (!pStringTableAddString)
67         pStringTableAddString = (void*)GetProcAddress(hdll, "pSetupStringTableAddString");
68
69     pStringTableDuplicate = (void*)GetProcAddress(hdll, "StringTableDuplicate");
70     if (!pStringTableDuplicate)
71         pStringTableDuplicate = (void*)GetProcAddress(hdll, "pSetupStringTableDuplicate");
72
73     pStringTableDestroy = (void*)GetProcAddress(hdll, "StringTableDestroy");
74     if (!pStringTableDestroy)
75         pStringTableDestroy = (void*)GetProcAddress(hdll, "pSetupStringTableDestroy");
76
77     pStringTableLookUpString = (void*)GetProcAddress(hdll, "StringTableLookUpString");
78     if (!pStringTableLookUpString)
79         pStringTableLookUpString = (void*)GetProcAddress(hdll, "pSetupStringTableLookUpString");
80
81     pStringTableStringFromId = (void*)GetProcAddress(hdll, "StringTableStringFromId");
82     if (!pStringTableStringFromId)
83         pStringTableStringFromId = (void*)GetProcAddress(hdll, "pSetupStringTableStringFromId");
84 }
85
86 static void test_StringTableInitialize(void)
87 {
88     table=pStringTableInitialize();
89     ok(table!=NULL,"Failed to Initialize String Table\n");
90 }
91
92 static void test_StringTableAddString(void)
93 {
94     DWORD retval;
95
96     /* case insensitive */
97     hstring=pStringTableAddString(table,string,0);
98     ok(hstring!=-1,"Failed to add string to String Table\n");
99     
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);        
103     
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);            
107     
108     /* case sensitive */    
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);        
111 }
112
113 static void test_StringTableDuplicate(void)
114 {
115     table2=pStringTableDuplicate(table);
116     ok(table2!=NULL,"Failed to duplicate String Table\n");
117 }
118
119 static void test_StringTableLookUpString(void)
120 {   
121     DWORD retval, retval2;
122     
123     /* case insensitive */
124     retval=pStringTableLookUpString(table,string,0);
125     ok(retval!=-1,"Failed find string in String Table 1\n");
126     ok(retval==hstring,
127         "Lookup for string (%x) does not match previous handle (%x) in String Table 1\n",
128         retval, hstring);    
129
130     retval=pStringTableLookUpString(table2,string,0);
131     ok(retval!=-1,"Failed find string in String Table 2\n");
132     
133     retval=pStringTableLookUpString(table,String,0);
134     ok(retval!=-1,"Failed find String in String Table 1\n");
135
136     retval=pStringTableLookUpString(table2,String,0);
137     ok(retval!=-1,"Failed find String in String Table 2\n");    
138     
139     retval=pStringTableLookUpString(table,foo,0);
140     ok(retval!=-1,"Failed find foo in String Table 1\n");    
141     ok(retval==hfoo,
142         "Lookup for foo (%x) does not match previous handle (%x) in String Table 1\n",
143         retval, hfoo);        
144     
145     retval=pStringTableLookUpString(table2,foo,0);
146     ok(retval!=-1,"Failed find foo in String Table 2\n");    
147     
148     /* case sensitive */
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");
152     ok(retval2==hString,
153         "Lookup for String (%x) does not match previous handle (%x) in String Table 1\n",
154         retval, hString);        
155 }
156
157 static void test_StringTableStringFromId(void)
158 {
159     WCHAR *string2, *string3;
160     int result;
161
162     /* correct */
163     string2=pStringTableStringFromId(table,pStringTableLookUpString(table,string,0));
164     ok(string2!=NULL,"Failed to look up string by ID from String Table\n");
165     
166     result=lstrcmpiW(string, string2);
167     ok(result==0,"StringID %p does not match requested StringID %p\n",string,string2);
168
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");
172
173     result=lstrcmpiW(string, string3);
174     ok(result!=0,"StringID %p matches requested StringID %p\n",string,string3);
175 }
176
177 START_TEST(stringtable)
178 {
179     load_it_up();
180
181     test_StringTableInitialize();
182     test_StringTableAddString();
183     test_StringTableDuplicate();
184     test_StringTableLookUpString();
185     test_StringTableStringFromId();
186
187     /* assume we can always distroy */
188     pStringTableDestroy(table);
189     pStringTableDestroy(table2);
190
191     FreeLibrary(hdll);
192 }