| 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/debugger.h" | 6 #include "vm/debugger.h" |
| 6 #include "vm/unit_test.h" | 7 #include "vm/unit_test.h" |
| 7 | 8 |
| 8 namespace dart { | 9 namespace dart { |
| 9 | 10 |
| 11 // Search for the formatted string in buffer. |
| 12 // |
| 13 // TODO(turnidge): This function obscures the line number of failing |
| 14 // EXPECTs. Rework this. |
| 15 static void ExpectSubstringF(const char* buff, const char* fmt, ...) { |
| 16 Isolate* isolate = Isolate::Current(); |
| 17 |
| 18 va_list args; |
| 19 va_start(args, fmt); |
| 20 intptr_t len = OS::VSNPrint(NULL, 0, fmt, args); |
| 21 va_end(args); |
| 22 |
| 23 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); |
| 24 va_list args2; |
| 25 va_start(args2, fmt); |
| 26 OS::VSNPrint(buffer, (len + 1), fmt, args2); |
| 27 va_end(args2); |
| 28 |
| 29 EXPECT_SUBSTRING(buffer, buff); |
| 30 } |
| 31 |
| 32 |
| 10 TEST_CASE(Debugger_PrintBreakpointsToJSONArray) { | 33 TEST_CASE(Debugger_PrintBreakpointsToJSONArray) { |
| 11 const char* kScriptChars = | 34 const char* kScriptChars = |
| 12 "main() {\n" | 35 "main() {\n" |
| 13 " var x = new StringBuffer();\n" | 36 " var x = new StringBuffer();\n" |
| 14 " x.add('won');\n" | 37 " x.add('won');\n" |
| 15 " x.add('too');\n" | 38 " x.add('too');\n" |
| 16 " return x.toString();\n" | 39 " return x.toString();\n" |
| 17 "}\n"; | 40 "}\n"; |
| 18 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 41 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 19 EXPECT_VALID(lib); | 42 EXPECT_VALID(lib); |
| 43 Library& vmlib = Library::Handle(); |
| 44 vmlib ^= Api::UnwrapHandle(lib); |
| 45 EXPECT(!vmlib.IsNull()); |
| 20 | 46 |
| 21 Isolate* isolate = Isolate::Current(); | 47 Isolate* isolate = Isolate::Current(); |
| 22 Debugger* debugger = isolate->debugger(); | 48 Debugger* debugger = isolate->debugger(); |
| 23 const String& url = String::Handle(String::New(TestCase::url())); | 49 const String& url = String::Handle(String::New(TestCase::url())); |
| 24 | 50 |
| 25 // Empty case. | 51 // Empty case. |
| 26 { | 52 { |
| 27 JSONStream js; | 53 JSONStream js; |
| 28 { | 54 { |
| 29 JSONArray jsarr(&js); | 55 JSONArray jsarr(&js); |
| 30 debugger->PrintBreakpointsToJSONArray(&jsarr); | 56 debugger->PrintBreakpointsToJSONArray(&jsarr); |
| 31 } | 57 } |
| 32 EXPECT_STREQ("[]", js.ToCString()); | 58 EXPECT_STREQ("[]", js.ToCString()); |
| 33 } | 59 } |
| 34 | 60 |
| 35 // Test with a couple of breakpoints. | 61 // Test with a couple of breakpoints. |
| 36 debugger->SetBreakpointAtLine(url, 2); | 62 debugger->SetBreakpointAtLine(url, 2); |
| 37 debugger->SetBreakpointAtLine(url, 3); | 63 debugger->SetBreakpointAtLine(url, 3); |
| 38 { | 64 { |
| 39 JSONStream js; | 65 JSONStream js; |
| 40 { | 66 { |
| 41 JSONArray jsarr(&js); | 67 JSONArray jsarr(&js); |
| 42 debugger->PrintBreakpointsToJSONArray(&jsarr); | 68 debugger->PrintBreakpointsToJSONArray(&jsarr); |
| 43 } | 69 } |
| 44 EXPECT_STREQ( | 70 ExpectSubstringF( |
| 45 "[{\"type\":\"Breakpoint\",\"id\":2," | 71 js.ToCString(), |
| 46 "\"enabled\":true,\"resolved\":false," | 72 "[{\"type\":\"Breakpoint\",\"id\":\"debug\\/breakpoints\\/2\"," |
| 47 "\"location\":{\"type\":\"Location\"," | 73 "\"breakpointNumber\":2,\"enabled\":true,\"resolved\":false," |
| 48 "\"script\":\"test-lib\",\"tokenPos\":14}}," | 74 "\"location\":{\"type\":\"Location\"," |
| 49 "{\"type\":\"Breakpoint\",\"id\":1," | 75 "\"script\":{\"type\":\"@Script\"," |
| 50 "\"enabled\":true,\"resolved\":false," | 76 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\"," |
| 51 "\"location\":{\"type\":\"Location\"," | 77 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," |
| 52 "\"script\":\"test-lib\",\"tokenPos\":5}}]", | 78 "\"kind\":\"script\"},\"tokenPos\":14}}," |
| 53 js.ToCString()); | 79 "{\"type\":\"Breakpoint\",\"id\":\"debug\\/breakpoints\\/1\"," |
| 80 "\"breakpointNumber\":1,\"enabled\":true,\"resolved\":false," |
| 81 "\"location\":{\"type\":\"Location\"," |
| 82 "\"script\":{\"type\":\"@Script\"," |
| 83 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\"," |
| 84 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," |
| 85 "\"kind\":\"script\"},\"tokenPos\":5}}]", |
| 86 vmlib.index(), vmlib.index()); |
| 54 } | 87 } |
| 55 } | 88 } |
| 56 | 89 |
| 57 | 90 |
| 58 static bool saw_paused_event = false; | 91 static bool saw_paused_event = false; |
| 59 | 92 |
| 60 static void InspectPausedEvent(Dart_IsolateId isolate_id, | 93 static void InspectPausedEvent(Dart_IsolateId isolate_id, |
| 61 intptr_t bp_id, | 94 intptr_t bp_id, |
| 62 const Dart_CodeLocation& loc) { | 95 const Dart_CodeLocation& loc) { |
| 63 Isolate* isolate = Isolate::Current(); | 96 Isolate* isolate = Isolate::Current(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 debugger->SetBreakpointAtLine(url, 2); | 131 debugger->SetBreakpointAtLine(url, 2); |
| 99 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 132 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 100 EXPECT_VALID(result); | 133 EXPECT_VALID(result); |
| 101 EXPECT(Dart_IsString(result)); | 134 EXPECT(Dart_IsString(result)); |
| 102 | 135 |
| 103 // We ran the code in InspectPausedEvent. | 136 // We ran the code in InspectPausedEvent. |
| 104 EXPECT(saw_paused_event); | 137 EXPECT(saw_paused_event); |
| 105 } | 138 } |
| 106 | 139 |
| 107 } // namespace dart | 140 } // namespace dart |
| OLD | NEW |