class SimulatedObjectBase
{
public:
std::string m_className;
public:
explicit SimulatedObjectBase(std::string const & in_objectName, std::string const & in_className = "SimulatedObjectBase");
virtual ~SimulatedObjectBase();
virtual void SetObjectName (std::string const& in_objectName)
{
m_objectName = in_objectName;
}
const std::string& GetClassName() const {return m_className;}
const std::string& GetObjectName() const {return m_objectName;}
const std::string& GetTraceName() const {return m_objectName;}
virtual void _Dump(EventContext in_context = CTX_INFO) const;
void _SetOption (
std::string const & in_option,
std::string const & in_scope = Option::ALL,
OptionType::Enum in_optionType = OptionType::PERMANENTLY_ACTIVE,
int in_numRemainingCalls = 0) const;
void _SetOptionValue(
std::string const & in_name,
std::string const & in_value,
std::string const & in_scope = Option::ALL) const;
void _ResetOption(
std::string const & in_option,
std::string const & in_scope = Option::ALL) const;
void _ResetOptions (void) const;
bool _IsOptionSet (
std::string const & in_option,
std::string const & in_scope = Option::ALL) const;
bool _WasOptionSet(
std::string const & in_option,
std::string const & in_scope = Option::ALL) const;
std::string _GetOptionValueStr(std::string const & in_name, std::string const & in_scope = Option::ALL) const;
template<class T> T _GetOptionValue(const std::string& in_nameOption, std::string const & in_scope = Option::ALL) const
{
std::string optionValAsString = _GetOptionValueStr(in_nameOption, in_scope);
std::istringstream iss(optionValAsString);
T result = T();
if ((iss >> result).fail())
{
result = T();
std::ostringstream oss;
oss << "Could not convert option value >" << in_nameOption
<< "< with value >" << optionValAsString << "<"
<< " to type >" << typeid(T).name() << "<";
TRCF("SimulatedObjectBase::_GetOptionValue");
TRC(TL_ERROR, "WARNING: %s", oss.str().c_str());
}
return result;
}
bool _IsSilent (std::string const & in_scope = Option::ALL) const;
bool _IsError(std::string const & in_scope = Option::ALL) const;
bool _WasError(std::string const & in_scope = Option::ALL) const;
Options& _GetOptions(void) const;
void _ContinueExecution (std::string const & in_methodName) const;
virtual void _Trigger(int in_hint = 0) const;
protected:
void _MethodCall(std::string const & in_methodName, std::string const & in_callInfo = "", StringFunc in_func = StringFuncEmpty) const;
template <typename RT> RT _MethodCallReturn(std::string const & in_methodName, std::string const & in_callInfo = "", StringFunc in_func = StringFuncEmpty) const
{
typename RT retVal = RT();
std::string methodName = ExtractFunctionName(in_methodName);
_MethodCall(methodName,
in_callInfo,
([&](void) -> std::string
{
bool simulateFailure = _IsError(methodName);
std::string info = TestToolBox::MakeReturnValue(retVal,
simulateFailure, methodName, this);
if (info.empty() && simulateFailure)
{
info = "return error";
}
std::string infoFromFuncCall = in_func();
if (!infoFromFuncCall.empty() && !info.empty())
{
infoFromFuncCall += " ";
}
return infoFromFuncCall + info;
}));
return retVal;
};
void _EnsureWaitableConditionExists(std::string const & methodName) const;
Option* _FindOption(std::string const & in_option, std::string const & in_scope) const;
private:
std::string m_objectName;
Options mutable m_options;
WaitableConditions mutable m_waitableConditions;
boost::mutex mutable m_mutex;
};