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

Side by Side Diff: runtime/vm/trace_buffer_test.cc

Issue 50413003: TraceBuffer implementation with tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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 | « runtime/vm/trace_buffer.cc ('k') | runtime/vm/vm_sources.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include "platform/assert.h"
6 #include "vm/globals.h"
7 #include "vm/json_stream.h"
8 #include "vm/trace_buffer.h"
9 #include "vm/unit_test.h"
10
11 namespace dart {
12
13
14 UNIT_TEST_CASE(TraceBufferEmpty) {
15 TraceBuffer* trace_buffer = new TraceBuffer(3);
16 {
17 JSONStream js;
18 trace_buffer->PrintToJSONStream(&js);
19 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[]}", js.ToCString());
20 }
21 delete trace_buffer;
22 }
23
24
25 UNIT_TEST_CASE(TraceBufferClear) {
26 TraceBuffer* trace_buffer = new TraceBuffer(3);
27 trace_buffer->Trace(kMicrosecondsPerSecond * 1, "abc");
28 trace_buffer->Clear();
29 {
30 JSONStream js;
31 trace_buffer->PrintToJSONStream(&js);
32 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[]}", js.ToCString());
33 }
34 delete trace_buffer;
35 }
36
37
38 UNIT_TEST_CASE(TraceBufferTrace) {
39 TraceBuffer* trace_buffer = new TraceBuffer(3);
40
41 trace_buffer->Trace(kMicrosecondsPerSecond * 1, "abc");
42 {
43 JSONStream js;
44 trace_buffer->PrintToJSONStream(&js);
45 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":["
46 "{\"type\":\"TraceBufferEntry\",\"time\":1.000000,"
47 "\"message\":\"abc\"}]}", js.ToCString());
48 }
49 trace_buffer->Trace(kMicrosecondsPerSecond * 2, "def");
50 {
51 JSONStream js;
52 trace_buffer->PrintToJSONStream(&js);
53 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":["
54 "{\"type\":\"TraceBufferEntry\",\"time\":1.000000,"
55 "\"message\":\"abc\"},"
56 "{\"type\":\"TraceBufferEntry\",\"time\":2.000000,"
57 "\"message\":\"def\"}]}", js.ToCString());
58 }
59 trace_buffer->Trace(kMicrosecondsPerSecond * 3, "ghi");
60 {
61 JSONStream js;
62 trace_buffer->PrintToJSONStream(&js);
63 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":["
64 "{\"type\":\"TraceBufferEntry\",\"time\":1.000000,"
65 "\"message\":\"abc\"},"
66 "{\"type\":\"TraceBufferEntry\",\"time\":2.000000,"
67 "\"message\":\"def\"},"
68 "{\"type\":\"TraceBufferEntry\",\"time\":3.000000,"
69 "\"message\":\"ghi\"}]}", js.ToCString());
70 }
71 // This will overwrite the first Trace.
72 trace_buffer->Trace(kMicrosecondsPerSecond * 4, "jkl");
73 {
74 JSONStream js;
75 trace_buffer->PrintToJSONStream(&js);
76 EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":["
77 "{\"type\":\"TraceBufferEntry\",\"time\":2.000000,"
78 "\"message\":\"def\"},"
79 "{\"type\":\"TraceBufferEntry\",\"time\":3.000000,"
80 "\"message\":\"ghi\"},"
81 "{\"type\":\"TraceBufferEntry\",\"time\":4.000000,"
82 "\"message\":\"jkl\"}]}", js.ToCString());
83 }
84 delete trace_buffer;
85 }
86
87
88 UNIT_TEST_CASE(TraceBufferTraceF) {
89 TraceBuffer* trace_buffer = new TraceBuffer(3);
90 trace_buffer->TraceF("foo %d %s", 99, "bar");
91 {
92 JSONStream js;
93 trace_buffer->PrintToJSONStream(&js);
94 EXPECT_SUBSTRING("foo 99 bar", js.ToCString());
95 }
96 delete trace_buffer;
97 }
98
99
100 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/trace_buffer.cc ('k') | runtime/vm/vm_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698