summaryrefslogtreecommitdiff
path: root/test-suite/tests/ftw.test
blob: 847fb9ff430f930a3784edbe9ecea916ed923af2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
;;;; ftw.test --- exercise ice-9/ftw.scm      -*- scheme -*-
;;;;
;;;; Copyright 2006 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
;;;; License as published by the Free Software Foundation; either
;;;; version 3 of the License, or (at your option) any later version.
;;;; 
;;;; This library is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;;;; Lesser General Public License for more details.
;;;; 
;;;; You should have received a copy of the GNU Lesser General Public
;;;; License along with this library; if not, write to the Free Software
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

(define-module (test-suite test-ice-9-ftw)
  #:use-module (test-suite lib)
  #:use-module (ice-9 ftw))


;; the procedure-source checks here ensure the vector indexes we write match
;; what ice-9/posix.scm stat:dev and stat:ino do (which in turn match
;; libguile/filesys.c of course)

(define (stat:dev! st dev)
  (vector-set! st 0 dev))
(define (stat:ino! st ino)
  (vector-set! st 1 ino))

(let* ((s (stat "/"))
       (i (stat:ino s))
       (d (stat:dev s)))
  (stat:ino! s (1+ i))
  (stat:dev! s (1+ d))
  (if (not (and (= (stat:ino s) (1+ i))
                (= (stat:dev s) (1+ d))))
      (error "unexpected definitions of stat:dev and stat:ino")))

;;
;; visited?-proc
;;

(with-test-prefix "visited?-proc"

  ;; normally internal-only
  (let* ((visited?-proc (@@ (ice-9 ftw) visited?-proc))
	 (visited? (visited?-proc 97))
	 (s (stat "/")))

    (define (try-visited? dev ino)
      (stat:dev! s dev)
      (stat:ino! s ino)
      (visited? s))

    (pass-if "0 0 - 1st" (eq? #f (try-visited? 0 0)))
    (pass-if "0 0 - 2nd" (eq? #t (try-visited? 0 0)))
    (pass-if "0 0 - 3rd" (eq? #t (try-visited? 0 0)))

    (pass-if "0 1" (eq? #f (try-visited? 0 1)))
    (pass-if "0 2" (eq? #f (try-visited? 0 2)))
    (pass-if "0 3" (eq? #f (try-visited? 0 3)))

    (pass-if "5 5" (eq? #f (try-visited? 5 5)))
    (pass-if "5 7" (eq? #f (try-visited? 5 7)))
    (pass-if "7 5" (eq? #f (try-visited? 7 5)))
    (pass-if "7 7" (eq? #f (try-visited? 7 7)))

    (pass-if "5 5 - 2nd" (eq? #t (try-visited? 5 5)))
    (pass-if "5 7 - 2nd" (eq? #t (try-visited? 5 7)))
    (pass-if "7 5 - 2nd" (eq? #t (try-visited? 7 5)))
    (pass-if "7 7 - 2nd" (eq? #t (try-visited? 7 7)))))