aboutsummaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorMax Cai <maxtroy@google.com>2014-01-10 13:26:51 +0000
committerMax Cai <maxtroy@google.com>2014-01-10 14:43:32 +0000
commit1b1735ceb17374c5abf63139a134b00b958bec03 (patch)
tree684a4ce7a4a84555f2a728c006233caffb31ff0f /java
parent0c0f8c7ef03ede18a964e92b983a9315d6aeb26d (diff)
downloadprotobuf-1b1735ceb17374c5abf63139a134b00b958bec03.tar.gz
protobuf-1b1735ceb17374c5abf63139a134b00b958bec03.tar.bz2
protobuf-1b1735ceb17374c5abf63139a134b00b958bec03.zip
Don't serialize required fields whose 'has' flags are unset.
Change-Id: Ibbe944fff83e44a8f2206e18ee9ec6f10661297a
Diffstat (limited to 'java')
-rw-r--r--java/src/test/java/com/google/protobuf/NanoTest.java7
1 files changed, 6 insertions, 1 deletions
diff --git a/java/src/test/java/com/google/protobuf/NanoTest.java b/java/src/test/java/com/google/protobuf/NanoTest.java
index 49348441..bb95a177 100644
--- a/java/src/test/java/com/google/protobuf/NanoTest.java
+++ b/java/src/test/java/com/google/protobuf/NanoTest.java
@@ -2202,6 +2202,7 @@ public class NanoTest extends TestCase {
assertFalse(msg.hasDefaultFloatNan);
assertFalse(msg.hasDefaultNestedEnum);
assertFalse(msg.hasId);
+ assertFalse(msg.hasRequiredEnum);
msg.optionalInt32 = 123;
msg.optionalNestedMessage = new TestAllTypesNanoHas.NestedMessage();
msg.optionalNestedMessage.bb = 2;
@@ -2211,7 +2212,7 @@ public class NanoTest extends TestCase {
byte [] result = MessageNano.toByteArray(msg);
int msgSerializedSize = msg.getSerializedSize();
//System.out.printf("mss=%d result.length=%d\n", msgSerializedSize, result.length);
- assertTrue(msgSerializedSize == 13);
+ assertTrue(msgSerializedSize == 10);
assertEquals(result.length, msgSerializedSize);
// Has fields true upon parse.
@@ -2237,6 +2238,8 @@ public class NanoTest extends TestCase {
msg.hasDefaultBytes = true;
msg.hasDefaultFloatNan = true;
msg.hasDefaultNestedEnum = true;
+ msg.hasId = true;
+ msg.hasRequiredEnum = true;
byte [] result = MessageNano.toByteArray(msg);
int msgSerializedSize = msg.getSerializedSize();
@@ -2255,6 +2258,7 @@ public class NanoTest extends TestCase {
assertTrue(newMsg.hasDefaultFloatNan);
assertTrue(newMsg.hasDefaultNestedEnum);
assertTrue(newMsg.hasId);
+ assertTrue(newMsg.hasRequiredEnum);
assertEquals(0, newMsg.optionalInt32);
assertEquals(0, newMsg.optionalString.length());
assertEquals(0, newMsg.optionalBytes.length);
@@ -2266,6 +2270,7 @@ public class NanoTest extends TestCase {
assertEquals(TestAllTypesNanoHas.BAR, newMsg.defaultNestedEnum);
assertEquals(Float.NaN, newMsg.defaultFloatNan);
assertEquals(0, newMsg.id);
+ assertEquals(TestAllTypesNanoHas.FOO, newMsg.requiredEnum);
}
public void testNanoWithAccessorsBasic() throws Exception {