Example #1
0
int read_test2(TEST_DATA *data, IO_BUFFER *iobuf)
{
   IO_ITEM_HEADER item_header;
   int i;
   
   item_header.type = 99;             /* test data */
   if ( get_item_begin(iobuf,&item_header) < 0 )
   {
      Warning("Missing or invalid test data block.");
      return -4;
   }

   get_vector_of_long(data->lvar,2,iobuf);
   data->ilvar[0] = get_long(iobuf);
   data->ilvar[1] = get_long(iobuf);
   get_vector_of_int(data->isvar,2,iobuf);
   get_vector_of_short(data->svar,3,iobuf);
   get_vector_of_real(data->fvar,2,iobuf);
   get_vector_of_double(data->dvar,2,iobuf);
   data->hvar[0] = get_sfloat(iobuf);
   data->hvar[1] = get_sfloat(iobuf);
   get_vector_of_byte((uint8_t *)data->i8var,2,iobuf);
   get_vector_of_byte(data->u8var,2,iobuf);
   get_vector_of_short(data->i16var,2,iobuf);
   get_vector_of_short((int16_t *)data->u16var,2,iobuf);
   get_vector_of_int32(data->i32var,2,iobuf);
   get_vector_of_uint32(data->u32var,2,iobuf);
#ifdef HAVE_64BIT_INT
   get_vector_of_int64(data->i64var,2,iobuf);
   get_vector_of_uint64(data->u64var,2,iobuf);
#endif
   data->nbvar = get_count(iobuf);
   get_vector_of_byte(data->bvar,2,iobuf);
   for (i=0; i<4; i++)
      data->cnt16var[i] = get_count(iobuf);
   for (i=0; i<6; i++)
      data->cnt32var[i] = get_count(iobuf);
   for (i=0; i<6; i++)
      data->cntzvar[i] = get_count(iobuf);
   for (i=0; i<8; i++)
      data->cntvar[i] = get_count(iobuf);
   for (i=0; i<10; i++)
      data->scnt16var[i] = get_scount16(iobuf);
   for (i=0; i<12; i++)
      data->scnt32var[i] = get_scount32(iobuf);
   for (i=0; i<12; i++)
      data->scntzvar[i] = get_scount(iobuf);
   for (i=0; i<14; i++)
      data->scntvar[i] = get_scount(iobuf);
   get_string(data->str16var,sizeof(data->str16var),iobuf);
   get_long_string(data->str32var,sizeof(data->str32var),iobuf);
   get_var_string(data->strvvar,sizeof(data->strvvar),iobuf);

   return(get_item_end(iobuf,&item_header));
}
void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
{
  // a bunch of typedefs which will be handy later on
  typedef boost::dynamic_bitset<Block> bitset_type;
  typedef bitset_test<bitset_type> Tests;
  // typedef typename bitset_type::size_type size_type; // unusable with Borland 5.5.1

  std::string long_string = get_long_string();
  std::size_t ul_width = std::numeric_limits<unsigned long>::digits;

  //=====================================================================
  // Test b.empty()
  {
    bitset_type b;
    Tests::empty(b);
  }
  {
    bitset_type b(1, 1ul);
    Tests::empty(b);
  }
  {
    bitset_type b(bitset_type::bits_per_block
                  + bitset_type::bits_per_block/2, 15ul);
    Tests::empty(b);
  }
  //=====================================================================
  // Test b.to_long()
  {
    boost::dynamic_bitset<Block> b;
    Tests::to_ulong(b);
  }
  {
    boost::dynamic_bitset<Block> b(std::string("1"));
    Tests::to_ulong(b);
  }
  {
    boost::dynamic_bitset<Block> b(bitset_type::bits_per_block,
                                   static_cast<unsigned long>(-1));
    Tests::to_ulong(b);
  }
  {
    std::string str(ul_width - 1, '1');
    boost::dynamic_bitset<Block> b(str);
    Tests::to_ulong(b);
  }
  {
    std::string ul_str(ul_width, '1');
    boost::dynamic_bitset<Block> b(ul_str);
    Tests::to_ulong(b);
  }
  { // case overflow
    boost::dynamic_bitset<Block> b(long_string);
    Tests::to_ulong(b);
  }
  //=====================================================================
  // Test to_string(b, str)
  {
    boost::dynamic_bitset<Block> b;
    Tests::to_string(b);
  }
  {
    boost::dynamic_bitset<Block> b(std::string("0"));
    Tests::to_string(b);
  }
  {
    boost::dynamic_bitset<Block> b(long_string);
    Tests::to_string(b);
  }
  //=====================================================================
  // Test b.count()
  {
    boost::dynamic_bitset<Block> b;
    Tests::count(b);
  }
  {
    boost::dynamic_bitset<Block> b(std::string("0"));
    Tests::count(b);
  }
  {
    boost::dynamic_bitset<Block> b(std::string("1"));
    Tests::count(b);
  }
  {
    boost::dynamic_bitset<Block> b(8, 255ul);
    Tests::count(b);
  }
  {
    boost::dynamic_bitset<Block> b(long_string);
    Tests::count(b);
  }
  //=====================================================================
  // Test b.size()
  {
    boost::dynamic_bitset<Block> b;
    Tests::size(b);
  }
  {
    boost::dynamic_bitset<Block> b(std::string("0"));
    Tests::size(b);
  }
  {
    boost::dynamic_bitset<Block> b(long_string);
    Tests::size(b);
  }
  //=====================================================================
  // Test b.any()
  {
    boost::dynamic_bitset<Block> b;
    Tests::any(b);
  }
  {
    boost::dynamic_bitset<Block> b(std::string("0"));
    Tests::any(b);
  }
  {
    boost::dynamic_bitset<Block> b(long_string);
    Tests::any(b);
  }
  //=====================================================================
  // Test b.none()
  {
    boost::dynamic_bitset<Block> b;
    Tests::none(b);
  }
  {
    boost::dynamic_bitset<Block> b(std::string("0"));
    Tests::none(b);
  }
  {
    boost::dynamic_bitset<Block> b(long_string);
    Tests::none(b);
  }
  //=====================================================================
  // Test a.is_subset_of(b)
  {
    boost::dynamic_bitset<Block> a, b;
    Tests::subset(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
    Tests::subset(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
    Tests::subset(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    Tests::subset(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    a[long_string.size()/2].flip();
    Tests::subset(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    b[long_string.size()/2].flip();
    Tests::subset(a, b);
  }
  //=====================================================================
  // Test a.is_proper_subset_of(b)
  {
    boost::dynamic_bitset<Block> a, b;
    Tests::proper_subset(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
    Tests::proper_subset(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
    Tests::proper_subset(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    Tests::proper_subset(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    a[long_string.size()/2].flip();
    Tests::proper_subset(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    b[long_string.size()/2].flip();
    Tests::proper_subset(a, b);
  }
  //=====================================================================
  // Test intersects
  {
    bitset_type a; // empty
    bitset_type b;
    Tests::intersects(a, b);
  }
  {
    bitset_type a;
    bitset_type b(5, 8ul);
    Tests::intersects(a, b);
  }
  {
    bitset_type a(8, 0ul);
    bitset_type b(15, 0ul);
    b[9] = 1;
    Tests::intersects(a, b);
  }
  {
    bitset_type a(15, 0ul);
    bitset_type b(22, 0ul);
    a[14] = b[14] = 1;
    Tests::intersects(a, b);
  }
  //=====================================================================
  // Test find_first
  {
      // empty bitset
      bitset_type b;
      Tests::find_first(b);
  }
  {
      // bitset of size 1
      bitset_type b(1, 1ul);
      Tests::find_first(b);
  }
  {
      // all-0s bitset
      bitset_type b(4 * bitset_type::bits_per_block, 0ul);
      Tests::find_first(b);
  }
  {
      // first bit on
      bitset_type b(1, 1ul);
      Tests::find_first(b);
  }
  {
      // last bit on
      bitset_type b(4 * bitset_type::bits_per_block - 1, 0ul);
      b.set(b.size() - 1);
      Tests::find_first(b);
  }
  //=====================================================================
  // Test find_next
  {
      // empty bitset
      bitset_type b;

      // check
      Tests::find_next(b, 0);
      Tests::find_next(b, 1);
      Tests::find_next(b, 200);
      Tests::find_next(b, b.npos);
  }
  {
      // bitset of size 1 (find_next can never find)
      bitset_type b(1, 1ul);

      // check
      Tests::find_next(b, 0);
      Tests::find_next(b, 1);
      Tests::find_next(b, 200);
      Tests::find_next(b, b.npos);
  }
  {
      // all-1s bitset
      bitset_type b(16 * bitset_type::bits_per_block);
      b.set();

      // check
      const typename bitset_type::size_type larger_than_size = 5 + b.size();
      for(typename bitset_type::size_type i = 0; i <= larger_than_size; ++i) {
          Tests::find_next(b, i);
      }
      Tests::find_next(b, b.npos);
  }
  {
      // a bitset with 1s at block boundary only
      const int num_blocks = 32;
      const int block_width = bitset_type::bits_per_block;

      bitset_type b(num_blocks * block_width);
      typename bitset_type::size_type i = block_width - 1;
      for ( ; i < b.size(); i += block_width) {

        b.set(i);
        typename bitset_type::size_type first_in_block = i - (block_width - 1);
        b.set(first_in_block);
      }

      // check
      const typename bitset_type::size_type larger_than_size = 5 + b.size();
      for (i = 0; i <= larger_than_size; ++i) {
          Tests::find_next(b, i);
      }
      Tests::find_next(b, b.npos);

  }
  {
      // bitset with alternate 1s and 0s
      const typename bitset_type::size_type sz = 1000;
      bitset_type b(sz);

      typename bitset_type::size_type i = 0;
      for ( ; i < sz; ++i) {
        b[i] = (i%2 == 0);
      }

      // check
      const typename bitset_type::size_type larger_than_size = 5 + b.size();
      for (i = 0; i <= larger_than_size; ++i) {
          Tests::find_next(b, i);
      }
      Tests::find_next(b, b.npos);

  }
  //=====================================================================
  // Test operator==
  {
    boost::dynamic_bitset<Block> a, b;
    Tests::operator_equal(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
    Tests::operator_equal(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
    Tests::operator_equal(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    Tests::operator_equal(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    a[long_string.size()/2].flip();
    Tests::operator_equal(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    b[long_string.size()/2].flip();
    Tests::operator_equal(a, b);
  }
  //=====================================================================
  // Test operator!=
  {
    boost::dynamic_bitset<Block> a, b;
    Tests::operator_not_equal(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
    Tests::operator_not_equal(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
    Tests::operator_not_equal(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    Tests::operator_not_equal(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    a[long_string.size()/2].flip();
    Tests::operator_not_equal(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    b[long_string.size()/2].flip();
    Tests::operator_not_equal(a, b);
  }
  //=====================================================================
  // Test operator<
  {
    boost::dynamic_bitset<Block> a, b;
    Tests::operator_less_than(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
    Tests::operator_less_than(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
    Tests::operator_less_than(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(std::string("10")), b(std::string("11"));
    Tests::operator_less_than(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    Tests::operator_less_than(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    a[long_string.size()/2].flip();
    Tests::operator_less_than(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    b[long_string.size()/2].flip();
    Tests::operator_less_than(a, b);
  }
  // check for consistency with ulong behaviour
  {
    boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul);
    assert(a < b);
  }
  {
    boost::dynamic_bitset<Block> a(3, 4ul), b(3, 4ul);
    assert(!(a < b));
  }
  {
    boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul);
    assert(!(a < b));
  }
  //=====================================================================
  // Test operator<=
  {
    boost::dynamic_bitset<Block> a, b;
    Tests::operator_less_than_eq(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
    Tests::operator_less_than_eq(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
    Tests::operator_less_than_eq(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    Tests::operator_less_than_eq(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    a[long_string.size()/2].flip();
    Tests::operator_less_than_eq(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    b[long_string.size()/2].flip();
    Tests::operator_less_than_eq(a, b);
  }
  // check for consistency with ulong behaviour
  {
    boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul);
    assert(a <= b);
  }
  {
    boost::dynamic_bitset<Block> a(3, 4ul), b(3, 4ul);
    assert(a <= b);
  }
  {
    boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul);
    assert(!(a <= b));
  }
  //=====================================================================
  // Test operator>
  {
    boost::dynamic_bitset<Block> a, b;
    Tests::operator_greater_than(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
    Tests::operator_greater_than(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
    Tests::operator_greater_than(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    Tests::operator_greater_than(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    a[long_string.size()/2].flip();
    Tests::operator_greater_than(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    b[long_string.size()/2].flip();
    Tests::operator_greater_than(a, b);
  }
  // check for consistency with ulong behaviour
  {
    boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul);
    assert(!(a > b));
  }
  {
    boost::dynamic_bitset<Block> a(3, 4ul), b(3, 4ul);
    assert(!(a > b));
  }
  {
    boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul);
    assert(a > b);
  }
  //=====================================================================
  // Test operator<=
  {
    boost::dynamic_bitset<Block> a, b;
    Tests::operator_greater_than_eq(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(std::string("0")), b(std::string("0"));
    Tests::operator_greater_than_eq(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
    Tests::operator_greater_than_eq(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    Tests::operator_greater_than_eq(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    a[long_string.size()/2].flip();
    Tests::operator_greater_than_eq(a, b);
  }
  {
    boost::dynamic_bitset<Block> a(long_string), b(long_string);
    b[long_string.size()/2].flip();
    Tests::operator_greater_than_eq(a, b);
  }
  // check for consistency with ulong behaviour
  {
    boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul);
    assert(!(a >= b));
  }
  {
    boost::dynamic_bitset<Block> a(3, 4ul), b(3, 4ul);
    assert(a >= b);
  }
  {
    boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul);
    assert(a >= b);
  }
  //=====================================================================
  // Test b.test(pos)
  { // case pos >= b.size()
    boost::dynamic_bitset<Block> b;
    Tests::test_bit(b, 0);
  }
  { // case pos < b.size()
    boost::dynamic_bitset<Block> b(std::string("0"));
    Tests::test_bit(b, 0);
  }
  { // case pos == b.size() / 2
    boost::dynamic_bitset<Block> b(long_string);
    Tests::test_bit(b, long_string.size()/2);
  }
  //=====================================================================
  // Test b << pos
  { // case pos == 0
    std::size_t pos = 0;
    boost::dynamic_bitset<Block> b(std::string("1010"));
    Tests::operator_shift_left(b, pos);
  }
  { // case pos == size()/2
    std::size_t pos = long_string.size() / 2;
    boost::dynamic_bitset<Block> b(long_string);
    Tests::operator_shift_left(b, pos);
  }
  { // case pos >= n
    std::size_t pos = long_string.size();
    boost::dynamic_bitset<Block> b(long_string);
    Tests::operator_shift_left(b, pos);
  }
  //=====================================================================
  // Test b >> pos
  { // case pos == 0
    std::size_t pos = 0;
    boost::dynamic_bitset<Block> b(std::string("1010"));
    Tests::operator_shift_right(b, pos);
  }
  { // case pos == size()/2
    std::size_t pos = long_string.size() / 2;
    boost::dynamic_bitset<Block> b(long_string);
    Tests::operator_shift_right(b, pos);
  }
  { // case pos >= n
    std::size_t pos = long_string.size();
    boost::dynamic_bitset<Block> b(long_string);
    Tests::operator_shift_right(b, pos);
  }
  //=====================================================================
  // Test a & b
  {
    boost::dynamic_bitset<Block> lhs, rhs;
    Tests::operator_and(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
    Tests::operator_and(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
    Tests::operator_and(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
    Tests::operator_and(lhs, rhs);
  }
  //=====================================================================
  // Test a | b
  {
    boost::dynamic_bitset<Block> lhs, rhs;
    Tests::operator_or(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
    Tests::operator_or(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
    Tests::operator_or(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
    Tests::operator_or(lhs, rhs);
  }
  //=====================================================================
  // Test a^b
  {
    boost::dynamic_bitset<Block> lhs, rhs;
    Tests::operator_xor(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
    Tests::operator_xor(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
    Tests::operator_xor(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
    Tests::operator_xor(lhs, rhs);
  }
  //=====================================================================
  // Test a-b
  {
    boost::dynamic_bitset<Block> lhs, rhs;
    Tests::operator_sub(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
    Tests::operator_sub(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
    Tests::operator_sub(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
    Tests::operator_sub(lhs, rhs);
  }
}
Example #3
0
int read_test3(TEST_DATA *data, IO_BUFFER *iobuf)
{
   IO_ITEM_HEADER item_header1, item_header2;
   int i;
   
   item_header1.type = 990;             /* test data */
   if ( get_item_begin(iobuf,&item_header1) < 0 )
   {
      Warning("Missing or invalid test data block.");
      return -4;
   }

   item_header2.type = 991;             /* test data */
   if ( get_item_begin(iobuf,&item_header2) < 0 )
   {
      Warning("Missing or invalid test data sub-block 1.");
      return -4;
   }

   get_vector_of_long(data->lvar,2,iobuf);
   data->ilvar[0] = get_long(iobuf);
   data->ilvar[1] = get_long(iobuf);
   get_vector_of_int(data->isvar,2,iobuf);
   get_vector_of_short(data->svar,3,iobuf);
   
   get_item_end(iobuf,&item_header2);

   if ( next_subitem_type(iobuf) != 992 )
   {
      Warning("Failed to look ahead for next sub-item type.");
      return -4;
   }

   item_header2.type = 992;             /* test data */
   if ( get_item_begin(iobuf,&item_header2) < 0 )
   {
      Warning("Missing or invalid test data sub-block 2.");
      return -4;
   }

   get_vector_of_real(data->fvar,2,iobuf);
   get_vector_of_double(data->dvar,2,iobuf);
   data->hvar[0] = get_sfloat(iobuf);
   data->hvar[1] = get_sfloat(iobuf);
   get_vector_of_byte((uint8_t *)data->i8var,2,iobuf);
   get_vector_of_byte(data->u8var,2,iobuf);
   get_vector_of_short(data->i16var,2,iobuf);
   get_vector_of_short((int16_t *)data->u16var,2,iobuf);
   get_vector_of_int32(data->i32var,2,iobuf);
   get_vector_of_uint32(data->u32var,2,iobuf);
#ifdef HAVE_64BIT_INT
   get_vector_of_int64(data->i64var,2,iobuf);
   get_vector_of_uint64(data->u64var,2,iobuf);
#endif

   get_item_end(iobuf,&item_header2);
   
   /* Check that non-sequential access to sub-items also works */

   rewind_item(iobuf,&item_header1);

   item_header2.type = 994;             /* test data */
   if ( search_sub_item(iobuf,&item_header1,&item_header2) < 0 )
   {
      Warning("Cannot find test data sub-block 4.");
      return -4;
   }
   if ( get_item_begin(iobuf,&item_header2) < 0 )
   {
      Warning("Missing or invalid test data sub-block 4.");
      return -4;
   }

   get_string(data->str16var,sizeof(data->str16var),iobuf);
   get_long_string(data->str32var,sizeof(data->str32var),iobuf);
   get_var_string(data->strvvar,sizeof(data->strvvar),iobuf);

   get_item_end(iobuf,&item_header2);

   rewind_item(iobuf,&item_header1);

   item_header2.type = 993;             /* test data */
   if ( search_sub_item(iobuf,&item_header1,&item_header2) < 0 )
   {
      Warning("Cannot find test data sub-block 3.");
      return -4;
   }
   if ( get_item_begin(iobuf,&item_header2) < 0 )
   {
      Warning("Missing or invalid test data sub-block 3.");
      return -4;
   }

   data->nbvar = get_count(iobuf);
   get_vector_of_byte(data->bvar,2,iobuf);
   for (i=0; i<4; i++)
      data->cnt16var[i] = get_count(iobuf);
   for (i=0; i<6; i++)
      data->cnt32var[i] = get_count(iobuf);
   for (i=0; i<6; i++)
      data->cntzvar[i] = get_count(iobuf);
   for (i=0; i<8; i++)
      data->cntvar[i] = get_count(iobuf);
   for (i=0; i<10; i++)
      data->scnt16var[i] = get_scount16(iobuf);
   for (i=0; i<12; i++)
      data->scnt32var[i] = get_scount32(iobuf);
   for (i=0; i<12; i++)
      data->scntzvar[i] = get_scount(iobuf);
   for (i=0; i<14; i++)
      data->scntvar[i] = get_scount(iobuf);

   get_item_end(iobuf,&item_header2);

   return(get_item_end(iobuf,&item_header1));
}
void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
{

  typedef boost::dynamic_bitset<Block> bitset_type;
  typedef bitset_test<bitset_type> Tests;

  //=====================================================================
  // Test stream operator<<
  {

    // The test "variables" are: the stream type and its state, the
    // exception mask, the width, the fill char and the padding side (left/right)

    std::ios::iostate masks[] = {
                                  std::ios::goodbit,
                                  std::ios::eofbit,
                                  std::ios::failbit,
                                  std::ios::eofbit | std::ios::failbit
                                };

    static std::string strings[] = {
                                  std::string(""),
                                  std::string("0"),
                                  std::string("1"),
                                  std::string("11100"),
                                  get_long_string()
                                };

    char fill_chars[] =         { '*', 'x', ' ' };

    std::size_t num_masks   = sizeof(masks) / sizeof(masks[0]);
    std::size_t num_strings = sizeof(strings) / sizeof(strings[0]);
    std::size_t num_chars   = sizeof(fill_chars) / sizeof(fill_chars[0]);

    std::fstream not_good_stream("dynamic_bitset_tests - this file shouldn't exist",
                                 std::ios::in);


    for (std::size_t mi = 0; mi < num_masks; ++mi) {
      for (std::size_t si = 0; si < num_strings; ++si) {

        std::streamsize slen = (std::streamsize)(strings[si].length());

        assert( (std::numeric_limits<std::streamsize>::max)()
                 >=(std::streamsize)(1+slen*2) );

        for (std::size_t ci = 0; ci < num_chars; ++ci) {

          // note how "negative widths" are tested too
          const std::streamsize widths[] = { -1 - slen/2, 0, slen/2, 1 + slen*2 };
          std::size_t num_widths = sizeof(widths) / sizeof(widths[0]);

          for (std::size_t wi = 0; wi < num_widths; ++wi) {
            std::streamsize w = widths[wi];
            {
              // test 0 - stream !good()
              if(not_good_stream.good())
                  throw std::logic_error("Error in operator << tests"
                                         " - please, double check");
              bitset_type b(strings[si]);
              not_good_stream.width(w);
              not_good_stream.fill(fill_chars[ci]);
              try { not_good_stream.exceptions(masks[mi]); } catch(...) {}

              Tests::stream_inserter(b, not_good_stream, "<unused_string>");
            }
            {
              // test 1a - file stream
              bitset_type b(strings[si]);
              std::ofstream file(test_file_name(), std::ios::trunc);
              file.width(w);
              file.fill(fill_chars[ci]);
              file.exceptions(masks[mi]);
              Tests::stream_inserter(b, file, test_file_name());

            }
            {
              //NOTE: there are NO string stream tests - gps
            }
#if !defined (BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS)
            {
              // test 1b - wide file stream
              bitset_type b(strings[si]);
              std::wofstream file(test_file_name());
              file.width(w);
              file.fill(fill_chars[ci]);
              file.exceptions(masks[mi]);
              Tests::stream_inserter(b, file, test_file_name());
            }
#endif
          }
        }
      }
    } // for (; mi..)

  }

  //=====================================================================
  // Test stream operator>>
  {

  // The test "variables" are: the stream type, the exception mask,
  // the actual contents (and/or state) of the stream, and width.
  //
  // With few exceptions, each test case consists of writing a different
  // assortment of digits and "whitespaces" to a text stream and then checking
  // that what was written gets read back unchanged. That's NOT guaranteed by
  // the standard, unless the assortment always ends with a '\n' and satisfies
  // other conditions (see C99, 7.19.2/2), however it works in practice and is
  // a good "real life" test. Some characters, such as '\v' and '\f', are not
  // used exactly because they are the ones which will most likely give problems
  // on some systems (for instance '\f' could actually be written as a sequence
  // of new-lines, and we could never be able to read it back) [gps]
  //
  // Note how the bitset object is not initially empty. That helps checking
  // that it isn't erroneously clear()ed by operator>>.


  std::ios::iostate masks[] = {
                                  std::ios::goodbit,
                                  std::ios::eofbit,
                                  std::ios::failbit,
                                  std::ios::eofbit | std::ios::failbit
                                   };

  const std::string spaces = "\t\n "; //"\t\n\v\f ";

  const std::string long_string = get_long_string();
  /*const*/ static std::string strings[] = {
                  // NOTE: "const" gives the usual problems with Borland
                  //       (in Tests::stream_extractor instantiation)


#if !(defined __BORLANDC__     \
      && BOOST_WORKAROUND(BOOST_RWSTD_VER, BOOST_TESTED_AT(0x20101)))
                                        // Borland 5.5.1 with RW library crashes
            // empty string
            std::string(""),
            // no bitset
            spaces,
#endif
            // no bitset
            std::string("x"),
            std::string("\t  xyz"),

            // bitset of size 1
            std::string("0"),
            std::string("1"),

            std::string("  0  "),
            std::string("  1  "),
            spaces + "1",
            "1" + spaces,
            spaces + "1" + spaces,
            std::string("  x1x  "),
            std::string("  1x  "),

            // long bitset
            long_string,
            "  " + long_string + " xyz",
            spaces + long_string,
            spaces + long_string + spaces
    };


  //-----------------------------------------------------

  std::stringstream not_good_stream;
  not_good_stream << "test";
  std::string sink;
  not_good_stream >> sink; // now the stream should be in eof state

  const std::size_t num_masks = sizeof(masks) / sizeof(masks[0]);
  const std::size_t num_strings = sizeof(strings) / sizeof(strings[0]);

  for (std::size_t mi = 0; mi < num_masks; ++mi) {
    for (std::size_t si = 0; si < num_strings; ++si) {

      const std::streamsize slen = (std::streamsize)(strings[si].length());
      assert((std::numeric_limits<std::streamsize>::max)() >= (std::streamsize)(1+slen*2));

      std::streamsize widths[] = { -1, 0, slen/2, slen, 1 + slen*2 };
      std::size_t num_widths = sizeof(widths) / sizeof(widths[0]);

      for(std::size_t wi = 0; wi < num_widths; ++wi) {
        const std::streamsize w = widths[wi];

        // test 0 - !good() stream
        {
          if(not_good_stream.good())
            throw std::logic_error("Error in operator >> tests"
                                   " - please, double check");
          bitset_type b(1, 15ul); // note: b is not empty
          not_good_stream.width(w);
          try { not_good_stream.exceptions(masks[mi]); } catch(...) {}
          std::string irrelevant;
          Tests::stream_extractor(b, not_good_stream, irrelevant);
        }
        // test 1a - (narrow) file stream
        {
          bitset_type b(1, 255ul);
          {
            std::ofstream f(test_file_name());
            f << strings[si];
          }

          std::ifstream f(test_file_name());
          f.width(w);
          f.exceptions(masks[mi]);
          Tests::stream_extractor(b, f, strings[si]);
        }
#if !defined(BOOST_NO_STRINGSTREAM)
        // test 2a - stringstream
        {
          bitset_type b(1, 255ul);
          std::istringstream stream(strings[si]);
          stream.width(w);
          stream.exceptions(masks[mi]);
          Tests::stream_extractor(b, stream, strings[si]);
        }
#endif

#if !defined(BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS)
        // test 1b - wchar_t file stream
        {
          std::wstring wstr = widen_string(strings[si]);
          bitset_type b(1, 255ul);
          {
            std::basic_ofstream<wchar_t> of(test_file_name());
            of << wstr;
          }

          std::basic_ifstream<wchar_t> f(test_file_name());
          f.width(w);
          f.exceptions(masks[mi]);
          Tests::stream_extractor(b, f, wstr);
        }
        // test 2b - wstringstream
        {
          bitset_type b(1, 255ul);
          std::wstring wstr = widen_string(strings[si]);

          std::wistringstream wstream(wstr);
          wstream.width(w);
          wstream.exceptions(masks[mi]);
          Tests::stream_extractor(b, wstream, wstr);
        }
#endif // BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS

      }
    }

  } // for ( mi = 0; ...)


  }
  //=====================================================================
  // << Any other tests go here >>
  //         .....

}
void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
{
  typedef boost::dynamic_bitset<Block> bitset_type;
  typedef bitset_test< bitset_type > Tests;
  const int bits_per_block = bitset_type::bits_per_block;

  std::string long_string = get_long_string();

  //=====================================================================
  // Test operator&=
  {
    boost::dynamic_bitset<Block> lhs, rhs;
    Tests::and_assignment(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
    Tests::and_assignment(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
    Tests::and_assignment(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
    Tests::and_assignment(lhs, rhs);
  }
  //=====================================================================
  // Test operator |=
  {
    boost::dynamic_bitset<Block> lhs, rhs;
    Tests::or_assignment(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
    Tests::or_assignment(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(long_string.size(), 0), rhs(long_string);
    Tests::or_assignment(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(long_string.size(), 1), rhs(long_string);
    Tests::or_assignment(lhs, rhs);
  }
  //=====================================================================
  // Test operator^=
  {
    boost::dynamic_bitset<Block> lhs, rhs;
    Tests::xor_assignment(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
    Tests::xor_assignment(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(std::string("0")), rhs(std::string("1"));
    Tests::xor_assignment(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(long_string), rhs(long_string);
    Tests::xor_assignment(lhs, rhs);
  }
  //=====================================================================
  // Test operator-=
  {
    boost::dynamic_bitset<Block> lhs, rhs;
    Tests::sub_assignment(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(std::string("1")), rhs(std::string("0"));
    Tests::sub_assignment(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(std::string("0")), rhs(std::string("1"));
    Tests::sub_assignment(lhs, rhs);
  }
  {
    boost::dynamic_bitset<Block> lhs(long_string), rhs(long_string);
    Tests::sub_assignment(lhs, rhs);
  }
  //=====================================================================
  // Test operator<<=
  { // case pos == 0
    std::size_t pos = 0;
    {
      boost::dynamic_bitset<Block> b;
      Tests::shift_left_assignment(b, pos);
    }
    {
      boost::dynamic_bitset<Block> b(std::string("1010"));
      Tests::shift_left_assignment(b, pos);
    }
    {
      boost::dynamic_bitset<Block> b(long_string);
      Tests::shift_left_assignment(b, pos);
    }
  }
  {
    // test with both multiple and
    // non multiple of bits_per_block
    const int how_many = 10;
    for (int i = 1; i <= how_many; ++i) {
        std::size_t     multiple = i * bits_per_block;
        std::size_t non_multiple = multiple - 1;
        boost::dynamic_bitset<Block> b(long_string);

        Tests::shift_left_assignment(b, multiple);
        Tests::shift_left_assignment(b, non_multiple);
    }
  }
  { // case pos == size()/2
    std::size_t pos = long_string.size() / 2;
    boost::dynamic_bitset<Block> b(long_string);
    Tests::shift_left_assignment(b, pos);
  }
  { // case pos >= n
    std::size_t pos = long_string.size();
    boost::dynamic_bitset<Block> b(long_string);
    Tests::shift_left_assignment(b, pos);
  }
  //=====================================================================
  // Test operator>>=
  { // case pos == 0
    std::size_t pos = 0;
    {
      boost::dynamic_bitset<Block> b;
      Tests::shift_right_assignment(b, pos);
    }
    {
      boost::dynamic_bitset<Block> b(std::string("1010"));
      Tests::shift_right_assignment(b, pos);
    }
    {
      boost::dynamic_bitset<Block> b(long_string);
      Tests::shift_right_assignment(b, pos);
    }
  }
  {
    // test with both multiple and
    // non multiple of bits_per_block
    const int how_many = 10;
    for (int i = 1; i <= how_many; ++i) {
        std::size_t     multiple = i * bits_per_block;
        std::size_t non_multiple = multiple - 1;
        boost::dynamic_bitset<Block> b(long_string);

        Tests::shift_right_assignment(b, multiple);
        Tests::shift_right_assignment(b, non_multiple);
    }

  }
  { // case pos == size()/2
    std::size_t pos = long_string.size() / 2;
    boost::dynamic_bitset<Block> b(long_string);
    Tests::shift_right_assignment(b, pos);
  }
  { // case pos >= n
    std::size_t pos = long_string.size();
    boost::dynamic_bitset<Block> b(long_string);
    Tests::shift_right_assignment(b, pos);
  }
  //=====================================================================
  // test b.set()
  {
    boost::dynamic_bitset<Block> b;
    Tests::set_all(b);
  }
  {
    boost::dynamic_bitset<Block> b(std::string("0"));
    Tests::set_all(b);
  }
  {
    boost::dynamic_bitset<Block> b(long_string);
    Tests::set_all(b);
  }
  //=====================================================================
  // Test b.set(pos)
  { // case pos >= b.size()
    boost::dynamic_bitset<Block> b;
    Tests::set_one(b, 0, true);
  }
  { // case pos < b.size()
    boost::dynamic_bitset<Block> b(std::string("0"));
    Tests::set_one(b, 0, true);
  }
  { // case pos == b.size() / 2
    boost::dynamic_bitset<Block> b(long_string);
    Tests::set_one(b, long_string.size()/2, true);
  }
  //=====================================================================
  // Test b.reset()
  {
    boost::dynamic_bitset<Block> b;
    Tests::reset_all(b);
  }
  {
    boost::dynamic_bitset<Block> b(std::string("0"));
    Tests::reset_all(b);
  }
  {
    boost::dynamic_bitset<Block> b(long_string);
    Tests::reset_all(b);
  }
  //=====================================================================
  // Test b.reset(pos)
  { // case pos >= b.size()
    boost::dynamic_bitset<Block> b;
    Tests::reset_one(b, 0);
  }
  { // case pos < b.size()
    boost::dynamic_bitset<Block> b(std::string("0"));
    Tests::reset_one(b, 0);
  }
  { // case pos == b.size() / 2
    boost::dynamic_bitset<Block> b(long_string);
    Tests::reset_one(b, long_string.size()/2);
  }
  //=====================================================================
  // Test ~b
  {
    boost::dynamic_bitset<Block> b;
    Tests::operator_flip(b);
  }
  {
    boost::dynamic_bitset<Block> b(std::string("1"));
    Tests::operator_flip(b);
  }
  {
    boost::dynamic_bitset<Block> b(long_string);
    Tests::operator_flip(b);
  }
  //=====================================================================
  // Test b.flip()
  {
    boost::dynamic_bitset<Block> b;
    Tests::flip_all(b);
  }
  {
    boost::dynamic_bitset<Block> b(std::string("1"));
    Tests::flip_all(b);
  }
  {
    boost::dynamic_bitset<Block> b(long_string);
    Tests::flip_all(b);
  }
  //=====================================================================
  // Test b.flip(pos)
  { // case pos >= b.size()
    boost::dynamic_bitset<Block> b;
    Tests::flip_one(b, 0);
  }
  { // case pos < b.size()
    boost::dynamic_bitset<Block> b(std::string("0"));
    Tests::flip_one(b, 0);
  }
  { // case pos == b.size() / 2
    boost::dynamic_bitset<Block> b(long_string);
    Tests::flip_one(b, long_string.size()/2);
  }
}