summaryrefslogtreecommitdiff
path: root/test/ruby/test_marshal.rb
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-03 13:34:48 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-03 13:34:48 +0000
commit9f42dfa0123a704a2144727af7a14d0b5a17b431 (patch)
treef8e99f2380f1e382febef1c4bbfdbe1e7869a8aa /test/ruby/test_marshal.rb
parent87050da59fb29e098f32f5b941ea4091685c79ba (diff)
* test/ruby/test_dir.rb: add tests to achieve over 90% test coverage
of dir.c. * test/ruby/test_encoding.rb: add tests for dummy?, name_list and aliases. * test/ruby/test_marshal.rb: add some tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16797 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_marshal.rb')
-rw-r--r--test/ruby/test_marshal.rb68
1 files changed, 68 insertions, 0 deletions
diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb
index 3979e8a15f..2c69367e05 100644
--- a/test/ruby/test_marshal.rb
+++ b/test/ruby/test_marshal.rb
@@ -84,4 +84,72 @@ class TestMarshal < Test::Unit::TestCase
s2 = o2.str
assert_equal(s1, s2)
end
+
+ def test_pipe
+ o1 = C.new("a" * 10000)
+
+ r, w = IO.pipe
+ Marshal.dump(o1, w)
+ o2 = Marshal.load(r)
+ assert_equal(o1.str, o2.str)
+
+ r, w = IO.pipe
+ Marshal.dump(o1, w, 2)
+ o2 = Marshal.load(r)
+ assert_equal(o1.str, o2.str)
+
+ assert_raise(TypeError) { Marshal.dump("foo", Object.new) }
+ assert_raise(TypeError) { Marshal.load(Object.new) }
+ end
+
+ def test_limit
+ assert_equal([[[]]], Marshal.load(Marshal.dump([[[]]], 3)))
+ assert_raise(ArgumentError) { Marshal.dump([[[]]], 2) }
+ end
+
+ def test_userdef_invalid
+ o = C.new(nil)
+ assert_raise(TypeError) { Marshal.dump(o) }
+ end
+
+ def test_class
+ o = class << Object.new; self; end
+ assert_raise(TypeError) { Marshal.dump(o) }
+ assert_equal(Object, Marshal.load(Marshal.dump(Object)))
+ assert_equal(Enumerable, Marshal.load(Marshal.dump(Enumerable)))
+ end
+
+ class C2
+ def initialize(ary)
+ @ary = ary
+ end
+ def _dump(s)
+ @ary.clear
+ "foo"
+ end
+ end
+
+ def test_modify_array_during_dump
+ a = []
+ o = C2.new(a)
+ a << o << nil
+ assert_raise(RuntimeError) { Marshal.dump(a) }
+ end
+
+ def test_change_class_name
+ eval("class C3; def _dump(s); 'foo'; end; end")
+ m = Marshal.dump(C3.new)
+ assert_raise(TypeError) { Marshal.load(m) }
+ eval("C3 = nil")
+ assert_raise(TypeError) { Marshal.load(m) }
+ end
+
+ def test_change_struct
+ eval("C3 = Struct.new(:foo, :bar)")
+ m = Marshal.dump(C3.new("FOO", "BAR"))
+ eval("C3 = Struct.new(:foo)")
+ assert_raise(TypeError) { Marshal.load(m) }
+ eval("C3 = Struct.new(:foo, :baz)")
+ assert_raise(TypeError) { Marshal.load(m) }
+ end
end