PageRenderTime 27ms CodeModel.GetById 22ms app.highlight 5ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-29/SWIG/Examples/test-suite/ruby/unions_runme.rb

#
Ruby | 54 lines | 36 code | 11 blank | 7 comment | 10 complexity | 53a744e1e048d1ff61a0344bfc78e32a MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
 1
 2# This is the union runtime testcase. It ensures that values within a 
 3# union embedded within a struct can be set and read correctly.
 4
 5require 'unions'
 6
 7# Create new instances of SmallStruct and BigStruct for later use
 8small = Unions::SmallStruct.new()
 9small.jill = 200
10
11big = Unions::BigStruct.new()
12big.smallstruct = small
13big.jack = 300
14
15# Use SmallStruct then BigStruct to setup EmbeddedUnionTest.
16# Ensure values in EmbeddedUnionTest are set correctly for each.
17eut = Unions::EmbeddedUnionTest.new()
18
19# First check the SmallStruct in EmbeddedUnionTest
20eut.number = 1
21eut.uni.small = small
22Jill1 = eut.uni.small.jill
23if (Jill1 != 200)
24    print "Runtime test1 failed. eut.uni.small.jill=" , Jill1 , "\n"
25    exit 1
26end
27
28Num1 = eut.number
29if (Num1 != 1)
30    print "Runtime test2 failed. eut.number=" , Num1 , "\n"
31    exit 1
32end
33
34# Secondly check the BigStruct in EmbeddedUnionTest
35eut.number = 2
36eut.uni.big = big
37Jack1 = eut.uni.big.jack
38if (Jack1 != 300)
39    print "Runtime test3 failed. eut.uni.big.jack=" , Jack1 , "\n"
40    exit 1
41end
42
43Jill2 = eut.uni.big.smallstruct.jill
44if (Jill2 != 200)
45    print "Runtime test4 failed. eut.uni.big.smallstruct.jill=" , Jill2 , "\n"
46    exit 1
47end
48
49Num2 = eut.number
50if (Num2 != 2)
51    print "Runtime test5 failed. eut.number=" , Num2 , "\n"
52    exit 1
53end
54