PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/rel-1.3.35/Examples/test-suite/ruby/default_constructor_runme.rb

#
Ruby | 153 lines | 62 code | 22 blank | 69 comment | 0 complexity | 53328cc290059006a13ebd9ab3058cda 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 'default_constructor'
  11. include Default_constructor
  12. # Ruby 1.6 raises NameError if you try to call Class.new where no constructor
  13. # is defined; Ruby 1.7 changed this to NoMethodError
  14. NoConstructorError = Kernel.const_defined?("NoMethodError") ? NoMethodError : NameError
  15. # This should be no problem
  16. a = A.new
  17. # Nor should this
  18. aa = AA.new
  19. # The default constructor for B is private, so this should raise an exception
  20. begin
  21. b = B.new
  22. rescue ArgumentError
  23. # pass
  24. rescue TypeError
  25. # In Ruby 1.8 the exception raised is:
  26. # TypeError: allocator undefined for Default_constructor::BB
  27. exceptionRaised = true
  28. end
  29. # The two-argument constructor for B should work
  30. b = B.new(3, 4)
  31. # BB shouldn't inherit B's default constructor, so this should raise an exception
  32. begin
  33. bb = BB.new
  34. puts "Whoa. new BB created."
  35. rescue NoConstructorError
  36. # pass
  37. rescue TypeError
  38. # In Ruby 1.8 the exception raised is:
  39. # TypeError: allocator undefined for Default_constructor::BB
  40. exceptionRaised = true
  41. end
  42. # C's constructor is protected, so this should raise an exception
  43. begin
  44. c = C.new
  45. print "Whoa. new C created."
  46. rescue NoConstructorError
  47. # pass
  48. rescue TypeError
  49. # In Ruby 1.8 the exception raised is:
  50. # TypeError: allocator undefined for Default_constructor::C
  51. # pass
  52. rescue TypeError
  53. # In Ruby 1.8 the exception raised is:
  54. # TypeError: allocator undefined for Default_constructor::C
  55. # pass
  56. end
  57. # CC gets a default constructor, so no problem here
  58. cc = CC.new
  59. # D's constructor is private, so this should fail
  60. begin
  61. d = D.new
  62. puts "Whoa. new D created"
  63. rescue NoConstructorError
  64. # pass
  65. rescue TypeError
  66. # In Ruby 1.8 the exception raised is:
  67. # TypeError: allocator undefined for Default_constructor::D
  68. # pass
  69. end
  70. # DD shouldn't get a default constructor, so this should fail
  71. begin
  72. dd = DD.new
  73. puts "Whoa. new DD created"
  74. rescue NoConstructorError
  75. # pass
  76. rescue TypeError
  77. # In Ruby 1.8 the exception raised is:
  78. # TypeError: allocator undefined for Default_constructor::DD
  79. # pass
  80. rescue TypeError
  81. # In Ruby 1.8 the exception raised is:
  82. # TypeError: allocator undefined for Default_constructor::D
  83. # pass
  84. rescue TypeError
  85. # In Ruby 1.8 the exception raised is:
  86. # TypeError: allocator undefined for Default_constructor::DD
  87. # pass
  88. end
  89. # AD shouldn't get a default constructor, so this should fail
  90. begin
  91. ad = AD.new
  92. puts "Whoa. new AD created"
  93. rescue NoConstructorError
  94. # pass
  95. rescue TypeError
  96. # In Ruby 1.8 the exception raised is:
  97. # TypeError: allocator undefined for Default_constructor::AD
  98. # pass
  99. rescue TypeError
  100. # In Ruby 1.8 the exception raised is:
  101. # TypeError: allocator undefined for Default_constructor::AD
  102. # pass
  103. end
  104. # Both of the arguments to E's constructor have default values,
  105. # so this should be fine.
  106. e = E.new
  107. # EE should get a default constructor
  108. ee = EE.new
  109. # EB should not get a default constructor (because B doesn't have one)
  110. begin
  111. eb = EB.new
  112. puts "Whoa. new EB created"
  113. rescue NoConstructorError
  114. # pass
  115. rescue TypeError
  116. # In Ruby 1.8 the exception raised is:
  117. # TypeError: allocator undefined for Default_constructor::EB
  118. # pass
  119. rescue TypeError
  120. # In Ruby 1.8 the exception raised is:
  121. # TypeError: allocator undefined for Default_constructor::EB
  122. # pass
  123. end
  124. # This should work fine
  125. f = F.new
  126. # This should work fine
  127. ff = FFF.new
  128. # This should work fine
  129. g = G.new
  130. # This should work fine
  131. gg = GG.new