protobuf 2.8.0.beta9 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +0 -1
  3. data/{UPGRADING.md → CHANGES.md} +20 -12
  4. data/LICENSE.txt +14 -0
  5. data/README.md +60 -74
  6. data/bin/protoc-gen-ruby +26 -0
  7. data/bin/rprotoc +4 -58
  8. data/lib/protobuf.rb +15 -13
  9. data/lib/protobuf/code_generator.rb +41 -0
  10. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +51 -0
  11. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +248 -0
  12. data/lib/protobuf/field/base_field.rb +0 -1
  13. data/lib/protobuf/field/bytes_field.rb +1 -1
  14. data/lib/protobuf/field/message_field.rb +2 -4
  15. data/lib/protobuf/field/varint_field.rb +4 -7
  16. data/lib/protobuf/generators/base.rb +71 -0
  17. data/lib/protobuf/generators/enum_generator.rb +31 -0
  18. data/lib/protobuf/generators/extension_generator.rb +28 -0
  19. data/lib/protobuf/generators/field_generator.rb +132 -0
  20. data/lib/protobuf/generators/file_generator.rb +140 -0
  21. data/lib/protobuf/generators/group_generator.rb +113 -0
  22. data/lib/protobuf/generators/message_generator.rb +99 -0
  23. data/lib/protobuf/generators/printable.rb +161 -0
  24. data/lib/protobuf/generators/service_generator.rb +27 -0
  25. data/lib/protobuf/lifecycle.rb +7 -3
  26. data/lib/protobuf/message.rb +51 -34
  27. data/lib/protobuf/rpc/connectors/common.rb +4 -6
  28. data/lib/protobuf/rpc/server.rb +1 -1
  29. data/lib/protobuf/rpc/servers/zmq/server.rb +2 -2
  30. data/lib/protobuf/rpc/servers/zmq/worker.rb +2 -2
  31. data/lib/protobuf/rpc/service.rb +3 -3
  32. data/lib/protobuf/rpc/service_directory.rb +24 -12
  33. data/lib/protobuf/version.rb +1 -1
  34. data/proto/google/protobuf/compiler/plugin.proto +147 -0
  35. data/proto/google/protobuf/descriptor.proto +620 -0
  36. data/protobuf.gemspec +12 -21
  37. data/spec/bin/protoc-gen-ruby_spec.rb +18 -0
  38. data/spec/data/data.bin +3 -0
  39. data/{test/data/unk.png → spec/data/types.bin} +0 -0
  40. data/spec/encoding/all_types_spec.rb +91 -0
  41. data/spec/encoding/extreme_values_spec.rb +0 -0
  42. data/spec/lib/protobuf/code_generator_spec.rb +60 -0
  43. data/spec/lib/protobuf/generators/base_spec.rb +87 -0
  44. data/spec/lib/protobuf/generators/enum_generator_spec.rb +45 -0
  45. data/spec/lib/protobuf/generators/extension_generator_spec.rb +43 -0
  46. data/spec/lib/protobuf/generators/field_generator_spec.rb +99 -0
  47. data/spec/lib/protobuf/generators/file_generator_spec.rb +29 -0
  48. data/spec/lib/protobuf/generators/message_generator_spec.rb +0 -0
  49. data/spec/lib/protobuf/generators/service_generator_spec.rb +43 -0
  50. data/spec/lib/protobuf/lifecycle_spec.rb +31 -1
  51. data/spec/lib/protobuf/logger_spec.rb +5 -0
  52. data/spec/lib/protobuf/message_spec.rb +22 -8
  53. data/spec/lib/protobuf/rpc/connectors/common_spec.rb +1 -1
  54. data/spec/lib/protobuf/rpc/service_directory_spec.rb +45 -7
  55. data/spec/lib/protobuf/rpc/service_spec.rb +3 -3
  56. data/spec/spec_helper.rb +15 -16
  57. data/spec/support/test/all_types.data.bin +0 -0
  58. data/spec/support/test/all_types.data.txt +119 -0
  59. data/spec/support/test/defaults.pb.rb +25 -0
  60. data/spec/support/test/defaults.proto +9 -0
  61. data/spec/support/test/enum.pb.rb +10 -8
  62. data/spec/support/test/extended.pb.rb +5 -3
  63. data/spec/support/test/extreme_values.data.bin +0 -0
  64. data/spec/support/test/google_unittest.pb.rb +543 -0
  65. data/spec/support/test/google_unittest.proto +713 -0
  66. data/spec/support/test/google_unittest_import.pb.rb +37 -0
  67. data/{ext/protobuf-2.4.1/src/google/protobuf/io/package_info.h → spec/support/test/google_unittest_import.proto} +27 -17
  68. data/spec/support/test/google_unittest_import_public.pb.rb +8 -0
  69. data/{ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream_inl.h → spec/support/test/google_unittest_import_public.proto} +5 -31
  70. data/spec/support/test/multi_field_extensions.pb.rb +29 -7
  71. data/spec/support/test/multi_field_extensions.proto +12 -2
  72. data/spec/support/test/resource.pb.rb +20 -16
  73. metadata +149 -236
  74. data/examples/addressbook.pb.rb +0 -55
  75. data/examples/addressbook.proto +0 -24
  76. data/examples/reading_a_message.rb +0 -32
  77. data/examples/writing_a_message.rb +0 -46
  78. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/code_generator.h +0 -142
  79. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/command_line_interface.h +0 -318
  80. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum.h +0 -99
  81. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum_field.h +0 -103
  82. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_extension.h +0 -85
  83. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_field.h +0 -167
  84. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_file.h +0 -98
  85. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_generator.h +0 -72
  86. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_helpers.h +0 -159
  87. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message.h +0 -170
  88. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message_field.h +0 -102
  89. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_primitive_field.h +0 -103
  90. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_service.h +0 -118
  91. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_string_field.h +0 -104
  92. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h +0 -2721
  93. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/importer.h +0 -303
  94. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum.h +0 -84
  95. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum_field.h +0 -121
  96. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_extension.h +0 -77
  97. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_field.h +0 -108
  98. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_file.h +0 -101
  99. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_generator.h +0 -72
  100. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_helpers.h +0 -213
  101. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message.h +0 -109
  102. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message_field.h +0 -134
  103. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_primitive_field.h +0 -121
  104. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_service.h +0 -113
  105. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_string_field.h +0 -120
  106. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/mock_code_generator.h +0 -113
  107. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/package_info.h +0 -64
  108. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/parser.h +0 -434
  109. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.h +0 -73
  110. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.pb.h +0 -790
  111. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/python/python_generator.h +0 -156
  112. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/subprocess.h +0 -108
  113. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/zip_writer.h +0 -93
  114. data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.h +0 -1367
  115. data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.pb.h +0 -5223
  116. data/ext/protobuf-2.4.1/src/google/protobuf/descriptor_database.h +0 -366
  117. data/ext/protobuf-2.4.1/src/google/protobuf/dynamic_message.h +0 -136
  118. data/ext/protobuf-2.4.1/src/google/protobuf/extension_set.h +0 -904
  119. data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_reflection.h +0 -424
  120. data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_util.h +0 -82
  121. data/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream.h +0 -1102
  122. data/ext/protobuf-2.4.1/src/google/protobuf/io/gzip_stream.h +0 -207
  123. data/ext/protobuf-2.4.1/src/google/protobuf/io/printer.h +0 -136
  124. data/ext/protobuf-2.4.1/src/google/protobuf/io/tokenizer.h +0 -313
  125. data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream.h +0 -238
  126. data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl.h +0 -357
  127. data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl_lite.h +0 -340
  128. data/ext/protobuf-2.4.1/src/google/protobuf/message.h +0 -692
  129. data/ext/protobuf-2.4.1/src/google/protobuf/message_lite.h +0 -239
  130. data/ext/protobuf-2.4.1/src/google/protobuf/package_info.h +0 -64
  131. data/ext/protobuf-2.4.1/src/google/protobuf/reflection_ops.h +0 -80
  132. data/ext/protobuf-2.4.1/src/google/protobuf/repeated_field.h +0 -1295
  133. data/ext/protobuf-2.4.1/src/google/protobuf/service.h +0 -291
  134. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/common.h +0 -1211
  135. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/hash.h +0 -220
  136. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/map-util.h +0 -119
  137. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/once.h +0 -123
  138. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/stl_util-inl.h +0 -121
  139. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/strutil.h +0 -457
  140. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/substitute.h +0 -170
  141. data/ext/protobuf-2.4.1/src/google/protobuf/test_util.h +0 -174
  142. data/ext/protobuf-2.4.1/src/google/protobuf/test_util_lite.h +0 -101
  143. data/ext/protobuf-2.4.1/src/google/protobuf/testing/file.h +0 -83
  144. data/ext/protobuf-2.4.1/src/google/protobuf/testing/googletest.h +0 -98
  145. data/ext/protobuf-2.4.1/src/google/protobuf/text_format.h +0 -285
  146. data/ext/protobuf-2.4.1/src/google/protobuf/unittest.pb.h +0 -11915
  147. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_custom_options.pb.h +0 -2895
  148. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_embed_optimize_for.pb.h +0 -211
  149. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_empty.pb.h +0 -56
  150. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import.pb.h +0 -188
  151. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import_lite.pb.h +0 -151
  152. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite.pb.h +0 -4752
  153. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite_imports_nonlite.pb.h +0 -150
  154. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_mset.pb.h +0 -816
  155. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_no_generic_services.pb.h +0 -197
  156. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_optimize_for.pb.h +0 -403
  157. data/ext/protobuf-2.4.1/src/google/protobuf/unknown_field_set.h +0 -268
  158. data/ext/protobuf-2.4.1/src/google/protobuf/wire_format.h +0 -304
  159. data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite.h +0 -620
  160. data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite_inl.h +0 -774
  161. data/ext/ruby_generator/Makefile +0 -10
  162. data/ext/ruby_generator/RubyGenerator.cpp +0 -544
  163. data/ext/ruby_generator/RubyGenerator.h +0 -206
  164. data/ext/ruby_generator/extconf.rb +0 -35
  165. data/test/data/data_source.py +0 -14
  166. data/test/data/types_source.py +0 -22
  167. data/test/proto/addressbook.pb.rb +0 -66
  168. data/test/proto/addressbook.proto +0 -33
  169. data/test/proto/addressbook_base.pb.rb +0 -58
  170. data/test/proto/addressbook_base.proto +0 -26
  171. data/test/proto/addressbook_ext.pb.rb +0 -20
  172. data/test/proto/addressbook_ext.proto +0 -6
  173. data/test/proto/collision.pb.rb +0 -17
  174. data/test/proto/collision.proto +0 -5
  175. data/test/proto/ext_collision.pb.rb +0 -24
  176. data/test/proto/ext_collision.proto +0 -8
  177. data/test/proto/ext_range.pb.rb +0 -22
  178. data/test/proto/ext_range.proto +0 -7
  179. data/test/proto/float_default.proto +0 -10
  180. data/test/proto/lowercase.pb.rb +0 -30
  181. data/test/proto/lowercase.proto +0 -9
  182. data/test/proto/merge.pb.rb +0 -39
  183. data/test/proto/merge.proto +0 -15
  184. data/test/proto/nested.pb.rb +0 -30
  185. data/test/proto/nested.proto +0 -9
  186. data/test/proto/optional_field.pb.rb +0 -35
  187. data/test/proto/optional_field.proto +0 -12
  188. data/test/proto/packed.pb.rb +0 -22
  189. data/test/proto/packed.proto +0 -6
  190. data/test/proto/rpc.proto +0 -6
  191. data/test/proto/types.pb.rb +0 -84
  192. data/test/proto/types.proto +0 -37
  193. data/test/test_addressbook.rb +0 -56
  194. data/test/test_enum_value.rb +0 -41
  195. data/test/test_extension.rb +0 -36
  196. data/test/test_lowercase.rb +0 -11
  197. data/test/test_message.rb +0 -128
  198. data/test/test_optional_field.rb +0 -103
  199. data/test/test_packed_field.rb +0 -40
  200. data/test/test_parse.rb +0 -15
  201. data/test/test_repeated_types.rb +0 -132
  202. data/test/test_serialize.rb +0 -61
  203. data/test/test_standard_message.rb +0 -96
  204. data/test/test_types.rb +0 -226
