setupapi/tests: Fix some typos.
[wine/multimedia.git] / dlls / setupapi / tests / stringtable.c
blob1b8f2f40cb30a8b031c8ed7d291f454fcdec0edc
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 = GetModuleHandleA("setupapi.dll");
64 pStringTableInitialize = (void*)GetProcAddress(hdll, "StringTableInitialize");
65 if (!pStringTableInitialize)
66 pStringTableInitialize = (void*)GetProcAddress(hdll, "pSetupStringTableInitialize");
68 pStringTableAddString = (void*)GetProcAddress(hdll, "StringTableAddString");
69 if (!pStringTableAddString)
70 pStringTableAddString = (void*)GetProcAddress(hdll, "pSetupStringTableAddString");
72 pStringTableDuplicate = (void*)GetProcAddress(hdll, "StringTableDuplicate");
73 if (!pStringTableDuplicate)
74 pStringTableDuplicate = (void*)GetProcAddress(hdll, "pSetupStringTableDuplicate");
76 pStringTableDestroy = (void*)GetProcAddress(hdll, "StringTableDestroy");
77 if (!pStringTableDestroy)
78 pStringTableDestroy = (void*)GetProcAddress(hdll, "pSetupStringTableDestroy");
80 pStringTableLookUpString = (void*)GetProcAddress(hdll, "StringTableLookUpString");
81 if (!pStringTableLookUpString)
82 pStringTableLookUpString = (void*)GetProcAddress(hdll, "pSetupStringTableLookUpString");
84 pStringTableStringFromId = (void*)GetProcAddress(hdll, "StringTableStringFromId");
85 if (!pStringTableStringFromId)
86 pStringTableStringFromId = (void*)GetProcAddress(hdll, "pSetupStringTableStringFromId");
89 static void test_StringTableInitialize(void)
91 table=pStringTableInitialize();
92 ok(table!=NULL,"Failed to Initialize String Table\n");
95 static void test_StringTableAddString(void)
97 DWORD retval;
99 /* case insensitive */
100 hstring=pStringTableAddString(table,string,0);
101 ok(hstring!=-1,"Failed to add string to String Table\n");
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);
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);
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);
116 static void test_StringTableDuplicate(void)
118 table2=pStringTableDuplicate(table);
119 ok(table2!=NULL,"Failed to duplicate String Table\n");
122 static void test_StringTableLookUpString(void)
124 DWORD retval, retval2;
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);
133 retval=pStringTableLookUpString(table2,string,0);
134 ok(retval!=-1,"Failed find string in String Table 2\n");
136 retval=pStringTableLookUpString(table,String,0);
137 ok(retval!=-1,"Failed find String in String Table 1\n");
139 retval=pStringTableLookUpString(table2,String,0);
140 ok(retval!=-1,"Failed find String in String Table 2\n");
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);
148 retval=pStringTableLookUpString(table2,foo,0);
149 ok(retval!=-1,"Failed find foo in String Table 2\n");
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);
160 static void test_StringTableStringFromId(void)
162 WCHAR *string2, *string3;
163 int result;
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");
169 result=lstrcmpiW(string, string2);
170 ok(result==0,"StringID %p does not match requested StringID %p\n",string,string2);
172 /* This should never work */
173 string3=pStringTableStringFromId(table,0);
174 ok(string3!=NULL,"Failed to look up string by ID from String Table\n");
176 result=lstrcmpiW(string, string3);
177 ok(result!=0,"StringID %p matches requested StringID %p\n",string,string3);
180 START_TEST(stringtable)
182 load_it_up();
184 test_StringTableInitialize();
185 test_StringTableAddString();
186 test_StringTableDuplicate();
187 test_StringTableLookUpString();
188 test_StringTableStringFromId();
190 /* assume we can always destroy */
191 pStringTableDestroy(table);
192 pStringTableDestroy(table2);