2010-08-14 05:01:12 -04:00
|
|
|
require "test/unit"
|
|
|
|
require "objspace"
|
2011-12-15 03:57:01 -05:00
|
|
|
require_relative "../ruby/envutil"
|
2010-08-14 05:01:12 -04:00
|
|
|
|
|
|
|
class TestObjSpace < Test::Unit::TestCase
|
|
|
|
def test_memsize_of
|
|
|
|
assert_equal(0, ObjectSpace.memsize_of(true))
|
2010-10-27 14:16:39 -04:00
|
|
|
assert_equal(0, ObjectSpace.memsize_of(nil))
|
|
|
|
assert_equal(0, ObjectSpace.memsize_of(1))
|
2010-08-14 05:01:12 -04:00
|
|
|
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)))
|
2011-12-14 23:15:54 -05:00
|
|
|
|
|
|
|
assert_operator(ObjectSpace.memsize_of(Regexp.new("(a)"*1000).match("a"*1000)),
|
|
|
|
:>,
|
|
|
|
ObjectSpace.memsize_of(//.match("")))
|
2010-08-14 05:01:12 -04:00
|
|
|
end
|
|
|
|
|
2011-12-15 03:57:01 -05:00
|
|
|
def test_argf_memsize
|
|
|
|
size = ObjectSpace.memsize_of(ARGF)
|
|
|
|
assert_kind_of(Integer, size)
|
|
|
|
assert_operator(size, :>, 0)
|
|
|
|
argf = ARGF.dup
|
|
|
|
argf.inplace_mode = nil
|
|
|
|
size = ObjectSpace.memsize_of(argf)
|
|
|
|
argf.inplace_mode = "inplace_mode_suffix"
|
|
|
|
assert_equal(size + 20, ObjectSpace.memsize_of(argf))
|
|
|
|
end
|
|
|
|
|
2010-10-28 16:23:21 -04:00
|
|
|
def test_memsize_of_all
|
|
|
|
assert_kind_of(Integer, a = ObjectSpace.memsize_of_all)
|
|
|
|
assert_kind_of(Integer, b = ObjectSpace.memsize_of_all(String))
|
|
|
|
assert(a > b)
|
|
|
|
assert(a > 0)
|
|
|
|
assert(b > 0)
|
|
|
|
assert_raise(TypeError) {ObjectSpace.memsize_of_all('error')}
|
2010-10-27 14:16:39 -04:00
|
|
|
end
|
|
|
|
|
2010-08-14 05:01:12 -04:00
|
|
|
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
|