PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/trunk/Examples/test-suite/octave/unions_runme.m

#
MATLAB | 49 lines | 38 code | 11 blank | 0 comment | 7 complexity | eb5f9236f4721e9773924261d7c6b97e 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. unions
  4. # Create new instances of SmallStruct and BigStruct for later use
  5. small = unions.SmallStruct();
  6. small.jill = 200;
  7. big = unions.BigStruct();
  8. big.smallstruct = small;
  9. big.jack = 300;
  10. # Use SmallStruct then BigStruct to setup EmbeddedUnionTest.
  11. # Ensure values in EmbeddedUnionTest are set correctly for each.
  12. eut = unions.EmbeddedUnionTest();
  13. # First check the SmallStruct in EmbeddedUnionTest
  14. eut.number = 1;
  15. eut.uni.small = small;
  16. Jill1 = eut.uni.small.jill;
  17. if (Jill1 != 200)
  18. error("Runtime test1 failed. eut.uni.small.jill=%i" , Jill1)
  19. endif
  20. Num1 = eut.number;
  21. if (Num1 != 1)
  22. error("Runtime test2 failed. eut.number=%i" , Num1)
  23. endif
  24. # Secondly check the BigStruct in EmbeddedUnionTest
  25. eut.number = 2;
  26. eut.uni.big = big;
  27. Jack1 = eut.uni.big.jack;
  28. if (Jack1 != 300)
  29. error("Runtime test3 failed. eut.uni.big.jack=%i" , Jack1)
  30. endif
  31. Jill2 = eut.uni.big.smallstruct.jill;
  32. if (Jill2 != 200)
  33. error("Runtime test4 failed. eut.uni.big.smallstruct.jill=%i" , Jill2)
  34. endif
  35. Num2 = eut.number;
  36. if (Num2 != 2)
  37. error("Runtime test5 failed. eut.number=%i" , Num2)
  38. endif