#include "bitstream.h"
#include <stdio.h>

int main()
{
  static const char filename[]="foobar.xxx";
  const int bits[] = {1,1,0,1,0,1,1,0,0,0,1,1,0,0,0,0,0,1,0};
  const int nbits = sizeof(bits)/sizeof(bits[0]);
  int i;

  BITSTREAM *bsp;

  bsp=bitstream_wopen(fopen(filename, "wb"));
  for(i=0; i<nbits; i++)
  {
    bitstream_wbit(bsp, bits[i]);
  }
  bitstream_wclose(bsp);
  fprintf(stderr, "Write complete.\n"); 

  bsp=bitstream_ropen(fopen(filename, "rb"));
  for(i=0; i<nbits; i++)
  {
    if (bitstream_rbit(bsp)!=bits[i])
      fprintf(stderr, "Bit %d incorrect\n");
  }
  bitstream_rclose(bsp);
  fprintf(stderr, "All complete.\n"); 
}
