Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: third_party/protobuf/java/core/src/test/java/com/google/protobuf/GeneratedMessageTest.java

Issue 2599263002: third_party/protobuf: Update to HEAD (f52e188fe4) (Closed)
Patch Set: Address comments Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 import protobuf_unittest.UnittestProto.ForeignMessageOrBuilder; 58 import protobuf_unittest.UnittestProto.ForeignMessageOrBuilder;
59 import protobuf_unittest.UnittestProto.NestedTestAllTypes; 59 import protobuf_unittest.UnittestProto.NestedTestAllTypes;
60 import protobuf_unittest.UnittestProto.TestAllExtensions; 60 import protobuf_unittest.UnittestProto.TestAllExtensions;
61 import protobuf_unittest.UnittestProto.TestAllTypes; 61 import protobuf_unittest.UnittestProto.TestAllTypes;
62 import protobuf_unittest.UnittestProto.TestAllTypes.NestedMessage; 62 import protobuf_unittest.UnittestProto.TestAllTypes.NestedMessage;
63 import protobuf_unittest.UnittestProto.TestAllTypesOrBuilder; 63 import protobuf_unittest.UnittestProto.TestAllTypesOrBuilder;
64 import protobuf_unittest.UnittestProto.TestExtremeDefaultValues; 64 import protobuf_unittest.UnittestProto.TestExtremeDefaultValues;
65 import protobuf_unittest.UnittestProto.TestOneof2; 65 import protobuf_unittest.UnittestProto.TestOneof2;
66 import protobuf_unittest.UnittestProto.TestPackedTypes; 66 import protobuf_unittest.UnittestProto.TestPackedTypes;
67 import protobuf_unittest.UnittestProto.TestUnpackedTypes; 67 import protobuf_unittest.UnittestProto.TestUnpackedTypes;
68
69 import junit.framework.TestCase;
70
71 import java.io.ByteArrayInputStream; 68 import java.io.ByteArrayInputStream;
72 import java.io.ByteArrayOutputStream; 69 import java.io.ByteArrayOutputStream;
73 import java.io.ObjectInputStream; 70 import java.io.ObjectInputStream;
74 import java.io.ObjectOutputStream; 71 import java.io.ObjectOutputStream;
75 import java.util.Arrays; 72 import java.util.Arrays;
76 import java.util.Collections; 73 import java.util.Collections;
77 import java.util.Iterator; 74 import java.util.Iterator;
78 import java.util.List; 75 import java.util.List;
76 import junit.framework.TestCase;
79 77
80 /** 78 /**
81 * Unit test for generated messages and generated code. See also 79 * Unit test for generated messages and generated code. See also
82 * {@link MessageTest}, which tests some generated message functionality. 80 * {@link MessageTest}, which tests some generated message functionality.
83 * 81 *
84 * @author kenton@google.com Kenton Varda 82 * @author kenton@google.com Kenton Varda
85 */ 83 */
86 public class GeneratedMessageTest extends TestCase { 84 public class GeneratedMessageTest extends TestCase {
87 TestUtil.ReflectionTester reflectionTester = 85 TestUtil.ReflectionTester reflectionTester =
88 new TestUtil.ReflectionTester(TestAllTypes.getDescriptor(), null); 86 new TestUtil.ReflectionTester(TestAllTypes.getDescriptor(), null);
(...skipping 876 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 TestAllTypes.NestedMessage nestedMessage1 = 963 TestAllTypes.NestedMessage nestedMessage1 =
966 TestAllTypes.NestedMessage.newBuilder().build(); 964 TestAllTypes.NestedMessage.newBuilder().build();
967 TestAllTypes.NestedMessage nestedMessage2 = 965 TestAllTypes.NestedMessage nestedMessage2 =
968 TestAllTypes.NestedMessage.newBuilder().build(); 966 TestAllTypes.NestedMessage.newBuilder().build();
969 967
970 // Set all three flavors (enum, primitive, message and singular/repeated) 968 // Set all three flavors (enum, primitive, message and singular/repeated)
971 // and verify no invalidations fired 969 // and verify no invalidations fired
972 TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent(); 970 TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
973 971
974 TestAllTypes.Builder builder = (TestAllTypes.Builder) 972 TestAllTypes.Builder builder = (TestAllTypes.Builder)
975 ((GeneratedMessage) TestAllTypes.getDefaultInstance()). 973 ((AbstractMessage) TestAllTypes.getDefaultInstance()).
976 newBuilderForType(mockParent); 974 newBuilderForType(mockParent);
977 builder.setOptionalInt32(1); 975 builder.setOptionalInt32(1);
978 builder.setOptionalNestedEnum(TestAllTypes.NestedEnum.BAR); 976 builder.setOptionalNestedEnum(TestAllTypes.NestedEnum.BAR);
979 builder.setOptionalNestedMessage(nestedMessage1); 977 builder.setOptionalNestedMessage(nestedMessage1);
980 builder.addRepeatedInt32(1); 978 builder.addRepeatedInt32(1);
981 builder.addRepeatedNestedEnum(TestAllTypes.NestedEnum.BAR); 979 builder.addRepeatedNestedEnum(TestAllTypes.NestedEnum.BAR);
982 builder.addRepeatedNestedMessage(nestedMessage1); 980 builder.addRepeatedNestedMessage(nestedMessage1);
983 assertEquals(0, mockParent.getInvalidationCount()); 981 assertEquals(0, mockParent.getInvalidationCount());
984 982
985 // Now tell it we want changes and make sure it's only fired once 983 // Now tell it we want changes and make sure it's only fired once
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 builder.addRepeatedNestedMessage(nestedMessage2); 1018 builder.addRepeatedNestedMessage(nestedMessage2);
1021 builder.addRepeatedNestedMessage(nestedMessage1); 1019 builder.addRepeatedNestedMessage(nestedMessage1);
1022 assertEquals(6, mockParent.getInvalidationCount()); 1020 assertEquals(6, mockParent.getInvalidationCount());
1023 1021
1024 } 1022 }
1025 1023
1026 public void testInvalidations_Extensions() throws Exception { 1024 public void testInvalidations_Extensions() throws Exception {
1027 TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent(); 1025 TestUtil.MockBuilderParent mockParent = new TestUtil.MockBuilderParent();
1028 1026
1029 TestAllExtensions.Builder builder = (TestAllExtensions.Builder) 1027 TestAllExtensions.Builder builder = (TestAllExtensions.Builder)
1030 ((GeneratedMessage) TestAllExtensions.getDefaultInstance()). 1028 ((AbstractMessage) TestAllExtensions.getDefaultInstance()).
1031 newBuilderForType(mockParent); 1029 newBuilderForType(mockParent);
1032 1030
1033 builder.addExtension(UnittestProto.repeatedInt32Extension, 1); 1031 builder.addExtension(UnittestProto.repeatedInt32Extension, 1);
1034 builder.setExtension(UnittestProto.repeatedInt32Extension, 0, 2); 1032 builder.setExtension(UnittestProto.repeatedInt32Extension, 0, 2);
1035 builder.clearExtension(UnittestProto.repeatedInt32Extension); 1033 builder.clearExtension(UnittestProto.repeatedInt32Extension);
1036 assertEquals(0, mockParent.getInvalidationCount()); 1034 assertEquals(0, mockParent.getInvalidationCount());
1037 1035
1038 // Now tell it we want changes and make sure it's only fired once 1036 // Now tell it we want changes and make sure it's only fired once
1039 builder.buildPartial(); 1037 builder.buildPartial();
1040 builder.addExtension(UnittestProto.repeatedInt32Extension, 2); 1038 builder.addExtension(UnittestProto.repeatedInt32Extension, 2);
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
1667 } 1665 }
1668 try { 1666 try {
1669 builder.getRepeatedFieldBuilder( 1667 builder.getRepeatedFieldBuilder(
1670 descriptor.findFieldByName("optional_nested_message"), 0); 1668 descriptor.findFieldByName("optional_nested_message"), 0);
1671 fail("Exception was not thrown"); 1669 fail("Exception was not thrown");
1672 } catch (UnsupportedOperationException e) { 1670 } catch (UnsupportedOperationException e) {
1673 // We expect this exception. 1671 // We expect this exception.
1674 } 1672 }
1675 } 1673 }
1676 } 1674 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698