DayZ 1.24
Loading...
Searching...
No Matches
ScriptInvokerTests.c
Go to the documentation of this file.
1class ScriptInvokerTests : TestFramework
2{
5
6 //---------------------------------------------------------------------------
7 // Ctor - Decides the tests to run
8 //---------------------------------------------------------------------------
10 {
12
13 //AddInitTest("TestFirstUnique");
14 //AddInitTest("TestSecondUnique");
15 //AddInitTest("TestInsertRemoveUnique");
16 //AddInitTest("TestInsertUniqueImmediate");
17 //AddInitTest("TestClearRunning");
18 //AddInitTest("TestInvokeRunning");
19 AddInitTest("TestInsertRunning");
20 }
21
22 //---------------------------------------------------------------------------
23 // Dtor
24 //---------------------------------------------------------------------------
26 {
27
28 }
29
30 //---------------------------------------------------------------------------
31 // Tests
32 //---------------------------------------------------------------------------
33 // Test first insert flagged as unique
35 {
37
40 bool insert2 = m_Invoker.Insert(InvokeLog);
42
43 m_Invoker.Invoke("TestFirstUnique");
44 bool count = Assert(m_InvokeCount == 1);
45
47
48 return BTFR(insert1 && !insert2 && count);
49 }
50
51 //---------------------------------------------------------------------------
52 // Test second insert flagged as unique
54 {
56
57 bool insert1 = m_Invoker.Insert(InvokeLog);
61
62 m_Invoker.Invoke("TestSecondUnique");
63 bool count = Assert(m_InvokeCount == 1);
64
66
67 return BTFR(insert1 && !insert2 && count);
68 }
69
70 //---------------------------------------------------------------------------
71 // Test inserting and removing of unique
73 {
75
78 bool remove1 = m_Invoker.Remove(InvokeLog);
80 bool insert2 = m_Invoker.Insert(InvokeLog);
82
83 m_Invoker.Invoke("TestInsertRemoveUnique");
84 bool count = Assert(m_InvokeCount == 1);
85
87
88 return BTFR(insert1 && remove1 && insert2 && count);
89 }
90
91 //---------------------------------------------------------------------------
92 // Test inserting and of unique and immediate
94 {
96
99 bool insert2 = m_Invoker.Insert(InvokeLog, EScriptInvokerInsertFlags.IMMEDIATE);
101
102 m_Invoker.Invoke("TestInsertUniqueImmediate");
103 bool count = Assert(m_InvokeCount == 1);
104
105 InvokeReset();
106
107 return BTFR(insert1 && !insert2 && count);
108 }
109
110 //---------------------------------------------------------------------------
111 // Test clearing while invoking
113 {
114 InvokeReset();
115
116 m_Invoker.Insert(InvokeClear);
117 m_Invoker.Insert(InvokeLog);
118
119 m_Invoker.Invoke("TestClearRunning");
120 bool count = Assert(m_InvokeCount == 1);
121
122 InvokeReset();
123
124 return BTFR(count);
125 }
126
127 //---------------------------------------------------------------------------
128 // Test invoke while invoking (will result in overflow)
130 {
131 InvokeReset();
132
133 m_Invoker.Insert(InvokeInvoke);
134
135 m_Invoker.Invoke("TestInvokeRunning");
136
137 InvokeReset();
138
139 return BTFR(false); // This can never succeed, it will never even reach this point
140 }
141
142 //---------------------------------------------------------------------------
143 // Test insert while invoking
145 {
146 InvokeReset();
147
148 m_Invoker.Insert(InvokeInsert);
149
150 m_Invoker.Invoke("TestInvokeRunning");
152 bool count = Assert(m_InvokeCount == 129);
153
154 InvokeReset();
155
156 return BTFR(count);
157 }
158
159
160 //---------------------------------------------------------------------------
161 // Helpers
162 //---------------------------------------------------------------------------
163 void InvokeLog(string s)
164 {
165 //Debug.TFLog(s, this, "InvokeLog");
167 }
168
170 {
171 m_Invoker.Clear();
172 m_InvokeCount = 0;
173 }
174
175 void InvokeClear(string s)
176 {
177 InvokeLog(s);
178 m_Invoker.Clear();
179 }
180
181 void InvokeInvoke(string s)
182 {
183 InvokeLog(s);
184 m_Invoker.Invoke(s);
185 }
186
187 void InvokeInsert(string s)
188 {
189 InvokeLog(s);
191 }
192}
EScriptInvokerInsertFlags
Definition tools.c:130
bool Assert(bool condition)
void TFResult(TFR result)
void AddInitTest(string test)
TFResult BTFR(bool result)
ScriptInvoker Class provide list of callbacks usage:
Definition tools.c:116
TFResult TestInsertUniqueImmediate()
TFResult TestInsertRemoveUnique()
void InvokeClear(string s)
void InvokeInsert(string s)
ref ScriptInvoker m_Invoker
void InvokeInvoke(string s)
proto void Print(void var)
Prints content of variable to console/log.