Skip to content

Commit

Permalink
tests: Prepare upgrade to NUnit 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Helco committed Feb 11, 2024
1 parent e503ed9 commit 704ecf1
Show file tree
Hide file tree
Showing 38 changed files with 512 additions and 513 deletions.
6 changes: 3 additions & 3 deletions zzio.tests/zzio/MyAssert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public static void Equals(string expected, Stream? stream)
byte[] expectedBytes = Encoding.UTF8.GetBytes(expected);
byte[] actualBytes = new byte[expectedBytes.Length];
Assert.NotNull(stream);
Assert.AreEqual(actualBytes.Length, stream!.Read(actualBytes, 0, actualBytes.Length));
Assert.AreEqual(expectedBytes, actualBytes);
Assert.AreEqual(-1, stream.ReadByte());
Assert.That(stream!.Read(actualBytes, 0, actualBytes.Length), Is.EqualTo(actualBytes.Length));
Assert.That(actualBytes, Is.EqualTo(expectedBytes));
Assert.That(stream.ReadByte(), Is.EqualTo(-1));
stream.Close();
}
}
26 changes: 13 additions & 13 deletions zzio.tests/zzio/TestActorExDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ public class TestActorExDescription
private void testInstance(ActorExDescription aed)
{
Assert.NotNull(aed);
Assert.AreEqual(1337, aed.headBoneID);
Assert.AreEqual("hello.dff", aed.body.model);
Assert.AreEqual("wings.dff", aed.wings.model);

Assert.AreEqual(2, aed.body.animations.Length);
Assert.AreEqual("first.ani", aed.body.animations[0].filename);
Assert.AreEqual(AnimationType.Jump, aed.body.animations[0].type);
Assert.AreEqual("second.ani", aed.body.animations[1].filename);
Assert.AreEqual(AnimationType.Run, aed.body.animations[1].type);

Assert.AreEqual(1, aed.wings.animations.Length);
Assert.AreEqual("third.ani", aed.wings.animations[0].filename);
Assert.AreEqual(AnimationType.RunForwardLeft, aed.wings.animations[0].type);
Assert.That(aed.headBoneID, Is.EqualTo(1337));
Assert.That(aed.body.model, Is.EqualTo("hello.dff"));
Assert.That(aed.wings.model, Is.EqualTo("wings.dff"));

Assert.That(aed.body.animations.Length, Is.EqualTo(2));
Assert.That(aed.body.animations[0].filename, Is.EqualTo("first.ani"));
Assert.That(aed.body.animations[0].type, Is.EqualTo(AnimationType.Jump));
Assert.That(aed.body.animations[1].filename, Is.EqualTo("second.ani"));
Assert.That(aed.body.animations[1].type, Is.EqualTo(AnimationType.Run));

Assert.That(aed.wings.animations.Length, Is.EqualTo(1));
Assert.That(aed.wings.animations[0].filename, Is.EqualTo("third.ani"));
Assert.That(aed.wings.animations[0].type, Is.EqualTo(AnimationType.RunForwardLeft));
}

