ruby: streaming deserializer test

This commit is contained in:
frsyuki 2010-04-23 20:18:48 +09:00
parent b10a736744
commit c9fcf4020f

View File

@ -204,9 +204,11 @@ class MessagePackTestFormat < Test::Unit::TestCase
it "gc mark" do it "gc mark" do
obj = [{["a","b"]=>["c","d"]}, ["e","f"], "d"] obj = [{["a","b"]=>["c","d"]}, ["e","f"], "d"]
num = 4
raw = obj.to_msgpack * num
pac = MessagePack::Unpacker.new pac = MessagePack::Unpacker.new
parsed = 0 parsed = 0
obj.to_msgpack.split(//).each do |b| raw.split(//).each do |b|
pac.feed(b) pac.feed(b)
pac.each {|o| pac.each {|o|
GC.start GC.start
@ -215,16 +217,18 @@ class MessagePackTestFormat < Test::Unit::TestCase
} }
GC.start GC.start
end end
assert_equal(parsed, 1) assert_equal(parsed, num)
end end
it "streaming backward compatibility" do it "streaming backward compatibility" do
obj = [{["a","b"]=>["c","d"]}, ["e","f"], "d"] obj = [{["a","b"]=>["c","d"]}, ["e","f"], "d"]
num = 4
raw = obj.to_msgpack * num
pac = MessagePack::Unpacker.new pac = MessagePack::Unpacker.new
buffer = "" buffer = ""
nread = 0 nread = 0
parsed = 0 parsed = 0
obj.to_msgpack.split(//).each do |b| raw.split(//).each do |b|
buffer << b buffer << b
nread = pac.execute(buffer, nread) nread = pac.execute(buffer, nread)
if pac.finished? if pac.finished?
@ -237,7 +241,7 @@ class MessagePackTestFormat < Test::Unit::TestCase
next unless buffer.empty? next unless buffer.empty?
end end
end end
assert_equal(parsed, 1) assert_equal(parsed, num)
end end
private private