Code cleanup.
[ruby-eet.git] / test / test_stream.rb
1 # $Id: test_stream.rb 1 2005-03-26 01:45:38Z tilman $
2
3 require "eet"
4 require "test/unit"
5
6 class StreamTest < Test::Unit::TestCase
7         def setup
8                 stream = Eet::Stream.new
9                 stream << Eet::Chunk.new("tag", "foo")
10                 stream << Eet::Chunk.new("tag2", "bar")
11                 stream << Eet::Chunk.new("tag23", "baz")
12
13                 @data = stream.serialize
14                 assert_not_nil(@data)
15         end
16
17         def test_serialize
18                 assert_equal("CHnK\007\0\0\0tag\0foo" +
19                              "CHnK\010\0\0\0tag2\0bar" +
20                              "CHnK\011\0\0\0tag23\0baz", @data)
21         end
22
23         def test_deserialize
24                 stream = nil
25
26                 assert_nothing_raised do
27                         stream = Eet::Stream.deserialize(@data)
28                 end
29
30                 assert_equal(3, stream.length)
31
32                 values = {"tag" => "foo", "tag2" => "bar", "tag23" => "baz"}
33                 values.each do |k, v|
34                         found = stream.find { |c| c.tag == k }
35                         assert_not_nil(found, "chunk not found - #{k}")
36                         assert_equal(found.data, v)
37                         stream.delete(found)
38                 end
39
40                 assert_equal([], stream)
41         end
42 end