Michael W. Hudson | f008998 | 2003-03-03 12:29:42 +0000 | [diff] [blame] | 1 | import unittest |
| 2 | from test_support import TestSkipped, run_unittest |
| 3 | import os, struct |
| 4 | try: |
| 5 | import fcntl, termios |
| 6 | except ImportError: |
| 7 | raise TestSkipped("No fcntl or termios module") |
| 8 | if not hasattr(termios,'TIOCGPGRP'): |
| 9 | raise TestSkipped("termios module doesn't have TIOCGPGRP") |
| 10 | |
Neal Norwitz | 26f42f6 | 2003-03-20 04:33:16 +0000 | [diff] [blame] | 11 | try: |
| 12 | tty = open("/dev/tty", "r") |
| 13 | tty.close() |
| 14 | except IOError: |
| 15 | raise TestSkipped("Unable to open /dev/tty") |
| 16 | |
Michael W. Hudson | f008998 | 2003-03-03 12:29:42 +0000 | [diff] [blame] | 17 | class IoctlTests(unittest.TestCase): |
| 18 | def test_ioctl(self): |
| 19 | pgrp = os.getpgrp() |
| 20 | tty = open("/dev/tty", "r") |
| 21 | r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ") |
| 22 | self.assertEquals(pgrp, struct.unpack("i", r)[0]) |
| 23 | |
| 24 | def test_ioctl_mutate(self): |
| 25 | import array |
| 26 | buf = array.array('i', [0]) |
| 27 | pgrp = os.getpgrp() |
| 28 | tty = open("/dev/tty", "r") |
| 29 | r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1) |
| 30 | self.assertEquals(r, 0) |
| 31 | self.assertEquals(pgrp, buf[0]) |
| 32 | |
| 33 | def test_main(): |
| 34 | run_unittest(IoctlTests) |
| 35 | |
| 36 | if __name__ == "__main__": |
| 37 | test_main() |