google-protobuf 3.7.0 → 3.16.0

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.

Potentially problematic release.


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

Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/ext/google/protobuf_c/convert.c +349 -0
  3. data/ext/google/protobuf_c/convert.h +72 -0
  4. data/ext/google/protobuf_c/defs.c +1555 -1228
  5. data/ext/google/protobuf_c/defs.h +107 -0
  6. data/ext/google/protobuf_c/extconf.rb +4 -7
  7. data/ext/google/protobuf_c/map.c +310 -470
  8. data/ext/google/protobuf_c/map.h +66 -0
  9. data/ext/google/protobuf_c/message.c +931 -346
  10. data/ext/google/protobuf_c/message.h +101 -0
  11. data/ext/google/protobuf_c/protobuf.c +384 -51
  12. data/ext/google/protobuf_c/protobuf.h +44 -544
  13. data/ext/google/protobuf_c/repeated_field.c +311 -308
  14. data/ext/google/protobuf_c/repeated_field.h +62 -0
  15. data/ext/google/protobuf_c/ruby-upb.c +8914 -0
  16. data/ext/google/protobuf_c/ruby-upb.h +4452 -0
  17. data/ext/google/protobuf_c/third_party/wyhash/wyhash.h +145 -0
  18. data/lib/google/protobuf/any_pb.rb +1 -1
  19. data/lib/google/protobuf/api_pb.rb +3 -3
  20. data/lib/google/protobuf/duration_pb.rb +1 -1
  21. data/lib/google/protobuf/empty_pb.rb +1 -1
  22. data/lib/google/protobuf/field_mask_pb.rb +1 -1
  23. data/lib/google/protobuf/source_context_pb.rb +1 -1
  24. data/lib/google/protobuf/struct_pb.rb +4 -4
  25. data/lib/google/protobuf/timestamp_pb.rb +1 -1
  26. data/lib/google/protobuf/type_pb.rb +8 -8
  27. data/lib/google/protobuf/well_known_types.rb +8 -2
  28. data/lib/google/protobuf/wrappers_pb.rb +9 -9
  29. data/lib/google/protobuf.rb +70 -0
  30. data/tests/basic.rb +315 -72
  31. data/tests/generated_code_test.rb +0 -0
  32. data/tests/stress.rb +0 -0
  33. metadata +27 -16
  34. data/ext/google/protobuf_c/encode_decode.c +0 -1574
  35. data/ext/google/protobuf_c/storage.c +0 -1019
  36. data/ext/google/protobuf_c/upb.c +0 -17318
  37. data/ext/google/protobuf_c/upb.h +0 -9755
data/tests/basic.rb CHANGED
@@ -17,7 +17,6 @@ module BasicTest
17
17
  add_message "BadFieldNames" do
18
18
  optional :dup, :int32, 1
19
19
  optional :class, :int32, 2
20
- optional :"a.b", :int32, 3
21
20
  end
22
21
  end
23
22
 
@@ -32,12 +31,44 @@ module BasicTest
32
31
  end
33
32
  include CommonTests
34
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
+
35
66
  def test_has_field
36
- m = TestMessage.new
37
- assert !m.has_optional_msg?
38
- m.optional_msg = TestMessage2.new
39
- assert m.has_optional_msg?
40
- assert TestMessage.descriptor.lookup('optional_msg').has?(m)
67
+ m = TestSingularFields.new
68
+ assert !m.has_singular_msg?
69
+ m.singular_msg = TestMessage2.new
70
+ assert m.has_singular_msg?
71
+ assert TestSingularFields.descriptor.lookup('singular_msg').has?(m)
41
72
 
42
73
  m = OneofMessage.new
43
74
  assert !m.has_my_oneof?
@@ -46,32 +77,31 @@ module BasicTest
46
77
  assert_raise NoMethodError do
47
78
  m.has_a?
48
79
  end
