The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com). ## [1.4.0] - 2023-04-10 ### Added - Added a way to access the GlobalObjectIdHash via PrefabIdHash for use in the Connection Approval Callback. (#2437) - Added `OnServerStarted` and `OnServerStopped` events that will trigger only on the server (or host player) to notify that the server just started or is no longer active (#2420) - Added `OnClientStarted` and `OnClientStopped` events that will trigger only on the client (or host player) to notify that the client just started or is no longer active (#2420) - Added `NetworkTransform.UseHalfFloatPrecision` property that, when enabled, will use half float values for position, rotation, and scale. This yields a 50% bandwidth savings a the cost of precision. (#2388) - Added `NetworkTransform.UseQuaternionSynchronization` property that, when enabled, will synchronize the entire quaternion. (#2388) - Added `NetworkTransform.UseQuaternionCompression` property that, when enabled, will use a smallest three implementation reducing a full quaternion synchronization update to the size of an unsigned integer. (#2388) - Added `NetworkTransform.SlerpPosition` property that, when enabled along with interpolation being enabled, will interpolate using `Vector3.Slerp`. (#2388) - Added `BufferedLinearInterpolatorVector3` that replaces the float version, is now used by `NetworkTransform`, and provides the ability to enable or disable `Slerp`. (#2388) - Added `HalfVector3` used for scale when half float precision is enabled. (#2388) - Added `HalfVector4` used for rotation when half float precision and quaternion synchronization is enabled. (#2388) - Added `HalfVector3DeltaPosition` used for position when half float precision is enabled. This handles loss in position precision by updating only the delta position as opposed to the full position. (#2388) - Added `NetworkTransform.GetSpaceRelativePosition` and `NetworkTransform.GetSpaceRelativeRotation` helper methods to return the proper values depending upon whether local or world space. (#2388) - Added `NetworkTransform.OnAuthorityPushTransformState` virtual method that is invoked just prior to sending the `NetworkTransformState` to non-authoritative instances. This provides users with the ability to obtain more precise delta values for prediction related calculations. (#2388) - Added `NetworkTransform.OnNetworkTransformStateUpdated` virtual method that is invoked just after the authoritative `NetworkTransformState` is applied. This provides users with the ability to obtain more precise delta values for prediction related calculations. (#2388) - Added `NetworkTransform.OnInitialize`virtual method that is invoked after the `NetworkTransform` has been initialized or re-initialized when ownership changes. This provides for a way to make adjustments when `NetworkTransform` is initialized (i.e. resetting client prediction etc) (#2388) - Added `NetworkObject.SynchronizeTransform` property (default is true) that provides users with another way to help with bandwidth optimizations where, when set to false, the `NetworkObject`'s associated transform will not be included when spawning and/or synchronizing late joining players. (#2388) - Added `NetworkSceneManager.ActiveSceneSynchronizationEnabled` property, disabled by default, that enables client synchronization of server-side active scene changes. (#2383) - Added `NetworkObject.ActiveSceneSynchronization`, disabled by default, that will automatically migrate a `NetworkObject` to a newly assigned active scene. (#2383) - Added `NetworkObject.SceneMigrationSynchronization`, enabled by default, that will synchronize client(s) when a `NetworkObject` is migrated into a new scene on the server side via `SceneManager.MoveGameObjectToScene`. (#2383) ### Changed - Made sure the `CheckObjectVisibility` delegate is checked and applied, upon `NetworkShow` attempt. Found while supporting (#2454), although this is not a fix for this (already fixed) issue. (#2463) - Changed `NetworkTransform` authority handles delta checks on each new network tick and no longer consumes processing cycles checking for deltas for all frames in-between ticks. (#2388) - Changed the `NetworkTransformState` structure is now public and now has public methods that provide access to key properties of the `NetworkTransformState` structure. (#2388) - Changed `NetworkTransform` interpolation adjusts its interpolation "ticks ago" to be 2 ticks latent if it is owner authoritative and the instance is not the server or 1 tick latent if the instance is the server and/or is server authoritative. (#2388) - Updated `NetworkSceneManager` to migrate dynamically spawned `NetworkObject`s with `DestroyWithScene` set to false into the active scene if their current scene is unloaded. (#2383) - Updated the server to synchronize its local `NetworkSceneManager.ClientSynchronizationMode` during the initial client synchronization. (#2383) ### Fixed - Fixed issue where during client synchronization the synchronizing client could receive a ObjectSceneChanged message before the client-side NetworkObject instance had been instantiated and spawned. (#2502) - Fixed issue where `NetworkAnimator` was building client RPC parameters to exclude the host from sending itself messages but was not including it in the ClientRpc parameters. (#2492) - Fixed issue where `NetworkAnimator` was not properly detecting and synchronizing cross fade initiated transitions. (#2481) - Fixed issue where `NetworkAnimator` was not properly synchronizing animation state updates. (#2481) - Fixed float NetworkVariables not being rendered properly in the inspector of NetworkObjects. (#2441) - Fixed an issue where Named Message Handlers could remove themselves causing an exception when the metrics tried to access the name of the message.(#2426) - Fixed registry of public `NetworkVariable`s in derived `NetworkBehaviour`s (#2423) - Fixed issue where runtime association of `Animator` properties to `AnimationCurve`s would cause `NetworkAnimator` to attempt to update those changes. (#2416) - Fixed issue where `NetworkAnimator` would not check if its associated `Animator` was valid during serialization and would spam exceptions in the editor console. (#2416) - Fixed issue with a child's rotation rolling over when interpolation is enabled on a `NetworkTransform`. Now using half precision or full quaternion synchronization will always update all axis. (#2388) - Fixed issue where `NetworkTransform` was not setting the teleport flag when the `NetworkTransform.InLocalSpace` value changed. This issue only impacted `NetworkTransform` when interpolation was enabled. (#2388) - Fixed issue when the `NetworkSceneManager.ClientSynchronizationMode` is `LoadSceneMode.Additive` and the server changes the currently active scene prior to a client connecting then upon a client connecting and being synchronized the NetworkSceneManager would clear its internal ScenePlacedObjects list that could already be populated. (#2383) - Fixed issue where a client would load duplicate scenes of already preloaded scenes during the initial client synchronization and `NetworkSceneManager.ClientSynchronizationMode` was set to `LoadSceneMode.Additive`. (#2383)
504 lines
19 KiB
C#
504 lines
19 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using NUnit.Framework;
|
|
using NUnit.Framework.Internal;
|
|
|
|
namespace Unity.Netcode.EditorTests
|
|
{
|
|
public class MessageVersioningTests
|
|
{
|
|
public static int SentVersion;
|
|
public static int ReceivedVersion;
|
|
|
|
private const int k_DefaultB = 5;
|
|
private const int k_DefaultC = 10;
|
|
private const int k_DefaultD = 15;
|
|
private const long k_DefaultE = 20;
|
|
|
|
private struct VersionedTestMessage_v0 : INetworkMessage, INetworkSerializeByMemcpy
|
|
{
|
|
public int A;
|
|
public int B;
|
|
public int C;
|
|
public static bool Serialized;
|
|
public static bool Deserialized;
|
|
public static bool Handled;
|
|
public static List<VersionedTestMessage_v0> DeserializedValues = new List<VersionedTestMessage_v0>();
|
|
|
|
public void Serialize(FastBufferWriter writer, int targetVersion)
|
|
{
|
|
SentVersion = Version;
|
|
Serialized = true;
|
|
writer.WriteValueSafe(A);
|
|
writer.WriteValueSafe(B);
|
|
writer.WriteValueSafe(C);
|
|
}
|
|
|
|
public bool Deserialize(FastBufferReader reader, ref NetworkContext context, int receivedMessageVersion)
|
|
{
|
|
ReceivedVersion = Version;
|
|
Deserialized = true;
|
|
reader.ReadValueSafe(out A);
|
|
reader.ReadValueSafe(out B);
|
|
reader.ReadValueSafe(out C);
|
|
return true;
|
|
}
|
|
|
|
public void Handle(ref NetworkContext context)
|
|
{
|
|
Handled = true;
|
|
DeserializedValues.Add(this);
|
|
}
|
|
|
|
public int Version => 0;
|
|
}
|
|
|
|
private struct VersionedTestMessage_v1 : INetworkMessage, INetworkSerializeByMemcpy
|
|
{
|
|
public int A;
|
|
public int B;
|
|
public int C;
|
|
public int D;
|
|
public static bool Serialized;
|
|
public static bool Deserialized;
|
|
public static bool Downgraded;
|
|
public static bool Upgraded;
|
|
public static bool Handled;
|
|
public static List<VersionedTestMessage_v1> DeserializedValues = new List<VersionedTestMessage_v1>();
|
|
|
|
public void Serialize(FastBufferWriter writer, int targetVersion)
|
|
{
|
|
if (targetVersion < Version)
|
|
{
|
|
Downgraded = true;
|
|
var v0 = new VersionedTestMessage_v0 { A = A, B = B, C = C };
|
|
v0.Serialize(writer, targetVersion);
|
|
return;
|
|
}
|
|
SentVersion = Version;
|
|
Serialized = true;
|
|
writer.WriteValueSafe(C);
|
|
writer.WriteValueSafe(D);
|
|
writer.WriteValueSafe(A);
|
|
writer.WriteValueSafe(B);
|
|
}
|
|
|
|
public bool Deserialize(FastBufferReader reader, ref NetworkContext context, int receivedMessageVersion)
|
|
{
|
|
if (receivedMessageVersion < Version)
|
|
{
|
|
var v0 = new VersionedTestMessage_v0();
|
|
v0.Deserialize(reader, ref context, receivedMessageVersion);
|
|
A = v0.A;
|
|
B = v0.B;
|
|
C = v0.C;
|
|
D = k_DefaultD;
|
|
Upgraded = true;
|
|
return true;
|
|
}
|
|
ReceivedVersion = Version;
|
|
Deserialized = true;
|
|
reader.ReadValueSafe(out C);
|
|
reader.ReadValueSafe(out D);
|
|
reader.ReadValueSafe(out A);
|
|
reader.ReadValueSafe(out B);
|
|
return true;
|
|
}
|
|
|
|
public void Handle(ref NetworkContext context)
|
|
{
|
|
Handled = true;
|
|
DeserializedValues.Add(this);
|
|
}
|
|
|
|
public int Version => 1;
|
|
}
|
|
|
|
private struct VersionedTestMessage : INetworkMessage, INetworkSerializeByMemcpy
|
|
{
|
|
public int A;
|
|
public float D;
|
|
public long E;
|
|
public static bool Serialized;
|
|
public static bool Deserialized;
|
|
public static bool Downgraded;
|
|
public static bool Upgraded;
|
|
public static bool Handled;
|
|
public static List<VersionedTestMessage> DeserializedValues = new List<VersionedTestMessage>();
|
|
|
|
public void Serialize(FastBufferWriter writer, int targetVersion)
|
|
{
|
|
if (targetVersion < Version)
|
|
{
|
|
Downgraded = true;
|
|
var v1 = new VersionedTestMessage_v1 { A = A, B = k_DefaultB, C = k_DefaultC, D = (int)D };
|
|
v1.Serialize(writer, targetVersion);
|
|
return;
|
|
}
|
|
SentVersion = Version;
|
|
Serialized = true;
|
|
writer.WriteValueSafe(D);
|
|
writer.WriteValueSafe(A);
|
|
writer.WriteValueSafe(E);
|
|
}
|
|
|
|
public bool Deserialize(FastBufferReader reader, ref NetworkContext context, int receivedMessageVersion)
|
|
{
|
|
if (receivedMessageVersion < Version)
|
|
{
|
|
var v1 = new VersionedTestMessage_v1();
|
|
v1.Deserialize(reader, ref context, receivedMessageVersion);
|
|
A = v1.A;
|
|
D = v1.D;
|
|
E = k_DefaultE;
|
|
Upgraded = true;
|
|
return true;
|
|
}
|
|
ReceivedVersion = Version;
|
|
Deserialized = true;
|
|
reader.ReadValueSafe(out D);
|
|
reader.ReadValueSafe(out A);
|
|
reader.ReadValueSafe(out E);
|
|
return true;
|
|
}
|
|
|
|
public void Handle(ref NetworkContext context)
|
|
{
|
|
Handled = true;
|
|
DeserializedValues.Add(this);
|
|
}
|
|
|
|
public int Version => 2;
|
|
}
|
|
|
|
private class TestMessageProvider_v0 : IMessageProvider
|
|
{
|
|
public List<MessagingSystem.MessageWithHandler> GetMessages()
|
|
{
|
|
return new List<MessagingSystem.MessageWithHandler>
|
|
{
|
|
new MessagingSystem.MessageWithHandler
|
|
{
|
|
MessageType = typeof(VersionedTestMessage_v0),
|
|
Handler = MessagingSystem.ReceiveMessage<VersionedTestMessage_v0>,
|
|
GetVersion = MessagingSystem.CreateMessageAndGetVersion<VersionedTestMessage_v0>
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
private class TestMessageProvider_v1 : IMessageProvider
|
|
{
|
|
public List<MessagingSystem.MessageWithHandler> GetMessages()
|
|
{
|
|
return new List<MessagingSystem.MessageWithHandler>
|
|
{
|
|
new MessagingSystem.MessageWithHandler
|
|
{
|
|
MessageType = typeof(VersionedTestMessage_v1),
|
|
Handler = MessagingSystem.ReceiveMessage<VersionedTestMessage_v1>,
|
|
GetVersion = MessagingSystem.CreateMessageAndGetVersion<VersionedTestMessage_v1>
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
private class TestMessageProvider_v2 : IMessageProvider
|
|
{
|
|
public List<MessagingSystem.MessageWithHandler> GetMessages()
|
|
{
|
|
return new List<MessagingSystem.MessageWithHandler>
|
|
{
|
|
new MessagingSystem.MessageWithHandler
|
|
{
|
|
MessageType = typeof(VersionedTestMessage),
|
|
Handler = MessagingSystem.ReceiveMessage<VersionedTestMessage>,
|
|
GetVersion = MessagingSystem.CreateMessageAndGetVersion<VersionedTestMessage>
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
private class TestMessageSender : IMessageSender
|
|
{
|
|
public List<byte[]> MessageQueue = new List<byte[]>();
|
|
|
|
public void Send(ulong clientId, NetworkDelivery delivery, FastBufferWriter batchData)
|
|
{
|
|
MessageQueue.Add(batchData.ToArray());
|
|
}
|
|
}
|
|
|
|
private MessagingSystem m_MessagingSystem_v0;
|
|
private MessagingSystem m_MessagingSystem_v1;
|
|
private MessagingSystem m_MessagingSystem_v2;
|
|
private TestMessageSender m_MessageSender;
|
|
|
|
private void CreateFakeClients(MessagingSystem system, uint hash)
|
|
{
|
|
// Create three fake clients for each messaging system
|
|
// client 0 has version 0, client 1 has version 1, and client 2 has version 2
|
|
system.ClientConnected(0);
|
|
system.ClientConnected(1);
|
|
system.ClientConnected(2);
|
|
system.SetVersion(0, hash, 0);
|
|
system.SetVersion(1, hash, 1);
|
|
system.SetVersion(2, hash, 2);
|
|
}
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
VersionedTestMessage_v0.Serialized = false;
|
|
VersionedTestMessage_v0.Deserialized = false;
|
|
VersionedTestMessage_v0.Handled = false;
|
|
VersionedTestMessage_v0.DeserializedValues.Clear();
|
|
VersionedTestMessage_v1.Serialized = false;
|
|
VersionedTestMessage_v1.Deserialized = false;
|
|
VersionedTestMessage_v1.Downgraded = false;
|
|
VersionedTestMessage_v1.Upgraded = false;
|
|
VersionedTestMessage_v1.Handled = false;
|
|
VersionedTestMessage_v1.DeserializedValues.Clear();
|
|
VersionedTestMessage.Serialized = false;
|
|
VersionedTestMessage.Deserialized = false;
|
|
VersionedTestMessage.Downgraded = false;
|
|
VersionedTestMessage.Upgraded = false;
|
|
VersionedTestMessage.Handled = false;
|
|
VersionedTestMessage.DeserializedValues.Clear();
|
|
m_MessageSender = new TestMessageSender();
|
|
|
|
m_MessagingSystem_v0 = new MessagingSystem(m_MessageSender, this, new TestMessageProvider_v0());
|
|
m_MessagingSystem_v1 = new MessagingSystem(m_MessageSender, this, new TestMessageProvider_v1());
|
|
m_MessagingSystem_v2 = new MessagingSystem(m_MessageSender, this, new TestMessageProvider_v2());
|
|
|
|
CreateFakeClients(m_MessagingSystem_v0, XXHash.Hash32(typeof(VersionedTestMessage_v0).FullName));
|
|
CreateFakeClients(m_MessagingSystem_v1, XXHash.Hash32(typeof(VersionedTestMessage_v1).FullName));
|
|
CreateFakeClients(m_MessagingSystem_v2, XXHash.Hash32(typeof(VersionedTestMessage).FullName));
|
|
|
|
// Make sure that all three messages got the same IDs...
|
|
Assert.AreEqual(
|
|
m_MessagingSystem_v0.GetMessageType(typeof(VersionedTestMessage_v0)),
|
|
m_MessagingSystem_v1.GetMessageType(typeof(VersionedTestMessage_v1)));
|
|
Assert.AreEqual(
|
|
m_MessagingSystem_v0.GetMessageType(typeof(VersionedTestMessage_v0)),
|
|
m_MessagingSystem_v2.GetMessageType(typeof(VersionedTestMessage)));
|
|
}
|
|
|
|
[TearDown]
|
|
public void TearDown()
|
|
{
|
|
m_MessagingSystem_v0.Dispose();
|
|
m_MessagingSystem_v1.Dispose();
|
|
m_MessagingSystem_v2.Dispose();
|
|
}
|
|
|
|
private VersionedTestMessage_v0 GetMessage_v0()
|
|
{
|
|
var random = new Random();
|
|
return new VersionedTestMessage_v0
|
|
{
|
|
A = random.Next(),
|
|
B = random.Next(),
|
|
C = random.Next(),
|
|
};
|
|
}
|
|
|
|
private VersionedTestMessage_v1 GetMessage_v1()
|
|
{
|
|
var random = new Random();
|
|
return new VersionedTestMessage_v1
|
|
{
|
|
A = random.Next(),
|
|
B = random.Next(),
|
|
C = random.Next(),
|
|
D = random.Next(),
|
|
};
|
|
}
|
|
|
|
private VersionedTestMessage GetMessage_v2()
|
|
{
|
|
var random = new Random();
|
|
return new VersionedTestMessage
|
|
{
|
|
A = random.Next(),
|
|
D = (float)(random.NextDouble() * 10000),
|
|
E = ((long)random.Next() << 32) + random.Next()
|
|
};
|
|
}
|
|
|
|
public void CheckPostSendExpectations(int sourceLocalVersion, int remoteVersion)
|
|
{
|
|
Assert.AreEqual(Math.Min(sourceLocalVersion, remoteVersion) == 0, VersionedTestMessage_v0.Serialized);
|
|
Assert.AreEqual(Math.Min(sourceLocalVersion, remoteVersion) == 1, VersionedTestMessage_v1.Serialized);
|
|
Assert.AreEqual(Math.Min(sourceLocalVersion, remoteVersion) == 2, VersionedTestMessage.Serialized);
|
|
Assert.AreEqual(sourceLocalVersion >= 1 && remoteVersion < 1, VersionedTestMessage_v1.Downgraded);
|
|
Assert.AreEqual(sourceLocalVersion >= 2 && remoteVersion < 2, VersionedTestMessage.Downgraded);
|
|
|
|
Assert.AreEqual(1, m_MessageSender.MessageQueue.Count);
|
|
Assert.AreEqual(Math.Min(sourceLocalVersion, remoteVersion), SentVersion);
|
|
}
|
|
|
|
public void CheckPostReceiveExpectations(int sourceLocalVersion, int remoteVersion)
|
|
{
|
|
Assert.AreEqual(SentVersion == 0, VersionedTestMessage_v0.Deserialized);
|
|
Assert.AreEqual(SentVersion == 1, VersionedTestMessage_v1.Deserialized);
|
|
Assert.AreEqual(SentVersion == 2, VersionedTestMessage.Deserialized);
|
|
Assert.AreEqual(remoteVersion >= 1 && sourceLocalVersion < 1, VersionedTestMessage_v1.Upgraded);
|
|
Assert.AreEqual(remoteVersion >= 2 && sourceLocalVersion < 2, VersionedTestMessage.Upgraded);
|
|
|
|
Assert.AreEqual((remoteVersion == 0 ? 1 : 0), VersionedTestMessage_v0.DeserializedValues.Count);
|
|
Assert.AreEqual((remoteVersion == 1 ? 1 : 0), VersionedTestMessage_v1.DeserializedValues.Count);
|
|
Assert.AreEqual((remoteVersion == 2 ? 1 : 0), VersionedTestMessage.DeserializedValues.Count);
|
|
|
|
Assert.AreEqual(SentVersion, ReceivedVersion);
|
|
}
|
|
|
|
private void SendMessageWithVersions<T>(T message, int fromVersion, int toVersion) where T : unmanaged, INetworkMessage
|
|
{
|
|
MessagingSystem sendSystem;
|
|
switch (fromVersion)
|
|
{
|
|
case 0: sendSystem = m_MessagingSystem_v0; break;
|
|
case 1: sendSystem = m_MessagingSystem_v1; break;
|
|
default: sendSystem = m_MessagingSystem_v2; break;
|
|
}
|
|
sendSystem.SendMessage(ref message, NetworkDelivery.Reliable, (ulong)toVersion);
|
|
sendSystem.ProcessSendQueues();
|
|
CheckPostSendExpectations(fromVersion, toVersion);
|
|
|
|
MessagingSystem receiveSystem;
|
|
switch (toVersion)
|
|
{
|
|
case 0: receiveSystem = m_MessagingSystem_v0; break;
|
|
case 1: receiveSystem = m_MessagingSystem_v1; break;
|
|
default: receiveSystem = m_MessagingSystem_v2; break;
|
|
}
|
|
receiveSystem.HandleIncomingData((ulong)fromVersion, new ArraySegment<byte>(m_MessageSender.MessageQueue[0]), 0.0f);
|
|
receiveSystem.ProcessIncomingMessageQueue();
|
|
CheckPostReceiveExpectations(fromVersion, toVersion);
|
|
|
|
m_MessageSender.MessageQueue.Clear();
|
|
}
|
|
|
|
[Test]
|
|
public void WhenSendingV0ToV0_DataIsReceivedCorrectly()
|
|
{
|
|
var message = GetMessage_v0();
|
|
|
|
SendMessageWithVersions(message, 0, 0);
|
|
|
|
var receivedMessage = VersionedTestMessage_v0.DeserializedValues[0];
|
|
Assert.AreEqual(message.A, receivedMessage.A);
|
|
Assert.AreEqual(message.B, receivedMessage.B);
|
|
Assert.AreEqual(message.C, receivedMessage.C);
|
|
}
|
|
|
|
[Test]
|
|
public void WhenSendingV0ToV1_DataIsReceivedCorrectly()
|
|
{
|
|
var message = GetMessage_v0();
|
|
|
|
SendMessageWithVersions(message, 0, 1);
|
|
|
|
var receivedMessage = VersionedTestMessage_v1.DeserializedValues[0];
|
|
Assert.AreEqual(message.A, receivedMessage.A);
|
|
Assert.AreEqual(message.B, receivedMessage.B);
|
|
Assert.AreEqual(message.C, receivedMessage.C);
|
|
Assert.AreEqual(k_DefaultD, receivedMessage.D);
|
|
}
|
|
|
|
[Test]
|
|
public void WhenSendingV0ToV2_DataIsReceivedCorrectly()
|
|
{
|
|
var message = GetMessage_v0();
|
|
|
|
SendMessageWithVersions(message, 0, 2);
|
|
|
|
var receivedMessage = VersionedTestMessage.DeserializedValues[0];
|
|
Assert.AreEqual(message.A, receivedMessage.A);
|
|
Assert.AreEqual((float)k_DefaultD, receivedMessage.D);
|
|
Assert.AreEqual(k_DefaultE, receivedMessage.E);
|
|
}
|
|
|
|
[Test]
|
|
public void WhenSendingV1ToV0_DataIsReceivedCorrectly()
|
|
{
|
|
var message = GetMessage_v1();
|
|
|
|
SendMessageWithVersions(message, 1, 0);
|
|
|
|
var receivedMessage = VersionedTestMessage_v0.DeserializedValues[0];
|
|
Assert.AreEqual(message.A, receivedMessage.A);
|
|
Assert.AreEqual(message.B, receivedMessage.B);
|
|
Assert.AreEqual(message.C, receivedMessage.C);
|
|
}
|
|
|
|
[Test]
|
|
public void WhenSendingV1ToV1_DataIsReceivedCorrectly()
|
|
{
|
|
var message = GetMessage_v1();
|
|
|
|
SendMessageWithVersions(message, 1, 1);
|
|
|
|
var receivedMessage = VersionedTestMessage_v1.DeserializedValues[0];
|
|
Assert.AreEqual(message.A, receivedMessage.A);
|
|
Assert.AreEqual(message.B, receivedMessage.B);
|
|
Assert.AreEqual(message.C, receivedMessage.C);
|
|
Assert.AreEqual(message.D, receivedMessage.D);
|
|
}
|
|
|
|
[Test]
|
|
public void WhenSendingV1ToV2_DataIsReceivedCorrectly()
|
|
{
|
|
var message = GetMessage_v1();
|
|
|
|
SendMessageWithVersions(message, 1, 2);
|
|
|
|
var receivedMessage = VersionedTestMessage.DeserializedValues[0];
|
|
Assert.AreEqual(message.A, receivedMessage.A);
|
|
Assert.AreEqual((float)message.D, receivedMessage.D);
|
|
Assert.AreEqual(k_DefaultE, receivedMessage.E);
|
|
}
|
|
|
|
[Test]
|
|
public void WhenSendingV2ToV0_DataIsReceivedCorrectly()
|
|
{
|
|
var message = GetMessage_v2();
|
|
|
|
SendMessageWithVersions(message, 2, 0);
|
|
|
|
var receivedMessage = VersionedTestMessage_v0.DeserializedValues[0];
|
|
Assert.AreEqual(message.A, receivedMessage.A);
|
|
Assert.AreEqual(k_DefaultB, receivedMessage.B);
|
|
Assert.AreEqual(k_DefaultC, receivedMessage.C);
|
|
}
|
|
|
|
[Test]
|
|
public void WhenSendingV2ToV1_DataIsReceivedCorrectly()
|
|
{
|
|
var message = GetMessage_v2();
|
|
|
|
SendMessageWithVersions(message, 2, 1);
|
|
|
|
var receivedMessage = VersionedTestMessage_v1.DeserializedValues[0];
|
|
Assert.AreEqual(message.A, receivedMessage.A);
|
|
Assert.AreEqual(k_DefaultB, receivedMessage.B);
|
|
Assert.AreEqual(k_DefaultC, receivedMessage.C);
|
|
Assert.AreEqual((int)message.D, receivedMessage.D);
|
|
}
|
|
|
|
[Test]
|
|
public void WhenSendingV2ToV2_DataIsReceivedCorrectly()
|
|
{
|
|
var message = GetMessage_v2();
|
|
|
|
SendMessageWithVersions(message, 2, 2);
|
|
|
|
var receivedMessage = VersionedTestMessage.DeserializedValues[0];
|
|
Assert.AreEqual(message.A, receivedMessage.A);
|
|
Assert.AreEqual(message.D, receivedMessage.D);
|
|
Assert.AreEqual(message.E, receivedMessage.E);
|
|
}
|
|
}
|
|
}
|