mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
MessagePackerTest: cover FormatException case
This commit is contained in:
parent
17af872f99
commit
5736dd8d05
@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
namespace Mirror.Tests
|
namespace Mirror.Tests
|
||||||
{
|
{
|
||||||
@ -20,5 +21,35 @@ public void TestPacking()
|
|||||||
Assert.That(unpacked.sceneName, Is.EqualTo("Hello world"));
|
Assert.That(unpacked.sceneName, Is.EqualTo("Hello world"));
|
||||||
Assert.That(unpacked.sceneOperation, Is.EqualTo(SceneOperation.LoadAdditive));
|
Assert.That(unpacked.sceneOperation, Is.EqualTo(SceneOperation.LoadAdditive));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestUnpackIdMismatch()
|
||||||
|
{
|
||||||
|
// Unpack<T> has a id != msgType case that throws a FormatException.
|
||||||
|
// let's try to trigger it.
|
||||||
|
|
||||||
|
SceneMessage message = new SceneMessage()
|
||||||
|
{
|
||||||
|
sceneName = "Hello world",
|
||||||
|
sceneOperation = SceneOperation.LoadAdditive
|
||||||
|
};
|
||||||
|
|
||||||
|
byte[] data = MessagePacker.Pack(message);
|
||||||
|
|
||||||
|
// overwrite the id
|
||||||
|
data[0] = 0x01;
|
||||||
|
data[1] = 0x02;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SceneMessage unpacked = MessagePacker.Unpack<SceneMessage>(data);
|
||||||
|
// BAD: IF WE GET HERE THEN NO EXCEPTION WAS THROWN
|
||||||
|
Assert.Fail();
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
// GOOD
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user