// file: $isip/class/search/SymbolGraph/sgrp_02.cc
// version: $Id: sgrp_02.cc 9311 2003-09-26 20:20:41Z alphonso $
//

// isip include files
//
#include "SymbolGraph.h"
#include <Console.h>

// method: diagnose
//
// arguments:
//  Integral::DEBUG level: (input) debug level for diagnostics
//
// return: logical error status
//
// this is the diagnostics method
//
boolean SymbolGraph::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 local variables
  //
  SymbolGraph symbol_graph_00;
  SymbolGraph symbol_graph_01;
  SymbolGraph symbol_graph_02;  
  
  // read the lattice from disk
  //
  Sof in_text_00;
  in_text_00.open(L"$ISIP_DEVEL/doc/examples/data/models/tidigits_lattice.sof", File::READ_ONLY, File::TEXT);
  
  symbol_graph_00.read(in_text_00, 0);
  in_text_00.close();

  // write the lattice to a temp file (TEXT)
  //
  Filename file_text_00;
  Integral::makeTemp(file_text_00);
  File::registerTemp(file_text_00);
  
  Sof out_text_00;
  out_text_00.open(file_text_00, File::WRITE_ONLY, File::TEXT);

  symbol_graph_00.write(out_text_00, 0);
  out_text_00.close();

  // read the text file back
  //
  Sof in_text_01;
  in_text_01.open(file_text_00, File::READ_ONLY);

  symbol_graph_01.read(in_text_01, 0);
  in_text_01.close();  

  if (!symbol_graph_00.eq(symbol_graph_01)) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }
  
  // write the lattice to a temp file (BINARY)
  //  
  Filename file_bin_00;
  Integral::makeTemp(file_bin_00);
  File::registerTemp(file_bin_00);
  
  Sof out_bin_00;
  out_bin_00.open(file_bin_00, File::WRITE_ONLY, File::BINARY);

  symbol_graph_00.write(out_bin_00, 0);
  out_bin_00.close();

  // read the binary file back
  //
  Sof in_bin_00;
  in_bin_00.open(file_bin_00, File::READ_ONLY);

  symbol_graph_02.read(in_bin_00, 0);
  in_bin_00.close();

  if (!symbol_graph_00.eq(symbol_graph_02)) {
    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;
}
