OSDN Git Service

Correct a typographic error; fix MinGW-Bug #39193
[mingw/mingw-org-wsl.git] / w32api / tests / winsock.at
1 # winsock.at
2 #
3 # Autotest module to verify correct operation of various aspects
4 # of the Windows Sockets API.
5 #
6 #
7 # $Id$
8 #
9 # Written by Keith Marshall <keithmarshall@users.sourceforge.net>
10 # Copyright (C) 2017, MinGW.org Project
11 #
12 #
13 # Permission is hereby granted, free of charge, to any person obtaining a
14 # copy of this software and associated documentation files (the "Software"),
15 # to deal in the Software without restriction, including without limitation
16 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 # and/or sell copies of the Software, and to permit persons to whom the
18 # Software is furnished to do so, subject to the following conditions:
19 #
20 # The above copyright notice and this permission notice (including the next
21 # paragraph) shall be included in all copies or substantial portions of the
22 # Software.
23 #
24 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 # AUTHORS OR THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 # DEALINGS IN THE SOFTWARE.
31 #
32 #
33 # All tests specified herein are written in the C language.
34 #
35 MINGW_AT_LANG([C])
36
37 # MINGW_AT_INITIALIZE_FD_SET( NAME, FDLIST )
38 # ------------------------------------------
39 # Emit C source code to instantiate an fd_set entity called NAME,
40 # and populate it with the list of fd numbers specified by FDLIST;
41 # note that this permits assignment of duplicate fd entries within
42 # the fd_set population, contrary to correct operational practice.
43 #
44 m4_define([MINGW_AT_INITIALIZE_FD_SET],[dnl
45 [fd_set $1 = { m4_count($2), { $2 }}]dnl
46 ])
47
48 # MINGW_AT_CHECK_FD_MACRO( HEADER, MACRO, DESCRIPTION, EXPOUT, BODY )
49 # -------------------------------------------------------------------
50 # Construct a test group to verify the behaviour of MACRO, when compiled
51 # with inclusion of <HEADER.h>, under conditions per DESCRIPTION; confirm
52 # that execution of a main function, with specified BODY, produces output
53 # as specified by EXPOUT, on the standard output stream.
54 #
55 m4_define([MINGW_AT_CHECK_FD_MACRO],[dnl
56 AT_SETUP([$2 $3])AT_KEYWORDS([C $1 fd_set $2])dnl
57 MINGW_AT_DATA_CRLF([expout],[$4
58 ])MINGW_AT_CHECK_RUN([[[
59 #include <stdio.h>
60 #include <$1.h>
61
62 static void show_fd_set( fd_set *set )
63 {
64   unsigned int i = 0;
65   printf( "%d entries%c", set->fd_count, set->fd_count ? ':' : '\n' );
66   while( i < set->fd_count )
67   { int k = set->fd_array[i++];
68     printf( " %d%c", k, (i < set->fd_count) ? ',' : '\n' );
69   }
70 }
71
72 int main()
73 ]]$5],,[expout])dnl
74 AT_CLEANUP])
75
76 # MINGW_AT_CHECK_FD_ISSET_MACRO( HEADER, FD )
77 # -------------------------------------------
78 # Construct a test group to verify that descriptor FD is, or is not,
79 # present within the predefined (and degenerate) fd_set {1, 2, 2, 3},
80 # using the FD_ISSET macro as it is defined by <HEADER.h>
81 #
82 m4_define([MINGW_AT_CHECK_FD_ISSET_MACRO],[dnl
83 AT_SETUP([FD_ISSET does ]m4_case(m4_sign([$2-3]),[1],dnl
84 [not detect excluded],[detect included])[ descriptor])dnl
85 AT_KEYWORDS([C $1 fd_set FD_ISSET])MINGW_AT_CHECK_RUN([[
86 #include <$1.h>
87 int main()]
88 { MINGW_AT_INITIALIZE_FD_SET([at_set],[1, 2, 2, 3])[;
89   return FD_ISSET($2, &at_set) ? (($2 > 3) ? 1 : 0) : (($2 > 3) ? 0 : 1);
90 }]])
91 AT_CLEANUP])
92
93 # MINGW_AT_CHECK_WINSOCK( VERSION, HEADER )
94 # -----------------------------------------
95 # Run a sequence of checks for WinSock VERSION, compiling with
96 # inclusion of <HEADER.h>
97 #
98 m4_define([MINGW_AT_CHECK_WINSOCK],[dnl
99 AT_BANNER([Windows Sockets $1 fd_set macro checks.])
100 MINGW_AT_LINK_LIBS([m4_case([$1],[v2],[-lws2_32],[-lwsock32])])
101
102 # Verify that the FD_ZERO macro clears all descriptors from the
103 # predefined, non-empty fd_set {1, 2, 3, 4}
104 #
105 MINGW_AT_CHECK_FD_MACRO([$2],[FD_ZERO],dnl
106 [removes all descriptors],[0 entries],[
107 { MINGW_AT_INITIALIZE_FD_SET([at_set],[1, 2, 3, 4])[;
108   FD_ZERO (&at_set); show_fd_set (&at_set);
109   return 0;
110 }]])
111
112 # Verify that the FD_SET macro will successfully add descriptor 6
113 # to the predefined fd_set {1, 2, 3, 4}, given that it is not yet
114 # a member of that set.
115 #
116 MINGW_AT_CHECK_FD_MACRO([$2],[FD_SET],dnl
117 [adds one unique descriptor],[5 entries: 1, 2, 3, 4, 6],[
118 { MINGW_AT_INITIALIZE_FD_SET([at_set],[1, 2, 3, 4])[;
119   FD_SET (6, &at_set); show_fd_set (&at_set);
120   return 0;
121 }]])
122
123 # Verify that the FD_SET macro will NOT add a second instance of
124 # descriptor 2 to the predefined fd_set {1, 2, 3, 4}, given that
125 # it is already a member of that set.
126 #
127 MINGW_AT_CHECK_FD_MACRO([$2],[FD_SET],dnl
128 [does not add duplicate descriptors],[4 entries: 1, 2, 3, 4],[
129 { MINGW_AT_INITIALIZE_FD_SET([at_set],[1, 2, 3, 4])[;
130   FD_SET (2, &at_set); show_fd_set (&at_set);
131   return 0;
132 }]])
133
134 # Verify that the FD_CLR macro successfully removes a solitary
135 # instance of descriptor 2 from well-formed fd_set {1, 2, 3, 4}
136 #
137 MINGW_AT_CHECK_FD_MACRO([$2],[FD_CLR],dnl
138 [removes a uniquely matched descriptor],[3 entries: 1, 3, 4],[
139 { MINGW_AT_INITIALIZE_FD_SET([at_set],[1, 2, 3, 4])[;
140   FD_CLR (2, &at_set); show_fd_set (&at_set);
141   return 0;
142 }]])
143
144 # Verify that the FD_CLR macro correcly removes ALL instances
145 # of descriptor 2 from malformed fd_set {1, 2, 3, 4, 2}
146 #
147 MINGW_AT_CHECK_FD_MACRO([$2],[FD_CLR],dnl
148 [removes all matching descriptors],[3 entries: 1, 3, 4],[
149 { MINGW_AT_INITIALIZE_FD_SET([at_set],[1, 2, 3, 4, 2])[;
150   FD_CLR (2, &at_set); show_fd_set (&at_set);
151   return 0;
152 }]])
153
154 # Verify that the FD_ISSET macro correctly reports absence of
155 # descriptor 4 from, and presence of descriptor 2, within the
156 # predefined fd_set {1, 2, 3}; note that, since macro FD_ISSET
157 # may be defined in terms of Microsoft's __WSAFDIsSet() library
158 # function, we must ensure that the test code is linked with
159 # the appropriate version of the WinSock library.
160 #
161 MINGW_AT_CHECK_FD_ISSET_MACRO([$2],[4])
162 MINGW_AT_CHECK_FD_ISSET_MACRO([$2],[2])
163
164 # Finally, restore the default set of libraries which are to
165 # be used when linking subsequent test code.
166 #
167 MINGW_AT_LINK_LIBS_DEFAULT
168 ])
169
170 # Invoke the gamut of WinSock tests for each of the provided
171 # WinSock v1.1, and WinSock v2 implementations.
172 #
173 MINGW_AT_CHECK_WINSOCK([v1.1],[winsock])
174 MINGW_AT_CHECK_WINSOCK([v2],[winsock2])
175
176 # vim: filetype=config formatoptions=croql
177 # $RCSfile$: end of file