Commit a80a37cc authored by Jon Skeet's avatar Jon Skeet

Tidying up, and a couple of extra tests.

parent f26f8dce
...@@ -201,56 +201,54 @@ namespace Google.ProtocolBuffers { ...@@ -201,56 +201,54 @@ namespace Google.ProtocolBuffers {
} }
} }
/* TODO(jonskeet): Reinstate this when protoc is ready [Test]
public void testSkipWholeMessage() throws Exception { public void SkipWholeMessage() {
TestAllTypes message = TestUtil.getAllSet(); TestAllTypes message = TestUtil.GetAllSet();
byte[] rawBytes = message.toByteArray(); byte[] rawBytes = message.ToByteArray();
// Create two parallel inputs. Parse one as unknown fields while using // Create two parallel inputs. Parse one as unknown fields while using
// skipField() to skip each field on the other. Expect the same tags. // skipField() to skip each field on the other. Expect the same tags.
CodedInputStream input1 = CodedInputStream.newInstance(rawBytes); CodedInputStream input1 = CodedInputStream.CreateInstance(rawBytes);
CodedInputStream input2 = CodedInputStream.newInstance(rawBytes); CodedInputStream input2 = CodedInputStream.CreateInstance(rawBytes);
UnknownFieldSet.Builder unknownFields = UnknownFieldSet.newBuilder(); UnknownFieldSet.Builder unknownFields = UnknownFieldSet.CreateBuilder();
while (true) { while (true) {
int tag = input1.readTag(); uint tag = input1.ReadTag();
assertEquals(tag, input2.readTag()); Assert.AreEqual(tag, input2.ReadTag());
if (tag == 0) { if (tag == 0) {
break; break;
} }
unknownFields.mergeFieldFrom(tag, input1); unknownFields.MergeFieldFrom(tag, input1);
input2.skipField(tag); input2.SkipField(tag);
}
} }
}*/
/* TODO(jonskeet): Reinstate this when protoc is ready public void ReadHugeBlob() {
public void testReadHugeBlob() throws Exception {
// Allocate and initialize a 1MB blob. // Allocate and initialize a 1MB blob.
byte[] blob = new byte[1 << 20]; byte[] blob = new byte[1 << 20];
for (int i = 0; i < blob.length; i++) { for (int i = 0; i < blob.Length; i++) {
blob[i] = (byte)i; blob[i] = (byte)i;
} }
// Make a message containing it. // Make a message containing it.
TestAllTypes.Builder builder = TestAllTypes.newBuilder(); TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
TestUtil.setAllFields(builder); TestUtil.SetAllFields(builder);
builder.setOptionalBytes(ByteString.copyFrom(blob)); builder.SetOptionalBytes(ByteString.CopyFrom(blob));
TestAllTypes message = builder.build(); TestAllTypes message = builder.Build();
// Serialize and parse it. Make sure to parse from an InputStream, not // Serialize and parse it. Make sure to parse from an InputStream, not
// directly from a ByteString, so that CodedInputStream uses buffered // directly from a ByteString, so that CodedInputStream uses buffered
// reading. // reading.
TestAllTypes message2 = TestAllTypes message2 = TestAllTypes.ParseFrom(message.ToByteString().CreateCodedInput());
TestAllTypes.parseFrom(message.toByteString().newInput());
assertEquals(message.getOptionalBytes(), message2.getOptionalBytes()); Assert.AreEqual(message.OptionalBytes, message2.OptionalBytes);
// Make sure all the other fields were parsed correctly. // Make sure all the other fields were parsed correctly.
TestAllTypes message3 = TestAllTypes.newBuilder(message2) TestAllTypes message3 = TestAllTypes.CreateBuilder(message2)
.setOptionalBytes(TestUtil.getAllSet().getOptionalBytes()) .SetOptionalBytes(TestUtil.GetAllSet().OptionalBytes)
.build(); .Build();
TestUtil.assertAllFieldsSet(message3); TestUtil.AssertAllFieldsSet(message3);
}*/ }
[Test] [Test]
public void ReadMaliciouslyLargeBlob() { public void ReadMaliciouslyLargeBlob() {
......
...@@ -51,7 +51,6 @@ namespace Google.ProtocolBuffers { ...@@ -51,7 +51,6 @@ namespace Google.ProtocolBuffers {
/// then baseDescriptor should be for TestAllExtensions instead, and instead of /// then baseDescriptor should be for TestAllExtensions instead, and instead of
/// reading and writing normal fields, the tester will read and write extensions. /// reading and writing normal fields, the tester will read and write extensions.
/// All of the TestAllExtensions extensions must be registered in the registry. /// All of the TestAllExtensions extensions must be registered in the registry.
/// TODO(jonskeet): Enforce all of these with two factory methods.
/// </summary> /// </summary>
private ReflectionTester(MessageDescriptor baseDescriptor, private ReflectionTester(MessageDescriptor baseDescriptor,
ExtensionRegistry extensionRegistry) { ExtensionRegistry extensionRegistry) {
......
...@@ -102,7 +102,7 @@ namespace Google.ProtocolBuffers { ...@@ -102,7 +102,7 @@ namespace Google.ProtocolBuffers {
} }
#endregion #endregion
#region Uncategorised (TODO: Fix this!) #region Validation
/// <summary> /// <summary>
/// Verifies that the last call to ReadTag() returned the given tag value. /// Verifies that the last call to ReadTag() returned the given tag value.
/// This is used to verify that a nested group ended with the correct /// This is used to verify that a nested group ended with the correct
......
...@@ -8,7 +8,6 @@ namespace Google.ProtocolBuffers { ...@@ -8,7 +8,6 @@ namespace Google.ProtocolBuffers {
/// <summary> /// <summary>
/// An implementation of IMessage that can represent arbitrary types, given a MessageaDescriptor. /// An implementation of IMessage that can represent arbitrary types, given a MessageaDescriptor.
/// TODO: Implement appropriate generics.
/// </summary> /// </summary>
public class DynamicMessage : AbstractMessage<DynamicMessage, DynamicMessage.Builder> { public class DynamicMessage : AbstractMessage<DynamicMessage, DynamicMessage.Builder> {
......
...@@ -95,8 +95,7 @@ namespace Google.ProtocolBuffers { ...@@ -95,8 +95,7 @@ namespace Google.ProtocolBuffers {
set { set {
if (field.IsExtension) { if (field.IsExtension) {
ExtendableMessage<TMessage, TBuilder> message = MessageBeingBuilt; ExtendableMessage<TMessage, TBuilder> message = MessageBeingBuilt;
// TODO(jonskeet): Figure out how to call this! message.VerifyContainingType(field);
// message.VerifyExtensionContainingType(field);
message.Extensions[field, index] = value; message.Extensions[field, index] = value;
} else { } else {
base[field, index] = value; base[field, index] = value;
...@@ -109,8 +108,7 @@ namespace Google.ProtocolBuffers { ...@@ -109,8 +108,7 @@ namespace Google.ProtocolBuffers {
set { set {
if (field.IsExtension) { if (field.IsExtension) {
ExtendableMessage<TMessage, TBuilder> message = MessageBeingBuilt; ExtendableMessage<TMessage, TBuilder> message = MessageBeingBuilt;
// TODO(jonskeet): Figure out how to call this! message.VerifyContainingType(field);
// message.VerifyExtensionContainingType(field);
message.Extensions[field] = value; message.Extensions[field] = value;
} else { } else {
base[field] = value; base[field] = value;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment