Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: mojo/public/cpp/bindings/tests/struct_unittest.cc

Issue 1475813002: Mojo C++ bindings: support passing associated interface pointers/requests in method parameter lists… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@25_use_multiplex_router
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <string.h> 5 #include <string.h>
6 6
7 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" 7 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
8 #include "mojo/public/cpp/system/message_pipe.h" 8 #include "mojo/public/cpp/system/message_pipe.h"
9 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h" 9 #include "mojo/public/interfaces/bindings/tests/test_structs.mojom.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 // Set the subsequent area to a special value, so that we can find out if we 61 // Set the subsequent area to a special value, so that we can find out if we
62 // mistakenly access the area. 62 // mistakenly access the area.
63 void* subsequent_area = buf.Allocate(32); 63 void* subsequent_area = buf.Allocate(32);
64 memset(subsequent_area, 0xAA, 32); 64 memset(subsequent_area, 0xAA, 32);
65 65
66 OutputDataType output_data = reinterpret_cast<OutputDataType>(data); 66 OutputDataType output_data = reinterpret_cast<OutputDataType>(data);
67 output_data->DecodePointersAndHandles(&handles); 67 output_data->DecodePointersAndHandles(&handles);
68 68
69 U output; 69 U output;
70 Deserialize_(output_data, &output); 70 Deserialize_(output_data, &output, nullptr);
71 return output.Pass(); 71 return output.Pass();
72 } 72 }
73 73
74 using StructTest = testing::Test; 74 using StructTest = testing::Test;
75 75
76 } // namespace 76 } // namespace
77 77
78 TEST_F(StructTest, Rect) { 78 TEST_F(StructTest, Rect) {
79 RectPtr rect; 79 RectPtr rect;
80 EXPECT_TRUE(rect.is_null()); 80 EXPECT_TRUE(rect.is_null());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 RectPtr rect(MakeRect()); 132 RectPtr rect(MakeRect());
133 133
134 size_t size = GetSerializedSize_(rect); 134 size_t size = GetSerializedSize_(rect);
135 EXPECT_EQ(8U + 16U, size); 135 EXPECT_EQ(8U + 16U, size);
136 136
137 mojo::internal::FixedBufferForTesting buf(size); 137 mojo::internal::FixedBufferForTesting buf(size);
138 internal::Rect_Data* data; 138 internal::Rect_Data* data;
139 Serialize_(rect.Pass(), &buf, &data); 139 Serialize_(rect.Pass(), &buf, &data);
140 140
141 RectPtr rect2; 141 RectPtr rect2;
142 Deserialize_(data, &rect2); 142 Deserialize_(data, &rect2, nullptr);
143 143
144 CheckRect(*rect2); 144 CheckRect(*rect2);
145 } 145 }
146 146
147 // Construction of a struct with struct pointers from null. 147 // Construction of a struct with struct pointers from null.
148 TEST_F(StructTest, Construction_StructPointers) { 148 TEST_F(StructTest, Construction_StructPointers) {
149 RectPairPtr pair; 149 RectPairPtr pair;
150 EXPECT_TRUE(pair.is_null()); 150 EXPECT_TRUE(pair.is_null());
151 151
152 pair = RectPair::New(); 152 pair = RectPair::New();
(...skipping 12 matching lines...) Expand all
165 pair->second = MakeRect(); 165 pair->second = MakeRect();
166 166
167 size_t size = GetSerializedSize_(pair); 167 size_t size = GetSerializedSize_(pair);
168 EXPECT_EQ(8U + 16U + 2 * (8U + 16U), size); 168 EXPECT_EQ(8U + 16U + 2 * (8U + 16U), size);
169 169
170 mojo::internal::FixedBufferForTesting buf(size); 170 mojo::internal::FixedBufferForTesting buf(size);
171 internal::RectPair_Data* data; 171 internal::RectPair_Data* data;
172 Serialize_(pair.Pass(), &buf, &data); 172 Serialize_(pair.Pass(), &buf, &data);
173 173
174 RectPairPtr pair2; 174 RectPairPtr pair2;
175 Deserialize_(data, &pair2); 175 Deserialize_(data, &pair2, nullptr);
176 176
177 CheckRect(*pair2->first); 177 CheckRect(*pair2->first);
178 CheckRect(*pair2->second); 178 CheckRect(*pair2->second);
179 } 179 }
180 180
181 // Serialization test of a struct with an array member. 181 // Serialization test of a struct with an array member.
182 TEST_F(StructTest, Serialization_ArrayPointers) { 182 TEST_F(StructTest, Serialization_ArrayPointers) {
183 NamedRegionPtr region(NamedRegion::New()); 183 NamedRegionPtr region(NamedRegion::New());
184 region->name = "region"; 184 region->name = "region";
185 region->rects = Array<RectPtr>::New(4); 185 region->rects = Array<RectPtr>::New(4);
(...skipping 10 matching lines...) Expand all
196 4 * 8U + // rects payload (four pointers) 196 4 * 8U + // rects payload (four pointers)
197 4 * (8U + // rect header 197 4 * (8U + // rect header
198 16U), // rect payload (four ints) 198 16U), // rect payload (four ints)
199 size); 199 size);
200 200
201 mojo::internal::FixedBufferForTesting buf(size); 201 mojo::internal::FixedBufferForTesting buf(size);
202 internal::NamedRegion_Data* data; 202 internal::NamedRegion_Data* data;
203 Serialize_(region.Pass(), &buf, &data); 203 Serialize_(region.Pass(), &buf, &data);
204 204
205 NamedRegionPtr region2; 205 NamedRegionPtr region2;
206 Deserialize_(data, &region2); 206 Deserialize_(data, &region2, nullptr);
207 207
208 EXPECT_EQ(String("region"), region2->name); 208 EXPECT_EQ(String("region"), region2->name);
209 209
210 EXPECT_EQ(4U, region2->rects.size()); 210 EXPECT_EQ(4U, region2->rects.size());
211 for (size_t i = 0; i < region2->rects.size(); ++i) 211 for (size_t i = 0; i < region2->rects.size(); ++i)
212 CheckRect(*region2->rects[i], static_cast<int32_t>(i) + 1); 212 CheckRect(*region2->rects[i], static_cast<int32_t>(i) + 1);
213 } 213 }
214 214
215 // Serialization test of a struct with null array pointers. 215 // Serialization test of a struct with null array pointers.
216 TEST_F(StructTest, Serialization_NullArrayPointers) { 216 TEST_F(StructTest, Serialization_NullArrayPointers) {
217 NamedRegionPtr region(NamedRegion::New()); 217 NamedRegionPtr region(NamedRegion::New());
218 EXPECT_TRUE(region->name.is_null()); 218 EXPECT_TRUE(region->name.is_null());
219 EXPECT_TRUE(region->rects.is_null()); 219 EXPECT_TRUE(region->rects.is_null());
220 220
221 size_t size = GetSerializedSize_(region); 221 size_t size = GetSerializedSize_(region);
222 EXPECT_EQ(8U + // header 222 EXPECT_EQ(8U + // header
223 8U + // name pointer 223 8U + // name pointer
224 8U, // rects pointer 224 8U, // rects pointer
225 size); 225 size);
226 226
227 mojo::internal::FixedBufferForTesting buf(size); 227 mojo::internal::FixedBufferForTesting buf(size);
228 internal::NamedRegion_Data* data; 228 internal::NamedRegion_Data* data;
229 Serialize_(region.Pass(), &buf, &data); 229 Serialize_(region.Pass(), &buf, &data);
230 230
231 NamedRegionPtr region2; 231 NamedRegionPtr region2;
232 Deserialize_(data, &region2); 232 Deserialize_(data, &region2, nullptr);
233 233
234 EXPECT_TRUE(region2->name.is_null()); 234 EXPECT_TRUE(region2->name.is_null());
235 EXPECT_TRUE(region2->rects.is_null()); 235 EXPECT_TRUE(region2->rects.is_null());
236 } 236 }
237 237
238 // Tests deserializing structs as a newer version. 238 // Tests deserializing structs as a newer version.
239 TEST_F(StructTest, Versioning_OldToNew) { 239 TEST_F(StructTest, Versioning_OldToNew) {
240 { 240 {
241 MultiVersionStructV0Ptr input(MultiVersionStructV0::New()); 241 MultiVersionStructV0Ptr input(MultiVersionStructV0::New());
242 input->f_int32 = 123; 242 input->f_int32 = 123;
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 expected_output->f_int32 = 123; 406 expected_output->f_int32 = 123;
407 407
408 MultiVersionStructV0Ptr output = 408 MultiVersionStructV0Ptr output =
409 SerializeAndDeserialize<MultiVersionStructV0Ptr>(input.Pass()); 409 SerializeAndDeserialize<MultiVersionStructV0Ptr>(input.Pass());
410 EXPECT_TRUE(output); 410 EXPECT_TRUE(output);
411 EXPECT_TRUE(output->Equals(*expected_output)); 411 EXPECT_TRUE(output->Equals(*expected_output));
412 } 412 }
413 } 413 }
414 } // namespace test 414 } // namespace test
415 } // namespace mojo 415 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/map_unittest.cc ('k') | mojo/public/cpp/bindings/tests/union_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698