blob: 3945925f8dcf286b0b8aafd6fa39637e03010325 [file] [log] [blame]
Jake Farrell6f0f5272012-01-31 03:39:30 +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
Jake Farrella87810f2012-09-28 01:59:04 +000020require 'spec_helper'
Jake Farrell6f0f5272012-01-31 03:39:30 +000021
Jake Farrella87810f2012-09-28 01:59:04 +000022describe 'JsonProtocol' do
Jake Farrell6f0f5272012-01-31 03:39:30 +000023
Jake Farrella87810f2012-09-28 01:59:04 +000024 describe Thrift::JsonProtocol do
25 before(:each) do
26 @trans = Thrift::MemoryBufferTransport.new
27 @prot = Thrift::JsonProtocol.new(@trans)
28 end
Jake Farrell6f0f5272012-01-31 03:39:30 +000029
Jake Farrella87810f2012-09-28 01:59:04 +000030 it "should write json escaped char" do
31 @prot.write_json_escape_char("\n")
32 @trans.read(@trans.available).should == '\u000a'
Jake Farrell6f0f5272012-01-31 03:39:30 +000033
Jake Farrella87810f2012-09-28 01:59:04 +000034 @prot.write_json_escape_char(" ")
35 @trans.read(@trans.available).should == '\u0020'
36 end
Jake Farrell6f0f5272012-01-31 03:39:30 +000037
Jake Farrella87810f2012-09-28 01:59:04 +000038 it "should write json char" do
39 @prot.write_json_char("\n")
40 @trans.read(@trans.available).should == '\\n'
Jake Farrell6f0f5272012-01-31 03:39:30 +000041
Jake Farrella87810f2012-09-28 01:59:04 +000042 @prot.write_json_char(" ")
43 @trans.read(@trans.available).should == ' '
Jake Farrell6f0f5272012-01-31 03:39:30 +000044
Jake Farrella87810f2012-09-28 01:59:04 +000045 @prot.write_json_char("\\")
46 @trans.read(@trans.available).should == "\\\\"
Jake Farrell6f0f5272012-01-31 03:39:30 +000047
Jake Farrella87810f2012-09-28 01:59:04 +000048 @prot.write_json_char("@")
49 @trans.read(@trans.available).should == '@'
50 end
Jake Farrell6f0f5272012-01-31 03:39:30 +000051
Jake Farrella87810f2012-09-28 01:59:04 +000052 it "should write json string" do
53 @prot.write_json_string("this is a \\ json\nstring")
54 @trans.read(@trans.available).should == "\"this is a \\\\ json\\nstring\""
55 end
Jake Farrell6f0f5272012-01-31 03:39:30 +000056
Jake Farrella87810f2012-09-28 01:59:04 +000057 it "should write json base64" do
58 @prot.write_json_base64("this is a base64 string")
59 @trans.read(@trans.available).should == "\"\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\\n\"\""
60 end
Jake Farrell6f0f5272012-01-31 03:39:30 +000061
Jake Farrella87810f2012-09-28 01:59:04 +000062 it "should write json integer" do
63 @prot.write_json_integer(45)
64 @trans.read(@trans.available).should == "45"
Jake Farrell6f0f5272012-01-31 03:39:30 +000065
Jake Farrella87810f2012-09-28 01:59:04 +000066 @prot.write_json_integer(33000)
67 @trans.read(@trans.available).should == "33000"
Jake Farrell6f0f5272012-01-31 03:39:30 +000068
Jake Farrella87810f2012-09-28 01:59:04 +000069 @prot.write_json_integer(3000000000)
70 @trans.read(@trans.available).should == "3000000000"
Jake Farrell6f0f5272012-01-31 03:39:30 +000071
Jake Farrella87810f2012-09-28 01:59:04 +000072 @prot.write_json_integer(6000000000)
73 @trans.read(@trans.available).should == "6000000000"
74 end
Jake Farrell6f0f5272012-01-31 03:39:30 +000075
Jake Farrella87810f2012-09-28 01:59:04 +000076 it "should write json double" do
77 @prot.write_json_double(12.3)
78 @trans.read(@trans.available).should == "12.3"
Jake Farrell6f0f5272012-01-31 03:39:30 +000079
Jake Farrella87810f2012-09-28 01:59:04 +000080 @prot.write_json_double(-3.21)
81 @trans.read(@trans.available).should == "-3.21"
Jake Farrell6f0f5272012-01-31 03:39:30 +000082
Jake Farrella87810f2012-09-28 01:59:04 +000083 @prot.write_json_double(((+1.0/0.0)/(+1.0/0.0)))
84 @trans.read(@trans.available).should == "\"NaN\""
Jake Farrell6f0f5272012-01-31 03:39:30 +000085
Jake Farrella87810f2012-09-28 01:59:04 +000086 @prot.write_json_double((+1.0/0.0))
87 @trans.read(@trans.available).should == "\"Infinity\""
Jake Farrell6f0f5272012-01-31 03:39:30 +000088
Jake Farrella87810f2012-09-28 01:59:04 +000089 @prot.write_json_double((-1.0/0.0))
90 @trans.read(@trans.available).should == "\"-Infinity\""
91 end
Jake Farrell6f0f5272012-01-31 03:39:30 +000092
Jake Farrella87810f2012-09-28 01:59:04 +000093 it "should write json object start" do
94 @prot.write_json_object_start
95 @trans.read(@trans.available).should == "{"
96 end
Jake Farrell6f0f5272012-01-31 03:39:30 +000097
Jake Farrella87810f2012-09-28 01:59:04 +000098 it "should write json object end" do
99 @prot.write_json_object_end
100 @trans.read(@trans.available).should == "}"
101 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000102
Jake Farrella87810f2012-09-28 01:59:04 +0000103 it "should write json array start" do
104 @prot.write_json_array_start
105 @trans.read(@trans.available).should == "["
106 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000107
Jake Farrella87810f2012-09-28 01:59:04 +0000108 it "should write json array end" do
109 @prot.write_json_array_end
110 @trans.read(@trans.available).should == "]"
111 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000112
Jake Farrella87810f2012-09-28 01:59:04 +0000113 it "should write message begin" do
114 @prot.write_message_begin("name", 12, 32)
115 @trans.read(@trans.available).should == "[1,\"name\",12,32"
116 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000117
Jake Farrella87810f2012-09-28 01:59:04 +0000118 it "should write message end" do
119 @prot.write_message_end
120 @trans.read(@trans.available).should == "]"
121 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000122
Jake Farrella87810f2012-09-28 01:59:04 +0000123 it "should write struct begin" do
124 @prot.write_struct_begin("name")
125 @trans.read(@trans.available).should == "{"
126 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000127
Jake Farrella87810f2012-09-28 01:59:04 +0000128 it "should write struct end" do
129 @prot.write_struct_end
130 @trans.read(@trans.available).should == "}"
131 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000132
Jake Farrella87810f2012-09-28 01:59:04 +0000133 it "should write field begin" do
134 @prot.write_field_begin("name", Thrift::Types::STRUCT, 32)
135 @trans.read(@trans.available).should == "32{\"rec\""
136 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000137
Jake Farrella87810f2012-09-28 01:59:04 +0000138 it "should write field end" do
139 @prot.write_field_end
140 @trans.read(@trans.available).should == "}"
141 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000142
Jake Farrella87810f2012-09-28 01:59:04 +0000143 it "should write field stop" do
144 @prot.write_field_stop
145 @trans.read(@trans.available).should == ""
146 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000147
Jake Farrella87810f2012-09-28 01:59:04 +0000148 it "should write map begin" do
149 @prot.write_map_begin(Thrift::Types::STRUCT, Thrift::Types::LIST, 32)
150 @trans.read(@trans.available).should == "[\"rec\",\"lst\",32,{"
151 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000152
Jake Farrella87810f2012-09-28 01:59:04 +0000153 it "should write map end" do
154 @prot.write_map_end
155 @trans.read(@trans.available).should == "}]"
156 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000157
Jake Farrella87810f2012-09-28 01:59:04 +0000158 it "should write list begin" do
159 @prot.write_list_begin(Thrift::Types::STRUCT, 32)
160 @trans.read(@trans.available).should == "[\"rec\",32"
161 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000162
Jake Farrella87810f2012-09-28 01:59:04 +0000163 it "should write list end" do
164 @prot.write_list_end
165 @trans.read(@trans.available).should == "]"
166 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000167
Jake Farrella87810f2012-09-28 01:59:04 +0000168 it "should write set begin" do
169 @prot.write_set_begin(Thrift::Types::STRUCT, 32)
170 @trans.read(@trans.available).should == "[\"rec\",32"
171 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000172
Jake Farrella87810f2012-09-28 01:59:04 +0000173 it "should write set end" do
174 @prot.write_set_end
175 @trans.read(@trans.available).should == "]"
176 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000177
Jake Farrella87810f2012-09-28 01:59:04 +0000178 it "should write bool" do
179 @prot.write_bool(true)
180 @trans.read(@trans.available).should == "1"
Jake Farrell6f0f5272012-01-31 03:39:30 +0000181
Jake Farrella87810f2012-09-28 01:59:04 +0000182 @prot.write_bool(false)
183 @trans.read(@trans.available).should == "0"
184 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000185
Jake Farrella87810f2012-09-28 01:59:04 +0000186 it "should write byte" do
187 @prot.write_byte(100)
188 @trans.read(@trans.available).should == "100"
189 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000190
Jake Farrella87810f2012-09-28 01:59:04 +0000191 it "should write i16" do
192 @prot.write_i16(1000)
193 @trans.read(@trans.available).should == "1000"
194 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000195
Jake Farrella87810f2012-09-28 01:59:04 +0000196 it "should write i32" do
197 @prot.write_i32(3000000000)
198 @trans.read(@trans.available).should == "3000000000"
199 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000200
Jake Farrella87810f2012-09-28 01:59:04 +0000201 it "should write i64" do
202 @prot.write_i64(6000000000)
203 @trans.read(@trans.available).should == "6000000000"
204 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000205
Jake Farrella87810f2012-09-28 01:59:04 +0000206 it "should write double" do
207 @prot.write_double(1.23)
208 @trans.read(@trans.available).should == "1.23"
Jake Farrell6f0f5272012-01-31 03:39:30 +0000209
Jake Farrella87810f2012-09-28 01:59:04 +0000210 @prot.write_double(-32.1)
211 @trans.read(@trans.available).should == "-32.1"
Jake Farrell6f0f5272012-01-31 03:39:30 +0000212
Jake Farrella87810f2012-09-28 01:59:04 +0000213 @prot.write_double(((+1.0/0.0)/(+1.0/0.0)))
214 @trans.read(@trans.available).should == "\"NaN\""
Jake Farrell6f0f5272012-01-31 03:39:30 +0000215
Jake Farrella87810f2012-09-28 01:59:04 +0000216 @prot.write_double((+1.0/0.0))
217 @trans.read(@trans.available).should == "\"Infinity\""
Jake Farrell6f0f5272012-01-31 03:39:30 +0000218
Jake Farrella87810f2012-09-28 01:59:04 +0000219 @prot.write_double((-1.0/0.0))
220 @trans.read(@trans.available).should == "\"-Infinity\""
221 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000222
Jake Farrella87810f2012-09-28 01:59:04 +0000223 it "should write string" do
224 @prot.write_string("this is a test string")
225 @trans.read(@trans.available).should == "\"this is a test string\""
226 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000227
Jake Farrella87810f2012-09-28 01:59:04 +0000228 it "should write binary" do
229 @prot.write_binary("this is a base64 string")
230 @trans.read(@trans.available).should == "\"\"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmc=\\n\"\""
231 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000232
Jake Farrella87810f2012-09-28 01:59:04 +0000233 it "should get type name for type id" do
234 expect {@prot.get_type_name_for_type_id(Thrift::Types::STOP)}.to raise_error(NotImplementedError)
235 expect {@prot.get_type_name_for_type_id(Thrift::Types::VOID)}.to raise_error(NotImplementedError)
236 @prot.get_type_name_for_type_id(Thrift::Types::BOOL).should == "tf"
237 @prot.get_type_name_for_type_id(Thrift::Types::BYTE).should == "i8"
238 @prot.get_type_name_for_type_id(Thrift::Types::DOUBLE).should == "dbl"
239 @prot.get_type_name_for_type_id(Thrift::Types::I16).should == "i16"
240 @prot.get_type_name_for_type_id(Thrift::Types::I32).should == "i32"
241 @prot.get_type_name_for_type_id(Thrift::Types::I64).should == "i64"
242 @prot.get_type_name_for_type_id(Thrift::Types::STRING).should == "str"
243 @prot.get_type_name_for_type_id(Thrift::Types::STRUCT).should == "rec"
244 @prot.get_type_name_for_type_id(Thrift::Types::MAP).should == "map"
245 @prot.get_type_name_for_type_id(Thrift::Types::SET).should == "set"
246 @prot.get_type_name_for_type_id(Thrift::Types::LIST).should == "lst"
247 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000248
Jake Farrella87810f2012-09-28 01:59:04 +0000249 it "should get type id for type name" do
250 expect {@prot.get_type_id_for_type_name("pp")}.to raise_error(NotImplementedError)
251 @prot.get_type_id_for_type_name("tf").should == Thrift::Types::BOOL
252 @prot.get_type_id_for_type_name("i8").should == Thrift::Types::BYTE
253 @prot.get_type_id_for_type_name("dbl").should == Thrift::Types::DOUBLE
254 @prot.get_type_id_for_type_name("i16").should == Thrift::Types::I16
255 @prot.get_type_id_for_type_name("i32").should == Thrift::Types::I32
256 @prot.get_type_id_for_type_name("i64").should == Thrift::Types::I64
257 @prot.get_type_id_for_type_name("str").should == Thrift::Types::STRING
258 @prot.get_type_id_for_type_name("rec").should == Thrift::Types::STRUCT
259 @prot.get_type_id_for_type_name("map").should == Thrift::Types::MAP
260 @prot.get_type_id_for_type_name("set").should == Thrift::Types::SET
261 @prot.get_type_id_for_type_name("lst").should == Thrift::Types::LIST
262 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000263
Jake Farrella87810f2012-09-28 01:59:04 +0000264 it "should read json syntax char" do
265 @trans.write('F')
266 expect {@prot.read_json_syntax_char('G')}.to raise_error(Thrift::ProtocolException)
267 @trans.write('H')
268 @prot.read_json_syntax_char('H')
269 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000270
Jake Farrella87810f2012-09-28 01:59:04 +0000271 it "should read json escape char" do
272 @trans.write('0054')
273 @prot.read_json_escape_char.should == 'T'
274 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000275
Jake Farrella87810f2012-09-28 01:59:04 +0000276 it "should read json string" do
277 @trans.write("\"\\P")
278 expect {@prot.read_json_string(false)}.to raise_error(Thrift::ProtocolException)
Jake Farrell6f0f5272012-01-31 03:39:30 +0000279
Jake Farrella87810f2012-09-28 01:59:04 +0000280 @trans.write("\"\\n\"")
281 @prot.read_json_string(false).should == "\\n"
Jake Farrell6f0f5272012-01-31 03:39:30 +0000282
Jake Farrella87810f2012-09-28 01:59:04 +0000283 @trans.write("\"this is a test string\"")
284 @prot.read_json_string.should == "this is a test string"
285 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000286
Jake Farrella87810f2012-09-28 01:59:04 +0000287 it "should read json base64" do
288 @trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"")
289 @prot.read_json_base64.should == "this is a test string"
290 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000291
Jake Farrella87810f2012-09-28 01:59:04 +0000292 it "should is json numeric" do
293 @prot.is_json_numeric("A").should == false
294 @prot.is_json_numeric("+").should == true
295 @prot.is_json_numeric("-").should == true
296 @prot.is_json_numeric(".").should == true
297 @prot.is_json_numeric("0").should == true
298 @prot.is_json_numeric("1").should == true
299 @prot.is_json_numeric("2").should == true
300 @prot.is_json_numeric("3").should == true
301 @prot.is_json_numeric("4").should == true
302 @prot.is_json_numeric("5").should == true
303 @prot.is_json_numeric("6").should == true
304 @prot.is_json_numeric("7").should == true
305 @prot.is_json_numeric("8").should == true
306 @prot.is_json_numeric("9").should == true
307 @prot.is_json_numeric("E").should == true
308 @prot.is_json_numeric("e").should == true
309 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000310
Jake Farrella87810f2012-09-28 01:59:04 +0000311 it "should read json numeric chars" do
312 @trans.write("1.453E45T")
313 @prot.read_json_numeric_chars.should == "1.453E45"
314 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000315
Jake Farrella87810f2012-09-28 01:59:04 +0000316 it "should read json integer" do
317 @trans.write("1.45\"\"")
318 expect {@prot.read_json_integer}.to raise_error(Thrift::ProtocolException)
319 @prot.read_string
Jake Farrell6f0f5272012-01-31 03:39:30 +0000320
Jake Farrella87810f2012-09-28 01:59:04 +0000321 @trans.write("1453T")
322 @prot.read_json_integer.should == 1453
323 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000324
Jake Farrella87810f2012-09-28 01:59:04 +0000325 it "should read json double" do
326 @trans.write("1.45e3e01\"\"")
327 expect {@prot.read_json_double}.to raise_error(Thrift::ProtocolException)
328 @prot.read_string
Jake Farrell6f0f5272012-01-31 03:39:30 +0000329
Jake Farrella87810f2012-09-28 01:59:04 +0000330 @trans.write("\"1.453e01\"")
331 expect {@prot.read_json_double}.to raise_error(Thrift::ProtocolException)
Jake Farrell6f0f5272012-01-31 03:39:30 +0000332
Jake Farrella87810f2012-09-28 01:59:04 +0000333 @trans.write("1.453e01\"\"")
334 @prot.read_json_double.should == 14.53
335 @prot.read_string
Jake Farrell6f0f5272012-01-31 03:39:30 +0000336
Jake Farrella87810f2012-09-28 01:59:04 +0000337 @trans.write("\"NaN\"")
338 @prot.read_json_double.nan?.should == true
Jake Farrell6f0f5272012-01-31 03:39:30 +0000339
Jake Farrella87810f2012-09-28 01:59:04 +0000340 @trans.write("\"Infinity\"")
341 @prot.read_json_double.should == +1.0/0.0
Jake Farrell6f0f5272012-01-31 03:39:30 +0000342
Jake Farrella87810f2012-09-28 01:59:04 +0000343 @trans.write("\"-Infinity\"")
344 @prot.read_json_double.should == -1.0/0.0
345 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000346
Jake Farrella87810f2012-09-28 01:59:04 +0000347 it "should read json object start" do
348 @trans.write("{")
349 @prot.read_json_object_start.should == nil
350 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000351
Jake Farrella87810f2012-09-28 01:59:04 +0000352 it "should read json object end" do
353 @trans.write("}")
354 @prot.read_json_object_end.should == nil
355 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000356
Jake Farrella87810f2012-09-28 01:59:04 +0000357 it "should read json array start" do
358 @trans.write("[")
359 @prot.read_json_array_start.should == nil
360 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000361
Jake Farrella87810f2012-09-28 01:59:04 +0000362 it "should read json array end" do
363 @trans.write("]")
364 @prot.read_json_array_end.should == nil
365 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000366
Jake Farrella87810f2012-09-28 01:59:04 +0000367 it "should read_message_begin" do
368 @trans.write("[2,")
369 expect {@prot.read_message_begin}.to raise_error(Thrift::ProtocolException)
Jake Farrell6f0f5272012-01-31 03:39:30 +0000370
Jake Farrella87810f2012-09-28 01:59:04 +0000371 @trans.write("[1,\"name\",12,32\"\"")
372 @prot.read_message_begin.should == ["name", 12, 32]
373 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000374
Jake Farrella87810f2012-09-28 01:59:04 +0000375 it "should read message end" do
376 @trans.write("]")
377 @prot.read_message_end.should == nil
378 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000379
Jake Farrella87810f2012-09-28 01:59:04 +0000380 it "should read struct begin" do
381 @trans.write("{")
382 @prot.read_struct_begin.should == nil
383 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000384
Jake Farrella87810f2012-09-28 01:59:04 +0000385 it "should read struct end" do
386 @trans.write("}")
387 @prot.read_struct_end.should == nil
388 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000389
Jake Farrella87810f2012-09-28 01:59:04 +0000390 it "should read field begin" do
391 @trans.write("1{\"rec\"")
392 @prot.read_field_begin.should == [nil, 12, 1]
393 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000394
Jake Farrella87810f2012-09-28 01:59:04 +0000395 it "should read field end" do
396 @trans.write("}")
397 @prot.read_field_end.should == nil
398 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000399
Jake Farrella87810f2012-09-28 01:59:04 +0000400 it "should read map begin" do
401 @trans.write("[\"rec\",\"lst\",2,{")
402 @prot.read_map_begin.should == [12, 15, 2]
403 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000404
Jake Farrella87810f2012-09-28 01:59:04 +0000405 it "should read map end" do
406 @trans.write("}]")
407 @prot.read_map_end.should == nil
408 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000409
Jake Farrella87810f2012-09-28 01:59:04 +0000410 it "should read list begin" do
411 @trans.write("[\"rec\",2\"\"")
412 @prot.read_list_begin.should == [12, 2]
413 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000414
Jake Farrella87810f2012-09-28 01:59:04 +0000415 it "should read list end" do
416 @trans.write("]")
417 @prot.read_list_end.should == nil
418 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000419
Jake Farrella87810f2012-09-28 01:59:04 +0000420 it "should read set begin" do
421 @trans.write("[")
422 @prot.read_set_begin.should == nil
423 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000424
Jake Farrella87810f2012-09-28 01:59:04 +0000425 it "should read set end" do
426 @trans.write("]")
427 @prot.read_set_end.should == nil
428 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000429
Jake Farrella87810f2012-09-28 01:59:04 +0000430 it "should read bool" do
431 @trans.write("0\"\"")
432 @prot.read_bool.should == false
433 @prot.read_string
Jake Farrell6f0f5272012-01-31 03:39:30 +0000434
Jake Farrella87810f2012-09-28 01:59:04 +0000435 @trans.write("1\"\"")
436 @prot.read_bool.should == true
437 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000438
Jake Farrella87810f2012-09-28 01:59:04 +0000439 it "should read byte" do
440 @trans.write("60\"\"")
441 @prot.read_byte.should == 60
442 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000443
Jake Farrella87810f2012-09-28 01:59:04 +0000444 it "should read i16" do
445 @trans.write("1000\"\"")
446 @prot.read_i16.should == 1000
447 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000448
Jake Farrella87810f2012-09-28 01:59:04 +0000449 it "should read i32" do
450 @trans.write("3000000000\"\"")
451 @prot.read_i32.should == 3000000000
452 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000453
Jake Farrella87810f2012-09-28 01:59:04 +0000454 it "should read i64" do
455 @trans.write("6000000000\"\"")
456 @prot.read_i64.should == 6000000000
457 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000458
Jake Farrella87810f2012-09-28 01:59:04 +0000459 it "should read double" do
460 @trans.write("12.23\"\"")
461 @prot.read_double.should == 12.23
462 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000463
Jake Farrella87810f2012-09-28 01:59:04 +0000464 it "should read string" do
465 @trans.write("\"this is a test string\"")
466 @prot.read_string.should == "this is a test string"
467 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000468
Jake Farrella87810f2012-09-28 01:59:04 +0000469 it "should read binary" do
470 @trans.write("\"dGhpcyBpcyBhIHRlc3Qgc3RyaW5n\"")
471 @prot.read_binary.should == "this is a test string"
472 end
Jake Farrell6f0f5272012-01-31 03:39:30 +0000473 end
474
Jake Farrella87810f2012-09-28 01:59:04 +0000475 describe Thrift::JsonProtocolFactory do
Jake Farrell6f0f5272012-01-31 03:39:30 +0000476 it "should create a JsonProtocol" do
Jake Farrella87810f2012-09-28 01:59:04 +0000477 Thrift::JsonProtocolFactory.new.get_protocol(mock("MockTransport")).should be_instance_of(Thrift::JsonProtocol)
Jake Farrell6f0f5272012-01-31 03:39:30 +0000478 end
479 end
480end