OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/common/safe_browsing/ipc_protobuf_message_test.pb.h" | 5 #include "chrome/common/safe_browsing/ipc_protobuf_message_test.pb.h" |
6 #include "ipc/ipc_message.h" | 6 #include "ipc/ipc_message.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 #define IPC_MESSAGE_IMPL | 9 #define IPC_MESSAGE_IMPL |
10 #include "chrome/common/safe_browsing/ipc_protobuf_message_test_messages.h" | 10 #include "chrome/common/safe_browsing/ipc_protobuf_message_test_messages.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 TEST_P(IPCProtobufMessageTest, FundamentalField) { | 38 TEST_P(IPCProtobufMessageTest, FundamentalField) { |
39 TestMessage input; | 39 TestMessage input; |
40 | 40 |
41 if (field_is_present_) | 41 if (field_is_present_) |
42 input.set_fund_int(42); | 42 input.set_fund_int(42); |
43 | 43 |
44 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 44 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
45 IPC::WriteParam(&msg, input); | 45 IPC::WriteParam(&msg, input); |
46 | 46 |
47 TestMessage output; | 47 TestMessage output; |
48 PickleIterator iter(msg); | 48 base::PickleIterator iter(msg); |
49 ASSERT_TRUE(IPC::ReadParam(&msg, &iter, &output)); | 49 ASSERT_TRUE(IPC::ReadParam(&msg, &iter, &output)); |
50 | 50 |
51 if (field_is_present_) { | 51 if (field_is_present_) { |
52 ASSERT_TRUE(output.has_fund_int()); | 52 ASSERT_TRUE(output.has_fund_int()); |
53 EXPECT_EQ(input.fund_int(), output.fund_int()); | 53 EXPECT_EQ(input.fund_int(), output.fund_int()); |
54 } else { | 54 } else { |
55 ASSERT_FALSE(output.has_fund_int()); | 55 ASSERT_FALSE(output.has_fund_int()); |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 // Tests writing and reading a message with an optional string field. | 59 // Tests writing and reading a message with an optional string field. |
60 TEST_P(IPCProtobufMessageTest, StringField) { | 60 TEST_P(IPCProtobufMessageTest, StringField) { |
61 TestMessage input; | 61 TestMessage input; |
62 | 62 |
63 if (field_is_present_) | 63 if (field_is_present_) |
64 input.set_op_comp_string("some string"); | 64 input.set_op_comp_string("some string"); |
65 | 65 |
66 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 66 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
67 IPC::WriteParam(&msg, input); | 67 IPC::WriteParam(&msg, input); |
68 | 68 |
69 TestMessage output; | 69 TestMessage output; |
70 PickleIterator iter(msg); | 70 base::PickleIterator iter(msg); |
71 ASSERT_TRUE(IPC::ReadParam(&msg, &iter, &output)); | 71 ASSERT_TRUE(IPC::ReadParam(&msg, &iter, &output)); |
72 | 72 |
73 if (field_is_present_) { | 73 if (field_is_present_) { |
74 ASSERT_TRUE(output.has_op_comp_string()); | 74 ASSERT_TRUE(output.has_op_comp_string()); |
75 EXPECT_EQ(input.op_comp_string(), output.op_comp_string()); | 75 EXPECT_EQ(input.op_comp_string(), output.op_comp_string()); |
76 } else { | 76 } else { |
77 ASSERT_FALSE(output.has_op_comp_string()); | 77 ASSERT_FALSE(output.has_op_comp_string()); |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 // Tests writing and reading a message with an optional bytes field. | 81 // Tests writing and reading a message with an optional bytes field. |
82 TEST_P(IPCProtobufMessageTest, BytesField) { | 82 TEST_P(IPCProtobufMessageTest, BytesField) { |
83 TestMessage input; | 83 TestMessage input; |
84 | 84 |
85 if (field_is_present_) | 85 if (field_is_present_) |
86 input.set_op_comp_bytes("some string"); | 86 input.set_op_comp_bytes("some string"); |
87 | 87 |
88 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 88 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
89 IPC::WriteParam(&msg, input); | 89 IPC::WriteParam(&msg, input); |
90 | 90 |
91 TestMessage output; | 91 TestMessage output; |
92 PickleIterator iter(msg); | 92 base::PickleIterator iter(msg); |
93 ASSERT_TRUE(IPC::ReadParam(&msg, &iter, &output)); | 93 ASSERT_TRUE(IPC::ReadParam(&msg, &iter, &output)); |
94 | 94 |
95 if (field_is_present_) { | 95 if (field_is_present_) { |
96 ASSERT_TRUE(output.has_op_comp_bytes()); | 96 ASSERT_TRUE(output.has_op_comp_bytes()); |
97 EXPECT_EQ(input.op_comp_bytes(), output.op_comp_bytes()); | 97 EXPECT_EQ(input.op_comp_bytes(), output.op_comp_bytes()); |
98 } else { | 98 } else { |
99 ASSERT_FALSE(output.has_op_comp_bytes()); | 99 ASSERT_FALSE(output.has_op_comp_bytes()); |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 // Tests writing and reading a message with an optional submessage field. | 103 // Tests writing and reading a message with an optional submessage field. |
104 TEST_P(IPCProtobufMessageTest, OptionalSubmessage) { | 104 TEST_P(IPCProtobufMessageTest, OptionalSubmessage) { |
105 TestMessage input; | 105 TestMessage input; |
106 | 106 |
107 if (field_is_present_) | 107 if (field_is_present_) |
108 input.mutable_op_comp_sub()->set_foo(47); | 108 input.mutable_op_comp_sub()->set_foo(47); |
109 | 109 |
110 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 110 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
111 IPC::WriteParam(&msg, input); | 111 IPC::WriteParam(&msg, input); |
112 | 112 |
113 TestMessage output; | 113 TestMessage output; |
114 PickleIterator iter(msg); | 114 base::PickleIterator iter(msg); |
115 ASSERT_TRUE(IPC::ReadParam(&msg, &iter, &output)); | 115 ASSERT_TRUE(IPC::ReadParam(&msg, &iter, &output)); |
116 | 116 |
117 if (field_is_present_) { | 117 if (field_is_present_) { |
118 ASSERT_TRUE(output.has_op_comp_sub()); | 118 ASSERT_TRUE(output.has_op_comp_sub()); |
119 ASSERT_TRUE(output.op_comp_sub().has_foo()); | 119 ASSERT_TRUE(output.op_comp_sub().has_foo()); |
120 EXPECT_EQ(input.op_comp_sub().foo(), output.op_comp_sub().foo()); | 120 EXPECT_EQ(input.op_comp_sub().foo(), output.op_comp_sub().foo()); |
121 } else { | 121 } else { |
122 ASSERT_FALSE(output.has_op_comp_sub()); | 122 ASSERT_FALSE(output.has_op_comp_sub()); |
123 } | 123 } |
124 } | 124 } |
125 | 125 |
126 // Tests writing and reading a message with a repeated submessage field. | 126 // Tests writing and reading a message with a repeated submessage field. |
127 TEST_P(IPCProtobufMessageTest, RepeatedSubmessage) { | 127 TEST_P(IPCProtobufMessageTest, RepeatedSubmessage) { |
128 TestMessage input; | 128 TestMessage input; |
129 | 129 |
130 if (field_is_present_) { | 130 if (field_is_present_) { |
131 input.add_rep_comp_sub()->set_foo(0); | 131 input.add_rep_comp_sub()->set_foo(0); |
132 input.add_rep_comp_sub()->set_foo(1); | 132 input.add_rep_comp_sub()->set_foo(1); |
133 input.add_rep_comp_sub()->set_foo(2); | 133 input.add_rep_comp_sub()->set_foo(2); |
134 } | 134 } |
135 | 135 |
136 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); | 136 IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); |
137 IPC::WriteParam(&msg, input); | 137 IPC::WriteParam(&msg, input); |
138 | 138 |
139 TestMessage output; | 139 TestMessage output; |
140 PickleIterator iter(msg); | 140 base::PickleIterator iter(msg); |
141 ASSERT_TRUE(IPC::ReadParam(&msg, &iter, &output)); | 141 ASSERT_TRUE(IPC::ReadParam(&msg, &iter, &output)); |
142 | 142 |
143 if (field_is_present_) { | 143 if (field_is_present_) { |
144 ASSERT_EQ(3, output.rep_comp_sub_size()); | 144 ASSERT_EQ(3, output.rep_comp_sub_size()); |
145 ASSERT_TRUE(output.rep_comp_sub(0).has_foo()); | 145 ASSERT_TRUE(output.rep_comp_sub(0).has_foo()); |
146 EXPECT_EQ(input.rep_comp_sub(0).foo(), output.rep_comp_sub(0).foo()); | 146 EXPECT_EQ(input.rep_comp_sub(0).foo(), output.rep_comp_sub(0).foo()); |
147 ASSERT_TRUE(output.rep_comp_sub(1).has_foo()); | 147 ASSERT_TRUE(output.rep_comp_sub(1).has_foo()); |
148 EXPECT_EQ(input.rep_comp_sub(1).foo(), output.rep_comp_sub(1).foo()); | 148 EXPECT_EQ(input.rep_comp_sub(1).foo(), output.rep_comp_sub(1).foo()); |
149 ASSERT_TRUE(output.rep_comp_sub(2).has_foo()); | 149 ASSERT_TRUE(output.rep_comp_sub(2).has_foo()); |
150 EXPECT_EQ(input.rep_comp_sub(2).foo(), output.rep_comp_sub(2).foo()); | 150 EXPECT_EQ(input.rep_comp_sub(2).foo(), output.rep_comp_sub(2).foo()); |
151 } else { | 151 } else { |
152 ASSERT_EQ(0, output.rep_comp_sub_size()); | 152 ASSERT_EQ(0, output.rep_comp_sub_size()); |
153 } | 153 } |
154 } | 154 } |
155 | 155 |
156 INSTANTIATE_TEST_CASE_P(IPCProtobufMessage, | 156 INSTANTIATE_TEST_CASE_P(IPCProtobufMessage, |
157 IPCProtobufMessageTest, | 157 IPCProtobufMessageTest, |
158 ::testing::Bool()); | 158 ::testing::Bool()); |
OLD | NEW |