cryptui: Check for type mismatches in CryptUIWizImport.
[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 = GetModuleHandleA("setupapi.dll");
63
64     pStringTableInitialize = (void*)GetProcAddress(hdll, "StringTableInitialize");
65     if (!pStringTableInitialize)
66         pStringTableInitialize = (void*)GetProcAddress(hdll, "pSetupStringTableInitialize");
67
68     pStringTableAddString = (void*)GetProcAddress(hdll, "StringTableAddString");
69     if (!pStringTableAddString)
70         pStringTableAddString = (void*)GetProcAddress(hdll, "pSetupStringTableAddString");
71
72     pStringTableDuplicate = (void*)GetProcAddress(hdll, "StringTableDuplicate");
73     if (!pStringTableDuplicate)
74         pStringTableDuplicate = (void*)GetProcAddress(hdll, "pSetupStringTableDuplicate");
75
76     pStringTableDestroy = (void*)GetProcAddress(hdll, "StringTableDestroy");
77     if (!pStringTableDestroy)
78         pStringTableDestroy = (void*)GetProcAddress(hdll, "pSetupStringTableDestroy");
79
80     pStringTableLookUpString = (void*)GetProcAddress(hdll, "StringTableLookUpString");
81     if (!pStringTableLookUpString)
82         pStringTableLookUpString = (void*)GetProcAddress(hdll, "pSetupStringTableLookUpString");
83
84     pStringTableStringFromId = (void*)GetProcAddress(hdll, "StringTableStringFromId");
85     if (!pStringTableStringFromId)
86         pStringTableStringFromId = (void*)GetProcAddress(hdll, "pSetupStringTableStringFromId");
87 }
88
89 static void test_StringTableInitialize(void)
90 {
91     table=pStringTableInitialize();
92     ok(table!=NULL,"Failed to Initialize String Table\n");
93 }
94
95 static void test_StringTableAddString(void)
96 {
97     DWORD retval;
98
99     /* case insensitive */
100     hstring=pStringTableAddString(table,string,0);
101     ok(hstring!=-1,"Failed to add string to String Table\n");
102     
103     retval=pStringTableAddString(table,String,0);
104     ok(retval!=-1,"Failed to add String to String Table\n");    
105     ok(hstring==retval,"string handle %x != String handle %x in String Table\n", hstring, retval);        
106     
107     hfoo=pStringTableAddString(table,foo,0);
108     ok(hfoo!=-1,"Failed to add foo to String Table\n");        
109     ok(hfoo!=hstring,"foo and string share the same ID %x in String Table\n", hfoo);            
110     
111     /* case sensitive */    
112     hString=pStringTableAddString(table,String,ST_CASE_SENSITIVE_COMPARE);
113     ok(hstring!=hString,"String handle and string share same ID %x in Table\n", hstring);        
114 }
115
116 static void test_StringTableDuplicate(void)
117 {
118     table2=pStringTableDuplicate(table);
119     ok(table2!=NULL,"Failed to duplicate String Table\n");
120 }
121
122 static void test_StringTableLookUpString(void)
123 {   
124     DWORD retval, retval2;
125     
126     /* case insensitive */
127     retval=pStringTableLookUpString(table,string,0);
128     ok(retval!=-1,"Failed find string in String Table 1\n");
129     ok(retval==hstring,
130         "Lookup for string (%x) does not match previous handle (%x) in String Table 1\n",
131         retval, hstring);    
132
133     retval=pStringTableLookUpString(table2,string,0);
134     ok(retval!=-1,"Failed find string in String Table 2\n");
135     
136     retval=pStringTableLookUpString(table,String,0);
137     ok(retval!=-1,"Failed find String in String Table 1\n");
138
139     retval=pStringTableLookUpString(table2,String,0);
140     ok(retval!=-1,"Failed find String in String Table 2\n");    
141     
142     retval=pStringTableLookUpString(table,foo,0);
143     ok(retval!=-1,"Failed find foo in String Table 1\n");    
144     ok(retval==hfoo,
145         "Lookup for foo (%x) does not match previous handle (%x) in String Table 1\n",
146         retval, hfoo);        
147     
148     retval=pStringTableLookUpString(table2,foo,0);
149     ok(retval!=-1,"Failed find foo in String Table 2\n");    
150     
151     /* case sensitive */
152     retval=pStringTableLookUpString(table,string,ST_CASE_SENSITIVE_COMPARE);
153     retval2=pStringTableLookUpString(table,String,ST_CASE_SENSITIVE_COMPARE);    
154     ok(retval!=retval2,"Lookup of string equals String in Table 1\n");
155     ok(retval2==hString,
156         "Lookup for String (%x) does not match previous handle (%x) in String Table 1\n",
157         retval, hString);        
158 }
159
160 static void test_StringTableStringFromId(void)
161 {
162     WCHAR *string2;
163     int result;
164
165     /* correct */
166     string2=pStringTableStringFromId(table,pStringTableLookUpString(table,string,0));
167     ok(string2!=NULL,"Failed to look up string by ID from String Table\n");
168     
169     result=lstrcmpiW(string, string2);
170     ok(result==0,"StringID %p does not match requested StringID %p\n",string,string2);
171 }
172
173 START_TEST(stringtable)
174 {
175     load_it_up();
176
177     test_StringTableInitialize();
178     test_StringTableAddString();
179     test_StringTableDuplicate();
180     test_StringTableLookUpString();
181     test_StringTableStringFromId();
182
183     /* assume we can always destroy */
184     pStringTableDestroy(table);
185     pStringTableDestroy(table2);
186 }