ruby-protocol-buffers 1.5.0 → 1.5.1

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.
@@ -159,6 +159,10 @@ module ProtocolBuffers
159
159
  #{name}.clear
160
160
  __value.each { |i| @#{name}.push i }
161
161
  end
162
+ if @parent_for_notify
163
+ @parent_for_notify.default_changed(@tag_for_notify)
164
+ @parent_for_notify = @tag_for_notify = nil
165
+ end
162
166
  end
163
167
  end
164
168
  EOF
@@ -329,11 +329,38 @@ module ProtocolBuffers
329
329
  # Comparison by class and field values.
330
330
  def ==(obj)
331
331
  return false unless obj.is_a?(self.class)
332
- fields.each do |tag, field|
333
- return false unless self.__send__(field.name) == obj.__send__(field.name)
332
+ fields.each do |tag, _|
333
+ if value_for_tag?(tag)
334
+ return false unless (obj.value_for_tag?(tag) && value_for_tag(tag) == obj.value_for_tag(tag))
335
+ else
336
+ return false if obj.value_for_tag?(tag)
337
+ end
334
338
  end
335
339
  return true
336
340
  end
341
+
342
+ # Comparison by class and field values.
343
+ def eql?(obj)
344
+ return false unless obj.is_a?(self.class)
345
+ fields.each do |tag, _|
346
+ if value_for_tag?(tag)
347
+ return false unless (obj.value_for_tag?(tag) && value_for_tag(tag).eql?(obj.value_for_tag(tag)))
348
+ else
349
+ return false if obj.value_for_tag?(tag)
350
+ end
351
+ end
352
+ return true
353
+ end
354
+
355
+ def hash
356
+ hash_code = 0
357
+ fields.each do |tag, _|
358
+ if value_for_tag?(tag)
359
+ hash_code = hash_code ^ value_for_tag(tag).hash
360
+ end
361
+ end
362
+ hash_code
363
+ end
337
364
 
338
365
  # Reset all fields to the default value.
339
366
  def clear!
@@ -1,3 +1,3 @@
1
1
  module ProtocolBuffers
2
- VERSION = "1.5.0"
2
+ VERSION = "1.5.1"
3
3
  end
@@ -0,0 +1,119 @@
1
+ # encoding: binary
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
6
+ require 'protocol_buffers'
7
+
8
+ describe ProtocolBuffers, "message" do
9
+ before(:each) do
10
+ # clear our namespaces
11
+ %w( Simple Featureful Foo Packed TehUnknown TehUnknown2 TehUnknown3 Enums A C Services).each do |klass|
12
+ Object.send(:remove_const, klass.to_sym) if Object.const_defined?(klass.to_sym)
13
+ end
14
+
15
+ # load test protos
16
+ %w( simple featureful packed enums no_package services).each do |proto|
17
+ load File.join(File.dirname(__FILE__), "proto_files", "#{proto}.pb.rb")
18
+ end
19
+ end
20
+
21
+ it "correctly handles value_for_tag? when fields are set in the constructor" do
22
+ a = Featureful::A.new(
23
+ :i2 => 1,
24
+ :sub2 => Featureful::A::Sub.new(
25
+ :payload => "test_payload"
26
+ )
27
+ )
28
+
29
+ a.value_for_tag?(1).should == true
30
+ a.value_for_tag?(5).should == true
31
+ end
32
+
33
+ it "correctly handles value_for_tag? when a MessageField is set to the same object in two locations within the same proto and set in the constructor" do
34
+ d = Featureful::D.new(
35
+ :f => [1, 2, 3].map do |num|
36
+ Featureful::F.new(
37
+ :s => "#{num}"
38
+ )
39
+ end
40
+ )
41
+ c = Featureful::C.new(
42
+ :d => d,
43
+ :e => [1].map do |num|
44
+ Featureful::E.new(
45
+ :d => d
46
+ )
47
+ end
48
+ )
49
+
50
+ c.value_for_tag?(1).should == true
51
+ end
52
+
53
+ it "correctly handles value_for_tag? when a Messagefield is set to the same object in two locations within the same proto and set outside of the constructor" do
54
+ d = Featureful::D.new
55
+ d.f = [1, 2, 3].map do |num|
56
+ Featureful::F.new(
57
+ :s => "#{num}"
58
+ )
59
+ end
60
+ c = Featureful::C.new
61
+ c.d = d
62
+ c.e = [1].map do |num|
63
+ Featureful::E.new(
64
+ :d => d
65
+ )
66
+ end
67
+
68
+ c.value_for_tag?(1).should == true
69
+ end
70
+
71
+ it "correctly handles value_for_tag? when a field is accessed and then modified and this field is a MessageField with only a repeated field accessed" do
72
+ c = Featureful::C.new
73
+ c_d = c.d
74
+ c_d.f = [1, 2, 3].map do |num|
75
+ Featureful::F.new(
76
+ :s => "#{num}"
77
+ )
78
+ end
79
+ d = Featureful::D.new
80
+ d.f = [1, 2, 3].map do |num|
81
+ Featureful::F.new(
82
+ :s => "#{num}"
83
+ )
84
+ end
85
+ c.e = [1].map do |num|
86
+ Featureful::E.new(
87
+ :d => d
88
+ )
89
+ end
90
+
91
+ c.value_for_tag?(1).should == true
92
+ end
93
+
94
+ it "correctly handles value_for_tag? when a field is accessed and then modified and this field is a MessageField with a repeated and optional field accessed" do
95
+ c = Featureful::C.new
96
+ c_d = c.d
97
+ c_d.f = [1, 2, 3].map do |num|
98
+ Featureful::F.new(
99
+ :s => "#{num}"
100
+ )
101
+ end
102
+ d = Featureful::D.new
103
+ d.f = [1, 2, 3].map do |num|
104
+ Featureful::F.new(
105
+ :s => "#{num}"
106
+ )
107
+ end
108
+ d.f2 = Featureful::F.new(
109
+ :s => "4"
110
+ )
111
+ c.e = [1].map do |num|
112
+ Featureful::E.new(
113
+ :d => d
114
+ )
115
+ end
116
+
117
+ c.value_for_tag?(1).should == true
118
+ end
119
+ end
@@ -8,10 +8,17 @@ module Featureful
8
8
  class A < ::ProtocolBuffers::Message; end
9
9
  class B < ::ProtocolBuffers::Message; end
10
10
  class ABitOfEverything < ::ProtocolBuffers::Message; end
11
+ class C < ::ProtocolBuffers::Message; end
12
+ class D < ::ProtocolBuffers::Message; end
13
+ class E < ::ProtocolBuffers::Message; end
14
+ class F < ::ProtocolBuffers::Message; end
11
15
 
12
16
  # enums
13
17
  module MainPayloads
14
18
  include ::ProtocolBuffers::Enum
19
+
20
+ set_fully_qualified_name "featureful.MainPayloads"
21
+
15
22
  P1 = 2
16
23
  P2 = 3
17
24
  P3 = 4
@@ -24,6 +31,8 @@ module Featureful
24
31
  class Group2 < ::ProtocolBuffers::Message; end
25
32
  class Group3 < ::ProtocolBuffers::Message; end
26
33
 
34
+ set_fully_qualified_name "featureful.A"
35
+
27
36
  # nested messages
28
37
  class Sub < ::ProtocolBuffers::Message
29
38
  # forward declarations
@@ -32,12 +41,19 @@ module Featureful
32
41
  # enums
33
42
  module Payloads
34
43
  include ::ProtocolBuffers::Enum
44
+
45
+ set_fully_qualified_name "featureful.A.Sub.Payloads"
46
+
35
47
  P1 = 0
36
48
  P2 = 1
37
49
  end
38
50
 
51
+ set_fully_qualified_name "featureful.A.Sub"
52
+
39
53
  # nested messages
40
54
  class SubSub < ::ProtocolBuffers::Message
55
+ set_fully_qualified_name "featureful.A.Sub.SubSub"
56
+
41
57
  optional :string, :subsub_payload, 1
42
58
  end
43
59
 
@@ -50,8 +66,12 @@ module Featureful
50
66
  # forward declarations
51
67
  class Subgroup < ::ProtocolBuffers::Message; end
52
68
 
69
+ set_fully_qualified_name "featureful.A.Group1"
70
+
53
71
  # nested messages
54
72
  class Subgroup < ::ProtocolBuffers::Message
73
+ set_fully_qualified_name "featureful.A.Group1.Subgroup"
74
+
55
75
  required :int32, :i1, 1
56
76
  end
57
77
 
@@ -63,8 +83,12 @@ module Featureful
63
83
  # forward declarations
64
84
  class Subgroup < ::ProtocolBuffers::Message; end
65
85
 
86
+ set_fully_qualified_name "featureful.A.Group2"
87
+
66
88
  # nested messages
67
89
  class Subgroup < ::ProtocolBuffers::Message
90
+ set_fully_qualified_name "featureful.A.Group2.Subgroup"
91
+
68
92
  required :int32, :i1, 1
69
93
  end
70
94
 
@@ -76,8 +100,12 @@ module Featureful
76
100
  # forward declarations
77
101
  class Subgroup < ::ProtocolBuffers::Message; end
78
102
 
103
+ set_fully_qualified_name "featureful.A.Group3"
104
+
79
105
  # nested messages
80
106
  class Subgroup < ::ProtocolBuffers::Message
107
+ set_fully_qualified_name "featureful.A.Group3.Subgroup"
108
+
81
109
  required :int32, :i1, 1
82
110
  end
83
111
 
@@ -97,10 +125,14 @@ module Featureful
97
125
  end
98
126
 
99
127
  class B < ::ProtocolBuffers::Message
128
+ set_fully_qualified_name "featureful.B"
129
+
100
130
  repeated ::Featureful::A, :a, 1
101
131
  end
102
132
 
103
133
  class ABitOfEverything < ::ProtocolBuffers::Message
134
+ set_fully_qualified_name "featureful.ABitOfEverything"
135
+
104
136
  optional :double, :double_field, 1
105
137
  optional :float, :float_field, 2
106
138
  optional :int32, :int32_field, 3
@@ -118,4 +150,30 @@ module Featureful
118
150
  optional :bytes, :bytes_field, 15
119
151
  end
120
152
 
153
+ class C < ::ProtocolBuffers::Message
154
+ set_fully_qualified_name "featureful.C"
155
+
156
+ optional ::Featureful::D, :d, 1
157
+ repeated ::Featureful::E, :e, 2
158
+ end
159
+
160
+ class D < ::ProtocolBuffers::Message
161
+ set_fully_qualified_name "featureful.D"
162
+
163
+ repeated ::Featureful::F, :f, 1
164
+ optional ::Featureful::F, :f2, 2
165
+ end
166
+
167
+ class E < ::ProtocolBuffers::Message
168
+ set_fully_qualified_name "featureful.E"
169
+
170
+ optional ::Featureful::D, :d, 1
171
+ end
172
+
173
+ class F < ::ProtocolBuffers::Message
174
+ set_fully_qualified_name "featureful.F"
175
+
176
+ optional :string, :s, 1
177
+ end
178
+
121
179
  end
@@ -73,3 +73,21 @@ message ABitOfEverything {
73
73
  optional string string_field = 14 [default = "zomgkittenz"];
74
74
  optional bytes bytes_field = 15;
75
75
  };
76
+
77
+ message C {
78
+ optional D d = 1;
79
+ repeated E e = 2;
80
+ }
81
+
82
+ message D {
83
+ repeated F f = 1;
84
+ optional F f2 = 2;
85
+ }
86
+
87
+ message E {
88
+ optional D d = 1;
89
+ }
90
+
91
+ message F {
92
+ optional string s = 1;
93
+ }
@@ -742,6 +742,107 @@ describe ProtocolBuffers, "runtime" do
742
742
 
743
743
  end
744
744
 
745
+ it "correctly handles ==, eql? and hash" do
746
+ f1 = Featureful::A.new
747
+ f1.i1 = [1, 2, 3]
748
+ f1.i3 = 4
749
+ sub111 = Featureful::A::Sub.new
750
+ sub111.payload = "sub11payload"
751
+ sub111.payload_type = Featureful::A::Sub::Payloads::P1
752
+ sub111.subsub1.subsub_payload = "sub11subsubpayload"
753
+ sub112 = Featureful::A::Sub.new
754
+ sub112.payload = "sub12payload"
755
+ sub112.payload_type = Featureful::A::Sub::Payloads::P2
756
+ sub112.subsub1.subsub_payload = "sub12subsubpayload"
757
+ f1.sub1 = [sub111, sub112]
758
+ f1.sub3.payload = ""
759
+ f1.sub3.payload_type = Featureful::A::Sub::Payloads::P1
760
+ f1.sub3.subsub1.subsub_payload = "sub3subsubpayload"
761
+ f1.group3.i1 = 1
762
+
763
+ f2 = Featureful::A.new
764
+ f2.i1 = [1, 2, 3]
765
+ f2.i3 = 4
766
+ sub211 = Featureful::A::Sub.new
767
+ sub211.payload = "sub11payload"
768
+ sub211.payload_type = Featureful::A::Sub::Payloads::P1
769
+ sub211.subsub1.subsub_payload = "sub11subsubpayload"
770
+ sub212 = Featureful::A::Sub.new
771
+ sub212.payload = "sub12payload"
772
+ sub212.payload_type = Featureful::A::Sub::Payloads::P2
773
+ sub212.subsub1.subsub_payload = "sub12subsubpayload"
774
+ f2.sub1 = [sub211, sub212]
775
+ f2.sub3.payload = ""
776
+ f2.sub3.payload_type = Featureful::A::Sub::Payloads::P1
777
+ f2.sub3.subsub1.subsub_payload = "sub3subsubpayload"
778
+ f2.group3.i1 = 1
779
+
780
+ # different because subsub1.sub_payload different
781
+ f3 = Featureful::A.new
782
+ f3.i1 = [1, 2, 3]
783
+ f3.i3 = 4
784
+ sub311 = Featureful::A::Sub.new
785
+ sub311.payload = "sub11payload"
786
+ sub311.payload_type = Featureful::A::Sub::Payloads::P1
787
+ sub311.subsub1.subsub_payload = "sub11subsubpayload"
788
+ sub312 = Featureful::A::Sub.new
789
+ sub312.payload = "sub12payload"
790
+ sub312.payload_type = Featureful::A::Sub::Payloads::P2
791
+ sub312.subsub1.subsub_payload = "sub12subsubpayload_DIFFERENT"
792
+ f3.sub1 = [sub311, sub312]
793
+ f3.sub3.payload = ""
794
+ f3.sub3.payload_type = Featureful::A::Sub::Payloads::P1
795
+ f3.sub3.subsub1.subsub_payload = "sub3subsubpayload"
796
+ f3.group3.i1 = 1
797
+
798
+ # different because sub3.payload not set
799
+ f4 = Featureful::A.new
800
+ f4.i1 = [1, 2, 3]
801
+ f4.i3 = 4
802
+ sub411 = Featureful::A::Sub.new
803
+ sub411.payload = "sub11payload"
804
+ sub411.payload_type = Featureful::A::Sub::Payloads::P1
805
+ sub411.subsub1.subsub_payload = "sub11subsubpayload"
806
+ sub412 = Featureful::A::Sub.new
807
+ sub412.payload = "sub12payload"
808
+ sub412.payload_type = Featureful::A::Sub::Payloads::P2
809
+ sub412.subsub1.subsub_payload = "sub12subsubpayload"
810
+ f4.sub1 = [sub411, sub412]
811
+ f4.sub3.payload_type = Featureful::A::Sub::Payloads::P1
812
+ f4.sub3.subsub1.subsub_payload = "sub3subsubpayload"
813
+ f4.group3.i1 = 1
814
+
815
+ f1.should == f2
816
+ f1.should_not == f3
817
+ f1.should_not == f4
818
+ f2.should == f1
819
+ f2.should_not == f3
820
+ f2.should_not == f4
821
+ f3.should_not == f1
822
+ f3.should_not == f2
823
+ f3.should_not == f4
824
+
825
+ f1.eql?(f2).should == true
826
+ f1.eql?(f3).should_not == true
827
+ f1.eql?(f4).should_not == true
828
+ f2.eql?(f1).should == true
829
+ f2.eql?(f3).should_not == true
830
+ f2.eql?(f4).should_not == true
831
+ f3.eql?(f1).should_not == true
832
+ f3.eql?(f2).should_not == true
833
+ f3.eql?(f4).should_not == true
834
+
835
+ f1.hash.should == f2.hash
836
+ f1.hash.should_not == f3.hash
837
+ f1.hash.should_not == f4.hash
838
+ f2.hash.should == f1.hash
839
+ f2.hash.should_not == f3.hash
840
+ f2.hash.should_not == f4.hash
841
+ f3.hash.should_not == f1.hash
842
+ f3.hash.should_not == f2.hash
843
+ f3.hash.should_not == f4.hash
844
+ end
845
+
745
846
  it "correctly handles fully qualified names on Messages" do
746
847
  Simple::Test1.fully_qualified_name.should == "simple.Test1"
747
848
  Simple::Foo.fully_qualified_name.should == "simple.Foo"
@@ -103,6 +103,7 @@ def has_compiler?
103
103
  end
104
104
 
105
105
  RSpec.configure do |config|
106
+ config.backtrace_exclusion_patterns = []
106
107
  config.after(:each) do
107
108
  # clear our namespaces
108
109
  Object.send(:remove_const, :Simple) if defined?(Simple)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-protocol-buffers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-09-19 00:00:00.000000000 Z
15
+ date: 2013-10-28 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: autotest-standalone
@@ -177,6 +177,7 @@ files:
177
177
  - ruby-protocol-buffers.gemspec
178
178
  - spec/compiler_spec.rb
179
179
  - spec/fields_spec.rb
180
+ - spec/message_spec.rb
180
181
  - spec/negative_int32_spec.rb
181
182
  - spec/nil_bugs_spec.rb
182
183
  - spec/proto_files/depends.proto
@@ -217,7 +218,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
217
218
  version: '0'
218
219
  segments:
219
220
  - 0
220
- hash: -120727640880373349
221
+ hash: 4464428252949135553
221
222
  required_rubygems_version: !ruby/object:Gem::Requirement
222
223
  none: false
223
224
  requirements:
@@ -226,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
226
227
  version: '0'
227
228
  segments:
228
229
  - 0
229
- hash: -120727640880373349
230
+ hash: 4464428252949135553
230
231
  requirements: []
231
232
  rubyforge_project:
232
233
  rubygems_version: 1.8.23
@@ -236,6 +237,7 @@ summary: Ruby compiler and runtime for the google protocol buffers library.
236
237
  test_files:
237
238
  - spec/compiler_spec.rb
238
239
  - spec/fields_spec.rb
240
+ - spec/message_spec.rb
239
241
  - spec/negative_int32_spec.rb
240
242
  - spec/nil_bugs_spec.rb
241
243
  - spec/proto_files/depends.proto