Skip to content
Snippets Groups Projects
AlgorithmHistoryTest.h 2.53 KiB
Newer Older
Dickon Champion's avatar
Dickon Champion committed
#ifndef ALGORITHMHISTORYTEST_H_
#define ALGORITHMHISTORYTEST_H_

#include <cxxtest/TestSuite.h>
Dickon Champion's avatar
Dickon Champion committed
#include "MantidAPI/AlgorithmHistory.h"
#include "MantidAPI/WorkspaceProperty.h"
Nick Draper's avatar
Nick Draper committed
#include <sstream>
Dickon Champion's avatar
Dickon Champion committed

using namespace Mantid::API;
Dickon Champion's avatar
Dickon Champion committed

// 'Empty' algorithm class for tests
class testalg : public Algorithm
{
public:
  testalg() : Algorithm() {}
  virtual ~testalg() {}
  const std::string name() const { return "testalg";} ///< Algorithm's name for identification
  const int version() const { return 1;} ///< Algorithm's version for identification
  const std::string category() const { return "Cat";} ///< Algorithm's category for identification

  void init()
  {
    declareProperty(new WorkspaceProperty<Workspace>("arg1_param","x",Direction::Input));
    declareProperty("arg2_param",23);
  }
  void exec() {}
};
Dickon Champion's avatar
Dickon Champion committed

class AlgorithmHistoryTest : public CxxTest::TestSuite
{
public:
  void testPopulate()
  {
    std::string correctOutput = "Algorithm: testalg ";
    correctOutput = correctOutput + "v1\n";
Nick Draper's avatar
Nick Draper committed
    correctOutput = correctOutput + "Execution Date: 2008-Feb-29 09:54:49\n";
    correctOutput = correctOutput + "Execution Duration: 14 seconds\n";
    correctOutput = correctOutput + "Parameters:\n";
    correctOutput = correctOutput + "  Name: arg1_param, ";
    correctOutput = correctOutput + "Value: 20, ";
    correctOutput = correctOutput + "Default?: No, ";
    correctOutput = correctOutput + "Direction: Input\n";
    correctOutput = correctOutput + "  Name: arg2_param, ";
    correctOutput = correctOutput + "Value: 23, ";
    correctOutput = correctOutput + "Default?: Yes, ";
    correctOutput = correctOutput + "Direction: N/A\n";
Nick Draper's avatar
Nick Draper committed

    //set the time
    std::time_t rawtime;
    std::tm * timeinfo = new std::tm;
    timeinfo->tm_isdst = -1;
Nick Draper's avatar
Nick Draper committed

    /* The datetime must match that in the strng above */
Nick Draper's avatar
Nick Draper committed
    timeinfo->tm_year = 108;
    timeinfo->tm_mon = 1;
    timeinfo->tm_mday = 29;
    timeinfo->tm_hour = 9;
    timeinfo->tm_min = 54;
    timeinfo->tm_sec = 49;
    std::time_t execTime = mktime ( timeinfo );
Nick Draper's avatar
Nick Draper committed

Dickon Champion's avatar
Dickon Champion committed
    // Not really much to test
    Algorithm *alg = new testalg;
    alg->initialize();
    alg->setPropertyValue("arg1_param","20");
Nick Draper's avatar
Nick Draper committed

    AlgorithmHistory AH(alg,execTime,14.0);
Nick Draper's avatar
Nick Draper committed
    //dump output to sting
    std::ostringstream output;
    output.exceptions( std::ios::failbit | std::ios::badbit );
Nick Draper's avatar
Nick Draper committed
    TS_ASSERT_THROWS_NOTHING(output << AH);
    TS_ASSERT_EQUALS(output.str(),correctOutput);
Dickon Champion's avatar
Dickon Champion committed

  }


};

#endif /* ALGORITHMHISTORYTEST_H_*/