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/dart_api_impl.h" | 5 #include "vm/dart_api_impl.h" |
6 #include "vm/debugger.h" | 6 #include "vm/debugger.h" |
7 #include "vm/unit_test.h" | 7 #include "vm/unit_test.h" |
8 | 8 |
9 namespace dart { | 9 namespace dart { |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 " return x.toString();\n" | 39 " return x.toString();\n" |
40 "}\n"; | 40 "}\n"; |
41 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 41 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
42 EXPECT_VALID(lib); | 42 EXPECT_VALID(lib); |
43 Library& vmlib = Library::Handle(); | 43 Library& vmlib = Library::Handle(); |
44 vmlib ^= Api::UnwrapHandle(lib); | 44 vmlib ^= Api::UnwrapHandle(lib); |
45 EXPECT(!vmlib.IsNull()); | 45 EXPECT(!vmlib.IsNull()); |
46 | 46 |
47 Isolate* isolate = Isolate::Current(); | 47 Isolate* isolate = Isolate::Current(); |
48 Debugger* debugger = isolate->debugger(); | 48 Debugger* debugger = isolate->debugger(); |
49 const String& url = String::Handle(String::New(TestCase::url())); | |
50 | 49 |
51 // Empty case. | 50 // Empty case. |
52 { | 51 { |
53 JSONStream js; | 52 JSONStream js; |
54 { | 53 { |
55 JSONArray jsarr(&js); | 54 JSONArray jsarr(&js); |
56 debugger->PrintBreakpointsToJSONArray(&jsarr); | 55 debugger->PrintBreakpointsToJSONArray(&jsarr); |
57 } | 56 } |
58 EXPECT_STREQ("[]", js.ToCString()); | 57 EXPECT_STREQ("[]", js.ToCString()); |
59 } | 58 } |
60 | 59 |
61 // Test with a couple of breakpoints. | 60 // Test with a couple of breakpoints. |
62 debugger->SetBreakpointAtLine(url, 2); | 61 Dart_Handle url = NewString(TestCase::url()); |
63 debugger->SetBreakpointAtLine(url, 3); | 62 EXPECT_VALID(Dart_SetBreakpoint(url, 2)); |
| 63 EXPECT_VALID(Dart_SetBreakpoint(url, 3)); |
64 { | 64 { |
65 JSONStream js; | 65 JSONStream js; |
66 { | 66 { |
67 JSONArray jsarr(&js); | 67 JSONArray jsarr(&js); |
68 debugger->PrintBreakpointsToJSONArray(&jsarr); | 68 debugger->PrintBreakpointsToJSONArray(&jsarr); |
69 } | 69 } |
70 ExpectSubstringF( | 70 ExpectSubstringF( |
71 js.ToCString(), | 71 js.ToCString(), |
72 "[{\"type\":\"Breakpoint\",\"fixedId\":true,\"id\":\"breakpoints\\/2\"," | 72 "[{\"type\":\"Breakpoint\",\"fixedId\":true,\"id\":\"breakpoints\\/2\"," |
73 "\"breakpointNumber\":2,\"resolved\":false," | 73 "\"breakpointNumber\":2,\"resolved\":false," |
(...skipping 17 matching lines...) Expand all Loading... |
91 static bool saw_paused_event = false; | 91 static bool saw_paused_event = false; |
92 | 92 |
93 static void InspectPausedEvent(Dart_IsolateId isolate_id, | 93 static void InspectPausedEvent(Dart_IsolateId isolate_id, |
94 intptr_t bp_id, | 94 intptr_t bp_id, |
95 const Dart_CodeLocation& loc) { | 95 const Dart_CodeLocation& loc) { |
96 Isolate* isolate = Isolate::Current(); | 96 Isolate* isolate = Isolate::Current(); |
97 Debugger* debugger = isolate->debugger(); | 97 Debugger* debugger = isolate->debugger(); |
98 | 98 |
99 // The debugger knows that it is paused, and why. | 99 // The debugger knows that it is paused, and why. |
100 EXPECT(debugger->IsPaused()); | 100 EXPECT(debugger->IsPaused()); |
101 const DebuggerEvent* event = debugger->PauseEvent(); | 101 const ServiceEvent* event = debugger->PauseEvent(); |
102 EXPECT(event != NULL); | 102 EXPECT(event != NULL); |
103 EXPECT(event->type() == DebuggerEvent::kBreakpointReached); | 103 EXPECT(event->kind() == ServiceEvent::kPauseBreakpoint); |
104 saw_paused_event = true; | 104 saw_paused_event = true; |
105 } | 105 } |
106 | 106 |
107 | 107 |
108 TEST_CASE(Debugger_PauseEvent) { | 108 TEST_CASE(Debugger_PauseEvent) { |
109 const char* kScriptChars = | 109 const char* kScriptChars = |
110 "main() {\n" | 110 "main() {\n" |
111 " var x = new StringBuffer();\n" | 111 " var x = new StringBuffer();\n" |
112 " x.write('won');\n" | 112 " x.write('won');\n" |
113 " x.write('too');\n" | 113 " x.write('too');\n" |
114 " return x.toString();\n" | 114 " return x.toString();\n" |
115 "}\n"; | 115 "}\n"; |
116 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 116 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
117 EXPECT_VALID(lib); | 117 EXPECT_VALID(lib); |
118 | 118 |
119 Isolate* isolate = Isolate::Current(); | 119 Isolate* isolate = Isolate::Current(); |
120 Debugger* debugger = isolate->debugger(); | 120 Debugger* debugger = isolate->debugger(); |
121 const String& url = String::Handle(String::New(TestCase::url())); | |
122 | 121 |
123 // No pause event. | 122 // No pause event. |
124 EXPECT(!debugger->IsPaused()); | 123 EXPECT(!debugger->IsPaused()); |
125 EXPECT(debugger->PauseEvent() == NULL); | 124 EXPECT(debugger->PauseEvent() == NULL); |
126 | 125 |
127 saw_paused_event = false; | 126 saw_paused_event = false; |
128 Dart_SetPausedEventHandler(InspectPausedEvent); | 127 Dart_SetPausedEventHandler(InspectPausedEvent); |
129 | 128 |
130 // Set a breakpoint and run. | 129 // Set a breakpoint and run. |
131 debugger->SetBreakpointAtLine(url, 2); | 130 EXPECT_VALID(Dart_SetBreakpoint(NewString(TestCase::url()), 2)); |
132 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 131 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
133 EXPECT_VALID(result); | 132 EXPECT_VALID(result); |
134 EXPECT(Dart_IsString(result)); | 133 EXPECT(Dart_IsString(result)); |
135 | 134 |
136 // We ran the code in InspectPausedEvent. | 135 // We ran the code in InspectPausedEvent. |
137 EXPECT(saw_paused_event); | 136 EXPECT(saw_paused_event); |
138 } | 137 } |
139 | 138 |
140 #endif // !PRODUCT | 139 #endif // !PRODUCT |
141 | 140 |
142 } // namespace dart | 141 } // namespace dart |
OLD | NEW |