login_tty: Stricter unit test.
authorBruno Haible <bruno@clisp.org>
Fri, 17 Sep 2010 02:00:49 +0000 (04:00 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 17 Sep 2010 02:00:49 +0000 (04:00 +0200)
* modules/login_tty-tests (Depends-on): Add tcgetsid.
* tests/test-login_tty.c (main): Also check the results of tcgetpgrp()
and tcgetsid() after login_tty.
Reported by Mats Erik Andersson <mats.andersson@gisladisker.se>.

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

index d86265a15f2c9ad493f3e261078739d18b478864..25c63a520daf0e23015b4fe27916fafa1fe085cf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-09-16  Bruno Haible  <bruno@clisp.org>
+
+       login_tty: Stricter unit test.
+       * modules/login_tty-tests (Depends-on): Add tcgetsid.
+       * tests/test-login_tty.c (main): Also check the results of tcgetpgrp()
+       and tcgetsid() after login_tty.
+       Reported by Mats Erik Andersson <mats.andersson@gisladisker.se>.
+
 2010-09-16  Bruno Haible  <bruno@clisp.org>
 
        New module 'tcgetsid'.
index b9cbbd73948b2d145f7c43779b28321900febb2d..306b0ebe12973c172a4695302e2bfaeafd6e0496 100644 (file)
@@ -3,6 +3,7 @@ tests/test-login_tty.c
 
 Depends-on:
 openpty
+tcgetsid
 
 configure.ac:
 
index cd08f54b42a8b3da5deaa25976dca6b923454b4a..8560c5a6d734250143bff713835bb157fcd106c4 100644 (file)
 /* Specification.  */
 extern int login_tty (int);
 
+#include <errno.h>
 #include <pty.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <termios.h>
+#include <unistd.h>
 
 int
 main ()
@@ -48,5 +52,23 @@ main ()
       }
   }
 
+  /* From here on, we cannot use stderr for error messages any more.
+     If a test fails, just abort.  */
+
+  /* Check that fd = 0, 1, 2 are now open to the controlling terminal for the
+     current process and that it is a session of its own.  */
+  {
+    int fd;
+    for (fd = 0; fd < 3; fd++)
+      if (!(tcgetpgrp (fd) == getpid ()))
+        abort ();
+    for (fd = 0; fd < 3; fd++)
+      {
+        int sid = tcgetsid (fd);
+        if (!(sid == -1 ? errno == ENOSYS : sid == getpid ()))
+          abort ();
+      }
+  }
+
   return 0;
 }