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