PageRenderTime 29ms CodeModel.GetById 17ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 1ms

/trunk/Examples/test-suite/java/unions_runme.java

#
Java | 68 lines | 48 code | 13 blank | 7 comment | 10 complexity | 04ee6bee188e3e29f755b8eab57e62ab MD5 | raw file
 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
 5import unions.*;
 6
 7public class unions_runme {
 8
 9  static {
10    try {
11	System.loadLibrary("unions");
12    } catch (UnsatisfiedLinkError e) {
13      System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
14      System.exit(1);
15    }
16  }
17
18  public static void main(String argv[]) {
19
20    // Create new instances of SmallStruct and BigStruct for later use
21    SmallStruct small = new SmallStruct();
22    small.setJill((short)200);
23
24    BigStruct big = new BigStruct();
25    big.setSmallstruct(small);
26    big.setJack(300);
27
28    // Use SmallStruct then BigStruct to setup EmbeddedUnionTest.
29    // Ensure values in EmbeddedUnionTest are set correctly for each.
30    EmbeddedUnionTest eut = new EmbeddedUnionTest();
31
32    // First check the SmallStruct in EmbeddedUnionTest
33    eut.setNumber(1);
34    eut.getUni().setSmall(small);
35    short Jill1 = eut.getUni().getSmall().getJill();
36    if (Jill1 != 200) {
37        System.err.println("Runtime test1 failed. eut.uni.small.jill=" + Jill1);
38        System.exit(1);
39    }
40
41    int Num1 = eut.getNumber();
42    if (Num1 != 1) {
43        System.err.println("Runtime test2 failed. eut.number=" + Num1);
44        System.exit(1);
45    }
46
47    // Secondly check the BigStruct in EmbeddedUnionTest
48    eut.setNumber(2);
49    eut.getUni().setBig(big);
50    int Jack1 = eut.getUni().getBig().getJack();
51    if (Jack1 != 300) {
52        System.err.println("Runtime test3 failed. eut.uni.big.jack=" + Jack1);
53        System.exit(1);
54    }
55
56    short Jill2 = eut.getUni().getBig().getSmallstruct().getJill();
57    if (Jill2 != 200) {
58        System.err.println("Runtime test4 failed. eut.uni.big.smallstruct.jill=" + Jill2);
59        System.exit(1);
60    }
61
62    int Num2 = eut.getNumber();
63    if (Num2 != 2) {
64        System.err.println("Runtime test5 failed. eut.number=" + Num2);
65        System.exit(1);
66    }
67}
68}