data/protobuf.gemspec CHANGED
@@ -1,44 +1,35 @@
1
1
  # encoding: UTF-8
2
- $:.push File.expand_path("./lib", File.dirname(__FILE__))
2
+ $:.push ::File.expand_path("../lib", __FILE__)
3
3
  require "protobuf/version"
4
4
 
5
- Gem::Specification.new do |s|
5
+ ::Gem::Specification.new do |s|
6
6
  s.name = 'protobuf'
7
- s.version = Protobuf::VERSION
8
- s.date = Time.now.strftime('%Y-%m-%d')
7
+ s.version = ::Protobuf::VERSION
8
+ s.date = ::Time.now.strftime('%Y-%m-%d')
9
+ s.license = 'WTFPL'
9
10
 
10
- s.authors = ['BJ Neilsen', 'Brandon Dewitt']
11
- s.email = ["bj.neilsen+protobuf@gmail.com", "brandonsdewitt+protobuf@gmail.com"]
12
- s.homepage = "https://github.com/localshred/protobuf"
13
- s.summary = "Google Protocol Buffers v#{Protobuf::PROTOC_VERSION} Serialization and RPC implementation for Ruby."
11
+ s.authors = ['BJ Neilsen', 'Brandon Dewitt', 'Devin Christensen']
12
+ s.email = ['bj.neilsen+protobuf@gmail.com', 'brandonsdewitt+protobuf@gmail.com', 'quixoten@gmail.com']
13
+ s.homepage = 'https://github.com/localshred/protobuf'
14
+ s.summary = "Google Protocol Buffers serialization and RPC implementation for Ruby."
14
15
  s.description = s.summary
