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

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

Issue 10416050: Remove the partially completed code for remote IsolateMirrors and (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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 | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/dart_entry.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/utils.h" 7 #include "platform/utils.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_api_state.h" 10 #include "vm/dart_api_state.h"
(...skipping 2139 matching lines...) Expand 10 before | Expand all | Expand 10 after
2150 EXPECT_EQ(iso_2, Dart_CurrentIsolate()); 2150 EXPECT_EQ(iso_2, Dart_CurrentIsolate());
2151 Dart_ShutdownIsolate(); 2151 Dart_ShutdownIsolate();
2152 EXPECT(NULL == Dart_CurrentIsolate()); 2152 EXPECT(NULL == Dart_CurrentIsolate());
2153 Dart_EnterIsolate(iso_1); 2153 Dart_EnterIsolate(iso_1);
2154 EXPECT_EQ(iso_1, Dart_CurrentIsolate()); 2154 EXPECT_EQ(iso_1, Dart_CurrentIsolate());
2155 Dart_ShutdownIsolate(); 2155 Dart_ShutdownIsolate();
2156 EXPECT(NULL == Dart_CurrentIsolate()); 2156 EXPECT(NULL == Dart_CurrentIsolate());
2157 } 2157 }
2158 2158
2159 2159
2160 TEST_CASE(DebugName) {
2161 Dart_Handle debug_name = Dart_DebugName();
2162 EXPECT_VALID(debug_name);
2163 EXPECT(Dart_IsString(debug_name));
2164 }
2165
2166
2160 static void MyMessageNotifyCallback(Dart_Isolate dest_isolate) { 2167 static void MyMessageNotifyCallback(Dart_Isolate dest_isolate) {
2161 } 2168 }
2162 2169
2163 2170
2164 UNIT_TEST_CASE(SetMessageCallbacks) { 2171 UNIT_TEST_CASE(SetMessageCallbacks) {
2165 Dart_Isolate dart_isolate = TestCase::CreateTestIsolate(); 2172 Dart_Isolate dart_isolate = TestCase::CreateTestIsolate();
2166 Dart_SetMessageNotifyCallback(&MyMessageNotifyCallback); 2173 Dart_SetMessageNotifyCallback(&MyMessageNotifyCallback);
2167 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); 2174 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate);
2168 EXPECT_EQ(&MyMessageNotifyCallback, isolate->message_notify_callback()); 2175 EXPECT_EQ(&MyMessageNotifyCallback, isolate->message_notify_callback());
2169 Dart_ShutdownIsolate(); 2176 Dart_ShutdownIsolate();
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
2691 EXPECT_VALID(result); 2698 EXPECT_VALID(result);
2692 result = Dart_IntegerToInt64(result, &value); 2699 result = Dart_IntegerToInt64(result, &value);
2693 EXPECT_EQ(40, value); 2700 EXPECT_EQ(40, value);
2694 2701
2695 // Now access and set various native instance fields of the returned object. 2702 // Now access and set various native instance fields of the returned object.
2696 const int kNativeFld0 = 0; 2703 const int kNativeFld0 = 0;
2697 const int kNativeFld1 = 1; 2704 const int kNativeFld1 = 1;
2698 const int kNativeFld2 = 2; 2705 const int kNativeFld2 = 2;
2699 const int kNativeFld3 = 3; 2706 const int kNativeFld3 = 3;
2700 const int kNativeFld4 = 4; 2707 const int kNativeFld4 = 4;
2708 int field_count = 0;
2701 intptr_t field_value = 0; 2709 intptr_t field_value = 0;
2710 EXPECT_VALID(Dart_GetNativeInstanceFieldCount(retobj, &field_count));
2711 EXPECT_EQ(4, field_count);
2702 result = Dart_GetNativeInstanceField(retobj, kNativeFld4, &field_value); 2712 result = Dart_GetNativeInstanceField(retobj, kNativeFld4, &field_value);
2703 EXPECT(Dart_IsError(result)); 2713 EXPECT(Dart_IsError(result));
2704 result = Dart_GetNativeInstanceField(retobj, kNativeFld0, &field_value); 2714 result = Dart_GetNativeInstanceField(retobj, kNativeFld0, &field_value);
2705 EXPECT_VALID(result); 2715 EXPECT_VALID(result);
2706 EXPECT_EQ(0, field_value); 2716 EXPECT_EQ(0, field_value);
2707 result = Dart_GetNativeInstanceField(retobj, kNativeFld1, &field_value); 2717 result = Dart_GetNativeInstanceField(retobj, kNativeFld1, &field_value);
2708 EXPECT_VALID(result); 2718 EXPECT_VALID(result);
2709 EXPECT_EQ(0, field_value); 2719 EXPECT_EQ(0, field_value);
2710 result = Dart_GetNativeInstanceField(retobj, kNativeFld2, &field_value); 2720 result = Dart_GetNativeInstanceField(retobj, kNativeFld2, &field_value);
2711 EXPECT_VALID(result); 2721 EXPECT_VALID(result);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2768 EXPECT_VALID(result); 2778 EXPECT_VALID(result);
2769 2779
2770 // Load up a test script in it. 2780 // Load up a test script in it.
2771 2781
2772 // Invoke a function which returns an object of type NativeFields. 2782 // Invoke a function which returns an object of type NativeFields.
2773 Dart_Handle retobj = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); 2783 Dart_Handle retobj = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL);
2774 EXPECT_VALID(retobj); 2784 EXPECT_VALID(retobj);
2775 2785
2776 // Now access and set various instance fields of the returned object. 2786 // Now access and set various instance fields of the returned object.
2777 TestNativeFields(retobj); 2787 TestNativeFields(retobj);
2788
2789 // Test that accessing an error handle propagates the error.
2790 Dart_Handle error = Api::NewError("myerror");
2791 intptr_t field_value = 0;
2792
2793 result = Dart_GetNativeInstanceField(error, 0, &field_value);
2794 EXPECT(Dart_IsError(result));
2795 EXPECT_STREQ("myerror", Dart_GetError(result));
2796
2797 result = Dart_SetNativeInstanceField(error, 0, 1);
2798 EXPECT(Dart_IsError(result));
2799 EXPECT_STREQ("myerror", Dart_GetError(result));
2778 } 2800 }
2779 2801
2780 2802
2781 TEST_CASE(ImplicitNativeFieldAccess) { 2803 TEST_CASE(ImplicitNativeFieldAccess) {
2782 const char* kScriptChars = 2804 const char* kScriptChars =
2783 "#import('dart:nativewrappers');" 2805 "#import('dart:nativewrappers');"
2784 "class NativeFields extends NativeFieldWrapperClass4 {\n" 2806 "class NativeFields extends NativeFieldWrapperClass4 {\n"
2785 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" 2807 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
2786 " int fld0;\n" 2808 " int fld0;\n"
2787 " int fld1;\n" 2809 " int fld1;\n"
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
3293 result = Dart_StringToCString(result, &str); 3315 result = Dart_StringToCString(result, &str);
3294 EXPECT_STREQ("hidden top !!!", str); 3316 EXPECT_STREQ("hidden top !!!", str);
3295 } 3317 }
3296 3318
3297 3319
3298 TEST_CASE(Invoke_FunnyArgs) { 3320 TEST_CASE(Invoke_FunnyArgs) {
3299 const char* kScriptChars = 3321 const char* kScriptChars =
3300 "test(arg) => 'hello $arg';\n"; 3322 "test(arg) => 'hello $arg';\n";
3301 3323
3302 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 3324 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
3325 Dart_Handle func_name = Dart_NewString("test");
3303 Dart_Handle args[1]; 3326 Dart_Handle args[1];
3304 const char* str; 3327 const char* str;
3305 3328
3306 // Make sure that valid args yield valid results. 3329 // Make sure that valid args yield valid results.
3307 args[0] = Dart_NewString("!!!"); 3330 args[0] = Dart_NewString("!!!");
3308 Dart_Handle result = Dart_Invoke(lib, Dart_NewString("test"), 1, args); 3331 Dart_Handle result = Dart_Invoke(lib, func_name, 1, args);
3309 EXPECT_VALID(result); 3332 EXPECT_VALID(result);
3310 result = Dart_StringToCString(result, &str); 3333 result = Dart_StringToCString(result, &str);
3311 EXPECT_STREQ("hello !!!", str); 3334 EXPECT_STREQ("hello !!!", str);
3312 3335
3313 // Make sure that null is legal. 3336 // Make sure that null is legal.
3314 args[0] = Dart_Null(); 3337 args[0] = Dart_Null();
3315 result = Dart_Invoke(lib, Dart_NewString("test"), 1, args); 3338 result = Dart_Invoke(lib, func_name, 1, args);
3316 EXPECT_VALID(result); 3339 EXPECT_VALID(result);
3317 result = Dart_StringToCString(result, &str); 3340 result = Dart_StringToCString(result, &str);
3318 EXPECT_STREQ("hello null", str); 3341 EXPECT_STREQ("hello null", str);
3319 3342
3320 // Pass a non-instance handle. 3343 // Pass an error handle as the target. The error is propagated.
3344 result = Dart_Invoke(Api::NewError("myerror"),
3345 func_name, 1, args);
3346 EXPECT(Dart_IsError(result));
3347 EXPECT_STREQ("myerror", Dart_GetError(result));
3348
3349 // Pass an error handle as the function name. The error is propagated.
3350 result = Dart_Invoke(lib, Api::NewError("myerror"), 1, args);
3351 EXPECT(Dart_IsError(result));
3352 EXPECT_STREQ("myerror", Dart_GetError(result));
3353
3354 // Pass a non-instance handle as a parameter..
3321 args[0] = lib; 3355 args[0] = lib;
3322 result = Dart_Invoke(lib, Dart_NewString("test"), 1, args); 3356 result = Dart_Invoke(lib, func_name, 1, args);
3323 EXPECT(Dart_IsError(result)); 3357 EXPECT(Dart_IsError(result));
3324 EXPECT_STREQ("Dart_Invoke expects argument 0 to be an instance of Object.", 3358 EXPECT_STREQ("Dart_Invoke expects argument 0 to be an instance of Object.",
3325 Dart_GetError(result)); 3359 Dart_GetError(result));
3326 3360
3327 // Pass an error handle. The error is contagious. 3361 // Pass an error handle as a parameter. The error is propagated.
3328 args[0] = Api::NewError("myerror"); 3362 args[0] = Api::NewError("myerror");
3329 result = Dart_Invoke(lib, Dart_NewString("test"), 1, args); 3363 result = Dart_Invoke(lib, func_name, 1, args);
3330 EXPECT(Dart_IsError(result)); 3364 EXPECT(Dart_IsError(result));
3331 EXPECT_STREQ("myerror", Dart_GetError(result)); 3365 EXPECT_STREQ("myerror", Dart_GetError(result));
3332 } 3366 }
3333 3367
3334 3368
3335 TEST_CASE(Invoke_Null) { 3369 TEST_CASE(Invoke_Null) {
3336 Dart_Handle result = Dart_Invoke(Dart_Null(), 3370 Dart_Handle result = Dart_Invoke(Dart_Null(),
3337 Dart_NewString("toString"), 3371 Dart_NewString("toString"),
3338 0, 3372 0,
3339 NULL); 3373 NULL);
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
3743 3777
3744 // Further calls to LoadScript are errors. 3778 // Further calls to LoadScript are errors.
3745 result = Dart_LoadScript(url, source); 3779 result = Dart_LoadScript(url, source);
3746 EXPECT(Dart_IsError(result)); 3780 EXPECT(Dart_IsError(result));
3747 EXPECT_STREQ("Dart_LoadScript: " 3781 EXPECT_STREQ("Dart_LoadScript: "
3748 "A script has already been loaded from 'dart:test-lib'.", 3782 "A script has already been loaded from 'dart:test-lib'.",
3749 Dart_GetError(result)); 3783 Dart_GetError(result));
3750 } 3784 }
3751 3785
3752 3786
3787 TEST_CASE(RootLibrary) {
3788 const char* kScriptChars =
3789 "main() {"
3790 " return 12345;"
3791 "}";
3792
3793 Dart_Handle root_lib = Dart_RootLibrary();
3794 EXPECT_VALID(root_lib);
3795 EXPECT(Dart_IsNull(root_lib));
3796
3797 // Load a script.
3798 Dart_Handle url = Dart_NewString(TestCase::url());
3799 Dart_Handle source = Dart_NewString(kScriptChars);
3800 EXPECT_VALID(Dart_LoadScript(url, source));
3801
3802 root_lib = Dart_RootLibrary();
3803 Dart_Handle lib_name = Dart_LibraryName(root_lib);
3804 EXPECT_VALID(lib_name);
3805 EXPECT(!Dart_IsNull(root_lib));
3806 const char* name_cstr = "";
3807 EXPECT_VALID(Dart_StringToCString(lib_name, &name_cstr));
3808 EXPECT_STREQ(TestCase::url(), name_cstr);
3809 }
3810
3811
3753 static const char* var_mapping[] = { 3812 static const char* var_mapping[] = {
3754 "GOOGLE3", ".", 3813 "GOOGLE3", ".",
3755 "ABC", "lala", 3814 "ABC", "lala",
3756 "var1", "", 3815 "var1", "",
3757 "var2", "winner", 3816 "var2", "winner",
3758 }; 3817 };
3759 static int index = 0; 3818 static int index = 0;
3760 3819
3761 3820
3762 static Dart_Handle import_library_handler(Dart_LibraryTag tag, 3821 static Dart_Handle import_library_handler(Dart_LibraryTag tag,
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
3912 EXPECT_STREQ("incoming error", Dart_GetError(result)); 3971 EXPECT_STREQ("incoming error", Dart_GetError(result));
3913 3972
3914 url = Dart_NewString("noodles.dart"); 3973 url = Dart_NewString("noodles.dart");
3915 result = Dart_LookupLibrary(url); 3974 result = Dart_LookupLibrary(url);
3916 EXPECT(Dart_IsError(result)); 3975 EXPECT(Dart_IsError(result));
3917 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.", 3976 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.",
3918 Dart_GetError(result)); 3977 Dart_GetError(result));
3919 } 3978 }
3920 3979
3921 3980
3981 TEST_CASE(LibraryName) {
3982 const char* kLibrary1Chars =
3983 "#library('library1_name');";
3984 Dart_Handle url = Dart_NewString("library1_url");
3985 Dart_Handle source = Dart_NewString(kLibrary1Chars);
3986 Dart_Handle lib = Dart_LoadLibrary(url, source);
3987 Dart_Handle error = Dart_Error("incoming error");
3988 EXPECT_VALID(lib);
3989
3990 Dart_Handle result = Dart_LibraryName(Dart_Null());
3991 EXPECT(Dart_IsError(result));
3992 EXPECT_STREQ("Dart_LibraryName expects argument 'library' to be non-null.",
3993 Dart_GetError(result));
3994
3995 result = Dart_LibraryName(Dart_True());
3996 EXPECT(Dart_IsError(result));
3997 EXPECT_STREQ(
3998 "Dart_LibraryName expects argument 'library' to be of type Library.",
3999 Dart_GetError(result));
4000
4001 result = Dart_LibraryName(error);
4002 EXPECT(Dart_IsError(result));
4003 EXPECT_STREQ("incoming error", Dart_GetError(result));
4004
4005 result = Dart_LibraryName(lib);
4006 EXPECT_VALID(result);
4007 EXPECT(Dart_IsString(result));
4008 const char* cstr = NULL;
4009 EXPECT_VALID(Dart_StringToCString(result, &cstr));
4010 EXPECT_STREQ("library1_name", cstr);
4011 }
4012
4013
3922 TEST_CASE(LibraryUrl) { 4014 TEST_CASE(LibraryUrl) {
3923 const char* kLibrary1Chars = 4015 const char* kLibrary1Chars =
3924 "#library('library1_name');"; 4016 "#library('library1_name');";
3925 Dart_Handle url = Dart_NewString("library1_url"); 4017 Dart_Handle url = Dart_NewString("library1_url");
3926 Dart_Handle source = Dart_NewString(kLibrary1Chars); 4018 Dart_Handle source = Dart_NewString(kLibrary1Chars);
3927 Dart_Handle lib = Dart_LoadLibrary(url, source); 4019 Dart_Handle lib = Dart_LoadLibrary(url, source);
3928 Dart_Handle error = Dart_Error("incoming error"); 4020 Dart_Handle error = Dart_Error("incoming error");
3929 EXPECT_VALID(lib); 4021 EXPECT_VALID(lib);
3930 4022
3931 Dart_Handle result = Dart_LibraryUrl(Dart_Null()); 4023 Dart_Handle result = Dart_LibraryUrl(Dart_Null());
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after
4799 // We should have received the expected number of interrupts. 4891 // We should have received the expected number of interrupts.
4800 EXPECT_EQ(kInterruptCount, interrupt_count); 4892 EXPECT_EQ(kInterruptCount, interrupt_count);
4801 4893
4802 // Give the spawned thread enough time to properly exit. 4894 // Give the spawned thread enough time to properly exit.
4803 Isolate::SetInterruptCallback(saved); 4895 Isolate::SetInterruptCallback(saved);
4804 } 4896 }
4805 4897
4806 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 4898 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
4807 4899
4808 } // namespace dart 4900 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/dart_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698