From 7726f83026035d1e8a3e90fb83fdef6abaa38e31 Mon Sep 17 00:00:00 2001 From: vis2k Date: Thu, 30 Jul 2020 22:48:10 +0200 Subject: [PATCH] convert --- .../Tests/Editor/MessageInheritanceTest.cs | 127 ------------------ .../Editor/MessageInheritanceTest.cs.meta | 11 -- .../Editor/ScriptableObjectWriterTest.cs | 6 +- 3 files changed, 5 insertions(+), 139 deletions(-) delete mode 100644 Assets/Mirror/Tests/Editor/MessageInheritanceTest.cs delete mode 100644 Assets/Mirror/Tests/Editor/MessageInheritanceTest.cs.meta diff --git a/Assets/Mirror/Tests/Editor/MessageInheritanceTest.cs b/Assets/Mirror/Tests/Editor/MessageInheritanceTest.cs deleted file mode 100644 index e62a36ed7..000000000 --- a/Assets/Mirror/Tests/Editor/MessageInheritanceTest.cs +++ /dev/null @@ -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}"); - } - } -} diff --git a/Assets/Mirror/Tests/Editor/MessageInheritanceTest.cs.meta b/Assets/Mirror/Tests/Editor/MessageInheritanceTest.cs.meta deleted file mode 100644 index 4e78acae8..000000000 --- a/Assets/Mirror/Tests/Editor/MessageInheritanceTest.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 808855b645f9843d2b3077ab1304b2b3 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Mirror/Tests/Editor/ScriptableObjectWriterTest.cs b/Assets/Mirror/Tests/Editor/ScriptableObjectWriterTest.cs index cf3c37778..3c1e4b061 100644 --- a/Assets/Mirror/Tests/Editor/ScriptableObjectWriterTest.cs +++ b/Assets/Mirror/Tests/Editor/ScriptableObjectWriterTest.cs @@ -16,9 +16,13 @@ public class ScriptableObjectWriterTest // other types are generated by the weaver - class ScriptableObjectMessage : MessageBase + struct ScriptableObjectMessage : IMessageBase { public MyScriptableObject scriptableObject; + + // Weaver auto generates serialization + public void Deserialize(NetworkReader reader) {} + public void Serialize(NetworkWriter writer) {} } [Test]