diff options
author | Jon Skeet <skeet@pobox.com> | 2009-01-27 12:25:21 +0000 |
---|---|---|
committer | Jon Skeet <skeet@pobox.com> | 2009-01-27 12:25:21 +0000 |
commit | 642a8140c88dfb61f5f4812fc179e4f42beb4978 (patch) | |
tree | 4d5bef960bd3af7d84c168e675076c0f69990e1a /src/ProtocolBuffers.Test/ReflectionTester.cs | |
parent | 25a2792283ec695d3c038559ea0682f1d83d9bd3 (diff) | |
download | protobuf-642a8140c88dfb61f5f4812fc179e4f42beb4978.tar.gz protobuf-642a8140c88dfb61f5f4812fc179e4f42beb4978.tar.bz2 protobuf-642a8140c88dfb61f5f4812fc179e4f42beb4978.zip |
Setters/adders now throw ArgumentNullException appropriately.
Diffstat (limited to 'src/ProtocolBuffers.Test/ReflectionTester.cs')
-rw-r--r-- | src/ProtocolBuffers.Test/ReflectionTester.cs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/ProtocolBuffers.Test/ReflectionTester.cs b/src/ProtocolBuffers.Test/ReflectionTester.cs index 889b2f6b..767c8cc9 100644 --- a/src/ProtocolBuffers.Test/ReflectionTester.cs +++ b/src/ProtocolBuffers.Test/ReflectionTester.cs @@ -810,5 +810,37 @@ namespace Google.ProtocolBuffers { Assert.AreEqual("524", message[f("repeated_string_piece"), 1]); Assert.AreEqual("525", message[f("repeated_cord"), 1]); } + + /// <summary> + /// Verifies that the reflection setters for the given Builder object throw an + /// ArgumentNullException if they are passed a null value. + /// </summary> + public void AssertReflectionSettersRejectNull(IBuilder builder) { + TestUtil.AssertArgumentNullException(() => builder[f("optional_string")] = null); + TestUtil.AssertArgumentNullException(() => builder[f("optional_bytes")] = null); + TestUtil.AssertArgumentNullException(() => builder[f("optional_nested_enum")] = null); + TestUtil.AssertArgumentNullException(() => builder[f("optional_nested_message")] = null); + TestUtil.AssertArgumentNullException(() => builder[f("optional_nested_message")] = null); + TestUtil.AssertArgumentNullException(() => builder.WeakAddRepeatedField(f("repeated_string"), null)); + TestUtil.AssertArgumentNullException(() => builder.WeakAddRepeatedField(f("repeated_bytes"), null)); + TestUtil.AssertArgumentNullException(() => builder.WeakAddRepeatedField(f("repeated_nested_enum"), null)); + TestUtil.AssertArgumentNullException(() => builder.WeakAddRepeatedField(f("repeated_nested_message"), null)); + } + + /// <summary> + /// Verifies that the reflection repeated setters for the given Builder object throw an + /// ArgumentNullException if they are passed a null value. + /// </summary> + public void AssertReflectionRepeatedSettersRejectNull(IBuilder builder) { + builder.WeakAddRepeatedField(f("repeated_string"), "one"); + TestUtil.AssertArgumentNullException(() => builder.SetRepeatedField(f("repeated_string"), 0, null)); + builder.WeakAddRepeatedField(f("repeated_bytes"), TestUtil.ToBytes("one")); + TestUtil.AssertArgumentNullException(() => builder.SetRepeatedField(f("repeated_bytes"), 0, null)); + builder.WeakAddRepeatedField(f("repeated_nested_enum"), nestedBaz); + TestUtil.AssertArgumentNullException(() => builder.SetRepeatedField(f("repeated_nested_enum"), 0, null)); + builder.WeakAddRepeatedField(f("repeated_nested_message"), + new TestAllTypes.Types.NestedMessage.Builder { Bb = 218 }.Build()); + TestUtil.AssertArgumentNullException(() => builder.SetRepeatedField(f("repeated_nested_message"), 0, null)); + } } } |