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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/trace_buffer.cc ('k') | runtime/vm/vm_sources.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/trace_buffer_test.cc
diff --git a/runtime/vm/trace_buffer_test.cc b/runtime/vm/trace_buffer_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..128487685fc2cd2dfee39f5c0311584dddae345d
--- /dev/null
+++ b/runtime/vm/trace_buffer_test.cc
@@ -0,0 +1,100 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#include "platform/assert.h"
+#include "vm/globals.h"
+#include "vm/json_stream.h"
+#include "vm/trace_buffer.h"
+#include "vm/unit_test.h"
+
+namespace dart {
+
+
+UNIT_TEST_CASE(TraceBufferEmpty) {
+ TraceBuffer* trace_buffer = new TraceBuffer(3);
+ {
+ JSONStream js;
+ trace_buffer->PrintToJSONStream(&js);
+ EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[]}", js.ToCString());
+ }
+ delete trace_buffer;
+}
+
+
+UNIT_TEST_CASE(TraceBufferClear) {
+ TraceBuffer* trace_buffer = new TraceBuffer(3);
+ trace_buffer->Trace(kMicrosecondsPerSecond * 1, "abc");
+ trace_buffer->Clear();
+ {
+ JSONStream js;
+ trace_buffer->PrintToJSONStream(&js);
+ EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":[]}", js.ToCString());
+ }
+ delete trace_buffer;
+}
+
+
+UNIT_TEST_CASE(TraceBufferTrace) {
+ TraceBuffer* trace_buffer = new TraceBuffer(3);
+
+ trace_buffer->Trace(kMicrosecondsPerSecond * 1, "abc");
+ {
+ JSONStream js;
+ trace_buffer->PrintToJSONStream(&js);
+ EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":["
+ "{\"type\":\"TraceBufferEntry\",\"time\":1.000000,"
+ "\"message\":\"abc\"}]}", js.ToCString());
+ }
+ trace_buffer->Trace(kMicrosecondsPerSecond * 2, "def");
+ {
+ JSONStream js;
+ trace_buffer->PrintToJSONStream(&js);
+ EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":["
+ "{\"type\":\"TraceBufferEntry\",\"time\":1.000000,"
+ "\"message\":\"abc\"},"
+ "{\"type\":\"TraceBufferEntry\",\"time\":2.000000,"
+ "\"message\":\"def\"}]}", js.ToCString());
+ }
+ trace_buffer->Trace(kMicrosecondsPerSecond * 3, "ghi");
+ {
+ JSONStream js;
+ trace_buffer->PrintToJSONStream(&js);
+ EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":["
+ "{\"type\":\"TraceBufferEntry\",\"time\":1.000000,"
+ "\"message\":\"abc\"},"
+ "{\"type\":\"TraceBufferEntry\",\"time\":2.000000,"
+ "\"message\":\"def\"},"
+ "{\"type\":\"TraceBufferEntry\",\"time\":3.000000,"
+ "\"message\":\"ghi\"}]}", js.ToCString());
+ }
+ // This will overwrite the first Trace.
+ trace_buffer->Trace(kMicrosecondsPerSecond * 4, "jkl");
+ {
+ JSONStream js;
+ trace_buffer->PrintToJSONStream(&js);
+ EXPECT_STREQ("{\"type\":\"TraceBuffer\",\"members\":["
+ "{\"type\":\"TraceBufferEntry\",\"time\":2.000000,"
+ "\"message\":\"def\"},"
+ "{\"type\":\"TraceBufferEntry\",\"time\":3.000000,"
+ "\"message\":\"ghi\"},"
+ "{\"type\":\"TraceBufferEntry\",\"time\":4.000000,"
+ "\"message\":\"jkl\"}]}", js.ToCString());
+ }
+ delete trace_buffer;
+}
+
+
+UNIT_TEST_CASE(TraceBufferTraceF) {
+ TraceBuffer* trace_buffer = new TraceBuffer(3);
+ trace_buffer->TraceF("foo %d %s", 99, "bar");
+ {
+ JSONStream js;
+ trace_buffer->PrintToJSONStream(&js);
+ EXPECT_SUBSTRING("foo 99 bar", js.ToCString());
+ }
+ delete trace_buffer;
+}
+
+
+} // namespace dart
« 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