/*

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 "blockeditor.h"
#include "navigator.h"
#include <string.h>

//global variables

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

  Accumulator    buffer;
  BlockEditor    filter;
  Navigator      scout;
  
  
  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("Setting the scouts accumulator\n");
  scout.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",           scout.LinePos(filter.SelectionStart()) ); 
  
  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", scout.LinePos(filter.SelectionStart()) ); 
 
  printf("--------------------------- 4 ------------------------\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(scout.LineEnd(filter.SelectionStart()));
  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("----------------------- 5 ----------------------\n");
    
  printf("Selecting next line using NextLine \n");
  filter.SelectionStart(scout.NextLine(filter.SelectionStart()));  
  filter.SelectionEnd(scout.LineEnd(filter.SelectionStart()));    
  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 );
}

