Added a few more Unicode digits from Unicode version 4.1.
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 /* 
21  * TODO:
22  * Add case sensitivity test for StringTableAddString/StringTableLookupString
23  * Add test for StringTableStringFromIdEx
24  */
25
26 #include <stdarg.h>
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "winreg.h"
33 #include "setupapi.h"
34
35 #include "wine/test.h"
36
37
38 static DWORD    (WINAPI *pStringTableAddString)(HSTRING_TABLE, LPWSTR, DWORD);
39 static VOID     (WINAPI *pStringTableDestroy)(HSTRING_TABLE);
40 static HSTRING_TABLE (WINAPI *pStringTableDuplicate)(HSTRING_TABLE hStringTable);
41 static HSTRING_TABLE (WINAPI *pStringTableInitialize)(VOID);
42 static DWORD    (WINAPI *pStringTableLookUpString)(HSTRING_TABLE, LPWSTR, DWORD);
43 static LPWSTR   (WINAPI *pStringTableStringFromId)(HSTRING_TABLE, DWORD);
44 #if 0
45 static BOOL     (WINAPI *pStringTableStringFromIdEx)(HSTRING_TABLE, DWORD, LPWSTR, LPDWORD);
46 static VOID     (WINAPI *pStringTableTrim)(HSTRING_TABLE);
47 #endif
48
49 HMODULE hdll;
50 static WCHAR string[] = {'s','t','r','i','n','g',0};
51 HANDLE table, table2;  /* Handles pointing to our tables */
52
53 static void load_it_up(void)
54 {
55     hdll = LoadLibraryA("setupapi.dll");
56     if (!hdll)
57         return;
58
59     pStringTableInitialize = (void*)GetProcAddress(hdll, "StringTableInitialize");
60     if (!pStringTableInitialize)
61         pStringTableInitialize = (void*)GetProcAddress(hdll, "pSetupStringTableInitialize");
62
63     pStringTableAddString = (void*)GetProcAddress(hdll, "StringTableAddString");
64     if (!pStringTableAddString)
65         pStringTableAddString = (void*)GetProcAddress(hdll, "pSetupStringTableAddString");
66
67     pStringTableDuplicate = (void*)GetProcAddress(hdll, "StringTableDuplicate");
68     if (!pStringTableDuplicate)
69         pStringTableDuplicate = (void*)GetProcAddress(hdll, "pSetupStringTableDuplicate");
70
71     pStringTableDestroy = (void*)GetProcAddress(hdll, "StringTableDestroy");
72     if (!pStringTableDestroy)
73         pStringTableDestroy = (void*)GetProcAddress(hdll, "pSetupStringTableDestroy");
74
75     pStringTableLookUpString = (void*)GetProcAddress(hdll, "StringTableLookUpString");
76     if (!pStringTableLookUpString)
77         pStringTableLookUpString = (void*)GetProcAddress(hdll, "pSetupStringTableLookUpString");
78
79     pStringTableStringFromId = (void*)GetProcAddress(hdll, "StringTableStringFromId");
80     if (!pStringTableStringFromId)
81         pStringTableStringFromId = (void*)GetProcAddress(hdll, "pSetupStringTableStringFromId");
82 }
83
84 static void test_StringTableInitialize(void)
85 {
86     table=pStringTableInitialize();
87     ok(table!=NULL,"Failed to Initialize String Table\n");
88 }
89
90 static void test_StringTableAddString(void)
91 {
92     DWORD retval;
93
94     retval=pStringTableAddString(table,string,0);
95     ok(retval!=-1,"Failed to add string to String Table\n");
96 }
97
98 static void test_StringTableDuplicate(void)
99 {
100     table2=pStringTableDuplicate(table);
101     ok(table2!=NULL,"Failed to duplicate String Table\n");
102 }
103
104 static void test_StringTableLookUpString(void)
105 {   
106     DWORD retval, retval2;
107     
108     retval=pStringTableLookUpString(table,string,0);
109     ok(retval!=-1,"Failed find string in String Table 1\n");
110
111     retval2=pStringTableLookUpString(table2,string,0);
112     ok(retval2!=-1,"Failed find string in String Table 2\n");
113 }
114
115 static void test_StringTableStringFromId(void)
116 {
117     WCHAR *string2, *string3;
118     int result;
119
120     /* correct */
121     string2=pStringTableStringFromId(table,pStringTableLookUpString(table,string,0));
122     ok(string2!=NULL,"Failed to look up string by ID from String Table\n");
123     
124     result=lstrcmpiW(string, string2);
125     ok(result==0,"StringID %p does not match requested StringID %p\n",string,string2);
126
127     /* This should never work */
128     string3=pStringTableStringFromId(table,0);
129     ok(string3!=NULL,"Failed to look up string by ID from String Table\n");
130
131     result=lstrcmpiW(string, string3);
132     ok(result!=0,"StringID %p matches requested StringID %p\n",string,string3);
133 }
134
135 START_TEST(stringtable)
136 {
137     load_it_up();
138
139     test_StringTableInitialize();
140     test_StringTableAddString();
141     test_StringTableDuplicate();
142     test_StringTableLookUpString();
143     test_StringTableStringFromId();
144
145     /* assume we can always distroy */
146     pStringTableDestroy(table);
147     pStringTableDestroy(table2);
148
149     FreeLibrary(hdll);
150 }