49
- assert_raise ArgumentError do
50
- OneofMessage.descriptor.lookup('a').has?(m)
51
- end
80
+ assert_true OneofMessage.descriptor.lookup('a').has?(m)
52
81
 
53
- m = TestMessage.new
82
+ m = TestSingularFields.new
54
83
  assert_raise NoMethodError do
55
- m.has_optional_int32?
84
+ m.has_singular_int32?
56
85
  end
57
86
  assert_raise ArgumentError do
58
- TestMessage.descriptor.lookup('optional_int32').has?(m)
87
+ TestSingularFields.descriptor.lookup('singular_int32').has?(m)
59
88
  end
60
89
 
61
90
  assert_raise NoMethodError do
62
- m.has_optional_string?
91
+ m.has_singular_string?
63
92
  end
64
93
  assert_raise ArgumentError do
65
- TestMessage.descriptor.lookup('optional_string').has?(m)
94
+ TestSingularFields.descriptor.lookup('singular_string').has?(m)
66
95
  end
67
96
 
68
97
  assert_raise NoMethodError do
69
- m.has_optional_bool?
98
+ m.has_singular_bool?
70
99
  end
71
100
  assert_raise ArgumentError do
72
- TestMessage.descriptor.lookup('optional_bool').has?(m)
101
+ TestSingularFields.descriptor.lookup('singular_bool').has?(m)
73
102
  end
74
103
 
104
+ m = TestMessage.new
75
105
  assert_raise NoMethodError do
76
106
  m.has_repeated_msg?
77
107
  end
@@ -80,40 +110,59 @@ module BasicTest
80
110
  end
81
111
  end
82
112
 
113
+ def test_no_presence
114
+ m = TestSingularFields.new
115
+
116
+ # Explicitly setting to zero does not cause anything to be serialized.
117
+ m.singular_int32 = 0
118
+ assert_equal "", TestSingularFields.encode(m)
119
+
120
+ # Explicitly setting to a non-zero value *does* cause serialization.
121
+ m.singular_int32 = 1
122
+ assert_not_equal "", TestSingularFields.encode(m)
123
+
124
+ m.singular_int32 = 0
125
+ assert_equal "", TestSingularFields.encode(m)
126
+ end
127
+
83
128
  def test_set_clear_defaults
84
- m = TestMessage.new
129
+ m = TestSingularFields.new
130
+
131
+ m.singular_int32 = -42
132
+ assert_equal -42, m.singular_int32
133
+ m.clear_singular_int32
134
+ assert_equal 0, m.singular_int32
135
+
136
+ m.singular_int32 = 50
137
+ assert_equal 50, m.singular_int32
138
+ TestSingularFields.descriptor.lookup('singular_int32').clear(m)
139
+ assert_equal 0, m.singular_int32
140
+
141
+ m.singular_string = "foo bar"
142
+ assert_equal "foo bar", m.singular_string
143
+ m.clear_singular_string
144
+ assert_equal "", m.singular_string
145
+
146
+ m.singular_string = "foo"
147
+ assert_equal "foo", m.singular_string
148
+ TestSingularFields.descriptor.lookup('singular_string').clear(m)
149
+ assert_equal "", m.singular_string
150
+
151
+ m.singular_msg = TestMessage2.new(:foo => 42)
152
+ assert_equal TestMessage2.new(:foo => 42), m.singular_msg
153
+ assert m.has_singular_msg?
154
+ m.clear_singular_msg
155
+ assert_equal nil, m.singular_msg
156
+ assert !m.has_singular_msg?
157
+
158
+ m.singular_msg = TestMessage2.new(:foo => 42)
159
+ assert_equal TestMessage2.new(:foo => 42), m.singular_msg
160
+ TestSingularFields.descriptor.lookup('singular_msg').clear(m)
161
+ assert_equal nil, m.singular_msg
162
+ end
85
163
 
