PageRenderTime 22ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/ruby/li_std_string_runme.rb

#
Ruby | 144 lines | 94 code | 30 blank | 20 comment | 29 complexity | 097769976e40afdf3bfed1c4a689674f MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. #!/usr/bin/env ruby
  2. #
  3. # Put description here
  4. #
  5. #
  6. #
  7. #
  8. #
  9. require 'swig_assert'
  10. require 'li_std_string'
  11. include Li_std_string
  12. # Checking expected use of %typemap(in) std::string {}
  13. test_value("Fee")
  14. # Checking expected result of %typemap(out) std::string {}
  15. raise RuntimeError unless test_value("Fi") == "Fi"
  16. # Verify type-checking for %typemap(in) std::string {}
  17. exceptionRaised = false
  18. begin
  19. test_value(0)
  20. rescue TypeError
  21. exceptionRaised = true
  22. ensure
  23. raise RuntimeError unless exceptionRaised
  24. end
  25. # Checking expected use of %typemap(in) const std::string & {}
  26. test_const_reference("Fo")
  27. # Checking expected result of %typemap(out) const std::string& {}
  28. raise RuntimeError unless test_const_reference("Fum") == "Fum"
  29. # Verify type-checking for %typemap(in) const std::string & {}
  30. exceptionRaised = false
  31. begin
  32. test_const_reference(0)
  33. rescue TypeError
  34. exceptionRaised = true
  35. ensure
  36. raise RuntimeError unless exceptionRaised
  37. end
  38. #
  39. # Input and output typemaps for pointers and non-const references to
  40. # std::string are *not* supported; the following tests confirm
  41. # that none of these cases are slipping through.
  42. #
  43. exceptionRaised = false
  44. begin
  45. test_pointer("foo")
  46. rescue TypeError
  47. exceptionRaised = true
  48. ensure
  49. raise RuntimeError unless exceptionRaised
  50. end
  51. result = test_pointer_out()
  52. raise RuntimeError if result.is_a? String
  53. exceptionRaised = false
  54. begin
  55. test_const_pointer("bar")
  56. rescue TypeError
  57. exceptionRaised = true
  58. ensure
  59. raise RuntimeError unless exceptionRaised
  60. end
  61. result = test_const_pointer_out()
  62. raise RuntimeError if result.is_a? String
  63. exceptionRaised = false
  64. begin
  65. test_reference("foo")
  66. rescue TypeError
  67. exceptionRaised = true
  68. ensure
  69. raise RuntimeError unless exceptionRaised
  70. end
  71. result = test_reference_out()
  72. raise RuntimeError if result.is_a? String
  73. # Member Strings
  74. myStructure = Structure.new
  75. if (myStructure.MemberString2 != "member string 2")
  76. raise RuntimeError
  77. end
  78. s = "Hello"
  79. myStructure.MemberString2 = s
  80. if (myStructure.MemberString2 != s)
  81. raise RuntimeError
  82. end
  83. if (myStructure.ConstMemberString != "const member string")
  84. raise RuntimeError
  85. end
  86. if (Structure.StaticMemberString2 != "static member string 2")
  87. raise RuntimeError
  88. end
  89. Structure.StaticMemberString2 = s
  90. if (Structure.StaticMemberString2 != s)
  91. raise RuntimeError
  92. end
  93. if (Structure.ConstStaticMemberString != "const static member string")
  94. raise RuntimeError
  95. end
  96. if (test_reference_input("hello") != "hello")
  97. raise RuntimeError
  98. end
  99. s = test_reference_inout("hello")
  100. if (s != "hellohello")
  101. raise RuntimeError
  102. end
  103. if (stdstring_empty() != "")
  104. raise RuntimeError
  105. end
  106. if (c_empty() != "")
  107. raise RuntimeError
  108. end
  109. if (c_null() != nil)
  110. raise RuntimeError
  111. end
  112. if (get_null(c_null()) != nil)
  113. raise RuntimeError
  114. end