// file: $isip/class/search/HistoryPool/cpol_02.cc
// version: $Id: hpol_02.cc 8974 2003-01-11 17:49:53Z alphonso $
//

// isip include files
//
#include "HistoryPool.h"

// method: diagnose
//
// arguments:
//  Integral::DEBUG level: (input) debug level for diagnostics
//
// return: logical error status
//
// this is the diagnostics method
//
boolean HistoryPool::diagnose(Integral::DEBUG level_a) {

  //----------------------------------------------------------------------
  //
  // 0. preliminaries
  //
  //----------------------------------------------------------------------

  // output the class name
  //
  if (level_a > Integral::NONE) {
    SysString output(L"diagnosing class ");
    output.concat(CLASS_NAME);
    output.concat(L": ");
    Console::put(output);
    Console::increaseIndention();
  }

  //---------------------------------------------------------------------
  //
  // 1. required public methods
  //
  //---------------------------------------------------------------------

  // set indentation
  //
  if (level_a > Integral::NONE) {
    Console::put(L"testing required public methods...\n");
    Console::increaseIndention();
  }
  
  HistoryPool hpol_00;
  HistoryPool hpol_01;

  History* hist_00 = (History*)NULL;
  History* hist_01 = (History*)NULL;
  
  if (!hpol_00.eq(hpol_01)) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }

  hist_00 = hpol_00.initAndAllocate();
  
  if (hpol_00.eq(hpol_01)) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }

  hist_01 = hpol_00.initAndAllocate();

  if (hist_00 != hist_01) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }
  
  // reset indentation
  //
  if (level_a > Integral::NONE) {
    Console::decreaseIndention();
  }

  //---------------------------------------------------------------------
  //
  // 2. class-specific public methods
  //
  //---------------------------------------------------------------------

  // set indentation
  //
  if (level_a > Integral::NONE) {
    Console::put(L"testing class-specific public methods...\n");
    Console::increaseIndention(); 
  }

  Context cont_00;
  Context cont_01;
  
  History* hist_02 = (History*)NULL;
  History* hist_03 = (History*)NULL;
  
  hist_02 = hpol_00.pushAndAllocate(hist_01, &cont_00);
  hist_03 = hpol_00.pushAndAllocate(hist_02, &cont_01);  

  Context* cont_02 = (Context*)NULL;
  Context* cont_03 = (Context*)NULL;  
  
  History* hist_04 = (History*)NULL;
  History* hist_05 = (History*)NULL;

  hist_04 = hpol_00.popAndAllocate(hist_03, cont_02);
  hist_05 = hpol_00.popAndAllocate(hist_04, cont_03);

  if (hist_04 != hist_02) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }
  if (hist_05 != hist_01) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }

  if (&cont_01 != cont_02) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }
  if (&cont_00 != cont_03) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }  
  
  // reset indentation
  //
  if (level_a > Integral::NONE) {
    Console::decreaseIndention();
  }
  
  //---------------------------------------------------------------------
  //
  // 4. print completion message
  //
  //---------------------------------------------------------------------

  // reset indentation
  //
  if (level_a > Integral::NONE) {
    Console::decreaseIndention();
  }
  
  if (level_a > Integral::NONE) {
    SysString output(L"diagnostics passed for class ");
    output.concat(name());
    output.concat(L"\n");
    Console::put(output);
  }
  
  // exit gracefully
  //
  return true;
}
