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

Side by Side Diff: vm/dart_api_impl_test.cc

Issue 10832146: Improve method names in the ThrowException test to make it less misleading. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 "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 3945 matching lines...) Expand 10 before | Expand all | Expand 10 after
3956 3956
3957 static Dart_NativeFunction native_lookup(Dart_Handle name, int argument_count) { 3957 static Dart_NativeFunction native_lookup(Dart_Handle name, int argument_count) {
3958 return reinterpret_cast<Dart_NativeFunction>(&ExceptionNative); 3958 return reinterpret_cast<Dart_NativeFunction>(&ExceptionNative);
3959 } 3959 }
3960 3960
3961 3961
3962 TEST_CASE(ThrowException) { 3962 TEST_CASE(ThrowException) {
3963 const char* kScriptChars = 3963 const char* kScriptChars =
3964 "class ThrowException {\n" 3964 "class ThrowException {\n"
3965 " ThrowException(int i) : fld1 = i {}\n" 3965 " ThrowException(int i) : fld1 = i {}\n"
3966 " int method1(int i) native \"ThrowException_native\";" 3966 " int thrower(int i) native \"ThrowException_native\";"
3967 " int method2() {\n" 3967 " int test() {\n"
3968 " try { method1(10); } catch(var a) { return 5; } return 10;\n" 3968 " try { thrower(10); } catch(var a) { return 5; } return 10;\n"
3969 " }\n" 3969 " }\n"
3970 " int fld1;\n" 3970 " int fld1;\n"
3971 "}\n" 3971 "}\n"
3972 "ThrowException testMain() {\n" 3972 "ThrowException testMain() {\n"
3973 " ThrowException obj = new ThrowException(10);\n" 3973 " ThrowException obj = new ThrowException(10);\n"
3974 " return obj;\n" 3974 " return obj;\n"
3975 "}\n"; 3975 "}\n";
3976 Dart_Handle result; 3976 Dart_Handle result;
3977 Isolate* isolate = Isolate::Current(); 3977 Isolate* isolate = Isolate::Current();
3978 EXPECT(isolate != NULL); 3978 EXPECT(isolate != NULL);
3979 ApiState* state = isolate->api_state(); 3979 ApiState* state = isolate->api_state();
3980 EXPECT(state != NULL); 3980 EXPECT(state != NULL);
3981 intptr_t size = state->ZoneSizeInBytes(); 3981 intptr_t size = state->ZoneSizeInBytes();
3982 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 3982 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
3983 3983
3984 // Load up a test script which extends the native wrapper class. 3984 // Load up a test script which extends the native wrapper class.
3985 Dart_Handle lib = TestCase::LoadTestScript( 3985 Dart_Handle lib = TestCase::LoadTestScript(
3986 kScriptChars, 3986 kScriptChars,
3987 reinterpret_cast<Dart_NativeEntryResolver>(native_lookup)); 3987 reinterpret_cast<Dart_NativeEntryResolver>(native_lookup));
3988 3988
3989 // Invoke a function which returns an object of type ThrowException. 3989 // Invoke a function which returns an object of type ThrowException.
3990 Dart_Handle retobj = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL); 3990 Dart_Handle retobj = Dart_Invoke(lib, Dart_NewString("testMain"), 0, NULL);
3991 EXPECT_VALID(retobj); 3991 EXPECT_VALID(retobj);
3992 3992
3993 // Throwing an exception here should result in an error. 3993 // Throwing an exception here should result in an error.
3994 result = Dart_ThrowException(retobj); 3994 result = Dart_ThrowException(retobj);
3995 EXPECT(Dart_IsError(result)); 3995 EXPECT(Dart_IsError(result));
3996 3996
3997 // Now invoke method2 which invokes a natve method where it is 3997 // Now invoke 'test' which indirectly invokes a natve method where
Bill Hesse 2012/08/06 08:02:50 native is misspelled natve. Sentence is confusing
3998 // ok to throw an exception, check the result which would indicate 3998 // it is ok to throw an exception, check the result which would
3999 // if an exception was thrown or not. 3999 // indicate if an exception was thrown or not.
4000 result = Dart_Invoke(retobj, Dart_NewString("method2"), 0, NULL); 4000 result = Dart_Invoke(retobj, Dart_NewString("test"), 0, NULL);
4001 EXPECT_VALID(result); 4001 EXPECT_VALID(result);
4002 EXPECT(Dart_IsInteger(result)); 4002 EXPECT(Dart_IsInteger(result));
4003 int64_t value = 0; 4003 int64_t value = 0;
4004 result = Dart_IntegerToInt64(result, &value); 4004 result = Dart_IntegerToInt64(result, &value);
4005 EXPECT_EQ(5, value); 4005 EXPECT_EQ(5, value);
4006 4006
4007 Dart_ExitScope(); // Exit the Dart API scope. 4007 Dart_ExitScope(); // Exit the Dart API scope.
4008 EXPECT_EQ(size, state->ZoneSizeInBytes()); 4008 EXPECT_EQ(size, state->ZoneSizeInBytes());
4009 } 4009 }
4010 4010
(...skipping 2522 matching lines...) Expand 10 before | Expand all | Expand 10 after
6533 EXPECT(Dart_IsString(str)); 6533 EXPECT(Dart_IsString(str));
6534 len = -1; 6534 len = -1;
6535 EXPECT_VALID(Dart_StringLength(str, &len)); 6535 EXPECT_VALID(Dart_StringLength(str, &len));
6536 EXPECT_EQ(0, len); 6536 EXPECT_EQ(0, len);
6537 } 6537 }
6538 6538
6539 6539
6540 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 6540 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
6541 6541
6542 } // namespace dart 6542 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698