google-protobuf 3.11.1 → 3.25.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/ext/google/protobuf_c/Rakefile +3 -0
  3. data/ext/google/protobuf_c/convert.c +314 -0
  4. data/ext/google/protobuf_c/convert.h +50 -0
  5. data/ext/google/protobuf_c/defs.c +745 -1620
  6. data/ext/google/protobuf_c/defs.h +82 -0
  7. data/ext/google/protobuf_c/extconf.rb +15 -8
  8. data/ext/google/protobuf_c/glue.c +56 -0
  9. data/ext/google/protobuf_c/map.c +336 -512
  10. data/ext/google/protobuf_c/map.h +44 -0
  11. data/ext/google/protobuf_c/message.c +1096 -520
  12. data/ext/google/protobuf_c/message.h +86 -0
  13. data/ext/google/protobuf_c/protobuf.c +301 -94
  14. data/ext/google/protobuf_c/protobuf.h +66 -620
  15. data/ext/google/protobuf_c/repeated_field.c +323 -353
  16. data/ext/google/protobuf_c/repeated_field.h +41 -0
  17. data/ext/google/protobuf_c/ruby-upb.c +14414 -0
  18. data/ext/google/protobuf_c/ruby-upb.h +13044 -0
  19. data/ext/google/protobuf_c/shared_convert.c +64 -0
  20. data/ext/google/protobuf_c/shared_convert.h +26 -0
  21. data/ext/google/protobuf_c/shared_message.c +65 -0
  22. data/ext/google/protobuf_c/shared_message.h +25 -0
  23. data/ext/google/protobuf_c/third_party/utf8_range/LICENSE +22 -0
  24. data/ext/google/protobuf_c/third_party/utf8_range/naive.c +92 -0
  25. data/ext/google/protobuf_c/third_party/utf8_range/range2-neon.c +157 -0
  26. data/ext/google/protobuf_c/third_party/utf8_range/range2-sse.c +170 -0
  27. data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.h +21 -0
  28. data/ext/google/protobuf_c/wrap_memcpy.c +7 -29
  29. data/lib/google/protobuf/any_pb.rb +24 -5
  30. data/lib/google/protobuf/api_pb.rb +27 -23
  31. data/lib/google/protobuf/descriptor_dsl.rb +465 -0
  32. data/lib/google/protobuf/descriptor_pb.rb +86 -0
  33. data/lib/google/protobuf/duration_pb.rb +24 -5
  34. data/lib/google/protobuf/empty_pb.rb +24 -3
  35. data/lib/google/protobuf/ffi/descriptor.rb +165 -0
  36. data/lib/google/protobuf/ffi/descriptor_pool.rb +75 -0
  37. data/lib/google/protobuf/ffi/enum_descriptor.rb +171 -0
  38. data/lib/google/protobuf/ffi/ffi.rb +213 -0
  39. data/lib/google/protobuf/ffi/field_descriptor.rb +319 -0
  40. data/lib/google/protobuf/ffi/file_descriptor.rb +59 -0
  41. data/lib/google/protobuf/ffi/internal/arena.rb +66 -0
  42. data/lib/google/protobuf/ffi/internal/convert.rb +305 -0
  43. data/lib/google/protobuf/ffi/internal/pointer_helper.rb +35 -0
  44. data/lib/google/protobuf/ffi/internal/type_safety.rb +25 -0
  45. data/lib/google/protobuf/ffi/map.rb +407 -0
  46. data/lib/google/protobuf/ffi/message.rb +662 -0
  47. data/lib/google/protobuf/ffi/object_cache.rb +30 -0
  48. data/lib/google/protobuf/ffi/oneof_descriptor.rb +95 -0
  49. data/lib/google/protobuf/ffi/repeated_field.rb +383 -0
  50. data/lib/google/protobuf/field_mask_pb.rb +24 -4
  51. data/lib/google/protobuf/message_exts.rb +10 -28
  52. data/lib/google/protobuf/object_cache.rb +97 -0
  53. data/lib/google/protobuf/plugin_pb.rb +47 -0
  54. data/lib/google/protobuf/repeated_field.rb +18 -28
  55. data/lib/google/protobuf/source_context_pb.rb +24 -4
  56. data/lib/google/protobuf/struct_pb.rb +24 -20
  57. data/lib/google/protobuf/timestamp_pb.rb +24 -5
  58. data/lib/google/protobuf/type_pb.rb +27 -68
  59. data/lib/google/protobuf/well_known_types.rb +17 -36
  60. data/lib/google/protobuf/wrappers_pb.rb +24 -28
  61. data/lib/google/protobuf.rb +32 -118
  62. data/lib/google/protobuf_ffi.rb +50 -0
  63. data/lib/google/protobuf_native.rb +20 -0
  64. data/lib/google/tasks/ffi.rake +102 -0
  65. metadata +92 -32
  66. data/ext/google/protobuf_c/encode_decode.c +0 -1758
  67. data/ext/google/protobuf_c/storage.c +0 -1149
  68. data/ext/google/protobuf_c/upb.c +0 -13289
  69. data/ext/google/protobuf_c/upb.h +0 -7085
  70. data/tests/basic.rb +0 -445
  71. data/tests/generated_code_test.rb +0 -23
  72. data/tests/stress.rb +0 -38
