OLD | NEW |
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 public void testEquals() throws Exception { | 48 public void testEquals() throws Exception { |
49 // Since the generated equals and hashCode methods for lite messages are a | 49 // Since the generated equals and hashCode methods for lite messages are a |
50 // mostly complete subset of those for regular messages, we can mostly assum
e | 50 // mostly complete subset of those for regular messages, we can mostly assum
e |
51 // that the generated methods are already thoroughly tested by the regular t
ests. | 51 // that the generated methods are already thoroughly tested by the regular t
ests. |
52 | 52 |
53 // This test mostly just verifies is that a proto with | 53 // This test mostly just verifies is that a proto with |
54 // optimize_for = LITE_RUNTIME and java_generates_equals_and_hash_compiles | 54 // optimize_for = LITE_RUNTIME and java_generates_equals_and_hash_compiles |
55 // correctly when linked only against the lite library. | 55 // correctly when linked only against the lite library. |
56 | 56 |
57 // We do however do some basic testing to make sure that equals is actually | 57 // We do however do some basic testing to make sure that equals is actually |
58 // overriden to test for value equality rather than simple object equality. | 58 // overridden to test for value equality rather than simple object equality. |
59 | 59 |
60 // Check that two identical objs are equal. | 60 // Check that two identical objs are equal. |
61 Foo foo1a = Foo.newBuilder() | 61 Foo foo1a = Foo.newBuilder() |
62 .setValue(1) | 62 .setValue(1) |
63 .addBar(Bar.newBuilder().setName("foo1")) | 63 .addBar(Bar.newBuilder().setName("foo1")) |
64 .build(); | 64 .build(); |
65 Foo foo1b = Foo.newBuilder() | 65 Foo foo1b = Foo.newBuilder() |
66 .setValue(1) | 66 .setValue(1) |
67 .addBar(Bar.newBuilder().setName("foo1")) | 67 .addBar(Bar.newBuilder().setName("foo1")) |
68 .build(); | 68 .build(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 private void assertEqualsAndHashCodeAreFalse(Object o1, Object o2) { | 116 private void assertEqualsAndHashCodeAreFalse(Object o1, Object o2) { |
117 assertFalse(o1.equals(o2)); | 117 assertFalse(o1.equals(o2)); |
118 assertFalse(o1.hashCode() == o2.hashCode()); | 118 assertFalse(o1.hashCode() == o2.hashCode()); |
119 } | 119 } |
120 | 120 |
121 public void testRecursiveHashcode() { | 121 public void testRecursiveHashcode() { |
122 // This tests that we don't infinite loop. | 122 // This tests that we don't infinite loop. |
123 TestRecursiveOneof.getDefaultInstance().hashCode(); | 123 TestRecursiveOneof.getDefaultInstance().hashCode(); |
124 } | 124 } |
125 } | 125 } |
OLD | NEW |