PageRenderTime 27ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 68 lines | 48 code | 13 blank | 7 comment | 10 complexity | 04ee6bee188e3e29f755b8eab57e62ab MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. // This is the union runtime testcase. It ensures that values within a
  2. // union embedded within a struct can be set and read correctly.
  3. import unions.*;
  4. public class unions_runme {
  5. static {
  6. try {
  7. System.loadLibrary("unions");
  8. } catch (UnsatisfiedLinkError e) {
  9. 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);
  10. System.exit(1);
  11. }
  12. }
  13. public static void main(String argv[]) {
  14. // Create new instances of SmallStruct and BigStruct for later use
  15. SmallStruct small = new SmallStruct();
  16. small.setJill((short)200);
  17. BigStruct big = new BigStruct();
  18. big.setSmallstruct(small);
  19. big.setJack(300);
  20. // Use SmallStruct then BigStruct to setup EmbeddedUnionTest.
  21. // Ensure values in EmbeddedUnionTest are set correctly for each.
  22. EmbeddedUnionTest eut = new EmbeddedUnionTest();
  23. // First check the SmallStruct in EmbeddedUnionTest
  24. eut.setNumber(1);
  25. eut.getUni().setSmall(small);
  26. short Jill1 = eut.getUni().getSmall().getJill();
  27. if (Jill1 != 200) {
  28. System.err.println("Runtime test1 failed. eut.uni.small.jill=" + Jill1);
  29. System.exit(1);
  30. }
  31. int Num1 = eut.getNumber();
  32. if (Num1 != 1) {
  33. System.err.println("Runtime test2 failed. eut.number=" + Num1);
  34. System.exit(1);
  35. }
  36. // Secondly check the BigStruct in EmbeddedUnionTest
  37. eut.setNumber(2);
  38. eut.getUni().setBig(big);
  39. int Jack1 = eut.getUni().getBig().getJack();
  40. if (Jack1 != 300) {
  41. System.err.println("Runtime test3 failed. eut.uni.big.jack=" + Jack1);
  42. System.exit(1);
  43. }
  44. short Jill2 = eut.getUni().getBig().getSmallstruct().getJill();
  45. if (Jill2 != 200) {
  46. System.err.println("Runtime test4 failed. eut.uni.big.smallstruct.jill=" + Jill2);
  47. System.exit(1);
  48. }
  49. int Num2 = eut.getNumber();
  50. if (Num2 != 2) {
  51. System.err.println("Runtime test5 failed. eut.number=" + Num2);
  52. System.exit(1);
  53. }
  54. }
  55. }