[KERNEL32_WINETEST]
[reactos.git] / rostests / winetests / kernel32 / comm.c
1 /* Unit test suite for comm functions
2 *
3 * Copyright 2003 Kevin Groeneveld
4 * Copyright 2005 Uwe Bonnes
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 #include <stdio.h>
22
23 #include "wine/test.h"
24 #include "winbase.h"
25 #include "winnls.h"
26
27 #define TIMEOUT 1000 /* one second for Timeouts*/
28 #define SLOWBAUD 150
29 #define FASTBAUD 115200
30 #define TIMEDELTA 150 /* 150 ms uncertainty allowed */
31
32 /* Define the appropriate LOOPBACK(s) TRUE if you have a Loopback cable with
33 * the mentioned shorts connected to your Serial port
34 */
35 #define LOOPBACK_TXD_RXD FALSE /* Sub-D 9: Short 2-3 */
36 #define LOOPBACK_CTS_RTS FALSE /* Sub-D 9: Short 7-8 */
37 #define LOOPBACK_DTR_DSR FALSE /* Sub-D 9: Short 4-6 */
38 #define LOOPBACK_DTR_RING FALSE /* Sub-D 9: Short 4-9 */
39 #define LOOPBACK_DTR_DCD FALSE /* Sub-D 9: Short 4-1 */
40 /* Many Linux serial drivers have the TIOCM_LOOP flag in the TIOCM_SET ioctl
41 * available. For the 8250 this is equivalent to TXD->RXD, OUT2->DCD,
42 * OUT1->RI, RTS->CTS and DTR->DSR
43 */
44
45 typedef struct
46 {
47 char string[100];
48 BOOL result;
49 BOOL old_style;
50 DCB dcb1, dcb2;
51 COMMTIMEOUTS timeouts1, timeouts2;
52 } TEST;
53
54 static TEST test[] =
55 {
56 {
57 "baud=9600 parity=e data=5 stop=1 xon=on odsr=off octs=off dtr=on rts=on idsr=on",
58 TRUE, FALSE,
59 { 0x00000000, 0x00002580, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
60 { 0xffffffff, 0x00002580, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0x05, 0x02, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
61 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
62 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
63 },
64 {
65 "baud=0 parity=M data=6 stop=1.5 xon=off odsr=on octs=ON dtr=off rts=off idsr=OFF",
66 TRUE, FALSE,
67 { 0x00000000, 0x00000000, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x06, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
68 { 0xffffffff, 0x00000000, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0x06, 0x03, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
69 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
70 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
71 },
72 {
73 "BAUD=4000000000 parity=n data=7 stop=2 to=off",
74 TRUE, FALSE,
75 { 0x00000000, 0xee6b2800, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x07, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
76 { 0xffffffff, 0xee6b2800, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0x07, 0x00, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
77 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
78 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }
79 },
80 {
81 "Baud=115200 Parity=O Data=8 To=On",
82 TRUE, FALSE,
83 { 0x00000000, 0x0001c200, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x08, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
84 { 0xffffffff, 0x0001c200, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0x08, 0x01, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
85 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000EA60 },
86 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000EA60 }
87 },
88 {
89 "PaRiTy=s Data=7 DTR=on",
90 TRUE, FALSE,
91 { 0x00000000, 0x00000000, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
92 { 0xffffffff, 0xffffffff, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0x07, 0x04, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
93 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
94 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
95 },
96 {
97 "data=4",
98 FALSE, FALSE,
99 { 0x00000000, 0x00000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
100 { 0xffffffff, 0xffffffff, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
101 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
102 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
103 },
104 {
105 "data=9",
106 FALSE, FALSE,
107 { 0x00000000, 0x00000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
108 { 0xffffffff, 0xffffffff, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
109 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
110 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
111 },
112 {
113 "parity=no",
114 FALSE, FALSE,
115 { 0x00000000, 0x00000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
116 { 0xffffffff, 0xffffffff, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
117 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
118 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
119 },
120 {
121 "stop=0",
122 FALSE, FALSE,
123 { 0x00000000, 0x00000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
124 { 0xffffffff, 0xffffffff, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
125 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
126 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
127 },
128 {
129 "stop=1.501",
130 FALSE, FALSE,
131 { 0x00000000, 0x00000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
132 { 0xffffffff, 0xffffffff, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
133 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
134 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
135 },
136 {
137 "stop=3",
138 FALSE, FALSE,
139 { 0x00000000, 0x00000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
140 { 0xffffffff, 0xffffffff, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
141 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
142 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
143 },
144 {
145 "to=foobar",
146 FALSE, FALSE,
147 { 0x00000000, 0x00000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
148 { 0xffffffff, 0xffffffff, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
149 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
150 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
151 },
152 {
153 " baud=9600",
154 FALSE, FALSE,
155 { 0x00000000, 0x00000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
156 { 0xffffffff, 0xffffffff, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
157 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
158 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
159 },
160 {
161 "baud= 9600",
162 FALSE, FALSE,
163 { 0x00000000, 0x00000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
164 { 0xffffffff, 0xffffffff, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
165 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
166 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
167 },
168 {
169 "baud=9600,data=8",
170 FALSE, FALSE,
171 { 0x00000000, 0x00000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
172 { 0xffffffff, 0xffffffff, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
173 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
174 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
175 },
176 {
177 "11,n,8,1",
178 TRUE, TRUE,
179 { 0x00000000, 0x0000006e, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
180 { 0xffffffff, 0x0000006e, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0x08, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
181 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
182 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
183 },
184 {
185 "30 ,E, 5,1.5",
186 TRUE, TRUE,
187 { 0x00000000, 0x0000012c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x05, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
188 { 0xffffffff, 0x0000012c, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0x05, 0x02, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
189 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
190 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
191 },
192 {
193 "60, m, 6, 2 ",
194 TRUE, TRUE,
195 { 0x00000000, 0x00000258, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x06, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
196 { 0xffffffff, 0x00000258, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0x06, 0x03, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
197 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
198 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
199 },
200 {
201 "12 , o , 7 , 1",
202 TRUE, TRUE,
203 { 0x00000000, 0x000004b0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
204 { 0xffffffff, 0x000004b0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0x07, 0x01, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
205 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
206 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
207 },
208 {
209 "24,s,8,1.5",
210 TRUE, TRUE,
211 { 0x00000000, 0x00000960, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x08, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
212 { 0xffffffff, 0x00000960, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0x08, 0x04, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
213 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
214 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
215 },
216 {
217 "48,n,8,1,p",
218 TRUE, TRUE,
219 { 0x00000000, 0x000012c0, 0, 0, 1, 1, 2, 0, 0, 0, 0, 0, 0, 2, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
220 { 0xffffffff, 0x000012c0, 1, 1, 1, 1, 2, 1, 1, 0, 0, 1, 1, 2, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0x08, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
221 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
222 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
223 },
224 {
225 "96,N,8,1 , x ",
226 TRUE, TRUE,
227 { 0x00000000, 0x00002580, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
228 { 0xffffffff, 0x00002580, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0x08, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
229 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
230 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
231 },
232 {
233 "19, e, 7, 1, x",
234 TRUE, TRUE,
235 { 0x00000000, 0x00004b00, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x07, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
236 { 0xffffffff, 0x00004b00, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0x07, 0x02, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
237 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
238 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
239 },
240 {
241 "0,M,7,1,P",
242 TRUE, TRUE,
243 { 0x00000000, 0x00000000, 0, 0, 1, 1, 2, 0, 0, 0, 0, 0, 0, 2, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
244 { 0xffffffff, 0x00000000, 1, 1, 1, 1, 2, 1, 1, 0, 0, 1, 1, 2, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0x07, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
245 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
246 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
247 },
248 {
249 "4000000000,O,7,1.5,X",
250 TRUE, TRUE,
251 { 0x00000000, 0xee6b2800, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
252 { 0xffffffff, 0xee6b2800, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0x07, 0x01, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
253 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
254 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
255 },
256 {
257 "96,N,8,1 to=on",
258 FALSE, TRUE,
259 { 0x00000000, 0x00000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
260 { 0xffffffff, 0xffffffff, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
261 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
262 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
263 },
264 {
265 "96,NO,8,1",
266 FALSE, TRUE,
267 { 0x00000000, 0x00000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
268 { 0xffffffff, 0xffffffff, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
269 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
270 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
271 },
272 {
273 "96,N,4,1",
274 FALSE, TRUE,
275 { 0x00000000, 0x00000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
276 { 0xffffffff, 0xffffffff, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
277 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
278 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
279 },
280 {
281 "96,N,9,1",
282 FALSE, TRUE,
283 { 0x00000000, 0x00000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
284 { 0xffffffff, 0xffffffff, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
285 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
286 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
287 },
288 {
289 "96,N,8,0",
290 FALSE, TRUE,
291 { 0x00000000, 0x00000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
292 { 0xffffffff, 0xffffffff, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
293 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
294 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
295 },
296 {
297 "96,N,8,3",
298 FALSE, TRUE,
299 { 0x00000000, 0x00000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
300 { 0xffffffff, 0xffffffff, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
301 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
302 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
303 },
304 {
305 "96,N,8,1,K",
306 FALSE, TRUE,
307 { 0x00000000, 0x00000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
308 { 0xffffffff, 0xffffffff, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
309 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
310 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
311 },
312 {
313 "COM0:baud=115200",
314 FALSE, FALSE,
315 { 0x00000000, 0x00000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
316 { 0xffffffff, 0xffffffff, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
317 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
318 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
319 },
320 {
321 "COMx:baud=38400 data=8",
322 TRUE, FALSE,
323 { 0x00000000, 0x00009600, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
324 { 0xffffffff, 0x00009600, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0x08, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
325 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
326 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
327 },
328 {
329 "COMx :to=on stop=1.5",
330 TRUE, FALSE,
331 { 0x00000000, 0x00000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
332 { 0xffffffff, 0xffffffff, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
333 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000EA60 },
334 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000EA60 }
335 },
336 {
337 "COMx: baud=12345 data=7",
338 TRUE, FALSE,
339 { 0x00000000, 0x00003039, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
340 { 0xffffffff, 0x00003039, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0x07, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
341 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
342 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
343 },
344 {
345 "COMx : xon=on odsr=off",
346 TRUE, FALSE,
347 { 0x00000000, 0x00000000, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
348 { 0xffffffff, 0xffffffff, 1, 1, 1, 0, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
349 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
350 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
351 },
352 {
353 "COM0:9600,N,8,1",
354 FALSE, TRUE,
355 { 0x00000000, 0x00000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
356 { 0xffffffff, 0xffffffff, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 3, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
357 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
358 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
359 },
360 {
361 "COMx:9600,N,8,1",
362 TRUE, TRUE,
363 { 0x00000000, 0x00002580, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
364 { 0xffffffff, 0x00002580, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0x08, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
365 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
366 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
367 },
368 {
369 "COMx: 11,E,7,2",
370 TRUE, TRUE,
371 { 0x00000000, 0x0000006e, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x07, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
372 { 0xffffffff, 0x0000006e, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0x07, 0x02, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
373 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
374 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
375 },
376 {
377 "COMx :19,M,5,1",
378 TRUE, TRUE,
379 { 0x00000000, 0x00004b00, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x05, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
380 { 0xffffffff, 0x00004b00, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0x05, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
381 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
382 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
383 },
384 {
385 "COMx : 57600,S,6,2,x",
386 TRUE, TRUE,
387 { 0x00000000, 0x0000e100, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0x00000, 0x0000, 0x0000, 0x0000, 0x06, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0000 },
388 { 0xffffffff, 0x0000e100, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0x1ffff, 0xffff, 0xffff, 0xffff, 0x06, 0x04, 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xffff },
389 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
390 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
391 },
392 };
393
394 #define TEST_COUNT (sizeof(test) / sizeof(TEST))
395
396 /* This function can be useful if you are modifying the test cases and want to
397 output the contents of a DCB structure. */
398 /*static print_dcb(DCB *pdcb)
399 {
400 printf("0x%08x, 0x%08x, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, %u, 0x%05x, 0x%04x, 0x%04x, 0x%04x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%04x\n",
401 pdcb->DCBlength,
402 pdcb->BaudRate,
403 pdcb->fBinary,
404 pdcb->fParity,
405 pdcb->fOutxCtsFlow,
406 pdcb->fOutxDsrFlow,
407 pdcb->fDtrControl,
408 pdcb->fDsrSensitivity,
409 pdcb->fTXContinueOnXoff,
410 pdcb->fOutX,
411 pdcb->fInX,
412 pdcb->fErrorChar,
413 pdcb->fNull,
414 pdcb->fRtsControl,
415 pdcb->fAbortOnError,
416 pdcb->fDummy2,
417 pdcb->wReserved,
418 pdcb->XonLim,
419 pdcb->XoffLim,
420 pdcb->ByteSize,
421 pdcb->Parity,
422 pdcb->StopBits,
423 pdcb->XonChar & 0xff,
424 pdcb->XoffChar & 0xff,
425 pdcb->ErrorChar & 0xff,
426 pdcb->EofChar & 0xff,
427 pdcb->EvtChar & 0xff,
428 pdcb->wReserved1 & 0xffff );
429 } */
430
431 static void check_result(const char *function, TEST *ptest, int initial_value, BOOL result)
432 {
433 DWORD LastError = GetLastError();
434 DWORD CorrectError = (ptest->result ? 0xdeadbeef : ERROR_INVALID_PARAMETER);
435
436 ok(LastError == CorrectError, "%s(\"%s\"), 0x%02x: GetLastError() returned %d, should be %d\n", function, ptest->string, initial_value, LastError, CorrectError);
437 ok(result == ptest->result, "%s(\"%s\"), 0x%02x: return value should be %s\n", function, ptest->string, initial_value, ptest->result ? "TRUE" : "FALSE");
438 }
439
440 #define check_dcb_member(a,b) ok(pdcb1->a == pdcb2->a, "%s(\"%s\"), 0x%02x: "#a" is "b", should be "b"\n", function, ptest->string, initial_value, pdcb1->a, pdcb2->a)
441 #define check_dcb_member2(a,c,b) if(pdcb2->a == c) { check_dcb_member(a,b); } else { ok(pdcb1->a == pdcb2->a || pdcb1->a == c, "%s(\"%s\"), 0x%02x: "#a" is "b", should be "b" or "b"\n", function, ptest->string, initial_value, pdcb1->a, pdcb2->a, c); }
442
443 static void check_dcb(const char *function, TEST *ptest, int initial_value, DCB *pdcb1, DCB *pdcb2)
444 {
445 /* DCBlength is a special case since Win 9x sets it but NT does not.
446 We will accept either as correct. */
447 check_dcb_member2(DCBlength, (DWORD)sizeof(DCB), "%u");
448
449 /* For old style control strings Win 9x does not set the next five members, NT does. */
450 if(ptest->old_style && ptest->result)
451 {
452 check_dcb_member2(fOutxCtsFlow, ((unsigned int)initial_value & 1), "%u");
453 check_dcb_member2(fDtrControl, ((unsigned int)initial_value & 3), "%u");
454 check_dcb_member2(fOutX, ((unsigned int)initial_value & 1), "%u");
455 check_dcb_member2(fInX, ((unsigned)initial_value & 1), "%u");
456 check_dcb_member2(fRtsControl, ((unsigned)initial_value & 3), "%u");
457 }
458 else
459 {
460 check_dcb_member(fOutxCtsFlow, "%u");
461 check_dcb_member(fDtrControl, "%u");
462 check_dcb_member(fOutX, "%u");
463 check_dcb_member(fInX, "%u");
464 check_dcb_member(fRtsControl, "%u");
465 }
466
467 if(ptest->result)
468 {
469 /* For the idsr=xxx parameter, NT sets fDsrSensitivity, 9x sets
470 fOutxDsrFlow. */
471 if(!ptest->old_style)
472 {
473 check_dcb_member2(fOutxDsrFlow, pdcb2->fDsrSensitivity, "%u");
474 check_dcb_member2(fDsrSensitivity, pdcb2->fOutxDsrFlow, "%u");
475 }
476 else
477 {
478 /* For old style control strings Win 9x does not set the
479 fOutxDsrFlow member, NT does. */
480 check_dcb_member2(fOutxDsrFlow, ((unsigned int)initial_value & 1), "%u");
481 check_dcb_member(fDsrSensitivity, "%u");
482 }
483 }
484 else
485 {
486 check_dcb_member(fOutxDsrFlow, "%u");
487 check_dcb_member(fDsrSensitivity, "%u");
488 }
489
490 /* Check the result of the DCB members. */
491 check_dcb_member(BaudRate, "%u");
492 check_dcb_member(fBinary, "%u");
493 check_dcb_member(fParity, "%u");
494 check_dcb_member(fTXContinueOnXoff, "%u");
495 check_dcb_member(fErrorChar, "%u");
496 check_dcb_member(fNull, "%u");
497 check_dcb_member(fAbortOnError, "%u");
498 check_dcb_member(fDummy2, "%u");
499 check_dcb_member(wReserved, "%u");
500 check_dcb_member(XonLim, "%u");
501 check_dcb_member(XoffLim, "%u");
502 check_dcb_member(ByteSize, "%u");
503 check_dcb_member(Parity, "%u");
504 check_dcb_member(StopBits, "%u");
505 check_dcb_member(XonChar, "%d");
506 check_dcb_member(XoffChar, "%d");
507 check_dcb_member(ErrorChar, "%d");
508 check_dcb_member(EofChar, "%d");
509 check_dcb_member(EvtChar, "%d");
510 check_dcb_member(wReserved1, "%u");
511 }
512
513 #define check_timeouts_member(a) ok(ptimeouts1->a == ptimeouts2->a, "%s(\"%s\"), 0x%02x: "#a" is %u, should be %u\n", function, ptest->string, initial_value, ptimeouts1->a, ptimeouts2->a);
514
515 static void check_timeouts(const char *function, TEST *ptest, int initial_value, COMMTIMEOUTS *ptimeouts1, COMMTIMEOUTS *ptimeouts2)
516 {
517 check_timeouts_member(ReadIntervalTimeout);
518 check_timeouts_member(ReadTotalTimeoutMultiplier);
519 check_timeouts_member(ReadTotalTimeoutConstant);
520 check_timeouts_member(WriteTotalTimeoutMultiplier);
521 check_timeouts_member(WriteTotalTimeoutConstant);
522 }
523
524 static void test_BuildCommDCBA(TEST *ptest, int initial_value, DCB *pexpected_dcb)
525 {
526 BOOL result;
527 DCB dcb;
528
529 /* set initial conditions */
530 memset(&dcb, initial_value, sizeof(DCB));
531 SetLastError(0xdeadbeef);
532
533 result = BuildCommDCBA(ptest->string, &dcb);
534
535 /* check results */
536 check_result("BuildCommDCBA", ptest, initial_value, result);
537 check_dcb("BuildCommDCBA", ptest, initial_value, &dcb, pexpected_dcb);
538 }
539
540 static void test_BuildCommDCBAndTimeoutsA(TEST *ptest, int initial_value, DCB *pexpected_dcb, COMMTIMEOUTS *pexpected_timeouts)
541 {
542 BOOL result;
543 DCB dcb;
544 COMMTIMEOUTS timeouts;
545
546 /* set initial conditions */
547 memset(&dcb, initial_value, sizeof(DCB));
548 memset(&timeouts, initial_value, sizeof(COMMTIMEOUTS));
549 SetLastError(0xdeadbeef);
550
551 result = BuildCommDCBAndTimeoutsA(ptest->string, &dcb, &timeouts);
552
553 /* check results */
554 check_result("BuildCommDCBAndTimeoutsA", ptest, initial_value, result);
555 check_dcb("BuildCommDCBAndTimeoutsA", ptest, initial_value, &dcb, pexpected_dcb);
556 check_timeouts("BuildCommDCBAndTimeoutsA", ptest, initial_value, &timeouts, pexpected_timeouts);
557 }
558
559 static void test_BuildCommDCBW(TEST *ptest, int initial_value, DCB *pexpected_dcb)
560 {
561 BOOL result;
562 DCB dcb;
563 WCHAR wide_string[sizeof(ptest->string)];
564 static int reportedDCBW = 0;
565
566 MultiByteToWideChar(CP_ACP, 0, ptest->string, -1, wide_string, sizeof(wide_string) / sizeof(WCHAR));
567
568 /* set initial conditions */
569 memset(&dcb, initial_value, sizeof(DCB));
570 SetLastError(0xdeadbeef);
571
572 result = BuildCommDCBW(wide_string, &dcb);
573
574 if(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
575 {
576 if(!reportedDCBW++)
577 win_skip("BuildCommDCBW is not implemented\n");
578 return;
579 }
580
581 /* check results */
582 check_result("BuildCommDCBW", ptest, initial_value, result);
583 check_dcb("BuildCommDCBW", ptest, initial_value, &dcb, pexpected_dcb);
584 }
585
586 static void test_BuildCommDCBAndTimeoutsW(TEST *ptest, int initial_value, DCB *pexpected_dcb, COMMTIMEOUTS *pexpected_timeouts)
587 {
588 BOOL result;
589 DCB dcb;
590 COMMTIMEOUTS timeouts;
591 WCHAR wide_string[sizeof(ptest->string)];
592 static int reportedDCBAndTW = 0;
593
594 MultiByteToWideChar(CP_ACP, 0, ptest->string, -1, wide_string, sizeof(wide_string) / sizeof(WCHAR));
595
596 /* set initial conditions */
597 memset(&dcb, initial_value, sizeof(DCB));
598 memset(&timeouts, initial_value, sizeof(COMMTIMEOUTS));
599 SetLastError(0xdeadbeef);
600
601 result = BuildCommDCBAndTimeoutsW(wide_string, &dcb, &timeouts);
602
603 if(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
604 {
605 if(!reportedDCBAndTW++)
606 win_skip("BuildCommDCBAndTimeoutsW is not implemented\n");
607 return;
608 }
609
610 /* check results */
611 check_result("BuildCommDCBAndTimeoutsW", ptest, initial_value, result);
612 check_dcb("BuildCommDCBAndTimeoutsW", ptest, initial_value, &dcb, pexpected_dcb);
613 check_timeouts("BuildCommDCBAndTimeoutsW", ptest, initial_value, &timeouts, pexpected_timeouts);
614 }
615
616 static void test_BuildCommDCB(void)
617 {
618 char port_name[] = "COMx";
619 char port = 0;
620 unsigned int i;
621 char *ptr;
622
623 /* Some of these tests require a valid COM port. This loop will try to find
624 a valid port. */
625 for(port_name[3] = '1'; port_name[3] <= '9'; port_name[3]++)
626 {
627 COMMCONFIG commconfig;
628 DWORD size = sizeof(COMMCONFIG);
629
630 if(GetDefaultCommConfig(port_name, &commconfig, &size))
631 {
632 port = port_name[3];
633 break;
634 }
635 }
636
637 if(!port)
638 trace("Could not find a valid COM port. Some tests will be skipped.\n");
639
640 for(i = 0; i < TEST_COUNT; i++)
641 {
642 /* Check if this test case needs a valid COM port. */
643 ptr = strstr(test[i].string, "COMx");
644
645 /* If required, substitute valid port number into device control string. */
646 if(ptr)
647 {
648 if(port)
649 ptr[3] = port;
650 else
651 continue;
652 }
653
654 test_BuildCommDCBA(&test[i], 0x00, &test[i].dcb1);
655 test_BuildCommDCBA(&test[i], 0xff, &test[i].dcb2);
656 test_BuildCommDCBAndTimeoutsA(&test[i], 0x00, &test[i].dcb1, &test[i].timeouts1);
657 test_BuildCommDCBAndTimeoutsA(&test[i], 0xff, &test[i].dcb2, &test[i].timeouts2);
658
659 test_BuildCommDCBW(&test[i], 0x00, &test[i].dcb1);
660 test_BuildCommDCBW(&test[i], 0xff, &test[i].dcb2);
661 test_BuildCommDCBAndTimeoutsW(&test[i], 0x00, &test[i].dcb1, &test[i].timeouts1);
662 test_BuildCommDCBAndTimeoutsW(&test[i], 0xff, &test[i].dcb2, &test[i].timeouts2);
663 }
664 }
665
666 static HANDLE test_OpenComm(BOOL doOverlap)
667 {
668 HANDLE hcom = INVALID_HANDLE_VALUE;
669 char port_name[] = "COMx";
670 static BOOL shown = FALSE;
671 DWORD errors;
672 COMSTAT comstat;
673
674 /* Try to find a port */
675 for(port_name[3] = '1'; port_name[3] <= '9'; port_name[3]++)
676 {
677 hcom = CreateFile( port_name, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
678 (doOverlap)?FILE_FLAG_OVERLAPPED:0, NULL );
679 if (hcom != INVALID_HANDLE_VALUE)
680 break;
681 }
682 if(!shown)
683 {
684 if (hcom == INVALID_HANDLE_VALUE)
685 trace("Could not find a valid COM port. Skipping test_ReadTimeOut\n");
686 else
687 trace("Found Com port %s. Connected devices may disturb results\n", port_name);
688 /*shown = TRUE; */
689 }
690 if (hcom != INVALID_HANDLE_VALUE)
691 {
692 BOOL ret;
693
694 ret = ClearCommError(hcom, &errors, &comstat);
695 if (!ret && (GetLastError() == ERROR_NOT_READY || GetLastError() == ERROR_INVALID_HANDLE))
696 {
697 if (GetLastError() == ERROR_NOT_READY)
698 trace("%s doesn't respond, skipping the test\n", port_name);
699 else
700 trace("%s is not a real serial port, skipping the test\n", port_name);
701 CloseHandle(hcom);
702 return INVALID_HANDLE_VALUE;
703 }
704
705 ok(ret, "Unexpected error %u on open\n", GetLastError());
706 ok(comstat.cbInQue == 0, "Unexpected %d chars in InQueue\n",comstat.cbInQue);
707 ok(comstat.cbOutQue == 0, "Still pending %d charcters in OutQueue\n", comstat.cbOutQue);
708 ok(errors == 0, "Unexpected errors 0x%08x\n", errors);
709 }
710 return hcom;
711 }
712
713 static void test_GetModemStatus(HANDLE hcom)
714 {
715 DWORD ModemStat = 0;
716
717 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
718 trace("GetCommModemStatus returned 0x%08x->%s%s%s%s\n", ModemStat,
719 (ModemStat &MS_RLSD_ON)?"MS_RLSD_ON ":"",
720 (ModemStat &MS_RING_ON)?"MS_RING_ON ":"",
721 (ModemStat &MS_DSR_ON)?"MS_DSR_ON ":"",
722 (ModemStat &MS_CTS_ON)?"MS_CTS_ON ":"");
723 }
724
725 /* When we don't write anything, Read should time out even on a loopbacked port */
726 static void test_ReadTimeOut(HANDLE hcom)
727 {
728 DCB dcb;
729 COMMTIMEOUTS timeouts;
730 char rbuf[32];
731 DWORD before, after, read, timediff, LastError;
732 BOOL res;
733
734 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
735 dcb.BaudRate = FASTBAUD;
736 dcb.ByteSize = 8;
737 dcb.Parity = NOPARITY;
738 dcb.fRtsControl=RTS_CONTROL_ENABLE;
739 dcb.fDtrControl=DTR_CONTROL_ENABLE;
740 dcb.StopBits = ONESTOPBIT;
741 ok(SetCommState(hcom, &dcb), "SetCommState failed\n");
742
743 ZeroMemory( &timeouts, sizeof(timeouts));
744 timeouts.ReadTotalTimeoutConstant = TIMEOUT;
745 ok(SetCommTimeouts(hcom, &timeouts),"SetCommTimeouts failed\n");
746
747 before = GetTickCount();
748 SetLastError(0xdeadbeef);
749 res = ReadFile(hcom, rbuf, sizeof(rbuf), &read, NULL);
750 LastError = GetLastError();
751 after = GetTickCount();
752 ok( res == TRUE, "A timed-out read should return TRUE\n");
753 ok( LastError == 0xdeadbeef, "err=%d\n", LastError);
754 timediff = after - before;
755 ok( timediff > TIMEOUT>>2 && timediff < TIMEOUT *2,
756 "Unexpected TimeOut %d, expected %d\n", timediff, TIMEOUT);
757 }
758
759 static void test_waittxempty(HANDLE hcom)
760 {
761 DCB dcb;
762 COMMTIMEOUTS timeouts;
763 char tbuf[]="test_waittxempty";
764 DWORD before, after, written, timediff, evtmask = 0;
765 BOOL res_write, res;
766 DWORD baud = SLOWBAUD;
767
768 trace("test_waittxempty\n");
769 /* set a low baud rate to have ample time*/
770 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
771 dcb.BaudRate = baud;
772 dcb.ByteSize = 8;
773 dcb.Parity = NOPARITY;
774 dcb.fRtsControl=RTS_CONTROL_ENABLE;
775 dcb.fDtrControl=DTR_CONTROL_ENABLE;
776 dcb.StopBits = ONESTOPBIT;
777 ok(SetCommState(hcom, &dcb), "SetCommState failed\n");
778
779 ZeroMemory( &timeouts, sizeof(timeouts));
780 timeouts.ReadTotalTimeoutConstant = TIMEOUT;
781 ok(SetCommTimeouts(hcom, &timeouts),"SetCommTimeouts failed\n");
782
783 ok(SetupComm(hcom,1024,1024),"SetUpComm failed\n");
784 ok(SetCommMask(hcom, EV_TXEMPTY), "SetCommMask failed\n");
785
786 before = GetTickCount();
787 res_write=WriteFile(hcom, tbuf, sizeof(tbuf), &written, NULL);
788 after = GetTickCount();
789 ok(res_write == TRUE, "WriteFile failed\n");
790 ok(written == sizeof(tbuf),
791 "WriteFile: Unexpected write_size %d\n", written);
792
793 trace("WriteFile succeeded, took %d ms to write %d Bytes at %d Baud\n",
794 after - before, written, baud);
795
796 before = GetTickCount();
797 res = WaitCommEvent(hcom, &evtmask, NULL);
798 after = GetTickCount();
799
800 ok(res == TRUE, "WaitCommEvent failed\n");
801 ok((evtmask & EV_TXEMPTY),
802 "WaitCommEvent: Unexpected EvtMask 0x%08x, expected 0x%08x\n",
803 evtmask, EV_TXEMPTY);
804
805 timediff = after - before;
806
807 trace("WaitCommEvent for EV_TXEMPTY took %d ms\n", timediff);
808 /* 050604: This shows a difference between XP (tested with mingw compiled crosstest):
809 XP returns Writefile only after everything went out of the Serial port,
810 while wine returns immediately.
811 Thus on XP, WaintCommEvent after setting the CommMask for EV_TXEMPTY
812 nearly return immediate,
813 while on wine the most time is spent here
814 */
815 }
816
817 /* A new open handle should not return error or have bytes in the Queues */
818 static void test_ClearCommErrors(HANDLE hcom)
819 {
820 DWORD errors;
821 COMSTAT lpStat;
822
823 ok(ClearCommError(hcom, &errors, &lpStat), "ClearCommError failed\n");
824 ok(lpStat.cbInQue == 0, "Unexpected %d chars in InQueue\n", lpStat.cbInQue);
825 ok(lpStat.cbOutQue == 0, "Unexpected %d chars in OutQueue\n", lpStat.cbOutQue);
826 ok(errors == 0, "ClearCommErrors: Unexpected error 0x%08x\n", errors);
827 trace("test_ClearCommErrors done\n");
828 }
829
830 static void test_non_pending_errors(HANDLE hcom)
831 {
832 DCB dcb;
833 DWORD err;
834
835 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
836 dcb.ByteSize = 255; /* likely bogus */
837 ok(!SetCommState(hcom, &dcb), "SetCommState should have failed\n");
838 ok(ClearCommError(hcom, &err, NULL), "ClearCommError should succeed\n");
839 ok(!(err & CE_MODE), "ClearCommError shouldn't set CE_MODE byte in this case (%x)\n", err);
840 }
841
842 /**/
843 static void test_LoopbackRead(HANDLE hcom)
844 {
845 DCB dcb;
846 COMMTIMEOUTS timeouts;
847 char rbuf[32];
848 DWORD before, after, diff, read, read1, written, evtmask=0, i;
849 BOOL res;
850 char tbuf[]="test_LoopbackRead";
851
852 trace("Starting test_LoopbackRead\n");
853 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
854 dcb.BaudRate = FASTBAUD;
855 dcb.ByteSize = 8;
856 dcb.Parity = NOPARITY;
857 dcb.fRtsControl=RTS_CONTROL_ENABLE;
858 dcb.fDtrControl=DTR_CONTROL_ENABLE;
859 dcb.StopBits = ONESTOPBIT;
860 ok(SetCommState(hcom, &dcb), "SetCommState failed\n");
861
862 ZeroMemory( &timeouts, sizeof(timeouts));
863 timeouts.ReadTotalTimeoutConstant = TIMEOUT;
864 ok(SetCommTimeouts(hcom, &timeouts),"SetCommTimeouts failed\n");
865
866 ok(SetCommMask(hcom, EV_TXEMPTY), "SetCommMask failed\n");
867
868 before = GetTickCount();
869 ok(WriteFile(hcom,tbuf,sizeof(tbuf),&written, NULL), "WriteFile failed\n");
870 after = GetTickCount();
871 ok(written == sizeof(tbuf),"WriteFile %d bytes written\n", written);
872 diff = after -before;
873
874 /* make sure all bytes are written, so Readfile will succeed in one call*/
875 ok(WaitCommEvent(hcom, &evtmask, NULL), "WaitCommEvent failed\n");
876 before = GetTickCount();
877 ok(evtmask == EV_TXEMPTY,
878 "WaitCommEvent: Unexpected EvtMask 0x%08x, expected 0x%08x\n",
879 evtmask, EV_TXEMPTY);
880 trace("Write %d ms WaitCommEvent EV_TXEMPTY %d ms\n", diff, before- after);
881
882 read=0;
883 ok(ReadFile(hcom, rbuf, sizeof(rbuf), &read, NULL), "Readfile failed\n");
884 ok(read == sizeof(tbuf),"ReadFile read %d bytes, expected \"%s\"\n", read,rbuf);
885
886 /* Now do the same with a slower Baud rate.
887 As we request more characters then written, we will hit the timeout
888 */
889
890 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
891 dcb.BaudRate = 9600;
892 dcb.ByteSize = 8;
893 dcb.Parity = NOPARITY;
894 dcb.fRtsControl=RTS_CONTROL_ENABLE;
895 dcb.fDtrControl=DTR_CONTROL_ENABLE;
896 dcb.StopBits = ONESTOPBIT;
897 ok(SetCommState(hcom, &dcb), "SetCommState failed\n");
898
899 ok(SetCommMask(hcom, EV_RXCHAR), "SetCommMask failed\n");
900 ok(WriteFile(hcom,tbuf,sizeof(tbuf),&written, NULL), "WriteFile failed\n");
901 ok(written == sizeof(tbuf),"WriteFile %d bytes written\n", written);
902
903 trace("WaitCommEventEV_RXCHAR\n");
904 ok(WaitCommEvent(hcom, &evtmask, NULL), "WaitCommEvent failed\n");
905 ok(evtmask == EV_RXCHAR, "WaitCommEvent: Unexpected EvtMask 0x%08x, expected 0x%08x\n",
906 evtmask, EV_RXCHAR);
907
908 before = GetTickCount();
909 res = ReadFile(hcom, rbuf, sizeof(rbuf), &read, NULL);
910 after = GetTickCount();
911 ok(res, "Readfile failed\n");
912 ok(read == sizeof(tbuf),"ReadFile read %d bytes\n", read);
913 diff = after - before;
914 trace("Readfile for %d chars took %d ms\n", read, diff);
915 ok( (diff > TIMEOUT - TIMEDELTA) && (diff < TIMEOUT + TIMEDELTA),
916 "Timedout Wait took %d ms, expected around %d\n", diff, TIMEOUT);
917
918 /* now do a plain read with slow speed
919 * This will result in several low level reads and a timeout to happen
920 */
921 dcb.BaudRate = SLOWBAUD;
922 ok(SetCommState(hcom, &dcb), "SetCommState failed\n");
923 ok(WriteFile(hcom,tbuf,sizeof(tbuf),&written, NULL), "WriteFile failed\n");
924 before = GetTickCount();
925 read = 0;
926 read1 =0;
927 i=0;
928 do
929 {
930 res = ReadFile(hcom, rbuf+read, sizeof(rbuf)-read, &read1, NULL);
931 ok(res, "Readfile failed\n");
932 read += read1;
933 i++;
934 }
935 while ((read < sizeof(tbuf)) && (i <10));
936 after = GetTickCount();
937 ok( read == sizeof(tbuf),"ReadFile read %d bytes\n", read);
938 trace("Plain Read for %d char at %d baud took %d ms\n", read, SLOWBAUD, after-before);
939 }
940
941 static void test_LoopbackCtsRts(HANDLE hcom)
942 {
943 DWORD ModemStat = 0, defaultStat = 0;
944 DCB dcb;
945
946 memset (&dcb, 0, sizeof (dcb));
947 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
948 if (dcb.fRtsControl == RTS_CONTROL_HANDSHAKE)
949 {
950 trace("RTS_CONTROL_HANDSHAKE is set, so don't manipulate RTS\n");
951 return;
952 }
953 ok(GetCommModemStatus(hcom, &defaultStat), "GetCommModemStatus failed\n");
954 /* XP returns some values in the low nibble, so mask them out*/
955 defaultStat &= MS_CTS_ON|MS_DSR_ON|MS_RING_ON|MS_RLSD_ON;
956 if(defaultStat & MS_CTS_ON)
957 {
958 ok(EscapeCommFunction(hcom, CLRRTS), "EscapeCommFunction failed to clear RTS\n");
959 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
960 ok ((ModemStat & MS_CTS_ON) == 0, "CTS didn't react: 0x%04x, expected 0x%04x\n",
961 ModemStat, (defaultStat & ~MS_CTS_ON));
962 ok(EscapeCommFunction(hcom, SETRTS), "EscapeCommFunction failed to clear RTS\n");
963 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
964 ok (ModemStat == defaultStat, "Failed to restore CTS: 0x%04x, expected 0x%04x\n",
965 ModemStat, defaultStat);
966 }
967 else
968 {
969 ok(EscapeCommFunction(hcom, SETRTS), "EscapeCommFunction failed to set RTS\n");
970 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
971 ok ((ModemStat & MS_CTS_ON) == MS_CTS_ON,
972 "CTS didn't react: 0x%04x, expected 0x%04x\n",
973 ModemStat, (defaultStat | MS_CTS_ON));
974 ok(EscapeCommFunction(hcom, CLRRTS), "EscapeCommFunction failed to clear RTS\n");
975 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
976 ok (ModemStat == defaultStat, "Failed to restore CTS: 0x%04x, expected 0x%04x\n",
977 ModemStat, defaultStat);
978 }
979 }
980
981 static void test_LoopbackDtrDcd(HANDLE hcom)
982 {
983 DWORD ModemStat = 0, defaultStat = 0;
984 DCB dcb;
985
986 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
987 if (dcb.fDtrControl == DTR_CONTROL_HANDSHAKE)
988 {
989 trace("DTR_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
990 return;
991 }
992 ok(GetCommModemStatus(hcom, &defaultStat), "GetCommModemStatus failed\n");
993 /* XP returns some values in the low nibble, so mask them out*/
994 defaultStat &= MS_CTS_ON|MS_DSR_ON|MS_RING_ON|MS_RLSD_ON;
995 if(defaultStat & MS_RLSD_ON)
996 {
997 ok(EscapeCommFunction(hcom, CLRDTR), "EscapeCommFunction failed to clear DTR\n");
998 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
999 ok ((ModemStat & MS_RLSD_ON) == 0, "RLSD didn't react: 0x%04x, expected 0x%04x\n",
1000 ModemStat, (defaultStat & ~MS_RLSD_ON));
1001 ok(EscapeCommFunction(hcom, SETDTR), "EscapeCommFunction failed to set DTR\n");
1002 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
1003 ok (ModemStat == defaultStat, "Failed to restore RLSD: 0x%04x, expected 0x%04x\n",
1004 ModemStat, defaultStat);
1005 }
1006 else
1007 {
1008 ok(EscapeCommFunction(hcom, SETDTR), "EscapeCommFunction failed to set DTR\n");
1009 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
1010 ok ((ModemStat & MS_RLSD_ON) == MS_RLSD_ON,
1011 "RLSD didn't react: 0x%04x, expected 0x%04x\n",
1012 ModemStat, (defaultStat | MS_RLSD_ON));
1013 ok(EscapeCommFunction(hcom, CLRDTR), "EscapeCommFunction failed to clear DTR\n");
1014 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
1015 ok (ModemStat == defaultStat, "Failed to restore RLSD: 0x%04x, expected 0x%04x\n",
1016 ModemStat, defaultStat);
1017 }
1018 }
1019
1020 static void test_LoopbackDtrDsr(HANDLE hcom)
1021 {
1022 DWORD ModemStat = 0, defaultStat = 0;
1023 DCB dcb;
1024
1025 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
1026 if (dcb.fDtrControl == DTR_CONTROL_DISABLE)
1027 {
1028 trace("DTR_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
1029 return;
1030 }
1031 ok(GetCommModemStatus(hcom, &defaultStat), "GetCommModemStatus failed\n");
1032 /* XP returns some values in the low nibble, so mask them out*/
1033 defaultStat &= MS_CTS_ON|MS_DSR_ON|MS_RING_ON|MS_RLSD_ON;
1034 if(defaultStat & MS_DSR_ON)
1035 {
1036 ok(EscapeCommFunction(hcom, CLRDTR), "EscapeCommFunction failed to clear DTR\n");
1037 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
1038 ok ((ModemStat & MS_DSR_ON) == 0, "CTS didn't react: 0x%04x, expected 0x%04x\n",
1039 ModemStat, (defaultStat & ~MS_DSR_ON));
1040 ok(EscapeCommFunction(hcom, SETDTR), "EscapeCommFunction failed to clear DTR\n");
1041 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
1042 ok (ModemStat == defaultStat, "Failed to restore DSR: 0x%04x, expected 0x%04x\n",
1043 ModemStat, defaultStat);
1044 }
1045 else
1046 {
1047 ok(EscapeCommFunction(hcom, SETDTR), "EscapeCommFunction failed to set DTR\n");
1048 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
1049 ok ((ModemStat & MS_DSR_ON) == MS_DSR_ON,
1050 "CTS didn't react: 0x%04x,expected 0x%04x\n",
1051 ModemStat, (defaultStat | MS_DSR_ON));
1052 ok(EscapeCommFunction(hcom, CLRDTR), "EscapeCommFunction failed to clear DTR\n");
1053 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
1054 ok (ModemStat == defaultStat, "Failed to restore DSR: 0x%04x, expected 0x%04x\n",
1055 ModemStat, defaultStat);
1056 }
1057 }
1058
1059 static void test_LoopbackDtrRing(HANDLE hcom)
1060 {
1061 DWORD ModemStat = 0, defaultStat = 0;
1062 DCB dcb;
1063
1064 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
1065 if (dcb.fDtrControl == DTR_CONTROL_HANDSHAKE)
1066 {
1067 trace("DTR_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
1068 return;
1069 }
1070 ok(GetCommModemStatus(hcom, &defaultStat), "GetCommModemStatus failed\n");
1071 /* XP returns some values in the low nibble, so mask them out*/
1072 defaultStat &= MS_CTS_ON|MS_DSR_ON|MS_RING_ON|MS_RLSD_ON;
1073 if(defaultStat & MS_RING_ON)
1074 {
1075 ok(EscapeCommFunction(hcom, CLRDTR), "EscapeCommFunction failed to clear DTR\n");
1076 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
1077 ok ((ModemStat & MS_RING_ON) == 0, "RING didn't react: 0x%04x, expected 0x%04x\n",
1078 ModemStat, (defaultStat & ~MS_RING_ON));
1079 ok(EscapeCommFunction(hcom, SETDTR), "EscapeCommFunction failed to set DTR\n");
1080 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
1081 ok (ModemStat == defaultStat, "Failed to restore RING: 0x%04x, expected 0x%04x\n",
1082 ModemStat, defaultStat);
1083 }
1084 else
1085 {
1086 ok(EscapeCommFunction(hcom, SETDTR), "EscapeCommFunction failed to set DTR\n");
1087 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
1088 ok ((ModemStat & MS_RING_ON) == MS_RING_ON,
1089 "RING didn't react: 0x%04x,expected 0x%04x\n",
1090 ModemStat, (defaultStat | MS_RING_ON));
1091 ok(EscapeCommFunction(hcom, CLRDTR), "EscapeCommFunction failed to clear DTR\n");
1092 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
1093 ok (ModemStat == defaultStat, "Failed to restore RING: 0x%04x, expected 0x%04x\n",
1094 ModemStat, defaultStat);
1095 }
1096 }
1097
1098 /*
1099 * Set up a WaitCommEvent for anything in the receive buffer,
1100 * then write to TX to put a character
1101 * into the RX buffer
1102 * Need Loopback TX->RX
1103 */
1104
1105 static void test_WaitRx(HANDLE hcom)
1106 {
1107 OVERLAPPED overlapped, overlapped_w;
1108 HANDLE hComPortEvent, hComWriteEvent;
1109 DWORD before, after, after1, diff, success_wait = FALSE, success_write;
1110 DWORD err_wait, err_write, written, evtmask=0;
1111
1112 ok(SetCommMask(hcom, EV_RXCHAR), "SetCommMask failed\n");
1113 hComPortEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
1114 ok(hComPortEvent != 0, "CreateEvent failed\n");
1115 ZeroMemory( &overlapped, sizeof(overlapped));
1116 overlapped.hEvent = hComPortEvent;
1117
1118 hComWriteEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
1119 ok(hComWriteEvent != NULL, "CreateEvent res %d\n", GetLastError());
1120 ZeroMemory( &overlapped_w, sizeof(overlapped_w));
1121 overlapped_w.hEvent = hComWriteEvent;
1122
1123 before = GetTickCount();
1124 {success_wait = WaitCommEvent(hcom, &evtmask, &overlapped);}
1125 err_wait = GetLastError();
1126 after = GetTickCount();
1127 trace("Success 0x%08x err %d evtmask 0x%08x\n", success_wait, err_wait, evtmask);
1128 ok(success_wait || err_wait == ERROR_IO_PENDING, "overlapped WaitCommEvent failed\n");
1129 trace("overlapped WriteCommEvent returned.\n");
1130
1131 success_write= WriteFile(hcom, "X", 1, &written, &overlapped_w);
1132 err_write = GetLastError();
1133 ok(success_write || err_write == ERROR_IO_PENDING,
1134 "overlapped WriteFile failed, err %d\n",
1135 err_write);
1136
1137 if (!success_write && (err_write == ERROR_IO_PENDING)) {
1138 success_write = WaitForSingleObjectEx(hComWriteEvent, TIMEOUT, TRUE);
1139 err_write = GetLastError();
1140 ok(success_write == WAIT_OBJECT_0, "WaitForSingleObjectEx, res %d, err %d\n",
1141 success_write, err_write);
1142 }
1143 Sleep(TIMEOUT >>1);
1144 success_write = GetOverlappedResult(hcom, &overlapped_w, &written, FALSE);
1145 err_write = GetLastError();
1146
1147 trace("Write after Wait res 0x%08x err %d\n",success_write, err_write);
1148 ok(success_write && written ==1, "Write after Wait res 0x%08x err %d\n",
1149 success_write, err_write);
1150
1151 if (!success_wait && (err_wait == ERROR_IO_PENDING)) {
1152 success_wait = WaitForSingleObjectEx(hComPortEvent, TIMEOUT, TRUE);
1153 err_wait = GetLastError();
1154 ok(success_wait == WAIT_OBJECT_0, "wait hComPortEvent, res 0x%08x, err %d\n",
1155 success_wait, err_wait);
1156 }
1157 success_wait = GetOverlappedResult(hcom, &overlapped, &written, FALSE);
1158 err_wait = GetLastError();
1159 after1 = GetTickCount();
1160 trace("Success 0x%08x err %d evtmask 0x%08x diff1 %d, diff2 %d\n",
1161 success_wait, err_wait, evtmask, after-before, after1-before);
1162
1163 ok(evtmask & EV_RXCHAR, "Detect EV_RXCHAR: 0x%08x, expected 0x%08x\n",
1164 evtmask, EV_RXCHAR);
1165 diff = after1 - before;
1166 ok ((diff > (TIMEOUT>>1) -TIMEDELTA) && (diff < (TIMEOUT>>1) + TIMEDELTA),
1167 "Unexpected time %d, expected around %d\n", diff, TIMEOUT>>1);
1168
1169 }
1170
1171 /* Change the controling line after the given timeout to the given state
1172 By the loopback, this should trigger the WaitCommEvent
1173 */
1174 static DWORD CALLBACK toggle_ctlLine(LPVOID arg)
1175 {
1176 DWORD_PTR *args = arg;
1177 DWORD timeout = args[0];
1178 DWORD ctl = args[1];
1179 HANDLE hcom = (HANDLE) args[2];
1180 HANDLE hComPortEvent = (HANDLE) args[3];
1181 DWORD success, err;
1182
1183 trace("toggle_ctlLine timeout %d ctl 0x%08x handle %p\n", timeout, ctl, hcom );
1184 Sleep(timeout);
1185 ok(EscapeCommFunction(hcom, ctl),"EscapeCommFunction 0x%08x failed\n", ctl);
1186 trace("toggle_ctline done\n");
1187 success = WaitForSingleObjectEx(hComPortEvent, TIMEOUT, TRUE);
1188 err = GetLastError();
1189 trace("toggle_ctline WaitForSingleObjectEx res 0x%08x err %d\n",
1190 success, err);
1191 return 0;
1192 }
1193
1194 /*
1195 * Wait for a change in CTS
1196 * Needs Loopback from DTR to CTS
1197 */
1198 static void test_WaitCts(HANDLE hcom)
1199 {
1200 DCB dcb;
1201 OVERLAPPED overlapped;
1202 HANDLE hComPortEvent;
1203 HANDLE alarmThread;
1204 DWORD_PTR args[4];
1205 DWORD alarmThreadId, before, after, after1, diff, success, err, written, evtmask=0, defaultStat = 0;
1206
1207 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
1208 dcb.fRtsControl=RTS_CONTROL_ENABLE;
1209 dcb.fDtrControl=DTR_CONTROL_ENABLE;
1210 ok(SetCommState(hcom, &dcb), "SetCommState failed\n");
1211 if (dcb.fDtrControl == RTS_CONTROL_DISABLE)
1212 {
1213 trace("RTS_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
1214 return;
1215 }
1216 args[0]= TIMEOUT >>1;
1217 ok(GetCommModemStatus(hcom, &defaultStat), "GetCommModemStatus failed\n");
1218 if(defaultStat & MS_CTS_ON)
1219 args[1] = CLRRTS;
1220 else
1221 args[1] = SETRTS;
1222 args[2]=(DWORD_PTR)hcom;
1223
1224 trace("test_WaitCts timeout %ld clt 0x%08lx handle %p\n",args[0], args[1], hcom);
1225
1226 ok(SetCommMask(hcom, EV_CTS), "SetCommMask failed\n");
1227 hComPortEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
1228 ok(hComPortEvent != 0, "CreateEvent failed\n");
1229 args[3] = (DWORD_PTR)hComPortEvent;
1230 alarmThread = CreateThread(NULL, 0, toggle_ctlLine, args, 0, &alarmThreadId);
1231 /* Wait a minimum to let the thread start up */
1232 Sleep(10);
1233 trace("Thread created\n");
1234 ok(alarmThread !=0 , "CreateThread Failed\n");
1235
1236 ZeroMemory( &overlapped, sizeof(overlapped));
1237 overlapped.hEvent = hComPortEvent;
1238 before = GetTickCount();
1239 success = WaitCommEvent(hcom, &evtmask, &overlapped);
1240 err = GetLastError();
1241 after = GetTickCount();
1242
1243 trace("Success 0x%08x err %d evtmask 0x%08x\n", success, err, evtmask);
1244 ok(success || err == ERROR_IO_PENDING, "overlapped WaitCommEvent failed\n");
1245 trace("overlapped WriteCommEvent returned.\n");
1246 if (!success && (err == ERROR_IO_PENDING))
1247 ok(WaitForSingleObjectEx(hComPortEvent, TIMEOUT, TRUE) == 0,
1248 "WaitCts hComPortEvent failed\n");
1249 success = GetOverlappedResult(hcom, &overlapped, &written, FALSE);
1250 err = GetLastError();
1251 after1 = GetTickCount();
1252 trace("Success 0x%08x err %d evtmask 0x%08x diff1 %d, diff2 %d\n",
1253 success, err, evtmask, after-before, after1-before);
1254
1255 ok(evtmask & EV_CTS, "Failed to detect EV_CTS: 0x%08x, expected 0x%08x\n",
1256 evtmask, EV_CTS);
1257 ok(GetCommModemStatus(hcom, &evtmask), "GetCommModemStatus failed\n");
1258 if(defaultStat & MS_CTS_ON)
1259 ok((evtmask & MS_CTS_ON) == 0,"CTS didn't change state!\n");
1260 else
1261 ok((evtmask & MS_CTS_ON), "CTS didn't change state!\n");
1262
1263 diff = after1 - before;
1264 ok ((diff > (TIMEOUT>>1) -TIMEDELTA) && (diff < (TIMEOUT>>1) + TIMEDELTA),
1265 "Unexpected time %d, expected around %d\n", diff, TIMEOUT>>1);
1266
1267 /*restore RTS Settings*/
1268 if(defaultStat & MS_CTS_ON)
1269 args[1] = SETRTS;
1270 else
1271 args[1] = CLRRTS;
1272 }
1273
1274 /* Change the Comm Mask while a Wait is going on
1275 WaitCommevent should return with a EVTMASK set to zero
1276 */
1277 static DWORD CALLBACK reset_CommMask(LPVOID arg)
1278 {
1279 DWORD_PTR *args = arg;
1280 DWORD timeout = args[0];
1281 HANDLE hcom = (HANDLE) args[1];
1282
1283 trace(" Changing CommMask on the fly for handle %p after timeout %d\n",
1284 hcom, timeout);
1285 Sleep(timeout);
1286 ok(SetCommMask(hcom, 0),"SetCommMask %p failed\n", hcom);
1287 trace("SetCommMask changed\n");
1288 return 0;
1289 }
1290
1291 /* Set up a Wait for a change on CTS. We don't toggle any line, but we
1292 reset the CommMask and expect the wait to return with a mask of 0
1293 No special port connections needed
1294 */
1295 static void test_AbortWaitCts(HANDLE hcom)
1296 {
1297 DCB dcb;
1298 OVERLAPPED overlapped;
1299 HANDLE hComPortEvent;
1300 HANDLE alarmThread;
1301 DWORD_PTR args[2];
1302 DWORD alarmThreadId, before, after, after1, diff, success, err, written, evtmask=0;
1303
1304 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
1305 if (dcb.fDtrControl == RTS_CONTROL_DISABLE)
1306 {
1307 trace("RTS_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
1308 return;
1309 }
1310 args[0]= TIMEOUT >>1;
1311 args[1]= (DWORD_PTR)hcom;
1312
1313 trace("test_AbortWaitCts timeout %ld handle %p\n",args[0], hcom);
1314
1315 ok(SetCommMask(hcom, EV_CTS), "SetCommMask failed\n");
1316 hComPortEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
1317 ok(hComPortEvent != 0, "CreateEvent failed\n");
1318 alarmThread = CreateThread(NULL, 0, reset_CommMask, args, 0, &alarmThreadId);
1319 /* Wait a minimum to let the thread start up */
1320 Sleep(10);
1321 trace("Thread created\n");
1322 ok(alarmThread !=0 , "CreateThread Failed\n");
1323
1324 ZeroMemory( &overlapped, sizeof(overlapped));
1325 overlapped.hEvent = hComPortEvent;
1326 before = GetTickCount();
1327 success = WaitCommEvent(hcom, &evtmask, &overlapped);
1328 err = GetLastError();
1329 after = GetTickCount();
1330
1331 trace("Success 0x%08x err %d evtmask 0x%08x\n", success, err, evtmask);
1332 ok(success || err == ERROR_IO_PENDING, "overlapped WaitCommEvent failed\n");
1333 trace("overlapped WriteCommEvent returned.\n");
1334 if (!success && (err == ERROR_IO_PENDING))
1335 ok(WaitForSingleObjectEx(hComPortEvent, TIMEOUT, TRUE) == 0,
1336 "AbortWaitCts hComPortEvent failed\n");
1337 success = GetOverlappedResult(hcom, &overlapped, &written, FALSE);
1338 err = GetLastError();
1339 after1 = GetTickCount();
1340 trace("Success 0x%08x err %d evtmask 0x%08x diff1 %d, diff2 %d\n",
1341 success, err, evtmask, after-before, after1-before);
1342
1343 ok(evtmask == 0, "Incorrect EventMask 0x%08x returned on Wait aborted bu SetCommMask, expected 0x%08x\n",
1344 evtmask, 0);
1345 ok(GetCommModemStatus(hcom, &evtmask), "GetCommModemStatus failed\n");
1346 diff = after1 - before;
1347 ok ((diff > (TIMEOUT>>1) -TIMEDELTA) && (diff < (TIMEOUT>>1) + TIMEDELTA),
1348 "Unexpected time %d, expected around %d\n", diff, TIMEOUT>>1);
1349
1350 }
1351
1352 /*
1353 * Wait for a change in DSR
1354 * Needs Loopback from DTR to DSR
1355 */
1356 static void test_WaitDsr(HANDLE hcom)
1357 {
1358 DCB dcb;
1359 OVERLAPPED overlapped;
1360 HANDLE hComPortEvent;
1361 HANDLE alarmThread;
1362 DWORD_PTR args[3];
1363 DWORD alarmThreadId, before, after, after1, diff, success, err, written, evtmask=0, defaultStat = 0;
1364
1365 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
1366 if (dcb.fDtrControl == DTR_CONTROL_DISABLE)
1367 {
1368 trace("DTR_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
1369 return;
1370 }
1371 args[0]= TIMEOUT >>1;
1372 ok(GetCommModemStatus(hcom, &defaultStat), "GetCommModemStatus failed\n");
1373 if(defaultStat & MS_DSR_ON)
1374 args[1] = CLRDTR;
1375 else
1376 args[1] = SETDTR;
1377 args[2]= (DWORD_PTR)hcom;
1378
1379 trace("test_WaitDsr timeout %ld clt 0x%08lx handle %p\n",args[0], args[1], hcom);
1380
1381 ok(SetCommMask(hcom, EV_DSR), "SetCommMask failed\n");
1382 hComPortEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
1383 ok(hComPortEvent != 0, "CreateEvent failed\n");
1384 alarmThread = CreateThread(NULL, 0, toggle_ctlLine, args, 0, &alarmThreadId);
1385 ok(alarmThread !=0 , "CreateThread Failed\n");
1386
1387 ZeroMemory( &overlapped, sizeof(overlapped));
1388 overlapped.hEvent = hComPortEvent;
1389 before = GetTickCount();
1390 success = WaitCommEvent(hcom, &evtmask, &overlapped);
1391 err = GetLastError();
1392 after = GetTickCount();
1393
1394 trace("Success 0x%08x err %d evtmask 0x%08x\n", success, err, evtmask);
1395 ok(success || err == ERROR_IO_PENDING, "overlapped WaitCommEvent failed\n");
1396 trace("overlapped WriteCommEvent returned.\n");
1397 if (!success && (err == ERROR_IO_PENDING))
1398 ok(WaitForSingleObjectEx(hComPortEvent, TIMEOUT, TRUE) == 0,
1399 "wait hComPortEvent failed\n");
1400 success = GetOverlappedResult(hcom, &overlapped, &written, FALSE);
1401 err = GetLastError();
1402 after1 = GetTickCount();
1403 trace("Success 0x%08x err %d evtmask 0x%08x diff1 %d, diff2 %d\n",
1404 success, err, evtmask, after-before, after1-before);
1405
1406 ok(evtmask & EV_DSR, "Failed to detect EV_DSR: 0x%08x, expected 0x%08x\n",
1407 evtmask, EV_DSR);
1408 ok(GetCommModemStatus(hcom, &evtmask), "GetCommModemStatus failed\n");
1409 if(defaultStat & MS_DSR_ON)
1410 ok((evtmask & MS_DSR_ON) == 0,"DTR didn't change state!\n");
1411 else
1412 ok((evtmask & MS_DSR_ON), "DTR didn't change state!\n");
1413
1414 diff = after1 - before;
1415 ok ((diff > (TIMEOUT>>1) -TIMEDELTA) && (diff < (TIMEOUT>>1) + TIMEDELTA),
1416 "Unexpected time %d, expected around %d\n", diff, TIMEOUT>>1);
1417
1418 /*restore RTS Settings*/
1419 if(defaultStat & MS_DSR_ON)
1420 args[1] = SETDTR;
1421 else
1422 args[1] = CLRDTR;
1423 }
1424
1425 /*
1426 * Wait for a Ring
1427 * Needs Loopback from DTR to RING
1428 */
1429 static void test_WaitRing(HANDLE hcom)
1430 {
1431 DCB dcb;
1432 OVERLAPPED overlapped;
1433 HANDLE hComPortEvent;
1434 HANDLE alarmThread;
1435 DWORD_PTR args[3];
1436 DWORD alarmThreadId, before, after, after1, diff, success, err, written, evtmask=0, defaultStat;
1437 BOOL ret;
1438
1439 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
1440 if (dcb.fDtrControl == DTR_CONTROL_DISABLE)
1441 {
1442 trace("DTR_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
1443 return;
1444 }
1445 args[0]= TIMEOUT >>1;
1446 ok((ret = GetCommModemStatus(hcom, &defaultStat)), "GetCommModemStatus failed\n");
1447 if (!ret) {
1448 skip("modem status failed -> skip.\n");
1449 return;
1450 }
1451 if(defaultStat & MS_RING_ON)
1452 args[1] = CLRDTR;
1453 else
1454 args[1] = SETDTR;
1455 args[2]=(DWORD_PTR) hcom;
1456
1457 trace("test_WaitRing timeout %ld clt 0x%08lx handle %p\n",args[0], args[1], hcom);
1458
1459 ok(SetCommMask(hcom, EV_RING), "SetCommMask failed\n");
1460 hComPortEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
1461 ok(hComPortEvent != 0, "CreateEvent failed\n");
1462 alarmThread = CreateThread(NULL, 0, toggle_ctlLine, args, 0, &alarmThreadId);
1463 ok(alarmThread !=0 , "CreateThread Failed\n");
1464
1465 ZeroMemory( &overlapped, sizeof(overlapped));
1466 overlapped.hEvent = hComPortEvent;
1467 before = GetTickCount();
1468 success = WaitCommEvent(hcom, &evtmask, &overlapped);
1469 err = GetLastError();
1470 after = GetTickCount();
1471
1472 trace("Success 0x%08x err %d evtmask 0x%08x\n", success, err, evtmask);
1473 ok(success || err == ERROR_IO_PENDING, "overlapped WaitCommEvent failed\n");
1474 trace("overlapped WriteCommEvent returned.\n");
1475 if (!success && (err == ERROR_IO_PENDING))
1476 ok(WaitForSingleObjectEx(hComPortEvent, TIMEOUT, TRUE) == 0,
1477 "wait hComPortEvent failed\n");
1478 success = GetOverlappedResult(hcom, &overlapped, &written, FALSE);
1479 err = GetLastError();
1480 after1 = GetTickCount();
1481 trace("Success 0x%08x err %d evtmask 0x%08x diff1 %d, diff2 %d\n",
1482 success, err, evtmask, after-before, after1-before);
1483
1484 ok(evtmask & EV_RING, "Failed to detect EV_RING: 0x%08x, expected 0x%08x\n",
1485 evtmask, EV_CTS);
1486 ok(GetCommModemStatus(hcom, &evtmask), "GetCommModemStatus failed\n");
1487 if(defaultStat & MS_RING_ON)
1488 ok((evtmask & MS_RING_ON) == 0,"DTR didn't change state!\n");
1489 else
1490 ok((evtmask & MS_RING_ON), "DTR didn't change state!\n");
1491
1492 diff = after1 - before;
1493 ok ((diff > (TIMEOUT>>1) -TIMEDELTA) && (diff < (TIMEOUT>>1) + TIMEDELTA),
1494 "Unexpected time %d, expected around %d\n", diff, TIMEOUT>>1);
1495
1496 /*restore RTS Settings*/
1497 if(defaultStat & MS_RING_ON)
1498 args[1] = SETDTR;
1499 else
1500 args[1] = CLRDTR;
1501 }
1502 /*
1503 * Wait for a change in DCD
1504 * Needs Loopback from DTR to DCD
1505 */
1506 static void test_WaitDcd(HANDLE hcom)
1507 {
1508 DCB dcb;
1509 OVERLAPPED overlapped;
1510 HANDLE hComPortEvent;
1511 HANDLE alarmThread;
1512 DWORD_PTR args[3];
1513 DWORD alarmThreadId, before, after, after1, diff, success, err, written, evtmask=0, defaultStat = 0;
1514
1515 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
1516 if (dcb.fDtrControl == DTR_CONTROL_DISABLE)
1517 {
1518 trace("DTR_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
1519 return;
1520 }
1521 args[0]= TIMEOUT >>1;
1522 ok(GetCommModemStatus(hcom, &defaultStat), "GetCommModemStatus failed\n");
1523 if(defaultStat & MS_RLSD_ON)
1524 args[1] = CLRDTR;
1525 else
1526 args[1] = SETDTR;
1527 args[2]= (DWORD_PTR)hcom;
1528
1529 trace("test_WaitDcd timeout %ld clt 0x%08lx handle %p\n",args[0], args[1], hcom);
1530
1531 ok(SetCommMask(hcom, EV_RLSD), "SetCommMask failed\n");
1532 hComPortEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
1533 ok(hComPortEvent != 0, "CreateEvent failed\n");
1534 alarmThread = CreateThread(NULL, 0, toggle_ctlLine, args, 0, &alarmThreadId);
1535 ok(alarmThread !=0 , "CreateThread Failed\n");
1536
1537 ZeroMemory( &overlapped, sizeof(overlapped));
1538 overlapped.hEvent = hComPortEvent;
1539 before = GetTickCount();
1540 success = WaitCommEvent(hcom, &evtmask, &overlapped);
1541 err = GetLastError();
1542 after = GetTickCount();
1543
1544 trace("Success 0x%08x err %d evtmask 0x%08x\n", success, err, evtmask);
1545 ok(success || err == ERROR_IO_PENDING, "overlapped WaitCommEvent failed\n");
1546 trace("overlapped WriteCommEvent returned.\n");
1547 if (!success && (err == ERROR_IO_PENDING))
1548 ok(WaitForSingleObjectEx(hComPortEvent, TIMEOUT, TRUE) == 0,
1549 "wait hComPortEvent failed\n");
1550 success = GetOverlappedResult(hcom, &overlapped, &written, FALSE);
1551 err = GetLastError();
1552 after1 = GetTickCount();
1553 trace("Success 0x%08x err %d evtmask 0x%08x diff1 %d, diff2 %d\n",
1554 success, err, evtmask, after-before, after1-before);
1555
1556 ok(evtmask & EV_RLSD, "Failed to detect EV_RLSD: 0x%08x, expected 0x%08x\n",
1557 evtmask, EV_CTS);
1558 ok(GetCommModemStatus(hcom, &evtmask), "GetCommModemStatus failed\n");
1559 if(defaultStat & MS_RLSD_ON)
1560 ok((evtmask & MS_RLSD_ON) == 0,"DTR didn't change state!\n");
1561 else
1562 ok((evtmask & MS_RLSD_ON), "DTR didn't change state!\n");
1563
1564 diff = after1 - before;
1565 ok ((diff > (TIMEOUT>>1) -TIMEDELTA) && (diff < (TIMEOUT>>1) + TIMEDELTA),
1566 "Unexpected time %d, expected around %d\n", diff, TIMEOUT>>1);
1567
1568 /*restore RTS Settings*/
1569 if(defaultStat & MS_RLSD_ON)
1570 args[1] = SETDTR;
1571 else
1572 args[1] = CLRDTR;
1573 }
1574
1575 /*
1576 Set Break after timeout
1577 */
1578 static DWORD CALLBACK set_CommBreak(LPVOID arg)
1579 {
1580 DWORD_PTR *args = arg;
1581 DWORD timeout = args[0];
1582 HANDLE hcom = (HANDLE) args[1];
1583
1584 trace("SetCommBreak for handle %p after timeout %d\n",
1585 hcom, timeout);
1586 Sleep(timeout);
1587 ok(SetCommBreak(hcom),"SetCommBreak %p failed\n", hcom);
1588 trace("SetCommBreak done\n");
1589 return 0;
1590 }
1591
1592 /*
1593 Wait for the Break condition (TX resp. RX active)
1594 Needs Loopback TX-RX
1595 */
1596 static void test_WaitBreak(HANDLE hcom)
1597 {
1598 OVERLAPPED overlapped;
1599 HANDLE hComPortEvent;
1600 HANDLE alarmThread;
1601 DWORD_PTR args[2];
1602 DWORD alarmThreadId, before, after, after1, diff, success, err, written, evtmask=0;
1603
1604 ok(SetCommMask(hcom, EV_BREAK), "SetCommMask failed\n");
1605 hComPortEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
1606 ok(hComPortEvent != 0, "CreateEvent failed\n");
1607
1608 trace("test_WaitBreak\n");
1609 args[0]= TIMEOUT >>1;
1610 args[1]= (DWORD_PTR)hcom;
1611 alarmThread = CreateThread(NULL, 0, set_CommBreak, args, 0, &alarmThreadId);
1612 /* Wait a minimum to let the thread start up */
1613 Sleep(10);
1614 trace("Thread created\n");
1615 ok(alarmThread !=0 , "CreateThread Failed\n");
1616
1617 ZeroMemory( &overlapped, sizeof(overlapped));
1618 overlapped.hEvent = hComPortEvent;
1619 before = GetTickCount();
1620 success = WaitCommEvent(hcom, &evtmask, &overlapped);
1621 err = GetLastError();
1622 after = GetTickCount();
1623
1624 trace("Success 0x%08x err %d evtmask 0x%08x\n", success, err, evtmask);
1625 ok(success || err == ERROR_IO_PENDING, "overlapped WaitCommEvent failed\n");
1626 trace("overlapped WriteCommEvent returned.\n");
1627
1628 if (!success && (err == ERROR_IO_PENDING))
1629 {
1630 success = WaitForSingleObjectEx(hComPortEvent, TIMEOUT, TRUE);
1631 ok(!success, "wait hComPortEvent res %d\n", GetLastError());
1632 }
1633 success = GetOverlappedResult(hcom, &overlapped, &written, FALSE);
1634 err = GetLastError();
1635 after1 = GetTickCount();
1636 trace("Success 0x%08x err %d evtmask 0x%08x diff1 %d, diff2 %d\n",
1637 success, err, evtmask, after-before, after1-before);
1638
1639 ok(evtmask & EV_BREAK, "Failed to detect EV_BREAK: 0x%08x, expected 0x%08x\n",
1640 evtmask, EV_BREAK);
1641 ok(GetCommModemStatus(hcom, &evtmask), "GetCommModemStatus failed\n");
1642
1643 diff = after1 - before;
1644 ok ((diff > (TIMEOUT>>1) -TIMEDELTA) && (diff < (TIMEOUT>>1) + TIMEDELTA),
1645 "Unexpected time %d, expected around %d\n", diff, TIMEOUT>>1);
1646
1647 ok(ClearCommBreak(hcom), "ClearCommBreak failed\n");
1648 }
1649
1650 static void test_stdio(void)
1651 {
1652 DCB dcb;
1653
1654 /* cygwin tries this to determine the stdin handle type */
1655 ok( !GetCommState( GetStdHandle(STD_INPUT_HANDLE), &dcb ), "GetCommState succeeded on stdin\n" );
1656 ok( GetLastError() == ERROR_INVALID_HANDLE || GetLastError() == ERROR_INVALID_FUNCTION,
1657 "got error %u\n", GetLastError() );
1658 }
1659
1660 START_TEST(comm)
1661 {
1662 HANDLE hcom;
1663 /* use variables and not #define to compile the code */
1664 BOOL loopback_txd_rxd = LOOPBACK_TXD_RXD;
1665 BOOL loopback_rts_cts = LOOPBACK_CTS_RTS;
1666 BOOL loopback_dtr_dsr = LOOPBACK_DTR_DSR;
1667 BOOL loopback_dtr_ring = LOOPBACK_DTR_RING;
1668 BOOL loopback_dtr_dcd = LOOPBACK_DTR_DCD;
1669
1670 test_BuildCommDCB();
1671 hcom = test_OpenComm(FALSE);
1672 if (hcom != INVALID_HANDLE_VALUE)
1673 {
1674 test_GetModemStatus(hcom);
1675 test_ReadTimeOut(hcom);
1676 test_waittxempty(hcom);
1677 CloseHandle(hcom);
1678 }
1679 hcom = test_OpenComm(FALSE);
1680 if (hcom != INVALID_HANDLE_VALUE)
1681 {
1682 Sleep(200); /* Give the laster character of test_waittxempty to drop into the receiver */
1683 test_ClearCommErrors(hcom);
1684 CloseHandle(hcom);
1685 }
1686 hcom = test_OpenComm(FALSE);
1687 if (hcom != INVALID_HANDLE_VALUE)
1688 {
1689 test_non_pending_errors(hcom);
1690 CloseHandle(hcom);
1691 }
1692 if((loopback_txd_rxd) && ((hcom = test_OpenComm(FALSE))!=INVALID_HANDLE_VALUE))
1693 {
1694 test_LoopbackRead(hcom);
1695 CloseHandle(hcom);
1696 }
1697 if((loopback_rts_cts) && ((hcom = test_OpenComm(FALSE))!=INVALID_HANDLE_VALUE))
1698 {
1699 test_LoopbackCtsRts(hcom);
1700 CloseHandle(hcom);
1701 }
1702 if((loopback_dtr_dsr) && ((hcom = test_OpenComm(FALSE))!=INVALID_HANDLE_VALUE))
1703 {
1704 test_LoopbackDtrDsr(hcom);
1705 CloseHandle(hcom);
1706 }
1707 if((loopback_dtr_ring) && ((hcom = test_OpenComm(FALSE))!=INVALID_HANDLE_VALUE))
1708 {
1709 test_LoopbackDtrRing(hcom);
1710 CloseHandle(hcom);
1711 }
1712 if((loopback_dtr_dcd) && ((hcom = test_OpenComm(FALSE))!=INVALID_HANDLE_VALUE))
1713 {
1714 test_LoopbackDtrDcd(hcom);
1715 CloseHandle(hcom);
1716 }
1717 if((loopback_txd_rxd) && ((hcom = test_OpenComm(TRUE))!=INVALID_HANDLE_VALUE))
1718 {
1719 test_WaitRx(hcom);
1720 CloseHandle(hcom);
1721 }
1722 if((loopback_rts_cts) && ((hcom = test_OpenComm(TRUE))!=INVALID_HANDLE_VALUE))
1723 {
1724 test_WaitCts(hcom);
1725 CloseHandle(hcom);
1726 }
1727 if((hcom = test_OpenComm(TRUE))!=INVALID_HANDLE_VALUE)
1728 {
1729 test_AbortWaitCts(hcom);
1730 CloseHandle(hcom);
1731 }
1732 if((loopback_dtr_dsr) && ((hcom = test_OpenComm(TRUE))!=INVALID_HANDLE_VALUE))
1733 {
1734 test_WaitDsr(hcom);
1735 CloseHandle(hcom);
1736 }
1737 if((loopback_dtr_ring) && ((hcom = test_OpenComm(TRUE))!=INVALID_HANDLE_VALUE))
1738 {
1739 test_WaitRing(hcom);
1740 CloseHandle(hcom);
1741 }
1742 if((loopback_dtr_dcd) && ((hcom = test_OpenComm(TRUE))!=INVALID_HANDLE_VALUE))
1743 {
1744 test_WaitDcd(hcom);
1745 CloseHandle(hcom);
1746 }
1747 if(loopback_txd_rxd && (hcom = test_OpenComm(TRUE))!=INVALID_HANDLE_VALUE)
1748 {
1749 test_WaitBreak(hcom);
1750 CloseHandle(hcom);
1751 }
1752 test_stdio();
1753 }