// file: $isip/class/asr/Machine/mach_02.cc
//

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

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

  String tmp_str;
  Machine mach_00;

  // test the protocol methods
  //
  if (!mach_00.setProtocol(Machine::REMOTE_SHELL)) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }
  if (mach_00.getProtocol() != Machine::REMOTE_SHELL) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }

  // set the node name methods
  //
  tmp_str.assign(L"isip004");
  if (!mach_00.setNodeName(tmp_str)) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }
  if (!mach_00.getNodeName().eq(tmp_str)) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }

  // test the architecture methods
  //
  tmp_str.assign(L"sparc");  
  if (!mach_00.setArchitecture(tmp_str)) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }
  if (!mach_00.getArchitecture().eq(tmp_str)) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }

  // test the num processors methods
  //
  if (!mach_00.setNumProcessors(2)) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }
  if (mach_00.getNumProcessors() != 2) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }

  // test the processor speed methods
  //
  VectorDouble speed_00(2);
  speed_00(0) = 8.0e9;
  speed_00(1) = 1.0e12;
  
  if (!mach_00.setProcessorSpeed(speed_00)) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }

  if (!mach_00.getProcessorSpeed().eq(speed_00)) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }  
  
  // test the main memory methods
  //
  if (!mach_00.setMainMemory(8.0e8)) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }
  if (!Integral::almostEqual(mach_00.getMainMemory(), 8.0e8)) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }

  // test the swap memory methods
  //
  if (!mach_00.setSwapMemory(800e6)) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }
  if (!Integral::almostEqual(mach_00.getSwapMemory(), 8.0e8)) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }

  // test the OS methods
  //
  tmp_str.assign(L"solaris");
  if (!mach_00.setOS(tmp_str)) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }
  if (!mach_00.getOS().eq(tmp_str)) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }

  // test the OS version methods
  //
  tmp_str.assign(L"7.0");  
  if (!mach_00.setOSVersion(tmp_str)) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }
  if (!mach_00.getOSVersion().eq(tmp_str)) {
    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);
  }  
  
  // reset indentation
  //
  if (level_a > Integral::NONE) {
    Console::decreaseIndention();
  }

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