#!/bin/sh
exec ./guile-test-env guile -s "$0" "$@"
!#

(use-modules (gw-test-glib))

(display "checking that <gw:gint64> works as advertized...")
(let* ((minval (- (inexact->exact (expt 2 63))))
       (maxval (- (+ minval 1)))
       (echo-func gw-test-gw-glib-echo-gint64))
  (if (and (= minval (echo-func minval))
           (zero? (echo-func 0))
           (= maxval (echo-func maxval)))
      (display "yes\n")
      (begin (display "no\n") (exit 1))))

;; TODO add more demanding checks for <gw:gchars> allocation issues.

(display "checking that (<gw:gchars> caller-owned) works as advertized...")
(let* ((test-str "xyzzy")
       (result-str (gw-test-gw-standard-echo-gchars-caller-owned test-str)))
  (if (and (string? result-str)
           (string=? test-str result-str)
           (not (eq? test-str result-str))
           (not (gw-test-gw-standard-echo-gchars-caller-owned #f)))
      (display "yes\n")
      (begin (display "no\n") (exit 1))))

(display "checking that (<gw:gchars> const caller-owned) works as advertized...")
(let* ((test-str "xyzzy")
       (result-str
        (gw-test-gw-standard-echo-const-gchars-caller-owned test-str)))

  (if (and (string? result-str)
           (string=? test-str result-str)
           (not (eq? test-str result-str))
           (not (gw-test-gw-standard-echo-const-gchars-caller-owned #f)))
      (display "yes\n")
      (begin (display "no\n") (exit 1))))

(display "checking that (<gw:gchars> callee-owned) works as advertized...")
(let* ((test-str "xyzzy")
       (result-str (gw-test-gw-standard-echo-gchars-callee-owned test-str)))
  (if (and (string? result-str)
           (string=? test-str result-str)
           (not (eq? test-str result-str))
           (not (gw-test-gw-standard-echo-gchars-callee-owned #f)))
      (display "yes\n")
      (begin (display "no\n") (exit 1))))

(display "checking that (<gw:gchars> const callee-owned) works as advertized...")
(let* ((test-str "xyzzy")
       (result-str
        (gw-test-gw-standard-echo-const-gchars-callee-owned test-str)))

  (if (and (string? result-str)
           (string=? test-str result-str)
           (not (eq? test-str result-str))
           (not (gw-test-gw-standard-echo-const-gchars-callee-owned #f)))
      (display "yes\n")
      (begin (display "no\n") (exit 1))))

(display "checking that gw:glist-of <gw:gchars> works...")
(let ((sample '("foo" "bar" "baz")))
  (if (and (equal? sample (gw-test-gw-glib-echo-gchars-list-1 sample))
           (equal? sample (gw-test-gw-glib-echo-gchars-list-2 sample)))
      (display "yes\n")
      (begin (display "no\n") (exit 1))))

(display "checking that gw:glist-of wcp values works...")
(let ((sample (list (gw-test-make-int-carrier 1)
                    (gw-test-make-int-carrier 2)
                    (gw-test-make-int-carrier 3))))
  (if (and (equal? sample (gw-test-gw-glib-echo-test-foo-list sample)))
      (display "yes\n")
      (begin (display "no\n") (exit 1)))

  (for-each gw-test-destroy-int-carrier sample))

(display "checking that gw:gslist-of <gw:gchars> works...")
(let ((sample '("foo" "bar" "baz")))
  (if (and (equal? sample (gw-test-gw-glib-echo-gchars-slist-1 sample))
           (equal? sample (gw-test-gw-glib-echo-gchars-slist-2 sample)))
      (display "yes\n")
      (begin (display "no\n") (exit 1))))

(display "checking that gw:gslist-of wcp values works...")
(let ((sample (list (gw-test-make-int-carrier 1)
                    (gw-test-make-int-carrier 2)
                    (gw-test-make-int-carrier 3))))
  (if (and (equal? sample (gw-test-gw-glib-echo-test-foo-slist sample)))
      (display "yes\n")
      (begin (display "no\n") (exit 1)))

  (for-each gw-test-destroy-int-carrier sample))

(exit 0)

;; Local Variables:
;; mode: scheme
;; End:
