blob: ebbeb0a7ddd78f2137aa2a2fa1669502f1e003a9 [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +00001#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18#
19
Kevin Clark4bd89162008-07-08 00:47:49 +000020require 'thrift'
21
22module Fixtures
23 module Structs
24 class OneBool
25 include Thrift::Struct
26 attr_accessor :bool
27 FIELDS = {
28 1 => {:type => Thrift::Types::BOOL, :name => 'bool'}
29 }
Kevin Clarkc85fd502009-01-14 23:55:10 +000030
31 def validate
32 end
Kevin Clark4bd89162008-07-08 00:47:49 +000033 end
34
35 class OneByte
36 include Thrift::Struct
37 attr_accessor :byte
38 FIELDS = {
39 1 => {:type => Thrift::Types::BYTE, :name => 'byte'}
40 }
Kevin Clarkc85fd502009-01-14 23:55:10 +000041
42 def validate
43 end
Kevin Clark4bd89162008-07-08 00:47:49 +000044 end
45
46 class OneI16
47 include Thrift::Struct
48 attr_accessor :i16
49 FIELDS = {
50 1 => {:type => Thrift::Types::I16, :name => 'i16'}
51 }
Kevin Clarkc85fd502009-01-14 23:55:10 +000052
53 def validate
54 end
Kevin Clark4bd89162008-07-08 00:47:49 +000055 end
56
57 class OneI32
58 include Thrift::Struct
59 attr_accessor :i32
60 FIELDS = {
61 1 => {:type => Thrift::Types::I32, :name => 'i32'}
62 }
Kevin Clarkc85fd502009-01-14 23:55:10 +000063
64 def validate
65 end
Kevin Clark4bd89162008-07-08 00:47:49 +000066 end
67
68 class OneI64
69 include Thrift::Struct
70 attr_accessor :i64
71 FIELDS = {
72 1 => {:type => Thrift::Types::I64, :name => 'i64'}
73 }
Kevin Clarkc85fd502009-01-14 23:55:10 +000074
75 def validate
76 end
Kevin Clark4bd89162008-07-08 00:47:49 +000077 end
78
79 class OneDouble
80 include Thrift::Struct
81 attr_accessor :double
82 FIELDS = {
83 1 => {:type => Thrift::Types::DOUBLE, :name => 'double'}
84 }
Kevin Clarkc85fd502009-01-14 23:55:10 +000085
86 def validate
87 end
Kevin Clark4bd89162008-07-08 00:47:49 +000088 end
89
90 class OneString
91 include Thrift::Struct
92 attr_accessor :string
93 FIELDS = {
94 1 => {:type => Thrift::Types::STRING, :name => 'string'}
95 }
Kevin Clarkc85fd502009-01-14 23:55:10 +000096
97 def validate
98 end
Kevin Clark4bd89162008-07-08 00:47:49 +000099 end
100
101 class OneMap
102 include Thrift::Struct
103 attr_accessor :map
104 FIELDS = {
105 1 => {:type => Thrift::Types::MAP, :name => 'map', :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::STRING}}
106 }
Kevin Clarkc85fd502009-01-14 23:55:10 +0000107
108 def validate
109 end
Kevin Clark4bd89162008-07-08 00:47:49 +0000110 end
111
112 class NestedMap
113 include Thrift::Struct
114 attr_accessor :map
115 FIELDS = {
116 0 => {:type => Thrift::Types::MAP, :name => 'map', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::MAP, :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::I32}}}
117 }
Kevin Clarkc85fd502009-01-14 23:55:10 +0000118
119 def validate
120 end
Kevin Clark4bd89162008-07-08 00:47:49 +0000121 end
122
123 class OneList
124 include Thrift::Struct
125 attr_accessor :list
126 FIELDS = {
127 1 => {:type => Thrift::Types::LIST, :name => 'list', :element => {:type => Thrift::Types::STRING}}
128 }
Kevin Clarkc85fd502009-01-14 23:55:10 +0000129
130 def validate
131 end
Kevin Clark4bd89162008-07-08 00:47:49 +0000132 end
133
134 class NestedList
135 include Thrift::Struct
136 attr_accessor :list
137 FIELDS = {
138 0 => {:type => Thrift::Types::LIST, :name => 'list', :element => {:type => Thrift::Types::LIST, :element => { :type => Thrift::Types::I32 } } }
139 }
Kevin Clarkc85fd502009-01-14 23:55:10 +0000140
141 def validate
142 end
Kevin Clark4bd89162008-07-08 00:47:49 +0000143 end
144
145 class OneSet
146 include Thrift::Struct
147 attr_accessor :set
148 FIELDS = {
149 1 => {:type => Thrift::Types::SET, :name => 'set', :element => {:type => Thrift::Types::STRING}}
150 }
Kevin Clarkc85fd502009-01-14 23:55:10 +0000151
152 def validate
153 end
Kevin Clark4bd89162008-07-08 00:47:49 +0000154 end
155
156 class NestedSet
157 include Thrift::Struct
158 attr_accessor :set
159 FIELDS = {
160 1 => {:type => Thrift::Types::SET, :name => 'set', :element => {:type => Thrift::Types::SET, :element => { :type => Thrift::Types::STRING } }}
161 }
Kevin Clarkc85fd502009-01-14 23:55:10 +0000162
163 def validate
164 end
Kevin Clark4bd89162008-07-08 00:47:49 +0000165 end
166
167 # struct OneOfEach {
168 # 1: bool im_true,
169 # 2: bool im_false,
170 # 3: byte a_bite,
171 # 4: i16 integer16,
172 # 5: i32 integer32,
173 # 6: i64 integer64,
174 # 7: double double_precision,
175 # 8: string some_characters,
176 # 9: string zomg_unicode,
177 # 10: bool what_who,
178 # 11: binary base64,
179 # }
180 class OneOfEach
181 include Thrift::Struct
182 attr_accessor :im_true, :im_false, :a_bite, :integer16, :integer32, :integer64, :double_precision, :some_characters, :zomg_unicode, :what_who, :base64
183 FIELDS = {
184 1 => {:type => Thrift::Types::BOOL, :name => 'im_true'},
185 2 => {:type => Thrift::Types::BOOL, :name => 'im_false'},
186 3 => {:type => Thrift::Types::BYTE, :name => 'a_bite'},
187 4 => {:type => Thrift::Types::I16, :name => 'integer16'},
188 5 => {:type => Thrift::Types::I32, :name => 'integer32'},
189 6 => {:type => Thrift::Types::I64, :name => 'integer64'},
190 7 => {:type => Thrift::Types::DOUBLE, :name => 'double_precision'},
191 8 => {:type => Thrift::Types::STRING, :name => 'some_characters'},
192 9 => {:type => Thrift::Types::STRING, :name => 'zomg_unicode'},
193 10 => {:type => Thrift::Types::BOOL, :name => 'what_who'},
194 11 => {:type => Thrift::Types::STRING, :name => 'base64'}
195 }
196
197 # Added for assert_equal
198 def ==(other)
199 [:im_true, :im_false, :a_bite, :integer16, :integer32, :integer64, :double_precision, :some_characters, :zomg_unicode, :what_who, :base64].each do |f|
200 var = "@#{f}"
201 return false if instance_variable_get(var) != other.instance_variable_get(var)
202 end
203 true
204 end
Kevin Clarkc85fd502009-01-14 23:55:10 +0000205
206 def validate
207 end
Kevin Clark4bd89162008-07-08 00:47:49 +0000208 end
209
210 # struct Nested1 {
211 # 1: list<OneOfEach> a_list
212 # 2: map<i32, OneOfEach> i32_map
213 # 3: map<i64, OneOfEach> i64_map
214 # 4: map<double, OneOfEach> dbl_map
215 # 5: map<string, OneOfEach> str_map
216 # }
217 class Nested1
218 include Thrift::Struct
219 attr_accessor :a_list, :i32_map, :i64_map, :dbl_map, :str_map
220 FIELDS = {
221 1 => {:type => Thrift::Types::LIST, :name => 'a_list', :element => {:type => Thrift::Types::STRUCT, :class => OneOfEach}},
222 2 => {:type => Thrift::Types::MAP, :name => 'i32_map', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRUCT, :class => OneOfEach}},
223 3 => {:type => Thrift::Types::MAP, :name => 'i64_map', :key => {:type => Thrift::Types::I64}, :value => {:type => Thrift::Types::STRUCT, :class => OneOfEach}},
224 4 => {:type => Thrift::Types::MAP, :name => 'dbl_map', :key => {:type => Thrift::Types::DOUBLE}, :value => {:type => Thrift::Types::STRUCT, :class => OneOfEach}},
225 5 => {:type => Thrift::Types::MAP, :name => 'str_map', :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::STRUCT, :class => OneOfEach}}
226 }
Kevin Clarkc85fd502009-01-14 23:55:10 +0000227
228 def validate
229 end
Kevin Clark4bd89162008-07-08 00:47:49 +0000230 end
231
232 # struct Nested2 {
233 # 1: list<Nested1> a_list
234 # 2: map<i32, Nested1> i32_map
235 # 3: map<i64, Nested1> i64_map
236 # 4: map<double, Nested1> dbl_map
237 # 5: map<string, Nested1> str_map
238 # }
239 class Nested2
240 include Thrift::Struct
241 attr_accessor :a_list, :i32_map, :i64_map, :dbl_map, :str_map
242 FIELDS = {
243 1 => {:type => Thrift::Types::LIST, :name => 'a_list', :element => {:type => Thrift::Types::STRUCT, :class => Nested1}},
244 2 => {:type => Thrift::Types::MAP, :name => 'i32_map', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRUCT, :class => Nested1}},
245 3 => {:type => Thrift::Types::MAP, :name => 'i64_map', :key => {:type => Thrift::Types::I64}, :value => {:type => Thrift::Types::STRUCT, :class => Nested1}},
246 4 => {:type => Thrift::Types::MAP, :name => 'dbl_map', :key => {:type => Thrift::Types::DOUBLE}, :value => {:type => Thrift::Types::STRUCT, :class => Nested1}},
247 5 => {:type => Thrift::Types::MAP, :name => 'str_map', :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::STRUCT, :class => Nested1}}
248 }
Kevin Clarkc85fd502009-01-14 23:55:10 +0000249
250 def validate
251 end
Kevin Clark4bd89162008-07-08 00:47:49 +0000252 end
253
254 # struct Nested3 {
255 # 1: list<Nested2> a_list
256 # 2: map<i32, Nested2> i32_map
257 # 3: map<i64, Nested2> i64_map
258 # 4: map<double, Nested2> dbl_map
259 # 5: map<string, Nested2> str_map
260 # }
261 class Nested3
262 include Thrift::Struct
263 attr_accessor :a_list, :i32_map, :i64_map, :dbl_map, :str_map
264 FIELDS = {
265 1 => {:type => Thrift::Types::LIST, :name => 'a_list', :element => {:type => Thrift::Types::STRUCT, :class => Nested2}},
266 2 => {:type => Thrift::Types::MAP, :name => 'i32_map', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRUCT, :class => Nested2}},
267 3 => {:type => Thrift::Types::MAP, :name => 'i64_map', :key => {:type => Thrift::Types::I64}, :value => {:type => Thrift::Types::STRUCT, :class => Nested2}},
268 4 => {:type => Thrift::Types::MAP, :name => 'dbl_map', :key => {:type => Thrift::Types::DOUBLE}, :value => {:type => Thrift::Types::STRUCT, :class => Nested2}},
269 5 => {:type => Thrift::Types::MAP, :name => 'str_map', :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::STRUCT, :class => Nested2}}
270 }
Kevin Clarkc85fd502009-01-14 23:55:10 +0000271
272 def validate
273 end
Kevin Clark4bd89162008-07-08 00:47:49 +0000274 end
275
276 # struct Nested4 {
277 # 1: list<Nested3> a_list
278 # 2: map<i32, Nested3> i32_map
279 # 3: map<i64, Nested3> i64_map
280 # 4: map<double, Nested3> dbl_map
281 # 5: map<string, Nested3> str_map
282 # }
283 class Nested4
284 include Thrift::Struct
285 attr_accessor :a_list, :i32_map, :i64_map, :dbl_map, :str_map
286 FIELDS = {
287 1 => {:type => Thrift::Types::LIST, :name => 'a_list', :element => {:type => Thrift::Types::STRUCT, :class => Nested3}},
288 2 => {:type => Thrift::Types::MAP, :name => 'i32_map', :key => {:type => Thrift::Types::I32}, :value => {:type => Thrift::Types::STRUCT, :class => Nested3}},
289 3 => {:type => Thrift::Types::MAP, :name => 'i64_map', :key => {:type => Thrift::Types::I64}, :value => {:type => Thrift::Types::STRUCT, :class => Nested3}},
290 4 => {:type => Thrift::Types::MAP, :name => 'dbl_map', :key => {:type => Thrift::Types::DOUBLE}, :value => {:type => Thrift::Types::STRUCT, :class => Nested3}},
291 5 => {:type => Thrift::Types::MAP, :name => 'str_map', :key => {:type => Thrift::Types::STRING}, :value => {:type => Thrift::Types::STRUCT, :class => Nested3}}
292 }
Kevin Clarkc85fd502009-01-14 23:55:10 +0000293
294 def validate
295 end
Kevin Clark4bd89162008-07-08 00:47:49 +0000296 end
297 end
298end