// file: $isip/class/search/ContextMap/cmap_02.cc
// version: $Id: cmap_02.cc 8858 2002-12-05 20:08:33Z alphonso $
//

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

// method: diagnose
//
// arguments:
//  Integral::DEBUG level: (input) debug level for diagnostics
//
// return: a boolean value indicating status
//
// this is the diagnose method
//
boolean ContextMap::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();
  }

  // declare variables
  //
  ContextMap cont_map_00;  

  // set up the search symbols
  //
  SearchSymbol sym_00(L"S_1");
  SearchSymbol sym_01(L"S_2");
  SearchSymbol sym_02(L"S_3");
  
  Vector<SearchSymbol> syms(3);

  syms(0).assign(sym_00);
  syms(1).assign(sym_01);
  syms(2).assign(sym_02); 
  
  // test the context methods
  //
  cont_map_00.setContext(syms);

  if (!cont_map_00.getContext().eq(syms)) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }

  // test the context index methods
  //
  cont_map_00.setContextIndex(3);
  
  if ((ulong)cont_map_00.getContextIndex() != 3) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }

  cont_map_00.setContextIndex(31);
  
  if ((ulong)cont_map_00.getContextIndex() != 31) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }  

  // test the assign methods
  //
  ContextMap cont_map_01(cont_map_00);

  if (!cont_map_00.eq(cont_map_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(); 
  }

  // 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;
}
