~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to test/ruby/test_marshal.rb

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-01-24 11:42:29 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20080124114229-jw2f87rdxlq6gp11
Tags: 1.9.0.0-2ubuntu1
* Merge from debian unstable, remaining changes:
  - Robustify check for target_os, fixing build failure on lpia.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
  def test_marshal_cloned_class
37
37
    assert_instance_of(StrClone, Marshal.load(Marshal.dump(StrClone.new("abc"))))
38
38
  end
 
39
 
 
40
  def test_inconsistent_struct
 
41
    TestMarshal.const_set :StructOrNot, Struct.new(:a)
 
42
    s = Marshal.dump(StructOrNot.new(1))
 
43
    TestMarshal.instance_eval { remove_const :StructOrNot }
 
44
    TestMarshal.const_set :StructOrNot, Class.new
 
45
    assert_raise(TypeError, "[ruby-dev:31709]") { Marshal.load(s) }
 
46
  end
 
47
 
 
48
  def test_struct_invalid_members
 
49
    TestMarshal.const_set :StructInvalidMembers, Struct.new(:a)
 
50
    Marshal.load("\004\bIc&TestMarshal::StructInvalidMembers\006:\020__members__\"\bfoo")
 
51
    assert_raise(TypeError, "[ruby-dev:31759]") {
 
52
      TestMarshal::StructInvalidMembers.members
 
53
    }
 
54
  end
 
55
 
 
56
  class C
 
57
    def initialize(str)
 
58
      @str = str
 
59
    end
 
60
    def _dump(limit)
 
61
      @str
 
62
    end
 
63
    def self._load(s)
 
64
      new(s)
 
65
    end
 
66
  end
 
67
 
 
68
  def test_too_long_string
 
69
    (data = Marshal.dump(C.new("a")))[-2, 1] = "\003\377\377\377"
 
70
    e = assert_raise(ArgumentError, "[ruby-dev:32054]") {
 
71
      Marshal.load(data)
 
72
    }
 
73
    assert_equal("marshal data too short", e.message)
 
74
  end
39
75
end