Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <limits> | 5 #include <limits> |
| 6 #include <memory> | 6 #include <memory> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "components/tracing/core/proto_zero_message_handle.h" | 9 #include "components/tracing/core/proto_zero_message_handle.h" |
| 10 #include "components/tracing/test/example_proto/library.pbzero.h" | 10 #include "components/tracing/test/example_proto/library.pbzero.h" |
| 11 #include "components/tracing/test/example_proto/test_messages.pb.h" | 11 #include "components/tracing/test/example_proto/test_messages.pb.h" |
| 12 #include "components/tracing/test/example_proto/test_messages.pbzero.h" | 12 #include "components/tracing/test/example_proto/test_messages.pbzero.h" |
| 13 #include "components/tracing/test/fake_scattered_buffer.h" | 13 #include "components/tracing/test/fake_scattered_buffer.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "third_party/protobuf/src/google/protobuf/descriptor.h" | |
| 15 | 16 |
| 16 namespace tracing { | 17 namespace tracing { |
| 17 namespace proto { | 18 namespace proto { |
| 18 | 19 |
| 19 namespace pbtest = pbzero::foo::bar; | 20 namespace pbtest = pbzero::foo::bar; |
| 20 namespace pbgold = foo::bar; // Official C++ protobuf compiler. | 21 namespace pbgold = foo::bar; // Official C++ protobuf compiler. |
| 21 | 22 |
| 22 using tracing::v2::FakeScatteredBuffer; | 23 using tracing::v2::FakeScatteredBuffer; |
| 23 using tracing::v2::ProtoZeroMessage; | 24 using tracing::v2::ProtoZeroMessage; |
| 24 using tracing::v2::ScatteredStreamWriter; | 25 using tracing::v2::ScatteredStreamWriter; |
| 25 using tracing::v2::ProtoZeroMessageHandle; | 26 using tracing::v2::ProtoZeroMessageHandle; |
| 26 using tracing::v2::ProtoZeroMessageHandleBase; | 27 using tracing::v2::ProtoZeroMessageHandleBase; |
| 28 using tracing::v2::proto::ProtoFieldDescriptor; | |
| 27 | 29 |
| 28 constexpr size_t kChunkSize = 42; | 30 constexpr size_t kChunkSize = 42; |
| 29 | 31 |
| 30 class ProtoZeroConformanceTest : public ::testing::Test { | 32 class ProtoZeroConformanceTest : public ::testing::Test { |
| 31 public: | 33 public: |
| 32 void SetUp() override { | 34 void SetUp() override { |
| 33 buffer_.reset(new FakeScatteredBuffer(kChunkSize)); | 35 buffer_.reset(new FakeScatteredBuffer(kChunkSize)); |
| 34 stream_writer_.reset(new ScatteredStreamWriter(buffer_.get())); | 36 stream_writer_.reset(new ScatteredStreamWriter(buffer_.get())); |
| 35 } | 37 } |
| 36 | 38 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 EXPECT_FALSE(gold_msg_a.repeated_a(1).has_value_b()); | 150 EXPECT_FALSE(gold_msg_a.repeated_a(1).has_value_b()); |
| 149 EXPECT_EQ(1000, gold_msg_a.super_nested().value_c()); | 151 EXPECT_EQ(1000, gold_msg_a.super_nested().value_c()); |
| 150 } | 152 } |
| 151 | 153 |
| 152 TEST(ProtoZeroTest, Simple) { | 154 TEST(ProtoZeroTest, Simple) { |
| 153 // Test the includes for indirect public import: library.pbzero.h -> | 155 // Test the includes for indirect public import: library.pbzero.h -> |
| 154 // library_internals/galaxies.pbzero.h -> upper_import.pbzero.h . | 156 // library_internals/galaxies.pbzero.h -> upper_import.pbzero.h . |
| 155 EXPECT_LE(0u, sizeof(pbtest::TrickyPublicImport)); | 157 EXPECT_LE(0u, sizeof(pbtest::TrickyPublicImport)); |
| 156 } | 158 } |
| 157 | 159 |
| 158 TEST(ProtoZeroTest, FieldNumbers) { | 160 TEST(ProtoZeroTest, Reflection) { |
| 159 // Tests camel case conversion as well. | 161 // Tests camel case conversion as well. |
| 160 EXPECT_EQ(1, pbtest::CamelCaseFields::kFooBarBazFieldNumber); | 162 EXPECT_EQ(1, pbtest::CamelCaseFields::kFooBarBazFieldNumber); |
| 161 EXPECT_EQ(2, pbtest::CamelCaseFields::kBarBazFieldNumber); | 163 EXPECT_EQ(2, pbtest::CamelCaseFields::kBarBazFieldNumber); |
| 162 EXPECT_EQ(3, pbtest::CamelCaseFields::kMooMooFieldNumber); | 164 EXPECT_EQ(3, pbtest::CamelCaseFields::kMooMooFieldNumber); |
| 163 EXPECT_EQ(4, pbtest::CamelCaseFields::kURLEncoderFieldNumber); | 165 EXPECT_EQ(4, pbtest::CamelCaseFields::kURLEncoderFieldNumber); |
| 164 EXPECT_EQ(5, pbtest::CamelCaseFields::kXMapFieldNumber); | 166 EXPECT_EQ(5, pbtest::CamelCaseFields::kXMapFieldNumber); |
| 165 EXPECT_EQ(6, pbtest::CamelCaseFields::kUrLENcoDerFieldNumber); | 167 EXPECT_EQ(6, pbtest::CamelCaseFields::kUrLENcoDerFieldNumber); |
| 166 EXPECT_EQ(7, pbtest::CamelCaseFields::kBigBangFieldNumber); | 168 EXPECT_EQ(7, pbtest::CamelCaseFields::kBigBangFieldNumber); |
| 167 EXPECT_EQ(8, pbtest::CamelCaseFields::kU2FieldNumber); | 169 EXPECT_EQ(8, pbtest::CamelCaseFields::kU2FieldNumber); |
| 168 EXPECT_EQ(9, pbtest::CamelCaseFields::kBangBigFieldNumber); | 170 EXPECT_EQ(9, pbtest::CamelCaseFields::kBangBigFieldNumber); |
| 171 | |
| 172 const ProtoFieldDescriptor* reflection = | |
| 173 pbtest::EveryField::GetFieldDescriptor( | |
| 174 pbtest::EveryField::kFieldInt32FieldNumber); | |
| 175 EXPECT_EQ("field_int32", reflection->name()); | |
| 176 EXPECT_EQ(ProtoFieldDescriptor::Type::TYPE_INT32, reflection->type()); | |
| 177 EXPECT_EQ(1u, reflection->number()); | |
| 178 EXPECT_FALSE(reflection->is_repeated()); | |
| 179 | |
| 180 EXPECT_FALSE(pbtest::TransgalacticParcel::GetFieldDescriptor(42)->is_valid()); | |
| 181 } | |
| 182 | |
| 183 TEST(ProtoZeroTest, GeneratorAssumptions) { | |
| 184 // Generator plugin assumes that values of field types are equally defined | |
| 185 // in protobuf compiler and in our proto utils. | |
| 186 | |
| 187 #define COMPARE_FIELD_TYPE_VALUES(value) \ | |
|
Primiano Tucci (use gerrit)
2016/09/01 16:18:06
nit: don't indent defines
| |
| 188 EXPECT_EQ( \ | |
| 189 static_cast<int>(google::protobuf::FieldDescriptor::Type::value), \ | |
| 190 static_cast<int>(ProtoFieldDescriptor::Type::value)) | |
| 191 | |
| 192 COMPARE_FIELD_TYPE_VALUES(TYPE_DOUBLE); | |
| 193 COMPARE_FIELD_TYPE_VALUES(TYPE_FLOAT); | |
| 194 COMPARE_FIELD_TYPE_VALUES(TYPE_INT64); | |
| 195 COMPARE_FIELD_TYPE_VALUES(TYPE_UINT64); | |
| 196 COMPARE_FIELD_TYPE_VALUES(TYPE_INT32); | |
| 197 COMPARE_FIELD_TYPE_VALUES(TYPE_FIXED64); | |
| 198 COMPARE_FIELD_TYPE_VALUES(TYPE_FIXED32); | |
| 199 COMPARE_FIELD_TYPE_VALUES(TYPE_BOOL); | |
| 200 COMPARE_FIELD_TYPE_VALUES(TYPE_STRING); | |
| 201 COMPARE_FIELD_TYPE_VALUES(TYPE_MESSAGE); | |
| 202 COMPARE_FIELD_TYPE_VALUES(TYPE_BYTES); | |
| 203 COMPARE_FIELD_TYPE_VALUES(TYPE_UINT32); | |
| 204 COMPARE_FIELD_TYPE_VALUES(TYPE_ENUM); | |
| 205 COMPARE_FIELD_TYPE_VALUES(TYPE_SFIXED32); | |
| 206 COMPARE_FIELD_TYPE_VALUES(TYPE_SFIXED64); | |
| 207 COMPARE_FIELD_TYPE_VALUES(TYPE_SINT32); | |
| 208 COMPARE_FIELD_TYPE_VALUES(TYPE_SINT64); | |
| 209 | |
| 210 #undef COMPARE_FIELD_TYPE_VALUES | |
|
Primiano Tucci (use gerrit)
2016/09/01 16:18:06
ditto, remove trailing spaces.
| |
| 169 } | 211 } |
| 170 | 212 |
| 171 } // namespace proto | 213 } // namespace proto |
| 172 } // namespace tracing | 214 } // namespace tracing |
| OLD | NEW |