Release 0.9.39.
[wine/gsoc-2012-control.git] / dlls / setupapi / tests / stringtable.c
blob59e49c0cee58cae2c29b30c4470761f38266733e
1 /*
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
20 /*
21 * TODO:
22 * Add test for StringTableStringFromIdEx
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "winreg.h"
32 #include "setupapi.h"
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);
48 #if 0
49 static BOOL (WINAPI *pStringTableStringFromIdEx)(HSTRING_TABLE, DWORD, LPWSTR, LPDWORD);
50 static VOID (WINAPI *pStringTableTrim)(HSTRING_TABLE);
51 #endif
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 */
60 static void load_it_up(void)
62 hdll = LoadLibraryA("setupapi.dll");
63 if (!hdll)
64 return;
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)
99 DWORD retval;
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);
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);
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");
131 ok(retval==hstring,
132 "Lookup for string (%x) does not match previous handle (%x) in String Table 1\n",
133 retval, hstring);
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");
146 ok(retval==hfoo,
147 "Lookup for foo (%x) does not match previous handle (%x) in String Table 1\n",
148 retval, hfoo);
150 retval=pStringTableLookUpString(table2,foo,0);
151 ok(retval!=-1,"Failed find foo in String Table 2\n");
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);
162 static void test_StringTableStringFromId(void)
164 WCHAR *string2, *string3;
165 int result;
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");
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)
184 load_it_up();
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);
196 FreeLibrary(hdll);