From: Bruno Haible Date: Mon, 5 Apr 2010 11:15:11 +0000 (+0200) Subject: ptsname: Improve test. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c358102053be9ce7f33788c579f6e1e034f143c9;p=pspp ptsname: Improve test. --- diff --git a/ChangeLog b/ChangeLog index f45c228de1..feb4e916ab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-04-05 Bruno Haible + + ptsname: Improve test. + * tests/test-ptsname.c (main): Also try the various master names of BSD + systems. + 2010-04-05 Bruno Haible memchr: Avoid a possible C++ test error. diff --git a/tests/test-ptsname.c b/tests/test-ptsname.c index 7d4e7d44d2..ce392833cc 100644 --- a/tests/test-ptsname.c +++ b/tests/test-ptsname.c @@ -54,13 +54,13 @@ main (void) close (fd); } - /* Try various master names of MacOS X. */ + /* Try various master names of MacOS X: /dev/pty[p-w][0-9a-f] */ { int char1; int char2; for (char1 = 'p'; char1 <= 'w'; char1++) - for (char2 = '0'; char2 <= 'f'; char2 = (char2 == '9' ? 'a' : char2 + 1)) + for (char2 = '0'; char2 <= 'f'; (char2 == '9' ? char2 = 'a' : char2++)) { char master_name[32]; int fd; @@ -82,5 +82,35 @@ main (void) } } + /* Try various master names of *BSD: /dev/pty[p-sP-S][0-9a-v] */ + { + int upper; + int char1; + int char2; + + for (upper = 0; upper <= 1; upper++) + for (char1 = (upper ? 'P' : 'p'); char1 <= (upper ? 'S' : 's'); char1++) + for (char2 = '0'; char2 <= 'v'; (char2 == '9' ? char2 = 'a' : char2++)) + { + char master_name[32]; + int fd; + + sprintf (master_name, "/dev/pty%c%c", char1, char2); + fd = open (master_name, O_RDONLY); + if (fd >= 0) + { + char *result; + char slave_name[32]; + + result = ptsname (fd); + ASSERT (result != NULL); + sprintf (slave_name, "/dev/tty%c%c", char1, char2); + ASSERT (strcmp (result, slave_name) == 0); + + close (fd); + } + } + } + return 0; }