aboutsummaryrefslogtreecommitdiff
path: root/javanano/src/test/java/com
diff options
context:
space:
mode:
authorBrian Duff <bduff@google.com>2014-10-01 13:33:40 -0700
committerBrian Duff <bduff@google.com>2015-04-28 12:42:55 -0700
commitd099a88685bf4b2df1689eb4cc56e75065cb87b1 (patch)
tree8b50aaed239f2f70e26710dd3965942e7145141b /javanano/src/test/java/com
parentfb96026b8deb79aa023c9f5c460582e8fea8f331 (diff)
downloadprotobuf-d099a88685bf4b2df1689eb4cc56e75065cb87b1.tar.gz
protobuf-d099a88685bf4b2df1689eb4cc56e75065cb87b1.tar.bz2
protobuf-d099a88685bf4b2df1689eb4cc56e75065cb87b1.zip
Add clone() method support for nano.
Upstreamed from Another Place (cr/57247854). Change-Id: I2aaf59544c0f5ae21a51891d8a5eeda1dc722c90
Diffstat (limited to 'javanano/src/test/java/com')
-rw-r--r--javanano/src/test/java/com/google/protobuf/nano/NanoTest.java20
-rw-r--r--javanano/src/test/java/com/google/protobuf/nano/unittest_extension_nano.proto1
2 files changed, 21 insertions, 0 deletions
diff --git a/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java b/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java
index c81846e5..91cc385f 100644
--- a/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java
+++ b/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java
@@ -3023,6 +3023,10 @@ public class NanoTest extends TestCase {
assertTrue(Arrays.equals(floats, message.getExtension(RepeatedExtensions.repeatedFloat)));
assertTrue(Arrays.equals(doubles, message.getExtension(RepeatedExtensions.repeatedDouble)));
assertTrue(Arrays.equals(enums, message.getExtension(RepeatedExtensions.repeatedEnum)));
+
+ // Clone the message and ensure it's still equal.
+ Extensions.ExtendableMessage clone = message.clone();
+ assertEquals(clone, message);
}
public void testNullExtensions() throws Exception {
@@ -4406,6 +4410,22 @@ public class NanoTest extends TestCase {
assertTrue(Arrays.equals(nonPacked.enums, packed.enums));
}
+ public void testClone() throws Exception {
+ // A simple message.
+ AnotherMessage anotherMessage = new AnotherMessage();
+ anotherMessage.string = "Hello";
+ anotherMessage.value = true;
+ anotherMessage.integers = new int[] { 1, 2, 3 };
+
+ AnotherMessage clone = anotherMessage.clone();
+ assertEquals(clone, anotherMessage);
+
+ // Verify it was a deep clone - changes to the clone shouldn't affect the
+ // original.
+ clone.integers[1] = 100;
+ assertFalse(clone.equals(anotherMessage));
+ }
+
private void assertHasWireData(MessageNano message, boolean expected) {
byte[] bytes = MessageNano.toByteArray(message);
int wireLength = bytes.length;
diff --git a/javanano/src/test/java/com/google/protobuf/nano/unittest_extension_nano.proto b/javanano/src/test/java/com/google/protobuf/nano/unittest_extension_nano.proto
index d1c5766d..ca56b3dd 100644
--- a/javanano/src/test/java/com/google/protobuf/nano/unittest_extension_nano.proto
+++ b/javanano/src/test/java/com/google/protobuf/nano/unittest_extension_nano.proto
@@ -16,6 +16,7 @@ enum AnEnum {
message AnotherMessage {
optional string string = 1;
optional bool value = 2;
+ repeated int32 integers = 3;
}
message ContainerMessage {