Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
pmtcreationandcleanup.c
Go to the documentation of this file.
2 {
3  // Simply exists
4 }
5 
7 {
9  bool m_bTestEventsPassed = false;
10 
12 
13  //---------------------------------------------------------------------------
14  // Ctor - Decides the tests to run
15  //---------------------------------------------------------------------------
17  {
18  //AddInitTest("TestInvalidSize");
19  AddInitTest("TestCCSB");
20  AddInitTest("TestEvents");
21  AddInitTest("TestOwnership");
22  }
23 
24  //---------------------------------------------------------------------------
25  // Tests
26  //---------------------------------------------------------------------------
27  // Test invalid size VMEs
29  {
30  Debug.ParticleLog("Expecting VME: Invalid size. (0)", this, "TestInvalidSize");
31  TestCreationSmallBlocking(0, false);
32 
33  Debug.ParticleLog("Expecting VME: Invalid size. (-3)", this, "TestInvalidSize");
34  TestCreationSmallBlocking(-3, false);
35 
36  return NTFR(TFR.SUCCESS); // No way to check if a VME popped or not...
37  }
38 
39  //---------------------------------------------------------------------------
40  // TestCreationCleanupSmallBlocking
42  {
43  return TestCleanup("TestMultiCreation", 3000);
44  }
45 
46  //---------------------------------------------------------------------------
47  // Test if events are called properly
49  {
51  bool success = !pm.IsFinishedAllocating(); // We need it to not be done in the same frame
52  if (Assert(success))
53  {
54  pm.GetEvents().Event_OnAllocationEnd.Insert(PassCheckEvents);
55 
56  m_EventTestManagerID = InsertManager(pm);
57  AddFrameTest("CheckTestEvents");
58 
59  return NTFR(TFR.SUCCESS);
60  }
61 
62  return NTFR(TFR.FAIL);
63  }
64 
65  //---------------------------------------------------------------------------
66  // Test ownership
68  {
69  ParticleManager pm = CreatePMFixedBlocking(1);
70  bool success = pm.IsFinishedAllocating(); // We need it to be done in the same frame
71  if (Assert(success))
72  {
73  m_OwnershipTestManagerID = InsertManager(pm);
75 
76  ParticleProperties pp = new ParticleProperties(GetGame().GetPlayer().GetPosition(), ParticlePropertiesFlags.NONE, null, vector.Zero, dummy);
77  string particlePath = ParticleList.GetParticleFullPath(ParticleList.EXPLOSION_LANDMINE);
78 
79  bool result = Assert(pm.CreateParticleByPath(particlePath, pp) != null);
80  Debug.ParticleLog("Expecting VME: All particles in pool are already used.", this, "TestOwnership");
81  result &= Assert(pm.CreateParticleByPath(particlePath, pp) == null);
82  delete dummy;
83  result &= Assert(pm.CreateParticleByPath(particlePath, pp) != null);
84 
85  return BTFR(result);
86  }
87 
88  return NTFR(TFR.FAIL);
89  }
90 
91  //---------------------------------------------------------------------------
92  // OnFrame Checks
93  //---------------------------------------------------------------------------
95  {
96  ParticleManager pm;
97  if (GetManager(m_EventTestManagerID, pm))
98  {
99  if (pm)
100  {
101  if (pm.IsFinishedAllocating())
102  {
104  }
105  }
106  else
107  {
108  return BTFR(Assert(false));
109  }
110  }
111  else
112  {
113  return BTFR(Assert(false));
114  }
115 
116  return NTFR(TFR.PENDING);
117  }
118 
119  //---------------------------------------------------------------------------
120  // Passes
121  //---------------------------------------------------------------------------
123  {
124  Assert(pm.IsFinishedAllocating());
125  m_bTestEventsPassed = true;
126  }
127 
128  //---------------------------------------------------------------------------
129  // Helpers
130  //---------------------------------------------------------------------------
131  TFResult TestCreationSmallBlocking(int size, bool enableAsserts = true)
132  {
133  // Blocking, so that we can test AllocatedCount
134  ParticleManager pm = CreatePMFixedBlocking(size);
135  PrintPMStats(pm);
136 
137  bool success = true;
138 
139  if (enableAsserts)
140  {
141  success &= Assert(pm.GetPoolSize() == size);
142  success &= Assert(pm.GetAllocatedCount() == size);
143  success &= Assert(pm.GetEvents() != null);
144  }
145 
146  return BTFR(success);
147  }
148 
149  TFResult TestCleanup(string f, int p1 = 0)
150  {
151  int pmTotal = ParticleManager.GetStaticActiveCount();
152  int psTotal = ParticleSource.GetStaticActiveCount();
153 
154  PrintActiveStats();
155 
156  TFResult res = CTFR();
157 
158  GetGame().GameScript.CallFunction(this, f, res, p1);
159 
160  int pmTotalPost = ParticleManager.GetStaticActiveCount();
161  int psTotalPost = ParticleSource.GetStaticActiveCount();
162 
163  PrintActiveStats();
164 
165  bool success = Assert(pmTotal == pmTotalPost);
166  success &= Assert(psTotal == psTotalPost);
167 
168  return res.And(BTFR(success));
169  }
170 
172  {
173  TFResult res = CTFR();
174  for (int i = 0; i < instances; ++i)
175  {
176  res.And(TestCreationSmallBlocking(1));
177  }
178  return res;
179  }
180 }
GetGame
proto native CGame GetGame()
m_OwnershipTestManagerID
int m_OwnershipTestManagerID
Definition: pmtcreationandcleanup.c:11
TestEvents
TFResult TestEvents()
Definition: pmtcreationandcleanup.c:48
NTFR
TFResult NTFR(TFR result)
Definition: testframework.c:273
TestMultiCreation
TFResult TestMultiCreation(int instances)
Definition: pmtcreationandcleanup.c:171
m_EventTestManagerID
class OwnershipTestDummyClass m_EventTestManagerID
PMTCreationAndCleanup
void PMTCreationAndCleanup()
Definition: pmtcreationandcleanup.c:16
OwnershipTestDummyClass
Definition: pmtcreationandcleanup.c:1
TestOwnership
TFResult TestOwnership()
Definition: pmtcreationandcleanup.c:67
PMTF
Definition: pmtf.c:1
TFResult
void TFResult(TFR result)
Definition: testframework.c:12
m_bTestEventsPassed
bool m_bTestEventsPassed
Definition: pmtcreationandcleanup.c:9
TestCleanup
TFResult TestCleanup(string f, int p1=0)
Definition: pmtcreationandcleanup.c:149
AddFrameTest
protected void AddFrameTest(string test)
Definition: testframework.c:254
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
ParticleList
Definition: particlelist.c:11
vector
Definition: enconvert.c:105
CheckTestEvents
TFResult CheckTestEvents()
Definition: pmtcreationandcleanup.c:94
PassCheckEvents
void PassCheckEvents(ParticleManager pm)
Definition: pmtcreationandcleanup.c:122
ParticleManagerSettings
class ParticleManagerConstants ParticleManagerSettings(int poolSize, int flags=ParticleManagerSettingsFlags.NONE)
Settings given to ParticleManager on creation (in ctor)
Definition: particlemanager.c:35
TestCCSB
TFResult TestCCSB()
Definition: pmtcreationandcleanup.c:41
TestCreationSmallBlocking
TFResult TestCreationSmallBlocking(int size, bool enableAsserts=true)
Definition: pmtcreationandcleanup.c:131
TestInvalidSize
TFResult TestInvalidSize()
Definition: pmtcreationandcleanup.c:28
Assert
protected bool Assert(bool condition)
Definition: testframework.c:262
CTFR
TFResult CTFR()
Definition: testframework.c:286
ParticleSource
Entity which has the particle instance as an ObjectComponent.
Definition: particlesource.c:123
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
AddInitTest
protected void AddInitTest(string test)
Definition: testframework.c:249
Debug
Definition: debug.c:13
TFR
TFR
Definition: testframework.c:1
BTFR
TFResult BTFR(bool result)
Definition: testframework.c:278
ParticleManager
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
Definition: particlemanager.c:84