in testtools/micromock/tools/micromockgenerator/micromockgenerator.cpp [145:405]
void GenerateTimeDiscreteMockCallMacros(_In_ size_t supportedArgCount)
{
unsigned int i,j;
/*intended as ANSI, non TCHAR, since it produces C++ source code*/
ofstream fout("timediscretemicromockcallmacros.h");
fout<<CfileHeader<<endl;
for(i=0;i<supportedArgCount;i++)
{
fout<<"#define MOCK_TD_METHOD_"<<i<<"(prefix, resultType, name";
//write the argument list...
for(j=1;j<=i;j++)
{
fout<<", arg"<<j<<"Type, arg"<<j<<"Value";
}
//close the argument list
fout<<") \\"<<endl;
//MOCK_METHOD1... same thing
fout<<tab<<"MOCK_METHOD_"<<i<<"(prefix, resultType, name";
for(j=1;j<=i;j++)
{
fout<<", arg"<<j<<"Type, arg"<<j<<"Value";
}
fout<<")\\"<<endl;
fout<<tab<<"mockMethodCall->AddExtraCallArgument(new CMockCallArgument<UINT32>(MOCK_TIMEPROVIDER(__FUNCTION__)));\\"<<endl;
fout<<tab<<"result = REMATCH_ACTUAL_STATIC_MOCK_CALL(mockMethodCall);\\"<<endl;
fout<<endl;
fout << "#define MOCK_STATIC_TD_METHOD_" << i << "(prefix, resultType, name";
//write the argument list...
for (j = 1; j <= i; j++)
{
fout << ", arg" << j << "Type, arg" << j << "Value";
}
//close the argument list
fout << ") \\" << endl;
//MOCK_METHOD_n ... same thing
fout << tab << "MOCK_STATIC_METHOD_" << i << "(prefix, resultType, name";
for (j = 1; j <= i; j++)
{
fout << ", arg" << j << "Type, arg" << j << "Value";
}
fout << ")\\" << endl;
fout << tab << "mockMethodCall->AddExtraCallArgument(new CMockCallArgument<UINT32>(MOCK_TIMEPROVIDER(__FUNCTION__)));\\" << endl;
fout << tab << "result = REMATCH_ACTUAL_STATIC_MOCK_CALL(mockMethodCall);\\" << endl;
fout << endl;
}
fout<<"#define STIM_CALL_AT(var, time, ...) var.__VA_ARGS__.SetTime(time, var.getAndIncOrder(time))"<<endl;
fout<<endl;
for(i=0;i<supportedArgCount;i++)
{
fout<<"#define DECLARE_STIM_STATIC_TD_METHOD_"<<i<<"(prefix, resultType, name";
for(j=1;j<=i;j++)
{
fout<<", arg"<<j<<"Type, arg"<<j<<"Value";
}
fout<<")\\"<<endl;
fout<<"class pFunctionCall_Wrapper_##name \\"<<endl;
fout<<"{\\"<<endl;
fout<<tab<<"public:\\"<<endl;
fout<<tab<<"typedef resultType (*pRealFunctionType)(";
for(j=1;j<=i;j++)
{
fout<<"arg"<<j<<"Type arg"<<j<<"Value";
if((i>0) &&(j<i))fout<<", ";
}
fout<<");\\"<<endl;
fout<<tab<<"static pRealFunctionType realFunction;\\"<<endl;
fout<<"};\\"<<endl;
fout<<"pFunctionCall_Wrapper_##name::pRealFunctionType pFunctionCall_Wrapper_##name::realFunction = ::name; /*so this never can go to a header*/"<<endl;
fout<<endl;
fout<<"#define STIM_STATIC_TD_METHOD_"<<i<<"(prefix, resultType, name ";
for(j=1;j<=i;j++)
{
fout<<", arg"<<j<<"Type, arg"<<j<<"Value";
}
fout<<") call"<<i<<"Arg<resultType, ";
for(j=1;j<=i;j++)
{
fout<<"arg"<<j<<"Type, ";
}
fout<<"pFunctionCall_Wrapper_##name > name;"<<endl;
fout<<endl;
}
for(i=0;i<supportedArgCount;i++)
{
fout<<"template<typename resultType,";
for(j=1;j<=i;j++)
{
fout<<"typename arg"<<j<<"Type, ";
}
fout<<"class C>";
fout<<"class call"<<i<<"Arg : public canPlay"<<endl;
fout<<"{"<<endl;
fout<<"private:"<<endl;
fout<<tab<<"class timeS"<<endl;
fout<<tab<<"{"<<endl;
fout<<tab<<"public:"<<endl;
fout<<tab<<tab<<"timeS(";
for(j=1;j<=i;j++)
{
fout<<"arg"<<j<<"Type arg"<<j<<"Value";
if((i>0) && (j<i)) fout<<", ";
}
fout<<"): "<<endl;
fout<<tab<<tab<<"time(0), order(0)";
for(j=1;j<=i;j++)
{
fout<<", arg"<<j<<"(arg"<<j<<"Value)";
}
fout<<endl;
fout<<tab<<tab<<"{"<<endl;
fout<<tab<<tab<<"}"<<endl;
fout<<tab<<tab<<"UINT32 time;"<<endl;
fout<<tab<<tab<<"UINT32 order;"<<endl;
for(j=1;j<=i;j++)
{
fout<<tab<<tab<<"valueHolder<arg"<<j<<"Type> arg"<<j<<";"<<endl;
}
fout<<tab<<"};"<<endl;
fout<<tab<<"std::vector<timeS> allCalls;"<<endl;
fout<<"public:"<<endl;
fout<<tab<<"call"<<i<<"Arg()"<<endl;
fout<<tab<<"{"<<endl;
fout<<tab<<tab<<"stims_base::registerCallXArg(this);"<<endl;
fout<<tab<<"}"<<endl;
fout<<endl;
fout<<tab<<"virtual ~call"<<i<<"Arg<resultType, ";
for(j=1;j<=i;j++)
{
fout<<"arg"<<j<<"Type, ";
}
fout<<" C>()"<<endl;
fout<<tab<<"{"<<endl;
fout<<tab<<"}"<<endl;
fout<<tab<<"virtual void PlayTick(_In_ UINT32 tick, _In_ UINT32 order)"<<endl;
fout<<tab<<"{"<<endl;
fout<<tab<<tab<<"for(UINT32 i=0; i<allCalls.size();i++)"<<endl;
fout<<tab<<tab<<"{"<<endl;
fout<<tab<<tab<<tab<<"if((allCalls[i].time==tick)&&(allCalls[i].order==order))"<<endl;
fout<<tab<<tab<<tab<<"{"<<endl;
fout<<tab<<tab<<tab<<tab<<"C::realFunction(";
for(j=1;j<=i;j++)
{
fout<<"allCalls[i].arg"<<j;
if((i>0)&&(j<i)) fout<<", ";
}
fout<<");"<<endl;
fout<<tab<<tab<<tab<<"}"<<endl;
fout<<tab<<tab<<"}"<<endl;
fout<<tab<<"}"<<endl;
fout<<endl;
fout<<tab<<"call"<<i<<"Arg<resultType, ";
for(j=1;j<=i;j++)
{
fout<<"arg"<<j<<"Type, ";
}
fout<<"C>& SetTime(_In_ UINT32 time, _In_ UINT32 order)"<<endl;
fout<<tab<<"{"<<endl;
fout<<tab<<tab<<"if(allCalls.size()==0)"<<endl;
fout<<tab<<tab<<"{"<<endl;
fout<<tab<<tab<<tab<<"throw CMicroMockException(MICROMOCK_EXCEPTION_SET_TIME_BEFORE_CALL, _T(\"using SetTime before the call has been defined usually indicates an error in test code\"));"<<endl;
fout<<tab<<tab<<"}"<<endl;
fout<<tab<<tab<<"else"<<endl;
fout<<tab<<tab<<"{"<<endl;
fout<<tab<<tab<<tab<<"allCalls[allCalls.size()-1].time=time;"<<endl;
fout<<tab<<tab<<tab<<"allCalls[allCalls.size()-1].order=order;"<<endl;
fout<<tab<<tab<<"}"<<endl;
fout<<tab<<tab<<"return *this;"<<endl;
fout<<tab<<"}"<<endl;
fout<<endl;
fout<<tab<<"call"<<i<<"Arg<resultType, ";
for(j=1;j<=i;j++)
{
fout<<"arg"<<j<<"Type, ";
}
fout<<" C>& operator()(";
for(j=1;j<=i;j++)
{
fout<<"arg"<<j<<"Type arg"<<j;
if((i>0)&&(j<i)) fout<<",";
}
fout<<")"<<endl;
fout<<tab<<"{"<<endl;
fout<<tab<<tab<<"timeS s"<<((i==0)?"":"(");
for(j=1;j<=i;j++)
{
fout<<"arg"<<j;
if((i>0)&&(j<i)) fout<<", ";
}
fout<<((i==0)?"":")")<<";"<<endl;
fout<<tab<<tab<<"allCalls.push_back(s); /*time is updated \"later\" by chaining*/"<<endl;
fout<<tab<<tab<<"return *this;"<<endl;
fout<<tab<<"}"<<endl;
fout<<endl;
if(i>0)
{
fout<<tab<<"call"<<i<<"Arg<resultType, ";
for(j=1;j<=i;j++)
{
fout<<"arg"<<j<<"Type, ";
}
fout<<" C>& setArraySize(_In_ UINT32 parameter, _In_ size_t nElements)"<<endl;
fout<<tab<<"{"<<endl;
fout<<tab<<tab<<"if(allCalls.size()==0)"<<endl;
fout<<tab<<tab<<"{"<<endl;
fout<<tab<<tab<<tab<<"throw CMicroMockException(MICROMOCK_EXCEPTION_SET_ARRAY_SIZE_BEFORE_CALL, _T(\"using setArraySize before the call has been defined usually indicates an error in test code\"));"<<endl;
fout<<tab<<tab<<"}"<<endl;
fout<<tab<<tab<<"else"<<endl;
fout<<tab<<tab<<"{"<<endl;
fout<<tab<<tab<<tab<<"timeS& s = allCalls[allCalls.size()-1]; /*get the last element*/"<<endl;
fout<<tab<<tab<<tab<<"switch(parameter)"<<endl;
fout<<tab<<tab<<tab<<"{"<<endl;
for(j=1;j<=i;j++)
{
fout<<tab<<tab<<tab<<tab<<"case "<<j<<":"<<endl;
fout<<tab<<tab<<tab<<tab<<"{"<<endl;
fout<<tab<<tab<<tab<<tab<<tab<<"s.arg"<<j<<".setArraySize(nElements);"<<endl;
fout<<tab<<tab<<tab<<tab<<tab<<"break;"<<endl;
fout<<tab<<tab<<tab<<tab<<"}"<<endl;
}
fout<<tab<<tab<<tab<<tab<<"default:"<<endl;
fout<<tab<<tab<<tab<<tab<<"{"<<endl;
fout<<tab<<tab<<tab<<tab<<tab<<"ASSERT_FAIL(_T(\"there are no parameters so big\"));"<<endl;
fout<<tab<<tab<<tab<<tab<<"}"<<endl;
fout<<tab<<tab<<tab<<"}"<<endl;
fout<<tab<<tab<<tab<<"return *this;"<<endl;
fout<<tab<<tab<<"}"<<endl;
fout<<tab<<"}"<<endl;
}
fout<<"};"<<endl;
fout<<endl;
}
fout<<"#endif // TIMEDISCRETEMICROMOCKCALLMACROS_H"<<endl;
fout<<endl;
fout.close();
}