| 260 | |
---|
| 261 | |
---|
| 262 | # Test an end-of-binary call. Arrange to receive binary data but don't bother counting it |
---|
| 263 | # as it comes. Rely on getting receive_end_of_binary_data to signal the transition back to |
---|
| 264 | # line mode. |
---|
| 265 | # At the present time, this isn't strictly necessary with sized binary chunks because by |
---|
| 266 | # definition we accumulate them and make exactly one call to receive_binary_data, but |
---|
| 267 | # we may want to support a mode in the future that would break up large chunks into multiple |
---|
| 268 | # calls. |
---|
| 269 | class LazyBinary |
---|
| 270 | include EM::Protocols::LineText2 |
---|
| 271 | attr_reader :data, :end |
---|
| 272 | def initialize *args |
---|
| 273 | super |
---|
| 274 | @data = "" |
---|
| 275 | set_text_mode 1000 |
---|
| 276 | end |
---|
| 277 | def receive_binary_data data |
---|
| 278 | # we expect to get all the data in one chunk, even in the byte-by-byte case, |
---|
| 279 | # because sized transfers by definition give us exactly one call to |
---|
| 280 | # #receive_binary_data. |
---|
| 281 | @data = data |
---|
| 282 | end |
---|
| 283 | def receive_end_of_binary_data |
---|
| 284 | @end = true |
---|
| 285 | end |
---|
| 286 | end |
---|
| 287 | def test_receive_end_of_binary_data |
---|
| 288 | testdata = "_" * 1000 |
---|
| 289 | a = LazyBinary.new |
---|
| 290 | testdata.length.times {|i| a.receive_data( testdata[i...i+1] ) } |
---|
| 291 | assert_equal( "_" * 1000, a.data ) |
---|
| 292 | assert( a.end ) |
---|
| 293 | end |
---|