15
16
 
16
17
  s.files = `git ls-files`.split("\n")
17
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
19
20
  s.require_paths = ["lib"]
20
21
 
21
- unless ENV['WITHOUT_PROTO_COMPILER']
22
- if defined?(JRUBY_VERSION)
23
- s.platform = 'java'
24
- else
25
- s.extensions << File.join('ext', 'ruby_generator', 'extconf.rb')
26
- end
27
- end
28
-
29
- s.add_dependency 'activesupport'
30
- s.add_dependency 'ffi'
22
+ s.add_dependency 'activesupport', '< 4.0'
31
23
  s.add_dependency 'multi_json'
32
24
  s.add_dependency 'thor'
33
25
 
34
26
  s.add_development_dependency 'eventmachine'
35
27
  s.add_development_dependency 'ffi-rzmq'
36
- # s.add_development_dependency 'perftools.rb'
37
- s.add_development_dependency 'pry'
38
28
  s.add_development_dependency 'pry-nav'
39
29
  s.add_development_dependency 'rake'
40
30
  s.add_development_dependency 'rake-compiler'
41
31
  s.add_development_dependency 'rspec'
42
32
  s.add_development_dependency 'simplecov'
43
33
  s.add_development_dependency 'yard'
34
+ # s.add_development_dependency 'perftools.rb'
44
35
  end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ require 'protobuf/code_generator'
