PageRenderTime 15ms CodeModel.GetById 2ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 80 lines | 56 code | 12 blank | 12 comment | 20 complexity | 4b595f1fe1268bf6b61a4830ccfac5ac MD5 | raw file
 1// This tests changes the package name from nspace to nspacePackage as javac can't seem to resolve classes and packages having the same name
 2public class nspace_runme {
 3
 4  static {
 5    try {
 6	System.loadLibrary("nspace");
 7    } catch (UnsatisfiedLinkError e) {
 8      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);
 9      System.exit(1);
10    }
11  }
12
13  public static void main(String argv[]) {
14    // constructors and destructors
15    nspacePackage.Outer.Inner1.Color color1 = new nspacePackage.Outer.Inner1.Color();
16    nspacePackage.Outer.Inner1.Color color = new nspacePackage.Outer.Inner1.Color(color1);
17    color1.delete();
18    color1 = null;
19
20    // class methods
21    color.colorInstanceMethod(20.0);
22    nspacePackage.Outer.Inner1.Color.colorStaticMethod(20.0);
23    nspacePackage.Outer.Inner1.Color created = nspacePackage.Outer.Inner1.Color.create();
24
25    // class enums
26    nspacePackage.Outer.SomeClass someClass = new nspacePackage.Outer.SomeClass();
27    nspacePackage.Outer.Inner1.Color.Channel channel = someClass.GetInner1ColorChannel();
28    if (channel != nspacePackage.Outer.Inner1.Color.Channel.Transmission)
29      throw new RuntimeException("Transmission wrong");
30
31    // class anonymous enums
32    int val1 = nspacePackage.Outer.Inner1.Color.ColorEnumVal1;
33    int val2 = nspacePackage.Outer.Inner1.Color.ColorEnumVal2;
34    if (val1 != 0 || val2 != 0x22)
35      throw new RuntimeException("ColorEnumVal wrong");
36
37    // instance member variables
38    color.setInstanceMemberVariable(123);
39    if (color.getInstanceMemberVariable() != 123)
40      throw new RuntimeException("instance member variable failed");
41
42    // static member variables
43    nspacePackage.Outer.Inner1.Color.setStaticMemberVariable(789);
44    if (nspacePackage.Outer.Inner1.Color.getStaticMemberVariable() != 789)
45      throw new RuntimeException("static member variable failed");
46    if (nspacePackage.Outer.Inner1.Color.staticConstMemberVariable != 222)
47      throw new RuntimeException("static const member variable failed");
48    if (nspacePackage.Outer.Inner1.Color.staticConstEnumMemberVariable != nspacePackage.Outer.Inner1.Color.Channel.Transmission)
49      throw new RuntimeException("static const enum member variable failed");
50
51    // Same class different namespaces
52    nspacePackage.Outer.Inner1.Color col1 = new nspacePackage.Outer.Inner1.Color();
53    nspacePackage.Outer.Inner2.Color col2 = nspacePackage.Outer.Inner2.Color.create();
54    col2.colors(col1, col1, col2, col2, col2);
55
56    // check globals in a namespace don't get mangled with the nspacePackage option
57    nspacePackage.nspace.namespaceFunction(color);
58    nspacePackage.nspace.setNamespaceVar(111);
59    if (nspacePackage.nspace.getNamespaceVar() != 111)
60      throw new RuntimeException("global var failed");
61
62    // global enums
63    nspacePackage.Outer.Inner1.Channel outerChannel1 = someClass.GetInner1Channel();
64    if (outerChannel1 != nspacePackage.Outer.Inner1.Channel.Transmission1)
65      throw new RuntimeException("Transmission1 wrong");
66    nspacePackage.Outer.Inner2.Channel outerChannel2 = someClass.GetInner2Channel();
67    if (outerChannel2 != nspacePackage.Outer.Inner2.Channel.Transmission2)
68      throw new RuntimeException("Transmission2 wrong");
69
70    // turn feature off / ignoring
71    nspacePackage.Outer.namespce ns = new nspacePackage.Outer.namespce();
72    nspacePackage.NoNSpacePlease nons = new nspacePackage.NoNSpacePlease();
73
74    // Derived class
75    nspacePackage.Outer.Inner3.Blue blue3 = new nspacePackage.Outer.Inner3.Blue();
76    blue3.blueInstanceMethod();
77    nspacePackage.Outer.Inner4.Blue blue4 = new nspacePackage.Outer.Inner4.Blue();
78    blue4.blueInstanceMethod();
79  }
80}