86
- m.optional_int32 = -42
87
- assert_equal -42, m.optional_int32
88
- m.clear_optional_int32
89
- assert_equal 0, m.optional_int32
90
-
91
- m.optional_int32 = 50
92
- assert_equal 50, m.optional_int32
93
- TestMessage.descriptor.lookup('optional_int32').clear(m)
94
- assert_equal 0, m.optional_int32
95
-
96
- m.optional_string = "foo bar"
97
- assert_equal "foo bar", m.optional_string
98
- m.clear_optional_string
99
- assert_equal "", m.optional_string
100
-
101
- m.optional_string = "foo"
102
- assert_equal "foo", m.optional_string
103
- TestMessage.descriptor.lookup('optional_string').clear(m)
104
- assert_equal "", m.optional_string
105
-
106
- m.optional_msg = TestMessage2.new(:foo => 42)
107
- assert_equal TestMessage2.new(:foo => 42), m.optional_msg
108
- assert m.has_optional_msg?
109
- m.clear_optional_msg
110
- assert_equal nil, m.optional_msg
111
- assert !m.has_optional_msg?
112
-
113
- m.optional_msg = TestMessage2.new(:foo => 42)
114
- assert_equal TestMessage2.new(:foo => 42), m.optional_msg
115
- TestMessage.descriptor.lookup('optional_msg').clear(m)
116
- assert_equal nil, m.optional_msg
164
+ def test_clear_repeated_fields
165
+ m = TestMessage.new
117
166
 
118
167
  m.repeated_int32.push(1)
119
168
  assert_equal [1], m.repeated_int32
@@ -129,6 +178,7 @@ module BasicTest
129
178
  m.a = "foo"
130
179
  assert_equal "foo", m.a
131
180
  assert m.has_my_oneof?
181
+ assert_equal :a, m.my_oneof
132
182
  m.clear_a
133
183
  assert !m.has_my_oneof?
134
184
 
@@ -144,7 +194,6 @@ module BasicTest
144
194
  assert !m.has_my_oneof?
145
195
  end
146
196
 
147
-
148
197
  def test_initialization_map_errors
149
198
  e = assert_raise ArgumentError do
150
199
  TestMessage.new(:hello => "world")
@@ -154,12 +203,12 @@ module BasicTest
154
203
  e = assert_raise ArgumentError do
155
204
  MapMessage.new(:map_string_int32 => "hello")
156
205
  end
157
- assert_equal e.message, "Expected Hash object as initializer value for map field 'map_string_int32'."
206
+ assert_equal e.message, "Expected Hash object as initializer value for map field 'map_string_int32' (given String)."
158
207
 
159
208
  e = assert_raise ArgumentError do
160
209
  TestMessage.new(:repeated_uint32 => "hello")
161
210
  end
162
- assert_equal e.message, "Expected array as initializer value for repeated field 'repeated_uint32'."
211
+ assert_equal e.message, "Expected array as initializer value for repeated field 'repeated_uint32' (given String)."
163
212
  end
164
213
 
165
214
  def test_map_field
@@ -170,10 +219,12 @@ module BasicTest
170
219
  m = MapMessage.new(
171
220
  :map_string_int32 => {"a" => 1, "b" => 2},
172
221
  :map_string_msg => {"a" => TestMessage2.new(:foo => 1),
173
- "b" => TestMessage2.new(:foo => 2)})
222
+ "b" => TestMessage2.new(:foo => 2)},
223
+ :map_string_enum => {"a" => :A, "b" => :B})
174
224
  assert m.map_string_int32.keys.sort == ["a", "b"]
175
225
  assert m.map_string_int32["a"] == 1
176
226
  assert m.map_string_msg["b"].foo == 2
227
+ assert m.map_string_enum["a"] == :A
177
228
 
178
229
  m.map_string_int32["c"] = 3
179
230
  assert m.map_string_int32["c"] == 3
@@ -197,18 +248,37 @@ module BasicTest
197
248
  m.map_string_int32 = {}
198
249
  end
199
250
 
200
- assert_raise TypeError do
251
+ assert_raise Google::Protobuf::TypeError do
201
252
  m = MapMessage.new(:map_string_int32 => { 1 => "I am not a number" })
