PageRenderTime 37ms CodeModel.GetById 17ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 1ms

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

#
Java | 81 lines | 50 code | 18 blank | 13 comment | 1 complexity | 7730ff7da3d677089c6c076ca626ac17 MD5 | raw file
 1
 2// This is the java_typemaps_proxy runtime testcase. Contrived example checks that the pure Java code from the Java typemaps compiles.
 3
 4import java_typemaps_proxy.*;
 5import java.lang.reflect.*;
 6
 7public class java_typemaps_proxy_runme {
 8
 9  static {
10    try {
11	System.loadLibrary("java_typemaps_proxy");
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    Greeting greet = new Greeting();
21    Farewell bye = new Farewell();
22
23    // Check that pure Java methods have been added
24    greet.sayhello();
25    bye.saybye(new java.math.BigDecimal(java.math.BigInteger.ONE));
26
27    // No finalize method so may as well delete manually
28    bye.delete();
29
30    // Check that Greeting is derived from Exception
31    try {
32      throw new Greeting();
33    } catch (Greeting g) {
34        String msg = g.getMessage(); 
35    }
36
37    // Check that Greeting has implemented the EventListener interface
38    Greeting.cheerio(greet); 
39
40    // The default getCPtr() call in each method will through an exception if null is passed.
41    // Make sure the modified version works with and without null objects.
42    Greeting.ciao(null);
43    Greeting.ciao(greet);
44
45    // Create a NULL pointer for Farewell using the constructor with changed modifiers
46    Farewell nullFarewell = new Farewell(0, false);
47
48    // Test typemaps are being found for templated classes
49    AdieuIntPtrPtr.adieu();
50
51    // Check the %javamethodmodifiers feature
52    try {
53      Method methodmodifiertest = nullFarewell.getClass().getDeclaredMethod("methodmodifiertest", (java.lang.Class[])null);
54      if ( !Modifier.isPrivate(methodmodifiertest.getModifiers()) )
55        throw new RuntimeException("NS::Farewell::methodmodifiertest not private" );
56
57    } catch (NoSuchMethodException n) {
58      throw new RuntimeException("NoSuchmethodException caught. Test failed.");
59    } catch (SecurityException s) {
60      throw new RuntimeException("SecurityException caught. Test failed.");
61    }
62
63    // Check the premature garbage collection prevention parameter
64    // Check it is normally present
65    long nullPtr = 0;
66    With with = new With(null);
67    java_typemaps_proxyJNI.new_With(nullPtr, with);
68    java_typemaps_proxyJNI.With_static_method(nullPtr, with);
69    java_typemaps_proxyJNI.With_member_method(nullPtr, with, nullPtr, with);
70    java_typemaps_proxyJNI.delete_With(nullPtr);
71    java_typemaps_proxyJNI.global_method_with(nullPtr, with);
72
73    // Check that it can be turned off
74    java_typemaps_proxyJNI.new_Without(nullPtr);
75    java_typemaps_proxyJNI.Without_static_method(nullPtr);
76    java_typemaps_proxyJNI.Without_member_method(nullPtr, nullPtr);
77    java_typemaps_proxyJNI.delete_Without(nullPtr);
78    java_typemaps_proxyJNI.global_method_without(nullPtr);
79  }
80}
81