[Test]
Expand Down
32 changes: 16 additions & 16 deletions zzio.tests/zzio/TestMapMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ public class TestMapMarker
private void testMarkers(MapMarker[] mapMarkers)
{
Assert.NotNull(mapMarkers);
Assert.AreEqual(3, mapMarkers.Length);

Assert.AreEqual(1234, mapMarkers[0].posX);
Assert.AreEqual(5678, mapMarkers[0].posY);
Assert.AreEqual(MapMarkerSection.EnchantedForest, mapMarkers[0].section);
Assert.AreEqual(1337, mapMarkers[0].sceneId);

Assert.AreEqual(9876, mapMarkers[1].posX);
Assert.AreEqual(5432, mapMarkers[1].posY);
Assert.AreEqual(MapMarkerSection.DarkSwamp, mapMarkers[1].section);
Assert.AreEqual(42, mapMarkers[1].sceneId);

Assert.AreEqual(1357, mapMarkers[2].posX);
Assert.AreEqual(2468, mapMarkers[2].posY);
Assert.AreEqual(MapMarkerSection.RealmOfClouds, mapMarkers[2].section);
Assert.AreEqual(1037, mapMarkers[2].sceneId);
Assert.That(mapMarkers.Length, Is.EqualTo(3));

Assert.That(mapMarkers[0].posX, Is.EqualTo(1234));
Assert.That(mapMarkers[0].posY, Is.EqualTo(5678));
Assert.That(mapMarkers[0].section, Is.EqualTo(MapMarkerSection.EnchantedForest));
Assert.That(mapMarkers[0].sceneId, Is.EqualTo(1337));

Assert.That(mapMarkers[1].posX, Is.EqualTo(9876));
Assert.That(mapMarkers[1].posY, Is.EqualTo(5432));
Assert.That(mapMarkers[1].section, Is.EqualTo(MapMarkerSection.DarkSwamp));
Assert.That(mapMarkers[1].sceneId, Is.EqualTo(42));

Assert.That(mapMarkers[2].posX, Is.EqualTo(1357));
Assert.That(mapMarkers[2].posY, Is.EqualTo(2468));
Assert.That(mapMarkers[2].section, Is.EqualTo(MapMarkerSection.RealmOfClouds));
Assert.That(mapMarkers[2].sceneId, Is.EqualTo(1037));
}

[Test]
Expand Down
32 changes: 16 additions & 16 deletions zzio.tests/zzio/TestPAKArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@ public void containsfile()
MemoryStream stream = new(sampleData, false);
PAKArchive archive = PAKArchive.ReadNew(stream);

Assert.True(archive.ContainsFile("A/a.txt"));
Assert.True(archive.ContainsFile("a/B.txt"));
Assert.True(archive.ContainsFile("a/c/d.txt"));
Assert.True(archive.ContainsFile("a/e/f/g.txt"));
Assert.True(archive.ContainsFile("a/A.tXT"));
Assert.True(archive.ContainsFile("a/../a/./\\..\\A\\a.txt"));

Assert.False(archive.ContainsFile("a.txt"));
Assert.False(archive.ContainsFile(".."));
Assert.False(archive.ContainsFile("../A/"));
Assert.False(archive.ContainsFile("../a/Z.txt"));
Assert.That(archive.ContainsFile("A/a.txt"), Is.True);
Assert.That(archive.ContainsFile("a/B.txt"), Is.True);
Assert.That(archive.ContainsFile("a/c/d.txt"), Is.True);
Assert.That(archive.ContainsFile("a/e/f/g.txt"), Is.True);
Assert.That(archive.ContainsFile("a/A.tXT"), Is.True);
Assert.That(archive.ContainsFile("a/../a/./\\..\\A\\a.txt"), Is.True);

Assert.That(archive.ContainsFile("a.txt"), Is.False);
Assert.That(archive.ContainsFile(".."), Is.False);
Assert.That(archive.ContainsFile("../A/"), Is.False);
Assert.That(archive.ContainsFile("../a/Z.txt"), Is.False);
}

private void testStream(Stream stream, string expected)
{
byte[] expectedBuffer = Encoding.UTF8.GetBytes(expected);
byte[] actualBuffer = new byte[expectedBuffer.Length];
Assert.AreEqual(0, stream.Position);
Assert.AreEqual(expectedBuffer.Length, stream.Read(actualBuffer, 0, expectedBuffer.Length));
Assert.AreEqual(-1, stream.ReadByte());
Assert.AreEqual(expectedBuffer, actualBuffer);
Assert.That(stream.Position, Is.EqualTo(0));
Assert.That(stream.Read(actualBuffer, 0, expectedBuffer.Length), Is.EqualTo(expectedBuffer.Length));
Assert.That(stream.ReadByte(), Is.EqualTo(-1));
Assert.That(actualBuffer, Is.EqualTo(expectedBuffer));
stream.Close();
}

Expand All @@ -63,7 +63,7 @@ public void getdirectorycontent()
MemoryStream stream = new(sampleData, false);
PAKArchive archive = PAKArchive.ReadNew(stream);

Assert.AreEqual(Array.Empty<string>(), archive.GetDirectoryContent("G/H/I"));
Assert.That(archive.GetDirectoryContent("G/H/I"), Is.EqualTo(Array.Empty<string>()));

Assert.That(archive.GetDirectoryContent("", true), Is.EquivalentTo(new string[]
{
Expand Down
40 changes: 20 additions & 20 deletions zzio.tests/zzio/TestResettableLazy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,50 @@ public class TestResettableLazy
public void IsEmptyByDefault()
{
var refLazy = new ResettableLazy<string>(() => "");
Assert.IsFalse(refLazy.HasValue);
Assert.That(refLazy.HasValue, Is.False);

var valLazy = new ResettableLazyValue<int>(() => 0);
Assert.IsFalse(valLazy.HasValue);
Assert.That(valLazy.HasValue, Is.False);
}

[Test]
public void IsNotEmptyAfterAccess()
{
var refLazy = new ResettableLazy<string>(() => "");
_ = refLazy.Value;
Assert.IsTrue(refLazy.HasValue);
Assert.That(refLazy.HasValue);

var valLazy = new ResettableLazyValue<int>(() => 0);
_ = valLazy.Value;
Assert.IsTrue(valLazy.HasValue);
Assert.That(valLazy.HasValue);
}

[Test]
public void CanBeInitialized()
{
var refLazy = new ResettableLazy<string>(() => "", "Hello World");
Assert.IsTrue(refLazy.HasValue);
Assert.AreEqual("Hello World", refLazy.Value);
Assert.That(refLazy.HasValue);
Assert.That(refLazy.Value, Is.EqualTo("Hello World"));

var valLazy = new ResettableLazyValue<int>(() => 0, 42);
Assert.IsTrue(valLazy.HasValue);
Assert.AreEqual(valLazy.Value, 42);
Assert.That(valLazy.HasValue);
Assert.That(valLazy.Value, Is.EqualTo(42));
}

[Test]
public void DoesNotCallCreatorEarly()
{
bool didCallRef = false;
var refLazy = new ResettableLazy<string>(() => { didCallRef = true; return ""; });
Assert.IsFalse(didCallRef);
Assert.That(didCallRef, Is.False);
_ = refLazy.Value;
Assert.IsTrue(didCallRef);
Assert.That(didCallRef);

bool didCallVal = false;
var valLazy = new ResettableLazyValue<int>(() => { didCallVal = true; return 0; });
Assert.IsFalse(didCallVal);
Assert.That(didCallVal, Is.False);
_ = valLazy.Value;
Assert.IsTrue(didCallVal);
Assert.That(didCallVal);
}

[Test]
Expand All @@ -62,24 +62,24 @@ public void CallsCreatorOnlyOnce()
_ = refLazy.Value;
_ = refLazy.Value;
_ = refLazy.Value;
Assert.AreEqual(1, callCountRef);
Assert.That(callCountRef, Is.EqualTo(1));

int callCountVal = 0;
var valLazy = new ResettableLazyValue<int>(() => { callCountVal++; return 0; });
_ = valLazy.Value;
_ = valLazy.Value;
_ = valLazy.Value;
Assert.AreEqual(1, callCountVal);
Assert.That(callCountVal, Is.EqualTo(1));
}

[Test]
public void TakesValueFromCreator()
{
var refLazy = new ResettableLazy<string>(() => "Hello World");
Assert.AreEqual("Hello World", refLazy.Value);
Assert.That(refLazy.Value, Is.EqualTo("Hello World"));

var valLazy = new ResettableLazyValue<int>(() => 42);
Assert.AreEqual(42, valLazy.Value);
Assert.That(valLazy.Value, Is.EqualTo(42));
}

[Test]
Expand All @@ -88,12 +88,12 @@ public void CanBeReset()
var refLazy = new ResettableLazy<string>(() => "");
_ = refLazy.Value;
refLazy.Reset();
Assert.IsFalse(refLazy.HasValue);
Assert.That(refLazy.HasValue, Is.False);

var valLazy = new ResettableLazyValue<int>(() => 0);
_ = valLazy.Value;
valLazy.Reset();
Assert.IsFalse(valLazy.HasValue);
Assert.That(valLazy.HasValue, Is.False);
}

[Test]
Expand All @@ -109,7 +109,7 @@ public void UsesCreatorAfterReset()
});
_ = refLazy.Value;
refLazy.Reset();
Assert.AreEqual("Second", refLazy.Value);
Assert.That(refLazy.Value, Is.EqualTo("Second"));

