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

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

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years 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 22 matching lines...) Expand all
33 import com.google.protobuf.Descriptors.FieldDescriptor; 33 import com.google.protobuf.Descriptors.FieldDescriptor;
34 import protobuf_unittest.UnittestOptimizeFor.TestOptimizedForSize; 34 import protobuf_unittest.UnittestOptimizeFor.TestOptimizedForSize;
35 import protobuf_unittest.UnittestProto; 35 import protobuf_unittest.UnittestProto;
36 import protobuf_unittest.UnittestProto.ForeignMessage; 36 import protobuf_unittest.UnittestProto.ForeignMessage;
37 import protobuf_unittest.UnittestProto.TestAllExtensions; 37 import protobuf_unittest.UnittestProto.TestAllExtensions;
38 import protobuf_unittest.UnittestProto.TestAllTypes; 38 import protobuf_unittest.UnittestProto.TestAllTypes;
39 import protobuf_unittest.UnittestProto.TestPackedTypes; 39 import protobuf_unittest.UnittestProto.TestPackedTypes;
40 import protobuf_unittest.UnittestProto.TestRequired; 40 import protobuf_unittest.UnittestProto.TestRequired;
41 import protobuf_unittest.UnittestProto.TestRequiredForeign; 41 import protobuf_unittest.UnittestProto.TestRequiredForeign;
42 import protobuf_unittest.UnittestProto.TestUnpackedTypes; 42 import protobuf_unittest.UnittestProto.TestUnpackedTypes;
43 import java.util.Map;
43 import junit.framework.TestCase; 44 import junit.framework.TestCase;
44 45
45 import java.util.Map;
46
47 /** 46 /**
48 * Unit test for {@link AbstractMessage}. 47 * Unit test for {@link AbstractMessage}.
49 * 48 *
50 * @author kenton@google.com Kenton Varda 49 * @author kenton@google.com Kenton Varda
51 */ 50 */
52 public class AbstractMessageTest extends TestCase { 51 public class AbstractMessageTest extends TestCase {
53 /** 52 /**
54 * Extends AbstractMessage and wraps some other message object. The methods 53 * Extends AbstractMessage and wraps some other message object. The methods
55 * of the Message interface which aren't explicitly implemented by 54 * of the Message interface which aren't explicitly implemented by
56 * AbstractMessage are forwarded to the wrapped object. This allows us to 55 * AbstractMessage are forwarded to the wrapped object. This allows us to
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 checkNotEqual(eUnknownFields, fUnknownFields); 484 checkNotEqual(eUnknownFields, fUnknownFields);
486 checkEqualsIsConsistent(eUnknownFields); 485 checkEqualsIsConsistent(eUnknownFields);
487 checkEqualsIsConsistent(fUnknownFields); 486 checkEqualsIsConsistent(fUnknownFields);
488 487
489 // Subsequent reconstitutions should be identical 488 // Subsequent reconstitutions should be identical
490 UnittestProto.TestEmptyMessage eUnknownFields2 = 489 UnittestProto.TestEmptyMessage eUnknownFields2 =
491 UnittestProto.TestEmptyMessage.parseFrom(e.toByteArray()); 490 UnittestProto.TestEmptyMessage.parseFrom(e.toByteArray());
492 checkEqualsIsConsistent(eUnknownFields, eUnknownFields2); 491 checkEqualsIsConsistent(eUnknownFields, eUnknownFields2);
493 } 492 }
494 493
495
496 /** 494 /**
497 * Asserts that the given proto has symmetric equals and hashCode methods. 495 * Asserts that the given proto has symmetric equals and hashCode methods.
498 */ 496 */
499 private void checkEqualsIsConsistent(Message message) { 497 private void checkEqualsIsConsistent(Message message) {
500 // Object should be equal to itself. 498 // Object should be equal to itself.
501 assertEquals(message, message); 499 assertEquals(message, message);
502 500
503 // Object should be equal to a dynamic copy of itself. 501 // Object should be equal to a dynamic copy of itself.
504 DynamicMessage dynamic = DynamicMessage.newBuilder(message).build(); 502 DynamicMessage dynamic = DynamicMessage.newBuilder(message).build();
505 checkEqualsIsConsistent(message, dynamic); 503 checkEqualsIsConsistent(message, dynamic);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 ByteString.copyFrom(new byte[]{(byte) 0x80}); // A lone continuation byt e. 540 ByteString.copyFrom(new byte[]{(byte) 0x80}); // A lone continuation byt e.
543 try { 541 try {
544 AbstractMessageLite.checkByteStringIsUtf8(byteString); 542 AbstractMessageLite.checkByteStringIsUtf8(byteString);
545 fail("Expected AbstractMessageLite.checkByteStringIsUtf8 to throw IllegalA rgumentException"); 543 fail("Expected AbstractMessageLite.checkByteStringIsUtf8 to throw IllegalA rgumentException");
546 } catch (IllegalArgumentException exception) { 544 } catch (IllegalArgumentException exception) {
547 assertEquals("Byte string is not UTF-8.", exception.getMessage()); 545 assertEquals("Byte string is not UTF-8.", exception.getMessage());
548 } 546 }
549 } 547 }
550 548
551 } 549 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698