19 if (
Result ==
TFR.PENDING || other.Result ==
TFR.PENDING)
20 ErrorEx(
"Trying to And while one of the results are PENDING.");
22 if (
Result ==
TFR.SUCCESS && other.Result ==
TFR.SUCCESS)
32 if (
Result ==
TFR.PENDING || other.Result ==
TFR.PENDING)
33 ErrorEx(
"Trying to Or while one of the results are PENDING.");
35 if (
Result ==
TFR.SUCCESS || other.Result ==
TFR.SUCCESS)
47 private Class m_Instance;
48 private string m_Test;
53 m_Instance = instance;
60 bool callResult =
GetGame().GameScript.CallFunction(m_Instance, m_Test,
m_Result, dt);
63 ErrorEx(
string.Format(
"Failed to call function \'%1\' on \'%2\'", m_Test, m_Instance.GetDebugName()));
77 return string.Format(
"%1::%2", m_Instance.ClassName(), m_Test);
86 private int m_Success;
88 private ref TFCallerArr m_Tests;
99 m_SucceededTests = {};
123 void AddTest(
Class instance,
string test,
bool repeat)
128 m_Results.Insert(result);
130 m_Tests.Insert(
new TFCaller(instance, test, result));
133 bool Run(
bool fatal,
float dt)
138 int runningTests = m_Tests.Count();
139 for (
int i = 0; i < runningTests; ++i)
141 TFCaller t = m_Tests[i];
147 foreach (TFCaller doneT : done)
148 m_Tests.RemoveItem(doneT);
151 if (fatal && m_Tests.Count() > 0)
153 Print(
"- Active tests -------------------------");
154 foreach (TFCaller rTest : m_Tests)
155 Print(rTest.GetTest());
156 Print(
"----------------------------------------");
158 ErrorEx(
"Not all tests are done while run was fatal.");
162 return m_Tests.Count() == 0;
165 private bool RunTest(TFCaller caller,
float dt)
167 TFR res = caller.Run(dt).Result;
173 m_FailedTests.Insert(caller.GetTestEx());
177 m_SucceededTests.Insert(caller.GetTestEx());
181 return res !=
TFR.PENDING;
186 return string.Format(
"{ [TFModule] :: Tests: %1 | Success: %2 | Failed: %3 | Pending: %4 }", Count(), Success(), Failed(), Pending());
189 void PrintResult(
string prefix =
"", TestFramework caller = null,
string function =
"")
191 Debug.TFLog(
string.Format(
"%1%2", prefix, Result()), caller, function);
192 if (m_SucceededTests.Count())
194 Debug.TFLog(
" |-[SUCCESS]", caller, function);
195 foreach (
string success : m_SucceededTests)
197 Debug.TFLog(
string.Format(
" |- %1", success), caller, function);
200 if (m_FailedTests.Count())
202 Debug.TFLog(
" |-[FAILED]", caller, function);
203 foreach (
string fail : m_FailedTests)
205 Debug.TFLog(
string.Format(
" |- %1", fail), caller, function);
215 private ref
TFModule m_OnFrameModule;
226 void ~TestFramework()
229 m_OnFrameModule.PrintResult(
"FM: ",
this,
"~TestFrameWork");
242 if (m_OnFrameModule.Run(
false, timeSlice))
256 m_OnFrameModule.AddTest(
this, test,
true);
class AutotestRunner m_Success
ref CatchingResultBasic m_Result
Super root of all classes in Enforce script.
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.
EntityEvent
Entity events for event-mask, or throwing event from code.
proto native TestBase GetTest(int handle)
Returns a test.
TFResult NTFR(TFR result)
class TFModule m_OnInitModule
Test Framework.
TFResult Or(TFResult other)
bool Assert(bool condition)
void TFResult(TFR result)
TFResult And(TFResult other)
void AddFrameTest(string test)
void AddInitTest(string test)
override void EOnInit(IEntity other, int extra)
TFResult BTFR(bool result)
override void EOnFrame(IEntity other, float timeSlice)
array< ref TFResult > TFResultArr