283 {
285 my_message_buffer_t mbuff;
286 unsigned char stuff[] = {
287 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
288 };
289 memcpy(mbuff.write_ptr(), stuff, 5);
290 mbuff.advance_write_ptr(5);
291 memcpy(mbuff.write_ptr(), stuff+5, 5);
292 mbuff.advance_write_ptr(5);
293 memcpy(mbuff.write_ptr(), stuff+10, 2);
294 mbuff.advance_write_ptr(2);
295
296 my_message_buffer_t::index_t index = mbuff.read_index();
298 mbuff.peek(&throw_away_buffer, 4, index);
299 mbuff.peek(&throw_away_buffer, 4, index);
300 mbuff.peek(&throw_away_buffer, 2, index);
301 BOOST_CHECK_THROW(mbuff.peek(&throw_away_buffer, 3, index), fc::out_of_range_exception);
302 mbuff.peek(&throw_away_buffer, 1, index);
303 mbuff.peek(&throw_away_buffer, 0, index);
304 mbuff.peek(&throw_away_buffer, 1, index);
305 BOOST_CHECK_THROW(mbuff.peek(&throw_away_buffer, 1, index), fc::out_of_range_exception);
306
307 mbuff.read(&throw_away_buffer, 4);
308 mbuff.read(&throw_away_buffer, 4);
309 mbuff.read(&throw_away_buffer, 2);
310 BOOST_CHECK_THROW(mbuff.read(&throw_away_buffer, 4), fc::out_of_range_exception);
311 mbuff.read(&throw_away_buffer, 1);
312 mbuff.read(&throw_away_buffer, 0);
313 mbuff.read(&throw_away_buffer, 1);
314 BOOST_CHECK_THROW(mbuff.read(&throw_away_buffer, 1), fc::out_of_range_exception);
315}