From 3783d9a8add33b240e326438fa0b16869dbcfb44 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 29 Jul 2015 16:05:57 -0700 Subject: remove the freeze API --- .../Collections/MapFieldTest.cs | 56 ---------------------- .../Collections/RepeatedFieldTest.cs | 36 -------------- .../Google.Protobuf.Test/GeneratedMessageTest.cs | 17 ------- 3 files changed, 109 deletions(-) (limited to 'csharp/src/Google.Protobuf.Test') diff --git a/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs b/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs index 46d3bd9a..c62ac046 100644 --- a/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs +++ b/csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs @@ -45,53 +45,6 @@ namespace Google.Protobuf.Collections /// public class MapFieldTest { - // Protobuf-specific tests - [Test] - public void Freeze_FreezesMessages() - { - var message = new ForeignMessage { C = 20 }; - var map = new MapField { { "x", message } }; - map.Freeze(); - Assert.IsTrue(message.IsFrozen); - } - - [Test] - public void Freeze_Idempotent() - { - var message = new ForeignMessage { C = 20 }; - var map = new MapField { { "x", message } }; - Assert.IsFalse(map.IsFrozen); - map.Freeze(); - Assert.IsTrue(message.IsFrozen); - map.Freeze(); - Assert.IsTrue(message.IsFrozen); - } - - [Test] - public void Freeze_PreventsMutation() - { - var map = new MapField(); - map.Freeze(); - Assert.IsTrue(map.IsFrozen); - Assert.IsTrue(map.IsReadOnly); - ICollection> collection = map; - Assert.Throws(() => map["x"] = "y"); - Assert.Throws(() => map.Add("x", "y")); - Assert.Throws(() => map.Remove("x")); - Assert.Throws(() => map.Clear()); - Assert.Throws(() => collection.Add(NewKeyValuePair("x", "y"))); - Assert.Throws(() => collection.Remove(NewKeyValuePair("x", "y"))); - } - - [Test] - public void Clone_ReturnsNonFrozen() - { - var map = new MapField(); - map.Freeze(); - var clone = map.Clone(); - clone.Add("x", "y"); - } - [Test] public void Clone_ClonesMessages() { @@ -422,10 +375,6 @@ namespace Google.Protobuf.Collections dictionary.Remove("x"); Assert.AreEqual(0, dictionary.Count); Assert.Throws(() => dictionary.Remove(null)); - - map.Freeze(); - // Call should fail even though it clearly doesn't contain 5 as a key. - Assert.Throws(() => dictionary.Remove(5)); } [Test] @@ -449,8 +398,6 @@ namespace Google.Protobuf.Collections var map = new MapField { { "x", "y" } }; IDictionary dictionary = map; Assert.IsFalse(dictionary.IsFixedSize); - map.Freeze(); - Assert.IsTrue(dictionary.IsFixedSize); } [Test] @@ -504,9 +451,6 @@ namespace Google.Protobuf.Collections Assert.Throws(() => dictionary["x"] = 5); Assert.Throws(() => dictionary[null] = "z"); Assert.Throws(() => dictionary["x"] = null); - map.Freeze(); - // Note: Not InvalidOperationException. - Assert.Throws(() => dictionary["a"] = "c"); } [Test] diff --git a/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs b/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs index 25be7731..33c4e10c 100644 --- a/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs +++ b/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs @@ -193,44 +193,10 @@ namespace Google.Protobuf.Collections Assert.Throws(() => list[2] = "bad"); } - [Test] - public void Freeze_FreezesElements() - { - var list = new RepeatedField { new TestAllTypes() }; - Assert.IsFalse(list[0].IsFrozen); - list.Freeze(); - Assert.IsTrue(list[0].IsFrozen); - } - - [Test] - public void Freeze_PreventsMutations() - { - var list = new RepeatedField { 0 }; - list.Freeze(); - Assert.Throws(() => list.Add(1)); - Assert.Throws(() => list[0] = 1); - Assert.Throws(() => list.Clear()); - Assert.Throws(() => list.RemoveAt(0)); - Assert.Throws(() => list.Remove(0)); - Assert.Throws(() => list.Insert(0, 0)); - } - - [Test] - public void Freeze_ReportsFrozen() - { - var list = new RepeatedField { 0 }; - Assert.IsFalse(list.IsFrozen); - Assert.IsFalse(list.IsReadOnly); - list.Freeze(); - Assert.IsTrue(list.IsFrozen); - Assert.IsTrue(list.IsReadOnly); - } - [Test] public void Clone_ReturnsMutable() { var list = new RepeatedField { 0 }; - list.Freeze(); var clone = list.Clone(); clone[0] = 1; } @@ -585,8 +551,6 @@ namespace Google.Protobuf.Collections var field = new RepeatedField { "first", "second" }; IList list = field; Assert.IsFalse(list.IsFixedSize); - field.Freeze(); - Assert.IsTrue(list.IsFixedSize); } [Test] diff --git a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs index 528a4023..dfaac48c 100644 --- a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs +++ b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs @@ -503,23 +503,6 @@ namespace Google.Protobuf Assert.AreNotEqual(original, clone); } - [Test] - public void Freeze() - { - var frozen = new TestAllTypes(); - frozen.Freeze(); - Assert.IsTrue(frozen.IsFrozen); - - Assert.Throws(() => frozen.ClearOneofField()); - Assert.Throws(() => frozen.SingleInt32 = 0); - Assert.Throws(() => frozen.SingleNestedMessage = null); - Assert.Throws(() => frozen.SingleNestedEnum = 0); - Assert.Throws(() => frozen.OneofString = null); - Assert.Throws(() => frozen.OneofUint32 = 0U); - Assert.Throws(() => frozen.RepeatedDouble.Add(0.0)); - Assert.Throws(() => frozen.RepeatedNestedMessage.Add(new TestAllTypes.Types.NestedMessage())); - } - [Test] public void OneofProperties() { -- cgit v1.2.3