test/test_blocker.rb in binaryparse-0.1.6 vs test/test_blocker.rb in binaryparse-0.2.0
- old
+ new
@@ -438,17 +438,64 @@
t2 = BBTimeRecord.new(buf)
assert(t2)
assert_nil(t2.t)
end
+ class BBPackNumRecord < BinaryBlocker::Blocker
+ has_one :p, :packed, :length => 2
+ end
+
+ def test_null_packed
+ t = BBPackNumRecord.new
+ assert(buf = t.block)
+
+ t2 = BBPackNumRecord.new(buf)
+ assert(t2)
+ assert_equal(0, t2.p)
+ end
+
+ def test_big_packed
+ t = BBPackNumRecord.new
+ t.p = 200
+ assert(buf = t.block)
+ assert_equal(1, buf.size)
+
+ t2 = BBPackNumRecord.new(buf)
+ assert(t2)
+ assert(t2.p < 100)
+ end
+
+ class Filler < BinaryBlocker::Blocker
+ has_one :f, :uint8
+ end
+
+ class NullFillerTest < BinaryBlocker::Blocker
+ has_fixed_array :fooboo, 3, [Filler]
+ end
+
+ def test_null_filler
+ t = NullFillerTest.new
+ assert(buf = t.block)
+ end
+
class BBSpaceString < BinaryBlocker::Blocker
has_one :name, :sstring, :length => 10
has_one :last, :string, :length => 5
end
def test_space_string
buf = "Name Last "
ss = BBSpaceString.new(buf)
assert(ss)
assert_equal("Name", ss.name)
+ end
+
+ class BBSubClass < BBSpaceString
+ end
+
+ def test_subclass
+ buf = "Name Last "
+ ss = BBSubClass.new(buf)
+ assert(ss)
+ #assert_equal("Name", ss.name)
end
end