bool didCallVal = false;
var valLazy = new ResettableLazyValue<int>(() =>
Expand All @@ -121,6 +121,6 @@ public void UsesCreatorAfterReset()
});
_ = valLazy.Value;
valLazy.Reset();
Assert.AreEqual(1337, valLazy.Value);
Assert.That(valLazy.Value, Is.EqualTo(1337));
}
}
68 changes: 34 additions & 34 deletions zzio.tests/zzio/TestSkeletalAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,52 +14,52 @@ public class TestSkeletalAnimation

private void testNullKeyFrame(AnimationKeyFrame frame)
{
Assert.AreEqual(0.0f, frame.rot.X, TOLERANCE);
Assert.AreEqual(0.0f, frame.rot.Y, TOLERANCE);
Assert.AreEqual(0.0f, frame.rot.Z, TOLERANCE);
Assert.AreEqual(0.0f, frame.rot.W, TOLERANCE);
Assert.AreEqual(0.0f, frame.pos.X, TOLERANCE);
Assert.AreEqual(0.0f, frame.pos.Y, TOLERANCE);
Assert.AreEqual(0.0f, frame.pos.Z, TOLERANCE);
Assert.That(frame.rot.X, Is.EqualTo(0.0f).Within(TOLERANCE));
Assert.That(frame.rot.Y, Is.EqualTo(0.0f).Within(TOLERANCE));
Assert.That(frame.rot.Z, Is.EqualTo(0.0f).Within(TOLERANCE));
Assert.That(frame.rot.W, Is.EqualTo(0.0f).Within(TOLERANCE));
Assert.That(frame.pos.X, Is.EqualTo(0.0f).Within(TOLERANCE));
Assert.That(frame.pos.Y, Is.EqualTo(0.0f).Within(TOLERANCE));
Assert.That(frame.pos.Z, Is.EqualTo(0.0f).Within(TOLERANCE));
}

