-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathConfigParserTest.cs
More file actions
234 lines (208 loc) · 9.91 KB
/
ConfigParserTest.cs
File metadata and controls
234 lines (208 loc) · 9.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RLBot.Flat;
using RLBotCS.ManagerTools;
namespace RLBotCSTests;
[TestClass]
public class ConfigParserTest
{
/// <summary>
/// Fails if the action does not throw an exception which is of type T
/// possibly wrapped in zero or more <see cref="ConfigParser.ConfigParserException"/>s.
/// </summary>
public static void AssertThrowsInnerException<T>(Action action)
where T : Exception
{
try
{
action();
}
catch (Exception e)
{
while (e.GetType() == typeof(ConfigParser.ConfigParserException))
{
if (e.InnerException == null)
{
Assert.Fail();
}
e = e.InnerException!;
}
Assert.IsInstanceOfType<T>(e);
return;
}
Assert.Fail();
}
[TestMethod]
public void EmptyVsDefaultMatchConfig()
{
ConfigParser parser = new();
MatchConfigurationT defaultMC = parser.LoadMatchConfig("TestTomls/default.toml");
MatchConfigurationT emptyMC = parser.LoadMatchConfig("TestTomls/empty.toml");
Assert.AreEqual(emptyMC.Launcher, defaultMC.Launcher);
Assert.AreEqual(emptyMC.LauncherArg, defaultMC.LauncherArg);
Assert.AreEqual(emptyMC.AutoStartAgents, defaultMC.AutoStartAgents);
Assert.AreEqual(emptyMC.WaitForAgents, defaultMC.WaitForAgents);
Assert.AreEqual(emptyMC.GameMapUpk, defaultMC.GameMapUpk);
Assert.HasCount(emptyMC.PlayerConfigurations.Count, defaultMC.PlayerConfigurations);
Assert.HasCount(emptyMC.ScriptConfigurations.Count, defaultMC.ScriptConfigurations);
Assert.AreEqual(emptyMC.GameMode, defaultMC.GameMode);
Assert.AreEqual(emptyMC.SkipReplays, defaultMC.SkipReplays);
Assert.AreEqual(emptyMC.InstantStart, defaultMC.InstantStart);
Assert.AreEqual(emptyMC.ExistingMatchBehavior, defaultMC.ExistingMatchBehavior);
Assert.AreEqual(emptyMC.EnableRendering, defaultMC.EnableRendering);
Assert.AreEqual(emptyMC.EnableStateSetting, defaultMC.EnableStateSetting);
Assert.AreEqual(emptyMC.AutoSaveReplay, defaultMC.AutoSaveReplay);
Assert.AreEqual(emptyMC.Freeplay, defaultMC.Freeplay);
MutatorSettingsT defaultMutS = defaultMC.Mutators;
MutatorSettingsT emptyMutS = emptyMC.Mutators;
Assert.AreEqual(emptyMutS.MatchLength, defaultMutS.MatchLength);
Assert.AreEqual(emptyMutS.MaxScore, defaultMutS.MaxScore);
Assert.AreEqual(emptyMutS.MultiBall, defaultMutS.MultiBall);
Assert.AreEqual(emptyMutS.Overtime, defaultMutS.Overtime);
Assert.AreEqual(emptyMutS.SeriesLength, defaultMutS.SeriesLength);
Assert.AreEqual(emptyMutS.GameSpeed, defaultMutS.GameSpeed);
Assert.AreEqual(emptyMutS.BallMaxSpeed, defaultMutS.BallMaxSpeed);
Assert.AreEqual(emptyMutS.BallType, defaultMutS.BallType);
Assert.AreEqual(emptyMutS.BallWeight, defaultMutS.BallWeight);
Assert.AreEqual(emptyMutS.BallSize, defaultMutS.BallSize);
Assert.AreEqual(emptyMutS.BallBounciness, defaultMutS.BallBounciness);
Assert.AreEqual(emptyMutS.BoostAmount, defaultMutS.BoostAmount);
Assert.AreEqual(emptyMutS.Rumble, defaultMutS.Rumble);
Assert.AreEqual(emptyMutS.BoostStrength, defaultMutS.BoostStrength);
Assert.AreEqual(emptyMutS.Gravity, defaultMutS.Gravity);
Assert.AreEqual(emptyMutS.Demolish, defaultMutS.Demolish);
Assert.AreEqual(emptyMutS.RespawnTime, defaultMutS.RespawnTime);
}
[TestMethod]
public void EdgeCases()
{
ConfigParser parser = new();
MatchConfigurationT edgeMC = parser.LoadMatchConfig("TestTomls/edge.toml");
Assert.AreEqual(DebugRendering.AlwaysOff, edgeMC.EnableRendering);
Assert.AreEqual(Launcher.Custom, edgeMC.Launcher);
// Ok for parsing, but wil not go through ConfigValidator
Assert.AreEqual("something invalid", edgeMC.LauncherArg);
Assert.AreEqual(MatchLengthMutator.TenMinutes, edgeMC.Mutators.MatchLength);
Assert.AreEqual(GravityMutator.Reverse, edgeMC.Mutators.Gravity);
Assert.AreEqual(PlayerClass.PsyonixBot, edgeMC.PlayerConfigurations[0].Variety.Type);
Assert.AreEqual("Boomer", edgeMC.PlayerConfigurations[0].Variety.AsPsyonixBot().Name);
Assert.AreEqual(
PsyonixSkill.Pro,
edgeMC.PlayerConfigurations[0].Variety.AsPsyonixBot().BotSkill
);
Assert.IsNull(edgeMC.PlayerConfigurations[0].Variety.AsPsyonixBot().Loadout);
Assert.AreEqual(PlayerClass.CustomBot, edgeMC.PlayerConfigurations[1].Variety.Type);
Assert.AreEqual(
"Edgy Test Bot",
edgeMC.PlayerConfigurations[1].Variety.AsCustomBot().Name
);
Assert.AreEqual("", edgeMC.PlayerConfigurations[1].Variety.AsCustomBot().AgentId);
Assert.AreEqual(0u, edgeMC.PlayerConfigurations[1].Team);
Assert.AreEqual(
"Edgy Test Bot",
edgeMC.PlayerConfigurations[2].Variety.AsCustomBot().Name
);
Assert.AreEqual(1u, edgeMC.PlayerConfigurations[2].Team);
PlayerLoadoutT loadoutP2 = edgeMC
.PlayerConfigurations[2]
.Variety.AsCustomBot()
.Loadout;
Assert.AreEqual(69u, loadoutP2.TeamColorId);
Assert.AreEqual(0u, loadoutP2.CustomColorId);
Assert.AreEqual(23u, loadoutP2.CarId);
Assert.AreEqual(6083u, loadoutP2.DecalId);
Assert.AreEqual(1580u, loadoutP2.WheelsId);
Assert.AreEqual(35u, loadoutP2.BoostId);
Assert.AreEqual(0u, loadoutP2.AntennaId);
Assert.AreEqual(0u, loadoutP2.HatId);
Assert.AreEqual(1681u, loadoutP2.PaintFinishId);
Assert.AreEqual(1681u, loadoutP2.CustomFinishId);
Assert.AreEqual(5635u, loadoutP2.EngineAudioId);
Assert.AreEqual(3220u, loadoutP2.TrailsId);
Assert.AreEqual(4118u, loadoutP2.GoalExplosionId);
Assert.AreEqual(12u, loadoutP2.LoadoutPaint.CarPaintId);
Assert.AreEqual(12u, loadoutP2.LoadoutPaint.DecalPaintId);
Assert.AreEqual(12u, loadoutP2.LoadoutPaint.WheelsPaintId);
Assert.AreEqual(12u, loadoutP2.LoadoutPaint.BoostPaintId);
Assert.AreEqual(0u, loadoutP2.LoadoutPaint.AntennaPaintId);
Assert.AreEqual(0u, loadoutP2.LoadoutPaint.HatPaintId);
Assert.AreEqual(12u, loadoutP2.LoadoutPaint.TrailsPaintId);
Assert.AreEqual(12u, loadoutP2.LoadoutPaint.GoalExplosionPaintId);
// Set to "" due to `auto_start=false`
Assert.AreEqual("", edgeMC.PlayerConfigurations[3].Variety.AsCustomBot().RunCommand);
Assert.AreEqual("", edgeMC.ScriptConfigurations[0].RunCommand);
}
[TestMethod]
public void EmptyVsDefaultBotAndScriptToml()
{
ConfigParser parser = new();
MatchConfigurationT mc = parser.LoadMatchConfig("TestTomls/empty_agents.toml");
PlayerConfigurationT player = mc.PlayerConfigurations[0];
Assert.AreEqual(PlayerClass.CustomBot, player.Variety.Type);
Assert.AreEqual("", player.Variety.AsCustomBot().Name);
Assert.AreEqual("", player.Variety.AsCustomBot().AgentId);
Assert.AreEqual(0u, player.Team);
Assert.AreEqual(Path.GetFullPath("TestTomls"), player.Variety.AsCustomBot().RootDir);
Assert.AreEqual("", player.Variety.AsCustomBot().RunCommand);
Assert.IsNull(player.Variety.AsCustomBot().Loadout);
Assert.IsFalse(player.Variety.AsCustomBot().Hivemind);
ScriptConfigurationT script = mc.ScriptConfigurations[0];
Assert.AreEqual("", script.Name);
Assert.AreEqual("", script.AgentId);
Assert.AreEqual(Path.GetFullPath("TestTomls"), script.RootDir);
Assert.AreEqual("", script.RunCommand);
}
[TestMethod]
public void Overrides()
{
ConfigParser parser = new();
MatchConfigurationT mc = parser.LoadMatchConfig("TestTomls/overrides.toml");
PlayerConfigurationT player = mc.PlayerConfigurations[0];
Assert.AreEqual("New Bot Name", player.Variety.AsCustomBot().Name);
Assert.IsNull(player.Variety.AsCustomBot().Loadout);
ScriptConfigurationT script = mc.ScriptConfigurations[0];
Assert.AreEqual("Normal Test Script", script.Name); // Not overriden
}
[TestMethod]
public void ConfigNotFound()
{
ConfigParser parser = new();
AssertThrowsInnerException<ArgumentNullException>(() => parser.LoadMatchConfig(null!));
AssertThrowsInnerException<FileNotFoundException>(() =>
parser.LoadMatchConfig("TestTomls/non-existent.toml")
);
// Match toml exists, but refers to bot that does not exist
Assert.IsTrue(Path.Exists("TestTomls/non-existent_bot.toml"));
AssertThrowsInnerException<FileNotFoundException>(() =>
parser.LoadMatchConfig("TestTomls/non-existent_bot.toml")
);
// Match toml exists, but refers to script that does not exist
Assert.IsTrue(Path.Exists("TestTomls/non-existent_script.toml"));
AssertThrowsInnerException<FileNotFoundException>(() =>
parser.LoadMatchConfig("TestTomls/non-existent_script.toml")
);
}
[TestMethod]
public void InvalidTomlConfig()
{
ConfigParser parser = new();
AssertThrowsInnerException<Tomlyn.TomlException>(() =>
parser.LoadMatchConfig("TestTomls/not_a_toml.json")
);
}
[TestMethod]
public void BadValues()
{
ConfigParser parser = new();
AssertThrowsInnerException<InvalidCastException>(() =>
parser.LoadMatchConfig("TestTomls/bad_boolean.toml")
);
AssertThrowsInnerException<InvalidCastException>(() =>
parser.LoadMatchConfig("TestTomls/bad_enum.toml")
);
AssertThrowsInnerException<InvalidCastException>(() =>
parser.LoadMatchConfig("TestTomls/bad_team.toml")
);
}
}