// file: $isip/class/pr/LanguageModelABNF/lmabnf_02.cc
// version: $Id: lmabnf_02.cc 10546 2006-04-11 18:47:42Z suh $

// ISIP include files
//
#include "LanguageModelABNF.h"

// method: diagnose
//
// arguments:
//  Integral::DEBUG level: (input) debug level for diagnostics
//
// return: a boolean value indicating status
//
boolean LanguageModelABNF::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 indention
  //
  if (level_a > Integral::NONE) {
    Console::put(L"testing required public methods...\n");
    Console::increaseIndention();
  }
  
  // test constructor
  //
  LanguageModelABNF lmabnf;
  
  // test debug methods
  //
  if (level_a > Integral::BRIEF) {
    Console::put(L"testing debug method...");
  }
  
  // load grammar file
  //
  Filename model_file_a;
  model_file_a.assign(L"diagnose_grammar_abnf.sof"); 

  Sof lm_abnf_file;
  
  lm_abnf_file.open(model_file_a, File::READ_ONLY);
  
  // test read methods
  //
  if (level_a > Integral::BRIEF) {
    Console::put(L"testing read method...");
  }  
  if(!lmabnf.read(lm_abnf_file,0)){
    return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__);
  }   

  lm_abnf_file.close();
  
  LanguageModelABNF lmabnf2;

  // test assign method
  //
  if(!(lmabnf2.assign(lmabnf))) {
    return Error::handle(name(), L"assign", Error::TEST, __FILE__, __LINE__);
  }
  if (level_a > Integral::BRIEF) {
    Console::put(L"testing assign method...");
  }

  // test eq method
  //
  if(!lmabnf2.eq(lmabnf)) {
    return Error::handle(name(), L"eq", Error::TEST, __FILE__, __LINE__);
  }  
  if (level_a > Integral::BRIEF) {
    Console::put(L"testing eq method...");
  }

  // test operator==
  //
  if(!(lmabnf2 == lmabnf)){
    return Error::handle(name(), L"operator==", Error::TEST, __FILE__, __LINE__);
  }
  if (level_a > Integral::BRIEF) {
    Console::put(L"testing operator== method...");
  }
 
  // test clear method
  //
  if(!lmabnf2.clear(Integral::RESET)) {
    return Error::handle(name(), L"clear", Error::TEST, __FILE__, __LINE__);
  }
  if (level_a > Integral::BRIEF) {
    Console::put(L"testing clear method...");
  } 
  
  // reset indention
  //
  if (level_a > Integral::NONE) {
    Console::decreaseIndention();
  }
  
  //--------------------------------------------------------------------------
  //
  // 2. class-specific public methods:
  //     
  //--------------------------------------------------------------------------

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

  lmabnf2.setRuleModel(lmabnf.getRuleModel());
  lmabnf2.setABNFRuleModel(lmabnf.getABNFRuleModel());
  
  // test write methods
  //
  Sof lm_abnf_file2;
  Filename model_file_a2(L"diagnose_grammar_abnf_output.sof");

  lm_abnf_file2.open(model_file_a2, File::WRITE_ONLY);

  if(!lmabnf2.write(lm_abnf_file2,0)) {
    return Error::handle(name(), L"write", Error::TEST, __FILE__, __LINE__);
  }
  if (level_a > Integral::BRIEF) {
    Console::put(L"testing write method...");
  }  
  lm_abnf_file2.close();  
  
  // reduce indention
  //
  if (level_a > Integral::NONE) {
    Console::decreaseIndention();
  }

  //--------------------------------------------------------------------------
  //
  // 3. Clean up.
  //
  //--------------------------------------------------------------------------    
  
  // reset indention
  //
  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);
  }
  
  // indicate success
  //
  return true;
}
