| OLD | NEW |
| 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 // Serialization warnings are only recorded in debug build. | 5 // Serialization warnings are only recorded in debug build. |
| 6 #ifndef NDEBUG | 6 #ifndef NDEBUG |
| 7 | 7 |
| 8 #include "mojo/public/cpp/bindings/array.h" | 8 #include "mojo/public/cpp/bindings/array.h" |
| 9 #include "mojo/public/cpp/bindings/lib/array_internal.h" | 9 #include "mojo/public/cpp/bindings/lib/array_internal.h" |
| 10 #include "mojo/public/cpp/bindings/lib/array_serialization.h" | 10 #include "mojo/public/cpp/bindings/lib/array_serialization.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 template <typename T> | 51 template <typename T> |
| 52 void TestWarning(InlinedStructPtr<T> obj, | 52 void TestWarning(InlinedStructPtr<T> obj, |
| 53 mojo::internal::ValidationError expected_warning) { | 53 mojo::internal::ValidationError expected_warning) { |
| 54 TestStructWarningImpl<T>(obj.Pass(), expected_warning); | 54 TestStructWarningImpl<T>(obj.Pass(), expected_warning); |
| 55 } | 55 } |
| 56 | 56 |
| 57 template <typename T, typename TPtr> | 57 template <typename T, typename TPtr> |
| 58 void TestStructWarningImpl(TPtr obj, | 58 void TestStructWarningImpl(TPtr obj, |
| 59 mojo::internal::ValidationError expected_warning) { | 59 mojo::internal::ValidationError expected_warning) { |
| 60 warning_observer_.set_last_warning(mojo::internal::VALIDATION_ERROR_NONE); | |
| 61 | |
| 62 mojo::internal::FixedBufferForTesting buf(GetSerializedSize_(*obj)); | 60 mojo::internal::FixedBufferForTesting buf(GetSerializedSize_(*obj)); |
| 63 typename T::Data_* data; | 61 typename T::Data_* data; |
| 64 Serialize_(obj.get(), &buf, &data); | 62 EXPECT_EQ(expected_warning, Serialize_(obj.get(), &buf, &data)); |
| 65 | |
| 66 EXPECT_EQ(expected_warning, warning_observer_.last_warning()); | |
| 67 } | 63 } |
| 68 | 64 |
| 69 template <typename T> | 65 template <typename T> |
| 70 void TestArrayWarning(T obj, | 66 void TestArrayWarning(T obj, |
| 71 mojo::internal::ValidationError expected_warning, | 67 mojo::internal::ValidationError expected_warning, |
| 72 const ArrayValidateParams* validate_params) { | 68 const ArrayValidateParams* validate_params) { |
| 73 warning_observer_.set_last_warning(mojo::internal::VALIDATION_ERROR_NONE); | |
| 74 | |
| 75 mojo::internal::FixedBufferForTesting buf(GetSerializedSize_(obj)); | 69 mojo::internal::FixedBufferForTesting buf(GetSerializedSize_(obj)); |
| 76 typename T::Data_* data; | 70 typename T::Data_* data; |
| 77 SerializeArray_(&obj, &buf, &data, validate_params); | 71 EXPECT_EQ(expected_warning, |
| 78 | 72 SerializeArray_(&obj, &buf, &data, validate_params)); |
| 79 EXPECT_EQ(expected_warning, warning_observer_.last_warning()); | |
| 80 } | 73 } |
| 81 | 74 |
| 82 mojo::internal::SerializationWarningObserverForTesting warning_observer_; | |
| 83 Environment env_; | 75 Environment env_; |
| 84 }; | 76 }; |
| 85 | 77 |
| 86 TEST_F(SerializationWarningTest, HandleInStruct) { | 78 TEST_F(SerializationWarningTest, HandleInStruct) { |
| 87 Struct2Ptr test_struct(Struct2::New()); | 79 Struct2Ptr test_struct(Struct2::New()); |
| 88 EXPECT_FALSE(test_struct->hdl.is_valid()); | 80 EXPECT_FALSE(test_struct->hdl.is_valid()); |
| 89 | 81 |
| 90 TestWarning(test_struct.Pass(), | 82 TestWarning(test_struct.Pass(), |
| 91 mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE); | 83 mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE); |
| 92 | 84 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 TestArrayWarning(test_array.Pass(), | 212 TestArrayWarning(test_array.Pass(), |
| 221 mojo::internal::VALIDATION_ERROR_UNEXPECTED_ARRAY_HEADER, | 213 mojo::internal::VALIDATION_ERROR_UNEXPECTED_ARRAY_HEADER, |
| 222 &validate_params_2); | 214 &validate_params_2); |
| 223 } | 215 } |
| 224 | 216 |
| 225 } // namespace | 217 } // namespace |
| 226 } // namespace test | 218 } // namespace test |
| 227 } // namespace mojo | 219 } // namespace mojo |
| 228 | 220 |
| 229 #endif | 221 #endif |
| OLD | NEW |