#! /bin/bash
exec guile -s "$0" 
!#

(use-modules (gnucash gnc-module))
(gnc:module-system-init)

(or (gnc:module-load "gnucash/app-utils" 0)
    (error "can't load module"))

(let ((id #f)
      (refresh-ran #f)
      (close-ran #f))

  (define (refresh-handler)
    (set! refresh-ran #t))

  (define (close-handler)
    (set! close-ran #t)
    (gnc:unregister-gui-component id))

  (set! id (gnc:register-gui-component "test-class"
                                       refresh-handler
                                       close-handler))
  (or (not (equal? id -1))
      (error "can't register"))

  (gnc:gui-refresh-all)

  (or refresh-ran (error "refresh didn't run"))

  (gnc:close-gui-component id)

  (or close-ran (error "close didn't run"))

  (set! refresh-ran #f)
  (set! close-ran #f)

  (gnc:gui-refresh-all)
  (gnc:close-gui-component id)

  (or (not (or refresh-ran close-ran))
      (error "component not removed")))

(exit 0)

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