| Index: mojo/public/cpp/bindings/tests/serialization_api_unittest.cc
|
| diff --git a/mojo/public/cpp/bindings/tests/serialization_api_unittest.cc b/mojo/public/cpp/bindings/tests/serialization_api_unittest.cc
|
| index 28ada48a0609dc46c2422c27d222d6870e346c70..addc4adf9ecd6a2df660d0eff17894c7ebe0a420 100644
|
| --- a/mojo/public/cpp/bindings/tests/serialization_api_unittest.cc
|
| +++ b/mojo/public/cpp/bindings/tests/serialization_api_unittest.cc
|
| @@ -37,11 +37,13 @@ class StructSerializationAPITest : public testing::Test {
|
| Type::Data_::Validate(bytes.data(), &bounds_checker, nullptr);
|
| EXPECT_EQ(expected_validation_error, actual_validation_error);
|
|
|
| + Type out_val;
|
| + auto deserialize_ret = out_val.Deserialize(bytes.data(), bytes.size());
|
| if (actual_validation_error == mojo::internal::ValidationError::NONE) {
|
| - Type out_val;
|
| - out_val.Deserialize(bytes.data());
|
| EXPECT_TRUE(val->Equals(out_val));
|
| }
|
| + EXPECT_EQ(actual_validation_error == mojo::internal::ValidationError::NONE,
|
| + deserialize_ret);
|
| }
|
|
|
| private:
|
| @@ -142,6 +144,24 @@ TEST_F(StructSerializationAPITest, NullableHandleSerialization) {
|
| mojo::internal::ValidationError::NONE);
|
| }
|
|
|
| +TEST_F(StructSerializationAPITest, DeserializationFailure) {
|
| + void* buf[100];
|
| + EmptyStruct es;
|
| +
|
| + // Bounds checker should fail this, since buf_size is too small.
|
| + EXPECT_FALSE(es.Deserialize(buf, 1));
|
| +
|
| + es.Serialize(buf, sizeof(buf));
|
| + EXPECT_TRUE(es.Deserialize(buf, sizeof(buf)));
|
| +
|
| + // Invalid struct header: this should happen inside
|
| + // EmptyStruct::Data_::Validate()).
|
| + es.Serialize(buf, sizeof(buf));
|
| + EmptyStruct::Data_* es_data = reinterpret_cast<EmptyStruct::Data_*>(buf);
|
| + es_data->header_.num_bytes = 0;
|
| + EXPECT_FALSE(es.Deserialize(buf, sizeof(buf)));
|
| +}
|
| +
|
| } // namespace
|
| } // namespace test
|
| } // namespace mojo
|
|
|