aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs
diff options
context:
space:
mode:
authorJon Skeet <jonskeet@google.com>2015-08-05 11:23:38 +0100
committerJon Skeet <jonskeet@google.com>2015-08-05 11:23:38 +0100
commitff334a60eb2e74722867dd41b78d7c8c90bc8d0c (patch)
tree6aca2c954c9ea56bff5690d6ee7e5423a2ac13d8 /csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs
parent607940321c8ceeb80ec1099d94add8eef86825e5 (diff)
downloadprotobuf-ff334a60eb2e74722867dd41b78d7c8c90bc8d0c.tar.gz
protobuf-ff334a60eb2e74722867dd41b78d7c8c90bc8d0c.tar.bz2
protobuf-ff334a60eb2e74722867dd41b78d7c8c90bc8d0c.zip
Change ReadTag and PeekTag to just use 0 as a return value for "end of stream", rather than using an awkward out parameter.
This simplifies quite a lot of code. Generated code in next commit.
Diffstat (limited to 'csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs')
-rw-r--r--csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs20
1 files changed, 11 insertions, 9 deletions
diff --git a/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs b/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs
index 6e25fa37..c4c92efd 100644
--- a/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs
+++ b/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs
@@ -279,9 +279,7 @@ namespace Google.Protobuf
ms.Position = 0;
CodedInputStream input = new CodedInputStream(ms);
- uint testtag;
- Assert.IsTrue(input.ReadTag(out testtag));
- Assert.AreEqual(tag, testtag);
+ Assert.AreEqual(tag, input.ReadTag());
// TODO(jonskeet): Should this be ArgumentNullException instead?
Assert.Throws<InvalidProtocolBufferException>(() => input.ReadBytes());
@@ -377,9 +375,7 @@ namespace Google.Protobuf
CodedInputStream input = new CodedInputStream(ms);
- uint actualTag;
- Assert.IsTrue(input.ReadTag(out actualTag));
- Assert.AreEqual(tag, actualTag);
+ Assert.AreEqual(tag, input.ReadTag());
string text = input.ReadString();
Assert.AreEqual('\ufffd', text[0]);
}
@@ -430,15 +426,21 @@ namespace Google.Protobuf
ms.Position = 0;
CodedInputStream input = new CodedInputStream(ms, new byte[ms.Length / 2]);
- uint tag;
- Assert.IsTrue(input.ReadTag(out tag));
+ uint tag = input.ReadTag();
Assert.AreEqual(1, WireFormat.GetTagFieldNumber(tag));
Assert.AreEqual(100, input.ReadBytes().Length);
- Assert.IsTrue(input.ReadTag(out tag));
+ tag = input.ReadTag();
Assert.AreEqual(2, WireFormat.GetTagFieldNumber(tag));
Assert.AreEqual(100, input.ReadBytes().Length);
}
}
+
+ [Test]
+ public void Tag0Throws()
+ {
+ var input = new CodedInputStream(new byte[] { 0 });
+ Assert.Throws<InvalidProtocolBufferException>(() => input.ReadTag());
+ }
}
} \ No newline at end of file