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

Side by Side Diff: runtime/vm/snapshot_test.cc

Issue 9303031: Add support for lists and backward references when decoding a message to a Dart_CObject object (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« runtime/vm/snapshot.cc ('K') | « runtime/vm/snapshot.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "vm/bigint_operations.h" 6 #include "vm/bigint_operations.h"
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_api_state.h" 9 #include "vm/dart_api_state.h"
10 #include "vm/snapshot.h" 10 #include "vm/snapshot.h"
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 } 881 }
882 free(value->value.as_array.values[i]); 882 free(value->value.as_array.values[i]);
883 } 883 }
884 free(value); 884 free(value);
885 } 885 }
886 } 886 }
887 Dart_ExitScope(); 887 Dart_ExitScope();
888 Dart_ShutdownIsolate(); 888 Dart_ShutdownIsolate();
889 } 889 }
890 890
891
892 UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) {
893 const int kArrayLength = 10;
894 static const char* kScriptChars =
895 "final int kArrayLength = 10;\n"
896 "getStringList() {\n"
897 " var s = 'Hello, world!';\n"
898 " var list = new List<String>(kArrayLength);\n"
899 " for (var i = 0; i < kArrayLength; i++) list[i] = s;\n"
900 " return list;\n"
901 "}\n"
902 "getDoubleList() {\n"
903 " var d = 3.14;\n"
904 " var list = new List<double>(kArrayLength);\n"
905 " for (var i = 0; i < kArrayLength; i++) list[i] = d;\n"
906 " return list;\n"
907 "}\n"
908 "getMixedList() {\n"
909 " var list = new List(kArrayLength);\n"
910 " for (var i = 0; i < kArrayLength; i++) {\n"
911 " list[i] = ((i % 2) == 0) ? 'A' : 2.72;\n"
912 " }\n"
913 " return list;\n"
914 "}\n"
915 "getSelfRefList() {\n"
916 " var list = new List(kArrayLength);\n"
917 " for (var i = 0; i < kArrayLength; i++) {\n"
918 " list[i] = list;\n"
919 " }\n"
920 " return list;\n"
921 "}\n";
922
923 TestCase::CreateTestIsolate();
924 Isolate* isolate = Isolate::Current();
925 EXPECT(isolate != NULL);
926 Dart_EnterScope();
927
928 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
929 EXPECT_VALID(lib);
930
931 {
932 DARTSCOPE_NOCHECKS(isolate);
933
934 {
935 // Generate a list of strings from Dart code.
936 Dart_CObject* object = GetDeserializedDartObject(lib, "getStringList");
937 EXPECT_NOTNULL(object);
938 EXPECT_EQ(Dart_CObject::kArray, object->type);
939 EXPECT_EQ(kArrayLength, object->value.as_array.length);
940 for (int i = 0; i < kArrayLength; i++) {
941 Dart_CObject* element = object->value.as_array.values[i];
942 EXPECT_EQ(object->value.as_array.values[0], element);
943 EXPECT_EQ(Dart_CObject::kString, element->type);
944 EXPECT_STREQ("Hello, world!", element->value.as_string);
945 }
946 free(object->value.as_array.values[0]);
947 free(object);
siva 2012/02/02 04:01:57 Here too if GetDesrializedDartObject used a ZoneAl
Søren Gjesse 2012/02/02 09:59:49 Moving to a zone allocator is part up later CL.
948 }
949 {
950 // Generate a list of doubles from Dart code.
951 Dart_CObject* object = GetDeserializedDartObject(lib, "getDoubleList");
952 EXPECT_NOTNULL(object);
953 EXPECT_EQ(Dart_CObject::kArray, object->type);
954 EXPECT_EQ(kArrayLength, object->value.as_array.length);
955 for (int i = 0; i < kArrayLength; i++) {
956 Dart_CObject* element = object->value.as_array.values[i];
957 EXPECT_EQ(object->value.as_array.values[0], element);
958 EXPECT_EQ(Dart_CObject::kDouble, element->type);
959 EXPECT_EQ(3.14, element->value.as_double);
960 }
961 free(object->value.as_array.values[0]);
962 free(object);
963 }
964 {
965 // Generate a list of objects of different types from Dart code.
966 Dart_CObject* object = GetDeserializedDartObject(lib, "getMixedList");
967 EXPECT_NOTNULL(object);
968 EXPECT_EQ(Dart_CObject::kArray, object->type);
969 EXPECT_EQ(kArrayLength, object->value.as_array.length);
970 for (int i = 0; i < kArrayLength; i++) {
971 Dart_CObject* element = object->value.as_array.values[i];
972 if ((i % 2) == 0) {
973 EXPECT_EQ(object->value.as_array.values[0], element);
974 EXPECT_EQ(Dart_CObject::kString, element->type);
975 EXPECT_STREQ("A", element->value.as_string);
976 } else {
977 EXPECT_EQ(object->value.as_array.values[1], element);
978 EXPECT_EQ(Dart_CObject::kDouble, element->type);
979 EXPECT_STREQ(2.72, element->value.as_double);
980 }
981 }
982 free(object->value.as_array.values[0]);
983 free(object->value.as_array.values[1]);
984 free(object);
985 }
986 {
987 // Generate a list of objects of different types from Dart code.
988 Dart_CObject* object = GetDeserializedDartObject(lib, "getSelfRefList");
989 EXPECT_NOTNULL(object);
990 EXPECT_EQ(Dart_CObject::kArray, object->type);
991 EXPECT_EQ(kArrayLength, object->value.as_array.length);
992 for (int i = 0; i < kArrayLength; i++) {
993 Dart_CObject* element = object->value.as_array.values[i];
994 EXPECT_EQ(Dart_CObject::kArray, element->type);
995 EXPECT_EQ(object, element);
996 }
997 free(object);
998 }
999 }
1000 Dart_ExitScope();
1001 Dart_ShutdownIsolate();
1002 }
1003
891 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 1004 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
892 1005
893 } // namespace dart 1006 } // namespace dart
OLDNEW
« runtime/vm/snapshot.cc ('K') | « runtime/vm/snapshot.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698