From d4f834ac08258528ba1de059686f7f8809da1f84 Mon Sep 17 00:00:00 2001 From: James Frowen Date: Thu, 23 Apr 2020 20:51:33 +0100 Subject: [PATCH] test for sync list using interface (#1767) --- .../Editor/Weaver/WeaverSyncListTests.cs | 17 ++++++++++ .../SyncListErrorForInterface.cs | 15 +++++++++ .../SyncListInterfaceWithCustomMethods.cs | 32 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncListTests~/SyncListErrorForInterface.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncListTests~/SyncListInterfaceWithCustomMethods.cs diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncListTests.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncListTests.cs index 0bd6a5fac..8fb3fc7eb 100644 --- a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncListTests.cs +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncListTests.cs @@ -158,6 +158,23 @@ public void SyncListGenericStructWithCustomMethods() Assert.That(weaverErrors, Is.Empty); } + [Test] + public void SyncListErrorForInterface() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.True); + string weaverError = @"Mirror\.Weaver error:"; + string type = @"MirrorTest\.MyInterfaceList"; + string errorMessage = @"cannot have item of type MirrorTest\.MyInterface\. Use a type supported by mirror instead"; + Assert.That(weaverErrors, Has.Some.Match($"{weaverError} {type} {errorMessage}")); + } + + [Test] + public void SyncListInterfaceWithCustomMethods() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.False); + Assert.That(weaverErrors, Is.Empty); + } + [Test] public void SyncListErrorWhenUsingGenericListInNetworkBehaviour() { diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncListTests~/SyncListErrorForInterface.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncListTests~/SyncListErrorForInterface.cs new file mode 100644 index 000000000..0f511a5d0 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncListTests~/SyncListErrorForInterface.cs @@ -0,0 +1,15 @@ +using UnityEngine; +using Mirror; + +namespace MirrorTest +{ + class SyncListErrorForInterface : NetworkBehaviour + { + MyInterfaceList Foo; + } + interface MyInterface + { + int someNumber { get; set; } + } + class MyInterfaceList : SyncList { } +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncListTests~/SyncListInterfaceWithCustomMethods.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncListTests~/SyncListInterfaceWithCustomMethods.cs new file mode 100644 index 000000000..df5cff025 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncListTests~/SyncListInterfaceWithCustomMethods.cs @@ -0,0 +1,32 @@ +using UnityEngine; +using Mirror; + +namespace MirrorTest +{ + class SyncListInterfaceWithCustomMethods : NetworkBehaviour + { + MyInterfaceList Foo; + } + + interface IMyInterface + { + int someNumber { get; set; } + } + + class MyUser : IMyInterface + { + public int someNumber { get; set; } + } + + class MyInterfaceList : SyncList + { + protected override void SerializeItem(NetworkWriter writer, IMyInterface item) + { + writer.WriteInt32(item.someNumber); + } + protected override IMyInterface DeserializeItem(NetworkReader reader) + { + return new MyUser { someNumber = reader.ReadInt32() }; + } + } +}