1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/objspace/test_objspace.rb
ko1 b36aa7af03 * ext/objspace/objspace.c (memsize_of): fix rdoc.
* ext/objspace/objspace.c (total_memsize_of_all_objects): added.
* test/objspace/test_objspace.rb:
  - add a test for ObjectSpace.total_memsize_of_all_objects.
  - add two tests for ObjectSpace.memsize_of (for nil and Fixnum).



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29614 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-27 18:16:39 +00:00

50 lines
1.5 KiB
Ruby

require "test/unit"
require "objspace"
class TestObjSpace < Test::Unit::TestCase
def test_memsize_of
assert_equal(0, ObjectSpace.memsize_of(true))
assert_equal(0, ObjectSpace.memsize_of(nil))
assert_equal(0, ObjectSpace.memsize_of(1))
assert_kind_of(Integer, ObjectSpace.memsize_of(Object.new))
assert_kind_of(Integer, ObjectSpace.memsize_of(Class))
assert_kind_of(Integer, ObjectSpace.memsize_of(""))
assert_kind_of(Integer, ObjectSpace.memsize_of([]))
assert_kind_of(Integer, ObjectSpace.memsize_of({}))
assert_kind_of(Integer, ObjectSpace.memsize_of(//))
f = File.new(__FILE__)
assert_kind_of(Integer, ObjectSpace.memsize_of(f))
f.close
assert_kind_of(Integer, ObjectSpace.memsize_of(/a/.match("a")))
assert_kind_of(Integer, ObjectSpace.memsize_of(Struct.new(:a)))
end
def test_total_memsize_of_all_objects
assert_kind_of(Integer, ObjectSpace.total_memsize_of_all_objects)
end
def test_count_objects_size
res = ObjectSpace.count_objects_size
assert_equal(false, res.empty?)
assert_equal(true, res[:TOTAL] > 0)
arg = {}
ObjectSpace.count_objects_size(arg)
assert_equal(false, arg.empty?)
end
def test_count_nodes
res = ObjectSpace.count_nodes
assert_equal(false, res.empty?)
arg = {}
ObjectSpace.count_nodes(arg)
assert_equal(false, arg.empty?)
end
def test_count_tdata_objects
res = ObjectSpace.count_tdata_objects
assert_equal(false, res.empty?)
arg = {}
ObjectSpace.count_tdata_objects(arg)
assert_equal(false, arg.empty?)
end
end