Dayz
Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Toggle main menu visibility
Loading...
Searching...
No Matches
scriptinvokertests.c
Go to the documentation of this file.
1
class
ScriptInvokerTests
:
TestFramework
2
{
3
ref
ScriptInvoker
m_Invoker
;
4
int
m_InvokeCount
;
5
6
//---------------------------------------------------------------------------
7
// Ctor - Decides the tests to run
8
//---------------------------------------------------------------------------
9
void
ScriptInvokerTests
()
10
{
11
m_Invoker
=
new
ScriptInvoker
();
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
//---------------------------------------------------------------------------
25
void
~ScriptInvokerTests
()
26
{
27
28
}
29
30
//---------------------------------------------------------------------------
31
// Tests
32
//---------------------------------------------------------------------------
33
// Test first insert flagged as unique
34
TFResult
TestFirstUnique
()
35
{
36
InvokeReset
();
37
38
bool
insert1 =
m_Invoker
.Insert(
InvokeLog
,
EScriptInvokerInsertFlags
.UNIQUE);
39
Assert
(insert1);
40
bool
insert2 =
m_Invoker
.Insert(
InvokeLog
);
41
Assert
(!insert2);
42
43
m_Invoker
.Invoke(
"TestFirstUnique"
);
44
bool
count =
Assert
(
m_InvokeCount
== 1);
45
46
InvokeReset
();
47
48
return
BTFR
(insert1 && !insert2 && count);
49
}
50
51
//---------------------------------------------------------------------------
52
// Test second insert flagged as unique
53
TFResult
TestSecondUnique
()
54
{
55
InvokeReset
();
56
57
bool
insert1 =
m_Invoker
.Insert(
InvokeLog
);
58
Assert
(insert1);
59
bool
insert2 =
m_Invoker
.Insert(
InvokeLog
,
EScriptInvokerInsertFlags
.UNIQUE);
60
Assert
(!insert2);
61
62
m_Invoker
.Invoke(
"TestSecondUnique"
);
63
bool
count =
Assert
(
m_InvokeCount
== 1);
64
65
InvokeReset
();
66
67
return
BTFR
(insert1 && !insert2 && count);
68
}
69
70
//---------------------------------------------------------------------------
71
// Test inserting and removing of unique
72
TFResult
TestInsertRemoveUnique
()
73
{
74
InvokeReset
();
75
76
bool
insert1 =
m_Invoker
.Insert(
InvokeLog
,
EScriptInvokerInsertFlags
.UNIQUE);
77
Assert
(insert1);
78
bool
remove1 =
m_Invoker
.Remove(
InvokeLog
);
79
Assert
(remove1);
80
bool
insert2 =
m_Invoker
.Insert(
InvokeLog
);
81
Assert
(insert2);
82
83
m_Invoker
.Invoke(
"TestInsertRemoveUnique"
);
84
bool
count =
Assert
(
m_InvokeCount
== 1);
85
86
InvokeReset
();
87
88
return
BTFR
(insert1 && remove1 && insert2 && count);
89
}
90
91
//---------------------------------------------------------------------------
92
// Test inserting and of unique and immediate
93
TFResult
TestInsertUniqueImmediate
()
94
{
95
InvokeReset
();
96
97
bool
insert1 =
m_Invoker
.Insert(
InvokeLog
,
EScriptInvokerInsertFlags
.UNIQUE);
98
Assert
(insert1);
99
bool
insert2 =
m_Invoker
.Insert(
InvokeLog
,
EScriptInvokerInsertFlags
.IMMEDIATE);
100
Assert
(insert2);
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
112
TFResult
TestClearRunning
()
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)
129
TFResult
TestInvokeRunning
()
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
144
TFResult
TestInsertRunning
()
145
{
146
InvokeReset
();
147
148
m_Invoker
.Insert(
InvokeInsert
);
149
150
m_Invoker
.Invoke(
"TestInvokeRunning"
);
151
Print
(
m_InvokeCount
);
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");
166
++
m_InvokeCount
;
167
}
168
169
void
InvokeReset
()
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);
190
m_Invoker
.Insert(
InvokeInsert
,
EScriptInvokerInsertFlags
.IMMEDIATE);
191
}
192
}
EScriptInvokerInsertFlags
EScriptInvokerInsertFlags
Definition
tools.c:130
ScriptInvoker
ScriptInvoker Class provide list of callbacks usage:
Definition
tools.c:116
ScriptInvokerTests::TestInsertRunning
TFResult TestInsertRunning()
Definition
scriptinvokertests.c:144
ScriptInvokerTests::InvokeClear
void InvokeClear(string s)
Definition
scriptinvokertests.c:175
ScriptInvokerTests::TestInvokeRunning
TFResult TestInvokeRunning()
Definition
scriptinvokertests.c:129
ScriptInvokerTests::InvokeInvoke
void InvokeInvoke(string s)
Definition
scriptinvokertests.c:181
ScriptInvokerTests::TestSecondUnique
TFResult TestSecondUnique()
Definition
scriptinvokertests.c:53
ScriptInvokerTests::TestClearRunning
TFResult TestClearRunning()
Definition
scriptinvokertests.c:112
ScriptInvokerTests::InvokeLog
void InvokeLog(string s)
Definition
scriptinvokertests.c:163
ScriptInvokerTests::m_Invoker
ref ScriptInvoker m_Invoker
Definition
scriptinvokertests.c:3
ScriptInvokerTests::~ScriptInvokerTests
void ~ScriptInvokerTests()
Definition
scriptinvokertests.c:25
ScriptInvokerTests::TestFirstUnique
TFResult TestFirstUnique()
Definition
scriptinvokertests.c:34
ScriptInvokerTests::InvokeReset
void InvokeReset()
Definition
scriptinvokertests.c:169
ScriptInvokerTests::ScriptInvokerTests
void ScriptInvokerTests()
Definition
scriptinvokertests.c:9
ScriptInvokerTests::InvokeInsert
void InvokeInsert(string s)
Definition
scriptinvokertests.c:187
ScriptInvokerTests::TestInsertRemoveUnique
TFResult TestInsertRemoveUnique()
Definition
scriptinvokertests.c:72
ScriptInvokerTests::TestInsertUniqueImmediate
TFResult TestInsertUniqueImmediate()
Definition
scriptinvokertests.c:93
ScriptInvokerTests::m_InvokeCount
int m_InvokeCount
Definition
scriptinvokertests.c:4
Print
proto void Print(void var)
Prints content of variable to console/log.
TestFramework
void TestFramework()
Definition
testframework.c:217
Assert
bool Assert(bool condition)
Definition
testframework.c:262
TFResult
void TFResult(TFR result)
Definition
testframework.c:12
AddInitTest
void AddInitTest(string test)
Definition
testframework.c:249
BTFR
TFResult BTFR(bool result)
Definition
testframework.c:278
Games
Dayz
scripts
3_game
systems
tftests
scriptinvokertests.c
Generated by
1.17.0