| 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() {
|
| +}
|
| +
|
| +}
|
| +}
|
|
|