PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-29/SWIG/Examples/test-suite/ruby/unions_runme.rb

#
Ruby | 54 lines | 36 code | 11 blank | 7 comment | 10 complexity | 53a744e1e048d1ff61a0344bfc78e32a 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. require 'unions'
  4. # Create new instances of SmallStruct and BigStruct for later use
  5. small = Unions::SmallStruct.new()
  6. small.jill = 200
  7. big = Unions::BigStruct.new()
  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.new()
  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. print "Runtime test1 failed. eut.uni.small.jill=" , Jill1 , "\n"
  19. exit 1
  20. end
  21. Num1 = eut.number
  22. if (Num1 != 1)
  23. print "Runtime test2 failed. eut.number=" , Num1 , "\n"
  24. exit 1
  25. end
  26. # Secondly check the BigStruct in EmbeddedUnionTest
  27. eut.number = 2
  28. eut.uni.big = big
  29. Jack1 = eut.uni.big.jack
  30. if (Jack1 != 300)
  31. print "Runtime test3 failed. eut.uni.big.jack=" , Jack1 , "\n"
  32. exit 1
  33. end
  34. Jill2 = eut.uni.big.smallstruct.jill
  35. if (Jill2 != 200)
  36. print "Runtime test4 failed. eut.uni.big.smallstruct.jill=" , Jill2 , "\n"
  37. exit 1
  38. end
  39. Num2 = eut.number
  40. if (Num2 != 2)
  41. print "Runtime test5 failed. eut.number=" , Num2 , "\n"
  42. exit 1
  43. end