202
253
  end
203
254
  end
204
255
 
256
+ def test_map_field_with_symbol
257
+ m = MapMessage.new
258
+ assert m.map_string_int32 == {}
259
+ assert m.map_string_msg == {}
260
+
261
+ m = MapMessage.new(
262
+ :map_string_int32 => {a: 1, "b" => 2},
263
+ :map_string_msg => {a: TestMessage2.new(:foo => 1),
264
+ b: TestMessage2.new(:foo => 10)})
265
+ assert_equal 1, m.map_string_int32[:a]
266
+ assert_equal 2, m.map_string_int32[:b]
267
+ assert_equal 10, m.map_string_msg[:b].foo
268
+ end
269
+
205
270
  def test_map_inspect
206
271
  m = MapMessage.new(
207
272
  :map_string_int32 => {"a" => 1, "b" => 2},
208
273
  :map_string_msg => {"a" => TestMessage2.new(:foo => 1),
209
- "b" => TestMessage2.new(:foo => 2)})
210
- expected = "<BasicTest::MapMessage: map_string_int32: {\"b\"=>2, \"a\"=>1}, map_string_msg: {\"b\"=><BasicTest::TestMessage2: foo: 2>, \"a\"=><BasicTest::TestMessage2: foo: 1>}>"
211
- assert_equal expected, m.inspect
274
+ "b" => TestMessage2.new(:foo => 2)},
275
+ :map_string_enum => {"a" => :A, "b" => :B})
276
+
277
+ # JRuby doesn't keep consistent ordering so check for either version
278
+ 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}>"
279
+ 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}>"
280
+ inspect_result = m.inspect
281
+ assert expected_a == inspect_result || expected_b == inspect_result, "Incorrect inspect result: #{inspect_result}"
212
282
  end
213
283
 
214
284
  def test_map_corruption
@@ -218,6 +288,128 @@ module BasicTest
218
288
  m.map_string_int32['aaa'] = 3
219
289
  end
220
290
 
