diff options
author | Jisi Liu <jisi.liu@gmail.com> | 2015-02-19 10:26:25 -0800 |
---|---|---|
committer | Jisi Liu <jisi.liu@gmail.com> | 2015-02-19 16:43:08 -0800 |
commit | 968150327d7bb45601702e60ab6d0073ccfecd7e (patch) | |
tree | 1a170c6ca01f3ff5c60782221df12e9e5bfbcac6 /javanano/src | |
parent | 7b72a24a2038dcb3409bb91d90f5a06abac3959c (diff) |
partial oneof tests.
Diffstat (limited to 'javanano/src')
-rw-r--r-- | javanano/src/test/java/com/google/protobuf/nano/NanoTest.java | 38 |
1 files changed, 38 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 feb3054f..6e3d3655 100644 --- a/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java +++ b/javanano/src/test/java/com/google/protobuf/nano/NanoTest.java @@ -3639,6 +3639,44 @@ public class NanoTest extends TestCase { assertEquals(6, map.size()); } + private void checkOneofCase(TestAllTypesNano nano, int field) + throws Exception { + assertEquals(field, nano.getOneofFieldCase()); + assertEquals( + field == TestAllTypesNano.ONEOF_BYTES_FIELD_NUMBER, + nano.hasOneofBytes()); + assertEquals( + field == TestAllTypesNano.ONEOF_ENUM_FIELD_NUMBER, + nano.hasOneofEnum()); + assertEquals( + field == TestAllTypesNano.ONEOF_FIXED64_FIELD_NUMBER, + nano.hasOneofFixed64()); + assertEquals( + field == TestAllTypesNano.ONEOF_NESTED_MESSAGE_FIELD_NUMBER, + nano.hasOneofNestedMessage()); + assertEquals( + field == TestAllTypesNano.ONEOF_STRING_FIELD_NUMBER, + nano.hasOneofString()); + assertEquals( + field == TestAllTypesNano.ONEOF_UINT32_FIELD_NUMBER, + nano.hasOneofUint32()); + + } + + public void testOneofBasic() throws Exception { + TestAllTypesNano m1 = new TestAllTypesNano(); + checkOneofCase(m1, 0); + + m1.setOneofString("hello"); + checkOneofCase(m1, TestAllTypesNano.ONEOF_STRING_FIELD_NUMBER); + + TestAllTypesNano m2 = new TestAllTypesNano(); + m2.setOneofEnum(TestAllTypesNano.BAZ); + assertTrue(m2.hasOneofEnum()); + assertEquals( + TestAllTypesNano.ONEOF_ENUM_FIELD_NUMBER, m2.getOneofFieldCase()); + } + public void testNullRepeatedFields() throws Exception { // Check that serialization after explicitly setting a repeated field // to null doesn't NPE. |