4
+
5
+ describe 'protoc-gen-ruby' do
6
+ let(:binpath) { ::File.expand_path('../../../bin/protoc-gen-ruby', __FILE__) }
7
+ let(:request_bytes) { ::Google::Protobuf::Compiler::CodeGeneratorRequest.new(:file_to_generate => [ "test/foo.proto" ]) }
8
+ let(:expected_file) { ::Google::Protobuf::Compiler::CodeGeneratorResponse::File.new(:name => 'test/foo.pb.rb') }
9
+ let(:expected_response_bytes) { ::Google::Protobuf::Compiler::CodeGeneratorRequest.encode(:files => [ expected_file ]) }
10
+
11
+ it 'reads the serialized request bytes and outputs serialized response bytes' do
12
+ ::IO.popen(binpath, 'w+') do |pipe|
13
+ pipe.write(request_bytes)
14
+ pipe.read(expected_response_bytes.size).should eq expected_response_bytes
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,3 @@
1
+
2
+ John Doe� jdoe@example.com"
3
+ 555-4321
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ describe ::Protobuf do
4
+ it "correctly encodes all types" do
5
+ message = GoogleUnittest::TestAllTypes.new(
6
+ optional_int32: 101,
7
+ optional_int64: 102,
8
+ optional_uint32: 103,
9
+ optional_uint64: 104,
10
+ optional_sint32: 105,
11
+ optional_sint64: 106,
12
+ optional_fixed32: 107,
13
+ optional_fixed64: 108,
14
+ optional_sfixed32: 109,
15
+ optional_sfixed64: 110,
16
+ optional_float: 111,
17
+ optional_double: 112,
18
+ optional_bool: true,
19
+ optional_string: "115",
20
+ optional_bytes: "116",
21
+ optional_nested_message: GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 118),
22
+ optional_foreign_message: GoogleUnittest::ForeignMessage.new(c: 119),
23
+ optional_import_message: GoogleUnittestImport::ImportMessage.new(d: 120),
24
+ optional_nested_enum: GoogleUnittest::TestAllTypes::NestedEnum::BAZ,
25
+ optional_foreign_enum: GoogleUnittest::ForeignEnum::FOREIGN_BAZ,
26
+ optional_import_enum: GoogleUnittestImport::ImportEnum::IMPORT_BAZ,
27
+ optional_string_piece: "124",
28
+ optional_cord: "125",
29
+ optional_public_import_message: GoogleUnittestImport::PublicImportMessage.new(e: 126),
30
+ optional_lazy_message: GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 127),
31
+ repeated_int32: [201, 301],
32
+ repeated_int64: [202, 302],
33
+ repeated_uint32: [203, 303],
34
+ repeated_uint64: [204, 304],
35
+ repeated_sint32: [205, 305],
36
+ repeated_sint64: [206, 306],
37
+ repeated_fixed32: [207, 307],
38
+ repeated_fixed64: [208, 308],
39
+ repeated_sfixed32: [209, 309],
40
+ repeated_sfixed64: [210, 310],
41
+ repeated_float: [211, 311],
42
+ repeated_double: [212, 312],
43
+ repeated_bool: [true, false],
44
+ repeated_string: ["215", "315"],
45
+ repeated_bytes: ["216", "316"],
46
+ repeated_nested_message: [::GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 218),
47
+ ::GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 318)],
48
+ repeated_foreign_message: [::GoogleUnittest::ForeignMessage.new(c: 219),
49
+ ::GoogleUnittest::ForeignMessage.new(c: 319)],
50
+ repeated_import_message: [::GoogleUnittestImport::ImportMessage.new(d: 220),
51
+ ::GoogleUnittestImport::ImportMessage.new(d: 320)],
52
+ repeated_nested_enum: [::GoogleUnittest::TestAllTypes::NestedEnum::BAR,
53
+ ::GoogleUnittest::TestAllTypes::NestedEnum::BAZ],
54
+ repeated_foreign_enum: [::GoogleUnittest::ForeignEnum::FOREIGN_BAR,
55
+ ::GoogleUnittest::ForeignEnum::FOREIGN_BAZ],
56
+ repeated_import_enum: [::GoogleUnittestImport::ImportEnum::IMPORT_BAR,
57
+ ::GoogleUnittestImport::ImportEnum::IMPORT_BAZ],
58
+ repeated_string_piece: ["224", "324"],
59
+ repeated_cord: ["225", "325"],
60
+ repeated_lazy_message: [::GoogleUnittest::TestAllTypes::NestedMessage.new(bb:227),
61
+ ::GoogleUnittest::TestAllTypes::NestedMessage.new(bb:327)],
62
+ default_int32: 401,
63
+ default_int64: 402,
64
+ default_uint32: 403,
65
+ default_uint64: 404,
66
+ default_sint32: 405,
67
+ default_sint64: 406,
68
+ default_fixed32: 407,
69
+ default_fixed64: 408,
70
+ default_sfixed32: 409,
71
+ default_sfixed64: 410,
72
+ default_float: 411,
73
+ default_double: 412,
74
+ default_bool: false,
75
+ default_string: "415",
76
+ default_bytes: "416",
77
+ default_nested_enum: ::GoogleUnittest::TestAllTypes::NestedEnum::FOO,
78
+ default_foreign_enum: ::GoogleUnittest::ForeignEnum::FOREIGN_FOO,
79
+ default_import_enum: ::GoogleUnittestImport::ImportEnum::IMPORT_FOO,
80
+ default_string_piece: "424",
81
+ default_cord: "425",
82
+ )
83
+
84
+ data_file_path = File.expand_path('../../support/test/all_types.data.bin', __FILE__)
85
+ data = File.open(data_file_path, 'rb') do |file|
86
+ file.read
87
+ end
88
+
89
+ data.should eq message.serialize_to_string
90
+ end
91
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ require 'protobuf/code_generator'
4
+
5
+ describe ::Protobuf::CodeGenerator do
6
+
7
+ # Some constants to shorten things up
8
+ DESCRIPTOR = ::Google::Protobuf
9
+ COMPILER = ::Google::Protobuf::Compiler
10
+
11
+ describe '#response_bytes' do
12
+ let(:input_file1) { DESCRIPTOR::FileDescriptorProto.new(:name => 'test/foo.proto') }
13
+ let(:input_file2) { DESCRIPTOR::FileDescriptorProto.new(:name => 'test/bar.proto') }
14
+
15
+ let(:output_file1) { COMPILER::CodeGeneratorResponse::File.new(:name => 'test/foo.pb.rb') }
16
+ let(:output_file2) { COMPILER::CodeGeneratorResponse::File.new(:name => 'test/bar.pb.rb') }
17
+
18
+ let(:file_generator1) { mock('file generator 1', :generate_output_file => output_file1) }
19
+ let(:file_generator2) { mock('file generator 2', :generate_output_file => output_file2) }
20
+
21
+ let(:request_bytes) do
22
+ COMPILER::CodeGeneratorRequest.encode(:proto_file => [ input_file1, input_file2 ])
23
+ end
24
+
25
+ let(:expected_response_bytes) do
26
+ COMPILER::CodeGeneratorResponse.encode(:file => [ output_file1, output_file2 ])
27
+ end
28
+
29
+ before do
30
+ ::Protobuf::Generators::FileGenerator.should_receive(:new).with(input_file1).and_return(file_generator1)
31
+ ::Protobuf::Generators::FileGenerator.should_receive(:new).with(input_file2).and_return(file_generator2)
32
+ end
33
+
34
+ it 'returns the serialized CodeGeneratorResponse which contains the generated file contents' do
35
+ generator = described_class.new(request_bytes)
36
+ generator.response_bytes.should eq expected_response_bytes
37
+ end
38
+ end
39
+
40
+ context 'class-level printing methods' do
41
+ describe '.fatal' do
42
+ it 'raises a CodeGeneratorFatalError error' do
43
+ expect {
44
+ described_class.fatal("something is wrong")
45
+ }.to raise_error(
46
+ ::Protobuf::CodeGenerator::CodeGeneratorFatalError,
47
+ "something is wrong"
48
+ )
49
+ end
50
+ end
51
+
52
+ describe '.warn' do
53
+ it 'prints a warning to stderr' do
54
+ STDERR.should_receive(:puts).with("[WARN] a warning")
55
+ described_class.warn("a warning")
56
+ end
57
+ end
58
+ end
59
+
60
+ end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+
3
+ require 'protobuf/code_generator'
4
+ require 'protobuf/generators/base'
5
+
6
+ describe ::Protobuf::Generators::Base do
7
+
8
+ subject { described_class.new(mock) }
9
+
10
+ context 'namespaces' do
11
+ let(:descriptor) { mock(:name => 'Baz') }
12
+ subject { described_class.new(descriptor, 0, :namespace => [ :foo, :bar ]) }
13
+ its(:type_namespace) { should eq [ :foo, :bar, 'Baz' ] }
14
+ its(:fully_qualified_type_namespace) { should eq '.foo.bar.Baz' }
15
+ end
16
+
17
+ describe '#run_once' do
18
+ it 'protects the block from being entered more than once' do
19
+ foo = 0
20
+ bar = 0
21
+
22
+ test_run_once = lambda do
23
+ bar += 1
24
+ subject.run_once(:foo_test) do
25
+ foo += 1
26
+ end
27
+ end
28
+
29
+ 10.times { test_run_once.call }
30
+ expect(foo).to eq(1)
31
+ expect(bar).to eq(10)
32
+ end
33
+
34
+ it 'always returns the same object' do
35
+ rv = subject.run_once(:foo_test) do
36
+ "foo bar"
37
+ end
38
+ expect(rv).to eq("foo bar")
39
+
40
+ rv = subject.run_once(:foo_test) do
41
+ "baz quux"
42
+ end
43
+ expect(rv).to eq("foo bar")
44
+ end
45
+ end
46
+
47
+ describe '#to_s' do
48
+ before do
49
+ class ToStringTest < ::Protobuf::Generators::Base
50
+ def compile
51
+ run_once(:compile) do
52
+ puts "this is a test"
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ subject { ToStringTest.new(mock) }
59
+
60
+ it 'compiles and returns the contents' do
61
+ 10.times do
62
+ expect(subject.to_s).to eq("this is a test\n")
63
+ end
64
+ end
65
+ end
66
+
67
+ describe '#validate_tags' do
68
+ context 'when tags are duplicated' do
69
+ it 'fails with a GeneratorFatalError' do
70
+ ::Protobuf::CodeGenerator.should_receive(:fatal)
71
+ .with(/FooBar object has duplicate tags\. Expected 3 tags, but got 4/)
72
+
73
+ described_class.validate_tags("FooBar", [1,2,2,3])
74
+ end
75
+ end
76
+
77
+ context 'when tags are missing in the range' do
78
+ it 'prints a warning' do
79
+ ::Protobuf::CodeGenerator.should_receive(:warn)
80
+ .with(/FooBar object should have 5 tags \(1\.\.5\), but found 4 tags/)
81
+ described_class.validate_tags("FooBar", [1,2,4,5])
82
+ end
83
+ end
84
+ end
85
+
86
+ end
87
+
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ require 'protobuf/generators/enum_generator'
4
+
5
+ describe ::Protobuf::Generators::EnumGenerator do
6
+
7
+ let(:values) {
8
+ [
9
+ { :name => 'FOO', :number => 1 },
10
+ { :name => 'BAR', :number => 2 },
11
+ { :name => 'BAZ', :number => 3 }
12
+ ]
13
+ }
14
+ let(:enum_fields) { { :name => 'TestEnum',
15
+ :value => values } }
16
+
17
+ let(:enum) { ::Google::Protobuf::EnumDescriptorProto.new(enum_fields) }
18
+
19
+ subject { described_class.new(enum) }
20
+
21
+ describe '#compile' do
22
+ let(:compiled) {
23
+ %q{class TestEnum < ::Protobuf::Enum
24
+ define :FOO, 1
25
+ define :BAR, 2
26
+ define :BAZ, 3
27
+ end
28
+
29
+ }
30
+ }
31
+
32
+ it 'compiles the enum and it\'s field values' do
33
+ subject.compile
34
+ subject.to_s.should eq(compiled)
35
+ end
36
+ end
37
+
38
+ describe '#build_value' do
39
+ it 'returns a string identifying the given enum value' do
40
+ subject.build_value(enum.value.first).should eq("define :FOO, 1")
41
+ end
42
+ end
43
+
44
+ end
45
+
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ require 'protobuf/code_generator'
4
+ require 'protobuf/generators/extension_generator'
5
+
6
+ describe ::Protobuf::Generators::ExtensionGenerator do
7
+
8
+ let(:field_descriptors) {
9
+ [
10
+ mock('field descriptor 1', :to_s => " field 1\n"),
11
+ mock('field descriptor 2', :to_s => " field 2\n"),
12
+ mock('field descriptor 3', :to_s => " field 3\n")
13
+ ]
14
+ }
15
+ let(:message_type) { 'FooBar' }
16
+
17
+ before do
18
+ ::Protobuf::Generators::FieldGenerator.should_receive(:new).with(field_descriptors[0], 1).and_return(field_descriptors[0])
19
+ ::Protobuf::Generators::FieldGenerator.should_receive(:new).with(field_descriptors[1], 1).and_return(field_descriptors[1])
20
+ ::Protobuf::Generators::FieldGenerator.should_receive(:new).with(field_descriptors[2], 1).and_return(field_descriptors[2])
21
+ end
22
+
23
+ subject { described_class.new(message_type, field_descriptors, 0) }
24
+
25
+ describe '#compile' do
26
+ let(:compiled) {
27
+ %q{class FooBar < ::Protobuf::Message
28
+ field 1
29
+ field 2
30
+ field 3
31
+ end
32
+
33
+ }
34
+ }
35
+
36
+ it 'compiles the a class with the extension fields' do
37
+ subject.compile
38
+ subject.to_s.should eq(compiled)
39
+ end
40
+ end
41
+
42
+ end
43
+
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+
3
+ require 'protobuf/generators/field_generator'
4
+
5
+ describe ::Protobuf::Generators::FieldGenerator do
6
+
7
+ let(:label_enum) { :LABEL_OPTIONAL }
8
+ let(:name) { 'foo_bar' }
9
+ let(:number) { 3 }
10
+ let(:type_enum) { :TYPE_STRING }
11
+ let(:type_name) { nil }
12
+ let(:default_value) { nil }
13
+ let(:extendee) { nil }
14
+ let(:field_options) { {} }
15
+
16
+ let(:field_fields) { { :label => label_enum,
17
+ :name => name,
18
+ :number => number,
19
+ :type => type_enum,
20
+ :type_name => type_name,
21
+ :default_value => default_value,
22
+ :extendee => extendee,
23
+ :options => field_options } }
24
+
25
+ let(:field) { ::Google::Protobuf::FieldDescriptorProto.new(field_fields) }
26
+
27
+ describe '#compile' do
28
+ subject { described_class.new(field).to_s }
29
+
30
+ it { should eq "optional ::Protobuf::Field::StringField, :foo_bar, 3\n" }
31
+
32
+ context 'when the type is another message' do
33
+ let(:type_enum) { :TYPE_MESSAGE }
34
+ let(:type_name) { '.foo.bar.Baz' }
35
+
36
+ it { should eq "optional ::Foo::Bar::Baz, :foo_bar, 3\n" }
37
+ end
38
+
39
+ context 'when a default value is used' do
40
+ let(:type_enum) { :TYPE_INT32 }
41
+ let(:default_value) { '42' }
42
+ it { should eq "optional ::Protobuf::Field::Int32Field, :foo_bar, 3, :default => 42\n" }
43
+
44
+ context 'when type is an enum' do
45
+ let(:type_enum) { :TYPE_ENUM }
46
+ let(:type_name) { '.foo.bar.Baz' }
47
+ let(:default_value) { 'QUUX' }
48
+
49
+ it { should eq "optional ::Foo::Bar::Baz, :foo_bar, 3, :default => ::Foo::Bar::Baz::QUUX\n" }
50
+ end
51
+
52
+ context 'when the type is a string' do
53
+ let(:type_enum) { :TYPE_STRING }
54
+ let(:default_value) { "a default \"string\"" }
55
+
56
+ it { should eq %Q{optional ::Protobuf::Field::StringField, :foo_bar, 3, :default => "a default \"string\""\n} }
57
+ end
58
+
59
+ context 'when float or double field type' do
60
+ let(:type_enum) { :TYPE_DOUBLE }
61
+
62
+ context 'when the default value is "nan"' do
63
+ let(:default_value) { 'nan' }
64
+ it { should match(/::Float::NAN/) }
65
+ end
66
+
67
+ context 'when the default value is "inf"' do
68
+ let(:default_value) { 'inf' }
69
+ it { should match(/::Float::INFINITY/) }
70
+ end
71
+
72
+ context 'when the default value is "-inf"' do
73
+ let(:default_value) { '-inf' }
74
+ it { should match(/-::Float::INFINITY/) }
75
+ end
76
+ end
77
+ end
78
+
79
+ context 'when the field is an extension' do
80
+ let(:extendee) { 'foo.bar.Baz' }
81
+
82
+ it { should eq "optional ::Protobuf::Field::StringField, :foo_bar, 3, :extension => true\n" }
83
+ end
84
+
85
+ context 'when field is packed' do
86
+ let(:field_options) { { :packed => true } }
87
+
88
+ it { should eq "optional ::Protobuf::Field::StringField, :foo_bar, 3, :packed => true\n" }
89
+ end
90
+
91
+ context 'when field is deprecated' do
92
+ let(:field_options) { { :deprecated => true } }
93
+
94
+ it { should eq "optional ::Protobuf::Field::StringField, :foo_bar, 3, :deprecated => true\n" }
95
+ end
96
+ end
97
+
98
+ end
99
+