291
+ def test_map_wrappers
292
+ run_asserts = ->(m) {
293
+ assert_equal 2.0, m.map_double[0].value
294
+ assert_equal 4.0, m.map_float[0].value
295
+ assert_equal 3, m.map_int32[0].value
296
+ assert_equal 4, m.map_int64[0].value
297
+ assert_equal 5, m.map_uint32[0].value
298
+ assert_equal 6, m.map_uint64[0].value
299
+ assert_equal true, m.map_bool[0].value
300
+ assert_equal 'str', m.map_string[0].value
301
+ assert_equal 'fun', m.map_bytes[0].value
302
+ }
303
+
304
+ m = proto_module::Wrapper.new(
305
+ map_double: {0 => Google::Protobuf::DoubleValue.new(value: 2.0)},
306
+ map_float: {0 => Google::Protobuf::FloatValue.new(value: 4.0)},
307
+ map_int32: {0 => Google::Protobuf::Int32Value.new(value: 3)},
308
+ map_int64: {0 => Google::Protobuf::Int64Value.new(value: 4)},
309
+ map_uint32: {0 => Google::Protobuf::UInt32Value.new(value: 5)},
310
+ map_uint64: {0 => Google::Protobuf::UInt64Value.new(value: 6)},
311
+ map_bool: {0 => Google::Protobuf::BoolValue.new(value: true)},
312
+ map_string: {0 => Google::Protobuf::StringValue.new(value: 'str')},
313
+ map_bytes: {0 => Google::Protobuf::BytesValue.new(value: 'fun')},
314
+ )
315
+
316
+ run_asserts.call(m)
317
+ serialized = proto_module::Wrapper::encode(m)
318
+ m2 = proto_module::Wrapper::decode(serialized)
319
+ run_asserts.call(m2)
320
+
321
+ # Test the case where we are serializing directly from the parsed form
322
+ # (before anything lazy is materialized).
323
+ m3 = proto_module::Wrapper::decode(serialized)
324
+ serialized2 = proto_module::Wrapper::encode(m3)
325
+ m4 = proto_module::Wrapper::decode(serialized2)
326
+ run_asserts.call(m4)
327
+
328
+ # Test that the lazy form compares equal to the expanded form.
329
+ m5 = proto_module::Wrapper::decode(serialized2)
330
+ assert_equal m5, m
331
+ end
332
+
333
+ def test_map_wrappers_with_default_values
334
+ run_asserts = ->(m) {
335
+ assert_equal 0.0, m.map_double[0].value
336
+ assert_equal 0.0, m.map_float[0].value
337
+ assert_equal 0, m.map_int32[0].value
338
+ assert_equal 0, m.map_int64[0].value
339
+ assert_equal 0, m.map_uint32[0].value
340
+ assert_equal 0, m.map_uint64[0].value
341
+ assert_equal false, m.map_bool[0].value
342
+ assert_equal '', m.map_string[0].value
343
+ assert_equal '', m.map_bytes[0].value
344
+ }
345
+
346
+ m = proto_module::Wrapper.new(
347
+ map_double: {0 => Google::Protobuf::DoubleValue.new(value: 0.0)},
348
+ map_float: {0 => Google::Protobuf::FloatValue.new(value: 0.0)},
349
+ map_int32: {0 => Google::Protobuf::Int32Value.new(value: 0)},
350
+ map_int64: {0 => Google::Protobuf::Int64Value.new(value: 0)},
351
+ map_uint32: {0 => Google::Protobuf::UInt32Value.new(value: 0)},
352
+ map_uint64: {0 => Google::Protobuf::UInt64Value.new(value: 0)},
353
+ map_bool: {0 => Google::Protobuf::BoolValue.new(value: false)},
354
+ map_string: {0 => Google::Protobuf::StringValue.new(value: '')},
355
+ map_bytes: {0 => Google::Protobuf::BytesValue.new(value: '')},
356
+ )
357
+
358
+ run_asserts.call(m)
359
+ serialized = proto_module::Wrapper::encode(m)
360
+ m2 = proto_module::Wrapper::decode(serialized)
361
+ run_asserts.call(m2)
362
+
363
+ # Test the case where we are serializing directly from the parsed form
364
+ # (before anything lazy is materialized).
365
+ m3 = proto_module::Wrapper::decode(serialized)
366
+ serialized2 = proto_module::Wrapper::encode(m3)
367
+ m4 = proto_module::Wrapper::decode(serialized2)
368
+ run_asserts.call(m4)
369
+
370
+ # Test that the lazy form compares equal to the expanded form.
371
+ m5 = proto_module::Wrapper::decode(serialized2)
372
+ assert_equal m5, m
373
+ end
374
+
375
+ def test_map_wrappers_with_no_value
376
+ run_asserts = ->(m) {
377
+ assert_equal 0.0, m.map_double[0].value
378
+ assert_equal 0.0, m.map_float[0].value
379
+ assert_equal 0, m.map_int32[0].value
380
+ assert_equal 0, m.map_int64[0].value
381
+ assert_equal 0, m.map_uint32[0].value
382
+ assert_equal 0, m.map_uint64[0].value
383
+ assert_equal false, m.map_bool[0].value
384
+ assert_equal '', m.map_string[0].value
385
+ assert_equal '', m.map_bytes[0].value
386
+ }
387
+
388
+ m = proto_module::Wrapper.new(
389
+ map_double: {0 => Google::Protobuf::DoubleValue.new()},
390
+ map_float: {0 => Google::Protobuf::FloatValue.new()},
391
+ map_int32: {0 => Google::Protobuf::Int32Value.new()},
392
+ map_int64: {0 => Google::Protobuf::Int64Value.new()},
393
+ map_uint32: {0 => Google::Protobuf::UInt32Value.new()},
394
+ map_uint64: {0 => Google::Protobuf::UInt64Value.new()},
395
+ map_bool: {0 => Google::Protobuf::BoolValue.new()},
396
+ map_string: {0 => Google::Protobuf::StringValue.new()},
397
+ map_bytes: {0 => Google::Protobuf::BytesValue.new()},
398
+ )
399
+ run_asserts.call(m)
400
+
401
+ serialized = proto_module::Wrapper::encode(m)
402
+ m2 = proto_module::Wrapper::decode(serialized)
403
+ run_asserts.call(m2)
404
+
405
+ # Test the case where we are serializing directly from the parsed form
406
+ # (before anything lazy is materialized).
407
+ m3 = proto_module::Wrapper::decode(serialized)
408
+ serialized2 = proto_module::Wrapper::encode(m3)
409
+ m4 = proto_module::Wrapper::decode(serialized2)
410
+ run_asserts.call(m4)
411
+ end
412
+
221
413
  def test_concurrent_decoding
