google-protobuf 3.21.12-java → 3.22.0-java

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of google-protobuf might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5ecc5e38a2f0ca009a14f6b404b7dea2ae0e55288a0a97e0fa38056eb04570e
4
- data.tar.gz: 1889f0affe5ea3d758e34b2f85f1cfaeec5c76a088f2e2b40504e7d76f06df42
3
+ metadata.gz: 2f8458cf5a18c8568d08d64f2700faf7e7a06f8ff7a3ff31491a59e2c3df8d9e
4
+ data.tar.gz: 70cc0e7750753568a933b6e91d3e10c8f6eac6ca38731e648e5a7677044d1019
5
5
  SHA512:
6
- metadata.gz: f7dfafd8c61370574fbf9bae88c5ad39c3015e89f74e2ebf943b0828a36fe61819b3e28363746bdf49b2194bec4f5ddf94b1fd9de6e7c79681bd37fd6d720dd6
7
- data.tar.gz: 70605c8d11270aeb1079d06f251fe38c3d6cfcf20215acadaceef4a12c463de0a0379136ced0532fb24aed867b38ad45030df1eefbcafff67221e33035511c0c
6
+ metadata.gz: e7ffd40db8498f83305bb22b7b9978ec7105deb594777a8a652a271052b5c826a66f371b078e19475771b39e1819872f5bc36d70e56b1cefd852bafc665cb6a7
7
+ data.tar.gz: 3fa901c9b4003f6e48ae4a7a904c8f50472281b986c0b06fbdb7551db67b10c90b3472112debffdd2b2ca14598a6c541691ed1b6735a3f13b363da09c72018ff
File without changes
File without changes
File without changes
@@ -29,6 +29,8 @@ module Google
29
29
  FieldOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldOptions").msgclass
30
30
  FieldOptions::CType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldOptions.CType").enummodule
31
31
  FieldOptions::JSType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldOptions.JSType").enummodule
32
+ FieldOptions::OptionRetention = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldOptions.OptionRetention").enummodule
33
+ FieldOptions::OptionTargetType = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.FieldOptions.OptionTargetType").enummodule
32
34
  OneofOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.OneofOptions").msgclass
33
35
  EnumOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumOptions").msgclass
34
36
  EnumValueOptions = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.EnumValueOptions").msgclass
@@ -41,6 +43,7 @@ module Google
41
43
  SourceCodeInfo::Location = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.SourceCodeInfo.Location").msgclass
42
44
  GeneratedCodeInfo = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.GeneratedCodeInfo").msgclass
43
45
  GeneratedCodeInfo::Annotation = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.GeneratedCodeInfo.Annotation").msgclass
46
+ GeneratedCodeInfo::Annotation::Semantic = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.GeneratedCodeInfo.Annotation.Semantic").enummodule
44
47
  end
45
48
  end
46
49
 
@@ -48,7 +51,7 @@ __END__
48
51
 
49
52
  google/protobuf/descriptor.protogoogle.protobuf"G
50
53
  FileDescriptorSet2
