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

Side by Side Diff: vm/dart_api_impl_test.cc

Issue 12209075: Provide implementations for (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 7 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
« no previous file with comments | « vm/dart_api_impl.cc ('k') | vm/object.h » ('j') | 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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "platform/json.h" 7 #include "platform/json.h"
8 #include "platform/utils.h" 8 #include "platform/utils.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 898 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 909
910 result = Dart_ScalarListReleaseData(Dart_Null()); 910 result = Dart_ScalarListReleaseData(Dart_Null());
911 EXPECT_ERROR(result, "Dart_ScalarListReleaseData expects argument 'array'" 911 EXPECT_ERROR(result, "Dart_ScalarListReleaseData expects argument 'array'"
912 " to be non-null."); 912 " to be non-null.");
913 result = Dart_ScalarListReleaseData(str); 913 result = Dart_ScalarListReleaseData(str);
914 EXPECT_ERROR(result, "Dart_ScalarListReleaseData expects argument 'array'" 914 EXPECT_ERROR(result, "Dart_ScalarListReleaseData expects argument 'array'"
915 " to be of type 'scalar list'."); 915 " to be of type 'scalar list'.");
916 } 916 }
917 917
918 918
919 static void TestDirectAccess(Dart_Handle lib,
920 Dart_Handle array,
921 Dart_Scalar_Type expected_type) {
922 // Invoke the dart function that sets initial values.
923 Dart_Handle dart_args[1];
924 dart_args[0] = array;
925 Dart_Invoke(lib, NewString("setMain"), 1, dart_args);
926
927 // Now Get a direct access to this typed array and check it's contents.
928 const int kLength = 10;
929 Dart_Handle result;
930 Dart_Scalar_Type type;
931 void* data;
932 intptr_t len;
933 result = Dart_ScalarListAcquireData(array, &type, &data, &len);
934 EXPECT_VALID(result);
935 EXPECT_EQ(expected_type, type);
936 EXPECT_EQ(kLength, len);
937 int8_t* dataP = reinterpret_cast<int8_t*>(data);
938 for (int i = 0; i < kLength; i++) {
939 EXPECT_EQ(i, dataP[i]);
940 }
941
942 // Now modify the values in the directly accessible array and then check
943 // it we see the changes back in dart.
944 for (int i = 0; i < kLength; i++) {
945 dataP[i] += 10;
946 }
947
948 // Release direct accesss to the typed array.
949 result = Dart_ScalarListReleaseData(array);
950 EXPECT_VALID(result);
951
952 // Invoke the dart function in order to check the modified values.
953 Dart_Invoke(lib, NewString("testMain"), 1, dart_args);
954 }
955
956
957 TEST_CASE(ScalarListDirectAccess1) {
958 const char* kScriptChars =
959 "import 'dart:scalarlist';\n"
960 "void setMain(var a) {"
961 " for (var i = 0; i < 10; i++) {"
962 " a[i] = i;"
963 " }"
964 "}\n"
965 "void testMain(var list) {"
966 " for (var i = 0; i < 10; i++) {"
967 " Expect.equals((10 + i), list[i]);"
968 " }\n"
969 "}\n"
970 "List main() {"
971 " var a = new Int8List(10);"
972 " return a;"
973 "}\n";
974 // Create a test library and Load up a test script in it.
975 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
976
977 // Test with an regular typed array object.
978 Dart_Handle list_access_test_obj;
979 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL);
980 EXPECT_VALID(list_access_test_obj);
981 TestDirectAccess(lib, list_access_test_obj, kInt8);
982
983 // Test with an external typed array object.
984 uint8_t data[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
985 intptr_t data_length = ARRAY_SIZE(data);
986 Dart_Handle ext_list_access_test_obj;
987 ext_list_access_test_obj = Dart_NewExternalByteArray(data,
988 data_length,
989 NULL, NULL);
990 EXPECT_VALID(ext_list_access_test_obj);
991 TestDirectAccess(lib, ext_list_access_test_obj, kUint8);
992 }
993
994
919 static void ExternalByteArrayAccessTests(Dart_Handle obj, 995 static void ExternalByteArrayAccessTests(Dart_Handle obj,
920 uint8_t data[], 996 uint8_t data[],
921 intptr_t data_length) { 997 intptr_t data_length) {
922 EXPECT_VALID(obj); 998 EXPECT_VALID(obj);
923 EXPECT(Dart_IsByteArray(obj)); 999 EXPECT(Dart_IsByteArray(obj));
924 EXPECT(Dart_IsByteArrayExternal(obj)); 1000 EXPECT(Dart_IsByteArrayExternal(obj));
925 EXPECT(Dart_IsList(obj)); 1001 EXPECT(Dart_IsList(obj));
926 1002
927 void* raw_data = NULL; 1003 void* raw_data = NULL;
928 EXPECT_VALID(Dart_ExternalByteArrayGetData(obj, &raw_data)); 1004 EXPECT_VALID(Dart_ExternalByteArrayGetData(obj, &raw_data));
(...skipping 6410 matching lines...) Expand 10 before | Expand all | Expand 10 after
7339 NULL); 7415 NULL);
7340 int64_t value = 0; 7416 int64_t value = 0;
7341 result = Dart_IntegerToInt64(result, &value); 7417 result = Dart_IntegerToInt64(result, &value);
7342 EXPECT_VALID(result); 7418 EXPECT_VALID(result);
7343 EXPECT_EQ(260, value); 7419 EXPECT_EQ(260, value);
7344 } 7420 }
7345 7421
7346 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 7422 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
7347 7423
7348 } // namespace dart 7424 } // namespace dart
OLDNEW
« no previous file with comments | « vm/dart_api_impl.cc ('k') | vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698