// file: $isip/class/pr/LanguageModelBNF/lmbnf_02.cc
// version: $Id: lmbnf_02.cc 10547 2006-04-11 18:49:30Z suh $

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

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

  // test debug methods
  //
  //lmbnf.setDebug(level_a);

  if (level_a > Integral::BRIEF) {
    Console::put(L"testing debug method...");
    lmbnf.debug(L"debug");
  }
  
  // reset indention
  //
  if (level_a > Integral::NONE) {
    Console::decreaseIndention();
  }

  //--------------------------------------------------------------------------
  //
  // 2. public methods:
  //     
  //--------------------------------------------------------------------------

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

  // load grammar file
  //
  Filename model_file_a;
  model_file_a.assign(L"diagnose_grammar_bnf.sof"); 

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

  lm_bnf_file.close();
  
  LanguageModelBNF lmbnf2;

  // test assign method
  //
  if(!(lmbnf2.assign(lmbnf))) {
    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(!lmbnf2.eq(lmbnf)) {
    return Error::handle(name(), L"eq", Error::TEST, __FILE__, __LINE__);
  }  
  if (level_a > Integral::BRIEF) {
    Console::put(L"testing eq method...");
  }

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

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

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

  lmbnf2.clear();

  // test write method is tested with class-specific public methods
  // 
  
  // reset indendtion
  //
  if (level_a > Integral::NONE) {
    Console::decreaseIndention();
  }

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

  // test getRuleMode and setRuleMode
  //
  lmbnf2.setRuleModel(lmbnf.getRuleModel());

  // test write methods
  //
  Sof lm_bnf_file2;
  Filename model_file_a2(L"diagnose_grammar_bnf_output.sof");

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

  if(!lmbnf2.write(lm_bnf_file2,0)) {
    return Error::handle(name(), L"write", Error::TEST, __FILE__, __LINE__);
  }

  lm_bnf_file2.close();  
      
  // reset indendtion
  //
  if (level_a > Integral::NONE) {
    Console::decreaseIndention();
  }
  
  //--------------------------------------------------------------------------
  //
  // 4. Clean up.
  //
  //--------------------------------------------------------------------------    

  //File::cleanTemps();
  
  // 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;
}
