summaryrefslogtreecommitdiff
path: root/test/objspace
diff options
context:
space:
mode:
authornari <nari@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-14 09:01:12 +0000
committernari <nari@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-08-14 09:01:12 +0000
commite5731864074cc642c2b4e77d74334ca2b72302d8 (patch)
tree44beb4f72190f252712644ac2a364abbe3d715b5 /test/objspace
parentdccf9e0c45f1f450d28ba0700dbb459247ba9f9d (diff)
* test/objspace/test_objspace.rb: added test for objspace.
* ext/objspace/objspace.c: considers T_ZOMBIE by lazy sweep GC. * gc.c: considers that dsize was 0. [ruby-dev:42022] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/objspace')
-rw-r--r--test/objspace/test_objspace.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb
new file mode 100644
index 0000000..cfdb485
--- /dev/null
+++ b/test/objspace/test_objspace.rb
@@ -0,0 +1,44 @@
+require "test/unit"
+require "objspace"
+
+class TestObjSpace < Test::Unit::TestCase
+ def test_memsize_of
+ assert_equal(0, ObjectSpace.memsize_of(true))
+ 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_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