/tags/rel-1-3-30/SWIG/Examples/test-suite/java/aggregate_runme.java

# · Java · 39 lines · 27 code · 10 blank · 2 comment · 8 complexity · bccebcaf50a8a0bda48c9f33eb672200 MD5 · raw file

  1. import aggregate.*;
  2. public class aggregate_runme {
  3. static {
  4. try {
  5. System.loadLibrary("aggregate");
  6. } catch (UnsatisfiedLinkError e) {
  7. 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);
  8. System.exit(1);
  9. }
  10. }
  11. public static void main(String argv[]) {
  12. // Confirm that move() returns correct results under normal use
  13. int result = aggregate.move(aggregate.UP);
  14. if (result != aggregate.UP) throw new RuntimeException("UP failed");
  15. result = aggregate.move(aggregate.DOWN);
  16. if (result != aggregate.DOWN) throw new RuntimeException("DOWN failed");
  17. result = aggregate.move(aggregate.LEFT);
  18. if (result != aggregate.LEFT) throw new RuntimeException("LEFT failed");
  19. result = aggregate.move(aggregate.RIGHT);
  20. if (result != aggregate.RIGHT) throw new RuntimeException("RIGHT failed");
  21. // Confirm that move() raises an exception when the contract is violated
  22. try {
  23. aggregate.move(0);
  24. throw new RuntimeException("0 test failed");
  25. }
  26. catch (IllegalArgumentException e) {
  27. }
  28. }
  29. }