222
414
  o = Outer.new
223
415
  o.items[0] = Inner.new
@@ -237,7 +429,8 @@ module BasicTest
237
429
  m = MapMessage.new(
238
430
  :map_string_int32 => {"a" => 1, "b" => 2},
239
431
  :map_string_msg => {"a" => TestMessage2.new(:foo => 1),
240
- "b" => TestMessage2.new(:foo => 2)})
432
+ "b" => TestMessage2.new(:foo => 2)},
433
+ :map_string_enum => {"a" => :A, "b" => :B})
241
434
  m2 = MapMessage.decode(MapMessage.encode(m))
242
435
  assert m == m2
243
436
 
@@ -267,6 +460,14 @@ module BasicTest
267
460
  assert_match(/No such field: not_in_message/, e.message)
268
461
  end
269
462
 
463
+ #def test_json_quoted_string
464
+ # m = TestMessage.decode_json(%q(
465
+ # "optionalInt64": "1",,
466
+ # }))
467
+ # puts(m)
468
+ # assert_equal 1, m.optional_int32
469
+ #end
470
+
270
471
  def test_to_h
271
472
  m = TestMessage.new(:optional_bool => true, :optional_double => -10.100001, :optional_string => 'foo', :repeated_string => ['bar1', 'bar2'], :repeated_msg => [TestMessage2.new(:foo => 100)])
272
473
  expected_result = {
@@ -278,6 +479,7 @@ module BasicTest
278
479
  :optional_int32=>0,
279
480
  :optional_int64=>0,
280
481
  :optional_msg=>nil,
482
+ :optional_msg2=>nil,
281
483
  :optional_string=>"foo",
282
484
  :optional_uint32=>0,
283
485
  :optional_uint64=>0,
@@ -298,10 +500,12 @@ module BasicTest
298
500
  m = MapMessage.new(
299
501
  :map_string_int32 => {"a" => 1, "b" => 2},
300
502
  :map_string_msg => {"a" => TestMessage2.new(:foo => 1),
301
- "b" => TestMessage2.new(:foo => 2)})
503
+ "b" => TestMessage2.new(:foo => 2)},
504
+ :map_string_enum => {"a" => :A, "b" => :B})
302
505
  expected_result = {
303
506
  :map_string_int32 => {"a" => 1, "b" => 2},
304
- :map_string_msg => {"a" => {:foo => 1}, "b" => {:foo => 2}}
507
+ :map_string_msg => {"a" => {:foo => 1}, "b" => {:foo => 2}},
508
+ :map_string_enum => {"a" => :A, "b" => :B}
305
509
  }
306
510
  assert_equal expected_result, m.to_h
307
511
  end
@@ -311,26 +515,50 @@ module BasicTest
311
515
  # TODO: Fix JSON in JRuby version.
312
516
  return if RUBY_PLATFORM == "java"
313
517
  m = MapMessage.new(:map_string_int32 => {"a" => 1})
