| 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 import com.google.protobuf.test.UnittestImport.ImportEnum; | 48 import com.google.protobuf.test.UnittestImport.ImportEnum; |
| 49 import com.google.protobuf.test.UnittestImport.ImportEnumForMap; | 49 import com.google.protobuf.test.UnittestImport.ImportEnumForMap; |
| 50 import protobuf_unittest.TestCustomOptions; | 50 import protobuf_unittest.TestCustomOptions; |
| 51 import protobuf_unittest.UnittestCustomOptions; | 51 import protobuf_unittest.UnittestCustomOptions; |
| 52 import protobuf_unittest.UnittestProto; | 52 import protobuf_unittest.UnittestProto; |
| 53 import protobuf_unittest.UnittestProto.ForeignEnum; | 53 import protobuf_unittest.UnittestProto.ForeignEnum; |
| 54 import protobuf_unittest.UnittestProto.ForeignMessage; | 54 import protobuf_unittest.UnittestProto.ForeignMessage; |
| 55 import protobuf_unittest.UnittestProto.TestAllExtensions; | 55 import protobuf_unittest.UnittestProto.TestAllExtensions; |
| 56 import protobuf_unittest.UnittestProto.TestAllTypes; | 56 import protobuf_unittest.UnittestProto.TestAllTypes; |
| 57 import protobuf_unittest.UnittestProto.TestExtremeDefaultValues; | 57 import protobuf_unittest.UnittestProto.TestExtremeDefaultValues; |
| 58 import protobuf_unittest.UnittestProto.TestJsonName; | |
| 59 import protobuf_unittest.UnittestProto.TestMultipleExtensionRanges; | 58 import protobuf_unittest.UnittestProto.TestMultipleExtensionRanges; |
| 60 import protobuf_unittest.UnittestProto.TestRequired; | 59 import protobuf_unittest.UnittestProto.TestRequired; |
| 61 import protobuf_unittest.UnittestProto.TestReservedFields; | 60 import protobuf_unittest.UnittestProto.TestReservedFields; |
| 62 import protobuf_unittest.UnittestProto.TestService; | 61 import protobuf_unittest.UnittestProto.TestService; |
| 62 import junit.framework.TestCase; |
| 63 |
| 63 import java.util.Arrays; | 64 import java.util.Arrays; |
| 64 import java.util.Collections; | 65 import java.util.Collections; |
| 65 import java.util.List; | 66 import java.util.List; |
| 66 import junit.framework.TestCase; | |
| 67 | 67 |
| 68 /** | 68 /** |
| 69 * Unit test for {@link Descriptors}. | 69 * Unit test for {@link Descriptors}. |
| 70 * | 70 * |
| 71 * @author kenton@google.com Kenton Varda | 71 * @author kenton@google.com Kenton Varda |
| 72 */ | 72 */ |
| 73 public class DescriptorsTest extends TestCase { | 73 public class DescriptorsTest extends TestCase { |
| 74 | 74 |
| 75 // Regression test for bug where referencing a FieldDescriptor.Type value | 75 // Regression test for bug where referencing a FieldDescriptor.Type value |
| 76 // before a FieldDescriptorProto.Type value would yield a | 76 // before a FieldDescriptorProto.Type value would yield a |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 descriptor.getOptions().getExtension(UnittestCustomOptions.messageOpt1)); | 375 descriptor.getOptions().getExtension(UnittestCustomOptions.messageOpt1)); |
| 376 | 376 |
| 377 FieldDescriptor field = descriptor.findFieldByName("field1"); | 377 FieldDescriptor field = descriptor.findFieldByName("field1"); |
| 378 assertNotNull(field); | 378 assertNotNull(field); |
| 379 | 379 |
| 380 assertTrue( | 380 assertTrue( |
| 381 field.getOptions().hasExtension(UnittestCustomOptions.fieldOpt1)); | 381 field.getOptions().hasExtension(UnittestCustomOptions.fieldOpt1)); |
| 382 assertEquals(Long.valueOf(8765432109L), | 382 assertEquals(Long.valueOf(8765432109L), |
| 383 field.getOptions().getExtension(UnittestCustomOptions.fieldOpt1)); | 383 field.getOptions().getExtension(UnittestCustomOptions.fieldOpt1)); |
| 384 | 384 |
| 385 OneofDescriptor oneof = descriptor.getOneofs().get(0); | |
| 386 assertNotNull(oneof); | |
| 387 | |
| 388 assertTrue( | |
| 389 oneof.getOptions().hasExtension(UnittestCustomOptions.oneofOpt1)); | |
| 390 assertEquals(Integer.valueOf(-99), | |
| 391 oneof.getOptions().getExtension(UnittestCustomOptions.oneofOpt1)); | |
| 392 | |
| 393 EnumDescriptor enumType = | 385 EnumDescriptor enumType = |
| 394 UnittestCustomOptions.TestMessageWithCustomOptions.AnEnum.getDescriptor(); | 386 UnittestCustomOptions.TestMessageWithCustomOptions.AnEnum.getDescriptor(); |
| 395 | 387 |
| 396 assertTrue( | 388 assertTrue( |
| 397 enumType.getOptions().hasExtension(UnittestCustomOptions.enumOpt1)); | 389 enumType.getOptions().hasExtension(UnittestCustomOptions.enumOpt1)); |
| 398 assertEquals(Integer.valueOf(-789), | 390 assertEquals(Integer.valueOf(-789), |
| 399 enumType.getOptions().getExtension(UnittestCustomOptions.enumOpt1)); | 391 enumType.getOptions().getExtension(UnittestCustomOptions.enumOpt1)); |
| 400 | 392 |
| 401 ServiceDescriptor service = | 393 ServiceDescriptor service = |
| 402 UnittestCustomOptions.TestServiceWithCustomOptions.getDescriptor(); | 394 UnittestCustomOptions.TestServiceWithCustomOptions.getDescriptor(); |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 .setLabel(FieldDescriptorProto.Label.LABEL_REPEATED) | 790 .setLabel(FieldDescriptorProto.Label.LABEL_REPEATED) |
| 799 .setOptions(DescriptorProtos.FieldOptions.newBuilder() | 791 .setOptions(DescriptorProtos.FieldOptions.newBuilder() |
| 800 .setPacked(true) | 792 .setPacked(true) |
| 801 .build()) | 793 .build()) |
| 802 .build()) | 794 .build()) |
| 803 .build()) | 795 .build()) |
| 804 .build(); | 796 .build(); |
| 805 Descriptors.FileDescriptor.buildFrom( | 797 Descriptors.FileDescriptor.buildFrom( |
| 806 fileDescriptorProto, new FileDescriptor[0]); | 798 fileDescriptorProto, new FileDescriptor[0]); |
| 807 } | 799 } |
| 808 | |
| 809 public void testFieldJsonName() throws Exception { | |
| 810 Descriptor d = TestJsonName.getDescriptor(); | |
| 811 assertEquals(6, d.getFields().size()); | |
| 812 assertEquals("fieldName1", d.getFields().get(0).getJsonName()); | |
| 813 assertEquals("fieldName2", d.getFields().get(1).getJsonName()); | |
| 814 assertEquals("FieldName3", d.getFields().get(2).getJsonName()); | |
| 815 assertEquals("FieldName4", d.getFields().get(3).getJsonName()); | |
| 816 assertEquals("FIELDNAME5", d.getFields().get(4).getJsonName()); | |
| 817 assertEquals("@type", d.getFields().get(5).getJsonName()); | |
| 818 } | |
| 819 } | 800 } |
| OLD | NEW |