google-protobuf 3.0.0.alpha.1.1 → 3.0.0.alpha.2.0
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 +5 -13
- data/ext/google/protobuf_c/defs.c +298 -9
- data/ext/google/protobuf_c/encode_decode.c +204 -29
- data/ext/google/protobuf_c/map.c +1 -1
- data/ext/google/protobuf_c/message.c +44 -0
- data/ext/google/protobuf_c/protobuf.c +2 -0
- data/ext/google/protobuf_c/protobuf.h +61 -2
- data/ext/google/protobuf_c/repeated_field.c +28 -31
- data/ext/google/protobuf_c/storage.c +230 -66
- data/ext/google/protobuf_c/upb.c +938 -153
- data/ext/google/protobuf_c/upb.h +607 -55
- data/tests/basic.rb +114 -2
- data/tests/generated_code_test.rb +17 -0
- metadata +7 -5
data/tests/basic.rb
CHANGED
@@ -73,6 +73,15 @@ module BasicTest
|
|
73
73
|
optional :key, :string, 1
|
74
74
|
optional :value, :message, 2, "TestMessage2"
|
75
75
|
end
|
76
|
+
|
77
|
+
add_message "OneofMessage" do
|
78
|
+
oneof :my_oneof do
|
79
|
+
optional :a, :string, 1
|
80
|
+
optional :b, :int32, 2
|
81
|
+
optional :c, :message, 3, "TestMessage2"
|
82
|
+
optional :d, :enum, 4, "TestEnum"
|
83
|
+
end
|
84
|
+
end
|
76
85
|
end
|
77
86
|
|
78
87
|
TestMessage = pool.lookup("TestMessage").msgclass
|
@@ -87,6 +96,7 @@ module BasicTest
|
|
87
96
|
pool.lookup("MapMessageWireEquiv_entry1").msgclass
|
88
97
|
MapMessageWireEquiv_entry2 =
|
89
98
|
pool.lookup("MapMessageWireEquiv_entry2").msgclass
|
99
|
+
OneofMessage = pool.lookup("OneofMessage").msgclass
|
90
100
|
|
91
101
|
# ------------ test cases ---------------
|
92
102
|
|
@@ -226,7 +236,8 @@ module BasicTest
|
|
226
236
|
assert l.count == 0
|
227
237
|
l = Google::Protobuf::RepeatedField.new(:int32, [1, 2, 3])
|
228
238
|
assert l.count == 3
|
229
|
-
|
239
|
+
assert_equal [1, 2, 3], l
|
240
|
+
assert_equal l, [1, 2, 3]
|
230
241
|
l.push 4
|
231
242
|
assert l == [1, 2, 3, 4]
|
232
243
|
dst_list = []
|
@@ -380,7 +391,7 @@ module BasicTest
|
|
380
391
|
# We only assert on inspect value when there is one map entry because the
|
381
392
|
# order in which elements appear is unspecified (depends on the internal
|
382
393
|
# hash function). We don't want a brittle test.
|
383
|
-
assert m.inspect == "{\"jkl;\"
|
394
|
+
assert m.inspect == "{\"jkl;\"=>42}"
|
384
395
|
|
385
396
|
assert m.keys == ["jkl;"]
|
386
397
|
assert m.values == [42]
|
@@ -582,6 +593,91 @@ module BasicTest
|
|
582
593
|
"b" => TestMessage2.new(:foo => 2)}
|
583
594
|
end
|
584
595
|
|
596
|
+
def test_oneof_descriptors
|
597
|
+
d = OneofMessage.descriptor
|
598
|
+
o = d.lookup_oneof("my_oneof")
|
599
|
+
assert o != nil
|
600
|
+
assert o.class == Google::Protobuf::OneofDescriptor
|
601
|
+
assert o.name == "my_oneof"
|
602
|
+
oneof_count = 0
|
603
|
+
d.each_oneof{ |oneof|
|
604
|
+
oneof_count += 1
|
605
|
+
assert oneof == o
|
606
|
+
}
|
607
|
+
assert oneof_count == 1
|
608
|
+
assert o.count == 4
|
609
|
+
field_names = o.map{|f| f.name}.sort
|
610
|
+
assert field_names == ["a", "b", "c", "d"]
|
611
|
+
end
|
612
|
+
|
613
|
+
def test_oneof
|
614
|
+
d = OneofMessage.new
|
615
|
+
assert d.a == nil
|
616
|
+
assert d.b == nil
|
617
|
+
assert d.c == nil
|
618
|
+
assert d.d == nil
|
619
|
+
assert d.my_oneof == nil
|
620
|
+
|
621
|
+
d.a = "hi"
|
622
|
+
assert d.a == "hi"
|
623
|
+
assert d.b == nil
|
624
|
+
assert d.c == nil
|
625
|
+
assert d.d == nil
|
626
|
+
assert d.my_oneof == :a
|
627
|
+
|
628
|
+
d.b = 42
|
629
|
+
assert d.a == nil
|
630
|
+
assert d.b == 42
|
631
|
+
assert d.c == nil
|
632
|
+
assert d.d == nil
|
633
|
+
assert d.my_oneof == :b
|
634
|
+
|
635
|
+
d.c = TestMessage2.new(:foo => 100)
|
636
|
+
assert d.a == nil
|
637
|
+
assert d.b == nil
|
638
|
+
assert d.c.foo == 100
|
639
|
+
assert d.d == nil
|
640
|
+
assert d.my_oneof == :c
|
641
|
+
|
642
|
+
d.d = :C
|
643
|
+
assert d.a == nil
|
644
|
+
assert d.b == nil
|
645
|
+
assert d.c == nil
|
646
|
+
assert d.d == :C
|
647
|
+
assert d.my_oneof == :d
|
648
|
+
|
649
|
+
d2 = OneofMessage.decode(OneofMessage.encode(d))
|
650
|
+
assert d2 == d
|
651
|
+
|
652
|
+
encoded_field_a = OneofMessage.encode(OneofMessage.new(:a => "string"))
|
653
|
+
encoded_field_b = OneofMessage.encode(OneofMessage.new(:b => 1000))
|
654
|
+
encoded_field_c = OneofMessage.encode(
|
655
|
+
OneofMessage.new(:c => TestMessage2.new(:foo => 1)))
|
656
|
+
encoded_field_d = OneofMessage.encode(OneofMessage.new(:d => :B))
|
657
|
+
|
658
|
+
d3 = OneofMessage.decode(
|
659
|
+
encoded_field_c + encoded_field_a + encoded_field_d)
|
660
|
+
assert d3.a == nil
|
661
|
+
assert d3.b == nil
|
662
|
+
assert d3.c == nil
|
663
|
+
assert d3.d == :B
|
664
|
+
|
665
|
+
d4 = OneofMessage.decode(
|
666
|
+
encoded_field_c + encoded_field_a + encoded_field_d +
|
667
|
+
encoded_field_c)
|
668
|
+
assert d4.a == nil
|
669
|
+
assert d4.b == nil
|
670
|
+
assert d4.c.foo == 1
|
671
|
+
assert d4.d == nil
|
672
|
+
|
673
|
+
d5 = OneofMessage.new(:a => "hello")
|
674
|
+
assert d5.a != nil
|
675
|
+
d5.a = nil
|
676
|
+
assert d5.a == nil
|
677
|
+
assert OneofMessage.encode(d5) == ''
|
678
|
+
assert d5.my_oneof == nil
|
679
|
+
end
|
680
|
+
|
585
681
|
def test_enum_field
|
586
682
|
m = TestMessage.new
|
587
683
|
assert m.optional_enum == :Default
|
@@ -621,6 +717,14 @@ module BasicTest
|
|
621
717
|
assert m.repeated_msg[0].object_id != m2.repeated_msg[0].object_id
|
622
718
|
end
|
623
719
|
|
720
|
+
def test_eq
|
721
|
+
m = TestMessage.new(:optional_int32 => 42,
|
722
|
+
:repeated_int32 => [1, 2, 3])
|
723
|
+
m2 = TestMessage.new(:optional_int32 => 43,
|
724
|
+
:repeated_int32 => [1, 2, 3])
|
725
|
+
assert m != m2
|
726
|
+
end
|
727
|
+
|
624
728
|
def test_enum_lookup
|
625
729
|
assert TestEnum::A == 1
|
626
730
|
assert TestEnum::B == 2
|
@@ -888,5 +992,13 @@ module BasicTest
|
|
888
992
|
m2 = TestMessage.decode_json(json_text)
|
889
993
|
assert m == m2
|
890
994
|
end
|
995
|
+
|
996
|
+
def test_json_maps
|
997
|
+
m = MapMessage.new(:map_string_int32 => {"a" => 1})
|
998
|
+
expected = '{"map_string_int32":{"a":1},"map_string_msg":{}}'
|
999
|
+
assert MapMessage.encode_json(m) == expected
|
1000
|
+
m2 = MapMessage.decode_json(MapMessage.encode_json(m))
|
1001
|
+
assert m == m2
|
1002
|
+
end
|
891
1003
|
end
|
892
1004
|
end
|
@@ -0,0 +1,17 @@
|
|
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'
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class GeneratedCodeTest < Test::Unit::TestCase
|
10
|
+
def test_generated_msg
|
11
|
+
# just test that we can instantiate the message. The purpose of this test
|
12
|
+
# is to ensure that the output of the code generator is valid Ruby and
|
13
|
+
# successfully creates message definitions and classes, not to test every
|
14
|
+
# aspect of the extension (basic.rb is for that).
|
15
|
+
m = A::B::C::TestMessage.new()
|
16
|
+
end
|
17
|
+
end
|
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.0.0.alpha.
|
4
|
+
version: 3.0.0.alpha.2.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: 2015-
|
11
|
+
date: 2015-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Protocol Buffers are Google's data interchange format.
|
14
14
|
email: protobuf@googlegroups.com
|
@@ -30,6 +30,7 @@ files:
|
|
30
30
|
- ext/google/protobuf_c/upb.h
|
31
31
|
- lib/google/protobuf.rb
|
32
32
|
- tests/basic.rb
|
33
|
+
- tests/generated_code_test.rb
|
33
34
|
- tests/stress.rb
|
34
35
|
homepage:
|
35
36
|
licenses:
|
@@ -41,20 +42,21 @@ require_paths:
|
|
41
42
|
- lib
|
42
43
|
required_ruby_version: !ruby/object:Gem::Requirement
|
43
44
|
requirements:
|
44
|
-
- -
|
45
|
+
- - ">="
|
45
46
|
- !ruby/object:Gem::Version
|
46
47
|
version: '0'
|
47
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
49
|
requirements:
|
49
|
-
- -
|
50
|
+
- - ">"
|
50
51
|
- !ruby/object:Gem::Version
|
51
52
|
version: 1.3.1
|
52
53
|
requirements: []
|
53
54
|
rubyforge_project:
|
54
|
-
rubygems_version: 2.4.
|
55
|
+
rubygems_version: 2.4.6
|
55
56
|
signing_key:
|
56
57
|
specification_version: 4
|
57
58
|
summary: Protocol Buffers
|
58
59
|
test_files:
|
59
60
|
- tests/basic.rb
|
60
61
|
- tests/stress.rb
|
62
|
+
- tests/generated_code_test.rb
|