| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/tracing/proto_zero_test/fake_runtime.h" |
| 6 #include "components/tracing/proto_zero_test/mock_messages.zeropb.h" |
| 7 |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace tracing { |
| 11 namespace proto { |
| 12 namespace { |
| 13 |
| 14 #define EXPECT_EVAL(expected, object, appender) \ |
| 15 object.appender; EXPECT_EQ(expected, object.GetLastCall()) |
| 16 |
| 17 using ::foo::bar::EveryField; |
| 18 using ::foo::bar::NestedA; |
| 19 using ::foo::bar::SmallEnum; |
| 20 using ::foo::bar::SignedEnum; |
| 21 using ::foo::bar::BigEnum; |
| 22 |
| 23 TEST(ProtoZeroTest, EveryField) { |
| 24 EveryField msg; |
| 25 EXPECT_EVAL("int32 f1 = -500", msg, set_field_int32(-500)); |
| 26 EXPECT_EVAL("int64 f2 = -5000000000", msg, set_field_int64(-5000000000)); |
| 27 EXPECT_EVAL("uint32 f3 = 600", msg, set_field_uint32(600)); |
| 28 EXPECT_EVAL("uint64 f4 = 6000000000", msg, set_field_uint64(6000000000)); |
| 29 EXPECT_EVAL("sint32 f5 = -700", msg, set_field_sint32(-700)); |
| 30 EXPECT_EVAL("sint64 f6 = -7000000000", msg, set_field_sint64(-7000000000)); |
| 31 EXPECT_EVAL("fixed32 f7 = 800", msg, set_field_fixed32(800)); |
| 32 EXPECT_EVAL("fixed64 f8 = 8000000000", msg, set_field_fixed64(8000000000)); |
| 33 EXPECT_EVAL("sfixed32 f9 = -900", msg, set_field_sfixed32(-900)); |
| 34 EXPECT_EVAL("sfixed64 f10 = -9000000000", msg, set_field_sfixed64(-9000000000)
); |
| 35 EXPECT_EVAL("float f11 = 1", msg, set_field_float(1)); |
| 36 EXPECT_EVAL("double f12 = 2", msg, set_field_double(2)); |
| 37 EXPECT_EVAL("bool f13 = true", msg, set_field_bool(true)); |
| 38 EXPECT_EVAL("string f500 = \"foo\"", msg, set_field_string("foo")); |
| 39 EXPECT_EVAL("bytes f505 = [3]", msg, set_field_bytes(nullptr, 3)); |
| 40 EXPECT_EVAL("int32 f999 = -8", msg, add_repeated_int32(-8)); |
| 41 EXPECT_EVAL("int32 f999 = -9", msg, add_repeated_int32(-9)); |
| 42 } |
| 43 |
| 44 TEST(ProtoZeroTest, Enums) { |
| 45 EveryField msg; |
| 46 EXPECT_EVAL("tiny f51 = 1", msg, set_small_enum(SmallEnum::TO_BE)); |
| 47 EXPECT_EVAL("int32 f52 = 0", msg, set_signed_enum(SignedEnum::NEUTRAL)); |
| 48 EXPECT_EVAL("int32 f53 = 10", msg, set_big_enum(BigEnum::BEGIN)); |
| 49 EXPECT_EVAL("tiny f600 = 1", msg, set_nested_enum(EveryField::NestedEnum::PING
)); |
| 50 } |
| 51 |
| 52 TEST(ProtoZeroTest, NestedMessages) { |
| 53 NestedA msg_a; |
| 54 EXPECT_EVAL("message 2", msg_a, add_repeated_a()); |
| 55 EXPECT_TRUE(msg_a.add_repeated_a() != nullptr); |
| 56 NestedA::NestedB msg_b; |
| 57 EXPECT_EVAL("message 1", msg_b, set_value_b()); |
| 58 NestedA::NestedB::NestedC msg_c; |
| 59 EXPECT_EVAL("int32 f1 = 100", msg_c, set_value_c(100)); |
| 60 } |
| 61 |
| 62 } // namespace |
| 63 } // namespace proto |
| 64 } // namespace tracing |
| OLD | NEW |