314
- expected = {mapStringInt32: {a: 1}, mapStringMsg: {}}
315
- expected_preserve = {map_string_int32: {a: 1}, map_string_msg: {}}
316
- assert JSON.parse(MapMessage.encode_json(m), :symbolize_names => true) == expected
518
+ expected = {mapStringInt32: {a: 1}, mapStringMsg: {}, mapStringEnum: {}}
519
+ expected_preserve = {map_string_int32: {a: 1}, map_string_msg: {}, map_string_enum: {}}
520
+ assert_equal JSON.parse(MapMessage.encode_json(m, :emit_defaults=>true), :symbolize_names => true), expected
317
521
 
318
- json = MapMessage.encode_json(m, :preserve_proto_fieldnames => true)
319
- assert JSON.parse(json, :symbolize_names => true) == expected_preserve
522
+ json = MapMessage.encode_json(m, :preserve_proto_fieldnames => true, :emit_defaults=>true)
523
+ assert_equal JSON.parse(json, :symbolize_names => true), expected_preserve
320
524
 
321
525
  m2 = MapMessage.decode_json(MapMessage.encode_json(m))
322
- assert m == m2
526
+ assert_equal m, m2
323
527
  end
324
528
 
325
529
  def test_json_maps_emit_defaults_submsg
326
530
  # TODO: Fix JSON in JRuby version.
327
531
  return if RUBY_PLATFORM == "java"
328
- m = MapMessage.new(:map_string_msg => {"a" => TestMessage2.new})
329
- expected = {mapStringInt32: {}, mapStringMsg: {a: {foo: 0}}}
532
+ m = MapMessage.new(:map_string_msg => {"a" => TestMessage2.new(foo: 0)})
533
+ expected = {mapStringInt32: {}, mapStringMsg: {a: {foo: 0}}, mapStringEnum: {}}
330
534
 
331
535
  actual = MapMessage.encode_json(m, :emit_defaults => true)
332
536
 
333
- assert JSON.parse(actual, :symbolize_names => true) == expected
537
+ assert_equal JSON.parse(actual, :symbolize_names => true), expected
538
+ end
539
+
540
+ def test_json_emit_defaults_submsg
541
+ # TODO: Fix JSON in JRuby version.
542
+ return if RUBY_PLATFORM == "java"
543
+ m = TestSingularFields.new(singular_msg: proto_module::TestMessage2.new)
544
+
545
+ expected = {
546
+ singularInt32: 0,
547
+ singularInt64: "0",
548
+ singularUint32: 0,
549
+ singularUint64: "0",
550
+ singularBool: false,
551
+ singularFloat: 0,
552
+ singularDouble: 0,
553
+ singularString: "",
554
+ singularBytes: "",
555
+ singularMsg: {},
556
+ singularEnum: "Default",
557
+ }
558
+
559
+ actual = proto_module::TestMessage.encode_json(m, :emit_defaults => true)
560
+
561
+ assert_equal expected, JSON.parse(actual, :symbolize_names => true)
334
562
  end
335
563
 
336
564
  def test_respond_to
@@ -351,11 +579,26 @@ module BasicTest
351
579
  assert nil != file_descriptor
352
580
  assert_equal "tests/basic_test.proto", file_descriptor.name
353
581
  assert_equal :proto3, file_descriptor.syntax
582
+ end
354
583
 
355
- file_descriptor = BadFieldNames.descriptor.file_descriptor
356
- assert nil != file_descriptor
357
- assert_equal nil, file_descriptor.name
358
- assert_equal :proto3, file_descriptor.syntax
584
+ # Ruby 2.5 changed to raise FrozenError instead of RuntimeError
585
+ FrozenErrorType = Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.5') ? RuntimeError : FrozenError
586
+
587
+ def test_map_freeze
588
+ m = proto_module::MapMessage.new
589
+ m.map_string_int32['a'] = 5
590
+ m.map_string_msg['b'] = proto_module::TestMessage2.new
591
+
592
+ m.map_string_int32.freeze
593
+ m.map_string_msg.freeze
594
+
595
+ assert m.map_string_int32.frozen?
596
+ assert m.map_string_msg.frozen?
597
+
598
+ assert_raise(FrozenErrorType) { m.map_string_int32['foo'] = 1 }
599
+ assert_raise(FrozenErrorType) { m.map_string_msg['bar'] = proto_module::TestMessage2.new }
600
+ assert_raise(FrozenErrorType) { m.map_string_int32.delete('a') }
601
+ assert_raise(FrozenErrorType) { m.map_string_int32.clear }
359
602
  end
