Apply PIE to nghttpx
[platform/upstream/nghttp2.git] / third-party / mruby / mrbgems / mruby-objectspace / test / objectspace.rb
1 assert('ObjectSpace.count_objects') do
2   h = {}
3   f = Fiber.new {} if Object.const_defined?(:Fiber)
4   ObjectSpace.count_objects(h)
5   assert_kind_of(Hash, h)
6   assert_true(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) })
7   assert_true(h.values.all? {|x| x.is_a?(Integer) })
8
9   assert_true(h.has_key?(:TOTAL))
10   assert_true(h.has_key?(:FREE))
11   assert_true(h.has_key?(:T_FIBER)) if Object.const_defined? :Fiber
12
13   assert_equal(h[:TOTAL] * 2, h.values.reduce(:+))
14
15   h = ObjectSpace.count_objects
16   assert_kind_of(Hash, h)
17   assert_true(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) })
18   assert_true(h.values.all? {|x| x.is_a?(Integer) })
19
20   assert_raise(TypeError) { ObjectSpace.count_objects(1) }
21
22   h0 = {:T_FOO=>1000}
23   h = ObjectSpace.count_objects(h0)
24   assert_false(h0.has_key?(:T_FOO))
25
26   GC.start
27   h_after = {}
28   h_before = ObjectSpace.count_objects
29
30   objs = []
31   1000.times do
32     objs << {}
33   end
34   ObjectSpace.count_objects(h)
35   objs = nil
36   GC.start
37   ObjectSpace.count_objects(h_after)
38
39   assert_equal(h[:T_HASH], h_before[:T_HASH] + 1000)
40   assert_equal(h_after[:T_HASH], h_before[:T_HASH])
41 end
42
43 assert('ObjectSpace.each_object') do
44   objs = []
45   objs_count = ObjectSpace.each_object { |obj|
46     objs << obj
47   }
48   assert_equal objs.length, objs_count
49
50   arys = []
51   arys_count = ObjectSpace.each_object(Array) { |obj|
52     arys << obj
53   }
54   assert_equal arys.length, arys_count
55   assert_true arys.length < objs.length
56 end
57
58 assert 'Check class pointer of ObjectSpace.each_object.' do
59   ObjectSpace.each_object { |obj| !obj }
60 end