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

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

Issue 659313006: mojo: Fix c++ bindings so serialization of empty arrays doesn't crash. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: Created 6 years, 2 months 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
« no previous file with comments | « mojo/public/cpp/bindings/lib/array_serialization.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "mojo/public/cpp/bindings/array.h" 5 #include "mojo/public/cpp/bindings/array.h"
6 #include "mojo/public/cpp/bindings/lib/array_internal.h" 6 #include "mojo/public/cpp/bindings/lib/array_internal.h"
7 #include "mojo/public/cpp/bindings/lib/array_serialization.h" 7 #include "mojo/public/cpp/bindings/lib/array_serialization.h"
8 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h" 8 #include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
9 #include "mojo/public/cpp/bindings/tests/container_test_util.h" 9 #include "mojo/public/cpp/bindings/tests/container_test_util.h"
10 #include "mojo/public/cpp/environment/environment.h" 10 #include "mojo/public/cpp/environment/environment.h"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 array.Pass(), &buf, &data); 164 array.Pass(), &buf, &data);
165 165
166 Array<int32_t> array2; 166 Array<int32_t> array2;
167 Deserialize_(data, &array2); 167 Deserialize_(data, &array2);
168 168
169 EXPECT_EQ(4U, array2.size()); 169 EXPECT_EQ(4U, array2.size());
170 for (size_t i = 0; i < array2.size(); ++i) 170 for (size_t i = 0; i < array2.size(); ++i)
171 EXPECT_EQ(static_cast<int32_t>(i), array2[i]); 171 EXPECT_EQ(static_cast<int32_t>(i), array2[i]);
172 } 172 }
173 173
174 TEST_F(ArrayTest, Serialization_EmptyArrayOfPOD) {
175 Array<int32_t> array(0);
176 size_t size = GetSerializedSize_(array);
177 EXPECT_EQ(8U, size);
178
179 FixedBuffer buf(size);
180 Array_Data<int32_t>* data;
181 SerializeArray_<ArrayValidateParams<0, false, NoValidateParams>>(
182 array.Pass(), &buf, &data);
183
184 Array<int32_t> array2;
185 Deserialize_(data, &array2);
186 EXPECT_EQ(0U, array2.size());
187 }
188
174 TEST_F(ArrayTest, Serialization_ArrayOfArrayOfPOD) { 189 TEST_F(ArrayTest, Serialization_ArrayOfArrayOfPOD) {
175 Array<Array<int32_t>> array(2); 190 Array<Array<int32_t>> array(2);
176 for (size_t j = 0; j < array.size(); ++j) { 191 for (size_t j = 0; j < array.size(); ++j) {
177 Array<int32_t> inner(4); 192 Array<int32_t> inner(4);
178 for (size_t i = 0; i < inner.size(); ++i) 193 for (size_t i = 0; i < inner.size(); ++i)
179 inner[i] = static_cast<int32_t>(i + (j * 10)); 194 inner[i] = static_cast<int32_t>(i + (j * 10));
180 array[j] = inner.Pass(); 195 array[j] = inner.Pass();
181 } 196 }
182 197
183 size_t size = GetSerializedSize_(array); 198 size_t size = GetSerializedSize_(array);
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 EXPECT_TRUE(array[i].moved()); 441 EXPECT_TRUE(array[i].moved());
427 EXPECT_EQ(value_ptrs[i], array[i].ptr()); 442 EXPECT_EQ(value_ptrs[i], array[i].ptr());
428 } 443 }
429 array.reset(); 444 array.reset();
430 EXPECT_EQ(0u, MoveOnlyType::num_instances()); 445 EXPECT_EQ(0u, MoveOnlyType::num_instances());
431 } 446 }
432 447
433 } // namespace 448 } // namespace
434 } // namespace test 449 } // namespace test
435 } // namespace mojo 450 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/array_serialization.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698