protoc 2.6.1.1 → 2.6.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (479) hide show
  1. checksums.yaml +4 -4
  2. data/ext/protoc/Makefile.in +10 -13
  3. data/ext/protoc/extconf.rb +0 -1
  4. data/ext/protoc/protobuf/CHANGES.txt +593 -0
  5. data/ext/protoc/protobuf/CONTRIBUTORS.txt +93 -0
  6. data/ext/protoc/protobuf/INSTALL.txt +237 -0
  7. data/ext/protoc/protobuf/LICENSE +33 -0
  8. data/ext/protoc/protobuf/Makefile.am +267 -0
  9. data/ext/protoc/protobuf/README.md +167 -0
  10. data/ext/protoc/protobuf/autogen.sh +41 -0
  11. data/ext/protoc/protobuf/benchmarks/ProtoBench.java +203 -0
  12. data/ext/protoc/protobuf/benchmarks/google_message1.dat +0 -0
  13. data/ext/protoc/protobuf/benchmarks/google_message2.dat +0 -0
  14. data/ext/protoc/protobuf/benchmarks/google_size.proto +136 -0
  15. data/ext/protoc/protobuf/benchmarks/google_speed.proto +136 -0
  16. data/ext/protoc/protobuf/benchmarks/readme.txt +50 -0
  17. data/ext/protoc/protobuf/configure.ac +159 -0
  18. data/ext/protoc/protobuf/editors/README.txt +5 -0
  19. data/ext/protoc/protobuf/editors/proto.vim +105 -0
  20. data/ext/protoc/protobuf/editors/protobuf-mode.el +220 -0
  21. data/ext/protoc/protobuf/examples/AddPerson.java +95 -0
  22. data/ext/protoc/protobuf/examples/ListPeople.java +50 -0
  23. data/ext/protoc/protobuf/examples/Makefile +58 -0
  24. data/ext/protoc/protobuf/examples/README.txt +29 -0
  25. data/ext/protoc/protobuf/examples/add_person.cc +95 -0
  26. data/ext/protoc/protobuf/examples/add_person.py +58 -0
  27. data/ext/protoc/protobuf/examples/addressbook.proto +30 -0
  28. data/ext/protoc/protobuf/examples/list_people.cc +68 -0
  29. data/ext/protoc/protobuf/examples/list_people.py +38 -0
  30. data/ext/protoc/protobuf/generate_descriptor_proto.sh +33 -0
  31. data/ext/protoc/protobuf/java/README.txt +96 -0
  32. data/ext/protoc/protobuf/java/pom.xml +217 -0
  33. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/AbstractMessage.java +466 -0
  34. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/AbstractMessageLite.java +355 -0
  35. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/AbstractParser.java +253 -0
  36. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/BlockingRpcChannel.java +51 -0
  37. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/BlockingService.java +64 -0
  38. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/BoundedByteString.java +163 -0
  39. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ByteString.java +1022 -0
  40. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/CodedInputStream.java +1311 -0
  41. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/CodedOutputStream.java +1297 -0
  42. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Descriptors.java +2238 -0
  43. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/DynamicMessage.java +622 -0
  44. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Extension.java +96 -0
  45. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ExtensionRegistry.java +392 -0
  46. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ExtensionRegistryLite.java +185 -0
  47. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/FieldSet.java +907 -0
  48. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/GeneratedMessage.java +2213 -0
  49. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/GeneratedMessageLite.java +949 -0
  50. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Internal.java +391 -0
  51. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java +122 -0
  52. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LazyField.java +154 -0
  53. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LazyFieldLite.java +176 -0
  54. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LazyStringArrayList.java +367 -0
  55. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LazyStringList.java +163 -0
  56. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LiteralByteString.java +362 -0
  57. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Message.java +244 -0
  58. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/MessageLite.java +320 -0
  59. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java +60 -0
  60. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/MessageOrBuilder.java +143 -0
  61. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/MessageReflection.java +931 -0
  62. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Parser.java +261 -0
  63. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ProtocolMessageEnum.java +58 -0
  64. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ProtocolStringList.java +48 -0
  65. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java +696 -0
  66. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RopeByteString.java +957 -0
  67. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RpcCallback.java +47 -0
  68. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RpcChannel.java +71 -0
  69. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RpcController.java +118 -0
  70. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RpcUtil.java +134 -0
  71. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Service.java +117 -0
  72. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ServiceException.java +52 -0
  73. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/SingleFieldBuilder.java +241 -0
  74. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/SmallSortedMap.java +618 -0
  75. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/TextFormat.java +1984 -0
  76. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/UninitializedMessageException.java +99 -0
  77. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/UnknownFieldSet.java +995 -0
  78. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java +205 -0
  79. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Utf8.java +349 -0
  80. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/WireFormat.java +163 -0
  81. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/AbstractMessageTest.java +527 -0
  82. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/BoundedByteStringTest.java +68 -0
  83. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/ByteStringTest.java +759 -0
  84. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/CheckUtf8Test.java +141 -0
  85. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/CodedInputStreamTest.java +769 -0
  86. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/CodedOutputStreamTest.java +401 -0
  87. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/DeprecatedFieldTest.java +80 -0
  88. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/DescriptorsTest.java +735 -0
  89. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/DynamicMessageTest.java +326 -0
  90. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java +48 -0
  91. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/GeneratedMessageTest.java +1515 -0
  92. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/IsValidUtf8Test.java +180 -0
  93. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java +421 -0
  94. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyFieldLiteTest.java +134 -0
  95. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyFieldTest.java +121 -0
  96. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyMessageLiteTest.java +319 -0
  97. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyStringArrayListTest.java +174 -0
  98. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java +143 -0
  99. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java +85 -0
  100. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LiteTest.java +148 -0
  101. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LiteralByteStringTest.java +396 -0
  102. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/MessageTest.java +353 -0
  103. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/NestedBuildersTest.java +185 -0
  104. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/ParserTest.java +381 -0
  105. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/RepeatedFieldBuilderTest.java +190 -0
  106. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java +97 -0
  107. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/RopeByteStringTest.java +115 -0
  108. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/ServiceTest.java +320 -0
  109. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/SingleFieldBuilderTest.java +155 -0
  110. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/SmallSortedMapTest.java +420 -0
  111. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/TestBadIdentifiers.java +96 -0
  112. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/TestUtil.java +4124 -0
  113. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/TextFormatTest.java +994 -0
  114. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/UnknownFieldSetTest.java +653 -0
  115. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java +227 -0
  116. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/WireFormatTest.java +606 -0
  117. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/lazy_fields_lite.proto +61 -0
  118. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/lite_equals_and_hash.proto +55 -0
  119. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/multiple_files_test.proto +77 -0
  120. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/nested_builders_test.proto +53 -0
  121. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/nested_extension.proto +46 -0
  122. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/nested_extension_lite.proto +48 -0
  123. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/non_nested_extension.proto +49 -0
  124. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/non_nested_extension_lite.proto +50 -0
  125. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/outer_class_name_test.proto +38 -0
  126. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/outer_class_name_test2.proto +42 -0
  127. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/outer_class_name_test3.proto +43 -0
  128. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_bad_identifiers.proto +157 -0
  129. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_check_utf8.proto +50 -0
  130. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_check_utf8_size.proto +51 -0
  131. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_custom_options.proto +43 -0
  132. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_extra_interfaces.proto +60 -0
  133. data/ext/protoc/protobuf/m4/ac_system_extensions.m4 +37 -0
  134. data/ext/protoc/protobuf/m4/acx_check_suncc.m4 +75 -0
  135. data/ext/protoc/protobuf/m4/acx_pthread.m4 +397 -0
  136. data/ext/protoc/protobuf/m4/stl_hash.m4 +72 -0
  137. data/ext/protoc/protobuf/more_tests/Makefile +41 -0
  138. data/ext/protoc/protobuf/post_process_dist.sh +60 -0
  139. data/ext/protoc/protobuf/protobuf-lite.pc.in +13 -0
  140. data/ext/protoc/protobuf/protobuf.pc.in +14 -0
  141. data/ext/protoc/protobuf/python/README.txt +105 -0
  142. data/ext/protoc/protobuf/python/ez_setup.py +284 -0
  143. data/ext/protoc/protobuf/python/google/__init__.py +1 -0
  144. data/ext/protoc/protobuf/python/google/protobuf/__init__.py +0 -0
  145. data/ext/protoc/protobuf/python/google/protobuf/descriptor.py +849 -0
  146. data/ext/protoc/protobuf/python/google/protobuf/descriptor_database.py +137 -0
  147. data/ext/protoc/protobuf/python/google/protobuf/descriptor_pool.py +643 -0
  148. data/ext/protoc/protobuf/python/google/protobuf/internal/__init__.py +0 -0
  149. data/ext/protoc/protobuf/python/google/protobuf/internal/api_implementation.cc +139 -0
  150. data/ext/protoc/protobuf/python/google/protobuf/internal/api_implementation.py +89 -0
  151. data/ext/protoc/protobuf/python/google/protobuf/internal/api_implementation_default_test.py +63 -0
  152. data/ext/protoc/protobuf/python/google/protobuf/internal/containers.py +269 -0
  153. data/ext/protoc/protobuf/python/google/protobuf/internal/cpp_message.py +663 -0
  154. data/ext/protoc/protobuf/python/google/protobuf/internal/decoder.py +831 -0
  155. data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_database_test.py +63 -0
  156. data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_pool_test.py +564 -0
  157. data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_pool_test1.proto +94 -0
  158. data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_pool_test2.proto +70 -0
  159. data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_python_test.py +54 -0
  160. data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_test.py +669 -0
  161. data/ext/protoc/protobuf/python/google/protobuf/internal/encoder.py +788 -0
  162. data/ext/protoc/protobuf/python/google/protobuf/internal/enum_type_wrapper.py +89 -0
  163. data/ext/protoc/protobuf/python/google/protobuf/internal/factory_test1.proto +57 -0
  164. data/ext/protoc/protobuf/python/google/protobuf/internal/factory_test2.proto +92 -0
  165. data/ext/protoc/protobuf/python/google/protobuf/internal/generator_test.py +343 -0
  166. data/ext/protoc/protobuf/python/google/protobuf/internal/message_factory_python_test.py +54 -0
  167. data/ext/protoc/protobuf/python/google/protobuf/internal/message_factory_test.py +131 -0
  168. data/ext/protoc/protobuf/python/google/protobuf/internal/message_listener.py +78 -0
  169. data/ext/protoc/protobuf/python/google/protobuf/internal/message_python_test.py +54 -0
  170. data/ext/protoc/protobuf/python/google/protobuf/internal/message_test.py +681 -0
  171. data/ext/protoc/protobuf/python/google/protobuf/internal/missing_enum_values.proto +50 -0
  172. data/ext/protoc/protobuf/python/google/protobuf/internal/more_extensions.proto +58 -0
  173. data/ext/protoc/protobuf/python/google/protobuf/internal/more_extensions_dynamic.proto +49 -0
  174. data/ext/protoc/protobuf/python/google/protobuf/internal/more_messages.proto +51 -0
  175. data/ext/protoc/protobuf/python/google/protobuf/internal/python_message.py +1251 -0
  176. data/ext/protoc/protobuf/python/google/protobuf/internal/reflection_test.py +2934 -0
  177. data/ext/protoc/protobuf/python/google/protobuf/internal/service_reflection_test.py +136 -0
  178. data/ext/protoc/protobuf/python/google/protobuf/internal/symbol_database_test.py +120 -0
  179. data/ext/protoc/protobuf/python/google/protobuf/internal/test_bad_identifiers.proto +52 -0
  180. data/ext/protoc/protobuf/python/google/protobuf/internal/test_util.py +662 -0
  181. data/ext/protoc/protobuf/python/google/protobuf/internal/text_encoding_test.py +68 -0
  182. data/ext/protoc/protobuf/python/google/protobuf/internal/text_format_test.py +743 -0
  183. data/ext/protoc/protobuf/python/google/protobuf/internal/type_checkers.py +328 -0
  184. data/ext/protoc/protobuf/python/google/protobuf/internal/unknown_fields_test.py +231 -0
  185. data/ext/protoc/protobuf/python/google/protobuf/internal/wire_format.py +268 -0
  186. data/ext/protoc/protobuf/python/google/protobuf/internal/wire_format_test.py +253 -0
  187. data/ext/protoc/protobuf/python/google/protobuf/message.py +284 -0
  188. data/ext/protoc/protobuf/python/google/protobuf/message_factory.py +155 -0
  189. data/ext/protoc/protobuf/python/google/protobuf/pyext/README +6 -0
  190. data/ext/protoc/protobuf/python/google/protobuf/pyext/__init__.py +0 -0
  191. data/ext/protoc/protobuf/python/google/protobuf/pyext/cpp_message.py +61 -0
  192. data/ext/protoc/protobuf/python/google/protobuf/pyext/descriptor.cc +357 -0
  193. data/ext/protoc/protobuf/python/google/protobuf/pyext/descriptor.h +96 -0
  194. data/ext/protoc/protobuf/python/google/protobuf/pyext/descriptor_cpp2_test.py +58 -0
  195. data/ext/protoc/protobuf/python/google/protobuf/pyext/extension_dict.cc +338 -0
  196. data/ext/protoc/protobuf/python/google/protobuf/pyext/extension_dict.h +123 -0
  197. data/ext/protoc/protobuf/python/google/protobuf/pyext/message.cc +2561 -0
  198. data/ext/protoc/protobuf/python/google/protobuf/pyext/message.h +305 -0
  199. data/ext/protoc/protobuf/python/google/protobuf/pyext/message_factory_cpp2_test.py +56 -0
  200. data/ext/protoc/protobuf/python/google/protobuf/pyext/proto2_api_test.proto +38 -0
  201. data/ext/protoc/protobuf/python/google/protobuf/pyext/python.proto +66 -0
  202. data/ext/protoc/protobuf/python/google/protobuf/pyext/python_protobuf.h +57 -0
  203. data/ext/protoc/protobuf/python/google/protobuf/pyext/reflection_cpp2_generated_test.py +94 -0
  204. data/ext/protoc/protobuf/python/google/protobuf/pyext/repeated_composite_container.cc +763 -0
  205. data/ext/protoc/protobuf/python/google/protobuf/pyext/repeated_composite_container.h +172 -0
  206. data/ext/protoc/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc +825 -0
  207. data/ext/protoc/protobuf/python/google/protobuf/pyext/repeated_scalar_container.h +112 -0
  208. data/ext/protoc/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h +95 -0
  209. data/ext/protoc/protobuf/python/google/protobuf/reflection.py +205 -0
  210. data/ext/protoc/protobuf/python/google/protobuf/service.py +226 -0
  211. data/ext/protoc/protobuf/python/google/protobuf/service_reflection.py +284 -0
  212. data/ext/protoc/protobuf/python/google/protobuf/symbol_database.py +185 -0
  213. data/ext/protoc/protobuf/python/google/protobuf/text_encoding.py +110 -0
  214. data/ext/protoc/protobuf/python/google/protobuf/text_format.py +873 -0
  215. data/ext/protoc/protobuf/python/mox.py +1401 -0
  216. data/ext/protoc/protobuf/python/setup.py +201 -0
  217. data/ext/protoc/protobuf/python/stubout.py +140 -0
  218. data/ext/protoc/protobuf/src/Makefile.am +418 -0
  219. data/ext/protoc/protobuf/src/google/protobuf/SEBS +240 -0
  220. data/ext/protoc/protobuf/src/google/protobuf/compiler/code_generator.cc +84 -0
  221. data/ext/protoc/protobuf/src/google/protobuf/compiler/code_generator.h +145 -0
  222. data/ext/protoc/protobuf/src/google/protobuf/compiler/command_line_interface.cc +1603 -0
  223. data/ext/protoc/protobuf/src/google/protobuf/compiler/command_line_interface.h +378 -0
  224. data/ext/protoc/protobuf/src/google/protobuf/compiler/command_line_interface_unittest.cc +1654 -0
  225. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc +158 -0
  226. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_enum.cc +288 -0
  227. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_enum.h +103 -0
  228. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_enum_field.cc +431 -0
  229. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_enum_field.h +122 -0
  230. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_extension.cc +210 -0
  231. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_extension.h +86 -0
  232. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_field.cc +166 -0
  233. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_field.h +185 -0
  234. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_file.cc +665 -0
  235. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_file.h +99 -0
  236. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_generator.cc +125 -0
  237. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_generator.h +72 -0
  238. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_helpers.cc +494 -0
  239. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_helpers.h +206 -0
  240. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_message.cc +2645 -0
  241. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_message.h +175 -0
  242. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_message_field.cc +375 -0
  243. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_message_field.h +121 -0
  244. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_options.h +58 -0
  245. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc +123 -0
  246. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc +451 -0
  247. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.h +123 -0
  248. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_service.cc +334 -0
  249. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_service.h +118 -0
  250. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_string_field.cc +642 -0
  251. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_string_field.h +127 -0
  252. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto +132 -0
  253. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_unittest.cc +2074 -0
  254. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_unittest.h +51 -0
  255. data/ext/protoc/protobuf/src/google/protobuf/compiler/importer.cc +480 -0
  256. data/ext/protoc/protobuf/src/google/protobuf/compiler/importer.h +317 -0
  257. data/ext/protoc/protobuf/src/google/protobuf/compiler/importer_unittest.cc +617 -0
  258. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_context.cc +195 -0
  259. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_context.h +95 -0
  260. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_doc_comment.cc +233 -0
  261. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_doc_comment.h +69 -0
  262. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc +67 -0
  263. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_enum.cc +333 -0
  264. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_enum.h +99 -0
  265. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_enum_field.cc +778 -0
  266. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_enum_field.h +158 -0
  267. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_extension.cc +207 -0
  268. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_extension.h +109 -0
  269. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_field.cc +213 -0
  270. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_field.h +162 -0
  271. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_file.cc +534 -0
  272. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_file.h +115 -0
  273. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_generator.cc +158 -0
  274. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_generator.h +72 -0
  275. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_generator_factory.cc +77 -0
  276. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_generator_factory.h +101 -0
  277. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_helpers.cc +737 -0
  278. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_helpers.h +322 -0
  279. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field.cc +826 -0
  280. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field.h +121 -0
  281. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_message.cc +1666 -0
  282. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_message.h +140 -0
  283. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_message_field.cc +1343 -0
  284. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_message_field.h +173 -0
  285. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_name_resolver.cc +266 -0
  286. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_name_resolver.h +124 -0
  287. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_plugin_unittest.cc +124 -0
  288. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_primitive_field.cc +877 -0
  289. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_primitive_field.h +160 -0
  290. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_service.cc +473 -0
  291. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_service.h +135 -0
  292. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_shared_code_generator.cc +201 -0
  293. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_shared_code_generator.h +90 -0
  294. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_string_field.cc +1056 -0
  295. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_string_field.h +160 -0
  296. data/ext/protoc/protobuf/src/google/protobuf/compiler/main.cc +61 -0
  297. data/ext/protoc/protobuf/src/google/protobuf/compiler/mock_code_generator.cc +240 -0
  298. data/ext/protoc/protobuf/src/google/protobuf/compiler/mock_code_generator.h +117 -0
  299. data/ext/protoc/protobuf/src/google/protobuf/compiler/package_info.h +64 -0
  300. data/ext/protoc/protobuf/src/google/protobuf/compiler/parser.cc +1750 -0
  301. data/ext/protoc/protobuf/src/google/protobuf/compiler/parser.h +522 -0
  302. data/ext/protoc/protobuf/src/google/protobuf/compiler/parser_unittest.cc +2612 -0
  303. data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.cc +163 -0
  304. data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.h +72 -0
  305. data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.pb.cc +1148 -0
  306. data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.pb.h +897 -0
  307. data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.proto +147 -0
  308. data/ext/protoc/protobuf/src/google/protobuf/compiler/python/python_generator.cc +1262 -0
  309. data/ext/protoc/protobuf/src/google/protobuf/compiler/python/python_generator.h +166 -0
  310. data/ext/protoc/protobuf/src/google/protobuf/compiler/python/python_plugin_unittest.cc +118 -0
  311. data/ext/protoc/protobuf/src/google/protobuf/compiler/subprocess.cc +463 -0
  312. data/ext/protoc/protobuf/src/google/protobuf/compiler/subprocess.h +108 -0
  313. data/ext/protoc/protobuf/src/google/protobuf/compiler/test_plugin.cc +51 -0
  314. data/ext/protoc/protobuf/src/google/protobuf/compiler/zip_output_unittest.sh +91 -0
  315. data/ext/protoc/protobuf/src/google/protobuf/compiler/zip_writer.cc +218 -0
  316. data/ext/protoc/protobuf/src/google/protobuf/compiler/zip_writer.h +93 -0
  317. data/ext/protoc/protobuf/src/google/protobuf/descriptor.cc +5420 -0
  318. data/ext/protoc/protobuf/src/google/protobuf/descriptor.h +1691 -0
  319. data/ext/protoc/protobuf/src/google/protobuf/descriptor.pb.cc +9135 -0
  320. data/ext/protoc/protobuf/src/google/protobuf/descriptor.pb.h +6761 -0
  321. data/ext/protoc/protobuf/src/google/protobuf/descriptor.proto +687 -0
  322. data/ext/protoc/protobuf/src/google/protobuf/descriptor_database.cc +543 -0
  323. data/ext/protoc/protobuf/src/google/protobuf/descriptor_database.h +369 -0
  324. data/ext/protoc/protobuf/src/google/protobuf/descriptor_database_unittest.cc +748 -0
  325. data/ext/protoc/protobuf/src/google/protobuf/descriptor_pb2_test.py +54 -0
  326. data/ext/protoc/protobuf/src/google/protobuf/descriptor_unittest.cc +5501 -0
  327. data/ext/protoc/protobuf/src/google/protobuf/dynamic_message.cc +764 -0
  328. data/ext/protoc/protobuf/src/google/protobuf/dynamic_message.h +148 -0
  329. data/ext/protoc/protobuf/src/google/protobuf/dynamic_message_unittest.cc +230 -0
  330. data/ext/protoc/protobuf/src/google/protobuf/extension_set.cc +1663 -0
  331. data/ext/protoc/protobuf/src/google/protobuf/extension_set.h +1234 -0
  332. data/ext/protoc/protobuf/src/google/protobuf/extension_set_heavy.cc +734 -0
  333. data/ext/protoc/protobuf/src/google/protobuf/extension_set_unittest.cc +1095 -0
  334. data/ext/protoc/protobuf/src/google/protobuf/generated_enum_reflection.h +91 -0
  335. data/ext/protoc/protobuf/src/google/protobuf/generated_message_reflection.cc +1683 -0
  336. data/ext/protoc/protobuf/src/google/protobuf/generated_message_reflection.h +504 -0
  337. data/ext/protoc/protobuf/src/google/protobuf/generated_message_reflection_unittest.cc +795 -0
  338. data/ext/protoc/protobuf/src/google/protobuf/generated_message_util.cc +65 -0
  339. data/ext/protoc/protobuf/src/google/protobuf/generated_message_util.h +113 -0
  340. data/ext/protoc/protobuf/src/google/protobuf/io/coded_stream.cc +914 -0
  341. data/ext/protoc/protobuf/src/google/protobuf/io/coded_stream.h +1220 -0
  342. data/ext/protoc/protobuf/src/google/protobuf/io/coded_stream_inl.h +69 -0
  343. data/ext/protoc/protobuf/src/google/protobuf/io/coded_stream_unittest.cc +1378 -0
  344. data/ext/protoc/protobuf/src/google/protobuf/io/gzip_stream.cc +326 -0
  345. data/ext/protoc/protobuf/src/google/protobuf/io/gzip_stream.h +209 -0
  346. data/ext/protoc/protobuf/src/google/protobuf/io/gzip_stream_unittest.sh +44 -0
  347. data/ext/protoc/protobuf/src/google/protobuf/io/package_info.h +54 -0
  348. data/ext/protoc/protobuf/src/google/protobuf/io/printer.cc +198 -0
  349. data/ext/protoc/protobuf/src/google/protobuf/io/printer.h +136 -0
  350. data/ext/protoc/protobuf/src/google/protobuf/io/printer_unittest.cc +285 -0
  351. data/ext/protoc/protobuf/src/google/protobuf/io/strtod.cc +113 -0
  352. data/ext/protoc/protobuf/src/google/protobuf/io/strtod.h +50 -0
  353. data/ext/protoc/protobuf/src/google/protobuf/io/tokenizer.cc +1127 -0
  354. data/ext/protoc/protobuf/src/google/protobuf/io/tokenizer.h +402 -0
  355. data/ext/protoc/protobuf/src/google/protobuf/io/tokenizer_unittest.cc +999 -0
  356. data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream.cc +57 -0
  357. data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream.h +248 -0
  358. data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_impl.cc +473 -0
  359. data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_impl.h +358 -0
  360. data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.cc +405 -0
  361. data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h +354 -0
  362. data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_unittest.cc +965 -0
  363. data/ext/protoc/protobuf/src/google/protobuf/lite_unittest.cc +350 -0
  364. data/ext/protoc/protobuf/src/google/protobuf/message.cc +358 -0
  365. data/ext/protoc/protobuf/src/google/protobuf/message.h +866 -0
  366. data/ext/protoc/protobuf/src/google/protobuf/message_lite.cc +335 -0
  367. data/ext/protoc/protobuf/src/google/protobuf/message_lite.h +247 -0
  368. data/ext/protoc/protobuf/src/google/protobuf/message_unittest.cc +427 -0
  369. data/ext/protoc/protobuf/src/google/protobuf/package_info.h +64 -0
  370. data/ext/protoc/protobuf/src/google/protobuf/reflection_ops.cc +269 -0
  371. data/ext/protoc/protobuf/src/google/protobuf/reflection_ops.h +81 -0
  372. data/ext/protoc/protobuf/src/google/protobuf/reflection_ops_unittest.cc +475 -0
  373. data/ext/protoc/protobuf/src/google/protobuf/repeated_field.cc +87 -0
  374. data/ext/protoc/protobuf/src/google/protobuf/repeated_field.h +1603 -0
  375. data/ext/protoc/protobuf/src/google/protobuf/repeated_field_reflection_unittest.cc +195 -0
  376. data/ext/protoc/protobuf/src/google/protobuf/repeated_field_unittest.cc +1442 -0
  377. data/ext/protoc/protobuf/src/google/protobuf/service.cc +46 -0
  378. data/ext/protoc/protobuf/src/google/protobuf/service.h +291 -0
  379. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops.h +227 -0
  380. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_arm64_gcc.h +325 -0
  381. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_arm_gcc.h +151 -0
  382. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_arm_qnx.h +146 -0
  383. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_atomicword_compat.h +122 -0
  384. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h +137 -0
  385. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_macosx.h +225 -0
  386. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_mips_gcc.h +313 -0
  387. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_pnacl.h +73 -0
  388. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_solaris.h +188 -0
  389. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_tsan.h +219 -0
  390. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc +137 -0
  391. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_gcc.h +293 -0
  392. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc +112 -0
  393. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_msvc.h +150 -0
  394. data/ext/protoc/protobuf/src/google/protobuf/stubs/common.cc +395 -0
  395. data/ext/protoc/protobuf/src/google/protobuf/stubs/common.h +1226 -0
  396. data/ext/protoc/protobuf/src/google/protobuf/stubs/common_unittest.cc +357 -0
  397. data/ext/protoc/protobuf/src/google/protobuf/stubs/hash.h +232 -0
  398. data/ext/protoc/protobuf/src/google/protobuf/stubs/map_util.h +771 -0
  399. data/ext/protoc/protobuf/src/google/protobuf/stubs/once.cc +99 -0
  400. data/ext/protoc/protobuf/src/google/protobuf/stubs/once.h +166 -0
  401. data/ext/protoc/protobuf/src/google/protobuf/stubs/once_unittest.cc +253 -0
  402. data/ext/protoc/protobuf/src/google/protobuf/stubs/platform_macros.h +103 -0
  403. data/ext/protoc/protobuf/src/google/protobuf/stubs/shared_ptr.h +470 -0
  404. data/ext/protoc/protobuf/src/google/protobuf/stubs/stl_util.h +121 -0
  405. data/ext/protoc/protobuf/src/google/protobuf/stubs/stringprintf.cc +175 -0
  406. data/ext/protoc/protobuf/src/google/protobuf/stubs/stringprintf.h +76 -0
  407. data/ext/protoc/protobuf/src/google/protobuf/stubs/stringprintf_unittest.cc +152 -0
  408. data/ext/protoc/protobuf/src/google/protobuf/stubs/structurally_valid.cc +536 -0
  409. data/ext/protoc/protobuf/src/google/protobuf/stubs/structurally_valid_unittest.cc +40 -0
  410. data/ext/protoc/protobuf/src/google/protobuf/stubs/strutil.cc +1279 -0
  411. data/ext/protoc/protobuf/src/google/protobuf/stubs/strutil.h +562 -0
  412. data/ext/protoc/protobuf/src/google/protobuf/stubs/strutil_unittest.cc +73 -0
  413. data/ext/protoc/protobuf/src/google/protobuf/stubs/substitute.cc +134 -0
  414. data/ext/protoc/protobuf/src/google/protobuf/stubs/substitute.h +170 -0
  415. data/ext/protoc/protobuf/src/google/protobuf/stubs/template_util.h +138 -0
  416. data/ext/protoc/protobuf/src/google/protobuf/stubs/template_util_unittest.cc +130 -0
  417. data/ext/protoc/protobuf/src/google/protobuf/stubs/type_traits.h +336 -0
  418. data/ext/protoc/protobuf/src/google/protobuf/stubs/type_traits_unittest.cc +628 -0
  419. data/ext/protoc/protobuf/src/google/protobuf/test_util.cc +3345 -0
  420. data/ext/protoc/protobuf/src/google/protobuf/test_util.h +215 -0
  421. data/ext/protoc/protobuf/src/google/protobuf/test_util_lite.cc +1585 -0
  422. data/ext/protoc/protobuf/src/google/protobuf/test_util_lite.h +101 -0
  423. data/ext/protoc/protobuf/src/google/protobuf/testdata/bad_utf8_string +1 -0
  424. data/ext/protoc/protobuf/src/google/protobuf/testdata/golden_message +0 -0
  425. data/ext/protoc/protobuf/src/google/protobuf/testdata/golden_message_oneof_implemented +0 -0
  426. data/ext/protoc/protobuf/src/google/protobuf/testdata/golden_packed_fields_message +0 -0
  427. data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_data.txt +134 -0
  428. data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_data_oneof_implemented.txt +129 -0
  429. data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_data_pointy.txt +134 -0
  430. data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_data_pointy_oneof.txt +129 -0
  431. data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_extensions_data.txt +134 -0
  432. data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_extensions_data_pointy.txt +134 -0
  433. data/ext/protoc/protobuf/src/google/protobuf/testing/file.cc +194 -0
  434. data/ext/protoc/protobuf/src/google/protobuf/testing/file.h +97 -0
  435. data/ext/protoc/protobuf/src/google/protobuf/testing/googletest.cc +255 -0
  436. data/ext/protoc/protobuf/src/google/protobuf/testing/googletest.h +102 -0
  437. data/ext/protoc/protobuf/src/google/protobuf/testing/zcgunzip.cc +73 -0
  438. data/ext/protoc/protobuf/src/google/protobuf/testing/zcgzip.cc +79 -0
  439. data/ext/protoc/protobuf/src/google/protobuf/text_format.cc +1746 -0
  440. data/ext/protoc/protobuf/src/google/protobuf/text_format.h +473 -0
  441. data/ext/protoc/protobuf/src/google/protobuf/text_format_unittest.cc +1479 -0
  442. data/ext/protoc/protobuf/src/google/protobuf/unittest.proto +861 -0
  443. data/ext/protoc/protobuf/src/google/protobuf/unittest_custom_options.proto +393 -0
  444. data/ext/protoc/protobuf/src/google/protobuf/unittest_embed_optimize_for.proto +50 -0
  445. data/ext/protoc/protobuf/src/google/protobuf/unittest_empty.proto +37 -0
  446. data/ext/protoc/protobuf/src/google/protobuf/unittest_enormous_descriptor.proto +1046 -0
  447. data/ext/protoc/protobuf/src/google/protobuf/unittest_import.proto +64 -0
  448. data/ext/protoc/protobuf/src/google/protobuf/unittest_import_lite.proto +51 -0
  449. data/ext/protoc/protobuf/src/google/protobuf/unittest_import_public.proto +40 -0
  450. data/ext/protoc/protobuf/src/google/protobuf/unittest_import_public_lite.proto +42 -0
  451. data/ext/protoc/protobuf/src/google/protobuf/unittest_lite.proto +384 -0
  452. data/ext/protoc/protobuf/src/google/protobuf/unittest_lite_imports_nonlite.proto +43 -0
  453. data/ext/protoc/protobuf/src/google/protobuf/unittest_mset.proto +83 -0
  454. data/ext/protoc/protobuf/src/google/protobuf/unittest_no_generic_services.proto +53 -0
  455. data/ext/protoc/protobuf/src/google/protobuf/unittest_optimize_for.proto +66 -0
  456. data/ext/protoc/protobuf/src/google/protobuf/unknown_field_set.cc +265 -0
  457. data/ext/protoc/protobuf/src/google/protobuf/unknown_field_set.h +318 -0
  458. data/ext/protoc/protobuf/src/google/protobuf/unknown_field_set_unittest.cc +599 -0
  459. data/ext/protoc/protobuf/src/google/protobuf/wire_format.cc +1101 -0
  460. data/ext/protoc/protobuf/src/google/protobuf/wire_format.h +336 -0
  461. data/ext/protoc/protobuf/src/google/protobuf/wire_format_lite.cc +471 -0
  462. data/ext/protoc/protobuf/src/google/protobuf/wire_format_lite.h +661 -0
  463. data/ext/protoc/protobuf/src/google/protobuf/wire_format_lite_inl.h +860 -0
  464. data/ext/protoc/protobuf/src/google/protobuf/wire_format_unittest.cc +1120 -0
  465. data/ext/protoc/protobuf/src/solaris/libstdc++.la +51 -0
  466. data/ext/protoc/protobuf/vsprojects/config.h +29 -0
  467. data/ext/protoc/protobuf/vsprojects/convert2008to2005.sh +20 -0
  468. data/ext/protoc/protobuf/vsprojects/extract_includes.bat +50 -0
  469. data/ext/protoc/protobuf/vsprojects/libprotobuf-lite.vcproj +302 -0
  470. data/ext/protoc/protobuf/vsprojects/libprotobuf.vcproj +470 -0
  471. data/ext/protoc/protobuf/vsprojects/libprotoc.vcproj +466 -0
  472. data/ext/protoc/protobuf/vsprojects/lite-test.vcproj +305 -0
  473. data/ext/protoc/protobuf/vsprojects/protobuf.sln +92 -0
  474. data/ext/protoc/protobuf/vsprojects/protoc.vcproj +192 -0
  475. data/ext/protoc/protobuf/vsprojects/readme.txt +114 -0
  476. data/ext/protoc/protobuf/vsprojects/test_plugin.vcproj +209 -0
  477. data/ext/protoc/protobuf/vsprojects/tests.vcproj +681 -0
  478. data/lib/protoc/version.rb +1 -1
  479. metadata +480 -3