private void testAnimation(SkeletalAnimation ani)
{
Assert.NotNull(ani);
Assert.AreEqual(4, ani.flags);
Assert.AreEqual(3.0f, ani.duration, TOLERANCE);
Assert.AreEqual(3, ani.BoneCount);
Assert.AreEqual(3, ani.boneFrames.Length);
Assert.That(ani.flags, Is.EqualTo(4));
Assert.That(ani.duration, Is.EqualTo(3.0f).Within(TOLERANCE));
Assert.That(ani.BoneCount, Is.EqualTo(3));
Assert.That(ani.boneFrames.Length, Is.EqualTo(3));

Assert.AreEqual(3, ani.boneFrames[0].Length);
Assert.AreEqual(1.0f, ani.boneFrames[0][0].rot.X, TOLERANCE);
Assert.AreEqual(2.0f, ani.boneFrames[0][0].rot.Y, TOLERANCE);
Assert.AreEqual(3.0f, ani.boneFrames[0][0].rot.Z, TOLERANCE);
Assert.AreEqual(4.0f, ani.boneFrames[0][0].rot.W, TOLERANCE);
Assert.AreEqual(5.0f, ani.boneFrames[0][0].pos.X, TOLERANCE);
Assert.AreEqual(6.0f, ani.boneFrames[0][0].pos.Y, TOLERANCE);
Assert.AreEqual(7.0f, ani.boneFrames[0][0].pos.Z, TOLERANCE);
Assert.AreEqual(0.0f, ani.boneFrames[0][0].time, TOLERANCE);
Assert.That(ani.boneFrames[0].Length, Is.EqualTo(3));
Assert.That(ani.boneFrames[0][0].rot.X, Is.EqualTo(1.0f).Within(TOLERANCE));
Assert.That(ani.boneFrames[0][0].rot.Y, Is.EqualTo(2.0f).Within(TOLERANCE));
Assert.That(ani.boneFrames[0][0].rot.Z, Is.EqualTo(3.0f).Within(TOLERANCE));
Assert.That(ani.boneFrames[0][0].rot.W, Is.EqualTo(4.0f).Within(TOLERANCE));
Assert.That(ani.boneFrames[0][0].pos.X, Is.EqualTo(5.0f).Within(TOLERANCE));
Assert.That(ani.boneFrames[0][0].pos.Y, Is.EqualTo(6.0f).Within(TOLERANCE));
Assert.That(ani.boneFrames[0][0].pos.Z, Is.EqualTo(7.0f).Within(TOLERANCE));
Assert.That(ani.boneFrames[0][0].time, Is.EqualTo(0.0f).Within(TOLERANCE));
testNullKeyFrame(ani.boneFrames[0][1]);
Assert.AreEqual(1.0f, ani.boneFrames[0][1].time, TOLERANCE);
Assert.That(ani.boneFrames[0][1].time, Is.EqualTo(1.0f).Within(TOLERANCE));
testNullKeyFrame(ani.boneFrames[0][2]);
Assert.AreEqual(2.0f, ani.boneFrames[0][2].time, TOLERANCE);
Assert.That(ani.boneFrames[0][2].time, Is.EqualTo(2.0f).Within(TOLERANCE));

Assert.AreEqual(2, ani.boneFrames[1].Length);
Assert.That(ani.boneFrames[1].Length, Is.EqualTo(2));
testNullKeyFrame(ani.boneFrames[1][0]);
Assert.AreEqual(0.0f, ani.boneFrames[1][0].time, TOLERANCE);
Assert.AreEqual(8.0f, ani.boneFrames[1][1].rot.X, TOLERANCE);
Assert.AreEqual(9.0f, ani.boneFrames[1][1].rot.Y, TOLERANCE);
Assert.AreEqual(10.0f, ani.boneFrames[1][1].rot.Z, TOLERANCE);
Assert.AreEqual(11.0f, ani.boneFrames[1][1].rot.W, TOLERANCE);
Assert.AreEqual(12.0f, ani.boneFrames[1][1].pos.X, TOLERANCE);
Assert.AreEqual(13.0f, ani.boneFrames[1][1].pos.Y, TOLERANCE);
Assert.AreEqual(14.0f, ani.boneFrames[1][1].pos.Z, TOLERANCE);
Assert.AreEqual(1.5, ani.boneFrames[1][1].time);
Assert.That(ani.boneFrames[1][0].time, Is.EqualTo(0.0f).Within(TOLERANCE));
Assert.That(ani.boneFrames[1][1].rot.X, Is.EqualTo(8.0f).Within(TOLERANCE));
Assert.That(ani.boneFrames[1][1].rot.Y, Is.EqualTo(9.0f).Within(TOLERANCE));
Assert.That(ani.boneFrames[1][1].rot.Z, Is.EqualTo(10.0f).Within(TOLERANCE));
Assert.That(ani.boneFrames[1][1].rot.W, Is.EqualTo(11.0f).Within(TOLERANCE));
Assert.That(ani.boneFrames[1][1].pos.X, Is.EqualTo(12.0f).Within(TOLERANCE));
Assert.That(ani.boneFrames[1][1].pos.Y, Is.EqualTo(13.0f).Within(TOLERANCE));
Assert.That(ani.boneFrames[1][1].pos.Z, Is.EqualTo(14.0f).Within(TOLERANCE));
Assert.That(ani.boneFrames[1][1].time, Is.EqualTo(1.5));

Assert.AreEqual(1, ani.boneFrames[2].Length);
Assert.That(ani.boneFrames[2].Length, Is.EqualTo(1));
testNullKeyFrame(ani.boneFrames[2][0]);
Assert.AreEqual(0.0f, ani.boneFrames[2][0].time, TOLERANCE);
Assert.That(ani.boneFrames[2][0].time, Is.EqualTo(0.0f).Within(TOLERANCE));
}

