PageRenderTime 62ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/test/externals/ruby1.8/drb/test_drb.rb

https://bitbucket.org/nicksieger/jruby
Ruby | 301 lines | 248 code | 53 blank | 0 comment | 4 complexity | 4bd6160f51175bc3fa687e4dff90e1c2 MD5 | raw file
Possible License(s): GPL-3.0, JSON
  1. require 'drbtest'
  2. class TestDRbCore < Test::Unit::TestCase
  3. include DRbCore
  4. end
  5. class TestDRbYield < Test::Unit::TestCase
  6. def setup
  7. @ext = DRbService.ext_service('ut_drb.rb')
  8. @there = @ext.front
  9. end
  10. def teardown
  11. @ext.stop_service if @ext
  12. end
  13. def test_01_one
  14. @there.echo_yield_1([]) {|one|
  15. assert_equal([], one)
  16. }
  17. @there.echo_yield_1(1) {|one|
  18. assert_equal(1, one)
  19. }
  20. @there.echo_yield_1(nil) {|one|
  21. assert_equal(nil, one)
  22. }
  23. end
  24. def test_02_two
  25. @there.echo_yield_2([], []) {|one, two|
  26. assert_equal([], one)
  27. assert_equal([], two)
  28. }
  29. @there.echo_yield_2(1, 2) {|one, two|
  30. assert_equal(1, one)
  31. assert_equal(2, two)
  32. }
  33. @there.echo_yield_2(3, nil) {|one, two|
  34. assert_equal(3, one)
  35. assert_equal(nil, two)
  36. }
  37. @there.echo_yield_1([:key, :value]) {|one, two|
  38. assert_equal(:key, one)
  39. assert_equal(:value, two)
  40. }
  41. end
  42. def test_03_many
  43. @there.echo_yield_0 {|*s|
  44. assert_equal([], s)
  45. }
  46. @there.echo_yield(nil) {|*s|
  47. assert_equal([nil], s)
  48. }
  49. @there.echo_yield(1) {|*s|
  50. assert_equal([1], s)
  51. }
  52. @there.echo_yield(1, 2) {|*s|
  53. assert_equal([1, 2], s)
  54. }
  55. @there.echo_yield(1, 2, 3) {|*s|
  56. assert_equal([1, 2, 3], s)
  57. }
  58. @there.echo_yield([], []) {|*s|
  59. assert_equal([[], []], s)
  60. }
  61. @there.echo_yield([]) {|*s|
  62. assert_equal([[]], s) # !
  63. }
  64. end
  65. def test_04_many_to_one
  66. @there.echo_yield_0 {|*s|
  67. assert_equal([], s)
  68. }
  69. @there.echo_yield(nil) {|*s|
  70. assert_equal([nil], s)
  71. }
  72. @there.echo_yield(1) {|*s|
  73. assert_equal([1], s)
  74. }
  75. @there.echo_yield(1, 2) {|*s|
  76. assert_equal([1, 2], s)
  77. }
  78. @there.echo_yield(1, 2, 3) {|*s|
  79. assert_equal([1, 2, 3], s)
  80. }
  81. @there.echo_yield([], []) {|*s|
  82. assert_equal([[], []], s)
  83. }
  84. @there.echo_yield([]) {|*s|
  85. assert_equal([[]], s)
  86. }
  87. end
  88. def test_05_array_subclass
  89. @there.xarray_each {|x| assert_kind_of(XArray, x)}
  90. @there.xarray_each {|*x| assert_kind_of(XArray, x[0])}
  91. end
  92. def test_06_taint
  93. x = proc {}
  94. assert(! x.tainted?)
  95. @there.echo_yield(x) {|o|
  96. assert_equal(x, o)
  97. assert(! x.tainted?)
  98. }
  99. end
  100. end
  101. class TestRubyYield < TestDRbYield
  102. def echo_yield(*arg)
  103. yield(*arg)
  104. end
  105. def echo_yield_0
  106. yield
  107. end
  108. def echo_yield_1(a)
  109. yield(a)
  110. end
  111. def echo_yield_2(a, b)
  112. yield(a, b)
  113. end
  114. def xarray_each
  115. xary = [XArray.new([0])]
  116. xary.each do |x|
  117. yield(x)
  118. end
  119. end
  120. def setup
  121. @there = self
  122. end
  123. def teardown
  124. end
  125. end
  126. class TestRuby18Yield < TestRubyYield
  127. class YieldTest18
  128. def echo_yield(*arg, &proc)
  129. proc.call(*arg)
  130. end
  131. def echo_yield_0(&proc)
  132. proc.call
  133. end
  134. def echo_yield_1(a, &proc)
  135. proc.call(a)
  136. end
  137. def echo_yield_2(a, b, &proc)
  138. proc.call(a, b)
  139. end
  140. def xarray_each(&proc)
  141. xary = [XArray.new([0])]
  142. xary.each(&proc)
  143. end
  144. end
  145. def setup
  146. @there = YieldTest18.new
  147. end
  148. end
  149. class TestDRbAry < Test::Unit::TestCase
  150. include DRbAry
  151. end
  152. class TestDRbMServer < Test::Unit::TestCase
  153. def setup
  154. @ext = DRbService.ext_service('ut_drb.rb')
  155. @there = @ext.front
  156. @server = (1..3).collect do |n|
  157. DRb::DRbServer.new(nil, Onecky.new(n.to_s))
  158. end
  159. end
  160. def teardown
  161. @server.each do |s|
  162. s.stop_service
  163. end
  164. @ext.stop_service if @ext
  165. end
  166. def test_01
  167. assert_equal(6, @there.sample(@server[0].front, @server[1].front, @server[2].front))
  168. end
  169. end
  170. class TestDRbSafe1 < TestDRbAry
  171. def setup
  172. @ext = DRbService.ext_service('ut_safe1.rb')
  173. @there = @ext.front
  174. end
  175. end
  176. class TestDRbEval < Test::Unit::TestCase
  177. def setup
  178. super
  179. @ext = DRbService.ext_service('ut_eval.rb')
  180. @there = @ext.front
  181. end
  182. def teardown
  183. @ext.stop_service if @ext
  184. end
  185. def test_01_safe1_safe4_eval
  186. assert_raises(SecurityError) do
  187. @there.method_missing(:instance_eval, 'ENV.inspect')
  188. end
  189. assert_raises(SecurityError) do
  190. @there.method_missing(:send, :eval, 'ENV.inspect')
  191. end
  192. remote_class = @there.remote_class
  193. assert_raises(SecurityError) do
  194. remote_class.class_eval('ENV.inspect')
  195. end
  196. assert_raises(SecurityError) do
  197. remote_class.module_eval('ENV.inspect')
  198. end
  199. four = @there.four
  200. assert_equal(1, four.method_missing(:send, :eval, '1'))
  201. remote_class = four.remote_class
  202. assert_equal(1, remote_class.class_eval('1'))
  203. assert_equal(1, remote_class.module_eval('1'))
  204. assert_raises(SecurityError) do
  205. remote_class.class_eval('ENV = {}')
  206. end
  207. assert_raises(SecurityError) do
  208. remote_class.module_eval('ENV = {}')
  209. end
  210. end
  211. end
  212. class TestDRbLarge < Test::Unit::TestCase
  213. def setup
  214. @ext = DRbService.ext_service('ut_large.rb')
  215. @there = @ext.front
  216. end
  217. def teardown
  218. @ext.stop_service if @ext
  219. end
  220. def test_01_large_ary
  221. ary = [2] * 10240
  222. assert_equal(10240, @there.size(ary))
  223. assert_equal(20480, @there.sum(ary))
  224. end
  225. def test_02_large_ary
  226. ary = ["Hello, World"] * 10240
  227. assert_equal(10240, @there.size(ary))
  228. end
  229. def test_03_large_ary
  230. ary = [Thread.current] * 10240
  231. assert_equal(10240, @there.size(ary))
  232. end
  233. def test_04_many_arg
  234. assert_raises(ArgumentError) {
  235. @there.arg_test(1, 2, 3, 4, 5, 6, 7, 8, 9, 0)
  236. }
  237. end
  238. def test_05_too_large_ary
  239. ary = ["Hello, World"] * 102400
  240. exception = nil
  241. begin
  242. @there.size(ary)
  243. rescue StandardError
  244. exception = $!
  245. end
  246. assert_kind_of(StandardError, exception)
  247. end
  248. end