From 1614c68629d274c17b6074339ba0697cb6d1123d Mon Sep 17 00:00:00 2001 From: James Frowen Date: Wed, 22 Apr 2020 17:54:09 +0100 Subject: [PATCH] Tests for sync dictionary and sync set (#1753) * sync dictionary tests * rename * changing error message * sync set tests --- .../Weaver/Processors/SyncVarProcessor.cs | 2 +- .../Weaver/WeaverSyncDictionaryTests.cs | 177 ++++++++++++++++++ .../Weaver/WeaverSyncDictionaryTests.cs.meta | 11 ++ .../SyncDictionary.cs | 12 ++ ...SyncDictionaryErrorForGenericStructItem.cs | 16 ++ ...ericStructItemWithCustomDeserializeOnly.cs | 22 +++ ...enericStructItemWithCustomSerializeOnly.cs | 22 +++ .../SyncDictionaryErrorForGenericStructKey.cs | 16 ++ ...nericStructKeyWithCustomDeserializeOnly.cs | 22 +++ ...GenericStructKeyWithCustomSerializeOnly.cs | 22 +++ ...ErrorWhenUsingGenericInNetworkBehaviour.cs | 11 ++ ...yncDictionaryGenericAbstractInheritance.cs | 13 ++ .../SyncDictionaryGenericInheritance.cs | 13 ++ ...onaryGenericStructItemWithCustomMethods.cs | 27 +++ ...ionaryGenericStructKeyWithCustomMethods.cs | 27 +++ .../SyncDictionaryInheritance.cs | 19 ++ .../SyncDictionaryStructItem.cs | 17 ++ ...naryStructItemWithCustomDeserializeOnly.cs | 23 +++ ...ncDictionaryStructItemWithCustomMethods.cs | 28 +++ ...ionaryStructItemWithCustomSerializeOnly.cs | 23 +++ .../SyncDictionaryStructKey.cs | 17 ++ ...onaryStructKeyWithCustomDeserializeOnly.cs | 23 +++ ...yncDictionaryStructKeyWithCustomMethods.cs | 28 +++ ...tionaryStructKeyWithCustomSerializeOnly.cs | 23 +++ .../Editor/Weaver/WeaverSyncListTests.cs | 4 +- .../Weaver/WeaverSyncListTests~/SyncList.cs | 2 +- .../Tests/Editor/Weaver/WeaverSyncSetTests.cs | 50 +++++ .../Editor/Weaver/WeaverSyncSetTests.cs.meta | 11 ++ .../Weaver/WeaverSyncSetTests~/SyncSet.cs | 10 + .../WeaverSyncSetTests~/SyncSetByteValid.cs | 12 ++ .../SyncSetGenericAbstractInheritance.cs | 13 ++ .../SyncSetGenericInheritance.cs | 13 ++ .../WeaverSyncSetTests~/SyncSetInheritance.cs | 14 ++ .../WeaverSyncSetTests~/SyncSetStruct.cs | 17 ++ 34 files changed, 756 insertions(+), 4 deletions(-) create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests.cs.meta create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionary.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructItem.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructItemWithCustomDeserializeOnly.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructItemWithCustomSerializeOnly.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructKey.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructKeyWithCustomDeserializeOnly.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructKeyWithCustomSerializeOnly.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorWhenUsingGenericInNetworkBehaviour.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryGenericAbstractInheritance.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryGenericInheritance.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryGenericStructItemWithCustomMethods.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryGenericStructKeyWithCustomMethods.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryInheritance.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructItem.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructItemWithCustomDeserializeOnly.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructItemWithCustomMethods.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructItemWithCustomSerializeOnly.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructKey.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructKeyWithCustomDeserializeOnly.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructKeyWithCustomMethods.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructKeyWithCustomSerializeOnly.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests.cs.meta create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSet.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSetByteValid.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSetGenericAbstractInheritance.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSetGenericInheritance.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSetInheritance.cs create mode 100644 Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSetStruct.cs diff --git a/Assets/Mirror/Editor/Weaver/Processors/SyncVarProcessor.cs b/Assets/Mirror/Editor/Weaver/Processors/SyncVarProcessor.cs index 20ef0e7d1..cd5a5ed67 100644 --- a/Assets/Mirror/Editor/Weaver/Processors/SyncVarProcessor.cs +++ b/Assets/Mirror/Editor/Weaver/Processors/SyncVarProcessor.cs @@ -346,7 +346,7 @@ public static void ProcessSyncVars(TypeDefinition td, List sync if (fd.FieldType.Resolve().HasGenericParameters) { - Weaver.Error($"{fd} Can not use generic SyncObjects directly in NetworkBehaviour. Create a class and inherit from the generic syncList instead."); + Weaver.Error($"{fd} Can not use generic SyncObjects directly in NetworkBehaviour. Create a class and inherit from the generic SyncObject instead."); return; } diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests.cs new file mode 100644 index 000000000..687311961 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests.cs @@ -0,0 +1,177 @@ +using NUnit.Framework; + +namespace Mirror.Weaver.Tests +{ + // Some tests for SyncObjects are in WeaverSyncListTests and apply to SyncDictionary too + public class WeaverSyncDictionaryTests : WeaverTestsBuildFromTestName + { + [Test] + public void SyncDictionary() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.False); + Assert.That(weaverErrors, Is.Empty); + } + + [Test] + public void SyncDictionaryGenericAbstractInheritance() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.False); + Assert.That(weaverErrors, Is.Empty); + } + + [Test] + public void SyncDictionaryGenericInheritance() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.False); + Assert.That(weaverErrors, Is.Empty); + } + + [Test] + public void SyncDictionaryInheritance() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.False); + Assert.That(weaverErrors, Is.Empty); + } + + [Test] + public void SyncDictionaryStructKey() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.False); + Assert.That(weaverErrors, Is.Empty); + } + + [Test] + public void SyncDictionaryStructItem() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.False); + Assert.That(weaverErrors, Is.Empty); + } + + [Test] + public void SyncDictionaryStructKeyWithCustomDeserializeOnly() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.False); + Assert.That(weaverErrors, Is.Empty); + } + + [Test] + public void SyncDictionaryStructItemWithCustomDeserializeOnly() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.False); + Assert.That(weaverErrors, Is.Empty); + } + + [Test] + public void SyncDictionaryStructKeyWithCustomMethods() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.False); + Assert.That(weaverErrors, Is.Empty); + } + + [Test] + public void SyncDictionaryStructItemWithCustomMethods() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.False); + Assert.That(weaverErrors, Is.Empty); + } + + [Test] + public void SyncDictionaryStructKeyWithCustomSerializeOnly() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.False); + Assert.That(weaverErrors, Is.Empty); + } + + + [Test] + public void SyncDictionaryStructItemWithCustomSerializeOnly() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.False); + Assert.That(weaverErrors, Is.Empty); + } + + [Test] + public void SyncDictionaryErrorForGenericStructKey() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.True); + string weaverError = @"Mirror\.Weaver error:"; + string type = @"MirrorTest\.MyGenericStructDictionary"; + string errorMessage = @"Can not create Serialize or Deserialize for generic element\. Override virtual methods with custom Serialize and Deserialize to use MirrorTest.MyGenericStruct`1 in SyncList"; + Assert.That(weaverErrors, Has.Some.Match($"{weaverError} {type} {errorMessage}")); + } + + [Test] + public void SyncDictionaryErrorForGenericStructItem() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.True); + string weaverError = @"Mirror\.Weaver error:"; + string type = @"MirrorTest\.MyGenericStructDictionary"; + string errorMessage = @"Can not create Serialize or Deserialize for generic element\. Override virtual methods with custom Serialize and Deserialize to use MirrorTest.MyGenericStruct`1 in SyncList"; + Assert.That(weaverErrors, Has.Some.Match($"{weaverError} {type} {errorMessage}")); + } + + [Test] + public void SyncDictionaryErrorForGenericStructKeyWithCustomDeserializeOnly() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.True); + string weaverError = @"Mirror\.Weaver error:"; + string type = @"MirrorTest\.MyGenericStructDictionary"; + string errorMessage = @"Can not create Serialize or Deserialize for generic element\. Override virtual methods with custom Serialize and Deserialize to use MirrorTest.MyGenericStruct`1 in SyncList"; + Assert.That(weaverErrors, Has.Some.Match($"{weaverError} {type} {errorMessage}")); + } + + [Test] + public void SyncDictionaryErrorForGenericStructItemWithCustomDeserializeOnly() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.True); + string weaverError = @"Mirror\.Weaver error:"; + string type = @"MirrorTest\.MyGenericStructDictionary"; + string errorMessage = @"Can not create Serialize or Deserialize for generic element\. Override virtual methods with custom Serialize and Deserialize to use MirrorTest.MyGenericStruct`1 in SyncList"; + Assert.That(weaverErrors, Has.Some.Match($"{weaverError} {type} {errorMessage}")); + } + + [Test] + public void SyncDictionaryErrorForGenericStructKeyWithCustomSerializeOnly() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.True); + string weaverError = @"Mirror\.Weaver error:"; + string type = @"MirrorTest\.MyGenericStructDictionary"; + string errorMessage = @"Can not create Serialize or Deserialize for generic element\. Override virtual methods with custom Serialize and Deserialize to use MirrorTest.MyGenericStruct`1 in SyncList"; + Assert.That(weaverErrors, Has.Some.Match($"{weaverError} {type} {errorMessage}")); + } + + [Test] + public void SyncDictionaryErrorForGenericStructItemWithCustomSerializeOnly() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.True); + string weaverError = @"Mirror\.Weaver error:"; + string type = @"MirrorTest\.MyGenericStructDictionary"; + string errorMessage = @"Can not create Serialize or Deserialize for generic element\. Override virtual methods with custom Serialize and Deserialize to use MirrorTest.MyGenericStruct`1 in SyncList"; + Assert.That(weaverErrors, Has.Some.Match($"{weaverError} {type} {errorMessage}")); + } + + [Test] + public void SyncDictionaryGenericStructKeyWithCustomMethods() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.False); + Assert.That(weaverErrors, Is.Empty); + } + + [Test] + public void SyncDictionaryGenericStructItemWithCustomMethods() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.False); + Assert.That(weaverErrors, Is.Empty); + } + + [Test] + public void SyncDictionaryErrorWhenUsingGenericInNetworkBehaviour() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.True); + string weaverError = @"Mirror\.Weaver error:"; + string type = @"MirrorTest\.SomeSyncDictionary`2 MirrorTest\.SyncDictionaryErrorWhenUsingGenericInNetworkBehaviour::someDictionary"; + string errorMessage = @"Can not use generic SyncObjects directly in NetworkBehaviour\. Create a class and inherit from the generic SyncObject instead\."; + Assert.That(weaverErrors, Has.Some.Match($"{weaverError} {type} {errorMessage}")); + } + } +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests.cs.meta b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests.cs.meta new file mode 100644 index 000000000..a96f8c071 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: de75571c46d27c34bb2c6a67d5eac558 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionary.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionary.cs new file mode 100644 index 000000000..266bd04ae --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionary.cs @@ -0,0 +1,12 @@ +using UnityEngine; +using Mirror; + +namespace MirrorTest +{ + class SyncDictionaryValid : NetworkBehaviour + { + public SyncDictionaryIntString Foo; + } + + public class SyncDictionaryIntString : SyncDictionary { } +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructItem.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructItem.cs new file mode 100644 index 000000000..8d1b8e7f1 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructItem.cs @@ -0,0 +1,16 @@ +using Mirror; + +namespace MirrorTest +{ + class SyncDictionaryErrorForGenericStructItem : NetworkBehaviour + { + MyGenericStructDictionary harpseals; + } + + struct MyGenericStruct + { + T genericpotato; + } + + class MyGenericStructDictionary : SyncDictionary> { }; +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructItemWithCustomDeserializeOnly.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructItemWithCustomDeserializeOnly.cs new file mode 100644 index 000000000..cf8b3c7cb --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructItemWithCustomDeserializeOnly.cs @@ -0,0 +1,22 @@ +using Mirror; + +namespace MirrorTest +{ + class SyncDictionaryErrorForGenericStructItemWithCustomDeserializeOnly : NetworkBehaviour + { + MyGenericStructDictionary harpseals; + } + + struct MyGenericStruct + { + public T genericpotato; + } + + class MyGenericStructDictionary : SyncDictionary> + { + protected override MyGenericStruct DeserializeItem(NetworkReader reader) + { + return new MyGenericStruct() { genericpotato = reader.ReadSingle() }; + } + }; +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructItemWithCustomSerializeOnly.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructItemWithCustomSerializeOnly.cs new file mode 100644 index 000000000..e6879810d --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructItemWithCustomSerializeOnly.cs @@ -0,0 +1,22 @@ +using Mirror; + +namespace MirrorTest +{ + class SyncDictionaryErrorForGenericStructItemWithCustomSerializeOnly : NetworkBehaviour + { + MyGenericStructDictionary harpseals; + } + + struct MyGenericStruct + { + public T genericpotato; + } + + class MyGenericStructDictionary : SyncDictionary> + { + protected override void SerializeItem(NetworkWriter writer, MyGenericStruct item) + { + writer.WriteSingle(item.genericpotato); + } + }; +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructKey.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructKey.cs new file mode 100644 index 000000000..387c40364 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructKey.cs @@ -0,0 +1,16 @@ +using Mirror; + +namespace MirrorTest +{ + class SyncDictionaryErrorForGenericStructKey : NetworkBehaviour + { + MyGenericStructDictionary harpseals; + } + + struct MyGenericStruct + { + T genericpotato; + } + + class MyGenericStructDictionary : SyncDictionary, int> { }; +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructKeyWithCustomDeserializeOnly.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructKeyWithCustomDeserializeOnly.cs new file mode 100644 index 000000000..0e1f7b2ee --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructKeyWithCustomDeserializeOnly.cs @@ -0,0 +1,22 @@ +using Mirror; + +namespace MirrorTest +{ + class SyncDictionaryErrorForGenericStructKeyWithCustomDeserializeOnly : NetworkBehaviour + { + MyGenericStructDictionary harpseals; + } + + struct MyGenericStruct + { + public T genericpotato; + } + + class MyGenericStructDictionary : SyncDictionary, int> + { + protected override MyGenericStruct DeserializeKey(NetworkReader reader) + { + return new MyGenericStruct() { genericpotato = reader.ReadSingle() }; + } + }; +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructKeyWithCustomSerializeOnly.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructKeyWithCustomSerializeOnly.cs new file mode 100644 index 000000000..0ee87884a --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorForGenericStructKeyWithCustomSerializeOnly.cs @@ -0,0 +1,22 @@ +using Mirror; + +namespace MirrorTest +{ + class SyncDictionaryErrorForGenericStructKeyWithCustomSerializeOnly : NetworkBehaviour + { + MyGenericStructDictionary harpseals; + } + + struct MyGenericStruct + { + public T genericpotato; + } + + class MyGenericStructDictionary : SyncDictionary, int> + { + protected override void SerializeKey(NetworkWriter writer, MyGenericStruct item) + { + writer.WriteSingle(item.genericpotato); + } + }; +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorWhenUsingGenericInNetworkBehaviour.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorWhenUsingGenericInNetworkBehaviour.cs new file mode 100644 index 000000000..4aee65267 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryErrorWhenUsingGenericInNetworkBehaviour.cs @@ -0,0 +1,11 @@ +using Mirror; + +namespace MirrorTest +{ + class SyncDictionaryErrorWhenUsingGenericInNetworkBehaviour : NetworkBehaviour + { + readonly SomeSyncDictionary someDictionary; + } + + public class SomeSyncDictionary : SyncDictionary { } +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryGenericAbstractInheritance.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryGenericAbstractInheritance.cs new file mode 100644 index 000000000..120f3d7c3 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryGenericAbstractInheritance.cs @@ -0,0 +1,13 @@ +using Mirror; + +namespace MirrorTest +{ + class SyncDictionaryGenericAbstractInheritance : NetworkBehaviour + { + readonly SomeDictionaryIntString dictionary = new SomeDictionaryIntString(); + } + + public abstract class SomeDictionary : SyncDictionary { } + + public class SomeDictionaryIntString : SomeDictionary { } +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryGenericInheritance.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryGenericInheritance.cs new file mode 100644 index 000000000..650e3a2c5 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryGenericInheritance.cs @@ -0,0 +1,13 @@ +using Mirror; + +namespace MirrorTest +{ + class SyncDictionaryGenericInheritance : NetworkBehaviour + { + readonly SomeDictionaryIntString dictionary = new SomeDictionaryIntString(); + } + + public class SomeDictionary : SyncDictionary { } + + public class SomeDictionaryIntString : SomeDictionary { } +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryGenericStructItemWithCustomMethods.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryGenericStructItemWithCustomMethods.cs new file mode 100644 index 000000000..fb45cd244 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryGenericStructItemWithCustomMethods.cs @@ -0,0 +1,27 @@ +using Mirror; + +namespace MirrorTest +{ + class SyncDictionaryGenericStructItemWithCustomMethods : NetworkBehaviour + { + MyGenericStructDictionary harpseals; + } + + struct MyGenericStruct + { + public T genericpotato; + } + + class MyGenericStructDictionary : SyncDictionary> + { + protected override void SerializeItem(NetworkWriter writer, MyGenericStruct item) + { + writer.WriteSingle(item.genericpotato); + } + + protected override MyGenericStruct DeserializeItem(NetworkReader reader) + { + return new MyGenericStruct() { genericpotato = reader.ReadSingle() }; + } + }; +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryGenericStructKeyWithCustomMethods.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryGenericStructKeyWithCustomMethods.cs new file mode 100644 index 000000000..be4306e8e --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryGenericStructKeyWithCustomMethods.cs @@ -0,0 +1,27 @@ +using Mirror; + +namespace MirrorTest +{ + class SyncDictionaryGenericStructKeyWithCustomMethods : NetworkBehaviour + { + MyGenericStructDictionary harpseals; + } + + struct MyGenericStruct + { + public T genericpotato; + } + + class MyGenericStructDictionary : SyncDictionary, int> + { + protected override void SerializeKey(NetworkWriter writer, MyGenericStruct item) + { + writer.WriteSingle(item.genericpotato); + } + + protected override MyGenericStruct DeserializeKey(NetworkReader reader) + { + return new MyGenericStruct() { genericpotato = reader.ReadSingle() }; + } + }; +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryInheritance.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryInheritance.cs new file mode 100644 index 000000000..f0b187e68 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryInheritance.cs @@ -0,0 +1,19 @@ +using UnityEngine; +using Mirror; + +namespace MirrorTest +{ + class SyncDictionaryInheritance : NetworkBehaviour + { + readonly SuperDictionary dictionary = new SuperDictionary(); + } + + public class SomeDictionary : SyncDictionary { } + + public class SomeDictionaryIntString : SomeDictionary { } + + public class SuperDictionary : SomeDictionaryIntString + { + + } +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructItem.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructItem.cs new file mode 100644 index 000000000..3dd290e11 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructItem.cs @@ -0,0 +1,17 @@ +using UnityEngine; +using Mirror; + +namespace MirrorTest +{ + class SyncDictionaryStructItem : NetworkBehaviour + { + MyStructDictionary Foo; + } + struct MyStruct + { + int potato; + float floatingpotato; + double givemetwopotatoes; + } + class MyStructDictionary : SyncDictionary { } +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructItemWithCustomDeserializeOnly.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructItemWithCustomDeserializeOnly.cs new file mode 100644 index 000000000..bf4d94c8b --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructItemWithCustomDeserializeOnly.cs @@ -0,0 +1,23 @@ +using UnityEngine; +using Mirror; + +namespace MirrorTest +{ + class SyncDictionaryStructItemWithCustomDeserializeOnly : NetworkBehaviour + { + MyStructDictionary Foo; + } + struct MyStruct + { + int potato; + float floatingpotato; + double givemetwopotatoes; + } + class MyStructDictionary : SyncDictionary + { + protected override MyStruct DeserializeItem(NetworkReader reader) + { + return new MyStruct() { /* read some stuff here */ }; + } + } +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructItemWithCustomMethods.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructItemWithCustomMethods.cs new file mode 100644 index 000000000..754db3423 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructItemWithCustomMethods.cs @@ -0,0 +1,28 @@ +using UnityEngine; +using Mirror; + +namespace MirrorTest +{ + class SyncDictionaryItemStructWithCustomMethods : NetworkBehaviour + { + MyStructDictionary Foo; + } + struct MyStruct + { + int potato; + float floatingpotato; + double givemetwopotatoes; + } + class MyStructDictionary : SyncDictionary + { + protected override void SerializeItem(NetworkWriter writer, MyStruct item) + { + // write some stuff here + } + + protected override MyStruct DeserializeItem(NetworkReader reader) + { + return new MyStruct() { /* read some stuff here */ }; + } + } +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructItemWithCustomSerializeOnly.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructItemWithCustomSerializeOnly.cs new file mode 100644 index 000000000..356cb346b --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructItemWithCustomSerializeOnly.cs @@ -0,0 +1,23 @@ +using UnityEngine; +using Mirror; + +namespace MirrorTest +{ + class SyncDictionaryStructItemWithCustomSerializeOnly : NetworkBehaviour + { + MyStructDictionary Foo; + } + struct MyStruct + { + int potato; + float floatingpotato; + double givemetwopotatoes; + } + class MyStructDictionary : SyncDictionary + { + protected override void SerializeItem(NetworkWriter writer, MyStruct item) + { + // write some stuff here + } + } +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructKey.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructKey.cs new file mode 100644 index 000000000..b6c5b7d80 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructKey.cs @@ -0,0 +1,17 @@ +using UnityEngine; +using Mirror; + +namespace MirrorTest +{ + class SyncDictionaryStructKey : NetworkBehaviour + { + MyStructDictionary Foo; + } + struct MyStruct + { + int potato; + float floatingpotato; + double givemetwopotatoes; + } + class MyStructDictionary : SyncDictionary { } +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructKeyWithCustomDeserializeOnly.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructKeyWithCustomDeserializeOnly.cs new file mode 100644 index 000000000..e16896467 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructKeyWithCustomDeserializeOnly.cs @@ -0,0 +1,23 @@ +using UnityEngine; +using Mirror; + +namespace MirrorTest +{ + class SyncDictionaryStructKeyWithCustomDeserializeOnly : NetworkBehaviour + { + MyStructDictionary Foo; + } + struct MyStruct + { + int potato; + float floatingpotato; + double givemetwopotatoes; + } + class MyStructDictionary : SyncDictionary + { + protected override MyStruct DeserializeKey(NetworkReader reader) + { + return new MyStruct() { /* read some stuff here */ }; + } + } +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructKeyWithCustomMethods.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructKeyWithCustomMethods.cs new file mode 100644 index 000000000..4443cf588 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructKeyWithCustomMethods.cs @@ -0,0 +1,28 @@ +using UnityEngine; +using Mirror; + +namespace MirrorTest +{ + class SyncDictionaryKeyStructWithCustomMethods : NetworkBehaviour + { + MyStructDictionary Foo; + } + struct MyStruct + { + int potato; + float floatingpotato; + double givemetwopotatoes; + } + class MyStructDictionary : SyncDictionary + { + protected override void SerializeKey(NetworkWriter writer, MyStruct item) + { + // write some stuff here + } + + protected override MyStruct DeserializeKey(NetworkReader reader) + { + return new MyStruct() { /* read some stuff here */ }; + } + } +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructKeyWithCustomSerializeOnly.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructKeyWithCustomSerializeOnly.cs new file mode 100644 index 000000000..52a4ebe38 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncDictionaryTests~/SyncDictionaryStructKeyWithCustomSerializeOnly.cs @@ -0,0 +1,23 @@ +using UnityEngine; +using Mirror; + +namespace MirrorTest +{ + class SyncDictionaryStructKeyWithCustomSerializeOnly : NetworkBehaviour + { + MyStructDictionary Foo; + } + struct MyStruct + { + int potato; + float floatingpotato; + double givemetwopotatoes; + } + class MyStructDictionary : SyncDictionary + { + protected override void SerializeKey(NetworkWriter writer, MyStruct item) + { + // write some stuff here + } + } +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncListTests.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncListTests.cs index e32559c4e..0c2204669 100644 --- a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncListTests.cs +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncListTests.cs @@ -171,8 +171,8 @@ public void SyncListErrorWhenUsingGenericListInNetworkBehaviour() { Assert.That(CompilationFinishedHook.WeaveFailed, Is.True); string weaverError = @"Mirror\.Weaver error:"; - string type = @"MirrorTest\.SomeList`1 MirrorTest.SyncListErrorWhenUsingGenericListInNetworkBehaviour::someList"; - string errorMessage = @"Can not use generic SyncObjects directly in NetworkBehaviour\. Create a class and inherit from the generic syncList instead\."; + string type = @"MirrorTest\.SomeList`1 MirrorTest\.SyncListErrorWhenUsingGenericListInNetworkBehaviour::someList"; + string errorMessage = @"Can not use generic SyncObjects directly in NetworkBehaviour\. Create a class and inherit from the generic SyncObject instead\."; Assert.That(weaverErrors, Has.Some.Match($"{weaverError} {type} {errorMessage}")); } } diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncListTests~/SyncList.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncListTests~/SyncList.cs index 2858a8622..2e4d17bde 100644 --- a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncListTests~/SyncList.cs +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncListTests~/SyncList.cs @@ -3,7 +3,7 @@ namespace MirrorTest { - class SyncListValid : NetworkBehaviour + class SyncList : NetworkBehaviour { public SyncListInt Foo; } diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests.cs new file mode 100644 index 000000000..26765a7a9 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests.cs @@ -0,0 +1,50 @@ +using NUnit.Framework; + +namespace Mirror.Weaver.Tests +{ + // Some tests for SyncObjects are in WeaverSyncListTests and apply to SyncDictionary too + public class WeaverSyncSetTests : WeaverTestsBuildFromTestName + { + [Test] + public void SyncSet() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.False); + Assert.That(weaverErrors, Is.Empty); + } + + [Test] + public void SyncSetByteValid() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.False); + Assert.That(weaverErrors, Is.Empty); + } + + [Test] + public void SyncSetGenericAbstractInheritance() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.False); + Assert.That(weaverErrors, Is.Empty); + } + + [Test] + public void SyncSetGenericInheritance() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.False); + Assert.That(weaverErrors, Is.Empty); + } + + [Test] + public void SyncSetInheritance() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.False); + Assert.That(weaverErrors, Is.Empty); + } + + [Test] + public void SyncSetStruct() + { + Assert.That(CompilationFinishedHook.WeaveFailed, Is.False); + Assert.That(weaverErrors, Is.Empty); + } + } +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests.cs.meta b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests.cs.meta new file mode 100644 index 000000000..25b40d8a8 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6aeadedebed6110459fac293b9435e88 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSet.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSet.cs new file mode 100644 index 000000000..31c00a196 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSet.cs @@ -0,0 +1,10 @@ +using UnityEngine; +using Mirror; + +namespace MirrorTest +{ + class SyncSet : NetworkBehaviour + { + public SyncListInt Foo; + } +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSetByteValid.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSetByteValid.cs new file mode 100644 index 000000000..9559cbb05 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSetByteValid.cs @@ -0,0 +1,12 @@ +using UnityEngine; +using Mirror; + +namespace MirrorTest +{ + class SyncSetByteValid : NetworkBehaviour + { + class MyByteClass : SyncHashSet {}; + + MyByteClass Foo; + } +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSetGenericAbstractInheritance.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSetGenericAbstractInheritance.cs new file mode 100644 index 000000000..e8cb1d30d --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSetGenericAbstractInheritance.cs @@ -0,0 +1,13 @@ +using Mirror; + +namespace MirrorTest +{ + class SyncSetGenericAbstractInheritance : NetworkBehaviour + { + readonly SomeSetInt superSyncSetString = new SomeSetInt(); + } + + public abstract class SomeSet : SyncHashSet { } + + public class SomeSetInt : SomeSet { } +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSetGenericInheritance.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSetGenericInheritance.cs new file mode 100644 index 000000000..afa0dc8f0 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSetGenericInheritance.cs @@ -0,0 +1,13 @@ +using Mirror; + +namespace MirrorTest +{ + class SyncSetGenericInheritance : NetworkBehaviour + { + readonly SomeSetInt someSet = new SomeSetInt(); + } + + public class SomeSet : SyncHashSet { } + + public class SomeSetInt : SomeSet { } +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSetInheritance.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSetInheritance.cs new file mode 100644 index 000000000..699f4d629 --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSetInheritance.cs @@ -0,0 +1,14 @@ +using UnityEngine; +using Mirror; + +namespace MirrorTest +{ + class SyncSetInheritance : NetworkBehaviour + { + readonly SuperSet superSet = new SuperSet(); + } + + public class SomeSet : SyncHashSet { } + + public class SuperSet : SomeSet { } +} diff --git a/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSetStruct.cs b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSetStruct.cs new file mode 100644 index 000000000..63386100d --- /dev/null +++ b/Assets/Mirror/Tests/Editor/Weaver/WeaverSyncSetTests~/SyncSetStruct.cs @@ -0,0 +1,17 @@ +using UnityEngine; +using Mirror; + +namespace MirrorTest +{ + class SyncSetStruct : NetworkBehaviour + { + MyStructSet Foo; + } + struct MyStruct + { + int potato; + float floatingpotato; + double givemetwopotatoes; + } + class MyStructSet : SyncHashSet { } +}