OLD | NEW |
1 #region Copyright notice and license | 1 #region Copyright notice and license |
2 // Protocol Buffers - Google's data interchange format | 2 // Protocol Buffers - Google's data interchange format |
3 // Copyright 2015 Google Inc. All rights reserved. | 3 // Copyright 2015 Google Inc. All rights reserved. |
4 // https://developers.google.com/protocol-buffers/ | 4 // https://developers.google.com/protocol-buffers/ |
5 // | 5 // |
6 // Redistribution and use in source and binary forms, with or without | 6 // Redistribution and use in source and binary forms, with or without |
7 // modification, are permitted provided that the following conditions are | 7 // modification, are permitted provided that the following conditions are |
8 // met: | 8 // met: |
9 // | 9 // |
10 // * Redistributions of source code must retain the above copyright | 10 // * Redistributions of source code must retain the above copyright |
(...skipping 14 matching lines...) Expand all Loading... |
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 #endregion | 31 #endregion |
32 | 32 |
33 using System.Collections.Generic; | 33 using System.Collections.Generic; |
34 using System.IO; | 34 using System.IO; |
35 using System.Reflection; | |
36 using Google.Protobuf.TestProtos; | 35 using Google.Protobuf.TestProtos; |
37 using NUnit.Framework; | 36 using NUnit.Framework; |
38 | 37 |
39 namespace Google.Protobuf | 38 namespace Google.Protobuf |
40 { | 39 { |
41 public class FieldCodecTest | 40 public class FieldCodecTest |
42 { | 41 { |
43 #pragma warning disable 0414 // Used by tests via reflection - do not remove! | 42 #pragma warning disable 0414 // Used by tests via reflection - do not remove! |
44 private static readonly List<ICodecTestData> Codecs = new List<ICodecTes
tData> | 43 private static readonly List<ICodecTestData> Codecs = new List<ICodecTes
tData> |
45 { | 44 { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 | 155 |
157 public void TestDefaultValue() | 156 public void TestDefaultValue() |
158 { | 157 { |
159 // WriteTagAndValue ignores default values | 158 // WriteTagAndValue ignores default values |
160 var stream = new MemoryStream(); | 159 var stream = new MemoryStream(); |
161 var codedOutput = new CodedOutputStream(stream); | 160 var codedOutput = new CodedOutputStream(stream); |
162 codec.WriteTagAndValue(codedOutput, codec.DefaultValue); | 161 codec.WriteTagAndValue(codedOutput, codec.DefaultValue); |
163 codedOutput.Flush(); | 162 codedOutput.Flush(); |
164 Assert.AreEqual(0, stream.Position); | 163 Assert.AreEqual(0, stream.Position); |
165 Assert.AreEqual(0, codec.CalculateSizeWithTag(codec.DefaultValue
)); | 164 Assert.AreEqual(0, codec.CalculateSizeWithTag(codec.DefaultValue
)); |
166 if (typeof(T).GetTypeInfo().IsValueType) | 165 if (typeof(T).IsValueType) |
167 { | 166 { |
168 Assert.AreEqual(default(T), codec.DefaultValue); | 167 Assert.AreEqual(default(T), codec.DefaultValue); |
169 } | 168 } |
170 | 169 |
171 // The plain ValueWriter/ValueReader delegates don't. | 170 // The plain ValueWriter/ValueReader delegates don't. |
172 if (codec.DefaultValue != null) // This part isn't appropriate f
or message types. | 171 if (codec.DefaultValue != null) // This part isn't appropriate f
or message types. |
173 { | 172 { |
174 codedOutput = new CodedOutputStream(stream); | 173 codedOutput = new CodedOutputStream(stream); |
175 codec.ValueWriter(codedOutput, codec.DefaultValue); | 174 codec.ValueWriter(codedOutput, codec.DefaultValue); |
176 codedOutput.Flush(); | 175 codedOutput.Flush(); |
(...skipping 10 matching lines...) Expand all Loading... |
187 Assert.AreEqual(name.Contains("Fixed"), codec.FixedSize != 0); | 186 Assert.AreEqual(name.Contains("Fixed"), codec.FixedSize != 0); |
188 } | 187 } |
189 | 188 |
190 public override string ToString() | 189 public override string ToString() |
191 { | 190 { |
192 return name; | 191 return name; |
193 } | 192 } |
194 } | 193 } |
195 } | 194 } |
196 } | 195 } |
OLD | NEW |