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 "platform/assert.h" | 5 #include "platform/assert.h" |
6 #include "vm/globals.h" | 6 #include "vm/globals.h" |
7 #include "vm/json_stream.h" | 7 #include "vm/json_stream.h" |
8 #include "vm/trace_buffer.h" | 8 #include "vm/trace_buffer.h" |
9 #include "vm/unit_test.h" | 9 #include "vm/unit_test.h" |
10 | 10 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 trace_buffer->TraceF("foo %d %s", 99, "bar"); | 97 trace_buffer->TraceF("foo %d %s", 99, "bar"); |
98 { | 98 { |
99 JSONStream js; | 99 JSONStream js; |
100 trace_buffer->PrintToJSONStream(&js); | 100 trace_buffer->PrintToJSONStream(&js); |
101 EXPECT_SUBSTRING("foo 99 bar", js.ToCString()); | 101 EXPECT_SUBSTRING("foo 99 bar", js.ToCString()); |
102 } | 102 } |
103 delete trace_buffer; | 103 delete trace_buffer; |
104 } | 104 } |
105 | 105 |
106 | 106 |
| 107 TEST_CASE(TraceBufferTraceWarning) { |
| 108 Isolate* isolate = Isolate::Current(); |
| 109 TraceBuffer::Init(isolate, 3); |
| 110 TraceBuffer* trace_buffer = isolate->trace_buffer(); |
| 111 const String& url = String::Handle(isolate, String::New("Plug")); |
| 112 const String& source = String::Handle(isolate, String::New("240V")); |
| 113 const Script& script = Script::Handle(isolate, |
| 114 Script::New(url, source, RawScript::kScriptTag)); |
| 115 { |
| 116 const intptr_t token_pos = 0; |
| 117 const char* message = "High Voltage"; |
| 118 TraceBuffer::TraceWarningF(isolate, script, token_pos, "%s", message); |
| 119 { |
| 120 JSONStream js; |
| 121 trace_buffer->PrintToJSONStream(&js); |
| 122 EXPECT_SUBSTRING("{\"type\":\"TraceBuffer\",\"members\":[" |
| 123 "{\"type\":\"TraceBufferEntry\",\"time\":", |
| 124 js.ToCString()); |
| 125 // Skip time. |
| 126 EXPECT_SUBSTRING("\"message\":{\"type\":\"Warning\"," |
| 127 "\"script\":{\"type\":\"@Script\",\"id\":" |
| 128 "\"scripts\\/Plug\",\"name\":\"Plug\",\"user_name\":" |
| 129 "\"Plug\",\"kind\":\"script\"},\"tokenPos\":0," |
| 130 "\"message\":\"High Voltage\"}}]}", |
| 131 js.ToCString()); |
| 132 } |
| 133 } |
| 134 { |
| 135 const intptr_t token_pos = 1; |
| 136 const char* message = "Low Voltage"; |
| 137 TraceBuffer::TraceWarningF(isolate, script, token_pos, "%s", message); |
| 138 } |
| 139 EXPECT_EQ(2, trace_buffer->Length()); |
| 140 EXPECT_STREQ("{\"type\":\"Warning\",\"script\":{\"type\":\"@Script\",\"id\":" |
| 141 "\"scripts\\/Plug\",\"name\":\"Plug\",\"user_name\":\"Plug\"," |
| 142 "\"kind\":\"script\"},\"tokenPos\":0,\"message\":" |
| 143 "\"High Voltage\"}", |
| 144 trace_buffer->At(0)->message); |
| 145 EXPECT_STREQ("{\"type\":\"Warning\",\"script\":{\"type\":\"@Script\",\"id\":" |
| 146 "\"scripts\\/Plug\",\"name\":\"Plug\",\"user_name\":\"Plug\"," |
| 147 "\"kind\":\"script\"},\"tokenPos\":1,\"message\":" |
| 148 "\"Low Voltage\"}", |
| 149 trace_buffer->At(1)->message); |
| 150 |
| 151 delete trace_buffer; |
| 152 } |
| 153 |
107 } // namespace dart | 154 } // namespace dart |
OLD | NEW |