quartz: Report the previous refcount of a PullPin object.
[wine/wine-kai.git] / dlls / serialui / tests / confdlg.c
blob95a850e628246869e1c03b467fecfb8aa417e459
1 /*
2 * Unit test suite for serialui API functions
4 * Copyright 2007 Detlef Riekenberg
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
22 #include <stdarg.h>
23 #include <stdio.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "winnls.h"
30 #include "wine/test.h"
33 static HINSTANCE hdll;
34 static DWORD (WINAPI *pGetDefaultCommConfigA)(LPCSTR, LPCOMMCONFIG, LPDWORD);
35 static DWORD (WINAPI *pGetDefaultCommConfigW)(LPCWSTR, LPCOMMCONFIG, LPDWORD);
38 static const CHAR com1A[] = "com1";
39 static const CHAR emptyA[] = "";
40 static const CHAR fmt_comA[] = "com%d";
41 static const CHAR str_colonA[] = ":";
43 static const WCHAR com1W[] = {'c','o','m','1',0};
44 static const WCHAR emptyW[] = {0};
45 static const WCHAR fmt_comW[] = {'c','o','m','%','d',0};
46 static const WCHAR str_colonW[] = {':',0};
48 /* ################# */
50 static LPCSTR load_functions(void)
52 LPCSTR ptr;
54 ptr = "serialui.dll";
55 hdll = LoadLibraryA(ptr);
56 if (!hdll) return ptr;
58 ptr = "drvGetDefaultCommConfigA";
59 pGetDefaultCommConfigA = (VOID *) GetProcAddress(hdll, ptr);
60 if (!pGetDefaultCommConfigA) return ptr;
62 ptr = "drvGetDefaultCommConfigW";
63 pGetDefaultCommConfigW = (VOID *) GetProcAddress(hdll, ptr);
64 if (!pGetDefaultCommConfigW) return ptr;
67 return NULL;
70 /* ################# */
72 static void test_drvGetDefaultCommConfigA(void)
74 COMMCONFIG pCC[3];
75 CHAR bufferA[16];
76 DWORD i;
77 DWORD res;
78 DWORD len;
81 /* off by one: one byte smaller */
82 i = sizeof(COMMCONFIG);
83 len = sizeof(COMMCONFIG) -1;
84 ZeroMemory(pCC, sizeof(pCC));
85 SetLastError(0xdeadbeef);
86 res = pGetDefaultCommConfigA(com1A, pCC, &len);
87 if (res == ERROR_CALL_NOT_IMPLEMENTED) {
88 /* NT does not implement the ANSI API */
89 skip("*A not implemented\n");
90 return;
92 ok( (res == ERROR_INSUFFICIENT_BUFFER) && (len >= i),
93 "returned %u with %u and %u (expected "
94 "ERROR_INSUFFICIENT_BUFFER and '>= %u')\n", res, GetLastError(), len, i);
96 /* test ports "com0" - "com10" */
97 for (i = 0; i < 11 ; i++) {
98 sprintf(bufferA, fmt_comA, i);
99 len = sizeof(pCC);
100 ZeroMemory(pCC, sizeof(pCC));
101 SetLastError(0xdeadbeef);
102 res = pGetDefaultCommConfigA(bufferA, pCC, &len);
103 if (i == 0) {
104 ok( res == ERROR_BADKEY,
105 "returned %u with %u and %u for %s (expected "
106 "ERROR_BADKEY)\n", res, GetLastError(), len, bufferA);
108 else
110 ok((res == ERROR_SUCCESS) || (res == ERROR_BADKEY),
111 "returned %u with %u and %u for %s (expected ERROR_SUCCESS or "
112 "ERROR_BADKEY)\n", res, GetLastError(), len, bufferA);
115 /* a name with a colon is invalid */
116 if (res == ERROR_SUCCESS) {
117 lstrcatA(bufferA, str_colonA);
118 len = sizeof(pCC);
119 ZeroMemory(pCC, sizeof(pCC));
120 res = pGetDefaultCommConfigA(bufferA, pCC, &len);
121 ok( res == ERROR_BADKEY,
122 "returned %u with %u and %u for %s (expected '0' with "
123 "ERROR_BADKEY)\n", res, GetLastError(), len, bufferA);
128 /* an empty String is not allowed */
129 len = sizeof(pCC);
130 ZeroMemory(pCC, sizeof(pCC));
131 SetLastError(0xdeadbeef);
132 res = pGetDefaultCommConfigA(emptyA, pCC, &len);
133 ok( res == ERROR_BADKEY,
134 "returned %u with %u and %u for %s (expected ERROR_BADKEY)\n",
135 res, GetLastError(), len, emptyA);
137 /* some NULL checks */
138 len = sizeof(pCC);
139 ZeroMemory(pCC, sizeof(pCC));
140 SetLastError(0xdeadbeef);
141 res = pGetDefaultCommConfigA(NULL, pCC, &len);
142 ok( res == ERROR_INVALID_PARAMETER,
143 "returned %u with %u and %u for NULL (expected ERROR_INVALID_PARAMETER)\n",
144 res, GetLastError(), len);
147 len = sizeof(pCC);
148 SetLastError(0xdeadbeef);
149 res = pGetDefaultCommConfigA(com1A, NULL, &len);
150 ok( res == ERROR_INVALID_PARAMETER,
151 "returned %u with %u and %u (expected ERROR_INVALID_PARAMETER)\n",
152 res, GetLastError(), len);
155 SetLastError(0xdeadbeef);
156 res = pGetDefaultCommConfigA(com1A, pCC, NULL);
157 ok( res == ERROR_INVALID_PARAMETER,
158 "returned %u with %u (expected ERROR_INVALID_PARAMETER)\n",
159 res, GetLastError());
162 /* ################# */
164 static void test_drvGetDefaultCommConfigW(void)
166 COMMCONFIG pCC[3];
167 WCHAR bufferW[16];
168 CHAR bufferA[16];
169 DWORD i;
170 DWORD res;
171 DWORD len;
174 /* off by one: one byte smaller */
175 i = sizeof(COMMCONFIG);
176 len = sizeof(COMMCONFIG) -1;
177 ZeroMemory(pCC, sizeof(pCC));
178 SetLastError(0xdeadbeef);
179 res = pGetDefaultCommConfigW(com1W, pCC, &len);
180 if (res == ERROR_CALL_NOT_IMPLEMENTED) {
181 skip("*W not implemented\n");
182 return;
184 ok( (res == ERROR_INSUFFICIENT_BUFFER) && (len >= i),
185 "returned %u with %u and %u (expected "
186 "ERROR_INSUFFICIENT_BUFFER and '>= %u')\n", res, GetLastError(), len, i);
188 /* test ports "com0" - "com10" */
189 for (i = 0; i < 11 ; i++) {
190 sprintf(bufferA, fmt_comA, i);
191 MultiByteToWideChar( CP_ACP, 0, bufferA, -1, bufferW, sizeof(bufferW)/sizeof(WCHAR) );
192 len = sizeof(pCC);
193 ZeroMemory(pCC, sizeof(pCC));
194 SetLastError(0xdeadbeef);
195 res = pGetDefaultCommConfigW(bufferW, pCC, &len);
196 if (i == 0) {
197 ok( res == ERROR_BADKEY,
198 "returned %u with %u and %u for %s (expected "
199 "ERROR_BADKEY)\n", res, GetLastError(), len, bufferA);
201 else
203 ok((res == ERROR_SUCCESS) || (res == ERROR_BADKEY),
204 "returned %u with %u and %u for %s (expected ERROR_SUCCESS or "
205 "ERROR_BADKEY)\n", res, GetLastError(), len, bufferA);
208 /* a name with a colon is invalid */
209 if (res == ERROR_SUCCESS) {
210 lstrcatA(bufferA, str_colonA);
211 lstrcatW(bufferW, str_colonW);
212 len = sizeof(pCC);
213 ZeroMemory(pCC, sizeof(pCC));
214 res = pGetDefaultCommConfigW(bufferW, pCC, &len);
215 ok( res == ERROR_BADKEY,
216 "returned %u with %u and %u for %s (expected '0' with "
217 "ERROR_BADKEY)\n", res, GetLastError(), len, bufferA);
221 /* an empty String is not allowed */
222 len = sizeof(pCC);
223 ZeroMemory(pCC, sizeof(pCC));
224 SetLastError(0xdeadbeef);
225 res = pGetDefaultCommConfigW(emptyW, pCC, &len);
226 ok( res == ERROR_BADKEY,
227 "returned %u with %u and %u for %s (expected ERROR_BADKEY)\n",
228 res, GetLastError(), len, emptyA);
230 /* some NULL checks */
231 len = sizeof(pCC);
232 ZeroMemory(pCC, sizeof(pCC));
233 SetLastError(0xdeadbeef);
234 res = pGetDefaultCommConfigW(NULL, pCC, &len);
235 ok( res == ERROR_INVALID_PARAMETER,
236 "returned %u with %u and %u for NULL (expected ERROR_INVALID_PARAMETER)\n",
237 res, GetLastError(), len);
240 len = sizeof(pCC);
241 SetLastError(0xdeadbeef);
242 res = pGetDefaultCommConfigW(com1W, NULL, &len);
243 ok( res == ERROR_INVALID_PARAMETER,
244 "returned %u with %u and %u (expected ERROR_INVALID_PARAMETER)\n",
245 res, GetLastError(), len);
248 SetLastError(0xdeadbeef);
249 res = pGetDefaultCommConfigW(com1W, pCC, NULL);
250 ok( res == ERROR_INVALID_PARAMETER,
251 "returned %u with %u (expected ERROR_INVALID_PARAMETER)\n",
252 res, GetLastError());
256 /* ################# */
258 START_TEST(confdlg)
260 LPCSTR ptr;
262 ptr = load_functions();
263 if (ptr) {
264 skip("got NULL with %u for %s\n", GetLastError(), ptr);
265 return;
268 test_drvGetDefaultCommConfigA();
269 test_drvGetDefaultCommConfigW();