test/test_blocker.rb in binaryparse-0.1.4 vs test/test_blocker.rb in binaryparse-0.1.5
- old
+ new
@@ -22,24 +22,18 @@
has_one :bar, :int32
end
def test_simple_valid
bb = BBTest2.new
- bb.foo = 32
bb.bar = 24
- assert_equal(32, bb.foo)
assert_equal(24, bb.bar)
- assert(!bb.valid?)
-
- bb.foo = 42
assert(bb.valid?)
end
def test_round_trip
bb = BBTest2.new
- bb.foo = 42
bb.bar = 21
buf = bb.block
bb2 = BBTest2.new
bb2.deblock(StringIO.new(buf))
@@ -51,23 +45,22 @@
assert_equal(bb3.bar, 21)
end
def test_failed_deblock
bb = BBTest2.new
- bb.foo = 43
bb.bar = 21
buf = bb.block
+ buf[0] = 0
bb2 = BBTest2.new
status = bb2.deblock(StringIO.new(buf))
assert(!status)
assert_raises(RuntimeError) do
BBTest2.new(StringIO.new(buf))
end
- bb.foo = 42
io = StringIO.new(bb.block)
assert(bb2.deblock(io))
assert_equal(bb2.foo, 42)
assert_equal(bb2.bar, 21)
@@ -86,19 +79,17 @@
has_one_of :foo, [BBSub1, BBSub2]
end
def test_has_one_of
bs1 = BBSub1.new
- bs1.foo = 42
buf = bs1.block
bb = BBTest3.new(StringIO.new(buf))
assert(bb)
assert_equal(BBSub1, bb.foo.class)
assert_equal(42, bb.foo.foo)
bs2 = BBSub2.new
- bs2.bar = 21
io = StringIO.new(bs2.block)
bb = BBTest3.new(io)
assert(bb)
assert_equal(BBSub2, bb.foo.class)
assert_equal(21, bb.foo.bar)
@@ -118,13 +109,11 @@
has_fixed_array :fooboo, 3, [BBSub1, BBSub2]
end
def test_fixed_array
bs1 = BBSub1.new
- bs1.foo = 42
bs2 = BBSub2.new
- bs2.bar = 21
buf = bs1.block + bs2.block + bs1.block
bb = BBTest4.new(buf)
assert(bb)
@@ -137,15 +126,12 @@
def test_building_fixed_array
fa = BBTest4.new
assert(fa)
fa.fooboo[0] = BBSub1.new
- fa.fooboo[0].foo = 42
fa.fooboo[1] = BBSub2.new
- fa.fooboo[1].bar = 21
fa.fooboo[2] = BBSub1.new
- fa.fooboo[2].foo = 42
assert_equal(42, fa.fooboo[0].foo)
assert_equal(21, fa.fooboo[1].bar)
assert_equal(42, fa.fooboo[2].foo)
buf = fa.block
@@ -165,13 +151,11 @@
has_counted_array :fooboo, :int16, [BBSub1, BBSub2]
end
def test_counted_array
bb1 = BBSub1.new
- bb1.foo = 42
bb2 = BBSub2.new
- bb2.bar = 21
fa = BBTest5.new
assert(fa)
assert_equal(0, fa.fooboo.size)
@@ -428,6 +412,31 @@
assert_equal(0, b2.foo)
assert_equal(3, b2.bar)
assert_equal('troaeipo', b2.str)
end
+ class BBDateRecord < BinaryBlocker::Blocker
+ has_one :date, :date
+ end
+
+ def test_null_dates
+ t = BBDateRecord.new
+ assert(buf = t.block)
+
+ t2 = BBDateRecord.new(buf)
+ assert(t2)
+ assert_nil(t2.date)
+ end
+
+ class BBTimeRecord < BinaryBlocker::Blocker
+ has_one :t, :time
+ end
+
+ def test_null_times
+ t = BBTimeRecord.new
+ assert(buf = t.block)
+
+ t2 = BBTimeRecord.new(buf)
+ assert(t2)
+ assert_nil(t2.t)
+ end
end