PageRenderTime 48ms CodeModel.GetById 29ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 226 lines | 198 code | 23 blank | 5 comment | 156 complexity | 94b9ae156e55252aa0f5b3156e7e91ad MD5 | raw file
  1
  2import extend_default.Override;
  3import extend_default.*;
  4
  5public class extend_default_runme {
  6  static {
  7    try {
  8        System.loadLibrary("extend_default");
  9    } catch (UnsatisfiedLinkError e) {
 10      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);
 11      System.exit(1);
 12    }
 13  }
 14
 15  public static void main(String argv[]) 
 16  {
 17    // %extend before the class definition
 18    {
 19      Before ex = new Before();
 20      if (ex.getI() != -1.0 && ex.getD() != -1.0)
 21        throw new RuntimeException("Before constructor 1 failed");
 22
 23      ex = new Before(10);
 24      if (ex.getI() != 10.0 && ex.getD() != -1.0)
 25        throw new RuntimeException("Before constructor 2 failed");
 26
 27      ex = new Before(20, 30.0);
 28      if (ex.getI() != 20 && ex.getD() != 30.0)
 29        throw new RuntimeException("Before constructor 3 failed");
 30    }
 31    {
 32      Before ex = new Before();
 33      if (ex.AddedMethod() != -2.0)
 34        throw new RuntimeException("Before AddedMethod 1 failed");
 35      if (ex.AddedMethod(-2) != -3.0)
 36        throw new RuntimeException("Before AddedMethod 2 failed");
 37      if (ex.AddedMethod(-10, -10.0) != -20)
 38        throw new RuntimeException("Before AddedMethod 3 failed");
 39    }
 40    {
 41      if (Before.AddedStaticMethod() != -2.0)
 42        throw new RuntimeException("Before AddedStaticMethod 1 failed");
 43      if (Before.AddedStaticMethod(-2) != -3.0)
 44        throw new RuntimeException("Before AddedStaticMethod 2 failed");
 45      if (Before.AddedStaticMethod(-10, -10.0) != -20)
 46        throw new RuntimeException("Before AddedStaticMethod 3 failed");
 47    }
 48
 49    // %extend after the class definition
 50    {
 51      After ex = new After();
 52      if (ex.getI() != -1.0 && ex.getD() != -1.0)
 53        throw new RuntimeException("After constructor 1 failed");
 54
 55      ex = new After(10);
 56      if (ex.getI() != 10.0 && ex.getD() != -1.0)
 57        throw new RuntimeException("After constructor 2 failed");
 58
 59      ex = new After(20, 30.0);
 60      if (ex.getI() != 20 && ex.getD() != 30.0)
 61        throw new RuntimeException("After constructor 3 failed");
 62    }
 63    {
 64      After ex = new After();
 65      if (ex.AddedMethod() != -2.0)
 66        throw new RuntimeException("After AddedMethod 1 failed");
 67      if (ex.AddedMethod(-2) != -3.0)
 68        throw new RuntimeException("After AddedMethod 2 failed");
 69      if (ex.AddedMethod(-10, -10.0) != -20)
 70        throw new RuntimeException("After AddedMethod 3 failed");
 71    }
 72    {
 73      if (After.AddedStaticMethod() != -2.0)
 74        throw new RuntimeException("After AddedStaticMethod 1 failed");
 75      if (After.AddedStaticMethod(-2) != -3.0)
 76        throw new RuntimeException("After AddedStaticMethod 2 failed");
 77      if (After.AddedStaticMethod(-10, -10.0) != -20)
 78        throw new RuntimeException("After AddedStaticMethod 3 failed");
 79    }
 80
 81    // %extend before the class definition - with overloading and default args
 82    {
 83      OverBefore ex = new OverBefore();
 84      if (ex.getI() != -1.0 && ex.getD() != -1.0)
 85        throw new RuntimeException("OverBefore constructor 1 failed");
 86
 87      ex = new OverBefore(10);
 88      if (ex.getI() != 10.0 && ex.getD() != -1.0)
 89        throw new RuntimeException("OverBefore constructor 2 failed");
 90
 91      ex = new OverBefore(20, 30.0);
 92      if (ex.getI() != 20 && ex.getD() != 30.0)
 93        throw new RuntimeException("OverBefore constructor 3 failed");
 94    }
 95    {
 96      OverBefore ex = new OverBefore();
 97      if (ex.AddedMethod() != -2.0)
 98        throw new RuntimeException("OverBefore AddedMethod 1 failed");
 99      if (ex.AddedMethod(-2) != -3.0)
100        throw new RuntimeException("OverBefore AddedMethod 2 failed");
101      if (ex.AddedMethod(-10, -10.0) != -20)
102        throw new RuntimeException("OverBefore AddedMethod 3 failed");
103    }
104    {
105      if (OverBefore.AddedStaticMethod() != -2.0)
106        throw new RuntimeException("OverBefore AddedStaticMethod 1 failed");
107      if (OverBefore.AddedStaticMethod(-2) != -3.0)
108        throw new RuntimeException("OverBefore AddedStaticMethod 2 failed");
109      if (OverBefore.AddedStaticMethod(-10, -10.0) != -20)
110        throw new RuntimeException("OverBefore AddedStaticMethod 3 failed");
111    }
112    {
113      OverBefore ex = new OverBefore("hello");
114      if (ex.getI() != -2.0 && ex.getD() != -2.0)
115        throw new RuntimeException("OverBefore overload constructor 1 failed");
116
117      ex = new OverBefore("hello", 10);
118      if (ex.getI() != 10.0 && ex.getD() != -1.0)
119        throw new RuntimeException("OverBefore overload constructor 2 failed");
120
121      ex = new OverBefore("hello", 20, 30.0);
122      if (ex.getI() != 20 && ex.getD() != 30.0)
123        throw new RuntimeException("OverBefore overload constructor 3 failed");
124    }
125    {
126      OverBefore ex = new OverBefore("hello");
127      if (ex.AddedMethod("hello") != -2.0)
128        throw new RuntimeException("OverBefore overload AddedMethod 1 failed");
129      if (ex.AddedMethod("hello", -2) != -3.0)
130        throw new RuntimeException("OverBefore overload AddedMethod 2 failed");
131      if (ex.AddedMethod("hello", -10, -10.0) != -20)
132        throw new RuntimeException("OverBefore overload AddedMethod 3 failed");
133    }
134    {
135      if (OverBefore.AddedStaticMethod("hello") != -2.0)
136        throw new RuntimeException("OverBefore overload AddedStaticMethod 1 failed");
137      if (OverBefore.AddedStaticMethod("hello", -2) != -3.0)
138        throw new RuntimeException("OverBefore overload AddedStaticMethod 2 failed");
139      if (OverBefore.AddedStaticMethod("hello", -10, -10.0) != -20)
140        throw new RuntimeException("OverBefore overload AddedStaticMethod 3 failed");
141    }
142
143    // %extend after the class definition - with overloading and default args
144    {
145      OverAfter ex = new OverAfter();
146      if (ex.getI() != -1.0 && ex.getD() != -1.0)
147        throw new RuntimeException("OverAfter constructor 1 failed");
148
149      ex = new OverAfter(10);
150      if (ex.getI() != 10.0 && ex.getD() != -1.0)
151        throw new RuntimeException("OverAfter constructor 2 failed");
152
153      ex = new OverAfter(20, 30.0);
154      if (ex.getI() != 20 && ex.getD() != 30.0)
155        throw new RuntimeException("OverAfter constructor 3 failed");
156    }
157    {
158      OverAfter ex = new OverAfter();
159      if (ex.AddedMethod() != -2.0)
160        throw new RuntimeException("OverAfter AddedMethod 1 failed");
161      if (ex.AddedMethod(-2) != -3.0)
162        throw new RuntimeException("OverAfter AddedMethod 2 failed");
163      if (ex.AddedMethod(-10, -10.0) != -20)
164        throw new RuntimeException("OverAfter AddedMethod 3 failed");
165    }
166    {
167      if (OverAfter.AddedStaticMethod() != -2.0)
168        throw new RuntimeException("OverAfter AddedStaticMethod 1 failed");
169      if (OverAfter.AddedStaticMethod(-2) != -3.0)
170        throw new RuntimeException("OverAfter AddedStaticMethod 2 failed");
171      if (OverAfter.AddedStaticMethod(-10, -10.0) != -20)
172        throw new RuntimeException("OverAfter AddedStaticMethod 3 failed");
173    }
174    {
175      OverAfter ex = new OverAfter("hello");
176      if (ex.getI() != -2.0 && ex.getD() != -2.0)
177        throw new RuntimeException("OverAfter overload constructor 1 failed");
178
179      ex = new OverAfter("hello", 10);
180      if (ex.getI() != 10.0 && ex.getD() != -1.0)
181        throw new RuntimeException("OverAfter overload constructor 2 failed");
182
183      ex = new OverAfter("hello", 20, 30.0);
184      if (ex.getI() != 20 && ex.getD() != 30.0)
185        throw new RuntimeException("OverAfter overload constructor 3 failed");
186    }
187    {
188      OverAfter ex = new OverAfter("hello");
189      if (ex.AddedMethod("hello") != -2.0)
190        throw new RuntimeException("OverAfter overload AddedMethod 1 failed");
191      if (ex.AddedMethod("hello", -2) != -3.0)
192        throw new RuntimeException("OverAfter overload AddedMethod 2 failed");
193      if (ex.AddedMethod("hello", -10, -10.0) != -20)
194        throw new RuntimeException("OverAfter overload AddedMethod 3 failed");
195    }
196    {
197      if (OverAfter.AddedStaticMethod("hello") != -2.0)
198        throw new RuntimeException("OverAfter overload AddedStaticMethod 1 failed");
199      if (OverAfter.AddedStaticMethod("hello", -2) != -3.0)
200        throw new RuntimeException("OverAfter overload AddedStaticMethod 2 failed");
201      if (OverAfter.AddedStaticMethod("hello", -10, -10.0) != -20)
202        throw new RuntimeException("OverAfter overload AddedStaticMethod 3 failed");
203    }
204
205    // Override
206    {
207      Override o = new Override();
208
209      if (o.over() != -1)
210        throw new RuntimeException("override test 1 failed");
211      if (o.over(10) != 10*10)
212        throw new RuntimeException("override test 2 failed");
213
214      if (o.ride() != -1)
215        throw new RuntimeException("override test 3 failed");
216      if (o.ride(10) != 10)
217        throw new RuntimeException("override test 4 failed");
218
219      if (o.overload() != -10)
220        throw new RuntimeException("override test 5 failed");
221      if (o.overload(10) != 10*10)
222        throw new RuntimeException("override test 6 failed");
223    }
224  }
225}
226