data/tests/basic.rb DELETED
@@ -1,445 +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_has_field
35
- m = TestMessage.new
36
- assert !m.has_optional_msg?
37
- m.optional_msg = TestMessage2.new
38
- assert m.has_optional_msg?
39
- assert TestMessage.descriptor.lookup('optional_msg').has?(m)
40
-
41
- m = OneofMessage.new
42
- assert !m.has_my_oneof?
43
- m.a = "foo"
44
- assert m.has_my_oneof?
45
- assert_raise NoMethodError do
46
- m.has_a?
47
- end
48
- assert_raise ArgumentError do
49
- OneofMessage.descriptor.lookup('a').has?(m)
50
- end
51
-
52
- m = TestMessage.new
53
- assert_raise NoMethodError do
54
- m.has_optional_int32?
55
- end
56
- assert_raise ArgumentError do
57
- TestMessage.descriptor.lookup('optional_int32').has?(m)
58
- end
59
-
60
- assert_raise NoMethodError do
61
- m.has_optional_string?
62
- end
63
- assert_raise ArgumentError do
64
- TestMessage.descriptor.lookup('optional_string').has?(m)
65
- end
66
-
67
- assert_raise NoMethodError do
68
- m.has_optional_bool?
69
- end
70
- assert_raise ArgumentError do
71
- TestMessage.descriptor.lookup('optional_bool').has?(m)
72
- end
73
-
74
- assert_raise NoMethodError do
75
- m.has_repeated_msg?
76
- end
77
- assert_raise ArgumentError do
78
- TestMessage.descriptor.lookup('repeated_msg').has?(m)
79
- end
80
- end
81
-
82
- def test_set_clear_defaults
83
- m = TestMessage.new
84
-
85
- m.optional_int32 = -42
86
- assert_equal -42, m.optional_int32
87
- m.clear_optional_int32
88
- assert_equal 0, m.optional_int32
89
-
90
- m.optional_int32 = 50
91
- assert_equal 50, m.optional_int32
92
- TestMessage.descriptor.lookup('optional_int32').clear(m)
93
- assert_equal 0, m.optional_int32
94
-
95
- m.optional_string = "foo bar"
96
- assert_equal "foo bar", m.optional_string
97
- m.clear_optional_string
98
- assert_equal "", m.optional_string
99
-
100
- m.optional_string = "foo"
101
- assert_equal "foo", m.optional_string
102
- TestMessage.descriptor.lookup('optional_string').clear(m)
103
- assert_equal "", m.optional_string
104
-
105
- m.optional_msg = TestMessage2.new(:foo => 42)
106
- assert_equal TestMessage2.new(:foo => 42), m.optional_msg
107
- assert m.has_optional_msg?
108
- m.clear_optional_msg
109
- assert_equal nil, m.optional_msg
110
- assert !m.has_optional_msg?
111
-
112
- m.optional_msg = TestMessage2.new(:foo => 42)
113
- assert_equal TestMessage2.new(:foo => 42), m.optional_msg
114
- TestMessage.descriptor.lookup('optional_msg').clear(m)
115
- assert_equal nil, m.optional_msg
116
-
117
- m.repeated_int32.push(1)
118
- assert_equal [1], m.repeated_int32
119
- m.clear_repeated_int32
120
- assert_equal [], m.repeated_int32
121
-
122
- m.repeated_int32.push(1)
123
- assert_equal [1], m.repeated_int32
124
- TestMessage.descriptor.lookup('repeated_int32').clear(m)
125
- assert_equal [], m.repeated_int32
126
-
127
- m = OneofMessage.new
128
- m.a = "foo"
129
- assert_equal "foo", m.a
130
- assert m.has_my_oneof?
131
- m.clear_a
132
- assert !m.has_my_oneof?
133
-
134
- m.a = "foobar"
135
- assert m.has_my_oneof?
136
- m.clear_my_oneof
137
- assert !m.has_my_oneof?
138
-
139
- m.a = "bar"
140
- assert_equal "bar", m.a
141
- assert m.has_my_oneof?
142
- OneofMessage.descriptor.lookup('a').clear(m)
143
- assert !m.has_my_oneof?
144
- end
145
-
146
-
147
- def test_initialization_map_errors
148
- e = assert_raise ArgumentError do
149
- TestMessage.new(:hello => "world")
150
- end
151
- assert_match(/hello/, e.message)
152
-
153
- e = assert_raise ArgumentError do
154
- MapMessage.new(:map_string_int32 => "hello")
155
- end
156
- assert_equal e.message, "Expected Hash object as initializer value for map field 'map_string_int32' (given String)."
157
-
158
- e = assert_raise ArgumentError do
159
- TestMessage.new(:repeated_uint32 => "hello")
160
- end
161
- assert_equal e.message, "Expected array as initializer value for repeated field 'repeated_uint32' (given String)."
162
- end
163
-
164
- def test_map_field
165
- m = MapMessage.new
166
- assert m.map_string_int32 == {}
167
- assert m.map_string_msg == {}
168
-
169
- m = MapMessage.new(
170
- :map_string_int32 => {"a" => 1, "b" => 2},
171
- :map_string_msg => {"a" => TestMessage2.new(:foo => 1),
172
- "b" => TestMessage2.new(:foo => 2)},
173
- :map_string_enum => {"a" => :A, "b" => :B})
174
- assert m.map_string_int32.keys.sort == ["a", "b"]
175
- assert m.map_string_int32["a"] == 1
176
- assert m.map_string_msg["b"].foo == 2
177
- assert m.map_string_enum["a"] == :A
178
-
179
- m.map_string_int32["c"] = 3
180
- assert m.map_string_int32["c"] == 3
181
- m.map_string_msg["c"] = TestMessage2.new(:foo => 3)
182
- assert m.map_string_msg["c"] == TestMessage2.new(:foo => 3)
183
- m.map_string_msg.delete("b")
184
- m.map_string_msg.delete("c")
185
- assert m.map_string_msg == { "a" => TestMessage2.new(:foo => 1) }
186
-
187
- assert_raise Google::Protobuf::TypeError do
188
- m.map_string_msg["e"] = TestMessage.new # wrong value type
189
- end
190
- # ensure nothing was added by the above
191
- assert m.map_string_msg == { "a" => TestMessage2.new(:foo => 1) }
192
-
193
- m.map_string_int32 = Google::Protobuf::Map.new(:string, :int32)
194
- assert_raise Google::Protobuf::TypeError do
195
- m.map_string_int32 = Google::Protobuf::Map.new(:string, :int64)
196
- end
197
- assert_raise Google::Protobuf::TypeError do
198
- m.map_string_int32 = {}
199
- end
200
-
201
- assert_raise TypeError do
202
- m = MapMessage.new(:map_string_int32 => { 1 => "I am not a number" })
203
- end
204
- end
205
-
206
- def test_map_field_with_symbol
207
- m = MapMessage.new
208
- assert m.map_string_int32 == {}
209
- assert m.map_string_msg == {}
210
-
211
- m = MapMessage.new(
212
- :map_string_int32 => {a: 1, "b" => 2},
213
- :map_string_msg => {a: TestMessage2.new(:foo => 1),
214
- b: TestMessage2.new(:foo => 10)})
215
- assert_equal 1, m.map_string_int32[:a]
216
- assert_equal 2, m.map_string_int32[:b]
217
- assert_equal 10, m.map_string_msg[:b].foo
218
- end
219
-
220
- def test_map_inspect
221
- m = MapMessage.new(
222
- :map_string_int32 => {"a" => 1, "b" => 2},
223
- :map_string_msg => {"a" => TestMessage2.new(:foo => 1),
224
- "b" => TestMessage2.new(:foo => 2)},
225
- :map_string_enum => {"a" => :A, "b" => :B})
226
- expected = "<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}>"
227
- assert_equal expected, m.inspect
228
- end
229
-
230
- def test_map_corruption
231
- # This pattern led to a crash in a previous version of upb/protobuf.
232
- m = MapMessage.new(map_string_int32: { "aaa" => 1 })
233
- m.map_string_int32['podid'] = 2
234
- m.map_string_int32['aaa'] = 3
235
- end
236
-
237
- def test_map_wrappers
238
- run_asserts = ->(m) {
239
- assert_equal 2.0, m.map_double[0].value
240
- assert_equal 4.0, m.map_float[0].value
241
- assert_equal 3, m.map_int32[0].value
242
- assert_equal 4, m.map_int64[0].value
243
- assert_equal 5, m.map_uint32[0].value
244
- assert_equal 6, m.map_uint64[0].value
245
- assert_equal true, m.map_bool[0].value
246
- assert_equal 'str', m.map_string[0].value
247
- assert_equal 'fun', m.map_bytes[0].value
248
- }
249
-
250
- m = proto_module::Wrapper.new(
251
- map_double: {0 => Google::Protobuf::DoubleValue.new(value: 2.0)},
252
- map_float: {0 => Google::Protobuf::FloatValue.new(value: 4.0)},
253
- map_int32: {0 => Google::Protobuf::Int32Value.new(value: 3)},
254
- map_int64: {0 => Google::Protobuf::Int64Value.new(value: 4)},
255
- map_uint32: {0 => Google::Protobuf::UInt32Value.new(value: 5)},
256
- map_uint64: {0 => Google::Protobuf::UInt64Value.new(value: 6)},
257
- map_bool: {0 => Google::Protobuf::BoolValue.new(value: true)},
258
- map_string: {0 => Google::Protobuf::StringValue.new(value: 'str')},
259
- map_bytes: {0 => Google::Protobuf::BytesValue.new(value: 'fun')},
260
- )
261
-
262
- run_asserts.call(m)
263
- serialized = proto_module::Wrapper::encode(m)
264
- m2 = proto_module::Wrapper::decode(serialized)
265
- run_asserts.call(m2)
266
-
267
- # Test the case where we are serializing directly from the parsed form
268
- # (before anything lazy is materialized).
269
- m3 = proto_module::Wrapper::decode(serialized)
270
- serialized2 = proto_module::Wrapper::encode(m3)
271
- m4 = proto_module::Wrapper::decode(serialized2)
272
- run_asserts.call(m4)
273
-
274
- # Test that the lazy form compares equal to the expanded form.
275
- m5 = proto_module::Wrapper::decode(serialized2)
276
- assert_equal m5, m
277
- end
278
-
279
- def test_concurrent_decoding
280
- o = Outer.new
281
- o.items[0] = Inner.new
282
- raw = Outer.encode(o)
283
-
284
- thds = 2.times.map do
285
- Thread.new do
286
- 100000.times do
287
- assert_equal o, Outer.decode(raw)
288
- end
289
- end
290
- end
291
- thds.map(&:join)
292
- end
293
-
294
- def test_map_encode_decode
295
- m = MapMessage.new(
296
- :map_string_int32 => {"a" => 1, "b" => 2},
297
- :map_string_msg => {"a" => TestMessage2.new(:foo => 1),
298
- "b" => TestMessage2.new(:foo => 2)},
299
- :map_string_enum => {"a" => :A, "b" => :B})
300
- m2 = MapMessage.decode(MapMessage.encode(m))
301
- assert m == m2
302
-
303
- m3 = MapMessageWireEquiv.decode(MapMessage.encode(m))
304
- assert m3.map_string_int32.length == 2
305
-
306
- kv = {}
307
- m3.map_string_int32.map { |msg| kv[msg.key] = msg.value }
308
- assert kv == {"a" => 1, "b" => 2}
309
-
310
- kv = {}
311
- m3.map_string_msg.map { |msg| kv[msg.key] = msg.value }
312
- assert kv == {"a" => TestMessage2.new(:foo => 1),
313
- "b" => TestMessage2.new(:foo => 2)}
314
- end
315
-
316
- def test_protobuf_decode_json_ignore_unknown_fields
317
- m = TestMessage.decode_json({
318
- optional_string: "foo",
319
- not_in_message: "some_value"
320
- }.to_json, { ignore_unknown_fields: true })
321
-
322
- assert_equal m.optional_string, "foo"
323
- e = assert_raise Google::Protobuf::ParseError do
324
- TestMessage.decode_json({ not_in_message: "some_value" }.to_json)
325
- end
326
- assert_match(/No such field: not_in_message/, e.message)
327
- end
328
-
329
- #def test_json_quoted_string
330
- # m = TestMessage.decode_json(%q(
331
- # "optionalInt64": "1",,
332
- # }))
333
- # puts(m)
334
- # assert_equal 1, m.optional_int32
335
- #end
336
-
337
- def test_to_h
338
- m = TestMessage.new(:optional_bool => true, :optional_double => -10.100001, :optional_string => 'foo', :repeated_string => ['bar1', 'bar2'], :repeated_msg => [TestMessage2.new(:foo => 100)])
339
- expected_result = {
340
- :optional_bool=>true,
341
- :optional_bytes=>"",
342
- :optional_double=>-10.100001,
343
- :optional_enum=>:Default,
344
- :optional_float=>0.0,
345
- :optional_int32=>0,
346
- :optional_int64=>0,
347
- :optional_msg=>nil,
348
- :optional_string=>"foo",
349
- :optional_uint32=>0,
350
- :optional_uint64=>0,
351
- :repeated_bool=>[],
352
- :repeated_bytes=>[],
353
- :repeated_double=>[],
354
- :repeated_enum=>[],
355
- :repeated_float=>[],
356
- :repeated_int32=>[],
357
- :repeated_int64=>[],
358
- :repeated_msg=>[{:foo => 100}],
359
- :repeated_string=>["bar1", "bar2"],
360
- :repeated_uint32=>[],
361
- :repeated_uint64=>[]
362
- }
363
- assert_equal expected_result, m.to_h
364
-
365
- m = MapMessage.new(
366
- :map_string_int32 => {"a" => 1, "b" => 2},
367
- :map_string_msg => {"a" => TestMessage2.new(:foo => 1),
368
- "b" => TestMessage2.new(:foo => 2)},
369
- :map_string_enum => {"a" => :A, "b" => :B})
370
- expected_result = {
371
- :map_string_int32 => {"a" => 1, "b" => 2},
372
- :map_string_msg => {"a" => {:foo => 1}, "b" => {:foo => 2}},
373
- :map_string_enum => {"a" => :A, "b" => :B}
374
- }
375
- assert_equal expected_result, m.to_h
376
- end
377
-
378
-
379
- def test_json_maps
380
- # TODO: Fix JSON in JRuby version.
381
- return if RUBY_PLATFORM == "java"
382
- m = MapMessage.new(:map_string_int32 => {"a" => 1})
383
- expected = {mapStringInt32: {a: 1}, mapStringMsg: {}, mapStringEnum: {}}
384
- expected_preserve = {map_string_int32: {a: 1}, map_string_msg: {}, map_string_enum: {}}
385
- assert_equal JSON.parse(MapMessage.encode_json(m), :symbolize_names => true), expected
386
-
387
- json = MapMessage.encode_json(m, :preserve_proto_fieldnames => true)
388
- assert_equal JSON.parse(json, :symbolize_names => true), expected_preserve
389
-
390
- m2 = MapMessage.decode_json(MapMessage.encode_json(m))
391
- assert_equal m, m2
392
- end
393
-
394
- def test_json_maps_emit_defaults_submsg
395
- # TODO: Fix JSON in JRuby version.
396
- return if RUBY_PLATFORM == "java"
397
- m = MapMessage.new(:map_string_msg => {"a" => TestMessage2.new})
398
- expected = {mapStringInt32: {}, mapStringMsg: {a: {foo: 0}}, mapStringEnum: {}}
399
-
400
- actual = MapMessage.encode_json(m, :emit_defaults => true)
401
-
402
- assert_equal JSON.parse(actual, :symbolize_names => true), expected
403
- end
404
-
405
- def test_respond_to
406
- # This test fails with JRuby 1.7.23, likely because of an old JRuby bug.
407
- return if RUBY_PLATFORM == "java"
408
- msg = MapMessage.new
409
- assert msg.respond_to?(:map_string_int32)
410
- assert !msg.respond_to?(:bacon)
411
- end
412
-
413
- def test_file_descriptor
414
- file_descriptor = TestMessage.descriptor.file_descriptor
415
- assert nil != file_descriptor
416
- assert_equal "tests/basic_test.proto", file_descriptor.name
417
- assert_equal :proto3, file_descriptor.syntax
418
-
419
- file_descriptor = TestEnum.descriptor.file_descriptor
420
- assert nil != file_descriptor
421
- assert_equal "tests/basic_test.proto", file_descriptor.name
422
- assert_equal :proto3, file_descriptor.syntax
423
- end
424
-
425
- # Ruby 2.5 changed to raise FrozenError instead of RuntimeError
426
- FrozenErrorType = Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.5') ? RuntimeError : FrozenError
427
-
428
- def test_map_freeze
429
- m = proto_module::MapMessage.new
430
- m.map_string_int32['a'] = 5
431
- m.map_string_msg['b'] = proto_module::TestMessage2.new
432
-
433
- m.map_string_int32.freeze
434
- m.map_string_msg.freeze
435
-
436
- assert m.map_string_int32.frozen?
437
- assert m.map_string_msg.frozen?
438
-
439
- assert_raise(FrozenErrorType) { m.map_string_int32['foo'] = 1 }
440
- assert_raise(FrozenErrorType) { m.map_string_msg['bar'] = proto_module::TestMessage2.new }
441
- assert_raise(FrozenErrorType) { m.map_string_int32.delete('a') }
442
- assert_raise(FrozenErrorType) { m.map_string_int32.clear }
443
- end
444
- end
445
- 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 mnew.inspect, m.inspect
34
- assert TestMessage.encode(mnew) == data
35
- end
36
- end
37
- end
38
- end