Chromium Code Reviews| Index: mojo/public/cpp/bindings/tests/union_unittest.cc |
| diff --git a/mojo/public/cpp/bindings/tests/union_unittest.cc b/mojo/public/cpp/bindings/tests/union_unittest.cc |
| index 6124d275f2c422c96eb52183ac1cb8acfaca96dd..ff7a355a8d517c6988d605c9ad7cbc01f1f1b796 100644 |
| --- a/mojo/public/cpp/bindings/tests/union_unittest.cc |
| +++ b/mojo/public/cpp/bindings/tests/union_unittest.cc |
| @@ -2,6 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include <vector> |
| #include "mojo/public/cpp/bindings/array.h" |
| #include "mojo/public/cpp/bindings/lib/array_internal.h" |
| #include "mojo/public/cpp/bindings/lib/array_serialization.h" |
| @@ -679,5 +680,140 @@ TEST(UnionTest, StructInUnionValidationNullable) { |
| internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, false)); |
| } |
| +TEST(UnionTest, ArrayInUnionGetterSetter) { |
| + Environment environment; |
| + |
| + Array<int8_t> array(2); |
| + array[0] = 8; |
| + array[1] = 9; |
| + |
| + ObjectUnionPtr obj(ObjectUnion::New()); |
| + obj->set_f_array_int8(array.Pass()); |
| + |
| + EXPECT_EQ(8, obj->get_f_array_int8()[0]); |
| + EXPECT_EQ(9, obj->get_f_array_int8()[1]); |
| +} |
| + |
| +TEST(UnionTest, ArrayInUnionSerialization) { |
| + Environment environment; |
| + |
| + Array<int8_t> array(2); |
| + array[0] = 8; |
| + array[1] = 9; |
| + |
| + ObjectUnionPtr obj(ObjectUnion::New()); |
| + obj->set_f_array_int8(array.Pass()); |
| + |
| + size_t size = GetSerializedSize_(obj, false); |
| + EXPECT_EQ(32U, size); |
| + |
| + mojo::internal::FixedBuffer buf(size); |
| + internal::ObjectUnion_Data* data = nullptr; |
| + SerializeUnion_(obj.Pass(), &buf, &data, false); |
| + |
| + std::vector<Handle> handles; |
| + data->EncodePointersAndHandles(&handles); |
| + data->DecodePointersAndHandles(&handles); |
| + |
| + ObjectUnionPtr obj2; |
| + Deserialize_(data, &obj2); |
| + |
| + EXPECT_EQ(8, obj2->get_f_array_int8()[0]); |
| + EXPECT_EQ(9, obj2->get_f_array_int8()[1]); |
| +} |
| + |
| +TEST(UnionTest, ArrayInUnionValidation) { |
| + Environment environment; |
| + |
| + Array<int8_t> array(2); |
| + array[0] = 8; |
| + array[1] = 9; |
| + |
| + ObjectUnionPtr obj(ObjectUnion::New()); |
| + obj->set_f_array_int8(array.Pass()); |
| + |
| + size_t size = GetSerializedSize_(obj, false); |
| + mojo::internal::FixedBuffer buf(size); |
| + internal::ObjectUnion_Data* data = nullptr; |
| + SerializeUnion_(obj.Pass(), &buf, &data, false); |
| + |
| + std::vector<Handle> handles; |
| + data->EncodePointersAndHandles(&handles); |
| + |
| + void* raw_buf = buf.Leak(); |
|
yzshen1
2015/04/21 16:39:14
Please dispose it properly.
azani
2015/04/21 17:43:33
Done.
|
| + mojo::internal::BoundsChecker bounds_checker(data, |
| + static_cast<uint32_t>(size), 0); |
| + |
| + EXPECT_TRUE( |
| + internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, false)); |
| +} |
| + |
| +TEST(UnionTest, MapInUnionGetterSetter) { |
| + Environment environment; |
| + Map<String, int8_t> map; |
| + map.insert("one", 1); |
| + map.insert("two", 2); |
| + |
| + ObjectUnionPtr obj(ObjectUnion::New()); |
| + obj->set_f_map_int8(map.Pass()); |
| + |
| + EXPECT_EQ(1, obj->get_f_map_int8()["one"]); |
| + EXPECT_EQ(2, obj->get_f_map_int8()["two"]); |
| +} |
| + |
| +TEST(UnionTest, MapInUnionSerialization) { |
| + Environment environment; |
| + Map<String, int8_t> map; |
| + map.insert("one", 1); |
| + map.insert("two", 2); |
| + |
| + ObjectUnionPtr obj(ObjectUnion::New()); |
| + obj->set_f_map_int8(map.Pass()); |
| + |
| + size_t size = GetSerializedSize_(obj, false); |
| + EXPECT_EQ(112U, size); |
| + |
| + mojo::internal::FixedBuffer buf(size); |
| + internal::ObjectUnion_Data* data = nullptr; |
| + SerializeUnion_(obj.Pass(), &buf, &data, false); |
| + |
| + std::vector<Handle> handles; |
| + data->EncodePointersAndHandles(&handles); |
| + data->DecodePointersAndHandles(&handles); |
| + |
| + ObjectUnionPtr obj2; |
| + Deserialize_(data, &obj2); |
| + |
| + EXPECT_EQ(1, obj2->get_f_map_int8()["one"]); |
| + EXPECT_EQ(2, obj2->get_f_map_int8()["two"]); |
| +} |
| + |
| +TEST(UnionTest, MapInUnionValidation) { |
| + Environment environment; |
| + Map<String, int8_t> map; |
| + map.insert("one", 1); |
| + map.insert("two", 2); |
| + |
| + ObjectUnionPtr obj(ObjectUnion::New()); |
| + obj->set_f_map_int8(map.Pass()); |
| + |
| + size_t size = GetSerializedSize_(obj, false); |
| + EXPECT_EQ(112U, size); |
| + |
| + mojo::internal::FixedBuffer buf(size); |
| + internal::ObjectUnion_Data* data = nullptr; |
| + SerializeUnion_(obj.Pass(), &buf, &data, false); |
| + |
| + std::vector<Handle> handles; |
| + data->EncodePointersAndHandles(&handles); |
| + |
| + void* raw_buf = buf.Leak(); |
|
yzshen1
2015/04/21 16:39:14
ditto.
azani
2015/04/21 17:43:33
Done.
|
| + mojo::internal::BoundsChecker bounds_checker(data, |
| + static_cast<uint32_t>(size), 0); |
| + |
| + EXPECT_TRUE( |
| + internal::ObjectUnion_Data::Validate(raw_buf, &bounds_checker, false)); |
| +} |
| + |
| } // namespace test |
| } // namespace mojo |