Class | TestBlocker |
In: |
test/test_blocker.rb
|
Parent: | Test::Unit::TestCase |
require ‘test/unit’ unless defined? $ZENTEST and $ZENTEST
# File test/test_blocker.rb, line 227 227: def test_bitfield 228: bb = BBTest7.new 229: assert(bb) 230: 231: #assert(bb.a.fld1) 232: bb.a.fld2 = 1 233: assert_equal(8, bb.a.raw_value) 234: bb.a.fld2 = 2 235: assert_equal(16, bb.a.raw_value) 236: bb.a.fld1 = 1 237: assert_equal(17, bb.a.raw_value) 238: 239: buf = bb.block 240: bb2 = BBTest7.new(buf) 241: assert_equal(17, bb.a.raw_value) 242: assert_equal(1, bb.a.fld1) 243: assert_equal(2, bb.a.fld2) 244: 245: assert_raises(NoMethodError) { bb.a.fld12 } 246: end
# File test/test_blocker.rb, line 138 138: def test_building_fixed_array 139: fa = BBTest4.new 140: assert(fa) 141: fa.fooboo[0] = BBSub1.new 142: fa.fooboo[0].foo = 42 143: fa.fooboo[1] = BBSub2.new 144: fa.fooboo[1].bar = 21 145: fa.fooboo[2] = BBSub1.new 146: fa.fooboo[2].foo = 42 147: assert_equal(42, fa.fooboo[0].foo) 148: assert_equal(21, fa.fooboo[1].bar) 149: assert_equal(42, fa.fooboo[2].foo) 150: 151: buf = fa.block 152: bb = BBTest4.new(buf) 153: assert(bb) 154: assert(bb.fooboo) 155: assert(bb.fooboo[0].foo) 156: assert_equal(42, bb.fooboo[0].foo) 157: assert_equal(21, bb.fooboo[1].bar) 158: assert_equal(42, bb.fooboo[2].foo) 159: 160: assert_raises(RangeError) { bb.fooboo[-1] } 161: assert_raises(RangeError) { bb.fooboo[3] } 162: end
# File test/test_blocker.rb, line 203 203: def test_composing 204: bb = BBTest6.new 205: assert(bb) 206: bb.a.foo = 1 207: assert_equal(1, bb.a.foo) 208: bb.a.bar = 2 209: assert_equal(2, bb.a.bar) 210: bb.bar = 1234 211: assert_equal(1234, bb.bar) 212: 213: buf = bb.block 214: assert_equal(10, buf.size) 215: 216: bb2 = BBTest6.new(buf) 217: assert(bb2) 218: assert_equal(1, bb2.a.foo) 219: assert_equal(2, bb2.a.bar) 220: assert_equal(1234, bb2.bar) 221: end
# File test/test_blocker.rb, line 168 168: def test_counted_array 169: bb1 = BBSub1.new 170: bb1.foo = 42 171: bb2 = BBSub2.new 172: bb2.bar = 21 173: 174: fa = BBTest5.new 175: assert(fa) 176: assert_equal(0, fa.fooboo.size) 177: 178: fa.fooboo << bb1 179: assert_equal(1, fa.fooboo.size) 180: 181: fa.fooboo << bb1 182: assert_equal(2, fa.fooboo.size) 183: 184: fa.fooboo << bb1 185: assert_equal(3, fa.fooboo.size) 186: 187: fa.fooboo << bb2 188: assert_equal(4, fa.fooboo.size) 189: 190: fa.fooboo << bb1 191: assert_equal(5, fa.fooboo.size) 192: 193: assert_raises(RangeError) { fa.fooboo[-1] } 194: assert_raises(RangeError) { fa.fooboo[5] } 195: assert(fa.fooboo[4]) 196: end
# File test/test_blocker.rb, line 371 371: def test_delimited_array 372: b = BBList.new 373: b.header = 19 374: b.footer = 67 375: 376: ia = ItemA.new 377: ia.iid = 1 378: ia.name = 'widget A' 379: assert_equal(1, ia.iid) 380: 381: ib = ItemB.new 382: ib.iid = 2 383: ib.name = 'widget B' 384: 385: b.items << ia << ib << ia << ib << ib << ib 386: assert_equal(6, b.items.size) 387: 388: buf = b.block 389: assert_equal(2 + (2 + 32) * 6 + 2, buf.size) 390: 391: b2 = BBList.new(buf) 392: assert_equal(19, b2.header) 393: assert_equal(67, b2.footer) 394: 395: assert_equal(6, b2.items.size) 396: 397: assert_equal(b2.items[0].iid, ia.iid) 398: assert_equal(b2.items[1].iid, ib.iid) 399: assert_equal(b2.items[2].iid, ia.iid) 400: assert_equal(b2.items[3].iid, ib.iid) 401: assert_equal(b2.items[4].iid, ib.iid) 402: assert_equal(b2.items[5].iid, ib.iid) 403: 404: assert_equal(b2.items[0].name, ia.name) 405: assert_equal(b2.items[1].name, ib.name) 406: assert_equal(b2.items[2].name, ia.name) 407: assert_equal(b2.items[3].name, ib.name) 408: assert_equal(b2.items[4].name, ib.name) 409: assert_equal(b2.items[5].name, ib.name) 410: end
# File test/test_blocker.rb, line 54 54: def test_failed_deblock 55: bb = BBTest2.new 56: bb.foo = 43 57: bb.bar = 21 58: buf = bb.block 59: 60: bb2 = BBTest2.new 61: status = bb2.deblock(StringIO.new(buf)) 62: assert(!status) 63: 64: assert_raises(RuntimeError) do 65: BBTest2.new(StringIO.new(buf)) 66: end 67: 68: bb.foo = 42 69: io = StringIO.new(bb.block) 70: assert(bb2.deblock(io)) 71: 72: assert_equal(bb2.foo, 42) 73: assert_equal(bb2.bar, 21) 74: assert_equal(6, io.pos) 75: end
# File test/test_blocker.rb, line 121 121: def test_fixed_array 122: bs1 = BBSub1.new 123: bs1.foo = 42 124: bs2 = BBSub2.new 125: bs2.bar = 21 126: 127: buf = bs1.block + bs2.block + bs1.block 128: bb = BBTest4.new(buf) 129: 130: assert(bb) 131: assert(bb.fooboo) 132: assert(bb.fooboo[0].foo) 133: assert_equal(42, bb.fooboo[0].foo) 134: assert_equal(21, bb.fooboo[1].bar) 135: assert_equal(42, bb.fooboo[2].foo) 136: end
# File test/test_blocker.rb, line 254 254: def test_fixed_string 255: b = BBString.new 256: b.foo = 1 257: b.name = "Patrick " 258: b.bar = 42 259: 260: assert_equal(1, b.foo) 261: assert_equal("Patrick ", b.name) 262: assert_equal(42, b.bar) 263: 264: buf = b.block 265: assert_equal(2 + 20 + 4, buf.size) 266: 267: b2 = BBString.new(buf) 268: assert_equal(1, b2.foo) 269: assert_equal("Patrick ", b2.name) 270: assert_equal(42, b2.bar) 271: end
# File test/test_blocker.rb, line 89 89: def test_has_one_of 90: bs1 = BBSub1.new 91: bs1.foo = 42 92: buf = bs1.block 93: bb = BBTest3.new(StringIO.new(buf)) 94: assert(bb) 95: assert_equal(BBSub1, bb.foo.class) 96: assert_equal(42, bb.foo.foo) 97: 98: bs2 = BBSub2.new 99: bs2.bar = 21 100: io = StringIO.new(bs2.block) 101: bb = BBTest3.new(io) 102: assert(bb) 103: assert_equal(BBSub2, bb.foo.class) 104: assert_equal(21, bb.foo.bar) 105: assert_equal(2, io.pos) 106: 107: bb.foo = bs1 108: assert_equal(BBSub1, bb.foo.class) 109: assert_equal(42, bb.foo.foo) 110: 111: buf = bb.block 112: bb = BBTest3.new(buf) 113: assert_equal(BBSub1, bb.foo.class) 114: assert_equal(42, bb.foo.foo) 115: end
# File test/test_blocker.rb, line 327 327: def test_packed_date 328: bdate = Date.civil(1967, 9, 30) 329: b = BBDate.new 330: b.today = bdate 331: 332: buf = b.block 333: assert_equal(4, buf.size) 334: 335: b2 = BBDate.new(buf) 336: assert_equal(bdate, b2.today) 337: end
# File test/test_blocker.rb, line 343 343: def test_packed_datetime 344: now = Time.local(1985, 5, 30, 7, 6, 5) 345: b = BBTime.new 346: b.now = now 347: 348: buf = b.block 349: assert_equal(14 / 2, buf.size) 350: 351: b2 = BBTime.new(buf) 352: assert_equal(now, b2.now) 353: end
# File test/test_blocker.rb, line 304 304: def test_packed_numbers 305: b = BBPacked.new 306: b.foo = 7 307: b.age = 32 308: b.bar = 3 309: 310: assert_equal(7, b.foo) 311: assert_equal(32, b.age) 312: assert_equal(3, b.bar) 313: 314: buf = b.block 315: assert_equal(2 + 2 + 4, buf.size) 316: 317: b2 = BBPacked.new(buf) 318: assert_equal(7, b2.foo) 319: assert_equal(32, b2.age) 320: assert_equal(3, b2.bar) 321: end
# File test/test_blocker.rb, line 38 38: def test_round_trip 39: bb = BBTest2.new 40: bb.foo = 42 41: bb.bar = 21 42: buf = bb.block 43: 44: bb2 = BBTest2.new 45: bb2.deblock(StringIO.new(buf)) 46: assert_equal(bb2.foo, 42) 47: assert_equal(bb2.bar, 21) 48: 49: bb3 = BBTest2.new(StringIO.new(buf)) 50: assert_equal(bb3.foo, 42) 51: assert_equal(bb3.bar, 21) 52: end
# File test/test_blocker.rb, line 25 25: def test_simple_valid 26: bb = BBTest2.new 27: bb.foo = 32 28: bb.bar = 24 29: 30: assert_equal(32, bb.foo) 31: assert_equal(24, bb.bar) 32: assert(!bb.valid?) 33: 34: bb.foo = 42 35: assert(bb.valid?) 36: end
# File test/test_blocker.rb, line 11 11: def test_usage 12: bb = BBTest1.new 13: bb.foo = 32 14: bb.bar = 24 15: 16: assert_equal(32, bb.foo) 17: assert_equal(24, bb.bar) 18: end
# File test/test_blocker.rb, line 279 279: def test_utf16 280: b = BBUTF16.new 281: b.foo = 1 282: b.name = "Patrick " 283: b.bar = 42 284: 285: assert_equal(1, b.foo) 286: assert_equal("Patrick ", b.name) 287: assert_equal(42, b.bar) 288: 289: buf = b.block 290: assert_equal(2 + 20 * 2 + 4, buf.size) 291: 292: b2 = BBUTF16.new(buf) 293: assert_equal(1, b2.foo) 294: assert_equal("Patrick ", b2.name) 295: assert_equal(42, b2.bar) 296: end