|
@@ -31,6 +31,7 @@
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
using System;
|
|
using System;
|
|
|
|
+using System.IO;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
using Google.Protobuf.TestProtos;
|
|
using Google.Protobuf.TestProtos;
|
|
using NUnit.Framework;
|
|
using NUnit.Framework;
|
|
@@ -583,6 +584,33 @@ namespace Google.Protobuf.Collections
|
|
Assert.False(map.TryGetValue(SampleNaNs.PayloadFlipped, out ignored));
|
|
Assert.False(map.TryGetValue(SampleNaNs.PayloadFlipped, out ignored));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ [Test]
|
|
|
|
+ public void AddEntriesFrom_CodedInputStream()
|
|
|
|
+ {
|
|
|
|
+ // map will have string key and string value
|
|
|
|
+ var keyTag = WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited);
|
|
|
|
+ var valueTag = WireFormat.MakeTag(2, WireFormat.WireType.LengthDelimited);
|
|
|
|
+
|
|
|
|
+ var memoryStream = new MemoryStream();
|
|
|
|
+ var output = new CodedOutputStream(memoryStream);
|
|
|
|
+ output.WriteLength(20); // total of keyTag + key + valueTag + value
|
|
|
|
+ output.WriteTag(keyTag);
|
|
|
|
+ output.WriteString("the_key");
|
|
|
|
+ output.WriteTag(valueTag);
|
|
|
|
+ output.WriteString("the_value");
|
|
|
|
+ output.Flush();
|
|
|
|
+
|
|
|
|
+ var field = new MapField<string,string>();
|
|
|
|
+ var mapCodec = new MapField<string,string>.Codec(FieldCodec.ForString(keyTag, ""), FieldCodec.ForString(valueTag, ""), 10);
|
|
|
|
+ var input = new CodedInputStream(memoryStream.ToArray());
|
|
|
|
+
|
|
|
|
+ // test the legacy overload of AddEntriesFrom that takes a CodedInputStream
|
|
|
|
+ field.AddEntriesFrom(input, mapCodec);
|
|
|
|
+ CollectionAssert.AreEquivalent(new[] { "the_key" }, field.Keys);
|
|
|
|
+ CollectionAssert.AreEquivalent(new[] { "the_value" }, field.Values);
|
|
|
|
+ Assert.IsTrue(input.IsAtEnd);
|
|
|
|
+ }
|
|
|
|
+
|
|
#if !NET35
|
|
#if !NET35
|
|
[Test]
|
|
[Test]
|
|
public void IDictionaryKeys_Equals_IReadOnlyDictionaryKeys()
|
|
public void IDictionaryKeys_Equals_IReadOnlyDictionaryKeys()
|