OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/assert.h" | 5 #include "platform/assert.h" |
6 #include "platform/text_buffer.h" | 6 #include "platform/text_buffer.h" |
7 #include "vm/json_stream.h" | 7 #include "vm/json_stream.h" |
8 #include "vm/unit_test.h" | 8 #include "vm/unit_test.h" |
9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
10 | 10 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 String& obj = String::Handle(); | 229 String& obj = String::Handle(); |
230 | 230 |
231 { | 231 { |
232 result = Dart_GetField(lib, NewString("ascii")); | 232 result = Dart_GetField(lib, NewString("ascii")); |
233 EXPECT_VALID(result); | 233 EXPECT_VALID(result); |
234 obj ^= Api::UnwrapHandle(result); | 234 obj ^= Api::UnwrapHandle(result); |
235 | 235 |
236 JSONStream js; | 236 JSONStream js; |
237 { | 237 { |
238 JSONObject jsobj(&js); | 238 JSONObject jsobj(&js); |
239 jsobj.AddPropertyStr("ascci", obj);; | 239 EXPECT(!jsobj.AddPropertyStr("ascii", obj)); |
240 } | 240 } |
241 EXPECT_STREQ("{\"ascci\":\"Hello, World!\"}", js.ToCString()); | 241 EXPECT_STREQ("{\"ascii\":\"Hello, World!\"}", js.ToCString()); |
242 } | 242 } |
243 | 243 |
244 { | 244 { |
| 245 result = Dart_GetField(lib, NewString("ascii")); |
| 246 EXPECT_VALID(result); |
| 247 obj ^= Api::UnwrapHandle(result); |
| 248 |
| 249 JSONStream js; |
| 250 { |
| 251 JSONObject jsobj(&js); |
| 252 EXPECT(jsobj.AddPropertyStr("subrange", obj, 1, 4)); |
| 253 } |
| 254 EXPECT_STREQ("{\"subrange\":\"ello\"}", js.ToCString()); |
| 255 } |
| 256 |
| 257 { |
245 result = Dart_GetField(lib, NewString("unicode")); | 258 result = Dart_GetField(lib, NewString("unicode")); |
246 EXPECT_VALID(result); | 259 EXPECT_VALID(result); |
247 obj ^= Api::UnwrapHandle(result); | 260 obj ^= Api::UnwrapHandle(result); |
248 | 261 |
249 JSONStream js; | 262 JSONStream js; |
250 { | 263 { |
251 JSONObject jsobj(&js); | 264 JSONObject jsobj(&js); |
252 jsobj.AddPropertyStr("unicode", obj); | 265 EXPECT(!jsobj.AddPropertyStr("unicode", obj)); |
253 } | 266 } |
254 EXPECT_STREQ("{\"unicode\":\"\\u00CE\\u00F1\\u0163\\u00E9r\\u00F1\\u00E5" | 267 EXPECT_STREQ("{\"unicode\":\"\\u00CE\\u00F1\\u0163\\u00E9r\\u00F1\\u00E5" |
255 "\\u0163\\u00EE\\u00F6\\u00F1\\u00E5\\u013C\\u00EE\\u017E" | 268 "\\u0163\\u00EE\\u00F6\\u00F1\\u00E5\\u013C\\u00EE\\u017E" |
256 "\\u00E5\\u0163\\u00EE\\u1EDD\\u00F1\"}", js.ToCString()); | 269 "\\u00E5\\u0163\\u00EE\\u1EDD\\u00F1\"}", js.ToCString()); |
257 } | 270 } |
258 | 271 |
259 { | 272 { |
260 result = Dart_GetField(lib, NewString("surrogates")); | 273 result = Dart_GetField(lib, NewString("surrogates")); |
261 EXPECT_VALID(result); | 274 EXPECT_VALID(result); |
262 obj ^= Api::UnwrapHandle(result); | 275 obj ^= Api::UnwrapHandle(result); |
263 | 276 |
264 JSONStream js; | 277 JSONStream js; |
265 { | 278 { |
266 JSONObject jsobj(&js); | 279 JSONObject jsobj(&js); |
267 jsobj.AddPropertyStr("surrogates", obj); | 280 EXPECT(!jsobj.AddPropertyStr("surrogates", obj)); |
268 } | 281 } |
269 EXPECT_STREQ("{\"surrogates\":\"\\uD834\\uDD1E\\uD834\\uDD1E\\uD834\\uDD1E" | 282 EXPECT_STREQ("{\"surrogates\":\"\\uD834\\uDD1E\\uD834\\uDD1E\\uD834\\uDD1E" |
270 "\\uD834\\uDD1E\\uD834\\uDD1E\"}", js.ToCString()); | 283 "\\uD834\\uDD1E\\uD834\\uDD1E\"}", js.ToCString()); |
271 } | 284 } |
272 | 285 |
273 { | 286 { |
274 result = Dart_GetField(lib, NewString("nullInMiddle")); | 287 result = Dart_GetField(lib, NewString("nullInMiddle")); |
275 EXPECT_VALID(result); | 288 EXPECT_VALID(result); |
276 obj ^= Api::UnwrapHandle(result); | 289 obj ^= Api::UnwrapHandle(result); |
277 | 290 |
278 JSONStream js; | 291 JSONStream js; |
279 { | 292 { |
280 JSONObject jsobj(&js); | 293 JSONObject jsobj(&js); |
281 jsobj.AddPropertyStr("nullInMiddle", obj); | 294 EXPECT(!jsobj.AddPropertyStr("nullInMiddle", obj)); |
282 } | 295 } |
283 EXPECT_STREQ("{\"nullInMiddle\":\"This has\\u0000 four words.\"}", | 296 EXPECT_STREQ("{\"nullInMiddle\":\"This has\\u0000 four words.\"}", |
284 js.ToCString()); | 297 js.ToCString()); |
285 } | 298 } |
286 } | 299 } |
287 | 300 |
288 | 301 |
289 TEST_CASE(JSON_JSONStream_Params) { | 302 TEST_CASE(JSON_JSONStream_Params) { |
290 const char* param_keys[] = {"dog", "cat"}; | 303 const char* param_keys[] = {"dog", "cat"}; |
291 const char* param_values[] = {"apple", "banana"}; | 304 const char* param_values[] = {"apple", "banana"}; |
292 | 305 |
293 JSONStream js; | 306 JSONStream js; |
294 EXPECT(js.num_params() == 0); | 307 EXPECT(js.num_params() == 0); |
295 js.SetParams(¶m_keys[0], ¶m_values[0], 2); | 308 js.SetParams(¶m_keys[0], ¶m_values[0], 2); |
296 EXPECT(js.num_params() == 2); | 309 EXPECT(js.num_params() == 2); |
297 EXPECT(!js.HasParam("lizard")); | 310 EXPECT(!js.HasParam("lizard")); |
298 EXPECT(js.HasParam("dog")); | 311 EXPECT(js.HasParam("dog")); |
299 EXPECT(js.HasParam("cat")); | 312 EXPECT(js.HasParam("cat")); |
300 EXPECT(js.ParamIs("cat", "banana")); | 313 EXPECT(js.ParamIs("cat", "banana")); |
301 EXPECT(!js.ParamIs("dog", "banana")); | 314 EXPECT(!js.ParamIs("dog", "banana")); |
302 } | 315 } |
303 | 316 |
304 } // namespace dart | 317 } // namespace dart |
OLD | NEW |