/trunk/Examples/test-suite/java/director_primitives_runme.java
Java | 138 lines | 105 code | 18 blank | 15 comment | 27 complexity | 8517853de2525e2531131182b78fdd48 MD5 | raw file
1/* 2 This test program shows a C# class JavaDerived inheriting from Base. Three types of classes are created 3 and the virtual methods called to demonstrate: 4 1) Wide variety of primitive types 5 2) Calling methods with zero, one or more parameters 6 3) Director methods that are not overridden in C# 7 4) Director classes that are not overridden at all in C#, ie non-director behaviour is as expected for director classes 8 5) Inheritance hierarchy using director methods 9 6) Return types working as well as parameters 10 11 The Caller class is a tester class, which calls the virtual functions from C++. 12*/ 13 14import director_primitives.*; 15 16public class director_primitives_runme { 17 18 static { 19 try { 20 System.loadLibrary("director_primitives"); 21 } catch (UnsatisfiedLinkError e) { 22 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); 23 System.exit(1); 24 } 25 } 26 27 public static void main(String argv[]) throws Throwable 28 { 29 director_primitives_runme r = new director_primitives_runme(); 30 r.run(); 31 } 32 33 void run() 34 { 35 if (director_primitives.getPrintDebug()) System.out.println("------------ Start ------------ "); 36 37 Caller myCaller = new Caller(); 38 39 // test C++ base class 40 { 41 Base myBase = new Base(100.0); 42 makeCalls(myCaller, myBase); 43 myBase.delete(); 44 } 45 46 if (director_primitives.getPrintDebug()) System.out.println("--------------------------------"); 47 48 // test vanilla C++ wrapped derived class 49 { 50 Base myBase = new Derived(200.0); 51 makeCalls(myCaller, myBase); 52 myBase.delete(); 53 } 54 55 if (director_primitives.getPrintDebug()) System.out.println("--------------------------------"); 56 57 // test director / C# derived class 58 { 59 Base myBase = new JavaDerived(300.0); 60 makeCalls(myCaller, myBase); 61 myBase.delete(); 62 } 63 64 if (director_primitives.getPrintDebug()) System.out.println("------------ Finish ------------ "); 65 } 66 67 void makeCalls(Caller myCaller, Base myBase) 68 { 69 myCaller.set(myBase); 70 71 myCaller.NoParmsMethodCall(); 72 if (myCaller.BoolMethodCall(true) != true) throw new RuntimeException("failed"); 73 if (myCaller.BoolMethodCall(false) != false) throw new RuntimeException("failed"); 74 if (myCaller.IntMethodCall(-123) != -123) throw new RuntimeException("failed"); 75 if (myCaller.UIntMethodCall(123) != 123) throw new RuntimeException("failed"); 76 if (myCaller.FloatMethodCall((float)-123.456) != (float)-123.456) throw new RuntimeException("failed"); 77 if (!myCaller.CharPtrMethodCall("test string").equals("test string")) throw new RuntimeException("failed"); 78 if (!myCaller.ConstCharPtrMethodCall("another string").equals("another string")) throw new RuntimeException("failed"); 79 if (myCaller.EnumMethodCall(HShadowMode.HShadowHard) != HShadowMode.HShadowHard) throw new RuntimeException("failed"); 80 myCaller.ManyParmsMethodCall(true, -123, 123, (float)123.456, "test string", "another string", HShadowMode.HShadowHard); 81 myCaller.NotOverriddenMethodCall(); 82 83 myCaller.reset(); 84 } 85} 86 87class JavaDerived extends Base 88{ 89 public JavaDerived(double dd) 90 { 91 super(dd); 92 } 93 94 public void NoParmsMethod() 95 { 96 if (director_primitives.getPrintDebug()) System.out.println("JavaDerived - NoParmsMethod()"); 97 } 98 public boolean BoolMethod(boolean x) 99 { 100 if (director_primitives.getPrintDebug()) System.out.println("JavaDerived - BoolMethod(" + x + ")"); 101 return x; 102 } 103 public int IntMethod(int x) 104 { 105 if (director_primitives.getPrintDebug()) System.out.println("JavaDerived - IntMethod(" + x + ")"); 106 return x; 107 } 108 public long UIntMethod(long x) 109 { 110 if (director_primitives.getPrintDebug()) System.out.println("JavaDerived - UIntMethod(" + x + ")"); 111 return x; 112 } 113 public float FloatMethod(float x) 114 { 115 if (director_primitives.getPrintDebug()) System.out.println("JavaDerived - FloatMethod(" + x + ")"); 116 return x; 117 } 118 public String CharPtrMethod(String x) 119 { 120 if (director_primitives.getPrintDebug()) System.out.println("JavaDerived - CharPtrMethod(" + x + ")"); 121 return x; 122 } 123 public String ConstCharPtrMethod(String x) 124 { 125 if (director_primitives.getPrintDebug()) System.out.println("JavaDerived - ConstCharPtrMethod(" + x + ")"); 126 return x; 127 } 128 public HShadowMode EnumMethod(HShadowMode x) 129 { 130 if (director_primitives.getPrintDebug()) System.out.println("JavaDerived - EnumMethod(" + x + ")"); 131 return x; 132 } 133 public void ManyParmsMethod(boolean b, int i, long u, float f, String c, String cc, HShadowMode h) 134 { 135 if (director_primitives.getPrintDebug()) System.out.println("JavaDerived - ManyParmsMethod(" + b + ", " + i + ", " + u + ", " + f + ", " + c + ", " + cc + ", " + h); 136 } 137} 138