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

Unified Diff: components/tracing/proto_zero_test/fake_runtime.h

Issue 2083373002: proto_zero_plugin [NOT FOR REVIEW]. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: full_featured_will_split_into_smaller_CLs_for_review Created 4 years, 5 months 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
Index: components/tracing/proto_zero_test/fake_runtime.h
diff --git a/components/tracing/proto_zero_test/fake_runtime.h b/components/tracing/proto_zero_test/fake_runtime.h
new file mode 100644
index 0000000000000000000000000000000000000000..8e444eb545375726180c8d638e277eeecca3e662
--- /dev/null
+++ b/components/tracing/proto_zero_test/fake_runtime.h
@@ -0,0 +1,102 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <inttypes.h>
+#include <stdio.h>
+
+#include <sstream>
+#include <string>
+
+#include "base/macros.h"
+
+// Disable runtime include in generarated proto headers.
+#define PROTO_ZERO_NO_RUNTIME
+
+namespace tracing {
+namespace proto {
+
+class AppendOnlyProtoMessage {
+ public:
+ explicit AppendOnlyProtoMessage();
+ ~AppendOnlyProtoMessage();
+
+ std::string GetLastCall() {
+ std::string str = last_.str();
+ last_.str("");
+ last_.clear();
+ return str;
+ }
+
+ protected:
+ template <class T>
+ void OpenNestedMessage(int field, T** message) {
+ // In actual runtime message is constructing on pre-allocated memory.
+ // Hence there is no need to delete the pointer after use.
+ // In testing case we can sacrifice memory leak.
+ *message = new T();
+ last_ << "message " << field;
+ }
+ void AppendTinyNumber(int field, int32_t value) {
+ last_ << "tiny f" << field << " = " << value;
+ }
+ void AppendBool(int field, bool value) {
+ last_ << "bool f" << field << " = " << (value ? "true" : "false");
+ }
+ void AppendInt32(int field, int32_t value) {
+ last_ << "int32 f" << field << " = " << value;
+ }
+ void AppendInt64(int field, int64_t value) {
+ last_ << "int64 f" << field << " = " << value;
+ }
+ void AppendUint32(int field, uint32_t value) {
+ last_ << "uint32 f" << field << " = " << value;
+ }
+ void AppendUint64(int field, uint64_t value) {
+ last_ << "uint64 f" << field << " = " << value;
+ }
+ void AppendSint32(int field, int32_t value) {
+ last_ << "sint32 f" << field << " = " << value;
+ }
+ void AppendSint64(int field, int64_t value) {
+ last_ << "sint64 f" << field << " = " << value;
+ }
+ void AppendFixed32(int field, uint32_t value) {
+ last_ << "fixed32 f" << field << " = " << value;
+ }
+ void AppendFixed64(int field, uint64_t value) {
+ last_ << "fixed64 f" << field << " = " << value;
+ }
+ void AppendSfixed32(int field, int32_t value) {
+ last_ << "sfixed32 f" << field << " = " << value;
+ }
+ void AppendSfixed64(int field, int64_t value) {
+ last_ << "sfixed64 f" << field << " = " << value;
+ }
+ void AppendFloat(int field, float value) {
+ last_ << "float f" << field << " = " << value;
+ }
+ void AppendDouble(int field, double value) {
+ last_ << "double f" << field << " = " << value;
+ }
+ void AppendString(int field, const char* value) {
+ last_ << "string f" << field << " = \"" << value << "\"";
+ }
+ void AppendBytes(int field, const uint8_t* data, size_t size) {
+ last_ << "bytes f" << field << " = [" << size << "]";
+ }
+
+ private:
+ std::ostringstream last_;
+
+ DISALLOW_COPY_AND_ASSIGN(AppendOnlyProtoMessage);
+};
+
+AppendOnlyProtoMessage::AppendOnlyProtoMessage() {
+}
+
+AppendOnlyProtoMessage::~AppendOnlyProtoMessage() {
+}
+
+}
+}

Powered by Google App Engine
This is Rietveld 408576698