51
- file ( 2$.google.protobuf.FileDescriptorProto"�
54
+ file ( 2$.google.protobuf.FileDescriptorProto"�
52
55
  FileDescriptorProto
53
56
  name ( 
54
57
  package ( 
@@ -63,7 +66,8 @@ dependency ( 
63
66
  extension ( 2%.google.protobuf.FieldDescriptorProto-
64
67
  options ( 2.google.protobuf.FileOptions9
65
68
  source_code_info ( 2.google.protobuf.SourceCodeInfo
66
- syntax ( "�
69
+ syntax ( 
70
+ edition
67
71
  ( "�
68
72
  DescriptorProto
69
73
  name ( 4
70
74
  field ( 2%.google.protobuf.FieldDescriptorProto8
@@ -184,15 +188,16 @@ deprecated (:false
184
188
  OptimizeMode
185
189
  SPEED
186
190
  CODE_SIZE
187
- LITE_RUNTIME* �����J&'"�
191
+ LITE_RUNTIME* �����J&'"�
188
192
  MessageOptions&
189
193
  message_set_wire_format (:false.
190
194
  no_standard_descriptor_accessor (:false
191
195
 
192
196
  deprecated (:false
193
- map_entry (C
197
+ map_entry (2
198
+ &deprecated_legacy_json_field_conflicts (BC
194
199
  uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����JJJJ J 
195
- "�
200
+ "�
196
201
  FieldOptions:
197
202
  ctype (2#.google.protobuf.FieldOptions.CType:STRING
198
203
  packed (?
@@ -202,7 +207,10 @@ deprecated (:false
202
207
 
203
208
  deprecated (:false
204
209
  weak
205
- (:falseC
210
+ (:false
211
+ debug_redact (:false@
212
+ retention (2-.google.protobuf.FieldOptions.OptionRetention>
213
+ target (2..google.protobuf.FieldOptions.OptionTargetTypeC
206
214
  uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption"/
207
215
  CType
208
216
 
@@ -212,13 +220,29 @@ deprecated (:false
212
220
  JSType
213
221
  JS_NORMAL
214
222
  JS_STRING
215
- JS_NUMBER* �����J"^
223
+ JS_NUMBER"U
224
+ OptionRetention
225
+ RETENTION_UNKNOWN
226
+ RETENTION_RUNTIME
227
+ RETENTION_SOURCE"�
228
+ OptionTargetType
229
+ TARGET_TYPE_UNKNOWN
230
+ TARGET_TYPE_FILE
231
+ TARGET_TYPE_EXTENSION_RANGE
232
+ TARGET_TYPE_MESSAGE
233
+ TARGET_TYPE_FIELD
234
+ TARGET_TYPE_ONEOF
235
+ TARGET_TYPE_ENUM
236
+ TARGET_TYPE_ENUM_ENTRY
237
+ TARGET_TYPE_SERVICE
238
+ TARGET_TYPE_METHOD * �����J"^
216
239
  OneofOptionsC
217
- uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����"�
240
+ uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����"�
218
241
  EnumOptions
219
242
  allow_alias (
220
243
 
221
- deprecated (:falseC
244
+ deprecated (:false2
245
+ &deprecated_legacy_json_field_conflicts (BC
222
246
  uninterpreted_option� ( 2$.google.protobuf.UninterpretedOption* �����J"}
223
247
  EnumValueOptions
224
248
 
@@ -256,14 +280,19 @@ IDEMPOTENT* 
256
280
  span (B
257
281
  leading_comments ( 
258
282
  trailing_comments ( !
259
- leading_detached_comments ( "�
283
+ leading_detached_comments ( "�
260
284
  GeneratedCodeInfoA
261
285
 
262
- annotation ( 2-.google.protobuf.GeneratedCodeInfo.AnnotationO
286
+ annotation ( 2-.google.protobuf.GeneratedCodeInfo.Annotation�
263
287
 
264
288
  Annotation
265
289
  path (B
266
290
  source_file ( 
267
291
  begin (
268
- end (B~
292
+ end (H
293
+ semantic (26.google.protobuf.GeneratedCodeInfo.Annotation.Semantic"(
294
+ Semantic
295
+ NONE
296
+ SET
297
+ ALIASB~
269
298
  com.google.protobufBDescriptorProtosHZ-google.golang.org/protobuf/types/descriptorpb��GPB�Google.Protobuf.Reflection
File without changes
File without changes
File without changes
@@ -49,5 +49,10 @@ module Google
49
49
  end
50
50
 
51
51
  end
52
+ class AbstractMessage
53
+ include MessageExts
54
+ extend MessageExts::ClassMethods
55
+ end
56
+ private_constant :AbstractMessage
52
57
  end
53
58
  end
@@ -0,0 +1,50 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: google/protobuf/compiler/plugin.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ require 'google/protobuf/descriptor_pb'
7
+
8
+ Google::Protobuf::DescriptorPool.generated_pool.build do
9
+ add_file("google/protobuf/compiler/plugin.proto", :syntax => :proto2) do
10
+ add_message "google.protobuf.compiler.Version" do
11
+ optional :major, :int32, 1
12
+ optional :minor, :int32, 2
13
+ optional :patch, :int32, 3
14
+ optional :suffix, :string, 4
15
+ end
16
+ add_message "google.protobuf.compiler.CodeGeneratorRequest" do
17
+ repeated :file_to_generate, :string, 1
18
+ optional :parameter, :string, 2
19
+ repeated :proto_file, :message, 15, "google.protobuf.FileDescriptorProto"
20
+ optional :compiler_version, :message, 3, "google.protobuf.compiler.Version"
21
+ end
22
+ add_message "google.protobuf.compiler.CodeGeneratorResponse" do
23
+ optional :error, :string, 1
24
+ optional :supported_features, :uint64, 2
25
+ repeated :file, :message, 15, "google.protobuf.compiler.CodeGeneratorResponse.File"
26
+ end
27
+ add_message "google.protobuf.compiler.CodeGeneratorResponse.File" do
28
+ optional :name, :string, 1
29
+ optional :insertion_point, :string, 2
30
+ optional :content, :string, 15
31
+ optional :generated_code_info, :message, 16, "google.protobuf.GeneratedCodeInfo"
32
+ end
33
+ add_enum "google.protobuf.compiler.CodeGeneratorResponse.Feature" do
34
+ value :FEATURE_NONE, 0
35
+ value :FEATURE_PROTO3_OPTIONAL, 1
36
+ end
37
+ end
38
+ end
39
+
40
+ module Google
41
+ module Protobuf
42
+ module Compiler
43
+ Version = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.compiler.Version").msgclass
44
+ CodeGeneratorRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.compiler.CodeGeneratorRequest").msgclass
45
+ CodeGeneratorResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.compiler.CodeGeneratorResponse").msgclass
46
+ CodeGeneratorResponse::File = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.compiler.CodeGeneratorResponse.File").msgclass
47
+ CodeGeneratorResponse::Feature = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("google.protobuf.compiler.CodeGeneratorResponse.Feature").enummodule
48
+ end
49
+ end
50
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-protobuf
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.21.12
4
+ version: 3.22.0
5
5
  platform: java
6
6
  authors:
7
7
  - Protobuf Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-14 00:00:00.000000000 Z
11
+ date: 2023-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -59,6 +59,7 @@ files:
59
59
  - lib/google/protobuf/empty_pb.rb
60
60
  - lib/google/protobuf/field_mask_pb.rb
61
61
  - lib/google/protobuf/message_exts.rb
62
+ - lib/google/protobuf/plugin_pb.rb
62
63
  - lib/google/protobuf/repeated_field.rb
63
64
  - lib/google/protobuf/source_context_pb.rb
64
65
  - lib/google/protobuf/struct_pb.rb
@@ -67,14 +68,11 @@ files:
67
68
  - lib/google/protobuf/well_known_types.rb
68
69
  - lib/google/protobuf/wrappers_pb.rb
69
70
  - lib/google/protobuf_java.jar
70
- - tests/basic.rb
71
- - tests/generated_code_test.rb
72
- - tests/stress.rb
73
71
  homepage: https://developers.google.com/protocol-buffers
74
72
  licenses:
75
73
  - BSD-3-Clause
76
74
  metadata:
77
- source_code_uri: https://github.com/protocolbuffers/protobuf/tree/v3.21.12/ruby
75
+ source_code_uri: https://github.com/protocolbuffers/protobuf/tree/v3.22.0/ruby
78
76
  post_install_message:
79
77
  rdoc_options: []
80
78
  require_paths:
@@ -94,7 +92,4 @@ rubygems_version: 3.2.29
94
92
  signing_key:
95
93
  specification_version: 4
96
94
  summary: Protocol Buffers
97
- test_files:
98
- - tests/basic.rb
99
- - tests/stress.rb
100
- - tests/generated_code_test.rb
95
+ test_files: []
data/tests/basic.rb DELETED
@@ -1,739 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- # basic_test_pb.rb is in the same directory as this test.
4
- $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
5
-
6
- require 'basic_test_pb'
7
- require 'common_tests'
8
- require 'google/protobuf'
9
- require 'json'
10
- require 'test/unit'
11
-
12
- # ------------- generated code --------------
13
-
14
- module BasicTest
15
- pool = Google::Protobuf::DescriptorPool.new
16
- pool.build do
17
- add_message "BadFieldNames" do
18
- optional :dup, :int32, 1
19
- optional :class, :int32, 2
20
- end
21
- end
22
-
23
- BadFieldNames = pool.lookup("BadFieldNames").msgclass
24
-
25
- # ------------ test cases ---------------
26
-
27
- class MessageContainerTest < Test::Unit::TestCase
28
- # Required by CommonTests module to resolve proto3 proto classes used in tests.
29
- def proto_module
30
- ::BasicTest
31
- end
32
- include CommonTests
33
-
34
- def test_issue_8311_crash
35
- Google::Protobuf::DescriptorPool.generated_pool.build do
36
- add_file("inner.proto", :syntax => :proto3) do
37
- add_message "Inner" do
38
- # Removing either of these fixes the segfault.
39
- optional :foo, :string, 1
40
- optional :bar, :string, 2
41
- end
42
- end
43
- end
44
-
45
- Google::Protobuf::DescriptorPool.generated_pool.build do
46
- add_file("outer.proto", :syntax => :proto3) do
47
- add_message "Outer" do
48
- repeated :inners, :message, 1, "Inner"
49
- end
50
- end
51
- end
52
-
53
- outer = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("Outer").msgclass
54
-
55
- outer.new(
56
- inners: []
57
- )['inners'].to_s
58
-
59
- assert_raise Google::Protobuf::TypeError do
60
- outer.new(
61
- inners: [nil]
62
- ).to_s
63
- end
64
- end
65
-
66
- def test_issue_8559_crash
67
- msg = TestMessage.new
68
- msg.repeated_int32 = ::Google::Protobuf::RepeatedField.new(:int32, [1, 2, 3])
69
-
70
- # https://github.com/jruby/jruby/issues/6818 was fixed in JRuby 9.3.0.0
71
- if cruby_or_jruby_9_3_or_higher?
72
- GC.start(full_mark: true, immediate_sweep: true)
73
- end
74
- TestMessage.encode(msg)
75
- end
76
-
77
- def test_issue_9440
78
- msg = HelloRequest.new
79
- msg.id = 8
80
- assert_equal 8, msg.id
81
- msg.version = '1'
82
- assert_equal 8, msg.id
83
- end
84
-
85
- def test_issue_9507
86
- pool = Google::Protobuf::DescriptorPool.new
87
- pool.build do
88
- add_message "NpeMessage" do
89
- optional :type, :enum, 1, "TestEnum"
90
- optional :other, :string, 2
91
- end
92
- add_enum "TestEnum" do
93
- value :Something, 0
94
- end
95
- end
96
-
97
- msgclass = pool.lookup("NpeMessage").msgclass
98
-
99
- m = msgclass.new(
100
- other: "foo" # must be set, but can be blank
101
- )
102
-
103
- begin
104
- encoded = msgclass.encode(m)
105
- rescue java.lang.NullPointerException
106
- flunk "NPE rescued"
107
- end
108
- decoded = msgclass.decode(encoded)
109
- decoded.inspect
110
- decoded.to_proto
111
- end
112
-
113
- def test_has_field
114
- m = TestSingularFields.new
115
- assert !m.has_singular_msg?
116
- m.singular_msg = TestMessage2.new
117
- assert m.has_singular_msg?
118
- assert TestSingularFields.descriptor.lookup('singular_msg').has?(m)
119
-
120
- m = OneofMessage.new
121
- assert !m.has_my_oneof?
122
- m.a = "foo"
123
- assert m.has_my_oneof?
124
- assert_raise NoMethodError do
125
- m.has_a?
126
- end
127
- assert_true OneofMessage.descriptor.lookup('a').has?(m)
128
-
129
- m = TestSingularFields.new
130
- assert_raise NoMethodError do
131
- m.has_singular_int32?
132
- end
133
- assert_raise ArgumentError do
134
- TestSingularFields.descriptor.lookup('singular_int32').has?(m)
135
- end
136
-
137
- assert_raise NoMethodError do
138
- m.has_singular_string?
139
- end
140
- assert_raise ArgumentError do
141
- TestSingularFields.descriptor.lookup('singular_string').has?(m)
142
- end
143
-
144
- assert_raise NoMethodError do
145
- m.has_singular_bool?
146
- end
147
- assert_raise ArgumentError do
148
- TestSingularFields.descriptor.lookup('singular_bool').has?(m)
149
- end
150
-
151
- m = TestMessage.new
152
- assert_raise NoMethodError do
153
- m.has_repeated_msg?
154
- end
155
- assert_raise ArgumentError do
156
- TestMessage.descriptor.lookup('repeated_msg').has?(m)
157
- end
158
- end
159
-
160
- def test_no_presence
161
- m = TestSingularFields.new
162
-
163
- # Explicitly setting to zero does not cause anything to be serialized.
164
- m.singular_int32 = 0
165
- assert_equal "", TestSingularFields.encode(m)
166
-
167
- # Explicitly setting to a non-zero value *does* cause serialization.
168
- m.singular_int32 = 1
169
- assert_not_equal "", TestSingularFields.encode(m)
170
-
171
- m.singular_int32 = 0
172
- assert_equal "", TestSingularFields.encode(m)
173
- end
174
-
175
- def test_set_clear_defaults
176
- m = TestSingularFields.new
177
-
178
- m.singular_int32 = -42
179
- assert_equal( -42, m.singular_int32 )
180
- m.clear_singular_int32
181
- assert_equal 0, m.singular_int32
182
-
183
- m.singular_int32 = 50
184
- assert_equal 50, m.singular_int32
185
- TestSingularFields.descriptor.lookup('singular_int32').clear(m)
186
- assert_equal 0, m.singular_int32
187
-
188
- m.singular_string = "foo bar"
189
- assert_equal "foo bar", m.singular_string
190
- m.clear_singular_string
191
- assert_equal "", m.singular_string
192
-
193
- m.singular_string = "foo"
194
- assert_equal "foo", m.singular_string
195
- TestSingularFields.descriptor.lookup('singular_string').clear(m)
196
- assert_equal "", m.singular_string
197
-
198
- m.singular_msg = TestMessage2.new(:foo => 42)
199
- assert_equal TestMessage2.new(:foo => 42), m.singular_msg
200
- assert m.has_singular_msg?
201
- m.clear_singular_msg
202
- assert_equal nil, m.singular_msg
203
- assert !m.has_singular_msg?
204
-
205
- m.singular_msg = TestMessage2.new(:foo => 42)
206
- assert_equal TestMessage2.new(:foo => 42), m.singular_msg
207
- TestSingularFields.descriptor.lookup('singular_msg').clear(m)
208
- assert_equal nil, m.singular_msg
209
- end
210
-
211
- def test_import_proto2
212
- m = TestMessage.new
213
- assert !m.has_optional_proto2_submessage?
214
- m.optional_proto2_submessage = ::FooBar::Proto2::TestImportedMessage.new
215
- assert m.has_optional_proto2_submessage?
216
- assert TestMessage.descriptor.lookup('optional_proto2_submessage').has?(m)
217
-
218
- m.clear_optional_proto2_submessage
219
- assert !m.has_optional_proto2_submessage?
220
- end
221
-
222
- def test_clear_repeated_fields
223
- m = TestMessage.new
224
-
225
- m.repeated_int32.push(1)
226
- assert_equal [1], m.repeated_int32
227
- m.clear_repeated_int32
228
- assert_equal [], m.repeated_int32
229
-
230
- m.repeated_int32.push(1)
231
- assert_equal [1], m.repeated_int32
232
- TestMessage.descriptor.lookup('repeated_int32').clear(m)
233
- assert_equal [], m.repeated_int32
234
-
235
- m = OneofMessage.new
236
- m.a = "foo"
237
- assert_equal "foo", m.a
238
- assert m.has_my_oneof?
239
- assert_equal :a, m.my_oneof
240
- m.clear_a
241
- assert !m.has_my_oneof?
242
-
243
- m.a = "foobar"
244
- assert m.has_my_oneof?
245
- m.clear_my_oneof
246
- assert !m.has_my_oneof?
247
-
248
- m.a = "bar"
249
- assert_equal "bar", m.a
250
- assert m.has_my_oneof?
251
- OneofMessage.descriptor.lookup('a').clear(m)
252
- assert !m.has_my_oneof?
253
- end
254
-
255
- def test_initialization_map_errors
256
- e = assert_raise ArgumentError do
257
- TestMessage.new(:hello => "world")
258
- end
259
- assert_match(/hello/, e.message)
260
-
261
- e = assert_raise ArgumentError do
262
- MapMessage.new(:map_string_int32 => "hello")
263
- end
264
- assert_equal e.message, "Expected Hash object as initializer value for map field 'map_string_int32' (given String)."
265
-
266
- e = assert_raise ArgumentError do
267
- TestMessage.new(:repeated_uint32 => "hello")
268
- end
269
- assert_equal e.message, "Expected array as initializer value for repeated field 'repeated_uint32' (given String)."
270
- end
271
-
272
- def test_map_field
273
- m = MapMessage.new
274
- assert m.map_string_int32 == {}
275
- assert m.map_string_msg == {}
276
-
277
- m = MapMessage.new(
278
- :map_string_int32 => {"a" => 1, "b" => 2},
279
- :map_string_msg => {"a" => TestMessage2.new(:foo => 1),
280
- "b" => TestMessage2.new(:foo => 2)},
281
- :map_string_enum => {"a" => :A, "b" => :B})
282
- assert m.map_string_int32.keys.sort == ["a", "b"]
283
- assert m.map_string_int32["a"] == 1
284
- assert m.map_string_msg["b"].foo == 2
285
- assert m.map_string_enum["a"] == :A
286
-
287
- m.map_string_int32["c"] = 3
288
- assert m.map_string_int32["c"] == 3
289
- m.map_string_msg["c"] = TestMessage2.new(:foo => 3)
290
- assert m.map_string_msg["c"] == TestMessage2.new(:foo => 3)
291
- m.map_string_msg.delete("b")
292
- m.map_string_msg.delete("c")
293
- assert m.map_string_msg == { "a" => TestMessage2.new(:foo => 1) }
294
-
295
- assert_raise Google::Protobuf::TypeError do
296
- m.map_string_msg["e"] = TestMessage.new # wrong value type
297
- end
298
- # ensure nothing was added by the above
299
- assert m.map_string_msg == { "a" => TestMessage2.new(:foo => 1) }
300
-
301
- m.map_string_int32 = Google::Protobuf::Map.new(:string, :int32)
302
- assert_raise Google::Protobuf::TypeError do
303
- m.map_string_int32 = Google::Protobuf::Map.new(:string, :int64)
304
- end
305
- assert_raise Google::Protobuf::TypeError do
306
- m.map_string_int32 = {}
307
- end
308
-
309
- assert_raise Google::Protobuf::TypeError do
310
- m = MapMessage.new(:map_string_int32 => { 1 => "I am not a number" })
311
- end
312
- end
313
-
314
- def test_map_field_with_symbol
315
- m = MapMessage.new
316
- assert m.map_string_int32 == {}
317
- assert m.map_string_msg == {}
318
-
319
- m = MapMessage.new(
320
- :map_string_int32 => {a: 1, "b" => 2},
321
- :map_string_msg => {a: TestMessage2.new(:foo => 1),
322
- b: TestMessage2.new(:foo => 10)})
323
- assert_equal 1, m.map_string_int32[:a]
324
- assert_equal 2, m.map_string_int32[:b]
325
- assert_equal 10, m.map_string_msg[:b].foo
326
- end
327
-
328
- def test_map_inspect
329
- m = MapMessage.new(
330
- :map_string_int32 => {"a" => 1, "b" => 2},
331
- :map_string_msg => {"a" => TestMessage2.new(:foo => 1),
332
- "b" => TestMessage2.new(:foo => 2)},
333
- :map_string_enum => {"a" => :A, "b" => :B})
334
-
335
- # JRuby doesn't keep consistent ordering so check for either version
336
- expected_a = "<BasicTest::MapMessage: map_string_int32: {\"b\"=>2, \"a\"=>1}, map_string_msg: {\"b\"=><BasicTest::TestMessage2: foo: 2>, \"a\"=><BasicTest::TestMessage2: foo: 1>}, map_string_enum: {\"b\"=>:B, \"a\"=>:A}>"
337
- expected_b = "<BasicTest::MapMessage: map_string_int32: {\"a\"=>1, \"b\"=>2}, map_string_msg: {\"a\"=><BasicTest::TestMessage2: foo: 1>, \"b\"=><BasicTest::TestMessage2: foo: 2>}, map_string_enum: {\"a\"=>:A, \"b\"=>:B}>"
338
- inspect_result = m.inspect
339
- assert expected_a == inspect_result || expected_b == inspect_result, "Incorrect inspect result: #{inspect_result}"
340
- end
341
-
342
- def test_map_corruption
343
- # This pattern led to a crash in a previous version of upb/protobuf.
344
- m = MapMessage.new(map_string_int32: { "aaa" => 1 })
345
- m.map_string_int32['podid'] = 2
346
- m.map_string_int32['aaa'] = 3
347
- end
348
-
349
- def test_map_wrappers
350
- run_asserts = ->(m) {
351
- assert_equal 2.0, m.map_double[0].value
352
- assert_equal 4.0, m.map_float[0].value
353
- assert_equal 3, m.map_int32[0].value
354
- assert_equal 4, m.map_int64[0].value
355
- assert_equal 5, m.map_uint32[0].value
356
- assert_equal 6, m.map_uint64[0].value
357
- assert_equal true, m.map_bool[0].value
358
- assert_equal 'str', m.map_string[0].value
359
- assert_equal 'fun', m.map_bytes[0].value
360
- }
361
-
362
- m = proto_module::Wrapper.new(
363
- map_double: {0 => Google::Protobuf::DoubleValue.new(value: 2.0)},
364
- map_float: {0 => Google::Protobuf::FloatValue.new(value: 4.0)},
365
- map_int32: {0 => Google::Protobuf::Int32Value.new(value: 3)},
366
- map_int64: {0 => Google::Protobuf::Int64Value.new(value: 4)},
367
- map_uint32: {0 => Google::Protobuf::UInt32Value.new(value: 5)},
368
- map_uint64: {0 => Google::Protobuf::UInt64Value.new(value: 6)},
369
- map_bool: {0 => Google::Protobuf::BoolValue.new(value: true)},
370
- map_string: {0 => Google::Protobuf::StringValue.new(value: 'str')},
371
- map_bytes: {0 => Google::Protobuf::BytesValue.new(value: 'fun')},
372
- )
373
-
374
- run_asserts.call(m)
375
- serialized = proto_module::Wrapper::encode(m)
376
- m2 = proto_module::Wrapper::decode(serialized)
377
- run_asserts.call(m2)
378
-
379
- # Test the case where we are serializing directly from the parsed form
380
- # (before anything lazy is materialized).
381
- m3 = proto_module::Wrapper::decode(serialized)
382
- serialized2 = proto_module::Wrapper::encode(m3)
383
- m4 = proto_module::Wrapper::decode(serialized2)
384
- run_asserts.call(m4)
385
-
386
- # Test that the lazy form compares equal to the expanded form.
387
- m5 = proto_module::Wrapper::decode(serialized2)
388
- assert_equal m5, m
389
- end
390
-
391
- def test_map_wrappers_with_default_values
392
- run_asserts = ->(m) {
393
- assert_equal 0.0, m.map_double[0].value
394
- assert_equal 0.0, m.map_float[0].value
395
- assert_equal 0, m.map_int32[0].value
396
- assert_equal 0, m.map_int64[0].value
397
- assert_equal 0, m.map_uint32[0].value
398
- assert_equal 0, m.map_uint64[0].value
399
- assert_equal false, m.map_bool[0].value
400
- assert_equal '', m.map_string[0].value
401
- assert_equal '', m.map_bytes[0].value
402
- }
403
-
404
- m = proto_module::Wrapper.new(
405
- map_double: {0 => Google::Protobuf::DoubleValue.new(value: 0.0)},
406
- map_float: {0 => Google::Protobuf::FloatValue.new(value: 0.0)},
407
- map_int32: {0 => Google::Protobuf::Int32Value.new(value: 0)},
408
- map_int64: {0 => Google::Protobuf::Int64Value.new(value: 0)},
409
- map_uint32: {0 => Google::Protobuf::UInt32Value.new(value: 0)},
410
- map_uint64: {0 => Google::Protobuf::UInt64Value.new(value: 0)},
411
- map_bool: {0 => Google::Protobuf::BoolValue.new(value: false)},
412
- map_string: {0 => Google::Protobuf::StringValue.new(value: '')},
413
- map_bytes: {0 => Google::Protobuf::BytesValue.new(value: '')},
414
- )
415
-
416
- run_asserts.call(m)
417
- serialized = proto_module::Wrapper::encode(m)
418
- m2 = proto_module::Wrapper::decode(serialized)
419
- run_asserts.call(m2)
420
-
421
- # Test the case where we are serializing directly from the parsed form
422
- # (before anything lazy is materialized).
423
- m3 = proto_module::Wrapper::decode(serialized)
424
- serialized2 = proto_module::Wrapper::encode(m3)
425
- m4 = proto_module::Wrapper::decode(serialized2)
426
- run_asserts.call(m4)
427
-
428
- # Test that the lazy form compares equal to the expanded form.
429
- m5 = proto_module::Wrapper::decode(serialized2)
430
- assert_equal m5, m
431
- end
432
-
433
- def test_map_wrappers_with_no_value
434
- run_asserts = ->(m) {
435
- assert_equal 0.0, m.map_double[0].value
436
- assert_equal 0.0, m.map_float[0].value
437
- assert_equal 0, m.map_int32[0].value
438
- assert_equal 0, m.map_int64[0].value
439
- assert_equal 0, m.map_uint32[0].value
440
- assert_equal 0, m.map_uint64[0].value
441
- assert_equal false, m.map_bool[0].value
442
- assert_equal '', m.map_string[0].value
443
- assert_equal '', m.map_bytes[0].value
444
- }
445
-
446
- m = proto_module::Wrapper.new(
447
- map_double: {0 => Google::Protobuf::DoubleValue.new()},
448
- map_float: {0 => Google::Protobuf::FloatValue.new()},
449
- map_int32: {0 => Google::Protobuf::Int32Value.new()},
450
- map_int64: {0 => Google::Protobuf::Int64Value.new()},
451
- map_uint32: {0 => Google::Protobuf::UInt32Value.new()},
452
- map_uint64: {0 => Google::Protobuf::UInt64Value.new()},
453
- map_bool: {0 => Google::Protobuf::BoolValue.new()},
454
- map_string: {0 => Google::Protobuf::StringValue.new()},
455
- map_bytes: {0 => Google::Protobuf::BytesValue.new()},
456
- )
457
- run_asserts.call(m)
458
-
459
- serialized = proto_module::Wrapper::encode(m)
460
- m2 = proto_module::Wrapper::decode(serialized)
461
- run_asserts.call(m2)
462
-
463
- # Test the case where we are serializing directly from the parsed form
464
- # (before anything lazy is materialized).
465
- m3 = proto_module::Wrapper::decode(serialized)
466
- serialized2 = proto_module::Wrapper::encode(m3)
467
- m4 = proto_module::Wrapper::decode(serialized2)
468
- run_asserts.call(m4)
469
- end
470
-
471
- def test_concurrent_decoding
472
- o = Outer.new
473
- o.items[0] = Inner.new
474
- raw = Outer.encode(o)
475
-
476
- thds = 2.times.map do
477
- Thread.new do
478
- 100000.times do
479
- assert_equal o, Outer.decode(raw)
480
- end
481
- end
482
- end
483
- thds.map(&:join)
484
- end
485
-
486
- def test_map_encode_decode
487
- m = MapMessage.new(
488
- :map_string_int32 => {"a" => 1, "b" => 2},
489
- :map_string_msg => {"a" => TestMessage2.new(:foo => 1),
490
- "b" => TestMessage2.new(:foo => 2)},
491
- :map_string_enum => {"a" => :A, "b" => :B})
492
- m2 = MapMessage.decode(MapMessage.encode(m))
493
- assert m == m2
494
-
495
- m3 = MapMessageWireEquiv.decode(MapMessage.encode(m))
496
- assert m3.map_string_int32.length == 2
497
-
498
- kv = {}
499
- m3.map_string_int32.map { |msg| kv[msg.key] = msg.value }
500
- assert kv == {"a" => 1, "b" => 2}
501
-
502
- kv = {}
503
- m3.map_string_msg.map { |msg| kv[msg.key] = msg.value }
504
- assert kv == {"a" => TestMessage2.new(:foo => 1),
505
- "b" => TestMessage2.new(:foo => 2)}
506
- end
507
-
508
- def test_protobuf_decode_json_ignore_unknown_fields
509
- m = TestMessage.decode_json({
510
- optional_string: "foo",
511
- not_in_message: "some_value"
512
- }.to_json, { ignore_unknown_fields: true })
513
-
514
- assert_equal m.optional_string, "foo"
515
- e = assert_raise Google::Protobuf::ParseError do
516
- TestMessage.decode_json({ not_in_message: "some_value" }.to_json)
517
- end
518
- assert_match(/No such field: not_in_message/, e.message)
519
- end
520
-
521
- #def test_json_quoted_string
522
- # m = TestMessage.decode_json(%q(
523
- # "optionalInt64": "1",,
524
- # }))
525
- # puts(m)
526
- # assert_equal 1, m.optional_int32
527
- #end
528
-
529
- def test_to_h
530
- m = TestMessage.new(:optional_bool => true, :optional_double => -10.100001, :optional_string => 'foo', :repeated_string => ['bar1', 'bar2'], :repeated_msg => [TestMessage2.new(:foo => 100)])
531
- expected_result = {
532
- :optional_bool=>true,
533
- :optional_bytes=>"",
534
- :optional_double=>-10.100001,
535
- :optional_enum=>:Default,
536
- :optional_float=>0.0,
537
- :optional_int32=>0,
538
- :optional_int64=>0,
539
- :optional_msg=>nil,
540
- :optional_msg2=>nil,
541
- :optional_proto2_submessage=>nil,
542
- :optional_string=>"foo",
543
- :optional_uint32=>0,
544
- :optional_uint64=>0,
545
- :repeated_bool=>[],
546
- :repeated_bytes=>[],
547
- :repeated_double=>[],
548
- :repeated_enum=>[],
549
- :repeated_float=>[],
550
- :repeated_int32=>[],
551
- :repeated_int64=>[],
552
- :repeated_msg=>[{:foo => 100}],
553
- :repeated_string=>["bar1", "bar2"],
554
- :repeated_uint32=>[],
555
- :repeated_uint64=>[]
556
- }
557
- assert_equal expected_result, m.to_h
558
-
559
- m = MapMessage.new(
560
- :map_string_int32 => {"a" => 1, "b" => 2},
561
- :map_string_msg => {"a" => TestMessage2.new(:foo => 1),
562
- "b" => TestMessage2.new(:foo => 2)},
563
- :map_string_enum => {"a" => :A, "b" => :B})
564
- expected_result = {
565
- :map_string_int32 => {"a" => 1, "b" => 2},
566
- :map_string_msg => {"a" => {:foo => 1}, "b" => {:foo => 2}},
567
- :map_string_enum => {"a" => :A, "b" => :B}
568
- }
569
- assert_equal expected_result, m.to_h
570
- end
571
-
572
-
573
- def test_json_maps
574
- m = MapMessage.new(:map_string_int32 => {"a" => 1})
575
- expected = {mapStringInt32: {a: 1}, mapStringMsg: {}, mapStringEnum: {}}
576
- expected_preserve = {map_string_int32: {a: 1}, map_string_msg: {}, map_string_enum: {}}
577
- assert_equal JSON.parse(MapMessage.encode_json(m, :emit_defaults=>true), :symbolize_names => true), expected
578
-
579
- json = MapMessage.encode_json(m, :preserve_proto_fieldnames => true, :emit_defaults=>true)
580
- assert_equal JSON.parse(json, :symbolize_names => true), expected_preserve
581
-
582
- m2 = MapMessage.decode_json(MapMessage.encode_json(m))
583
- assert_equal m, m2
584
- end
585
-
586
- def test_json_maps_emit_defaults_submsg
587
- m = MapMessage.new(:map_string_msg => {"a" => TestMessage2.new(foo: 0)})
588
- expected = {mapStringInt32: {}, mapStringMsg: {a: {foo: 0}}, mapStringEnum: {}}
589
-
590
- actual = MapMessage.encode_json(m, :emit_defaults => true)
591
-
592
- assert_equal JSON.parse(actual, :symbolize_names => true), expected
593
- end
594
-
595
- def test_json_emit_defaults_submsg
596
- m = TestSingularFields.new(singular_msg: proto_module::TestMessage2.new)
597
-
598
- expected = {
599
- singularInt32: 0,
600
- singularInt64: "0",
601
- singularUint32: 0,
602
- singularUint64: "0",
603
- singularBool: false,
604
- singularFloat: 0,
605
- singularDouble: 0,
606
- singularString: "",
607
- singularBytes: "",
608
- singularMsg: {},
609
- singularEnum: "Default",
610
- }
611
-
612
- actual = proto_module::TestMessage.encode_json(m, :emit_defaults => true)
613
-
614
- assert_equal expected, JSON.parse(actual, :symbolize_names => true)
615
- end
616
-
617
- def test_respond_to
618
- msg = MapMessage.new
619
- assert msg.respond_to?(:map_string_int32)
620
- assert !msg.respond_to?(:bacon)
621
- end
622
-
623
- def test_file_descriptor
624
- file_descriptor = TestMessage.descriptor.file_descriptor
625
- assert nil != file_descriptor
626
- assert_equal "tests/basic_test.proto", file_descriptor.name
627
- assert_equal :proto3, file_descriptor.syntax
628
-
629
- file_descriptor = TestEnum.descriptor.file_descriptor
630
- assert nil != file_descriptor
631
- assert_equal "tests/basic_test.proto", file_descriptor.name
632
- assert_equal :proto3, file_descriptor.syntax
633
- end
634
-
635
- # Ruby 2.5 changed to raise FrozenError instead of RuntimeError
636
- FrozenErrorType = Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.5') ? RuntimeError : FrozenError
637
-
638
- def test_map_freeze
639
- m = proto_module::MapMessage.new
640
- m.map_string_int32['a'] = 5
641
- m.map_string_msg['b'] = proto_module::TestMessage2.new
642
-
643
- m.map_string_int32.freeze
644
- m.map_string_msg.freeze
645
-
646
- assert m.map_string_int32.frozen?
647
- assert m.map_string_msg.frozen?
648
-
649
- assert_raise(FrozenErrorType) { m.map_string_int32['foo'] = 1 }
650
- assert_raise(FrozenErrorType) { m.map_string_msg['bar'] = proto_module::TestMessage2.new }
651
- assert_raise(FrozenErrorType) { m.map_string_int32.delete('a') }
652
- assert_raise(FrozenErrorType) { m.map_string_int32.clear }
653
- end
654
-
655
- def test_map_length
656
- m = proto_module::MapMessage.new
657
- assert_equal 0, m.map_string_int32.length
658
- assert_equal 0, m.map_string_msg.length
659
- assert_equal 0, m.map_string_int32.size
660
- assert_equal 0, m.map_string_msg.size
661
-
662
- m.map_string_int32['a'] = 1
663
- m.map_string_int32['b'] = 2
664
- m.map_string_msg['a'] = proto_module::TestMessage2.new
665
- assert_equal 2, m.map_string_int32.length
666
- assert_equal 1, m.map_string_msg.length
667
- assert_equal 2, m.map_string_int32.size
668
- assert_equal 1, m.map_string_msg.size
669
- end
670
-
671
- def test_string_with_singleton_class_enabled
672
- str = 'foobar'
673
- # NOTE: Accessing a singleton class of an object changes its low level class representation
674
- # as far as the C API's CLASS_OF() method concerned, exposing the issue
675
- str.singleton_class
676
- m = proto_module::TestMessage.new(
677
- optional_string: str,
678
- optional_bytes: str
679
- )
680
-
681
- assert_equal str, m.optional_string
682
- assert_equal str, m.optional_bytes
683
- end
684
-
685
- def test_utf8
686
- m = proto_module::TestMessage.new(
687
- optional_string: "µpb",
688
- )
689
- m2 = proto_module::TestMessage.decode(proto_module::TestMessage.encode(m))
690
- assert_equal m2, m
691
- end
692
-
693
- def test_map_fields_respond_to? # regression test for issue 9202
694
- msg = proto_module::MapMessage.new
695
- assert msg.respond_to?(:map_string_int32=)
696
- msg.map_string_int32 = Google::Protobuf::Map.new(:string, :int32)
697
- assert msg.respond_to?(:map_string_int32)
698
- assert_equal( Google::Protobuf::Map.new(:string, :int32), msg.map_string_int32 )
699
- assert msg.respond_to?(:clear_map_string_int32)
700
- msg.clear_map_string_int32
701
-
702
- assert !msg.respond_to?(:has_map_string_int32?)
703
- assert_raise NoMethodError do
704
- msg.has_map_string_int32?
705
- end
706
- assert !msg.respond_to?(:map_string_int32_as_value)
707
- assert_raise NoMethodError do
708
- msg.map_string_int32_as_value
709
- end
710
- assert !msg.respond_to?(:map_string_int32_as_value=)
711
- assert_raise NoMethodError do
712
- msg.map_string_int32_as_value = :boom
713
- end
714
- end
715
- end
716
-
717
- def test_oneof_fields_respond_to? # regression test for issue 9202
718
- msg = proto_module::OneofMessage.new
719
- # `has_` prefix + "?" suffix actions should only work for oneofs fields.
720
- assert msg.has_my_oneof?
721
- assert msg.respond_to? :has_my_oneof?
722
- assert !msg.respond_to?( :has_a? )
723
- assert_raise NoMethodError do
724
- msg.has_a?
725
- end
726
- assert !msg.respond_to?( :has_b? )
727
- assert_raise NoMethodError do
728
- msg.has_b?
729
- end
730
- assert !msg.respond_to?( :has_c? )
731
- assert_raise NoMethodError do
732
- msg.has_c?
733
- end
734
- assert !msg.respond_to?( :has_d? )
735
- assert_raise NoMethodError do
736
- msg.has_d?
737
- end
738
- end
739
- end
@@ -1,23 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- # generated_code.rb is in the same directory as this test.
4
- $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
5
-
6
- require 'generated_code_pb'
7
- require 'test_import_pb'
8
- require 'test_ruby_package_pb'
9
- require 'test/unit'
10
-
11
- class GeneratedCodeTest < Test::Unit::TestCase
12
- def test_generated_msg
13
- # just test that we can instantiate the message. The purpose of this test
14
- # is to ensure that the output of the code generator is valid Ruby and
15
- # successfully creates message definitions and classes, not to test every
16
- # aspect of the extension (basic.rb is for that).
17
- A::B::C::TestMessage.new
18
- A::B::C::TestMessage::NestedMessage.new
19
- A::B::C::TestLowercaseNested::Lowercase.new
20
- FooBar::TestImportedMessage.new
21
- A::B::TestRubyPackageMessage.new
22
- end
23
- end
data/tests/stress.rb DELETED
@@ -1,38 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- require 'google/protobuf'
4
- require 'test/unit'
5
-
6
- module StressTest
7
- pool = Google::Protobuf::DescriptorPool.new
8
- pool.build do
9
- add_message "TestMessage" do
10
- optional :a, :int32, 1
11
- repeated :b, :message, 2, "M"
12
- end
13
- add_message "M" do
14
- optional :foo, :string, 1
15
- end
16
- end
17
-
18
- TestMessage = pool.lookup("TestMessage").msgclass
19
- M = pool.lookup("M").msgclass
20
-
21
- class StressTest < Test::Unit::TestCase
22
- def get_msg
23
- TestMessage.new(:a => 1000,
24
- :b => [M.new(:foo => "hello"),
25
- M.new(:foo => "world")])
26
- end
27
- def test_stress
28
- m = get_msg
29
- data = TestMessage.encode(m)
30
- 100_000.times do
31
- mnew = TestMessage.decode(data)
32
- mnew = mnew.dup
33
- assert_equal m.inspect, mnew.inspect
34
- assert TestMessage.encode(mnew) == data
35
- end
36
- end
37
- end
38
- end