File: stdio-test.scm

package info (click to toggle)
gauche-c-wrapper 0.6.1-18
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,440 kB
  • sloc: ansic: 17,899; sh: 14,025; asm: 6,456; lisp: 5,485; yacc: 2,109; makefile: 520; exp: 194; cpp: 157; objc: 144; perl: 2
file content (52 lines) | stat: -rw-r--r-- 1,434 bytes parent folder | download | duplicates (7)
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
;;;
;;; Test include stdio.h
;;;

(use srfi-11)
(use gauche.test)
(use gauche.process)

(test-start "c-wrapper (include stdio.h)")
(use c-wrapper)

(c-include '("stdio.h" "unistd.h"))

(test "printf & fprintf"
      '("Hello, world" "error!")
      (lambda ()
        (let-values (((stdout-in stdout-out) (sys-pipe))
                     ((stderr-in stderr-out) (sys-pipe)))
          (let ((pid (sys-fork)))
            (if (= pid 0)
                (begin
                  (close-input-port stdout-in)
                  (close-input-port stderr-in)
                  (close 1)
                  (close 2)
                  (dup (port-file-number stdout-out))
                  (dup (port-file-number stderr-out))
                  (printf "Hello, world")
                  (fprintf stderr "error!")
                  (fflush stdout)
                  (fflush stderr)
                  (fclose stdout)
                  (fclose stderr)
                  (sys-exit 0))
                (begin
                  (close-output-port stdout-out)
                  (close-output-port stderr-out)
                  (let ((outstr (read-line stdout-in))
                        (errstr (read-line stderr-in)))
                    (sys-wait)
                    (list outstr errstr))))))))

(test "sscanf"
      5
      (lambda ()
        (let ((v (make <c-int>)))
          (sscanf "5" "%d" (ptr v))
          (v))))

;; epilogue
(test-end)