| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "vm/debugger.h" | 5 #include "vm/debugger.h" |
| 6 #include "vm/unit_test.h" | 6 #include "vm/unit_test.h" |
| 7 | 7 |
| 8 namespace dart { | 8 namespace dart { |
| 9 | 9 |
| 10 TEST_CASE(Debugger_PrintBreakpointsToJSONArray) { | 10 TEST_CASE(Debugger_PrintBreakpointsToJSONArray) { |
| 11 const char* kScriptChars = | 11 const char* kScriptChars = |
| 12 "void main() {\n" | 12 "main() {\n" |
| 13 " print('won');\n" | 13 " var x = new StringBuffer();\n" |
| 14 " print('too');\n" | 14 " x.add('won');\n" |
| 15 " print('free');\n" | 15 " x.add('too');\n" |
| 16 " print('for');\n" | 16 " return x.toString();\n" |
| 17 "}\n"; | 17 "}\n"; |
| 18 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 18 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 19 EXPECT_VALID(lib); | 19 EXPECT_VALID(lib); |
| 20 | 20 |
| 21 Isolate* isolate = Isolate::Current(); | 21 Isolate* isolate = Isolate::Current(); |
| 22 Debugger* debugger = isolate->debugger(); | 22 Debugger* debugger = isolate->debugger(); |
| 23 const String& url = String::Handle(String::New(TestCase::url())); | 23 const String& url = String::Handle(String::New(TestCase::url())); |
| 24 | 24 |
| 25 // Empty case. | 25 // Empty case. |
| 26 { | 26 { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 37 debugger->SetBreakpointAtLine(url, 3); | 37 debugger->SetBreakpointAtLine(url, 3); |
| 38 { | 38 { |
| 39 JSONStream js; | 39 JSONStream js; |
| 40 { | 40 { |
| 41 JSONArray jsarr(&js); | 41 JSONArray jsarr(&js); |
| 42 debugger->PrintBreakpointsToJSONArray(&jsarr); | 42 debugger->PrintBreakpointsToJSONArray(&jsarr); |
| 43 } | 43 } |
| 44 EXPECT_STREQ( | 44 EXPECT_STREQ( |
| 45 "[{\"type\":\"Breakpoint\",\"id\":2," | 45 "[{\"type\":\"Breakpoint\",\"id\":2," |
| 46 "\"enabled\":true,\"resolved\":false," | 46 "\"enabled\":true,\"resolved\":false," |
| 47 "\"location\":{\"type\":\"Location\",\"libId\":12," | 47 "\"location\":{\"type\":\"Location\"," |
| 48 "\"script\":\"dart:test-lib\",\"tokenPos\":12}}," | 48 "\"script\":\"dart:test-lib\",\"tokenPos\":14}}," |
| 49 "{\"type\":\"Breakpoint\",\"id\":1," | 49 "{\"type\":\"Breakpoint\",\"id\":1," |
| 50 "\"enabled\":true,\"resolved\":false," | 50 "\"enabled\":true,\"resolved\":false," |
| 51 "\"location\":{\"type\":\"Location\",\"libId\":12," | 51 "\"location\":{\"type\":\"Location\"," |
| 52 "\"script\":\"dart:test-lib\",\"tokenPos\":6}}]", | 52 "\"script\":\"dart:test-lib\",\"tokenPos\":5}}]", |
| 53 js.ToCString()); | 53 js.ToCString()); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 |
| 58 static bool saw_paused_event = false; |
| 59 |
| 60 static void InspectPausedEvent(Dart_IsolateId isolate_id, |
| 61 intptr_t bp_id, |
| 62 const Dart_CodeLocation& loc) { |
| 63 Isolate* isolate = Isolate::Current(); |
| 64 Debugger* debugger = isolate->debugger(); |
| 65 |
| 66 // The debugger knows that it is paused, and why. |
| 67 EXPECT(debugger->IsPaused()); |
| 68 const Debugger::DebuggerEvent* event = debugger->PauseEvent(); |
| 69 EXPECT(event != NULL); |
| 70 EXPECT(event->type == Debugger::kBreakpointReached); |
| 71 saw_paused_event = true; |
| 72 } |
| 73 |
| 74 |
| 75 TEST_CASE(Debugger_PauseEvent) { |
| 76 const char* kScriptChars = |
| 77 "main() {\n" |
| 78 " var x = new StringBuffer();\n" |
| 79 " x.write('won');\n" |
| 80 " x.write('too');\n" |
| 81 " return x.toString();\n" |
| 82 "}\n"; |
| 83 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 84 EXPECT_VALID(lib); |
| 85 |
| 86 Isolate* isolate = Isolate::Current(); |
| 87 Debugger* debugger = isolate->debugger(); |
| 88 const String& url = String::Handle(String::New(TestCase::url())); |
| 89 |
| 90 // No pause event. |
| 91 EXPECT(!debugger->IsPaused()); |
| 92 EXPECT(debugger->PauseEvent() == NULL); |
| 93 |
| 94 saw_paused_event = false; |
| 95 Dart_SetPausedEventHandler(InspectPausedEvent); |
| 96 |
| 97 // Set a breakpoint and run. |
| 98 debugger->SetBreakpointAtLine(url, 2); |
| 99 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 100 EXPECT_VALID(result); |
| 101 EXPECT(Dart_IsString(result)); |
| 102 |
| 103 // We ran the code in InspectPausedEvent. |
| 104 EXPECT(saw_paused_event); |
| 105 } |
| 106 |
| 107 |
| 108 |
| 57 } // namespace dart | 109 } // namespace dart |
| OLD | NEW |