wine.inf: We should not override existing associations.
[wine/hacks.git] / dlls / kernel / tests / comm.c
blob3fac9c2679665b9b5c69d94f213eb5594df62343
1 /* Unit test suite for comm functions
3 * Copyright 2003 Kevin Groeneveld
4 * Copyright 2005 Uwe Bonnes
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
21 #include <stdio.h>
23 #include "wine/test.h"
24 #include "winbase.h"
25 #include "winnls.h"
27 #define TIMEOUT 1000 /* one second for Timeouts*/
28 #define SLOWBAUD 150
29 #define FASTBAUD 115200
30 #define TIMEDELTA 100 /* 100 ms uncertainty allowed */
32 /* Define the appropriate LOOPBACK(s) TRUE if you have a Loopback cable with
33 * the mentioned shorts connected to your Serial port
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
45 typedef struct
47 char string[100];
48 BOOL result;
49 BOOL old_style;
50 DCB dcb1, dcb2;
51 COMMTIMEOUTS timeouts1, timeouts2;
52 } TEST;
54 static TEST test[] =
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
61 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
62 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
69 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
70 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
77 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
78 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
85 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000EA60 },
86 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000EA60 }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
93 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
94 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
101 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
102 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
109 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
110 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
117 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
118 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
125 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
126 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
133 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
134 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
141 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
142 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
149 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
150 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
157 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
158 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
165 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
166 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
173 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
174 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
181 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
182 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
189 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
190 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
197 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
198 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
205 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
206 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
213 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
214 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
221 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
222 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
229 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
230 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
237 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
238 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
245 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
246 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
253 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
254 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
261 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
262 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
269 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
270 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
277 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
278 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
285 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
286 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
293 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
294 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
301 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
302 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
309 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
310 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
317 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
318 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
325 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
326 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
333 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000EA60 },
334 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000EA60 }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
341 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
342 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
349 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
350 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
357 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
358 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
365 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
366 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
373 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
374 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
381 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
382 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
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, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)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, (char)0xff, (char)0xff, (char)0xff, (char)0xff, (char)0xff, 0xffff },
389 { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
390 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
394 #define TEST_COUNT (sizeof(test) / sizeof(TEST))
396 /* This function can be useful if you are modifiying the test cases and want to
397 output the contents of a DCB structure. */
398 /*static print_dcb(DCB *pdcb)
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, (char)0x%02x, (char)0x%02x, (char)0x%02x, (char)0x%02x, (char)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 } */
431 static void check_result(const char *function, TEST *ptest, int initial_value, BOOL result)
433 DWORD LastError = GetLastError();
434 DWORD CorrectError = (ptest->result ? 0xdeadbeef : ERROR_INVALID_PARAMETER);
436 ok(LastError == CorrectError, "%s(\"%s\"), 0x%02x: GetLastError() returned 0x%08lx, should be 0x%08lx\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");
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); }
443 static void check_dcb(const char *function, TEST *ptest, int initial_value, DCB *pdcb1, DCB *pdcb2)
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), "%lu");
449 /* For old style control strings Win 9x does not set the next five members, NT does. */
450 if(ptest->old_style && ptest->result)
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");
458 else
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");
467 if(ptest->result)
469 /* For the idsr=xxx parameter, NT sets fDsrSensitivity, 9x sets
470 fOutxDsrFlow. */
471 if(!ptest->old_style)
473 check_dcb_member2(fOutxDsrFlow, pdcb2->fDsrSensitivity, "%u");
474 check_dcb_member2(fDsrSensitivity, pdcb2->fOutxDsrFlow, "%u");
476 else
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");
484 else
486 check_dcb_member(fOutxDsrFlow, "%u");
487 check_dcb_member(fDsrSensitivity, "%u");
490 /* Check the result of the DCB members. */
491 check_dcb_member(BaudRate, "%lu");
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");
513 #define check_timeouts_member(a) ok(ptimeouts1->a == ptimeouts2->a, "%s(\"%s\"), 0x%02x: "#a" is %lu, should be %lu\n", function, ptest->string, initial_value, ptimeouts1->a, ptimeouts2->a);
515 static void check_timeouts(const char *function, TEST *ptest, int initial_value, COMMTIMEOUTS *ptimeouts1, COMMTIMEOUTS *ptimeouts2)
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);
524 static void test_BuildCommDCBA(TEST *ptest, int initial_value, DCB *pexpected_dcb)
526 BOOL result;
527 DCB dcb;
529 /* set initial conditions */
530 memset(&dcb, initial_value, sizeof(DCB));
531 SetLastError(0xdeadbeef);
533 result = BuildCommDCBA(ptest->string, &dcb);
535 /* check results */
536 check_result("BuildCommDCBA", ptest, initial_value, result);
537 check_dcb("BuildCommDCBA", ptest, initial_value, &dcb, pexpected_dcb);
540 static void test_BuildCommDCBAndTimeoutsA(TEST *ptest, int initial_value, DCB *pexpected_dcb, COMMTIMEOUTS *pexpected_timeouts)
542 BOOL result;
543 DCB dcb;
544 COMMTIMEOUTS timeouts;
546 /* set initial conditions */
547 memset(&dcb, initial_value, sizeof(DCB));
548 memset(&timeouts, initial_value, sizeof(COMMTIMEOUTS));
549 SetLastError(0xdeadbeef);
551 result = BuildCommDCBAndTimeoutsA(ptest->string, &dcb, &timeouts);
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);
559 static void test_BuildCommDCBW(TEST *ptest, int initial_value, DCB *pexpected_dcb)
561 BOOL result;
562 DCB dcb;
563 WCHAR wide_string[sizeof(ptest->string)];
565 MultiByteToWideChar(CP_ACP, 0, ptest->string, -1, wide_string, sizeof(wide_string) / sizeof(WCHAR));
567 /* set initial conditions */
568 memset(&dcb, initial_value, sizeof(DCB));
569 SetLastError(0xdeadbeef);
571 result = BuildCommDCBW(wide_string, &dcb);
573 if(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
574 return;
576 /* check results */
577 check_result("BuildCommDCBW", ptest, initial_value, result);
578 check_dcb("BuildCommDCBW", ptest, initial_value, &dcb, pexpected_dcb);
581 static void test_BuildCommDCBAndTimeoutsW(TEST *ptest, int initial_value, DCB *pexpected_dcb, COMMTIMEOUTS *pexpected_timeouts)
583 BOOL result;
584 DCB dcb;
585 COMMTIMEOUTS timeouts;
586 WCHAR wide_string[sizeof(ptest->string)];
588 MultiByteToWideChar(CP_ACP, 0, ptest->string, -1, wide_string, sizeof(wide_string) / sizeof(WCHAR));
590 /* set initial conditions */
591 memset(&dcb, initial_value, sizeof(DCB));
592 memset(&timeouts, initial_value, sizeof(COMMTIMEOUTS));
593 SetLastError(0xdeadbeef);
595 result = BuildCommDCBAndTimeoutsW(wide_string, &dcb, &timeouts);
597 if(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
598 return;
600 /* check results */
601 check_result("BuildCommDCBAndTimeoutsA", ptest, initial_value, result);
602 check_dcb("BuildCommDCBAndTimeoutsA", ptest, initial_value, &dcb, pexpected_dcb);
603 check_timeouts("BuildCommDCBAndTimeoutsA", ptest, initial_value, &timeouts, pexpected_timeouts);
606 static void test_BuildCommDCB(void)
608 char port_name[] = "COMx";
609 char port = 0;
610 unsigned int i;
611 char *ptr;
613 /* Some of these tests require a valid COM port. This loop will try to find
614 a valid port. */
615 for(port_name[3] = '1'; port_name[3] <= '9'; port_name[3]++)
617 COMMCONFIG commconfig;
618 DWORD size = sizeof(COMMCONFIG);
620 if(GetDefaultCommConfig(port_name, &commconfig, &size))
622 port = port_name[3];
623 break;
627 if(!port)
628 trace("Could not find a valid COM port. Some tests will be skipped.\n");
630 for(i = 0; i < TEST_COUNT; i++)
632 /* Check if this test case needs a valid COM port. */
633 ptr = strstr(test[i].string, "COMx");
635 /* If required, substitute valid port number into device control string. */
636 if(ptr)
638 if(port)
639 ptr[3] = port;
640 else
641 continue;
644 test_BuildCommDCBA(&test[i], 0x00, &test[i].dcb1);
645 test_BuildCommDCBA(&test[i], 0xff, &test[i].dcb2);
646 test_BuildCommDCBAndTimeoutsA(&test[i], 0x00, &test[i].dcb1, &test[i].timeouts1);
647 test_BuildCommDCBAndTimeoutsA(&test[i], 0xff, &test[i].dcb2, &test[i].timeouts2);
649 test_BuildCommDCBW(&test[i], 0x00, &test[i].dcb1);
650 test_BuildCommDCBW(&test[i], 0xff, &test[i].dcb2);
651 test_BuildCommDCBAndTimeoutsW(&test[i], 0x00, &test[i].dcb1, &test[i].timeouts1);
652 test_BuildCommDCBAndTimeoutsW(&test[i], 0xff, &test[i].dcb2, &test[i].timeouts2);
656 static HANDLE test_OpenComm(BOOL doOverlap)
658 HANDLE hcom = INVALID_HANDLE_VALUE;
659 char port_name[] = "COMx";
660 static BOOL shown = FALSE;
661 DWORD errors;
662 COMSTAT comstat;
664 /* Try to find a port */
665 for(port_name[3] = '1'; port_name[3] <= '9'; port_name[3]++)
667 hcom = CreateFile( port_name, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
668 (doOverlap)?FILE_FLAG_OVERLAPPED:0, NULL );
669 if (hcom != INVALID_HANDLE_VALUE)
670 break;
672 if(!shown)
674 if (hcom == INVALID_HANDLE_VALUE)
675 trace("Could not find a valid COM port. Skipping test_ReadTimeOut\n");
676 else
677 trace("Found Com port %s. Connected devices may disturbe results\n", port_name);
678 /*shown = TRUE; */
680 if (hcom != INVALID_HANDLE_VALUE)
682 ok(ClearCommError(hcom,&errors,&comstat), "Unexpected errors on open\n");
683 ok(comstat.cbInQue == 0, "Unexpected %ld chars in InQueue\n",comstat.cbInQue);
684 ok(comstat.cbOutQue == 0, "Still pending %ld charcters in OutQueue\n", comstat.cbOutQue);
685 ok(errors == 0, "Unexpected errors 0x%08lx\n", errors);
687 return hcom;
690 static void test_GetModemStatus(HANDLE hcom)
692 DWORD ModemStat;
694 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
695 trace("GetCommModemStatus returned 0x%08lx->%s%s%s%s\n", ModemStat,
696 (ModemStat &MS_RLSD_ON)?"MS_RLSD_ON ":"",
697 (ModemStat &MS_RING_ON)?"MS_RING_ON ":"",
698 (ModemStat &MS_DSR_ON)?"MS_DSR_ON ":"",
699 (ModemStat &MS_CTS_ON)?"MS_CTS_ON ":"");
702 /* When we don't write anything, Read should time out even on a loopbacked port */
703 static void test_ReadTimeOut(HANDLE hcom)
705 DCB dcb;
706 COMMTIMEOUTS timeouts;
707 char rbuf[32];
708 DWORD before, after, read, timediff, LastError;
709 BOOL res;
711 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
712 dcb.BaudRate = FASTBAUD;
713 dcb.ByteSize = 8;
714 dcb.Parity = NOPARITY;
715 dcb.fRtsControl=RTS_CONTROL_ENABLE;
716 dcb.fDtrControl=DTR_CONTROL_ENABLE;
717 dcb.StopBits = ONESTOPBIT;
718 ok(SetCommState(hcom, &dcb), "SetCommState failed\n");
720 ZeroMemory( &timeouts, sizeof(timeouts));
721 timeouts.ReadTotalTimeoutConstant = TIMEOUT;
722 ok(SetCommTimeouts(hcom, &timeouts),"SetCommTimeouts failed\n");
724 before = GetTickCount();
725 SetLastError(0xdeadbeef);
726 res = ReadFile(hcom, rbuf, sizeof(rbuf), &read, NULL);
727 LastError = GetLastError();
728 after = GetTickCount();
729 ok( res == TRUE, "A timed-out read should return TRUE\n");
730 ok( LastError == 0xdeadbeef, "err=%ld\n", LastError);
731 timediff = after - before;
732 ok( timediff > TIMEOUT>>2 && timediff < TIMEOUT *2,
733 "Unexpected TimeOut %ld, expected %d\n", timediff, TIMEOUT);
736 static void test_waittxempty(HANDLE hcom)
738 DCB dcb;
739 COMMTIMEOUTS timeouts;
740 char tbuf[]="test_waittxempty";
741 DWORD before, after, written, timediff, evtmask = 0;
742 BOOL res_write, res;
743 DWORD baud = SLOWBAUD;
745 trace("test_waittxempty\n");
746 /* set a low baud rate to have ample time*/
747 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
748 dcb.BaudRate = baud;
749 dcb.ByteSize = 8;
750 dcb.Parity = NOPARITY;
751 dcb.fRtsControl=RTS_CONTROL_ENABLE;
752 dcb.fDtrControl=DTR_CONTROL_ENABLE;
753 dcb.StopBits = ONESTOPBIT;
754 ok(SetCommState(hcom, &dcb), "SetCommState failed\n");
756 ZeroMemory( &timeouts, sizeof(timeouts));
757 timeouts.ReadTotalTimeoutConstant = TIMEOUT;
758 ok(SetCommTimeouts(hcom, &timeouts),"SetCommTimeouts failed\n");
760 ok(SetupComm(hcom,1024,1024),"SetUpComm failed\n");
761 ok(SetCommMask(hcom, EV_TXEMPTY), "SetCommMask failed\n");
763 before = GetTickCount();
764 res_write=WriteFile(hcom, tbuf, sizeof(tbuf), &written, NULL);
765 after = GetTickCount();
766 ok(res_write == TRUE, "WriteFile failed\n");
767 ok(written == sizeof(tbuf),
768 "WriteFile: Unexpected write_size %ld\n", written);
770 trace("WriteFile succeeded, took %ld ms to write %ld Bytes at %ld Baud\n",
771 after - before, written, baud);
773 before = GetTickCount();
774 res = WaitCommEvent(hcom, &evtmask, NULL);
775 after = GetTickCount();
777 ok(res == TRUE, "WaitCommEvent failed\n");
778 ok((evtmask & EV_TXEMPTY),
779 "WaitCommEvent: Unexpected EvtMask 0x%08lx, expected 0x%08x\n",
780 evtmask, EV_TXEMPTY);
782 timediff = after - before;
784 trace("WaitCommEvent for EV_TXEMPTY took %ld ms\n", timediff);
785 /* 050604: This shows a difference between XP (tested with mingw compiled crosstest):
786 XP returns Writefile only after everything went out of the Serial port,
787 while wine returns immedate.
788 Thus on XP, WaintCommEvent after setting the CommMask for EV_TXEMPTY
789 nearly return immediate,
790 while on wine the most time is spent here
794 /* A new open handle should not return error or have bytes in the Queues */
795 static void test_ClearCommErrors(HANDLE hcom)
797 DWORD errors;
798 COMSTAT lpStat;
800 ok(ClearCommError(hcom, &errors, &lpStat), "ClearCommError failed\n");
801 ok(lpStat.cbInQue == 0, "Unexpected %ld chars in InQueue\n", lpStat.cbInQue);
802 ok(lpStat.cbOutQue == 0, "Unexpected %ld chars in OutQueue\n", lpStat.cbOutQue);
803 ok(errors == 0, "ClearCommErrors: Unexpected error 0x%08lx\n", errors);
804 trace("test_ClearCommErrors done\n");
807 static void test_non_pending_errors(HANDLE hcom)
809 DCB dcb;
810 DWORD err;
812 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
813 dcb.ByteSize = 255; /* likely bogus */
814 ok(!SetCommState(hcom, &dcb), "SetCommState should have failed\n");
815 ok(ClearCommError(hcom, &err, NULL), "ClearCommError should succeed\n");
816 ok(!(err & CE_MODE), "ClearCommError shouldn't set CE_MODE byte in this case (%lx)\n", err);
819 /**/
820 static void test_LoopbackRead(HANDLE hcom)
822 DCB dcb;
823 COMMTIMEOUTS timeouts;
824 char rbuf[32];
825 DWORD before, after, diff, read, read1, written, evtmask=0, i;
826 BOOL res;
827 char tbuf[]="test_LoopbackRead";
829 trace("Starting test_LoopbackRead\n");
830 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
831 dcb.BaudRate = FASTBAUD;
832 dcb.ByteSize = 8;
833 dcb.Parity = NOPARITY;
834 dcb.fRtsControl=RTS_CONTROL_ENABLE;
835 dcb.fDtrControl=DTR_CONTROL_ENABLE;
836 dcb.StopBits = ONESTOPBIT;
837 ok(SetCommState(hcom, &dcb), "SetCommState failed\n");
839 ZeroMemory( &timeouts, sizeof(timeouts));
840 timeouts.ReadTotalTimeoutConstant = TIMEOUT;
841 ok(SetCommTimeouts(hcom, &timeouts),"SetCommTimeouts failed\n");
843 ok(SetCommMask(hcom, EV_TXEMPTY), "SetCommMask failed\n");
845 before = GetTickCount();
846 ok(WriteFile(hcom,tbuf,sizeof(tbuf),&written, NULL), "WriteFile failed\n");
847 after = GetTickCount();
848 ok(written == sizeof(tbuf),"WriteFile %ld bytes written\n", written);
849 diff = after -before;
851 /* make sure all bytes are written, so Readfile will succeed in one call*/
852 ok(WaitCommEvent(hcom, &evtmask, NULL), "WaitCommEvent failed\n");
853 before = GetTickCount();
854 ok(evtmask == EV_TXEMPTY,
855 "WaitCommEvent: Unexpected EvtMask 0x%08lx, expected 0x%08x\n",
856 evtmask, EV_TXEMPTY);
857 trace("Write %ld ms WaitCommEvent EV_TXEMPTY %ld ms\n", diff, before- after);
859 read=0;
860 ok(ReadFile(hcom, rbuf, sizeof(rbuf), &read, NULL), "Readfile failed\n");
861 ok(read == sizeof(tbuf),"ReadFile read %ld bytes, expected \"%s\"\n", read,rbuf);
863 /* Now do the same withe a slower Baud rate.
864 As we request more characters then written, we will hit the timeout
867 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
868 dcb.BaudRate = 9600;
869 dcb.ByteSize = 8;
870 dcb.Parity = NOPARITY;
871 dcb.fRtsControl=RTS_CONTROL_ENABLE;
872 dcb.fDtrControl=DTR_CONTROL_ENABLE;
873 dcb.StopBits = ONESTOPBIT;
874 ok(SetCommState(hcom, &dcb), "SetCommState failed\n");
876 ok(SetCommMask(hcom, EV_RXCHAR), "SetCommMask failed\n");
877 ok(WriteFile(hcom,tbuf,sizeof(tbuf),&written, NULL), "WriteFile failed\n");
878 ok(written == sizeof(tbuf),"WriteFile %ld bytes written\n", written);
880 trace("WaitCommEventEV_RXCHAR\n");
881 ok(WaitCommEvent(hcom, &evtmask, NULL), "WaitCommEvent failed\n");
882 ok(evtmask == EV_RXCHAR, "WaitCommEvent: Unexpected EvtMask 0x%08lx, expected 0x%08x\n",
883 evtmask, EV_RXCHAR);
885 before = GetTickCount();
886 res = ReadFile(hcom, rbuf, sizeof(rbuf), &read, NULL);
887 after = GetTickCount();
888 ok(res, "Readfile failed\n");
889 ok(read == sizeof(tbuf),"ReadFile read %ld bytes\n", read);
890 diff = after - before;
891 trace("Readfile for %ld chars took %ld ms\n", read, diff);
892 ok( (diff > TIMEOUT - TIMEDELTA) && (diff < TIMEOUT + TIMEDELTA),
893 "Timedout Wait took %ld ms, expected around %d\n", diff, TIMEOUT);
895 /* now do a plain read with slow speed
896 * This will result in several low level reads and a timeout to happen
898 dcb.BaudRate = SLOWBAUD;
899 ok(SetCommState(hcom, &dcb), "SetCommState failed\n");
900 ok(WriteFile(hcom,tbuf,sizeof(tbuf),&written, NULL), "WriteFile failed\n");
901 before = GetTickCount();
902 read = 0;
903 read1 =0;
904 i=0;
907 res = ReadFile(hcom, rbuf+read, sizeof(rbuf-read), &read1, NULL);
908 ok(res, "Readfile failed\n");
909 read += read1;
910 i++;
912 while ((read < sizeof(tbuf)) && (i <10));
913 after = GetTickCount();
914 ok( read == sizeof(tbuf),"ReadFile read %ld bytes\n", read);
915 trace("Plain Read for %ld char at %d baud took %ld ms\n", read, SLOWBAUD, after-before);
918 static void test_LoopbackCtsRts(HANDLE hcom)
920 DWORD ModemStat, defaultStat;
921 DCB dcb;
923 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
924 if (dcb.fRtsControl == RTS_CONTROL_HANDSHAKE)
926 trace("RTS_CONTROL_HANDSHAKE is set, so don't manipulate RTS\n");
927 return;
929 ok(GetCommModemStatus(hcom, &defaultStat), "GetCommModemStatus failed\n");
930 /* XP returns some values in the low nibble, so mask them out*/
931 defaultStat &= MS_CTS_ON|MS_DSR_ON|MS_RING_ON|MS_RLSD_ON;
932 if(defaultStat & MS_CTS_ON)
934 ok(EscapeCommFunction(hcom, CLRRTS), "EscapeCommFunction failed to clear RTS\n");
935 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
936 ok ((ModemStat & MS_CTS_ON) == 0, "CTS didn't react: 0x%04lx, expected 0x%04lx\n",
937 ModemStat, (defaultStat & ~MS_CTS_ON));
938 ok(EscapeCommFunction(hcom, SETRTS), "EscapeCommFunction failed to clear RTS\n");
939 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
940 ok (ModemStat == defaultStat, "Failed to restore CTS: 0x%04lx, expected 0x%04lx\n",
941 ModemStat, defaultStat);
943 else
945 ok(EscapeCommFunction(hcom, SETRTS), "EscapeCommFunction failed to set RTS\n");
946 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
947 ok ((ModemStat & MS_CTS_ON) == MS_CTS_ON,
948 "CTS didn't react: 0x%04lx, expected 0x%04lx\n",
949 ModemStat, (defaultStat | MS_CTS_ON));
950 ok(EscapeCommFunction(hcom, CLRRTS), "EscapeCommFunction failed to clear RTS\n");
951 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
952 ok (ModemStat == defaultStat, "Failed to restore CTS: 0x%04lx, expected 0x%04lx\n",
953 ModemStat, defaultStat);
957 static void test_LoopbackDtrDcd(HANDLE hcom)
959 DWORD ModemStat, defaultStat;
960 DCB dcb;
962 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
963 if (dcb.fDtrControl == DTR_CONTROL_HANDSHAKE)
965 trace("DTR_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
966 return;
968 ok(GetCommModemStatus(hcom, &defaultStat), "GetCommModemStatus failed\n");
969 /* XP returns some values in the low nibble, so mask them out*/
970 defaultStat &= MS_CTS_ON|MS_DSR_ON|MS_RING_ON|MS_RLSD_ON;
971 if(defaultStat & MS_RLSD_ON)
973 ok(EscapeCommFunction(hcom, CLRDTR), "EscapeCommFunction failed to clear DTR\n");
974 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
975 ok ((ModemStat & MS_RLSD_ON) == 0, "RLSD didn't react: 0x%04lx, expected 0x%04lx\n",
976 ModemStat, (defaultStat & ~MS_RLSD_ON));
977 ok(EscapeCommFunction(hcom, SETDTR), "EscapeCommFunction failed to set DTR\n");
978 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
979 ok (ModemStat == defaultStat, "Failed to restore RLSD: 0x%04lx, expected 0x%04lx\n",
980 ModemStat, defaultStat);
982 else
984 ok(EscapeCommFunction(hcom, SETDTR), "EscapeCommFunction failed to set DTR\n");
985 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
986 ok ((ModemStat & MS_RLSD_ON) == MS_RLSD_ON,
987 "RLSD didn't react: 0x%04lx, expected 0x%04lx\n",
988 ModemStat, (defaultStat | MS_RLSD_ON));
989 ok(EscapeCommFunction(hcom, CLRDTR), "EscapeCommFunction failed to clear DTR\n");
990 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
991 ok (ModemStat == defaultStat, "Failed to restore RLSD: 0x%04lx, expected 0x%04lx\n",
992 ModemStat, defaultStat);
996 static void test_LoopbackDtrDsr(HANDLE hcom)
998 DWORD ModemStat, defaultStat;
999 DCB dcb;
1001 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
1002 if (dcb.fDtrControl == DTR_CONTROL_DISABLE)
1004 trace("DTR_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
1005 return;
1007 ok(GetCommModemStatus(hcom, &defaultStat), "GetCommModemStatus failed\n");
1008 /* XP returns some values in the low nibble, so mask them out*/
1009 defaultStat &= MS_CTS_ON|MS_DSR_ON|MS_RING_ON|MS_RLSD_ON;
1010 if(defaultStat & MS_DSR_ON)
1012 ok(EscapeCommFunction(hcom, CLRDTR), "EscapeCommFunction failed to clear DTR\n");
1013 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
1014 ok ((ModemStat & MS_DSR_ON) == 0, "CTS didn't react: 0x%04lx, expected 0x%04lx\n",
1015 ModemStat, (defaultStat & ~MS_DSR_ON));
1016 ok(EscapeCommFunction(hcom, SETDTR), "EscapeCommFunction failed to clear DTR\n");
1017 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
1018 ok (ModemStat == defaultStat, "Failed to restore DSR: 0x%04lx, expected 0x%04lx\n",
1019 ModemStat, defaultStat);
1021 else
1023 ok(EscapeCommFunction(hcom, SETDTR), "EscapeCommFunction failed to set DTR\n");
1024 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
1025 ok ((ModemStat & MS_DSR_ON) == MS_DSR_ON,
1026 "CTS didn't react: 0x%04lx,expected 0x%04lx\n",
1027 ModemStat, (defaultStat | MS_DSR_ON));
1028 ok(EscapeCommFunction(hcom, CLRDTR), "EscapeCommFunction failed to clear DTR\n");
1029 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
1030 ok (ModemStat == defaultStat, "Failed to restore DSR: 0x%04lx, expected 0x%04lx\n",
1031 ModemStat, defaultStat);
1035 static void test_LoopbackDtrRing(HANDLE hcom)
1037 DWORD ModemStat, defaultStat;
1038 DCB dcb;
1040 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
1041 if (dcb.fDtrControl == DTR_CONTROL_HANDSHAKE)
1043 trace("DTR_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
1044 return;
1046 ok(GetCommModemStatus(hcom, &defaultStat), "GetCommModemStatus failed\n");
1047 /* XP returns some values in the low nibble, so mask them out*/
1048 defaultStat &= MS_CTS_ON|MS_DSR_ON|MS_RING_ON|MS_RLSD_ON;
1049 if(defaultStat & MS_RING_ON)
1051 ok(EscapeCommFunction(hcom, CLRDTR), "EscapeCommFunction failed to clear DTR\n");
1052 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
1053 ok ((ModemStat & MS_RING_ON) == 0, "RING didn't react: 0x%04lx, expected 0x%04lx\n",
1054 ModemStat, (defaultStat & ~MS_RING_ON));
1055 ok(EscapeCommFunction(hcom, SETDTR), "EscapeCommFunction failed to set DTR\n");
1056 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
1057 ok (ModemStat == defaultStat, "Failed to restore RING: 0x%04lx, expected 0x%04lx\n",
1058 ModemStat, defaultStat);
1060 else
1062 ok(EscapeCommFunction(hcom, SETDTR), "EscapeCommFunction failed to set DTR\n");
1063 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
1064 ok ((ModemStat & MS_RING_ON) == MS_RING_ON,
1065 "RING didn't react: 0x%04lx,expected 0x%04lx\n",
1066 ModemStat, (defaultStat | MS_RING_ON));
1067 ok(EscapeCommFunction(hcom, CLRDTR), "EscapeCommFunction failed to clear DTR\n");
1068 ok(GetCommModemStatus(hcom, &ModemStat), "GetCommModemStatus failed\n");
1069 ok (ModemStat == defaultStat, "Failed to restore RING: 0x%04lx, expected 0x%04lx\n",
1070 ModemStat, defaultStat);
1075 * Set up a WaitCommEvent for anything in the receive buffer,
1076 * then write to TX to put a character
1077 * into the RX buffer
1078 * Need Loopback TX->RX
1081 static void test_WaitRx(HANDLE hcom)
1083 OVERLAPPED overlapped, overlapped_w;
1084 HANDLE hComPortEvent, hComWriteEvent;
1085 DWORD before, after, after1, diff, success_wait = FALSE, success_write;
1086 DWORD err_wait, err_write, written, evtmask=0;
1088 ok(SetCommMask(hcom, EV_RXCHAR), "SetCommMask failed\n");
1089 hComPortEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
1090 ok(hComPortEvent != 0, "CreateEvent failed\n");
1091 ZeroMemory( &overlapped, sizeof(overlapped));
1092 overlapped.hEvent = hComPortEvent;
1094 ok((hComWriteEvent = CreateEvent( NULL, TRUE, FALSE, NULL )) !=0,
1095 "CreateEvent res 0x%08lx\n",
1096 GetLastError());
1097 ZeroMemory( &overlapped_w, sizeof(overlapped_w));
1098 overlapped_w.hEvent = hComWriteEvent;
1100 before = GetTickCount();
1101 {success_wait = WaitCommEvent(hcom, &evtmask, &overlapped);}
1102 err_wait = GetLastError();
1103 after = GetTickCount();
1104 trace("Success 0x%08lx err 0x%08lx evtmask 0x%08lx\n", success_wait, err_wait, evtmask);
1105 ok(success_wait || err_wait == ERROR_IO_PENDING, "overlapped WaitCommEvent failed\n");
1106 trace("overlapped WriteCommEvent returned.\n");
1108 success_write= WriteFile(hcom, "X", 1, &written, &overlapped_w);
1109 err_write = GetLastError();
1110 ok(success_write || err_write == ERROR_IO_PENDING,
1111 "overlapped WriteFile failed, err 0x%08lx\n",
1112 err_write);
1114 if (!success_write && (err_write == ERROR_IO_PENDING)) {
1115 success_write = WaitForSingleObjectEx(hComWriteEvent, TIMEOUT, TRUE);
1116 err_write = GetLastError();
1117 ok(success_write == WAIT_OBJECT_0, "WaitForSingleObjectEx, res 0x%08lx, err 0x%08lx\n",
1118 success_write, err_write);
1120 Sleep(TIMEOUT >>1);
1121 success_write = GetOverlappedResult(hcom, &overlapped_w, &written, FALSE);
1122 err_write = GetLastError();
1124 trace("Write after Wait res 0x%08lx err 0x%08lx\n",success_write, err_write);
1125 ok(success_write && written ==1, "Write after Wait res 0x%08lx err 0x%08lx\n",
1126 success_write, err_write);
1128 if (!success_wait && (err_wait == ERROR_IO_PENDING)) {
1129 success_wait = WaitForSingleObjectEx(hComPortEvent, TIMEOUT, TRUE);
1130 err_wait = GetLastError();
1131 ok(success_wait == WAIT_OBJECT_0, "wait hComPortEvent, res 0x%08lx, err 0x%08lx\n",
1132 success_wait, err_wait);
1134 success_wait = GetOverlappedResult(hcom, &overlapped, &written, FALSE);
1135 err_wait = GetLastError();
1136 after1 = GetTickCount();
1137 trace("Success 0x%08lx err 0x%08lx evtmask 0x%08lx diff1 %ld, diff2 %ld\n",
1138 success_wait, err_wait, evtmask, after-before, after1-before);
1140 ok(evtmask & EV_RXCHAR, "Detect EV_RXCHAR: 0x%08lx, expected 0x%08x\n",
1141 evtmask, EV_RXCHAR);
1142 diff = after1 - before;
1143 ok ((diff > (TIMEOUT>>1) -TIMEDELTA) && (diff < (TIMEOUT>>1) + TIMEDELTA),
1144 "Unexpected time %ld, expected around %d\n", diff, TIMEOUT>>1);
1148 /* Change the controling line after the given timeout to the given state
1149 By the loopback, this should trigger the WaitCommEvent
1151 static DWORD CALLBACK toggle_ctlLine(LPVOID arg)
1153 DWORD *args = (DWORD *) arg;
1154 DWORD timeout = args[0];
1155 DWORD ctl = args[1];
1156 HANDLE hcom = (HANDLE) args[2];
1157 HANDLE hComPortEvent = (HANDLE) args[3];
1158 DWORD success, err;
1160 trace("toggle_ctlLine timeout %ld clt 0x%08lx handle 0x%08lx\n",
1161 args[0], args[1], args[2]);
1162 Sleep(timeout);
1163 ok(EscapeCommFunction(hcom, ctl),"EscapeCommFunction 0x%08lx failed\n", ctl);
1164 trace("toggle_ctline done\n");
1165 success = WaitForSingleObjectEx(hComPortEvent, TIMEOUT, TRUE);
1166 err = GetLastError();
1167 trace("toggle_ctline WaitForSingleObjectEx res 0x%08lx err 0x%08lx\n",
1168 success, err);
1169 return 0;
1173 * Wait for a change in CTS
1174 * Needs Loopback from DTR to CTS
1176 static void test_WaitCts(HANDLE hcom)
1178 DCB dcb;
1179 OVERLAPPED overlapped;
1180 HANDLE hComPortEvent;
1181 HANDLE alarmThread;
1182 DWORD args[4], defaultStat;
1183 DWORD alarmThreadId, before, after, after1, diff, success, err, written, evtmask=0;
1185 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
1186 dcb.fRtsControl=RTS_CONTROL_ENABLE;
1187 dcb.fDtrControl=DTR_CONTROL_ENABLE;
1188 ok(SetCommState(hcom, &dcb), "SetCommState failed\n");
1189 if (dcb.fDtrControl == RTS_CONTROL_DISABLE)
1191 trace("RTS_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
1192 return;
1194 args[0]= TIMEOUT >>1;
1195 ok(GetCommModemStatus(hcom, &defaultStat), "GetCommModemStatus failed\n");
1196 if(defaultStat & MS_CTS_ON)
1197 args[1] = CLRRTS;
1198 else
1199 args[1] = SETRTS;
1200 args[2]=(DWORD) hcom;
1202 trace("test_WaitCts timeout %ld clt 0x%08lx handle 0x%08lx\n",args[0], args[1], args[2]);
1204 ok(SetCommMask(hcom, EV_CTS), "SetCommMask failed\n");
1205 hComPortEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
1206 ok(hComPortEvent != 0, "CreateEvent failed\n");
1207 args[3] = (DWORD) hComPortEvent;
1208 alarmThread = CreateThread(NULL, 0, toggle_ctlLine, (void *) &args, 0, &alarmThreadId);
1209 /* Wait a minimum to let the thread start up */
1210 Sleep(10);
1211 trace("Thread created\n");
1212 ok(alarmThread !=0 , "CreateThread Failed\n");
1214 ZeroMemory( &overlapped, sizeof(overlapped));
1215 overlapped.hEvent = hComPortEvent;
1216 before = GetTickCount();
1217 success = WaitCommEvent(hcom, &evtmask, &overlapped);
1218 err = GetLastError();
1219 after = GetTickCount();
1221 trace("Success 0x%08lx err 0x%08lx evtmask 0x%08lx\n", success, err, evtmask);
1222 ok(success || err == ERROR_IO_PENDING, "overlapped WaitCommEvent failed\n");
1223 trace("overlapped WriteCommEvent returned.\n");
1224 if (!success && (err == ERROR_IO_PENDING))
1225 ok(WaitForSingleObjectEx(hComPortEvent, TIMEOUT, TRUE) == 0,
1226 "WaitCts hComPortEvent failed\n");
1227 success = GetOverlappedResult(hcom, &overlapped, &written, FALSE);
1228 err = GetLastError();
1229 after1 = GetTickCount();
1230 trace("Success 0x%08lx err 0x%08lx evtmask 0x%08lx diff1 %ld, diff2 %ld\n",
1231 success, err, evtmask, after-before, after1-before);
1233 ok(evtmask & EV_CTS, "Failed to detect EV_CTS: 0x%08lx, expected 0x%08x\n",
1234 evtmask, EV_CTS);
1235 ok(GetCommModemStatus(hcom, &evtmask), "GetCommModemStatus failed\n");
1236 if(defaultStat & MS_CTS_ON)
1237 ok((evtmask & MS_CTS_ON) == 0,"CTS didn't change state!\n");
1238 else
1239 ok((evtmask & MS_CTS_ON), "CTS didn't change state!\n");
1241 diff = after1 - before;
1242 ok ((diff > (TIMEOUT>>1) -TIMEDELTA) && (diff < (TIMEOUT>>1) + TIMEDELTA),
1243 "Unexpected time %ld, expected around %d\n", diff, TIMEOUT>>1);
1245 /*restore RTS Settings*/
1246 if(defaultStat & MS_CTS_ON)
1247 args[1] = SETRTS;
1248 else
1249 args[1] = CLRRTS;
1252 /* Change the Comm Mask while a Wait is going on
1253 WaitCommevent should return with a EVTMASK set to zero
1255 static DWORD CALLBACK reset_CommMask(LPVOID arg)
1257 DWORD *args = (DWORD *) arg;
1258 DWORD timeout = args[0];
1259 HANDLE hcom = (HANDLE) args[1];
1261 trace(" Changing CommMask on the fly for handle %p after timeout %ld\n",
1262 hcom, timeout);
1263 Sleep(timeout);
1264 ok(SetCommMask(hcom, 0),"SetCommMask %p failed\n", hcom);
1265 trace("SetCommMask changed\n");
1266 return 0;
1269 /* Set up a Wait for a change on CTS. We don't toggle any line, but we
1270 reset the CommMask and expect the wait to return with a mask of 0
1271 No special port connections needed
1273 static void test_AbortWaitCts(HANDLE hcom)
1275 DCB dcb;
1276 OVERLAPPED overlapped;
1277 HANDLE hComPortEvent;
1278 HANDLE alarmThread;
1279 DWORD args[2];
1280 DWORD alarmThreadId, before, after, after1, diff, success, err, written, evtmask=0;
1282 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
1283 if (dcb.fDtrControl == RTS_CONTROL_DISABLE)
1285 trace("RTS_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
1286 return;
1288 args[0]= TIMEOUT >>1;
1289 args[1]=(DWORD) hcom;
1291 trace("test_AbortWaitCts timeout %ld handle 0x%08lx\n",args[0], args[1]);
1293 ok(SetCommMask(hcom, EV_CTS), "SetCommMask failed\n");
1294 hComPortEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
1295 ok(hComPortEvent != 0, "CreateEvent failed\n");
1296 alarmThread = CreateThread(NULL, 0, reset_CommMask, (void *) &args, 0, &alarmThreadId);
1297 /* Wait a minimum to let the thread start up */
1298 Sleep(10);
1299 trace("Thread created\n");
1300 ok(alarmThread !=0 , "CreateThread Failed\n");
1302 ZeroMemory( &overlapped, sizeof(overlapped));
1303 overlapped.hEvent = hComPortEvent;
1304 before = GetTickCount();
1305 success = WaitCommEvent(hcom, &evtmask, &overlapped);
1306 err = GetLastError();
1307 after = GetTickCount();
1309 trace("Success 0x%08lx err 0x%08lx evtmask 0x%08lx\n", success, err, evtmask);
1310 ok(success || err == ERROR_IO_PENDING, "overlapped WaitCommEvent failed\n");
1311 trace("overlapped WriteCommEvent returned.\n");
1312 if (!success && (err == ERROR_IO_PENDING))
1313 ok(WaitForSingleObjectEx(hComPortEvent, TIMEOUT, TRUE) == 0,
1314 "AbortWaitCts hComPortEvent failed\n");
1315 success = GetOverlappedResult(hcom, &overlapped, &written, FALSE);
1316 err = GetLastError();
1317 after1 = GetTickCount();
1318 trace("Success 0x%08lx err 0x%08lx evtmask 0x%08lx diff1 %ld, diff2 %ld\n",
1319 success, err, evtmask, after-before, after1-before);
1321 ok(evtmask == 0, "Incorect EventMask 0x%08lx returned on Wait aborted bu SetCommMask, expected 0x%08x\n",
1322 evtmask, 0);
1323 ok(GetCommModemStatus(hcom, &evtmask), "GetCommModemStatus failed\n");
1324 diff = after1 - before;
1325 ok ((diff > (TIMEOUT>>1) -TIMEDELTA) && (diff < (TIMEOUT>>1) + TIMEDELTA),
1326 "Unexpected time %ld, expected around %d\n", diff, TIMEOUT>>1);
1331 * Wait for a change in DSR
1332 * Needs Loopback from DTR to DSR
1334 static void test_WaitDsr(HANDLE hcom)
1336 DCB dcb;
1337 OVERLAPPED overlapped;
1338 HANDLE hComPortEvent;
1339 HANDLE alarmThread;
1340 DWORD args[3], defaultStat;
1341 DWORD alarmThreadId, before, after, after1, diff, success, err, written, evtmask=0;
1343 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
1344 if (dcb.fDtrControl == DTR_CONTROL_DISABLE)
1346 trace("DTR_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
1347 return;
1349 args[0]= TIMEOUT >>1;
1350 ok(GetCommModemStatus(hcom, &defaultStat), "GetCommModemStatus failed\n");
1351 if(defaultStat & MS_DSR_ON)
1352 args[1] = CLRDTR;
1353 else
1354 args[1] = SETDTR;
1355 args[2]=(DWORD) hcom;
1357 trace("test_WaitDsr timeout %ld clt 0x%08lx handle 0x%08lx\n",args[0], args[1], args[2]);
1359 ok(SetCommMask(hcom, EV_DSR), "SetCommMask failed\n");
1360 hComPortEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
1361 ok(hComPortEvent != 0, "CreateEvent failed\n");
1362 alarmThread = CreateThread(NULL, 0, toggle_ctlLine, (void *) &args, 0, &alarmThreadId);
1363 ok(alarmThread !=0 , "CreateThread Failed\n");
1365 ZeroMemory( &overlapped, sizeof(overlapped));
1366 overlapped.hEvent = hComPortEvent;
1367 before = GetTickCount();
1368 success = WaitCommEvent(hcom, &evtmask, &overlapped);
1369 err = GetLastError();
1370 after = GetTickCount();
1372 trace("Success 0x%08lx err 0x%08lx evtmask 0x%08lx\n", success, err, evtmask);
1373 ok(success || err == ERROR_IO_PENDING, "overlapped WaitCommEvent failed\n");
1374 trace("overlapped WriteCommEvent returned.\n");
1375 if (!success && (err == ERROR_IO_PENDING))
1376 ok(WaitForSingleObjectEx(hComPortEvent, TIMEOUT, TRUE) == 0,
1377 "wait hComPortEvent failed\n");
1378 success = GetOverlappedResult(hcom, &overlapped, &written, FALSE);
1379 err = GetLastError();
1380 after1 = GetTickCount();
1381 trace("Success 0x%08lx err 0x%08lx evtmask 0x%08lx diff1 %ld, diff2 %ld\n",
1382 success, err, evtmask, after-before, after1-before);
1384 ok(evtmask & EV_DSR, "Failed to detect EV_DSR: 0x%08lx, expected 0x%08x\n",
1385 evtmask, EV_DSR);
1386 ok(GetCommModemStatus(hcom, &evtmask), "GetCommModemStatus failed\n");
1387 if(defaultStat & MS_DSR_ON)
1388 ok((evtmask & MS_DSR_ON) == 0,"DTR didn't change state!\n");
1389 else
1390 ok((evtmask & MS_DSR_ON), "DTR didn't change state!\n");
1392 diff = after1 - before;
1393 ok ((diff > (TIMEOUT>>1) -TIMEDELTA) && (diff < (TIMEOUT>>1) + TIMEDELTA),
1394 "Unexpected time %ld, expected around %d\n", diff, TIMEOUT>>1);
1396 /*restore RTS Settings*/
1397 if(defaultStat & MS_DSR_ON)
1398 args[1] = SETDTR;
1399 else
1400 args[1] = CLRDTR;
1404 * Wait for a Ring
1405 * Needs Loopback from DTR to RING
1407 static void test_WaitRing(HANDLE hcom)
1409 DCB dcb;
1410 OVERLAPPED overlapped;
1411 HANDLE hComPortEvent;
1412 HANDLE alarmThread;
1413 DWORD args[3], defaultStat;
1414 DWORD alarmThreadId, before, after, after1, diff, success, err, written, evtmask=0;
1416 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
1417 if (dcb.fDtrControl == DTR_CONTROL_DISABLE)
1419 trace("DTR_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
1420 return;
1422 args[0]= TIMEOUT >>1;
1423 ok(GetCommModemStatus(hcom, &defaultStat), "GetCommModemStatus failed\n");
1424 if(defaultStat & MS_RING_ON)
1425 args[1] = CLRDTR;
1426 else
1427 args[1] = SETDTR;
1428 args[2]=(DWORD) hcom;
1430 trace("test_WaitRing timeout %ld clt 0x%08lx handle 0x%08lx\n",args[0], args[1], args[2]);
1432 ok(SetCommMask(hcom, EV_RING), "SetCommMask failed\n");
1433 hComPortEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
1434 ok(hComPortEvent != 0, "CreateEvent failed\n");
1435 alarmThread = CreateThread(NULL, 0, toggle_ctlLine, (void *) &args, 0, &alarmThreadId);
1436 ok(alarmThread !=0 , "CreateThread Failed\n");
1438 ZeroMemory( &overlapped, sizeof(overlapped));
1439 overlapped.hEvent = hComPortEvent;
1440 before = GetTickCount();
1441 success = WaitCommEvent(hcom, &evtmask, &overlapped);
1442 err = GetLastError();
1443 after = GetTickCount();
1445 trace("Success 0x%08lx err 0x%08lx evtmask 0x%08lx\n", success, err, evtmask);
1446 ok(success || err == ERROR_IO_PENDING, "overlapped WaitCommEvent failed\n");
1447 trace("overlapped WriteCommEvent returned.\n");
1448 if (!success && (err == ERROR_IO_PENDING))
1449 ok(WaitForSingleObjectEx(hComPortEvent, TIMEOUT, TRUE) == 0,
1450 "wait hComPortEvent failed\n");
1451 success = GetOverlappedResult(hcom, &overlapped, &written, FALSE);
1452 err = GetLastError();
1453 after1 = GetTickCount();
1454 trace("Success 0x%08lx err 0x%08lx evtmask 0x%08lx diff1 %ld, diff2 %ld\n",
1455 success, err, evtmask, after-before, after1-before);
1457 ok(evtmask & EV_RING, "Failed to detect EV_RING: 0x%08lx, expected 0x%08x\n",
1458 evtmask, EV_CTS);
1459 ok(GetCommModemStatus(hcom, &evtmask), "GetCommModemStatus failed\n");
1460 if(defaultStat & MS_RING_ON)
1461 ok((evtmask & MS_RING_ON) == 0,"DTR didn't change state!\n");
1462 else
1463 ok((evtmask & MS_RING_ON), "DTR didn't change state!\n");
1465 diff = after1 - before;
1466 ok ((diff > (TIMEOUT>>1) -TIMEDELTA) && (diff < (TIMEOUT>>1) + TIMEDELTA),
1467 "Unexpected time %ld, expected around %d\n", diff, TIMEOUT>>1);
1469 /*restore RTS Settings*/
1470 if(defaultStat & MS_RING_ON)
1471 args[1] = SETDTR;
1472 else
1473 args[1] = CLRDTR;
1476 * Wait for a change in DCD
1477 * Needs Loopback from DTR to DCD
1479 static void test_WaitDcd(HANDLE hcom)
1481 DCB dcb;
1482 OVERLAPPED overlapped;
1483 HANDLE hComPortEvent;
1484 HANDLE alarmThread;
1485 DWORD args[3], defaultStat;
1486 DWORD alarmThreadId, before, after, after1, diff, success, err, written, evtmask=0;
1488 ok(GetCommState(hcom, &dcb), "GetCommState failed\n");
1489 if (dcb.fDtrControl == DTR_CONTROL_DISABLE)
1491 trace("DTR_CONTROL_HANDSHAKE is set, so don't manipulate DTR\n");
1492 return;
1494 args[0]= TIMEOUT >>1;
1495 ok(GetCommModemStatus(hcom, &defaultStat), "GetCommModemStatus failed\n");
1496 if(defaultStat & MS_RLSD_ON)
1497 args[1] = CLRDTR;
1498 else
1499 args[1] = SETDTR;
1500 args[2]=(DWORD) hcom;
1502 trace("test_WaitDcd timeout %ld clt 0x%08lx handle 0x%08lx\n",args[0], args[1], args[2]);
1504 ok(SetCommMask(hcom, EV_RLSD), "SetCommMask failed\n");
1505 hComPortEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
1506 ok(hComPortEvent != 0, "CreateEvent failed\n");
1507 alarmThread = CreateThread(NULL, 0, toggle_ctlLine, (void *) &args, 0, &alarmThreadId);
1508 ok(alarmThread !=0 , "CreateThread Failed\n");
1510 ZeroMemory( &overlapped, sizeof(overlapped));
1511 overlapped.hEvent = hComPortEvent;
1512 before = GetTickCount();
1513 success = WaitCommEvent(hcom, &evtmask, &overlapped);
1514 err = GetLastError();
1515 after = GetTickCount();
1517 trace("Success 0x%08lx err 0x%08lx evtmask 0x%08lx\n", success, err, evtmask);
1518 ok(success || err == ERROR_IO_PENDING, "overlapped WaitCommEvent failed\n");
1519 trace("overlapped WriteCommEvent returned.\n");
1520 if (!success && (err == ERROR_IO_PENDING))
1521 ok(WaitForSingleObjectEx(hComPortEvent, TIMEOUT, TRUE) == 0,
1522 "wait hComPortEvent failed\n");
1523 success = GetOverlappedResult(hcom, &overlapped, &written, FALSE);
1524 err = GetLastError();
1525 after1 = GetTickCount();
1526 trace("Success 0x%08lx err 0x%08lx evtmask 0x%08lx diff1 %ld, diff2 %ld\n",
1527 success, err, evtmask, after-before, after1-before);
1529 ok(evtmask & EV_RLSD, "Failed to detect EV_RLSD: 0x%08lx, expected 0x%08x\n",
1530 evtmask, EV_CTS);
1531 ok(GetCommModemStatus(hcom, &evtmask), "GetCommModemStatus failed\n");
1532 if(defaultStat & MS_RLSD_ON)
1533 ok((evtmask & MS_RLSD_ON) == 0,"DTR didn't change state!\n");
1534 else
1535 ok((evtmask & MS_RLSD_ON), "DTR didn't change state!\n");
1537 diff = after1 - before;
1538 ok ((diff > (TIMEOUT>>1) -TIMEDELTA) && (diff < (TIMEOUT>>1) + TIMEDELTA),
1539 "Unexpected time %ld, expected around %d\n", diff, TIMEOUT>>1);
1541 /*restore RTS Settings*/
1542 if(defaultStat & MS_RLSD_ON)
1543 args[1] = SETDTR;
1544 else
1545 args[1] = CLRDTR;
1549 Set Break after timeout
1551 static DWORD CALLBACK set_CommBreak(LPVOID arg)
1553 DWORD *args = (DWORD *) arg;
1554 DWORD timeout = args[0];
1555 HANDLE hcom = (HANDLE) args[1];
1557 trace("SetCommBreak for handle %p after timeout %ld\n",
1558 hcom, timeout);
1559 Sleep(timeout);
1560 ok(SetCommBreak(hcom),"SetCommBreak %p failed\n", hcom);
1561 trace("SetCommBreak done\n");
1562 return 0;
1566 Wait for the Break condition (TX resp. RX active)
1567 Needs Loopback TX-RX
1569 static void test_WaitBreak(HANDLE hcom)
1571 OVERLAPPED overlapped;
1572 HANDLE hComPortEvent;
1573 HANDLE alarmThread;
1574 DWORD args[2];
1575 DWORD alarmThreadId, before, after, after1, diff, success, err, written, evtmask=0;
1577 ok(SetCommMask(hcom, EV_BREAK), "SetCommMask failed\n");
1578 hComPortEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
1579 ok(hComPortEvent != 0, "CreateEvent failed\n");
1581 trace("test_WaitBreak\n");
1582 args[0]= TIMEOUT >>1;
1583 args[1]=(DWORD) hcom;
1584 alarmThread = CreateThread(NULL, 0, set_CommBreak, (void *) &args, 0, &alarmThreadId);
1585 /* Wait a minimum to let the thread start up */
1586 Sleep(10);
1587 trace("Thread created\n");
1588 ok(alarmThread !=0 , "CreateThread Failed\n");
1590 ZeroMemory( &overlapped, sizeof(overlapped));
1591 overlapped.hEvent = hComPortEvent;
1592 before = GetTickCount();
1593 success = WaitCommEvent(hcom, &evtmask, &overlapped);
1594 err = GetLastError();
1595 after = GetTickCount();
1597 trace("Success 0x%08lx err 0x%08lx evtmask 0x%08lx\n", success, err, evtmask);
1598 ok(success || err == ERROR_IO_PENDING, "overlapped WaitCommEvent failed\n");
1599 trace("overlapped WriteCommEvent returned.\n");
1601 if (!success && (err == ERROR_IO_PENDING))
1602 ok(WaitForSingleObjectEx(hComPortEvent, TIMEOUT, TRUE) == 0,
1603 "wait hComPortEvent res 0x%08lx\n", GetLastError());
1604 success = GetOverlappedResult(hcom, &overlapped, &written, FALSE);
1605 err = GetLastError();
1606 after1 = GetTickCount();
1607 trace("Success 0x%08lx err 0x%08lx evtmask 0x%08lx diff1 %ld, diff2 %ld\n",
1608 success, err, evtmask, after-before, after1-before);
1610 ok(evtmask & EV_BREAK, "Failed to detect EV_BREAK: 0x%08lx, expected 0x%08x\n",
1611 evtmask, EV_BREAK);
1612 ok(GetCommModemStatus(hcom, &evtmask), "GetCommModemStatus failed\n");
1614 diff = after1 - before;
1615 ok ((diff > (TIMEOUT>>1) -TIMEDELTA) && (diff < (TIMEOUT>>1) + TIMEDELTA),
1616 "Unexpected time %ld, expected around %d\n", diff, TIMEOUT>>1);
1618 ok(ClearCommBreak(hcom), "ClearCommBreak failed\n");
1621 START_TEST(comm)
1623 HANDLE hcom;
1624 /* use variables and not #define to compile the code */
1625 BOOL loopback_txd_rxd = LOOPBACK_TXD_RXD;
1626 BOOL loopback_rts_cts = LOOPBACK_CTS_RTS;
1627 BOOL loopback_dtr_dsr = LOOPBACK_DTR_DSR;
1628 BOOL loopback_dtr_ring = LOOPBACK_DTR_RING;
1629 BOOL loopback_dtr_dcd = LOOPBACK_DTR_DCD;
1631 test_BuildCommDCB();
1632 hcom = test_OpenComm(FALSE);
1633 if (hcom != INVALID_HANDLE_VALUE)
1635 test_GetModemStatus(hcom);
1636 test_ReadTimeOut(hcom);
1637 test_waittxempty(hcom);
1638 CloseHandle(hcom);
1640 hcom = test_OpenComm(FALSE);
1641 if (hcom != INVALID_HANDLE_VALUE)
1643 Sleep(200); /* Give the laster character of test_waittxempty to drop into the receiver */
1644 test_ClearCommErrors(hcom);
1645 CloseHandle(hcom);
1647 hcom = test_OpenComm(FALSE);
1648 if (hcom != INVALID_HANDLE_VALUE)
1650 test_non_pending_errors(hcom);
1651 CloseHandle(hcom);
1653 if((loopback_txd_rxd) && ((hcom = test_OpenComm(FALSE))!=INVALID_HANDLE_VALUE))
1655 test_LoopbackRead(hcom);
1656 CloseHandle(hcom);
1658 if((loopback_rts_cts) && ((hcom = test_OpenComm(FALSE))!=INVALID_HANDLE_VALUE))
1660 test_LoopbackCtsRts(hcom);
1661 CloseHandle(hcom);
1663 if((loopback_dtr_dsr) && ((hcom = test_OpenComm(FALSE))!=INVALID_HANDLE_VALUE))
1665 test_LoopbackDtrDsr(hcom);
1666 CloseHandle(hcom);
1668 if((loopback_dtr_ring) && ((hcom = test_OpenComm(FALSE))!=INVALID_HANDLE_VALUE))
1670 test_LoopbackDtrRing(hcom);
1671 CloseHandle(hcom);
1673 if((loopback_dtr_dcd) && ((hcom = test_OpenComm(FALSE))!=INVALID_HANDLE_VALUE))
1675 test_LoopbackDtrDcd(hcom);
1676 CloseHandle(hcom);
1678 if((loopback_txd_rxd) && ((hcom = test_OpenComm(TRUE))!=INVALID_HANDLE_VALUE))
1680 test_WaitRx(hcom);
1681 CloseHandle(hcom);
1683 if((loopback_rts_cts) && ((hcom = test_OpenComm(TRUE))!=INVALID_HANDLE_VALUE))
1685 test_WaitCts(hcom);
1686 CloseHandle(hcom);
1688 if((hcom = test_OpenComm(TRUE))!=INVALID_HANDLE_VALUE)
1690 test_AbortWaitCts(hcom);
1691 CloseHandle(hcom);
1693 if((loopback_dtr_dsr) && ((hcom = test_OpenComm(TRUE))!=INVALID_HANDLE_VALUE))
1695 test_WaitDsr(hcom);
1696 CloseHandle(hcom);
1698 if((loopback_dtr_ring) && ((hcom = test_OpenComm(TRUE))!=INVALID_HANDLE_VALUE))
1700 test_WaitRing(hcom);
1701 CloseHandle(hcom);
1703 if((loopback_dtr_dcd) && ((hcom = test_OpenComm(TRUE))!=INVALID_HANDLE_VALUE))
1705 test_WaitDcd(hcom);
1706 CloseHandle(hcom);
1708 if(loopback_txd_rxd && (hcom = test_OpenComm(TRUE))!=INVALID_HANDLE_VALUE)
1710 test_WaitBreak(hcom);
1711 CloseHandle(hcom);