mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
convert
This commit is contained in:
parent
b7fa3b3f29
commit
7726f83026
@ -1,127 +0,0 @@
|
|||||||
using NUnit.Framework;
|
|
||||||
|
|
||||||
namespace Mirror.Tests.MessageInheritance
|
|
||||||
{
|
|
||||||
class ParentMessage : MessageBase
|
|
||||||
{
|
|
||||||
public int parentValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
class ChildMessage : ParentMessage
|
|
||||||
{
|
|
||||||
public int childValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public abstract class RequestMessageBase : MessageBase
|
|
||||||
{
|
|
||||||
public int responseId = 0;
|
|
||||||
}
|
|
||||||
public class ResponseMessage : RequestMessageBase
|
|
||||||
{
|
|
||||||
public int state;
|
|
||||||
public string message = "";
|
|
||||||
public int errorCode = 0; // optional for error codes
|
|
||||||
}
|
|
||||||
|
|
||||||
//reverseOrder to test this https://github.com/vis2k/Mirror/issues/1925
|
|
||||||
public class ResponseMessageReverse : RequestMessageBaseReverse
|
|
||||||
{
|
|
||||||
public int state;
|
|
||||||
public string message = "";
|
|
||||||
public int errorCode = 0; // optional for error codes
|
|
||||||
}
|
|
||||||
public abstract class RequestMessageBaseReverse : MessageBase
|
|
||||||
{
|
|
||||||
public int responseId = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
[TestFixture]
|
|
||||||
public class MessageInheritanceTest
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void SendsVauesInParentAndChildClass()
|
|
||||||
{
|
|
||||||
NetworkWriter writer = new NetworkWriter();
|
|
||||||
|
|
||||||
writer.WriteMessage(new ChildMessage
|
|
||||||
{
|
|
||||||
parentValue = 3,
|
|
||||||
childValue = 4
|
|
||||||
});
|
|
||||||
|
|
||||||
byte[] arr = writer.ToArray();
|
|
||||||
|
|
||||||
NetworkReader reader = new NetworkReader(arr);
|
|
||||||
ChildMessage received = new ChildMessage();
|
|
||||||
received.Deserialize(reader);
|
|
||||||
|
|
||||||
Assert.AreEqual(3, received.parentValue);
|
|
||||||
Assert.AreEqual(4, received.childValue);
|
|
||||||
|
|
||||||
int writeLength = writer.Length;
|
|
||||||
int readLength = reader.Position;
|
|
||||||
Assert.That(writeLength == readLength, $"OnSerializeAll and OnDeserializeAll calls write the same amount of data\n writeLength={writeLength}\n readLength={readLength}");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void SendsVauesWhenUsingAbstractClass()
|
|
||||||
{
|
|
||||||
NetworkWriter writer = new NetworkWriter();
|
|
||||||
|
|
||||||
const int state = 2;
|
|
||||||
const string message = "hello world";
|
|
||||||
const int responseId = 5;
|
|
||||||
writer.WriteMessage(new ResponseMessage
|
|
||||||
{
|
|
||||||
state = state,
|
|
||||||
message = message,
|
|
||||||
responseId = responseId,
|
|
||||||
});
|
|
||||||
|
|
||||||
byte[] arr = writer.ToArray();
|
|
||||||
|
|
||||||
NetworkReader reader = new NetworkReader(arr);
|
|
||||||
ResponseMessage received = new ResponseMessage();
|
|
||||||
received.Deserialize(reader);
|
|
||||||
|
|
||||||
Assert.AreEqual(state, received.state);
|
|
||||||
Assert.AreEqual(message, received.message);
|
|
||||||
Assert.AreEqual(responseId, received.responseId);
|
|
||||||
|
|
||||||
int writeLength = writer.Length;
|
|
||||||
int readLength = reader.Position;
|
|
||||||
Assert.That(writeLength == readLength, $"OnSerializeAll and OnDeserializeAll calls write the same amount of data\n writeLength={writeLength}\n readLength={readLength}");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void SendsVauesWhenUsingAbstractClassReverseDefineOrder()
|
|
||||||
{
|
|
||||||
NetworkWriter writer = new NetworkWriter();
|
|
||||||
|
|
||||||
const int state = 2;
|
|
||||||
const string message = "hello world";
|
|
||||||
const int responseId = 5;
|
|
||||||
writer.WriteMessage(new ResponseMessageReverse
|
|
||||||
{
|
|
||||||
state = state,
|
|
||||||
message = message,
|
|
||||||
responseId = responseId,
|
|
||||||
});
|
|
||||||
|
|
||||||
byte[] arr = writer.ToArray();
|
|
||||||
|
|
||||||
NetworkReader reader = new NetworkReader(arr);
|
|
||||||
ResponseMessageReverse received = new ResponseMessageReverse();
|
|
||||||
received.Deserialize(reader);
|
|
||||||
|
|
||||||
Assert.AreEqual(state, received.state);
|
|
||||||
Assert.AreEqual(message, received.message);
|
|
||||||
Assert.AreEqual(responseId, received.responseId);
|
|
||||||
|
|
||||||
int writeLength = writer.Length;
|
|
||||||
int readLength = reader.Position;
|
|
||||||
Assert.That(writeLength == readLength, $"OnSerializeAll and OnDeserializeAll calls write the same amount of data\n writeLength={writeLength}\n readLength={readLength}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 808855b645f9843d2b3077ab1304b2b3
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -16,9 +16,13 @@ public class ScriptableObjectWriterTest
|
|||||||
// other types are generated by the weaver
|
// other types are generated by the weaver
|
||||||
|
|
||||||
|
|
||||||
class ScriptableObjectMessage : MessageBase
|
struct ScriptableObjectMessage : IMessageBase
|
||||||
{
|
{
|
||||||
public MyScriptableObject scriptableObject;
|
public MyScriptableObject scriptableObject;
|
||||||
|
|
||||||
|
// Weaver auto generates serialization
|
||||||
|
public void Deserialize(NetworkReader reader) {}
|
||||||
|
public void Serialize(NetworkWriter writer) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
Loading…
Reference in New Issue
Block a user