Chromium Code Reviews| Index: components/tracing/test/proto_zero_generation_unittest.cc |
| diff --git a/components/tracing/test/proto_zero_generation_unittest.cc b/components/tracing/test/proto_zero_generation_unittest.cc |
| index 715b91fa26fb023f98867583b1fea75cb2772213..ecb75cc5db92ddfbe9edbb04fbdd041e0b1c386a 100644 |
| --- a/components/tracing/test/proto_zero_generation_unittest.cc |
| +++ b/components/tracing/test/proto_zero_generation_unittest.cc |
| @@ -12,6 +12,7 @@ |
| #include "components/tracing/test/example_proto/test_messages.pbzero.h" |
| #include "components/tracing/test/fake_scattered_buffer.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#include "third_party/protobuf/src/google/protobuf/descriptor.h" |
| namespace tracing { |
| namespace proto { |
| @@ -24,6 +25,7 @@ using tracing::v2::ProtoZeroMessage; |
| using tracing::v2::ScatteredStreamWriter; |
| using tracing::v2::ProtoZeroMessageHandle; |
| using tracing::v2::ProtoZeroMessageHandleBase; |
| +using tracing::v2::proto::ProtoFieldDescriptor; |
| constexpr size_t kChunkSize = 42; |
| @@ -155,7 +157,7 @@ TEST(ProtoZeroTest, Simple) { |
| EXPECT_LE(0u, sizeof(pbtest::TrickyPublicImport)); |
| } |
| -TEST(ProtoZeroTest, FieldNumbers) { |
| +TEST(ProtoZeroTest, Reflection) { |
| // Tests camel case conversion as well. |
| EXPECT_EQ(1, pbtest::CamelCaseFields::kFooBarBazFieldNumber); |
| EXPECT_EQ(2, pbtest::CamelCaseFields::kBarBazFieldNumber); |
| @@ -166,6 +168,46 @@ TEST(ProtoZeroTest, FieldNumbers) { |
| EXPECT_EQ(7, pbtest::CamelCaseFields::kBigBangFieldNumber); |
| EXPECT_EQ(8, pbtest::CamelCaseFields::kU2FieldNumber); |
| EXPECT_EQ(9, pbtest::CamelCaseFields::kBangBigFieldNumber); |
| + |
| + const ProtoFieldDescriptor* reflection = |
| + pbtest::EveryField::GetFieldDescriptor( |
| + pbtest::EveryField::kFieldInt32FieldNumber); |
| + EXPECT_EQ("field_int32", reflection->name()); |
| + EXPECT_EQ(ProtoFieldDescriptor::Type::TYPE_INT32, reflection->type()); |
| + EXPECT_EQ(1u, reflection->number()); |
| + EXPECT_FALSE(reflection->is_repeated()); |
| + |
| + EXPECT_FALSE(pbtest::TransgalacticParcel::GetFieldDescriptor(42)->is_valid()); |
| +} |
| + |
| +TEST(ProtoZeroTest, GeneratorAssumptions) { |
| + // Generator plugin assumes that values of field types are equally defined |
| + // in protobuf compiler and in our proto utils. |
| + |
| + #define COMPARE_FIELD_TYPE_VALUES(value) \ |
|
Primiano Tucci (use gerrit)
2016/09/01 16:18:06
nit: don't indent defines
|
| + EXPECT_EQ( \ |
| + static_cast<int>(google::protobuf::FieldDescriptor::Type::value), \ |
| + static_cast<int>(ProtoFieldDescriptor::Type::value)) |
| + |
| + COMPARE_FIELD_TYPE_VALUES(TYPE_DOUBLE); |
| + COMPARE_FIELD_TYPE_VALUES(TYPE_FLOAT); |
| + COMPARE_FIELD_TYPE_VALUES(TYPE_INT64); |
| + COMPARE_FIELD_TYPE_VALUES(TYPE_UINT64); |
| + COMPARE_FIELD_TYPE_VALUES(TYPE_INT32); |
| + COMPARE_FIELD_TYPE_VALUES(TYPE_FIXED64); |
| + COMPARE_FIELD_TYPE_VALUES(TYPE_FIXED32); |
| + COMPARE_FIELD_TYPE_VALUES(TYPE_BOOL); |
| + COMPARE_FIELD_TYPE_VALUES(TYPE_STRING); |
| + COMPARE_FIELD_TYPE_VALUES(TYPE_MESSAGE); |
| + COMPARE_FIELD_TYPE_VALUES(TYPE_BYTES); |
| + COMPARE_FIELD_TYPE_VALUES(TYPE_UINT32); |
| + COMPARE_FIELD_TYPE_VALUES(TYPE_ENUM); |
| + COMPARE_FIELD_TYPE_VALUES(TYPE_SFIXED32); |
| + COMPARE_FIELD_TYPE_VALUES(TYPE_SFIXED64); |
| + COMPARE_FIELD_TYPE_VALUES(TYPE_SINT32); |
| + COMPARE_FIELD_TYPE_VALUES(TYPE_SINT64); |
| + |
| + #undef COMPARE_FIELD_TYPE_VALUES |
|
Primiano Tucci (use gerrit)
2016/09/01 16:18:06
ditto, remove trailing spaces.
|
| } |
| } // namespace proto |