TestCommandLine.hh 1.95 KB
/*
 * TestCommandLine.hh
 *
 *  Created on: Jan 10, 2013
 *      Author: f.casimir
 */

#ifndef TESTCOMMANDLINE_HH_
#define TESTCOMMANDLINE_HH_

#include <vector>
#include <string>

namespace AMDA {
namespace CSlimFixtures {

class PgmResult;
/**
 * @class TestCommandLine
 * @detail This class is used into script table test. It stores all result of program execution for a later used.
 * To recall a result or a log, it must use expressions of type '${alias:RESULT}' or '${alias:OUTPUT}'.
 * Alias is the name of programm when you call "executeCommandAlias".
 * example of used:
 * !|script|TestCommandLine|
 * |reference|US 64: id 127|id test|
 * |note|!-Exécution du programme SimpleTest-!|
 * |check|execute|SimpleTest|command|cmd1|alias|1|
 * |note|La sortie standard de la commande 1 doit contenir 25 lignes|
 * |check|execute|!-test `wc -l ${cmd1:OUTPUT} | awk '{print $1}'` -eq 25-!|command|count1|alias|0|
 */
class TestCommandLine {
public:
	typedef std::vector<PgmResult*> PgmResultList;
	/**
	 * Constructor
	 */
	TestCommandLine();
	/**
	 * Destructor
	 */
	virtual ~TestCommandLine();

	// Getter methods
	/**
	 * @return last PgmResult of _pgmResultList or NULL if empty.
	 */
	PgmResult* getLastPgmResult();
	/**
	 * @return push a new PgmResult into _pgmResultList and return it.
	 */
	PgmResult* getNewPgmResult(const char* pAlias, const char* pCommand);
	/**
	 * @return a PgmResult* of the _pgmResultList with the alias pAlias or NULL.
	 */
	PgmResult* getPgmResult(const char* alias);

	// Other methods
	static TestCommandLine* from(void *fixtureStorage);

	/**
	 * @details replace into pOriginalCommand the pattern ${alias:variable} with its correspondence from the alias PgmResult.
	 * @return the new reinterpreted string.
	 */
	std::string interpret(std::string pOriginalCommand);

	std::string _currentNameTest;
	PgmResultList _pgmResultList;
	char* _logToDisplay = NULL;
};

} /* namespace CSlimFixtures */
} /* namespace AMDA */
#endif /* TESTCOMMANDLINE_HH_ */