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/globals.h" | 5 #include "platform/globals.h" |
6 | 6 |
7 #include "include/dart_tools_api.h" | 7 #include "include/dart_tools_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 case Dart_CObject_kArray: | 113 case Dart_CObject_kArray: |
114 // Use invalid type as a visited marker to avoid infinite | 114 // Use invalid type as a visited marker to avoid infinite |
115 // recursion on graphs with cycles. | 115 // recursion on graphs with cycles. |
116 second->type = Dart_CObject_kNumberOfTypes; | 116 second->type = Dart_CObject_kNumberOfTypes; |
117 EXPECT_EQ(first->value.as_array.length, second->value.as_array.length); | 117 EXPECT_EQ(first->value.as_array.length, second->value.as_array.length); |
118 for (int i = 0; i < first->value.as_array.length; i++) { | 118 for (int i = 0; i < first->value.as_array.length; i++) { |
119 CompareDartCObjects(first->value.as_array.values[i], | 119 CompareDartCObjects(first->value.as_array.values[i], |
120 second->value.as_array.values[i]); | 120 second->value.as_array.values[i]); |
121 } | 121 } |
122 break; | 122 break; |
123 case Dart_CObject_kCapability: | |
124 EXPECT_EQ(first->value.as_capability.id, second->value.as_capability.id); | |
125 break; | |
123 default: | 126 default: |
124 EXPECT(false); | 127 EXPECT(false); |
125 } | 128 } |
126 } | 129 } |
127 | 130 |
128 | 131 |
129 static void CheckEncodeDecodeMessage(Dart_CObject* root) { | 132 static void CheckEncodeDecodeMessage(Dart_CObject* root) { |
130 // Encode and decode the message. | 133 // Encode and decode the message. |
131 uint8_t* buffer = NULL; | 134 uint8_t* buffer = NULL; |
132 ApiMessageWriter writer(&buffer, &malloc_allocator); | 135 ApiMessageWriter writer(&buffer, &malloc_allocator); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 EXPECT_EQ(false, root->value.as_bool); | 398 EXPECT_EQ(false, root->value.as_bool); |
396 CheckEncodeDecodeMessage(root); | 399 CheckEncodeDecodeMessage(root); |
397 } | 400 } |
398 | 401 |
399 | 402 |
400 static uword allocator(intptr_t size) { | 403 static uword allocator(intptr_t size) { |
401 return reinterpret_cast<uword>(malloc(size)); | 404 return reinterpret_cast<uword>(malloc(size)); |
402 } | 405 } |
403 | 406 |
404 | 407 |
408 TEST_CASE(SerializeCapability) { | |
409 StackZone zone(Isolate::Current()); | |
410 | |
411 // Write snapshot with object content. | |
412 const Capability& capability = Capability::Handle(Capability::New(12345)); | |
413 uint8_t* buffer; | |
414 MessageWriter writer(&buffer, &zone_allocator, true); | |
415 writer.WriteMessage(capability); | |
416 intptr_t buffer_len = writer.BytesWritten(); | |
417 | |
418 // Read object back from the snapshot. | |
419 MessageSnapshotReader reader(buffer, | |
420 buffer_len, | |
421 Isolate::Current(), | |
422 zone.GetZone()); | |
423 Capability& obj = Capability::Handle(); | |
424 obj ^= reader.ReadObject(); | |
425 | |
426 EXPECT_STREQ(12345, obj.Id()); | |
427 | |
428 // Read object back from the snapshot into a C structure. | |
429 ApiNativeScope scope; | |
430 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | |
431 Dart_CObject* root = api_reader.ReadMessage(); | |
432 EXPECT_NOTNULL(root); | |
433 EXPECT_EQ(Dart_CObject_kCapability, root->type); | |
434 int64_t id = root->value.as_capability.id; | |
435 EXPECT_EQ(12345, id); | |
436 CheckEncodeDecodeMessage(root); | |
siva
2015/07/30 19:44:06
You should probably also have a case similar to th
turnidge
2015/07/30 21:04:13
Yes, that's what CheckEncodeDecodeMessage does.
| |
437 } | |
438 | |
439 | |
405 TEST_CASE(SerializeBigint) { | 440 TEST_CASE(SerializeBigint) { |
406 StackZone zone(Isolate::Current()); | 441 StackZone zone(Isolate::Current()); |
407 | 442 |
408 // Write snapshot with object content. | 443 // Write snapshot with object content. |
409 const char* cstr = "0x270FFFFFFFFFFFFFD8F0"; | 444 const char* cstr = "0x270FFFFFFFFFFFFFD8F0"; |
410 const String& str = String::Handle(String::New(cstr)); | 445 const String& str = String::Handle(String::New(cstr)); |
411 Bigint& bigint = Bigint::Handle(); | 446 Bigint& bigint = Bigint::Handle(); |
412 bigint ^= Integer::NewCanonical(str); | 447 bigint ^= Integer::NewCanonical(str); |
413 uint8_t* buffer; | 448 uint8_t* buffer; |
414 MessageWriter writer(&buffer, &zone_allocator, true); | 449 MessageWriter writer(&buffer, &zone_allocator, true); |
(...skipping 2603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3018 StackZone zone(Isolate::Current()); | 3053 StackZone zone(Isolate::Current()); |
3019 uint8_t* buffer; | 3054 uint8_t* buffer; |
3020 MessageWriter writer(&buffer, &zone_allocator, true); | 3055 MessageWriter writer(&buffer, &zone_allocator, true); |
3021 writer.WriteInlinedObjectHeader(kOmittedObjectId); | 3056 writer.WriteInlinedObjectHeader(kOmittedObjectId); |
3022 // For performance, we'd like single-byte headers when ids are omitted. | 3057 // For performance, we'd like single-byte headers when ids are omitted. |
3023 // If this starts failing, consider renumbering the snapshot ids. | 3058 // If this starts failing, consider renumbering the snapshot ids. |
3024 EXPECT_EQ(1, writer.BytesWritten()); | 3059 EXPECT_EQ(1, writer.BytesWritten()); |
3025 } | 3060 } |
3026 | 3061 |
3027 } // namespace dart | 3062 } // namespace dart |
OLD | NEW |