Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1118)

Unified Diff: runtime/vm/snapshot_test.cc

Issue 3003333002: [VM] Fix deserialization of arrays with type arguments in ApiMessageReader. (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/dart_api_message.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/snapshot_test.cc
diff --git a/runtime/vm/snapshot_test.cc b/runtime/vm/snapshot_test.cc
index 5f35e94dee95aed93430760d7cb59fb1e8fb13e6..dbc06801cf36d20a8f6f9ea6e11c253db6111f82 100644
--- a/runtime/vm/snapshot_test.cc
+++ b/runtime/vm/snapshot_test.cc
@@ -600,6 +600,48 @@ TEST_CASE(SerializeArray) {
CheckEncodeDecodeMessage(root);
}
+TEST_CASE(SerializeArrayWithTypeArgument) {
+ // Write snapshot with object content.
+ const int kArrayLength = 10;
+ Array& array = Array::Handle(Array::New(kArrayLength));
+
+ TypeArguments& type_args = TypeArguments::Handle();
+ type_args ^= TypeArguments::New(1);
+ type_args.SetTypeAt(0, Type::Handle(Type::ObjectType()));
+ type_args = type_args.Canonicalize();
+
+ array.SetTypeArguments(type_args);
+
+ Smi& smi = Smi::Handle();
+ for (int i = 0; i < kArrayLength; i++) {
+ smi ^= Smi::New(i);
+ array.SetAt(i, smi);
+ }
+ uint8_t* buffer;
+ MessageWriter writer(&buffer, &zone_allocator, &zone_deallocator, true);
+ writer.WriteMessage(array);
+ intptr_t buffer_len = writer.BytesWritten();
+
+ // Read object back from the snapshot.
+ MessageSnapshotReader reader(buffer, buffer_len, thread);
+ Array& serialized_array = Array::Handle();
+ serialized_array ^= reader.ReadObject();
+ EXPECT(array.CanonicalizeEquals(serialized_array));
+
+ // Read object back from the snapshot into a C structure.
+ ApiNativeScope scope;
+ ApiMessageReader api_reader(buffer, buffer_len);
+ Dart_CObject* root = api_reader.ReadMessage();
+ EXPECT_EQ(Dart_CObject_kArray, root->type);
+ EXPECT_EQ(kArrayLength, root->value.as_array.length);
+ for (int i = 0; i < kArrayLength; i++) {
+ Dart_CObject* element = root->value.as_array.values[i];
+ EXPECT_EQ(Dart_CObject_kInt32, element->type);
+ EXPECT_EQ(i, element->value.as_int32);
+ }
+ CheckEncodeDecodeMessage(root);
+}
+
TEST_CASE(FailSerializeLargeArray) {
Dart_CObject root;
root.type = Dart_CObject_kArray;
« no previous file with comments | « runtime/vm/dart_api_message.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698