Initial commit.
[ruby-eet.git] / test / test_basic.rb
1 # $Id: test_basic.rb 1 2005-03-26 01:45:38Z tilman $
2
3 require "eet"
4 require "test/unit"
5 require "common"
6
7 class BasicTestData
8         def initialize
9                 @name = "moo"
10                 @short = 512
11                 @int = 1024
12                 @long_long = (2 << 63) - 1
13                 @flag = true
14                 @float = 1234.0
15                 @double = 12341234.0
16         end
17
18         private
19         def to_eet_name
20                 "BasicTest"
21         end
22
23         def to_eet_properties
24                 {"name" => [@name],
25                  "i16" => [@short, :short],
26                  "i32" => [@int],
27                  "i64" => [@long_long, :long_long],
28                  "flag" => [@flag],
29                  "f32" => [@float],
30                  "f64" => [@double, :double]}
31         end
32 end
33
34 class BasicTest < Test::Unit::TestCase
35         def test_basic
36                 data = BasicTestData.new.to_eet
37                 assert_not_nil(data)
38
39                 stream = nil
40
41                 assert_nothing_raised do
42                         stream = Eet::Stream.deserialize(data)
43                 end
44
45                 assert_equal(1, stream.length)
46                 assert_equal("BasicTest", stream.first.tag)
47
48                 assert_nothing_raised do
49                         stream = Eet::Stream.deserialize(stream.first.data)
50                 end
51
52                 assert_equal(7, stream.length)
53
54                 values = {"name" => "moo\0",
55                           "i16" => "\0\2", "i32" => "\0\4\0\0",
56                           "i64" => "\377" * 8, "flag" => "\1",
57                           "f32" => "1234." + ("0" * 16) + "\0",
58                           "f64" => "12341234." + ("0" * 32) + "\0"}
59                 values.each do |k, v|
60                         found = stream.find { |c| c.tag == k }
61                         assert_not_nil(found, "chunk not found - #{k}")
62                         assert_equal(v, found.data)
63                         stream.delete(found)
64                 end
65
66                 assert_equal([], stream)
67         end
68 end