OSDN Git Service

2010-04-27 Tobias Burnus <burnus@net-b.de>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gfortran.dg / fseek.f90
1 ! { dg-do run }
2
3 PROGRAM test_fseek
4   INTEGER, PARAMETER :: SEEK_SET = 0, SEEK_CUR = 1, SEEK_END = 2, fd=10
5   INTEGER :: ierr = 0
6   INTEGER :: newline_length
7
8   ! We first need to determine if a newline is one or two characters
9   open (911,status="scratch")
10   write(911,"()")
11   newline_length = ftell(911)
12   close (911)
13   if (newline_length < 1 .or. newline_length > 2) call abort()
14
15   open(fd, status="scratch")
16   ! expected position: one leading blank + 10 + newline
17   WRITE(fd, *) "1234567890"
18   IF (FTELL(fd) /= 11 + newline_length) CALL abort()
19
20   ! move backward from current position
21   CALL FSEEK(fd, -11 - newline_length, SEEK_CUR, ierr)
22   IF (ierr /= 0 .OR. FTELL(fd) /= 0) CALL abort()
23
24   ! move to negative position (error)
25   CALL FSEEK(fd, -1, SEEK_SET, ierr)
26   IF (ierr == 0 .OR. FTELL(fd) /= 0) CALL abort()
27
28   ! move forward from end (11 + 10 + newline)
29   CALL FSEEK(fd, 10, SEEK_END, ierr)
30   IF (ierr /= 0 .OR. FTELL(fd) /= 21 + newline_length) CALL abort()
31
32   ! set position (0)
33   CALL FSEEK(fd, 0, SEEK_SET, ierr)
34   IF (ierr /= 0 .OR. FTELL(fd) /= 0) CALL abort()
35
36   ! move forward from current position
37   CALL FSEEK(fd, 5, SEEK_CUR, ierr)
38   IF (ierr /= 0 .OR. FTELL(fd) /= 5) CALL abort()
39
40   CALL FSEEK(fd, HUGE(0_1), SEEK_SET, ierr)
41   IF (ierr /= 0 .OR. FTELL(fd) /= HUGE(0_1)) CALL abort()
42
43   CALL FSEEK(fd, HUGE(0_2), SEEK_SET, ierr)
44   IF (ierr /= 0 .OR. FTELL(fd) /= HUGE(0_2)) CALL abort()
45
46   CALL FSEEK(fd, HUGE(0_4), SEEK_SET, ierr)
47   IF (ierr /= 0 .OR. FTELL(fd) /= HUGE(0_4)) CALL abort()
48   
49   CALL FSEEK(fd, -HUGE(0_4), SEEK_CUR, ierr)
50   IF (ierr /= 0 .OR. FTELL(fd) /= 0) CALL abort()
51 END PROGRAM
52