import source from 1.3.40
[external/swig.git] / Examples / test-suite / schemerunme / unions.scm
1 ;;; This is the union runtime testcase. It ensures that values within a
2 ;;; union embedded within a struct can be set and read correctly.
3
4 ;; Create new instances of SmallStruct and BigStruct for later use
5 (define small (new-SmallStruct))
6 (SmallStruct-jill-set small 200)
7
8 (define big (new-BigStruct))
9 (BigStruct-smallstruct-set big small)
10 (BigStruct-jack-set big 300)
11
12 ;; Use SmallStruct then BigStruct to setup EmbeddedUnionTest.
13 ;; Ensure values in EmbeddedUnionTest are set correctly for each.
14 (define eut (new-EmbeddedUnionTest))
15
16 ;; First check the SmallStruct in EmbeddedUnionTest
17 (EmbeddedUnionTest-number-set eut 1)
18 (EmbeddedUnionTest-uni-small-set (EmbeddedUnionTest-uni-get eut)
19                                  small)
20 (let ((Jill1 (SmallStruct-jill-get
21               (EmbeddedUnionTest-uni-small-get
22                (EmbeddedUnionTest-uni-get eut)))))
23   (if (not (= Jill1 200))
24       (begin
25         (display "Runtime test 1 failed.")
26         (exit 1))))
27
28 (let ((Num1 (EmbeddedUnionTest-number-get eut)))
29   (if (not (= Num1 1))
30       (begin
31         (display "Runtime test 2 failed.")
32         (exit 1))))
33
34 ;; that should do
35
36 (exit 0)