[Test]
Expand Down
32 changes: 16 additions & 16 deletions zzio.tests/zzio/TestVarConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ public class TestVarConfig

private void testConfig(VarConfig cfg)
{
Assert.AreEqual(new byte[] { 0xc0, 0xff, 0xee }, cfg.header);
Assert.AreEqual(1.0f, cfg.firstValue.floatValue, TOLERANCE);
Assert.AreEqual("", cfg.firstValue.stringValue);
Assert.AreEqual(3, cfg.variables.Count);

Assert.True(cfg.variables.ContainsKey("MY_FLOAT_VAR"));
Assert.AreEqual(2.0f, cfg.variables["MY_FLOAT_VAR"].floatValue, TOLERANCE);
Assert.AreEqual("", cfg.variables["MY_FLOAT_VAR"].stringValue);

Assert.True(cfg.variables.ContainsKey("MY_STRING_VAR"));
Assert.AreEqual(0.0f, cfg.variables["MY_STRING_VAR"].floatValue, TOLERANCE);
Assert.AreEqual("Zanzarah", cfg.variables["MY_STRING_VAR"].stringValue);

Assert.True(cfg.variables.ContainsKey("MY_BOTH_VAR"));
Assert.AreEqual(3.0f, cfg.variables["MY_BOTH_VAR"].floatValue);
Assert.AreEqual("Hello", cfg.variables["MY_BOTH_VAR"].stringValue);
Assert.That(cfg.header, Is.EqualTo(new byte[] { 0xc0, 0xff, 0xee }));
Assert.That(cfg.firstValue.floatValue, Is.EqualTo(1.0f).Within(TOLERANCE));
Assert.That(cfg.firstValue.stringValue, Is.EqualTo(""));
Assert.That(cfg.variables.Count, Is.EqualTo(3));

Assert.That(cfg.variables.ContainsKey("MY_FLOAT_VAR"), Is.True);
Assert.That(cfg.variables["MY_FLOAT_VAR"].floatValue, Is.EqualTo(2.0f).Within(TOLERANCE));
Assert.That(cfg.variables["MY_FLOAT_VAR"].stringValue, Is.EqualTo(""));

Assert.That(cfg.variables.ContainsKey("MY_STRING_VAR"), Is.True);
Assert.That(cfg.variables["MY_STRING_VAR"].floatValue, Is.EqualTo(0.0f).Within(TOLERANCE));
Assert.That(cfg.variables["MY_STRING_VAR"].stringValue, Is.EqualTo("Zanzarah"));

Assert.That(cfg.variables.ContainsKey("MY_BOTH_VAR"), Is.True);
Assert.That(cfg.variables["MY_BOTH_VAR"].floatValue, Is.EqualTo(3.0f));
Assert.That(cfg.variables["MY_BOTH_VAR"].stringValue, Is.EqualTo("Hello"));
}

[Test]
Expand Down
Loading

0 comments on commit 704ecf1

Please sign in to comment.