360
603
  end
361
604
  end
File without changes
data/tests/stress.rb CHANGED
File without changes
metadata CHANGED
@@ -1,43 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-protobuf
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0
4
+ version: 3.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Protobuf Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-01 00:00:00.000000000 Z
11
+ date: 2021-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler-dock
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.6.0
19
+ version: 1.1.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
20
23
  type: :development
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.0
30
+ - - "<"
25
31
  - !ruby/object:Gem::Version
26
- version: 0.6.0
32
+ version: '2.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rake-compiler
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: 0.9.5
39
+ version: 1.1.0
34
40
  type: :development
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
44
  - - "~>"
39
45
  - !ruby/object:Gem::Version
40
- version: 0.9.5
46
+ version: 1.1.0
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: test-unit
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -79,17 +85,22 @@ extensions:
79
85
  - ext/google/protobuf_c/extconf.rb
80
86
  extra_rdoc_files: []
81
87
  files:
88
+ - ext/google/protobuf_c/convert.c
89
+ - ext/google/protobuf_c/convert.h
82
90
  - ext/google/protobuf_c/defs.c
83
- - ext/google/protobuf_c/encode_decode.c
91
+ - ext/google/protobuf_c/defs.h
84
92
  - ext/google/protobuf_c/extconf.rb
85
93
  - ext/google/protobuf_c/map.c
94
+ - ext/google/protobuf_c/map.h
86
95
  - ext/google/protobuf_c/message.c
96
+ - ext/google/protobuf_c/message.h
87
97
  - ext/google/protobuf_c/protobuf.c
88
98
  - ext/google/protobuf_c/protobuf.h
89
99
  - ext/google/protobuf_c/repeated_field.c
90
- - ext/google/protobuf_c/storage.c
91
- - ext/google/protobuf_c/upb.c
92
- - ext/google/protobuf_c/upb.h
100
+ - ext/google/protobuf_c/repeated_field.h
101
+ - ext/google/protobuf_c/ruby-upb.c
102
+ - ext/google/protobuf_c/ruby-upb.h
103
+ - ext/google/protobuf_c/third_party/wyhash/wyhash.h
93
104
  - ext/google/protobuf_c/wrap_memcpy.c
94
105
  - lib/google/protobuf.rb
95
106
  - lib/google/protobuf/any_pb.rb
@@ -111,7 +122,8 @@ files:
111
122
  homepage: https://developers.google.com/protocol-buffers
112
123
  licenses:
113
124
  - BSD-3-Clause
114
- metadata: {}
125
+ metadata:
126
+ source_code_uri: https://github.com/protocolbuffers/protobuf/tree/v3.16.0/ruby
115
127
  post_install_message:
116
128
  rdoc_options: []
117
129
  require_paths:
@@ -120,15 +132,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
132
  requirements:
121
133
  - - ">="
122
134
  - !ruby/object:Gem::Version
123
- version: '0'
135
+ version: '2.3'
124
136
  required_rubygems_version: !ruby/object:Gem::Requirement
125
137
  requirements:
126
138
  - - ">="
127
139
  - !ruby/object:Gem::Version
128
140
  version: '0'
129
141
  requirements: []
130
- rubyforge_project:
131
- rubygems_version: 2.7.8
142
+ rubygems_version: 3.2.17
132
143
  signing_key:
133
144
  specification_version: 4
134
145
  summary: Protocol Buffers