@@ -0,0 +1,378 @@
1
+ // Protocol Buffers - Google's data interchange format
2
+ // Copyright 2008 Google Inc. All rights reserved.
3
+ // https://developers.google.com/protocol-buffers/
4
+ //
5
+ // Redistribution and use in source and binary forms, with or without
6
+ // modification, are permitted provided that the following conditions are
7
+ // met:
8
+ //
9
+ // * Redistributions of source code must retain the above copyright
10
+ // notice, this list of conditions and the following disclaimer.
11
+ // * Redistributions in binary form must reproduce the above
12
+ // copyright notice, this list of conditions and the following disclaimer
13
+ // in the documentation and/or other materials provided with the
14
+ // distribution.
15
+ // * Neither the name of Google Inc. nor the names of its
16
+ // contributors may be used to endorse or promote products derived from
17
+ // this software without specific prior written permission.
18
+ //
19
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ // Author: kenton@google.com (Kenton Varda)
32
+ // Based on original Protocol Buffers design by
33
+ // Sanjay Ghemawat, Jeff Dean, and others.
34
+ //
35
+ // Implements the Protocol Compiler front-end such that it may be reused by
36
+ // custom compilers written to support other languages.
37
+
38
+ #ifndef GOOGLE_PROTOBUF_COMPILER_COMMAND_LINE_INTERFACE_H__
39
+ #define GOOGLE_PROTOBUF_COMPILER_COMMAND_LINE_INTERFACE_H__
40
+
41
+ #include <google/protobuf/stubs/common.h>
42
+ #include <string>
43
+ #include <vector>
44
+ #include <map>
45
+ #include <set>
46
+ #include <utility>
47
+
48
+ namespace google {
49
+ namespace protobuf {
50
+
51
+ class Descriptor; // descriptor.h
52
+ class DescriptorPool; // descriptor.h
53
+ class FileDescriptor; // descriptor.h
54
+ class FileDescriptorProto; // descriptor.pb.h
55
+ template<typename T> class RepeatedPtrField; // repeated_field.h
56
+
57
+ namespace compiler {
58
+
59
+ class CodeGenerator; // code_generator.h
60
+ class GeneratorContext; // code_generator.h
61
+ class DiskSourceTree; // importer.h
62
+
63
+ // This class implements the command-line interface to the protocol compiler.
64
+ // It is designed to make it very easy to create a custom protocol compiler
65
+ // supporting the languages of your choice. For example, if you wanted to
66
+ // create a custom protocol compiler binary which includes both the regular
67
+ // C++ support plus support for your own custom output "Foo", you would
68
+ // write a class "FooGenerator" which implements the CodeGenerator interface,
69
+ // then write a main() procedure like this:
70
+ //
71
+ // int main(int argc, char* argv[]) {
72
+ // google::protobuf::compiler::CommandLineInterface cli;
73
+ //
74
+ // // Support generation of C++ source and headers.
75
+ // google::protobuf::compiler::cpp::CppGenerator cpp_generator;
76
+ // cli.RegisterGenerator("--cpp_out", &cpp_generator,
77
+ // "Generate C++ source and header.");
78
+ //
79
+ // // Support generation of Foo code.
80
+ // FooGenerator foo_generator;
81
+ // cli.RegisterGenerator("--foo_out", &foo_generator,
82
+ // "Generate Foo file.");
83
+ //
84
+ // return cli.Run(argc, argv);
85
+ // }
86
+ //
87
+ // The compiler is invoked with syntax like:
88
+ // protoc --cpp_out=outdir --foo_out=outdir --proto_path=src src/foo.proto
89
+ //
90
+ // For a full description of the command-line syntax, invoke it with --help.
91
+ class LIBPROTOC_EXPORT CommandLineInterface {
92
+ public:
93
+ CommandLineInterface();
94
+ ~CommandLineInterface();
95
+
96
+ // Register a code generator for a language.
97
+ //
98
+ // Parameters:
99
+ // * flag_name: The command-line flag used to specify an output file of
100
+ // this type. The name must start with a '-'. If the name is longer
101
+ // than one letter, it must start with two '-'s.
102
+ // * generator: The CodeGenerator which will be called to generate files
103
+ // of this type.
104
+ // * help_text: Text describing this flag in the --help output.
105
+ //
106
+ // Some generators accept extra parameters. You can specify this parameter
107
+ // on the command-line by placing it before the output directory, separated
108
+ // by a colon:
109
+ // protoc --foo_out=enable_bar:outdir
110
+ // The text before the colon is passed to CodeGenerator::Generate() as the
111
+ // "parameter".
112
+ void RegisterGenerator(const string& flag_name,
113
+ CodeGenerator* generator,
114
+ const string& help_text);
115
+
116
+ // Register a code generator for a language.
117
+ // Besides flag_name you can specify another option_flag_name that could be
118
+ // used to pass extra parameters to the registered code generator.
119
+ // Suppose you have registered a generator by calling:
120
+ // command_line_interface.RegisterGenerator("--foo_out", "--foo_opt", ...)
121
+ // Then you could invoke the compiler with a command like:
122
+ // protoc --foo_out=enable_bar:outdir --foo_opt=enable_baz
123
+ // This will pass "enable_bar,enable_baz" as the parameter to the generator.
124
+ void RegisterGenerator(const string& flag_name,
125
+ const string& option_flag_name,
126
+ CodeGenerator* generator,
127
+ const string& help_text);
128
+
129
+ // Enables "plugins". In this mode, if a command-line flag ends with "_out"
130
+ // but does not match any registered generator, the compiler will attempt to
131
+ // find a "plugin" to implement the generator. Plugins are just executables.
132
+ // They should live somewhere in the PATH.
133
+ //
134
+ // The compiler determines the executable name to search for by concatenating
135
+ // exe_name_prefix with the unrecognized flag name, removing "_out". So, for
136
+ // example, if exe_name_prefix is "protoc-" and you pass the flag --foo_out,
137
+ // the compiler will try to run the program "protoc-foo".
138
+ //
139
+ // The plugin program should implement the following usage:
140
+ // plugin [--out=OUTDIR] [--parameter=PARAMETER] PROTO_FILES < DESCRIPTORS
141
+ // --out indicates the output directory (as passed to the --foo_out
142
+ // parameter); if omitted, the current directory should be used. --parameter
143
+ // gives the generator parameter, if any was provided. The PROTO_FILES list
144
+ // the .proto files which were given on the compiler command-line; these are
145
+ // the files for which the plugin is expected to generate output code.
146
+ // Finally, DESCRIPTORS is an encoded FileDescriptorSet (as defined in
147
+ // descriptor.proto). This is piped to the plugin's stdin. The set will
148
+ // include descriptors for all the files listed in PROTO_FILES as well as
149
+ // all files that they import. The plugin MUST NOT attempt to read the
150
+ // PROTO_FILES directly -- it must use the FileDescriptorSet.
151
+ //
152
+ // The plugin should generate whatever files are necessary, as code generators
153
+ // normally do. It should write the names of all files it generates to
154
+ // stdout. The names should be relative to the output directory, NOT absolute
155
+ // names or relative to the current directory. If any errors occur, error
156
+ // messages should be written to stderr. If an error is fatal, the plugin
157
+ // should exit with a non-zero exit code.
158
+ void AllowPlugins(const string& exe_name_prefix);
159
+
160
+ // Run the Protocol Compiler with the given command-line parameters.
161
+ // Returns the error code which should be returned by main().
162
+ //
163
+ // It may not be safe to call Run() in a multi-threaded environment because
164
+ // it calls strerror(). I'm not sure why you'd want to do this anyway.
165
+ int Run(int argc, const char* const argv[]);
166
+
167
+ // Call SetInputsAreCwdRelative(true) if the input files given on the command
168
+ // line should be interpreted relative to the proto import path specified
169
+ // using --proto_path or -I flags. Otherwise, input file names will be
170
+ // interpreted relative to the current working directory (or as absolute
171
+ // paths if they start with '/'), though they must still reside inside
172
+ // a directory given by --proto_path or the compiler will fail. The latter
173
+ // mode is generally more intuitive and easier to use, especially e.g. when
174
+ // defining implicit rules in Makefiles.
175
+ void SetInputsAreProtoPathRelative(bool enable) {
176
+ inputs_are_proto_path_relative_ = enable;
177
+ }
178
+
179
+ // Provides some text which will be printed when the --version flag is
180
+ // used. The version of libprotoc will also be printed on the next line
181
+ // after this text.
182
+ void SetVersionInfo(const string& text) {
183
+ version_info_ = text;
184
+ }
185
+
186
+
187
+ private:
188
+ // -----------------------------------------------------------------
189
+
190
+ class ErrorPrinter;
191
+ class GeneratorContextImpl;
192
+ class MemoryOutputStream;
193
+
194
+ // Clear state from previous Run().
195
+ void Clear();
196
+
197
+ // Remaps each file in input_files_ so that it is relative to one of the
198
+ // directories in proto_path_. Returns false if an error occurred. This
199
+ // is only used if inputs_are_proto_path_relative_ is false.
200
+ bool MakeInputsBeProtoPathRelative(
201
+ DiskSourceTree* source_tree);
202
+
203
+ // Return status for ParseArguments() and InterpretArgument().
204
+ enum ParseArgumentStatus {
205
+ PARSE_ARGUMENT_DONE_AND_CONTINUE,
206
+ PARSE_ARGUMENT_DONE_AND_EXIT,
207
+ PARSE_ARGUMENT_FAIL
208
+ };
209
+
210
+ // Parse all command-line arguments.
211
+ ParseArgumentStatus ParseArguments(int argc, const char* const argv[]);
212
+
213
+ // Parses a command-line argument into a name/value pair. Returns
214
+ // true if the next argument in the argv should be used as the value,
215
+ // false otherwise.
216
+ //
217
+ // Exmaples:
218
+ // "-Isrc/protos" ->
219
+ // name = "-I", value = "src/protos"
220
+ // "--cpp_out=src/foo.pb2.cc" ->
221
+ // name = "--cpp_out", value = "src/foo.pb2.cc"
222
+ // "foo.proto" ->
223
+ // name = "", value = "foo.proto"
224
+ bool ParseArgument(const char* arg, string* name, string* value);
225
+
226
+ // Interprets arguments parsed with ParseArgument.
227
+ ParseArgumentStatus InterpretArgument(const string& name,
228
+ const string& value);
229
+
230
+ // Print the --help text to stderr.
231
+ void PrintHelpText();
232
+
233
+ // Generate the given output file from the given input.
234
+ struct OutputDirective; // see below
235
+ bool GenerateOutput(const vector<const FileDescriptor*>& parsed_files,
236
+ const OutputDirective& output_directive,
237
+ GeneratorContext* generator_context);
238
+ bool GeneratePluginOutput(const vector<const FileDescriptor*>& parsed_files,
239
+ const string& plugin_name,
240
+ const string& parameter,
241
+ GeneratorContext* generator_context,
242
+ string* error);
243
+
244
+ // Implements --encode and --decode.
245
+ bool EncodeOrDecode(const DescriptorPool* pool);
246
+
247
+ // Implements the --descriptor_set_out option.
248
+ bool WriteDescriptorSet(const vector<const FileDescriptor*> parsed_files);
249
+
250
+ // Get all transitive dependencies of the given file (including the file
251
+ // itself), adding them to the given list of FileDescriptorProtos. The
252
+ // protos will be ordered such that every file is listed before any file that
253
+ // depends on it, so that you can call DescriptorPool::BuildFile() on them
254
+ // in order. Any files in *already_seen will not be added, and each file
255
+ // added will be inserted into *already_seen. If include_source_code_info is
256
+ // true then include the source code information in the FileDescriptorProtos.
257
+ static void GetTransitiveDependencies(
258
+ const FileDescriptor* file,
259
+ bool include_source_code_info,
260
+ set<const FileDescriptor*>* already_seen,
261
+ RepeatedPtrField<FileDescriptorProto>* output);
262
+
263
+ // Implements the --print_free_field_numbers. This function prints free field
264
+ // numbers into stdout for the message and it's nested message types in
265
+ // post-order, i.e. nested types first. Printed range are left-right
266
+ // inclusive, i.e. [a, b].
267
+ //
268
+ // Groups:
269
+ // For historical reasons, groups are considered to share the same
270
+ // field number space with the parent message, thus it will not print free
271
+ // field numbers for groups. The field numbers used in the groups are
272
+ // excluded in the free field numbers of the parent message.
273
+ //
274
+ // Extension Ranges:
275
+ // Extension ranges are considered ocuppied field numbers and they will not be
276
+ // listed as free numbers in the output.
277
+ void PrintFreeFieldNumbers(const Descriptor* descriptor);
278
+
279
+ // -----------------------------------------------------------------
280
+
281
+ // The name of the executable as invoked (i.e. argv[0]).
282
+ string executable_name_;
283
+
284
+ // Version info set with SetVersionInfo().
285
+ string version_info_;
286
+
287
+ // Registered generators.
288
+ struct GeneratorInfo {
289
+ string flag_name;
290
+ string option_flag_name;
291
+ CodeGenerator* generator;
292
+ string help_text;
293
+ };
294
+ typedef map<string, GeneratorInfo> GeneratorMap;
295
+ GeneratorMap generators_by_flag_name_;
296
+ GeneratorMap generators_by_option_name_;
297
+ // A map from generator names to the parameters specified using the option
298
+ // flag. For example, if the user invokes the compiler with:
299
+ // protoc --foo_out=outputdir --foo_opt=enable_bar ...
300
+ // Then there will be an entry ("--foo_out", "enable_bar") in this map.
301
+ map<string, string> generator_parameters_;
302
+
303
+ // See AllowPlugins(). If this is empty, plugins aren't allowed.
304
+ string plugin_prefix_;
305
+
306
+ // Maps specific plugin names to files. When executing a plugin, this map
307
+ // is searched first to find the plugin executable. If not found here, the
308
+ // PATH (or other OS-specific search strategy) is searched.
309
+ map<string, string> plugins_;
310
+
311
+ // Stuff parsed from command line.
312
+ enum Mode {
313
+ MODE_COMPILE, // Normal mode: parse .proto files and compile them.
314
+ MODE_ENCODE, // --encode: read text from stdin, write binary to stdout.
315
+ MODE_DECODE, // --decode: read binary from stdin, write text to stdout.
316
+ MODE_PRINT, // Print mode: print info of the given .proto files and exit.
317
+ };
318
+
319
+ Mode mode_;
320
+
321
+ enum PrintMode {
322
+ PRINT_NONE, // Not in MODE_PRINT
323
+ PRINT_FREE_FIELDS, // --print_free_fields
324
+ };
325
+
326
+ PrintMode print_mode_;
327
+
328
+ enum ErrorFormat {
329
+ ERROR_FORMAT_GCC, // GCC error output format (default).
330
+ ERROR_FORMAT_MSVS // Visual Studio output (--error_format=msvs).
331
+ };
332
+
333
+ ErrorFormat error_format_;
334
+
335
+ vector<pair<string, string> > proto_path_; // Search path for proto files.
336
+ vector<string> input_files_; // Names of the input proto files.
337
+
338
+ // output_directives_ lists all the files we are supposed to output and what
339
+ // generator to use for each.
340
+ struct OutputDirective {
341
+ string name; // E.g. "--foo_out"
342
+ CodeGenerator* generator; // NULL for plugins
343
+ string parameter;
344
+ string output_location;
345
+ };
346
+ vector<OutputDirective> output_directives_;
347
+
348
+ // When using --encode or --decode, this names the type we are encoding or
349
+ // decoding. (Empty string indicates --decode_raw.)
350
+ string codec_type_;
351
+
352
+ // If --descriptor_set_out was given, this is the filename to which the
353
+ // FileDescriptorSet should be written. Otherwise, empty.
354
+ string descriptor_set_name_;
355
+
356
+ // True if --include_imports was given, meaning that we should
357
+ // write all transitive dependencies to the DescriptorSet. Otherwise, only
358
+ // the .proto files listed on the command-line are added.
359
+ bool imports_in_descriptor_set_;
360
+
361
+ // True if --include_source_info was given, meaning that we should not strip
362
+ // SourceCodeInfo from the DescriptorSet.
363
+ bool source_info_in_descriptor_set_;
364
+
365
+ // Was the --disallow_services flag used?
366
+ bool disallow_services_;
367
+
368
+ // See SetInputsAreProtoPathRelative().
369
+ bool inputs_are_proto_path_relative_;
370
+
371
+ GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CommandLineInterface);
372
+ };
373
+
374
+ } // namespace compiler
375
+ } // namespace protobuf
376
+
377
+ } // namespace google
378
+ #endif // GOOGLE_PROTOBUF_COMPILER_COMMAND_LINE_INTERFACE_H__
@@ -0,0 +1,1654 @@
1
+ // Protocol Buffers - Google's data interchange format
2
+ // Copyright 2008 Google Inc. All rights reserved.
3
+ // https://developers.google.com/protocol-buffers/
4
+ //
5
+ // Redistribution and use in source and binary forms, with or without
6
+ // modification, are permitted provided that the following conditions are
7
+ // met:
8
+ //
9
+ // * Redistributions of source code must retain the above copyright
10
+ // notice, this list of conditions and the following disclaimer.
11
+ // * Redistributions in binary form must reproduce the above
12
+ // copyright notice, this list of conditions and the following disclaimer
13
+ // in the documentation and/or other materials provided with the
14
+ // distribution.
15
+ // * Neither the name of Google Inc. nor the names of its
16
+ // contributors may be used to endorse or promote products derived from
17
+ // this software without specific prior written permission.
18
+ //
19
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ // Author: kenton@google.com (Kenton Varda)
32
+ // Based on original Protocol Buffers design by
33
+ // Sanjay Ghemawat, Jeff Dean, and others.
34
+
35
+ #include <sys/types.h>
36
+ #include <sys/stat.h>
37
+ #include <fcntl.h>
38
+ #ifdef _MSC_VER
39
+ #include <io.h>
40
+ #else
41
+ #include <unistd.h>
42
+ #endif
43
+ #include <memory>
44
+ #include <vector>
45
+
46
+ #include <google/protobuf/descriptor.pb.h>
47
+ #include <google/protobuf/descriptor.h>
48
+ #include <google/protobuf/io/zero_copy_stream.h>
49
+ #include <google/protobuf/compiler/command_line_interface.h>
50
+ #include <google/protobuf/compiler/code_generator.h>
51
+ #include <google/protobuf/compiler/mock_code_generator.h>
52
+ #include <google/protobuf/compiler/subprocess.h>
53
+ #include <google/protobuf/io/printer.h>
54
+ #include <google/protobuf/unittest.pb.h>
55
+ #include <google/protobuf/testing/file.h>
56
+ #include <google/protobuf/stubs/strutil.h>
57
+ #include <google/protobuf/stubs/substitute.h>
58
+
59
+ #include <google/protobuf/testing/googletest.h>
60
+ #include <gtest/gtest.h>
61
+
62
+ namespace google {
63
+ namespace protobuf {
64
+ namespace compiler {
65
+
66
+ #if defined(_WIN32)
67
+ #ifndef STDIN_FILENO
68
+ #define STDIN_FILENO 0
69
+ #endif
70
+ #ifndef STDOUT_FILENO
71
+ #define STDOUT_FILENO 1
72
+ #endif
73
+ #ifndef F_OK
74
+ #define F_OK 00 // not defined by MSVC for whatever reason
75
+ #endif
76
+ #endif
77
+
78
+ namespace {
79
+
80
+ class CommandLineInterfaceTest : public testing::Test {
81
+ protected:
82
+ virtual void SetUp();
83
+ virtual void TearDown();
84
+
85
+ // Runs the CommandLineInterface with the given command line. The
86
+ // command is automatically split on spaces, and the string "$tmpdir"
87
+ // is replaced with TestTempDir().
88
+ void Run(const string& command);
89
+
90
+ // -----------------------------------------------------------------
91
+ // Methods to set up the test (called before Run()).
92
+
93
+ class NullCodeGenerator;
94
+
95
+ // Normally plugins are allowed for all tests. Call this to explicitly
96
+ // disable them.
97
+ void DisallowPlugins() { disallow_plugins_ = true; }
98
+
99
+ // Create a temp file within temp_directory_ with the given name.
100
+ // The containing directory is also created if necessary.
101
+ void CreateTempFile(const string& name, const string& contents);
102
+
103
+ // Create a subdirectory within temp_directory_.
104
+ void CreateTempDir(const string& name);
105
+
106
+ void SetInputsAreProtoPathRelative(bool enable) {
107
+ cli_.SetInputsAreProtoPathRelative(enable);
108
+ }
109
+
110
+ // -----------------------------------------------------------------
111
+ // Methods to check the test results (called after Run()).
112
+
113
+ // Checks that no text was written to stderr during Run(), and Run()
114
+ // returned 0.
115
+ void ExpectNoErrors();
116
+
117
+ // Checks that Run() returned non-zero and the stderr output is exactly
118
+ // the text given. expected_test may contain references to "$tmpdir",
119
+ // which will be replaced by the temporary directory path.
120
+ void ExpectErrorText(const string& expected_text);
121
+
122
+ // Checks that Run() returned non-zero and the stderr contains the given
123
+ // substring.
124
+ void ExpectErrorSubstring(const string& expected_substring);
125
+
126
+ // Like ExpectErrorSubstring, but checks that Run() returned zero.
127
+ void ExpectErrorSubstringWithZeroReturnCode(
128
+ const string& expected_substring);
129
+
130
+ // Checks that the captured stdout is the same as the expected_text.
131
+ void ExpectCapturedStdout(const string& expected_text);
132
+
133
+ // Returns true if ExpectErrorSubstring(expected_substring) would pass, but
134
+ // does not fail otherwise.
135
+ bool HasAlternateErrorSubstring(const string& expected_substring);
136
+
137
+ // Checks that MockCodeGenerator::Generate() was called in the given
138
+ // context (or the generator in test_plugin.cc, which produces the same
139
+ // output). That is, this tests if the generator with the given name
140
+ // was called with the given parameter and proto file and produced the
141
+ // given output file. This is checked by reading the output file and
142
+ // checking that it contains the content that MockCodeGenerator would
143
+ // generate given these inputs. message_name is the name of the first
144
+ // message that appeared in the proto file; this is just to make extra
145
+ // sure that the correct file was parsed.
146
+ void ExpectGenerated(const string& generator_name,
147
+ const string& parameter,
148
+ const string& proto_name,
149
+ const string& message_name);
150
+ void ExpectGenerated(const string& generator_name,
151
+ const string& parameter,
152
+ const string& proto_name,
153
+ const string& message_name,
154
+ const string& output_directory);
155
+ void ExpectGeneratedWithMultipleInputs(const string& generator_name,
156
+ const string& all_proto_names,
157
+ const string& proto_name,
158
+ const string& message_name);
159
+ void ExpectGeneratedWithInsertions(const string& generator_name,
160
+ const string& parameter,
161
+ const string& insertions,
162
+ const string& proto_name,
163
+ const string& message_name);
164
+
165
+ void ExpectNullCodeGeneratorCalled(const string& parameter);
166
+
167
+ void ReadDescriptorSet(const string& filename,
168
+ FileDescriptorSet* descriptor_set);
169
+
170
+ private:
171
+ // The object we are testing.
172
+ CommandLineInterface cli_;
173
+
174
+ // Was DisallowPlugins() called?
175
+ bool disallow_plugins_;
176
+
177
+ // We create a directory within TestTempDir() in order to add extra
178
+ // protection against accidentally deleting user files (since we recursively
179
+ // delete this directory during the test). This is the full path of that
180
+ // directory.
181
+ string temp_directory_;
182
+
183
+ // The result of Run().
184
+ int return_code_;
185
+
186
+ // The captured stderr output.
187
+ string error_text_;
188
+
189
+ // The captured stdout.
190
+ string captured_stdout_;
191
+
192
+ // Pointers which need to be deleted later.
193
+ vector<CodeGenerator*> mock_generators_to_delete_;
194
+
195
+ NullCodeGenerator* null_generator_;
196
+ };
197
+
198
+ class CommandLineInterfaceTest::NullCodeGenerator : public CodeGenerator {
199
+ public:
200
+ NullCodeGenerator() : called_(false) {}
201
+ ~NullCodeGenerator() {}
202
+
203
+ mutable bool called_;
204
+ mutable string parameter_;
205
+
206
+ // implements CodeGenerator ----------------------------------------
207
+ bool Generate(const FileDescriptor* file,
208
+ const string& parameter,
209
+ GeneratorContext* context,
210
+ string* error) const {
211
+ called_ = true;
212
+ parameter_ = parameter;
213
+ return true;
214
+ }
215
+ };
216
+
217
+ // ===================================================================
218
+
219
+ void CommandLineInterfaceTest::SetUp() {
220
+ // Most of these tests were written before this option was added, so we
221
+ // run with the option on (which used to be the only way) except in certain
222
+ // tests where we turn it off.
223
+ cli_.SetInputsAreProtoPathRelative(true);
224
+
225
+ temp_directory_ = TestTempDir() + "/proto2_cli_test_temp";
226
+
227
+ // If the temp directory already exists, it must be left over from a
228
+ // previous run. Delete it.
229
+ if (File::Exists(temp_directory_)) {
230
+ File::DeleteRecursively(temp_directory_, NULL, NULL);
231
+ }
232
+
233
+ // Create the temp directory.
234
+ GOOGLE_CHECK_OK(File::CreateDir(temp_directory_, 0777));
235
+
236
+ // Register generators.
237
+ CodeGenerator* generator = new MockCodeGenerator("test_generator");
238
+ mock_generators_to_delete_.push_back(generator);
239
+ cli_.RegisterGenerator("--test_out", "--test_opt", generator, "Test output.");
240
+ cli_.RegisterGenerator("-t", generator, "Test output.");
241
+
242
+ generator = new MockCodeGenerator("alt_generator");
243
+ mock_generators_to_delete_.push_back(generator);
244
+ cli_.RegisterGenerator("--alt_out", generator, "Alt output.");
245
+
246
+ generator = null_generator_ = new NullCodeGenerator();
247
+ mock_generators_to_delete_.push_back(generator);
248
+ cli_.RegisterGenerator("--null_out", generator, "Null output.");
249
+
250
+ disallow_plugins_ = false;
251
+ }
252
+
253
+ void CommandLineInterfaceTest::TearDown() {
254
+ // Delete the temp directory.
255
+ File::DeleteRecursively(temp_directory_, NULL, NULL);
256
+
257
+ // Delete all the MockCodeGenerators.
258
+ for (int i = 0; i < mock_generators_to_delete_.size(); i++) {
259
+ delete mock_generators_to_delete_[i];
260
+ }
261
+ mock_generators_to_delete_.clear();
262
+ }
263
+
264
+ void CommandLineInterfaceTest::Run(const string& command) {
265
+ vector<string> args = Split(command, " ", true);
266
+
267
+ if (!disallow_plugins_) {
268
+ cli_.AllowPlugins("prefix-");
269
+ const char* possible_paths[] = {
270
+ // When building with shared libraries, libtool hides the real executable
271
+ // in .libs and puts a fake wrapper in the current directory.
272
+ // Unfortunately, due to an apparent bug on Cygwin/MinGW, if one program
273
+ // wrapped in this way (e.g. protobuf-tests.exe) tries to execute another
274
+ // program wrapped in this way (e.g. test_plugin.exe), the latter fails
275
+ // with error code 127 and no explanation message. Presumably the problem
276
+ // is that the wrapper for protobuf-tests.exe set some environment
277
+ // variables that confuse the wrapper for test_plugin.exe. Luckily, it
278
+ // turns out that if we simply invoke the wrapped test_plugin.exe
279
+ // directly, it works -- I guess the environment variables set by the
280
+ // protobuf-tests.exe wrapper happen to be correct for it too. So we do
281
+ // that.
282
+ ".libs/test_plugin.exe", // Win32 w/autotool (Cygwin / MinGW)
283
+ "test_plugin.exe", // Other Win32 (MSVC)
284
+ "test_plugin", // Unix
285
+ };
286
+
287
+ string plugin_path;
288
+
289
+ for (int i = 0; i < GOOGLE_ARRAYSIZE(possible_paths); i++) {
290
+ if (access(possible_paths[i], F_OK) == 0) {
291
+ plugin_path = possible_paths[i];
292
+ break;
293
+ }
294
+ }
295
+
296
+ if (plugin_path.empty()) {
297
+ GOOGLE_LOG(ERROR)
298
+ << "Plugin executable not found. Plugin tests are likely to fail.";
299
+ } else {
300
+ args.push_back("--plugin=prefix-gen-plug=" + plugin_path);
301
+ }
302
+ }
303
+
304
+ scoped_array<const char*> argv(new const char* [args.size()]);
305
+
306
+ for (int i = 0; i < args.size(); i++) {
307
+ args[i] = StringReplace(args[i], "$tmpdir", temp_directory_, true);
308
+ argv[i] = args[i].c_str();
309
+ }
310
+
311
+ // TODO(jieluo): Cygwin doesn't work well if we try to capture stderr and
312
+ // stdout at the same time. Need to figure out why and add this capture back
313
+ // for Cygwin.
314
+ #if !defined(__CYGWIN__)
315
+ CaptureTestStdout();
316
+ #endif
317
+ CaptureTestStderr();
318
+
319
+ return_code_ = cli_.Run(args.size(), argv.get());
320
+
321
+ error_text_ = GetCapturedTestStderr();
322
+ #if !defined(__CYGWIN__)
323
+ captured_stdout_ = GetCapturedTestStdout();
324
+ #endif
325
+ }
326
+
327
+ // -------------------------------------------------------------------
328
+
329
+ void CommandLineInterfaceTest::CreateTempFile(
330
+ const string& name,
331
+ const string& contents) {
332
+ // Create parent directory, if necessary.
333
+ string::size_type slash_pos = name.find_last_of('/');
334
+ if (slash_pos != string::npos) {
335
+ string dir = name.substr(0, slash_pos);
336
+ if (!File::Exists(temp_directory_ + "/" + dir)) {
337
+ GOOGLE_CHECK_OK(File::RecursivelyCreateDir(temp_directory_ + "/" + dir,
338
+ 0777));
339
+ }
340
+ }
341
+
342
+ // Write file.
343
+ string full_name = temp_directory_ + "/" + name;
344
+ GOOGLE_CHECK_OK(File::SetContents(full_name, contents, true));
345
+ }
346
+
347
+ void CommandLineInterfaceTest::CreateTempDir(const string& name) {
348
+ GOOGLE_CHECK_OK(File::RecursivelyCreateDir(temp_directory_ + "/" + name,
349
+ 0777));
350
+ }
351
+
352
+ // -------------------------------------------------------------------
353
+
354
+ void CommandLineInterfaceTest::ExpectNoErrors() {
355
+ EXPECT_EQ(0, return_code_);
356
+ EXPECT_EQ("", error_text_);
357
+ }
358
+
359
+ void CommandLineInterfaceTest::ExpectErrorText(const string& expected_text) {
360
+ EXPECT_NE(0, return_code_);
361
+ EXPECT_EQ(StringReplace(expected_text, "$tmpdir", temp_directory_, true),
362
+ error_text_);
363
+ }
364
+
365
+ void CommandLineInterfaceTest::ExpectErrorSubstring(
366
+ const string& expected_substring) {
367
+ EXPECT_NE(0, return_code_);
368
+ EXPECT_PRED_FORMAT2(testing::IsSubstring, expected_substring, error_text_);
369
+ }
370
+
371
+ void CommandLineInterfaceTest::ExpectErrorSubstringWithZeroReturnCode(
372
+ const string& expected_substring) {
373
+ EXPECT_EQ(0, return_code_);
374
+ EXPECT_PRED_FORMAT2(testing::IsSubstring, expected_substring, error_text_);
375
+ }
376
+
377
+ bool CommandLineInterfaceTest::HasAlternateErrorSubstring(
378
+ const string& expected_substring) {
379
+ EXPECT_NE(0, return_code_);
380
+ return error_text_.find(expected_substring) != string::npos;
381
+ }
382
+
383
+ void CommandLineInterfaceTest::ExpectGenerated(
384
+ const string& generator_name,
385
+ const string& parameter,
386
+ const string& proto_name,
387
+ const string& message_name) {
388
+ MockCodeGenerator::ExpectGenerated(
389
+ generator_name, parameter, "", proto_name, message_name, proto_name,
390
+ temp_directory_);
391
+ }
392
+
393
+ void CommandLineInterfaceTest::ExpectGenerated(
394
+ const string& generator_name,
395
+ const string& parameter,
396
+ const string& proto_name,
397
+ const string& message_name,
398
+ const string& output_directory) {
399
+ MockCodeGenerator::ExpectGenerated(
400
+ generator_name, parameter, "", proto_name, message_name, proto_name,
401
+ temp_directory_ + "/" + output_directory);
402
+ }
403
+
404
+ void CommandLineInterfaceTest::ExpectGeneratedWithMultipleInputs(
405
+ const string& generator_name,
406
+ const string& all_proto_names,
407
+ const string& proto_name,
408
+ const string& message_name) {
409
+ MockCodeGenerator::ExpectGenerated(
410
+ generator_name, "", "", proto_name, message_name,
411
+ all_proto_names,
412
+ temp_directory_);
413
+ }
414
+
415
+ void CommandLineInterfaceTest::ExpectGeneratedWithInsertions(
416
+ const string& generator_name,
417
+ const string& parameter,
418
+ const string& insertions,
419
+ const string& proto_name,
420
+ const string& message_name) {
421
+ MockCodeGenerator::ExpectGenerated(
422
+ generator_name, parameter, insertions, proto_name, message_name,
423
+ proto_name, temp_directory_);
424
+ }
425
+
426
+ void CommandLineInterfaceTest::ExpectNullCodeGeneratorCalled(
427
+ const string& parameter) {
428
+ EXPECT_TRUE(null_generator_->called_);
429
+ EXPECT_EQ(parameter, null_generator_->parameter_);
430
+ }
431
+
432
+ void CommandLineInterfaceTest::ReadDescriptorSet(
433
+ const string& filename, FileDescriptorSet* descriptor_set) {
434
+ string path = temp_directory_ + "/" + filename;
435
+ string file_contents;
436
+ GOOGLE_CHECK_OK(File::GetContents(path, &file_contents, true));
437
+
438
+ if (!descriptor_set->ParseFromString(file_contents)) {
439
+ FAIL() << "Could not parse file contents: " << path;
440
+ }
441
+ }
442
+
443
+ void CommandLineInterfaceTest::ExpectCapturedStdout(
444
+ const string& expected_text) {
445
+ EXPECT_EQ(expected_text, captured_stdout_);
446
+ }
447
+
448
+ // ===================================================================
449
+
450
+ TEST_F(CommandLineInterfaceTest, BasicOutput) {
451
+ // Test that the common case works.
452
+
453
+ CreateTempFile("foo.proto",
454
+ "syntax = \"proto2\";\n"
455
+ "message Foo {}\n");
456
+
457
+ Run("protocol_compiler --test_out=$tmpdir "
458
+ "--proto_path=$tmpdir foo.proto");
459
+
460
+ ExpectNoErrors();
461
+ ExpectGenerated("test_generator", "", "foo.proto", "Foo");
462
+ }
463
+
464
+ TEST_F(CommandLineInterfaceTest, BasicPlugin) {
465
+ // Test that basic plugins work.
466
+
467
+ CreateTempFile("foo.proto",
468
+ "syntax = \"proto2\";\n"
469
+ "message Foo {}\n");
470
+
471
+ Run("protocol_compiler --plug_out=$tmpdir "
472
+ "--proto_path=$tmpdir foo.proto");
473
+
474
+ ExpectNoErrors();
475
+ ExpectGenerated("test_plugin", "", "foo.proto", "Foo");
476
+ }
477
+
478
+ TEST_F(CommandLineInterfaceTest, GeneratorAndPlugin) {
479
+ // Invoke a generator and a plugin at the same time.
480
+
481
+ CreateTempFile("foo.proto",
482
+ "syntax = \"proto2\";\n"
483
+ "message Foo {}\n");
484
+
485
+ Run("protocol_compiler --test_out=$tmpdir --plug_out=$tmpdir "
486
+ "--proto_path=$tmpdir foo.proto");
487
+
488
+ ExpectNoErrors();
489
+ ExpectGenerated("test_generator", "", "foo.proto", "Foo");
490
+ ExpectGenerated("test_plugin", "", "foo.proto", "Foo");
491
+ }
492
+
493
+ TEST_F(CommandLineInterfaceTest, MultipleInputs) {
494
+ // Test parsing multiple input files.
495
+
496
+ CreateTempFile("foo.proto",
497
+ "syntax = \"proto2\";\n"
498
+ "message Foo {}\n");
499
+ CreateTempFile("bar.proto",
500
+ "syntax = \"proto2\";\n"
501
+ "message Bar {}\n");
502
+
503
+ Run("protocol_compiler --test_out=$tmpdir --plug_out=$tmpdir "
504
+ "--proto_path=$tmpdir foo.proto bar.proto");
505
+
506
+ ExpectNoErrors();
507
+ ExpectGeneratedWithMultipleInputs("test_generator", "foo.proto,bar.proto",
508
+ "foo.proto", "Foo");
509
+ ExpectGeneratedWithMultipleInputs("test_generator", "foo.proto,bar.proto",
510
+ "bar.proto", "Bar");
511
+ ExpectGeneratedWithMultipleInputs("test_plugin", "foo.proto,bar.proto",
512
+ "foo.proto", "Foo");
513
+ ExpectGeneratedWithMultipleInputs("test_plugin", "foo.proto,bar.proto",
514
+ "bar.proto", "Bar");
515
+ }
516
+
517
+ TEST_F(CommandLineInterfaceTest, MultipleInputsWithImport) {
518
+ // Test parsing multiple input files with an import of a separate file.
519
+
520
+ CreateTempFile("foo.proto",
521
+ "syntax = \"proto2\";\n"
522
+ "message Foo {}\n");
523
+ CreateTempFile("bar.proto",
524
+ "syntax = \"proto2\";\n"
525
+ "import \"baz.proto\";\n"
526
+ "message Bar {\n"
527
+ " optional Baz a = 1;\n"
528
+ "}\n");
529
+ CreateTempFile("baz.proto",
530
+ "syntax = \"proto2\";\n"
531
+ "message Baz {}\n");
532
+
533
+ Run("protocol_compiler --test_out=$tmpdir --plug_out=$tmpdir "
534
+ "--proto_path=$tmpdir foo.proto bar.proto");
535
+
536
+ ExpectNoErrors();
537
+ ExpectGeneratedWithMultipleInputs("test_generator", "foo.proto,bar.proto",
538
+ "foo.proto", "Foo");
539
+ ExpectGeneratedWithMultipleInputs("test_generator", "foo.proto,bar.proto",
540
+ "bar.proto", "Bar");
541
+ ExpectGeneratedWithMultipleInputs("test_plugin", "foo.proto,bar.proto",
542
+ "foo.proto", "Foo");
543
+ ExpectGeneratedWithMultipleInputs("test_plugin", "foo.proto,bar.proto",
544
+ "bar.proto", "Bar");
545
+ }
546
+
547
+ TEST_F(CommandLineInterfaceTest, CreateDirectory) {
548
+ // Test that when we output to a sub-directory, it is created.
549
+
550
+ CreateTempFile("bar/baz/foo.proto",
551
+ "syntax = \"proto2\";\n"
552
+ "message Foo {}\n");
553
+ CreateTempDir("out");
554
+ CreateTempDir("plugout");
555
+
556
+ Run("protocol_compiler --test_out=$tmpdir/out --plug_out=$tmpdir/plugout "
557
+ "--proto_path=$tmpdir bar/baz/foo.proto");
558
+
559
+ ExpectNoErrors();
560
+ ExpectGenerated("test_generator", "", "bar/baz/foo.proto", "Foo", "out");
561
+ ExpectGenerated("test_plugin", "", "bar/baz/foo.proto", "Foo", "plugout");
562
+ }
563
+
564
+ TEST_F(CommandLineInterfaceTest, GeneratorParameters) {
565
+ // Test that generator parameters are correctly parsed from the command line.
566
+
567
+ CreateTempFile("foo.proto",
568
+ "syntax = \"proto2\";\n"
569
+ "message Foo {}\n");
570
+
571
+ Run("protocol_compiler --test_out=TestParameter:$tmpdir "
572
+ "--plug_out=TestPluginParameter:$tmpdir "
573
+ "--proto_path=$tmpdir foo.proto");
574
+
575
+ ExpectNoErrors();
576
+ ExpectGenerated("test_generator", "TestParameter", "foo.proto", "Foo");
577
+ ExpectGenerated("test_plugin", "TestPluginParameter", "foo.proto", "Foo");
578
+ }
579
+
580
+ TEST_F(CommandLineInterfaceTest, ExtraGeneratorParameters) {
581
+ // Test that generator parameters specified with the option flag are
582
+ // correctly passed to the code generator.
583
+
584
+ CreateTempFile("foo.proto",
585
+ "syntax = \"proto2\";\n"
586
+ "message Foo {}\n");
587
+ // Create the "a" and "b" sub-directories.
588
+ CreateTempDir("a");
589
+ CreateTempDir("b");
590
+
591
+ Run("protocol_compiler "
592
+ "--test_opt=foo1 "
593
+ "--test_out=bar:$tmpdir/a "
594
+ "--test_opt=foo2 "
595
+ "--test_out=baz:$tmpdir/b "
596
+ "--test_opt=foo3 "
597
+ "--proto_path=$tmpdir foo.proto");
598
+
599
+ ExpectNoErrors();
600
+ ExpectGenerated(
601
+ "test_generator", "bar,foo1,foo2,foo3", "foo.proto", "Foo", "a");
602
+ ExpectGenerated(
603
+ "test_generator", "baz,foo1,foo2,foo3", "foo.proto", "Foo", "b");
604
+ }
605
+
606
+ TEST_F(CommandLineInterfaceTest, Insert) {
607
+ // Test running a generator that inserts code into another's output.
608
+
609
+ CreateTempFile("foo.proto",
610
+ "syntax = \"proto2\";\n"
611
+ "message Foo {}\n");
612
+
613
+ Run("protocol_compiler "
614
+ "--test_out=TestParameter:$tmpdir "
615
+ "--plug_out=TestPluginParameter:$tmpdir "
616
+ "--test_out=insert=test_generator,test_plugin:$tmpdir "
617
+ "--plug_out=insert=test_generator,test_plugin:$tmpdir "
618
+ "--proto_path=$tmpdir foo.proto");
619
+
620
+ ExpectNoErrors();
621
+ ExpectGeneratedWithInsertions(
622
+ "test_generator", "TestParameter", "test_generator,test_plugin",
623
+ "foo.proto", "Foo");
624
+ ExpectGeneratedWithInsertions(
625
+ "test_plugin", "TestPluginParameter", "test_generator,test_plugin",
626
+ "foo.proto", "Foo");
627
+ }
628
+
629
+ #if defined(_WIN32)
630
+
631
+ TEST_F(CommandLineInterfaceTest, WindowsOutputPath) {
632
+ // Test that the output path can be a Windows-style path.
633
+
634
+ CreateTempFile("foo.proto",
635
+ "syntax = \"proto2\";\n");
636
+
637
+ Run("protocol_compiler --null_out=C:\\ "
638
+ "--proto_path=$tmpdir foo.proto");
639
+
640
+ ExpectNoErrors();
641
+ ExpectNullCodeGeneratorCalled("");
642
+ }
643
+
644
+ TEST_F(CommandLineInterfaceTest, WindowsOutputPathAndParameter) {
645
+ // Test that we can have a windows-style output path and a parameter.
646
+
647
+ CreateTempFile("foo.proto",
648
+ "syntax = \"proto2\";\n");
649
+
650
+ Run("protocol_compiler --null_out=bar:C:\\ "
651
+ "--proto_path=$tmpdir foo.proto");
652
+
653
+ ExpectNoErrors();
654
+ ExpectNullCodeGeneratorCalled("bar");
655
+ }
656
+
657
+ TEST_F(CommandLineInterfaceTest, TrailingBackslash) {
658
+ // Test that the directories can end in backslashes. Some users claim this
659
+ // doesn't work on their system.
660
+
661
+ CreateTempFile("foo.proto",
662
+ "syntax = \"proto2\";\n"
663
+ "message Foo {}\n");
664
+
665
+ Run("protocol_compiler --test_out=$tmpdir\\ "
666
+ "--proto_path=$tmpdir\\ foo.proto");
667
+
668
+ ExpectNoErrors();
669
+ ExpectGenerated("test_generator", "", "foo.proto", "Foo");
670
+ }
671
+
672
+ #endif // defined(_WIN32) || defined(__CYGWIN__)
673
+
674
+ TEST_F(CommandLineInterfaceTest, PathLookup) {
675
+ // Test that specifying multiple directories in the proto search path works.
676
+
677
+ CreateTempFile("b/bar.proto",
678
+ "syntax = \"proto2\";\n"
679
+ "message Bar {}\n");
680
+ CreateTempFile("a/foo.proto",
681
+ "syntax = \"proto2\";\n"
682
+ "import \"bar.proto\";\n"
683
+ "message Foo {\n"
684
+ " optional Bar a = 1;\n"
685
+ "}\n");
686
+ CreateTempFile("b/foo.proto", "this should not be parsed\n");
687
+
688
+ Run("protocol_compiler --test_out=$tmpdir "
689
+ "--proto_path=$tmpdir/a --proto_path=$tmpdir/b foo.proto");
690
+
691
+ ExpectNoErrors();
692
+ ExpectGenerated("test_generator", "", "foo.proto", "Foo");
693
+ }
694
+
695
+ TEST_F(CommandLineInterfaceTest, ColonDelimitedPath) {
696
+ // Same as PathLookup, but we provide the proto_path in a single flag.
697
+
698
+ CreateTempFile("b/bar.proto",
699
+ "syntax = \"proto2\";\n"
700
+ "message Bar {}\n");
701
+ CreateTempFile("a/foo.proto",
702
+ "syntax = \"proto2\";\n"
703
+ "import \"bar.proto\";\n"
704
+ "message Foo {\n"
705
+ " optional Bar a = 1;\n"
706
+ "}\n");
707
+ CreateTempFile("b/foo.proto", "this should not be parsed\n");
708
+
709
+ #undef PATH_SEPARATOR
710
+ #if defined(_WIN32)
711
+ #define PATH_SEPARATOR ";"
712
+ #else
713
+ #define PATH_SEPARATOR ":"
714
+ #endif
715
+
716
+ Run("protocol_compiler --test_out=$tmpdir "
717
+ "--proto_path=$tmpdir/a"PATH_SEPARATOR"$tmpdir/b foo.proto");
718
+
719
+ #undef PATH_SEPARATOR
720
+
721
+ ExpectNoErrors();
722
+ ExpectGenerated("test_generator", "", "foo.proto", "Foo");
723
+ }
724
+
725
+ TEST_F(CommandLineInterfaceTest, NonRootMapping) {
726
+ // Test setting up a search path mapping a directory to a non-root location.
727
+
728
+ CreateTempFile("foo.proto",
729
+ "syntax = \"proto2\";\n"
730
+ "message Foo {}\n");
731
+
732
+ Run("protocol_compiler --test_out=$tmpdir "
733
+ "--proto_path=bar=$tmpdir bar/foo.proto");
734
+
735
+ ExpectNoErrors();
736
+ ExpectGenerated("test_generator", "", "bar/foo.proto", "Foo");
737
+ }
738
+
739
+ TEST_F(CommandLineInterfaceTest, MultipleGenerators) {
740
+ // Test that we can have multiple generators and use both in one invocation,
741
+ // each with a different output directory.
742
+
743
+ CreateTempFile("foo.proto",
744
+ "syntax = \"proto2\";\n"
745
+ "message Foo {}\n");
746
+ // Create the "a" and "b" sub-directories.
747
+ CreateTempDir("a");
748
+ CreateTempDir("b");
749
+
750
+ Run("protocol_compiler "
751
+ "--test_out=$tmpdir/a "
752
+ "--alt_out=$tmpdir/b "
753
+ "--proto_path=$tmpdir foo.proto");
754
+
755
+ ExpectNoErrors();
756
+ ExpectGenerated("test_generator", "", "foo.proto", "Foo", "a");
757
+ ExpectGenerated("alt_generator", "", "foo.proto", "Foo", "b");
758
+ }
759
+
760
+ TEST_F(CommandLineInterfaceTest, DisallowServicesNoServices) {
761
+ // Test that --disallow_services doesn't cause a problem when there are no
762
+ // services.
763
+
764
+ CreateTempFile("foo.proto",
765
+ "syntax = \"proto2\";\n"
766
+ "message Foo {}\n");
767
+
768
+ Run("protocol_compiler --disallow_services --test_out=$tmpdir "
769
+ "--proto_path=$tmpdir foo.proto");
770
+
771
+ ExpectNoErrors();
772
+ ExpectGenerated("test_generator", "", "foo.proto", "Foo");
773
+ }
774
+
775
+ TEST_F(CommandLineInterfaceTest, DisallowServicesHasService) {
776
+ // Test that --disallow_services produces an error when there are services.
777
+
778
+ CreateTempFile("foo.proto",
779
+ "syntax = \"proto2\";\n"
780
+ "message Foo {}\n"
781
+ "service Bar {}\n");
782
+
783
+ Run("protocol_compiler --disallow_services --test_out=$tmpdir "
784
+ "--proto_path=$tmpdir foo.proto");
785
+
786
+ ExpectErrorSubstring("foo.proto: This file contains services");
787
+ }
788
+
789
+ TEST_F(CommandLineInterfaceTest, AllowServicesHasService) {
790
+ // Test that services work fine as long as --disallow_services is not used.
791
+
792
+ CreateTempFile("foo.proto",
793
+ "syntax = \"proto2\";\n"
794
+ "message Foo {}\n"
795
+ "service Bar {}\n");
796
+
797
+ Run("protocol_compiler --test_out=$tmpdir "
798
+ "--proto_path=$tmpdir foo.proto");
799
+
800
+ ExpectNoErrors();
801
+ ExpectGenerated("test_generator", "", "foo.proto", "Foo");
802
+ }
803
+
804
+ TEST_F(CommandLineInterfaceTest, CwdRelativeInputs) {
805
+ // Test that we can accept working-directory-relative input files.
806
+
807
+ SetInputsAreProtoPathRelative(false);
808
+
809
+ CreateTempFile("foo.proto",
810
+ "syntax = \"proto2\";\n"
811
+ "message Foo {}\n");
812
+
813
+ Run("protocol_compiler --test_out=$tmpdir "
814
+ "--proto_path=$tmpdir $tmpdir/foo.proto");
815
+
816
+ ExpectNoErrors();
817
+ ExpectGenerated("test_generator", "", "foo.proto", "Foo");
818
+ }
819
+
820
+ TEST_F(CommandLineInterfaceTest, WriteDescriptorSet) {
821
+ CreateTempFile("foo.proto",
822
+ "syntax = \"proto2\";\n"
823
+ "message Foo {}\n");
824
+ CreateTempFile("bar.proto",
825
+ "syntax = \"proto2\";\n"
826
+ "import \"foo.proto\";\n"
827
+ "message Bar {\n"
828
+ " optional Foo foo = 1;\n"
829
+ "}\n");
830
+
831
+ Run("protocol_compiler --descriptor_set_out=$tmpdir/descriptor_set "
832
+ "--proto_path=$tmpdir bar.proto");
833
+
834
+ ExpectNoErrors();
835
+
836
+ FileDescriptorSet descriptor_set;
837
+ ReadDescriptorSet("descriptor_set", &descriptor_set);
838
+ if (HasFatalFailure()) return;
839
+ EXPECT_EQ(1, descriptor_set.file_size());
840
+ EXPECT_EQ("bar.proto", descriptor_set.file(0).name());
841
+ // Descriptor set should not have source code info.
842
+ EXPECT_FALSE(descriptor_set.file(0).has_source_code_info());
843
+ }
844
+
845
+ TEST_F(CommandLineInterfaceTest, WriteDescriptorSetWithSourceInfo) {
846
+ CreateTempFile("foo.proto",
847
+ "syntax = \"proto2\";\n"
848
+ "message Foo {}\n");
849
+ CreateTempFile("bar.proto",
850
+ "syntax = \"proto2\";\n"
851
+ "import \"foo.proto\";\n"
852
+ "message Bar {\n"
853
+ " optional Foo foo = 1;\n"
854
+ "}\n");
855
+
856
+ Run("protocol_compiler --descriptor_set_out=$tmpdir/descriptor_set "
857
+ "--include_source_info --proto_path=$tmpdir bar.proto");
858
+
859
+ ExpectNoErrors();
860
+
861
+ FileDescriptorSet descriptor_set;
862
+ ReadDescriptorSet("descriptor_set", &descriptor_set);
863
+ if (HasFatalFailure()) return;
864
+ EXPECT_EQ(1, descriptor_set.file_size());
865
+ EXPECT_EQ("bar.proto", descriptor_set.file(0).name());
866
+ // Source code info included.
867
+ EXPECT_TRUE(descriptor_set.file(0).has_source_code_info());
868
+ }
869
+
870
+ TEST_F(CommandLineInterfaceTest, WriteTransitiveDescriptorSet) {
871
+ CreateTempFile("foo.proto",
872
+ "syntax = \"proto2\";\n"
873
+ "message Foo {}\n");
874
+ CreateTempFile("bar.proto",
875
+ "syntax = \"proto2\";\n"
876
+ "import \"foo.proto\";\n"
877
+ "message Bar {\n"
878
+ " optional Foo foo = 1;\n"
879
+ "}\n");
880
+
881
+ Run("protocol_compiler --descriptor_set_out=$tmpdir/descriptor_set "
882
+ "--include_imports --proto_path=$tmpdir bar.proto");
883
+
884
+ ExpectNoErrors();
885
+
886
+ FileDescriptorSet descriptor_set;
887
+ ReadDescriptorSet("descriptor_set", &descriptor_set);
888
+ if (HasFatalFailure()) return;
889
+ EXPECT_EQ(2, descriptor_set.file_size());
890
+ if (descriptor_set.file(0).name() == "bar.proto") {
891
+ std::swap(descriptor_set.mutable_file()->mutable_data()[0],
892
+ descriptor_set.mutable_file()->mutable_data()[1]);
893
+ }
894
+ EXPECT_EQ("foo.proto", descriptor_set.file(0).name());
895
+ EXPECT_EQ("bar.proto", descriptor_set.file(1).name());
896
+ // Descriptor set should not have source code info.
897
+ EXPECT_FALSE(descriptor_set.file(0).has_source_code_info());
898
+ EXPECT_FALSE(descriptor_set.file(1).has_source_code_info());
899
+ }
900
+
901
+ TEST_F(CommandLineInterfaceTest, WriteTransitiveDescriptorSetWithSourceInfo) {
902
+ CreateTempFile("foo.proto",
903
+ "syntax = \"proto2\";\n"
904
+ "message Foo {}\n");
905
+ CreateTempFile("bar.proto",
906
+ "syntax = \"proto2\";\n"
907
+ "import \"foo.proto\";\n"
908
+ "message Bar {\n"
909
+ " optional Foo foo = 1;\n"
910
+ "}\n");
911
+
912
+ Run("protocol_compiler --descriptor_set_out=$tmpdir/descriptor_set "
913
+ "--include_imports --include_source_info --proto_path=$tmpdir bar.proto");
914
+
915
+ ExpectNoErrors();
916
+
917
+ FileDescriptorSet descriptor_set;
918
+ ReadDescriptorSet("descriptor_set", &descriptor_set);
919
+ if (HasFatalFailure()) return;
920
+ EXPECT_EQ(2, descriptor_set.file_size());
921
+ if (descriptor_set.file(0).name() == "bar.proto") {
922
+ std::swap(descriptor_set.mutable_file()->mutable_data()[0],
923
+ descriptor_set.mutable_file()->mutable_data()[1]);
924
+ }
925
+ EXPECT_EQ("foo.proto", descriptor_set.file(0).name());
926
+ EXPECT_EQ("bar.proto", descriptor_set.file(1).name());
927
+ // Source code info included.
928
+ EXPECT_TRUE(descriptor_set.file(0).has_source_code_info());
929
+ EXPECT_TRUE(descriptor_set.file(1).has_source_code_info());
930
+ }
931
+
932
+ // -------------------------------------------------------------------
933
+
934
+ TEST_F(CommandLineInterfaceTest, ParseErrors) {
935
+ // Test that parse errors are reported.
936
+
937
+ CreateTempFile("foo.proto",
938
+ "syntax = \"proto2\";\n"
939
+ "badsyntax\n");
940
+
941
+ Run("protocol_compiler --test_out=$tmpdir "
942
+ "--proto_path=$tmpdir foo.proto");
943
+
944
+ ExpectErrorText(
945
+ "foo.proto:2:1: Expected top-level statement (e.g. \"message\").\n");
946
+ }
947
+
948
+ TEST_F(CommandLineInterfaceTest, ParseErrorsMultipleFiles) {
949
+ // Test that parse errors are reported from multiple files.
950
+
951
+ // We set up files such that foo.proto actually depends on bar.proto in
952
+ // two ways: Directly and through baz.proto. bar.proto's errors should
953
+ // only be reported once.
954
+ CreateTempFile("bar.proto",
955
+ "syntax = \"proto2\";\n"
956
+ "badsyntax\n");
957
+ CreateTempFile("baz.proto",
958
+ "syntax = \"proto2\";\n"
959
+ "import \"bar.proto\";\n");
960
+ CreateTempFile("foo.proto",
961
+ "syntax = \"proto2\";\n"
962
+ "import \"bar.proto\";\n"
963
+ "import \"baz.proto\";\n");
964
+
965
+ Run("protocol_compiler --test_out=$tmpdir "
966
+ "--proto_path=$tmpdir foo.proto");
967
+
968
+ ExpectErrorText(
969
+ "bar.proto:2:1: Expected top-level statement (e.g. \"message\").\n"
970
+ "baz.proto: Import \"bar.proto\" was not found or had errors.\n"
971
+ "foo.proto: Import \"bar.proto\" was not found or had errors.\n"
972
+ "foo.proto: Import \"baz.proto\" was not found or had errors.\n");
973
+ }
974
+
975
+ TEST_F(CommandLineInterfaceTest, InputNotFoundError) {
976
+ // Test what happens if the input file is not found.
977
+
978
+ Run("protocol_compiler --test_out=$tmpdir "
979
+ "--proto_path=$tmpdir foo.proto");
980
+
981
+ ExpectErrorText(
982
+ "foo.proto: File not found.\n");
983
+ }
984
+
985
+ TEST_F(CommandLineInterfaceTest, CwdRelativeInputNotFoundError) {
986
+ // Test what happens when a working-directory-relative input file is not
987
+ // found.
988
+
989
+ SetInputsAreProtoPathRelative(false);
990
+
991
+ Run("protocol_compiler --test_out=$tmpdir "
992
+ "--proto_path=$tmpdir $tmpdir/foo.proto");
993
+
994
+ ExpectErrorText(
995
+ "$tmpdir/foo.proto: No such file or directory\n");
996
+ }
997
+
998
+ TEST_F(CommandLineInterfaceTest, CwdRelativeInputNotMappedError) {
999
+ // Test what happens when a working-directory-relative input file is not
1000
+ // mapped to a virtual path.
1001
+
1002
+ SetInputsAreProtoPathRelative(false);
1003
+
1004
+ CreateTempFile("foo.proto",
1005
+ "syntax = \"proto2\";\n"
1006
+ "message Foo {}\n");
1007
+
1008
+ // Create a directory called "bar" so that we can point --proto_path at it.
1009
+ CreateTempFile("bar/dummy", "");
1010
+
1011
+ Run("protocol_compiler --test_out=$tmpdir "
1012
+ "--proto_path=$tmpdir/bar $tmpdir/foo.proto");
1013
+
1014
+ ExpectErrorText(
1015
+ "$tmpdir/foo.proto: File does not reside within any path "
1016
+ "specified using --proto_path (or -I). You must specify a "
1017
+ "--proto_path which encompasses this file. Note that the "
1018
+ "proto_path must be an exact prefix of the .proto file "
1019
+ "names -- protoc is too dumb to figure out when two paths "
1020
+ "(e.g. absolute and relative) are equivalent (it's harder "
1021
+ "than you think).\n");
1022
+ }
1023
+
1024
+ TEST_F(CommandLineInterfaceTest, CwdRelativeInputNotFoundAndNotMappedError) {
1025
+ // Check what happens if the input file is not found *and* is not mapped
1026
+ // in the proto_path.
1027
+
1028
+ SetInputsAreProtoPathRelative(false);
1029
+
1030
+ // Create a directory called "bar" so that we can point --proto_path at it.
1031
+ CreateTempFile("bar/dummy", "");
1032
+
1033
+ Run("protocol_compiler --test_out=$tmpdir "
1034
+ "--proto_path=$tmpdir/bar $tmpdir/foo.proto");
1035
+
1036
+ ExpectErrorText(
1037
+ "$tmpdir/foo.proto: No such file or directory\n");
1038
+ }
1039
+
1040
+ TEST_F(CommandLineInterfaceTest, CwdRelativeInputShadowedError) {
1041
+ // Test what happens when a working-directory-relative input file is shadowed
1042
+ // by another file in the virtual path.
1043
+
1044
+ SetInputsAreProtoPathRelative(false);
1045
+
1046
+ CreateTempFile("foo/foo.proto",
1047
+ "syntax = \"proto2\";\n"
1048
+ "message Foo {}\n");
1049
+ CreateTempFile("bar/foo.proto",
1050
+ "syntax = \"proto2\";\n"
1051
+ "message Bar {}\n");
1052
+
1053
+ Run("protocol_compiler --test_out=$tmpdir "
1054
+ "--proto_path=$tmpdir/foo --proto_path=$tmpdir/bar "
1055
+ "$tmpdir/bar/foo.proto");
1056
+
1057
+ ExpectErrorText(
1058
+ "$tmpdir/bar/foo.proto: Input is shadowed in the --proto_path "
1059
+ "by \"$tmpdir/foo/foo.proto\". Either use the latter "
1060
+ "file as your input or reorder the --proto_path so that the "
1061
+ "former file's location comes first.\n");
1062
+ }
1063
+
1064
+ TEST_F(CommandLineInterfaceTest, ProtoPathNotFoundError) {
1065
+ // Test what happens if the input file is not found.
1066
+
1067
+ Run("protocol_compiler --test_out=$tmpdir "
1068
+ "--proto_path=$tmpdir/foo foo.proto");
1069
+
1070
+ ExpectErrorText(
1071
+ "$tmpdir/foo: warning: directory does not exist.\n"
1072
+ "foo.proto: File not found.\n");
1073
+ }
1074
+
1075
+ TEST_F(CommandLineInterfaceTest, MissingInputError) {
1076
+ // Test that we get an error if no inputs are given.
1077
+
1078
+ Run("protocol_compiler --test_out=$tmpdir "
1079
+ "--proto_path=$tmpdir");
1080
+
1081
+ ExpectErrorText("Missing input file.\n");
1082
+ }
1083
+
1084
+ TEST_F(CommandLineInterfaceTest, MissingOutputError) {
1085
+ CreateTempFile("foo.proto",
1086
+ "syntax = \"proto2\";\n"
1087
+ "message Foo {}\n");
1088
+
1089
+ Run("protocol_compiler --proto_path=$tmpdir foo.proto");
1090
+
1091
+ ExpectErrorText("Missing output directives.\n");
1092
+ }
1093
+
1094
+ TEST_F(CommandLineInterfaceTest, OutputWriteError) {
1095
+ CreateTempFile("foo.proto",
1096
+ "syntax = \"proto2\";\n"
1097
+ "message Foo {}\n");
1098
+
1099
+ string output_file =
1100
+ MockCodeGenerator::GetOutputFileName("test_generator", "foo.proto");
1101
+
1102
+ // Create a directory blocking our output location.
1103
+ CreateTempDir(output_file);
1104
+
1105
+ Run("protocol_compiler --test_out=$tmpdir "
1106
+ "--proto_path=$tmpdir foo.proto");
1107
+
1108
+ // MockCodeGenerator no longer detects an error because we actually write to
1109
+ // an in-memory location first, then dump to disk at the end. This is no
1110
+ // big deal.
1111
+ // ExpectErrorSubstring("MockCodeGenerator detected write error.");
1112
+
1113
+ #if defined(_WIN32) && !defined(__CYGWIN__)
1114
+ // Windows with MSVCRT.dll produces EPERM instead of EISDIR.
1115
+ if (HasAlternateErrorSubstring(output_file + ": Permission denied")) {
1116
+ return;
1117
+ }
1118
+ #endif
1119
+
1120
+ ExpectErrorSubstring(output_file + ": Is a directory");
1121
+ }
1122
+
1123
+ TEST_F(CommandLineInterfaceTest, PluginOutputWriteError) {
1124
+ CreateTempFile("foo.proto",
1125
+ "syntax = \"proto2\";\n"
1126
+ "message Foo {}\n");
1127
+
1128
+ string output_file =
1129
+ MockCodeGenerator::GetOutputFileName("test_plugin", "foo.proto");
1130
+
1131
+ // Create a directory blocking our output location.
1132
+ CreateTempDir(output_file);
1133
+
1134
+ Run("protocol_compiler --plug_out=$tmpdir "
1135
+ "--proto_path=$tmpdir foo.proto");
1136
+
1137
+ #if defined(_WIN32) && !defined(__CYGWIN__)
1138
+ // Windows with MSVCRT.dll produces EPERM instead of EISDIR.
1139
+ if (HasAlternateErrorSubstring(output_file + ": Permission denied")) {
1140
+ return;
1141
+ }
1142
+ #endif
1143
+
1144
+ ExpectErrorSubstring(output_file + ": Is a directory");
1145
+ }
1146
+
1147
+ TEST_F(CommandLineInterfaceTest, OutputDirectoryNotFoundError) {
1148
+ CreateTempFile("foo.proto",
1149
+ "syntax = \"proto2\";\n"
1150
+ "message Foo {}\n");
1151
+
1152
+ Run("protocol_compiler --test_out=$tmpdir/nosuchdir "
1153
+ "--proto_path=$tmpdir foo.proto");
1154
+
1155
+ ExpectErrorSubstring("nosuchdir/: No such file or directory");
1156
+ }
1157
+
1158
+ TEST_F(CommandLineInterfaceTest, PluginOutputDirectoryNotFoundError) {
1159
+ CreateTempFile("foo.proto",
1160
+ "syntax = \"proto2\";\n"
1161
+ "message Foo {}\n");
1162
+
1163
+ Run("protocol_compiler --plug_out=$tmpdir/nosuchdir "
1164
+ "--proto_path=$tmpdir foo.proto");
1165
+
1166
+ ExpectErrorSubstring("nosuchdir/: No such file or directory");
1167
+ }
1168
+
1169
+ TEST_F(CommandLineInterfaceTest, OutputDirectoryIsFileError) {
1170
+ CreateTempFile("foo.proto",
1171
+ "syntax = \"proto2\";\n"
1172
+ "message Foo {}\n");
1173
+
1174
+ Run("protocol_compiler --test_out=$tmpdir/foo.proto "
1175
+ "--proto_path=$tmpdir foo.proto");
1176
+
1177
+ #if defined(_WIN32) && !defined(__CYGWIN__)
1178
+ // Windows with MSVCRT.dll produces EINVAL instead of ENOTDIR.
1179
+ if (HasAlternateErrorSubstring("foo.proto/: Invalid argument")) {
1180
+ return;
1181
+ }
1182
+ #endif
1183
+
1184
+ ExpectErrorSubstring("foo.proto/: Not a directory");
1185
+ }
1186
+
1187
+ TEST_F(CommandLineInterfaceTest, GeneratorError) {
1188
+ CreateTempFile("foo.proto",
1189
+ "syntax = \"proto2\";\n"
1190
+ "message MockCodeGenerator_Error {}\n");
1191
+
1192
+ Run("protocol_compiler --test_out=$tmpdir "
1193
+ "--proto_path=$tmpdir foo.proto");
1194
+
1195
+ ExpectErrorSubstring(
1196
+ "--test_out: foo.proto: Saw message type MockCodeGenerator_Error.");
1197
+ }
1198
+
1199
+ TEST_F(CommandLineInterfaceTest, GeneratorPluginError) {
1200
+ // Test a generator plugin that returns an error.
1201
+
1202
+ CreateTempFile("foo.proto",
1203
+ "syntax = \"proto2\";\n"
1204
+ "message MockCodeGenerator_Error {}\n");
1205
+
1206
+ Run("protocol_compiler --plug_out=TestParameter:$tmpdir "
1207
+ "--proto_path=$tmpdir foo.proto");
1208
+
1209
+ ExpectErrorSubstring(
1210
+ "--plug_out: foo.proto: Saw message type MockCodeGenerator_Error.");
1211
+ }
1212
+
1213
+ TEST_F(CommandLineInterfaceTest, GeneratorPluginFail) {
1214
+ // Test a generator plugin that exits with an error code.
1215
+
1216
+ CreateTempFile("foo.proto",
1217
+ "syntax = \"proto2\";\n"
1218
+ "message MockCodeGenerator_Exit {}\n");
1219
+
1220
+ Run("protocol_compiler --plug_out=TestParameter:$tmpdir "
1221
+ "--proto_path=$tmpdir foo.proto");
1222
+
1223
+ ExpectErrorSubstring("Saw message type MockCodeGenerator_Exit.");
1224
+ ExpectErrorSubstring(
1225
+ "--plug_out: prefix-gen-plug: Plugin failed with status code 123.");
1226
+ }
1227
+
1228
+ TEST_F(CommandLineInterfaceTest, GeneratorPluginCrash) {
1229
+ // Test a generator plugin that crashes.
1230
+
1231
+ CreateTempFile("foo.proto",
1232
+ "syntax = \"proto2\";\n"
1233
+ "message MockCodeGenerator_Abort {}\n");
1234
+
1235
+ Run("protocol_compiler --plug_out=TestParameter:$tmpdir "
1236
+ "--proto_path=$tmpdir foo.proto");
1237
+
1238
+ ExpectErrorSubstring("Saw message type MockCodeGenerator_Abort.");
1239
+
1240
+ #ifdef _WIN32
1241
+ // Windows doesn't have signals. It looks like abort()ing causes the process
1242
+ // to exit with status code 3, but let's not depend on the exact number here.
1243
+ ExpectErrorSubstring(
1244
+ "--plug_out: prefix-gen-plug: Plugin failed with status code");
1245
+ #else
1246
+ // Don't depend on the exact signal number.
1247
+ ExpectErrorSubstring(
1248
+ "--plug_out: prefix-gen-plug: Plugin killed by signal");
1249
+ #endif
1250
+ }
1251
+
1252
+ TEST_F(CommandLineInterfaceTest, PluginReceivesSourceCodeInfo) {
1253
+ CreateTempFile("foo.proto",
1254
+ "syntax = \"proto2\";\n"
1255
+ "message MockCodeGenerator_HasSourceCodeInfo {}\n");
1256
+
1257
+ Run("protocol_compiler --plug_out=$tmpdir --proto_path=$tmpdir foo.proto");
1258
+
1259
+ ExpectErrorSubstring(
1260
+ "Saw message type MockCodeGenerator_HasSourceCodeInfo: 1.");
1261
+ }
1262
+
1263
+ TEST_F(CommandLineInterfaceTest, GeneratorPluginNotFound) {
1264
+ // Test what happens if the plugin isn't found.
1265
+
1266
+ CreateTempFile("error.proto",
1267
+ "syntax = \"proto2\";\n"
1268
+ "message Foo {}\n");
1269
+
1270
+ Run("protocol_compiler --badplug_out=TestParameter:$tmpdir "
1271
+ "--plugin=prefix-gen-badplug=no_such_file "
1272
+ "--proto_path=$tmpdir error.proto");
1273
+
1274
+ #ifdef _WIN32
1275
+ ExpectErrorSubstring("--badplug_out: prefix-gen-badplug: " +
1276
+ Subprocess::Win32ErrorMessage(ERROR_FILE_NOT_FOUND));
1277
+ #else
1278
+ // Error written to stdout by child process after exec() fails.
1279
+ ExpectErrorSubstring(
1280
+ "no_such_file: program not found or is not executable");
1281
+
1282
+ // Error written by parent process when child fails.
1283
+ ExpectErrorSubstring(
1284
+ "--badplug_out: prefix-gen-badplug: Plugin failed with status code 1.");
1285
+ #endif
1286
+ }
1287
+
1288
+ TEST_F(CommandLineInterfaceTest, GeneratorPluginNotAllowed) {
1289
+ // Test what happens if plugins aren't allowed.
1290
+
1291
+ CreateTempFile("error.proto",
1292
+ "syntax = \"proto2\";\n"
1293
+ "message Foo {}\n");
1294
+
1295
+ DisallowPlugins();
1296
+ Run("protocol_compiler --plug_out=TestParameter:$tmpdir "
1297
+ "--proto_path=$tmpdir error.proto");
1298
+
1299
+ ExpectErrorSubstring("Unknown flag: --plug_out");
1300
+ }
1301
+
1302
+ TEST_F(CommandLineInterfaceTest, HelpText) {
1303
+ Run("test_exec_name --help");
1304
+
1305
+ ExpectErrorSubstringWithZeroReturnCode("Usage: test_exec_name ");
1306
+ ExpectErrorSubstringWithZeroReturnCode("--test_out=OUT_DIR");
1307
+ ExpectErrorSubstringWithZeroReturnCode("Test output.");
1308
+ ExpectErrorSubstringWithZeroReturnCode("--alt_out=OUT_DIR");
1309
+ ExpectErrorSubstringWithZeroReturnCode("Alt output.");
1310
+ }
1311
+
1312
+ TEST_F(CommandLineInterfaceTest, GccFormatErrors) {
1313
+ // Test --error_format=gcc (which is the default, but we want to verify
1314
+ // that it can be set explicitly).
1315
+
1316
+ CreateTempFile("foo.proto",
1317
+ "syntax = \"proto2\";\n"
1318
+ "badsyntax\n");
1319
+
1320
+ Run("protocol_compiler --test_out=$tmpdir "
1321
+ "--proto_path=$tmpdir --error_format=gcc foo.proto");
1322
+
1323
+ ExpectErrorText(
1324
+ "foo.proto:2:1: Expected top-level statement (e.g. \"message\").\n");
1325
+ }
1326
+
1327
+ TEST_F(CommandLineInterfaceTest, MsvsFormatErrors) {
1328
+ // Test --error_format=msvs
1329
+
1330
+ CreateTempFile("foo.proto",
1331
+ "syntax = \"proto2\";\n"
1332
+ "badsyntax\n");
1333
+
1334
+ Run("protocol_compiler --test_out=$tmpdir "
1335
+ "--proto_path=$tmpdir --error_format=msvs foo.proto");
1336
+
1337
+ ExpectErrorText(
1338
+ "$tmpdir/foo.proto(2) : error in column=1: Expected top-level statement "
1339
+ "(e.g. \"message\").\n");
1340
+ }
1341
+
1342
+ TEST_F(CommandLineInterfaceTest, InvalidErrorFormat) {
1343
+ // Test --error_format=msvs
1344
+
1345
+ CreateTempFile("foo.proto",
1346
+ "syntax = \"proto2\";\n"
1347
+ "badsyntax\n");
1348
+
1349
+ Run("protocol_compiler --test_out=$tmpdir "
1350
+ "--proto_path=$tmpdir --error_format=invalid foo.proto");
1351
+
1352
+ ExpectErrorText(
1353
+ "Unknown error format: invalid\n");
1354
+ }
1355
+
1356
+ // -------------------------------------------------------------------
1357
+ // Flag parsing tests
1358
+
1359
+ TEST_F(CommandLineInterfaceTest, ParseSingleCharacterFlag) {
1360
+ // Test that a single-character flag works.
1361
+
1362
+ CreateTempFile("foo.proto",
1363
+ "syntax = \"proto2\";\n"
1364
+ "message Foo {}\n");
1365
+
1366
+ Run("protocol_compiler -t$tmpdir "
1367
+ "--proto_path=$tmpdir foo.proto");
1368
+
1369
+ ExpectNoErrors();
1370
+ ExpectGenerated("test_generator", "", "foo.proto", "Foo");
1371
+ }
1372
+
1373
+ TEST_F(CommandLineInterfaceTest, ParseSpaceDelimitedValue) {
1374
+ // Test that separating the flag value with a space works.
1375
+
1376
+ CreateTempFile("foo.proto",
1377
+ "syntax = \"proto2\";\n"
1378
+ "message Foo {}\n");
1379
+
1380
+ Run("protocol_compiler --test_out $tmpdir "
1381
+ "--proto_path=$tmpdir foo.proto");
1382
+
1383
+ ExpectNoErrors();
1384
+ ExpectGenerated("test_generator", "", "foo.proto", "Foo");
1385
+ }
1386
+
1387
+ TEST_F(CommandLineInterfaceTest, ParseSingleCharacterSpaceDelimitedValue) {
1388
+ // Test that separating the flag value with a space works for
1389
+ // single-character flags.
1390
+
1391
+ CreateTempFile("foo.proto",
1392
+ "syntax = \"proto2\";\n"
1393
+ "message Foo {}\n");
1394
+
1395
+ Run("protocol_compiler -t $tmpdir "
1396
+ "--proto_path=$tmpdir foo.proto");
1397
+
1398
+ ExpectNoErrors();
1399
+ ExpectGenerated("test_generator", "", "foo.proto", "Foo");
1400
+ }
1401
+
1402
+ TEST_F(CommandLineInterfaceTest, MissingValueError) {
1403
+ // Test that we get an error if a flag is missing its value.
1404
+
1405
+ Run("protocol_compiler --test_out --proto_path=$tmpdir foo.proto");
1406
+
1407
+ ExpectErrorText("Missing value for flag: --test_out\n");
1408
+ }
1409
+
1410
+ TEST_F(CommandLineInterfaceTest, MissingValueAtEndError) {
1411
+ // Test that we get an error if the last argument is a flag requiring a
1412
+ // value.
1413
+
1414
+ Run("protocol_compiler --test_out");
1415
+
1416
+ ExpectErrorText("Missing value for flag: --test_out\n");
1417
+ }
1418
+
1419
+ TEST_F(CommandLineInterfaceTest, PrintFreeFieldNumbers) {
1420
+ CreateTempFile(
1421
+ "foo.proto",
1422
+ "syntax = \"proto2\";\n"
1423
+ "package foo;\n"
1424
+ "message Foo {\n"
1425
+ " optional int32 a = 2;\n"
1426
+ " optional string b = 4;\n"
1427
+ " optional string c = 5;\n"
1428
+ " optional int64 d = 8;\n"
1429
+ " optional double e = 10;\n"
1430
+ "}\n");
1431
+ CreateTempFile(
1432
+ "bar.proto",
1433
+ "syntax = \"proto2\";\n"
1434
+ "message Bar {\n"
1435
+ " optional int32 a = 2;\n"
1436
+ " extensions 4 to 5;\n"
1437
+ " optional int64 d = 8;\n"
1438
+ " extensions 10;\n"
1439
+ "}\n");
1440
+ CreateTempFile(
1441
+ "baz.proto",
1442
+ "syntax = \"proto2\";\n"
1443
+ "message Baz {\n"
1444
+ " optional int32 a = 2;\n"
1445
+ " optional int64 d = 8;\n"
1446
+ " extensions 15 to max;\n" // unordered.
1447
+ " extensions 13;\n"
1448
+ " extensions 10 to 12;\n"
1449
+ " extensions 5;\n"
1450
+ " extensions 4;\n"
1451
+ "}\n");
1452
+ CreateTempFile(
1453
+ "quz.proto",
1454
+ "syntax = \"proto2\";\n"
1455
+ "message Quz {\n"
1456
+ " message Foo {}\n" // nested message
1457
+ " optional int32 a = 2;\n"
1458
+ " optional group C = 4 {\n"
1459
+ " optional int32 d = 5;\n"
1460
+ " }\n"
1461
+ " extensions 8 to 10;\n"
1462
+ " optional group E = 11 {\n"
1463
+ " optional int32 f = 9;\n" // explicitly reuse extension range 8-10
1464
+ " optional group G = 15 {\n" // nested group
1465
+ " message Foo {}\n" // nested message inside nested group
1466
+ " }\n"
1467
+ " }\n"
1468
+ "}\n");
1469
+
1470
+ Run("protocol_compiler --print_free_field_numbers --proto_path=$tmpdir "
1471
+ "foo.proto bar.proto baz.proto quz.proto");
1472
+
1473
+ ExpectNoErrors();
1474
+
1475
+ // TODO(jieluo): Cygwin doesn't work well if we try to capture stderr and
1476
+ // stdout at the same time. Need to figure out why and add this test back
1477
+ // for Cygwin.
1478
+ #if !defined(__CYGWIN__)
1479
+ ExpectCapturedStdout(
1480
+ "foo.Foo free: 1 3 6-7 9 11-INF\n"
1481
+ "Bar free: 1 3 6-7 9 11-INF\n"
1482
+ "Baz free: 1 3 6-7 9 14\n"
1483
+ "Quz.Foo free: 1-INF\n"
1484
+ "Quz.E.G.Foo free: 1-INF\n"
1485
+ "Quz free: 1 3 6-7 12-14 16-INF\n");
1486
+ #endif
1487
+ }
1488
+
1489
+ // ===================================================================
1490
+
1491
+ // Test for --encode and --decode. Note that it would be easier to do this
1492
+ // test as a shell script, but we'd like to be able to run the test on
1493
+ // platforms that don't have a Bourne-compatible shell available (especially
1494
+ // Windows/MSVC).
1495
+ class EncodeDecodeTest : public testing::Test {
1496
+ protected:
1497
+ virtual void SetUp() {
1498
+ duped_stdin_ = dup(STDIN_FILENO);
1499
+ }
1500
+
1501
+ virtual void TearDown() {
1502
+ dup2(duped_stdin_, STDIN_FILENO);
1503
+ close(duped_stdin_);
1504
+ }
1505
+
1506
+ void RedirectStdinFromText(const string& input) {
1507
+ string filename = TestTempDir() + "/test_stdin";
1508
+ GOOGLE_CHECK_OK(File::SetContents(filename, input, true));
1509
+ GOOGLE_CHECK(RedirectStdinFromFile(filename));
1510
+ }
1511
+
1512
+ bool RedirectStdinFromFile(const string& filename) {
1513
+ int fd = open(filename.c_str(), O_RDONLY);
1514
+ if (fd < 0) return false;
1515
+ dup2(fd, STDIN_FILENO);
1516
+ close(fd);
1517
+ return true;
1518
+ }
1519
+
1520
+ // Remove '\r' characters from text.
1521
+ string StripCR(const string& text) {
1522
+ string result;
1523
+
1524
+ for (int i = 0; i < text.size(); i++) {
1525
+ if (text[i] != '\r') {
1526
+ result.push_back(text[i]);
1527
+ }
1528
+ }
1529
+
1530
+ return result;
1531
+ }
1532
+
1533
+ enum Type { TEXT, BINARY };
1534
+ enum ReturnCode { SUCCESS, ERROR };
1535
+
1536
+ bool Run(const string& command) {
1537
+ vector<string> args;
1538
+ args.push_back("protoc");
1539
+ SplitStringUsing(command, " ", &args);
1540
+ args.push_back("--proto_path=" + TestSourceDir());
1541
+
1542
+ scoped_array<const char*> argv(new const char* [args.size()]);
1543
+ for (int i = 0; i < args.size(); i++) {
1544
+ argv[i] = args[i].c_str();
1545
+ }
1546
+
1547
+ CommandLineInterface cli;
1548
+ cli.SetInputsAreProtoPathRelative(true);
1549
+
1550
+ CaptureTestStdout();
1551
+ CaptureTestStderr();
1552
+
1553
+ int result = cli.Run(args.size(), argv.get());
1554
+
1555
+ captured_stdout_ = GetCapturedTestStdout();
1556
+ captured_stderr_ = GetCapturedTestStderr();
1557
+
1558
+ return result == 0;
1559
+ }
1560
+
1561
+ void ExpectStdoutMatchesBinaryFile(const string& filename) {
1562
+ string expected_output;
1563
+ GOOGLE_CHECK_OK(File::GetContents(filename, &expected_output, true));
1564
+
1565
+ // Don't use EXPECT_EQ because we don't want to print raw binary data to
1566
+ // stdout on failure.
1567
+ EXPECT_TRUE(captured_stdout_ == expected_output);
1568
+ }
1569
+
1570
+ void ExpectStdoutMatchesTextFile(const string& filename) {
1571
+ string expected_output;
1572
+ GOOGLE_CHECK_OK(File::GetContents(filename, &expected_output, true));
1573
+
1574
+ ExpectStdoutMatchesText(expected_output);
1575
+ }
1576
+
1577
+ void ExpectStdoutMatchesText(const string& expected_text) {
1578
+ EXPECT_EQ(StripCR(expected_text), StripCR(captured_stdout_));
1579
+ }
1580
+
1581
+ void ExpectStderrMatchesText(const string& expected_text) {
1582
+ EXPECT_EQ(StripCR(expected_text), StripCR(captured_stderr_));
1583
+ }
1584
+
1585
+ private:
1586
+ int duped_stdin_;
1587
+ string captured_stdout_;
1588
+ string captured_stderr_;
1589
+ };
1590
+
1591
+ TEST_F(EncodeDecodeTest, Encode) {
1592
+ RedirectStdinFromFile(TestSourceDir() + "/google/protobuf/"
1593
+ "testdata/text_format_unittest_data_oneof_implemented.txt");
1594
+ EXPECT_TRUE(Run("google/protobuf/unittest.proto "
1595
+ "--encode=protobuf_unittest.TestAllTypes"));
1596
+ ExpectStdoutMatchesBinaryFile(TestSourceDir() +
1597
+ "/google/protobuf/testdata/golden_message_oneof_implemented");
1598
+ ExpectStderrMatchesText("");
1599
+ }
1600
+
1601
+ TEST_F(EncodeDecodeTest, Decode) {
1602
+ RedirectStdinFromFile(TestSourceDir() +
1603
+ "/google/protobuf/testdata/golden_message_oneof_implemented");
1604
+ EXPECT_TRUE(Run("google/protobuf/unittest.proto "
1605
+ "--decode=protobuf_unittest.TestAllTypes"));
1606
+ ExpectStdoutMatchesTextFile(TestSourceDir() +
1607
+ "/google/protobuf/"
1608
+ "testdata/text_format_unittest_data_oneof_implemented.txt");
1609
+ ExpectStderrMatchesText("");
1610
+ }
1611
+
1612
+ TEST_F(EncodeDecodeTest, Partial) {
1613
+ RedirectStdinFromText("");
1614
+ EXPECT_TRUE(Run("google/protobuf/unittest.proto "
1615
+ "--encode=protobuf_unittest.TestRequired"));
1616
+ ExpectStdoutMatchesText("");
1617
+ ExpectStderrMatchesText(
1618
+ "warning: Input message is missing required fields: a, b, c\n");
1619
+ }
1620
+
1621
+ TEST_F(EncodeDecodeTest, DecodeRaw) {
1622
+ protobuf_unittest::TestAllTypes message;
1623
+ message.set_optional_int32(123);
1624
+ message.set_optional_string("foo");
1625
+ string data;
1626
+ message.SerializeToString(&data);
1627
+
1628
+ RedirectStdinFromText(data);
1629
+ EXPECT_TRUE(Run("--decode_raw"));
1630
+ ExpectStdoutMatchesText("1: 123\n"
1631
+ "14: \"foo\"\n");
1632
+ ExpectStderrMatchesText("");
1633
+ }
1634
+
1635
+ TEST_F(EncodeDecodeTest, UnknownType) {
1636
+ EXPECT_FALSE(Run("google/protobuf/unittest.proto "
1637
+ "--encode=NoSuchType"));
1638
+ ExpectStdoutMatchesText("");
1639
+ ExpectStderrMatchesText("Type not defined: NoSuchType\n");
1640
+ }
1641
+
1642
+ TEST_F(EncodeDecodeTest, ProtoParseError) {
1643
+ EXPECT_FALSE(Run("google/protobuf/no_such_file.proto "
1644
+ "--encode=NoSuchType"));
1645
+ ExpectStdoutMatchesText("");
1646
+ ExpectStderrMatchesText(
1647
+ "google/protobuf/no_such_file.proto: File not found.\n");
1648
+ }
1649
+
1650
+ } // anonymous namespace
1651
+
1652
+ } // namespace compiler
1653
+ } // namespace protobuf
1654
+ } // namespace google