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, 7 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
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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
3201 result = Dart_StringToCString(result, &str); 3223 result = Dart_StringToCString(result, &str);
3202 EXPECT_STREQ("hidden top !!!", str); 3224 EXPECT_STREQ("hidden top !!!", str);
3203 } 3225 }
3204 3226
3205 3227
3206 TEST_CASE(Invoke_FunnyArgs) { 3228 TEST_CASE(Invoke_FunnyArgs) {
3207 const char* kScriptChars = 3229 const char* kScriptChars =
3208 "test(arg) => 'hello $arg';\n"; 3230 "test(arg) => 'hello $arg';\n";
3209 3231
3210 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 3232 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
3233 Dart_Handle func_name = Dart_NewString("test");
3211 Dart_Handle args[1]; 3234 Dart_Handle args[1];
3212 const char* str; 3235 const char* str;
3213 3236
3214 // Make sure that valid args yield valid results. 3237 // Make sure that valid args yield valid results.
3215 args[0] = Dart_NewString("!!!"); 3238 args[0] = Dart_NewString("!!!");
3216 Dart_Handle result = Dart_Invoke(lib, Dart_NewString("test"), 1, args); 3239 Dart_Handle result = Dart_Invoke(lib, func_name, 1, args);
3217 EXPECT_VALID(result); 3240 EXPECT_VALID(result);
3218 result = Dart_StringToCString(result, &str); 3241 result = Dart_StringToCString(result, &str);
3219 EXPECT_STREQ("hello !!!", str); 3242 EXPECT_STREQ("hello !!!", str);
3220 3243
3221 // Make sure that null is legal. 3244 // Make sure that null is legal.
3222 args[0] = Dart_Null(); 3245 args[0] = Dart_Null();
3223 result = Dart_Invoke(lib, Dart_NewString("test"), 1, args); 3246 result = Dart_Invoke(lib, func_name, 1, args);
3224 EXPECT_VALID(result); 3247 EXPECT_VALID(result);
3225 result = Dart_StringToCString(result, &str); 3248 result = Dart_StringToCString(result, &str);
3226 EXPECT_STREQ("hello null", str); 3249 EXPECT_STREQ("hello null", str);
3227 3250
3228 // Pass a non-instance handle. 3251 // Pass an error handle as the target. The error is propagated.
3252 result = Dart_Invoke(Api::NewError("myerror"),
3253 func_name, 1, args);
3254 EXPECT(Dart_IsError(result));
3255 EXPECT_STREQ("myerror", Dart_GetError(result));
3256
3257 // Pass an error handle as the function name. The error is propagated.
3258 result = Dart_Invoke(lib, Api::NewError("myerror"), 1, args);
3259 EXPECT(Dart_IsError(result));
3260 EXPECT_STREQ("myerror", Dart_GetError(result));
3261
3262 // Pass a non-instance handle as a parameter..
3229 args[0] = lib; 3263 args[0] = lib;
3230 result = Dart_Invoke(lib, Dart_NewString("test"), 1, args); 3264 result = Dart_Invoke(lib, func_name, 1, args);
3231 EXPECT(Dart_IsError(result)); 3265 EXPECT(Dart_IsError(result));
3232 EXPECT_STREQ("Dart_Invoke expects argument 0 to be an instance of Object.", 3266 EXPECT_STREQ("Dart_Invoke expects argument 0 to be an instance of Object.",
3233 Dart_GetError(result)); 3267 Dart_GetError(result));
3234 3268
3235 // Pass an error handle. The error is contagious. 3269 // Pass an error handle as a parameter. The error is propagated.
3236 args[0] = Api::NewError("myerror"); 3270 args[0] = Api::NewError("myerror");
3237 result = Dart_Invoke(lib, Dart_NewString("test"), 1, args); 3271 result = Dart_Invoke(lib, func_name, 1, args);
3238 EXPECT(Dart_IsError(result)); 3272 EXPECT(Dart_IsError(result));
3239 EXPECT_STREQ("myerror", Dart_GetError(result)); 3273 EXPECT_STREQ("myerror", Dart_GetError(result));
3240 } 3274 }
3241 3275
3242 3276
3243 TEST_CASE(Invoke_Null) { 3277 TEST_CASE(Invoke_Null) {
3244 Dart_Handle result = Dart_Invoke(Dart_Null(), 3278 Dart_Handle result = Dart_Invoke(Dart_Null(),
3245 Dart_NewString("toString"), 3279 Dart_NewString("toString"),
3246 0, 3280 0,
3247 NULL); 3281 NULL);
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
3651 3685
3652 // Further calls to LoadScript are errors. 3686 // Further calls to LoadScript are errors.
3653 result = Dart_LoadScript(url, source); 3687 result = Dart_LoadScript(url, source);
3654 EXPECT(Dart_IsError(result)); 3688 EXPECT(Dart_IsError(result));
3655 EXPECT_STREQ("Dart_LoadScript: " 3689 EXPECT_STREQ("Dart_LoadScript: "
3656 "A script has already been loaded from 'dart:test-lib'.", 3690 "A script has already been loaded from 'dart:test-lib'.",
3657 Dart_GetError(result)); 3691 Dart_GetError(result));
3658 } 3692 }
3659 3693
3660 3694
3695 TEST_CASE(RootLibrary) {
3696 const char* kScriptChars =
3697 "main() {"
3698 " return 12345;"
3699 "}";
3700
3701 Dart_Handle root_lib = Dart_RootLibrary();
3702 EXPECT_VALID(root_lib);
3703 EXPECT(Dart_IsNull(root_lib));
3704
3705 // Load a script.
3706 Dart_Handle url = Dart_NewString(TestCase::url());
3707 Dart_Handle source = Dart_NewString(kScriptChars);
3708 EXPECT_VALID(Dart_LoadScript(url, source));
3709
3710 root_lib = Dart_RootLibrary();
3711 Dart_Handle lib_name = Dart_LibraryName(root_lib);
3712 EXPECT_VALID(lib_name);
3713 EXPECT(!Dart_IsNull(root_lib));
3714 const char* name_cstr = "";
3715 EXPECT_VALID(Dart_StringToCString(lib_name, &name_cstr));
3716 EXPECT_STREQ(TestCase::url(), name_cstr);
3717 }
3718
3719
3720 TEST_CASE(RegisteredLibraryUrls) {
3721 const char* kScriptChars =
3722 "main() {"
3723 " return 12345;"
3724 "}";
3725
3726 Dart_Handle lib_list = Dart_RegisteredLibraryUrls();
3727 EXPECT_VALID(lib_list);
3728 EXPECT(Dart_IsList(lib_list));
3729 Dart_Handle list_as_string = Dart_ToString(lib_list);
3730 const char* list_cstr = "";
3731 EXPECT_VALID(Dart_StringToCString(list_as_string, &list_cstr));
3732 EXPECT_NOTSUBSTRING(TestCase::url(), list_cstr);
3733
3734 // Load a script.
3735 Dart_Handle url = Dart_NewString(TestCase::url());
3736 Dart_Handle source = Dart_NewString(kScriptChars);
3737 EXPECT_VALID(Dart_LoadScript(url, source));
3738
3739 lib_list = Dart_RegisteredLibraryUrls();
3740 EXPECT_VALID(lib_list);
3741 EXPECT(Dart_IsList(lib_list));
3742 list_as_string = Dart_ToString(lib_list);
3743 list_cstr = "";
3744 EXPECT_VALID(Dart_StringToCString(list_as_string, &list_cstr));
3745 EXPECT_SUBSTRING(TestCase::url(), list_cstr);
3746 }
3747
3748
3661 static const char* var_mapping[] = { 3749 static const char* var_mapping[] = {
3662 "GOOGLE3", ".", 3750 "GOOGLE3", ".",
3663 "ABC", "lala", 3751 "ABC", "lala",
3664 "var1", "", 3752 "var1", "",
3665 "var2", "winner", 3753 "var2", "winner",
3666 }; 3754 };
3667 static int index = 0; 3755 static int index = 0;
3668 3756
3669 3757
3670 static Dart_Handle import_library_handler(Dart_LibraryTag tag, 3758 static Dart_Handle import_library_handler(Dart_LibraryTag tag,
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
3820 EXPECT_STREQ("incoming error", Dart_GetError(result)); 3908 EXPECT_STREQ("incoming error", Dart_GetError(result));
3821 3909
3822 url = Dart_NewString("noodles.dart"); 3910 url = Dart_NewString("noodles.dart");
3823 result = Dart_LookupLibrary(url); 3911 result = Dart_LookupLibrary(url);
3824 EXPECT(Dart_IsError(result)); 3912 EXPECT(Dart_IsError(result));
3825 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.", 3913 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.",
3826 Dart_GetError(result)); 3914 Dart_GetError(result));
3827 } 3915 }
3828 3916
3829 3917
3918 TEST_CASE(LibraryName) {
3919 const char* kLibrary1Chars =
3920 "#library('library1_name');";
3921 Dart_Handle url = Dart_NewString("library1_url");
3922 Dart_Handle source = Dart_NewString(kLibrary1Chars);
3923 Dart_Handle lib = Dart_LoadLibrary(url, source);
3924 Dart_Handle error = Dart_Error("incoming error");
3925 EXPECT_VALID(lib);
3926
3927 Dart_Handle result = Dart_LibraryName(Dart_Null());
3928 EXPECT(Dart_IsError(result));
3929 EXPECT_STREQ("Dart_LibraryName expects argument 'library' to be non-null.",
3930 Dart_GetError(result));
3931
3932 result = Dart_LibraryName(Dart_True());
3933 EXPECT(Dart_IsError(result));
3934 EXPECT_STREQ(
3935 "Dart_LibraryName expects argument 'library' to be of type Library.",
3936 Dart_GetError(result));
3937
3938 result = Dart_LibraryName(error);
3939 EXPECT(Dart_IsError(result));
3940 EXPECT_STREQ("incoming error", Dart_GetError(result));
3941
3942 result = Dart_LibraryName(lib);
3943 EXPECT_VALID(result);
3944 EXPECT(Dart_IsString(result));
3945 const char* cstr = NULL;
3946 EXPECT_VALID(Dart_StringToCString(result, &cstr));
3947 EXPECT_STREQ("library1_name", cstr);
3948 }
3949
3950
3830 TEST_CASE(LibraryUrl) { 3951 TEST_CASE(LibraryUrl) {
3831 const char* kLibrary1Chars = 3952 const char* kLibrary1Chars =
3832 "#library('library1_name');"; 3953 "#library('library1_name');";
3833 Dart_Handle url = Dart_NewString("library1_url"); 3954 Dart_Handle url = Dart_NewString("library1_url");
3834 Dart_Handle source = Dart_NewString(kLibrary1Chars); 3955 Dart_Handle source = Dart_NewString(kLibrary1Chars);
3835 Dart_Handle lib = Dart_LoadLibrary(url, source); 3956 Dart_Handle lib = Dart_LoadLibrary(url, source);
3836 Dart_Handle error = Dart_Error("incoming error"); 3957 Dart_Handle error = Dart_Error("incoming error");
3837 EXPECT_VALID(lib); 3958 EXPECT_VALID(lib);
3838 3959
3839 Dart_Handle result = Dart_LibraryUrl(Dart_Null()); 3960 Dart_Handle result = Dart_LibraryUrl(Dart_Null());
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after
4707 // We should have received the expected number of interrupts. 4828 // We should have received the expected number of interrupts.
4708 EXPECT_EQ(kInterruptCount, interrupt_count); 4829 EXPECT_EQ(kInterruptCount, interrupt_count);
4709 4830
4710 // Give the spawned thread enough time to properly exit. 4831 // Give the spawned thread enough time to properly exit.
4711 Isolate::SetInterruptCallback(saved); 4832 Isolate::SetInterruptCallback(saved);
4712 } 4833 }
4713 4834
4714 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 4835 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
4715 4836
4716 } // namespace dart 4837 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698