PageRenderTime 19ms CodeModel.GetById 11ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/guile/throw_exception_runme.scm

#
Lisp | 45 lines | 37 code | 4 blank | 4 comment | 0 complexity | 4854f9814d167f06544b5be7076ebdff MD5 | raw file
 1;; The SWIG modules have "passive" Linkage, i.e., they don't generate
 2;; Guile modules (namespaces) but simply put all the bindings into the
 3;; current module.  That's enough for such a simple test.
 4(dynamic-call "scm_init_throw_exception_module" (dynamic-link "./libthrow_exception.so"))
 5
 6(define-macro (check-throw form)
 7  `(catch 'swig-exception
 8     (lambda ()
 9       ,form
10       (error "Check failed (returned normally): " ',form))
11     (lambda (key result)
12       result)))
13
14(define-macro (check-throw-error form)
15  `(let ((result (check-throw ,form)))
16     (test-is-Error result)))
17
18(let ((foo (new-Foo)))
19  (let ((result (check-throw (Foo-test-int foo))))
20    (if (not (eqv? result 37))
21	(error "Foo-test-int failed, returned " result)))
22  (let ((result (check-throw (Foo-test-multi foo 1))))
23    (if (not (eqv? result 37))
24	(error "Foo-test-multi 1 failed, returned " result)))
25  (let ((result (check-throw (Foo-test-msg foo))))
26    (if (not (and (string? result)
27		  (string=? result "Dead")))
28	(error "Foo-test-msg failed, returned " result)))
29  (let ((result (check-throw (Foo-test-multi foo 2))))
30    (if (not (and (string? result)
31		  (string=? result "Dead")))
32	(error "Foo-test-multi 2 failed, returned " result)))
33  (check-throw-error (Foo-test-cls foo))
34  (check-throw-error (Foo-test-multi foo 3))
35  (check-throw-error (Foo-test-cls-ptr foo))
36  (check-throw-error (Foo-test-cls-ref foo))
37  ;; Namespace stuff
38  (let ((result (check-throw (Foo-test-enum foo))))
39    (if (not (eqv? result (enum2)))
40	(error "Foo-test-enum failed, returned " result)))
41  (check-throw-error (Foo-test-cls-td foo))
42  (check-throw-error (Foo-test-cls-ptr-td foo))
43  (check-throw-error (Foo-test-cls-ref-td foo)))
44  			      
45(exit 0)