#ifndef __BA1300_H
#define __BA1300_H  

#include "ba1100.h"

#if XVT_OS == XVT_OS_WIN
#define Separator '\\'
#else
#define Separator '/'
#endif

////////////////////////////////////////
//  Here defining classes             //
////////////////////////////////////////

class TTestSheet : public TDir_sheet
{
  TBit_array    _oldstatus; // Previous status of selected files
protected:
  void page_build(long first, byte rows);
public:
  TTestSheet(const char* titolo,  byte bottoni = 0x0);
  ~TTestSheet() ;
  void sr_status(bool save=TRUE);
};

class TTestFile : public TBaseisamfile
{
public:
  TTestFile(int ln,bool lt=TRUE) : TBaseisamfile(ln,lt) {}
  virtual ~TTestFile() {}
  int   close()   {return _close();}
  int   open(unsigned int mode = _manulock) {return _open(mode);}
  const char * file_name() const {return filename();}
};

class TTestWin : public TIndwin
{
protected:
  virtual void update() {update_text();}
  virtual void handler(WINDOW w, EVENT *e);
  void update_text() {set_mode(M_COPY); check_stop();}
public:
  void WriteW(short x, short y, const char* line) {stringat(x,y,line);update_text();do_events();}
  TTestWin(); 
  ~TTestWin() {};
};

class TTestProc
{
  TTestSheet  * _sheet;     // Sheet with files selected
  TTestFile   * _workf;     // working file
  TTestWin    * _win;       // Output window
  long        * _randseq;   // Random sequence
  long          _ntest;     // number of test in progress
  int           _nfile;     // number of file being tested
  long          _kriminal;  // number of record incriminated (Debug)
  int           _nkeys;     // # of keys defined for current file
  bool          _block;     // is test blocked ?
  bool          _rmc;       // Remove copies at the end of test ?
protected:
  void  do_random(long eod);
  void  filecopy(bool save=TRUE);
  void  DumpReport(int err, long i, long x, int key);
  long  sumop(const long n) {return ((n+1)*(n/2)+(n%2)*((n+1)/2));}
  int   ctrl_keys();
  bool  show_mess(int, int, long, long, int);
  const char * fmttime(const long);
public:
  TTestProc();
  ~TTestProc();
  const char* get_base();
  void do_test_1();
  void do_test_2();
  void do_debug();
  void remove_copy(int n);
  void load_random(const TString& st);
  bool stopped()    {return _block;}
  bool rm_copy()    {return _rmc;}
  void set_rmc(bool a=FALSE)    {_rmc = a;}
  long num_test()   {return _ntest;}
  void set_numt(const long num)   { _ntest = num;}
  int num_file()   {return _nfile;}
  void set_file(int n) {_nfile=n;}
  long number(const long n)  {return _randseq[n];}
  void set_sheet (TTestSheet * sh) {_sheet=sh;}
  TTestSheet * get_isheet() {return _sheet;}
  TTestWin   * get_win()    {return _win;}
};

class TTestReport : public TScroll_window
{
  TArray _report;
protected:
  virtual void update();
  virtual bool on_key(KEY);
public:
  TTestReport(const char* title);
  ~TTestReport() {};
  void load_report();
  TString& get_row(int n) {return (TString&)_report[n];}
};
#endif
