]> Savannah Git Hosting - gnulib.git/commitdiff
sys_socket tests: Improve tests for macro definitions.
authorCollin Funk <collin.funk1@gmail.com>
Tue, 23 Jul 2024 03:54:17 +0000 (20:54 -0700)
committerCollin Funk <collin.funk1@gmail.com>
Tue, 23 Jul 2024 03:54:17 +0000 (20:54 -0700)
* modules/sys_socket-tests (Depends-on): Add assert-h.
* tests/test-sys_socket.c (a): Remove variable.
(main): Test that each supported address family is defined to a distinct
value. Test that each constant passed as the second argument of
'shutdown' is defined to a distinct value.

ChangeLog
modules/sys_socket-tests
tests/test-sys_socket.c

index 335a29b0c035e16a105d070a0d3bed29fbffb5e8..cf20d60b76935c52a21fd5db95d7a6d3a87e11a9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-07-22  Collin Funk  <collin.funk1@gmail.com>
+
+       sys_socket tests: Improve tests for macro definitions.
+       * modules/sys_socket-tests (Depends-on): Add assert-h.
+       * tests/test-sys_socket.c (a): Remove variable.
+       (main): Test that each supported address family is defined to a distinct
+       value. Test that each constant passed as the second argument of
+       'shutdown' is defined to a distinct value.
+
 2024-07-22  Bruno Haible  <bruno@clisp.org>
 
        gnulib-tool: Omit the logs of skipped tests from test-suite.log.
index da67baf99a8f954a90e7910cecd8b35bef5d5693..b0bb4356ca8308dac29b9fa25c088da081005279 100644 (file)
@@ -2,6 +2,7 @@ Files:
 tests/test-sys_socket.c
 
 Depends-on:
+assert-h
 sys_socket-c++-tests
 
 configure.ac:
index 4e0f9ad46e22f5e7a2dd181646fe792d4ae51b04..6fbfb98a707c3a774dfae58d8368e6f69b1c8e8a 100644 (file)
 
 #include <sys/socket.h>
 
-#if HAVE_SHUTDOWN
-/* Check some integer constant expressions.  */
-int a[] = { SHUT_RD, SHUT_WR, SHUT_RDWR };
-#endif
+/* POSIX mandates that AF_UNSPEC shall be 0.  */
+static_assert (AF_UNSPEC == 0);
 
 /* Check that the 'socklen_t' type is defined.  */
 socklen_t t1;
@@ -59,6 +57,35 @@ main (void)
       break;
     }
 
+  /* Check that each supported address family has a distinct value.  */
+  switch (0)
+    {
+    case AF_UNSPEC:
+#if HAVE_IPV4
+    case AF_INET:
+#endif
+#if HAVE_IPV6
+    case AF_INET6:
+#endif
+#if HAVE_UNIXSOCKET
+    case AF_UNIX:
+#endif
+    default:
+      break;
+    }
+
+  /* Check that the shutdown type macros are defined to distinct values.  */
+#if HAVE_SHUTDOWN
+  switch (0)
+    {
+    case SHUT_RD:
+    case SHUT_WR:
+    case SHUT_RDWR:
+    default:
+      break;
+    }
+#endif
+
   x.ss_family = 42;
   i = 42;
   msg.msg_iov = &io;