/*

accumulator test

             CREATOR: DAn williams
                DATE:
         DESCRIPTION: test the viewport class
            FILENAME: fileaccumtest.cpp
             STARTED: jan 22
    OPERATING SYSTEM: Linux
1st VERSION FINISHED:

This code tests the functions of an accumulator

  char * DataEnd()
  long   GetSize( void );
  int    ReSize( long newSize);
  long   Insert( long position, long size);
  long   Remove( long position, long size);

*/


#include <stdio.h>
#include <stdlib.h>

void Error( char * desc );

#include "accumulator2.h"
#include "contentfilter.h"
#include <string.h>

//global variables

int main(int argc, char** argv)
{

  Accumulator    buffer;
  ContentFilter  filter;
  
  char           foo[20];
  long           fool;

  char *tempBuff = new char[1024];  

  printf("Setting buffer contents to 0123456789\n");

  //buffer.ReSize( 10 );
  //strcpy( buffer.Contents, "0123456789");
  buffer.SetN(0, 0, "0123456789\0", 11);
  buffer.ReadN(0, tempBuff, 1022);
  printf("Buffer Contents: %s\n", tempBuff);
  //printf("Buffer Contents: %s\n", buffer.Contents);

  printf("------------------ 1 ----------------\n");
 
  printf("Setting the filters accumulator\n");
  filter.SetAccumulator( &buffer );
  printf("The origional selection start is: %d\n",     filter.SelectionStart());
  printf("The origional selection end is: %d\n",       filter.SelectionEnd());
  printf("The origional selection size is: %d\n",      filter.SelectionSize() );
  printf("The origional selection contents are: %s\n", filter.Read(&foo[0], 18));
  printf("The Cursors line position: %d \n",           filter.LinePos() ); 
  
  printf("-------------------- 2 ----------------\n");

  printf("Setting the selection end to 7\n");
  filter.SelectionEnd( 7 );
  printf("The selection start is: %d\n",     filter.SelectionStart());
  printf("The selection end is: %d\n",       filter.SelectionEnd());
  printf("The selection size is: %d\n",      filter.SelectionSize() );
  printf("The selection contents are: %s\n", filter.Read(&foo[0], 18));
  printf("The Cursors line position: %d \n", filter.LinePos() ); 
   
  printf("-------------------- 3 -----------------\n");

  printf("Setting the selection start to 3\n");
  filter.SelectionStart( 3 );
  printf("The selection start is: %d\n",     filter.SelectionStart());
  printf("The selection end is: %d\n",       filter.SelectionEnd());
  printf("The selection size is: %d\n",      filter.SelectionSize() );
  printf("The selection contents are: %s\n", filter.Read(&foo[0], 18));
  printf("The Cursors line position: %d \n", filter.LinePos() ); 
 
  printf("------------------- 4 -------------------\n");

  printf("Seeking to character 5 via seek_set \n");
  filter.Seek( 5, SEEK_SET );
  printf("expanding selection to 2 characters from 5 \n");
  filter.SelectionEnd(filter.SelectionEnd() + 1); // add 1 character to selection
  printf("The selection start is: %d\n",     filter.SelectionStart());
  printf("The selection end is: %d\n",       filter.SelectionEnd());
  printf("The selection size is: %d\n",      filter.SelectionSize() );
  printf("The selection contents are: %s\n", filter.Read(&foo[0], 18));
  printf("The Cursors line position: %d \n", filter.LinePos() ); 
  //  printf("Buffer Contents: %s\n", buffer.Contents);
  buffer.ReadN(0, tempBuff, 1022);
  printf("Buffer Contents: %s\n", tempBuff);

  printf("------------------------ 5 -------------------\n");

  printf("Replacing the selection with \"Da\"\n");
  filter.Replace( "Da" );
  printf("The selection start is: %d\n", filter.SelectionStart());
  printf("The selection end is: %d\n", filter.SelectionEnd());
  printf("The selection size is: %d\n", filter.SelectionSize() );
  printf("The selection contents are: %s\n", filter.Read(&foo[0], 18));
  //  printf("Buffer Contents: %s\n", buffer.Contents);
  buffer.ReadN(0, tempBuff, 1022);
  printf("Buffer Contents: %s\n", tempBuff);
  printf("The Cursors line position: %d \n", filter.LinePos() ); 

  printf("------------------------- 6 -----------------------\n");

  printf("Replaceing characters 5&6 with \"Dan\" \n");
  filter.SelectionStart(5);
  filter.SelectionEnd(6);
  filter.Replace("Dan");
  printf("The selection start is: %d\n", filter.SelectionStart());
  printf("The selection end is: %d\n", filter.SelectionEnd());
  printf("The selection size is: %d\n", filter.SelectionSize() );
  printf("The selection contents are: %s\n", filter.Read(&foo[0], 18));
  buffer.ReadN(0, tempBuff, 1022);
  printf("Buffer Contents: %s\n", tempBuff);
  //printf("Buffer Contents: %s\n", buffer.Contents);
  printf("The Cursors line position: %d \n", filter.LinePos() ); 

  printf("-------------------------- 7 -----------------------\n");

  printf("Replaceing characters 5->7 with \"\" \n");
  filter.SelectionStart(5);
  filter.SelectionEnd(7);
  filter.Replace("");
  printf("The selection start is: %d\n", filter.SelectionStart());
  printf("The selection end is: %d\n", filter.SelectionEnd());
  printf("The selection size is: %d\n", filter.SelectionSize() );
  printf("The selection contents are: %s\n", filter.Read(&foo[0], 18));
  //printf("Buffer Contents: %s\n", buffer.Contents);
  buffer.ReadN(0, tempBuff, 1022);
  printf("Buffer Contents: %s\n", tempBuff);
  printf("The Cursors line position: %d \n", filter.LinePos() ); 
  
  printf("-------------------------- 8 -----------------------\n");

  printf("putting cursor at position 1 and adding the character A\n");
  filter.Seek( 1, SEEK_SET );
  filter.Putc( 'A' );
  printf("The selection start is: %d\n", filter.SelectionStart());
  printf("The selection end is: %d\n", filter.SelectionEnd());
  printf("The selection size is: %d\n", filter.SelectionSize() );
  printf("The selection contents are: %s\n", filter.Read(&foo[0], 18));
  //printf("Buffer Contents: %s\n", buffer.Contents);
  buffer.ReadN(0, tempBuff, 1022);
  printf("Buffer Contents: %s\n", tempBuff);
  printf("The Cursors line position: %d \n", filter.LinePos() ); 

  printf("--------------------------- 9 ----------------------\n");
  
  printf(" adding the character B\n");
  filter.Putc( 'B' );
  printf("The selection start is: %d\n", filter.SelectionStart());
  printf("The selection end is: %d\n", filter.SelectionEnd());
  printf("The selection size is: %d\n", filter.SelectionSize() );
  printf("The selection contents are: %s\n", filter.Read(&foo[0], 18));
  //  printf("Buffer Contents: %s\n", buffer.Contents);
  buffer.ReadN(0, tempBuff, 1022);
  printf("Buffer Contents: %s\n", tempBuff);
  printf("The Cursors line position: %d \n", filter.LinePos() ); 

  printf ("------------------------- 10 ----------------------\n");

  printf("putting character C over characters 1&2\n");
  filter.SelectionStart(1);
  filter.SelectionEnd(2);
  filter.Putc( 'C' );
  printf("The selection start is: %d\n", filter.SelectionStart());
  printf("The selection end is: %d\n", filter.SelectionEnd());
  printf("The selection size is: %d\n", filter.SelectionSize() );
  printf("The selection contents are: %s\n", filter.Read(&foo[0], 18));
  //printf("Buffer Contents: %s\n", buffer.Contents);
  buffer.ReadN(0, tempBuff, 1022);
  printf("Buffer Contents: %s\n", tempBuff);
  printf("The Cursors line position: %d \n", filter.LinePos() ); 

  printf("-------------------------- 11 -----------------------\n");

  printf(" adding the character B\n");
  filter.Putc( 'B' );
  printf("The selection start is: %d\n", filter.SelectionStart());
  printf("The selection end is: %d\n", filter.SelectionEnd());
  printf("The selection size is: %d\n", filter.SelectionSize() );
  printf("The selection contents are: %s\n", filter.Read(&foo[0], 18));
  //printf("Buffer Contents: %s\n", buffer.Contents);
  buffer.ReadN(0, tempBuff, 1022);
  printf("Buffer Contents: %s\n", tempBuff);
  printf("The Cursors line position: %d \n", filter.LinePos() ); 

  printf("--------------------------- 12 ------------------------\n");

  printf("Setting buffer contents to 012\\n34567\\n89\\0\n");
  buffer.SetN(0, 0, "012\n34567\n89\0", 13);
  buffer.ReadN(0, tempBuff, 1022);
  printf("Buffer Contents: %s\n", tempBuff);
  
  printf("selecting 0:0\n");
  filter.Seek(0,SEEK_SET);
  printf("selecting first line using LineEnd\n");
  filter.SelectionEnd(filter.LineEnd());
  printf("The selection start is: %d\n", filter.SelectionStart());
  printf("The selection end is: %d\n", filter.SelectionEnd());
  printf("The selection size is: %d\n", filter.SelectionSize() );
  printf("The selection contents are: %s\n", filter.Read(&foo[0], 18));

  
     
  printf("Done testing content filter\n");
    
  return ( 0 );
}


//subroutines


void Error( char * desc ){
  printf ("%s\n", desc);
  exit ( 0 );
}

