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 #include <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
16 #include "mojo/public/c/system/macros.h" | 16 #include "mojo/public/c/system/macros.h" |
17 #include "mojo/public/cpp/bindings/binding.h" | 17 #include "mojo/public/cpp/bindings/binding.h" |
18 #include "mojo/public/cpp/bindings/connector.h" | 18 #include "mojo/public/cpp/bindings/connector.h" |
| 19 #include "mojo/public/cpp/bindings/filter_chain.h" |
19 #include "mojo/public/cpp/bindings/interface_ptr.h" | 20 #include "mojo/public/cpp/bindings/interface_ptr.h" |
20 #include "mojo/public/cpp/bindings/lib/filter_chain.h" | |
21 #include "mojo/public/cpp/bindings/lib/router.h" | 21 #include "mojo/public/cpp/bindings/lib/router.h" |
22 #include "mojo/public/cpp/bindings/lib/validation_errors.h" | 22 #include "mojo/public/cpp/bindings/lib/validation_errors.h" |
23 #include "mojo/public/cpp/bindings/message.h" | 23 #include "mojo/public/cpp/bindings/message.h" |
24 #include "mojo/public/cpp/bindings/message_header_validator.h" | 24 #include "mojo/public/cpp/bindings/message_header_validator.h" |
25 #include "mojo/public/cpp/bindings/tests/validation_test_input_parser.h" | 25 #include "mojo/public/cpp/bindings/tests/validation_test_input_parser.h" |
26 #include "mojo/public/cpp/system/core.h" | 26 #include "mojo/public/cpp/system/core.h" |
27 #include "mojo/public/cpp/test_support/test_support.h" | 27 #include "mojo/public/cpp/test_support/test_support.h" |
28 #include "mojo/public/interfaces/bindings/tests/validation_test_associated_inter
faces.mojom.h" | 28 #include "mojo/public/interfaces/bindings/tests/validation_test_associated_inter
faces.mojom.h" |
29 #include "mojo/public/interfaces/bindings/tests/validation_test_interfaces.mojom
.h" | 29 #include "mojo/public/interfaces/bindings/tests/validation_test_interfaces.mojom
.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 for (size_t i = 0; error_inputs[i]; ++i) { | 369 for (size_t i = 0; error_inputs[i]; ++i) { |
370 std::vector<uint8_t> expected; | 370 std::vector<uint8_t> expected; |
371 if (!TestInputParser(error_inputs[i], false, expected, 0)) | 371 if (!TestInputParser(error_inputs[i], false, expected, 0)) |
372 ADD_FAILURE() << "Unexpected test result for: " << error_inputs[i]; | 372 ADD_FAILURE() << "Unexpected test result for: " << error_inputs[i]; |
373 } | 373 } |
374 } | 374 } |
375 } | 375 } |
376 | 376 |
377 TEST_F(ValidationTest, Conformance) { | 377 TEST_F(ValidationTest, Conformance) { |
378 DummyMessageReceiver dummy_receiver; | 378 DummyMessageReceiver dummy_receiver; |
379 mojo::internal::FilterChain validators(&dummy_receiver); | 379 mojo::FilterChain validators(&dummy_receiver); |
380 validators.Append<mojo::MessageHeaderValidator>(); | 380 validators.Append<mojo::MessageHeaderValidator>(); |
381 validators.Append<ConformanceTestInterface::RequestValidator_>(); | 381 validators.Append<ConformanceTestInterface::RequestValidator_>(); |
382 | 382 |
383 RunValidationTests("conformance_", validators.GetHead()); | 383 RunValidationTests("conformance_", &validators); |
384 } | 384 } |
385 | 385 |
386 TEST_F(ValidationTest, AssociatedConformace) { | 386 TEST_F(ValidationTest, AssociatedConformace) { |
387 DummyMessageReceiver dummy_receiver; | 387 DummyMessageReceiver dummy_receiver; |
388 mojo::internal::FilterChain validators(&dummy_receiver); | 388 mojo::FilterChain validators(&dummy_receiver); |
389 validators.Append<mojo::MessageHeaderValidator>(); | 389 validators.Append<mojo::MessageHeaderValidator>(); |
390 validators.Append<AssociatedConformanceTestInterface::RequestValidator_>(); | 390 validators.Append<AssociatedConformanceTestInterface::RequestValidator_>(); |
391 | 391 |
392 RunValidationTests("associated_conformance_", validators.GetHead()); | 392 RunValidationTests("associated_conformance_", &validators); |
393 } | 393 } |
394 | 394 |
395 // This test is similar to Conformance test but its goal is specifically | 395 // This test is similar to Conformance test but its goal is specifically |
396 // do bounds-check testing of message validation. For example we test the | 396 // do bounds-check testing of message validation. For example we test the |
397 // detection of off-by-one errors in method ordinals. | 397 // detection of off-by-one errors in method ordinals. |
398 TEST_F(ValidationTest, BoundsCheck) { | 398 TEST_F(ValidationTest, BoundsCheck) { |
399 DummyMessageReceiver dummy_receiver; | 399 DummyMessageReceiver dummy_receiver; |
400 mojo::internal::FilterChain validators(&dummy_receiver); | 400 mojo::FilterChain validators(&dummy_receiver); |
401 validators.Append<mojo::MessageHeaderValidator>(); | 401 validators.Append<mojo::MessageHeaderValidator>(); |
402 validators.Append<BoundsCheckTestInterface::RequestValidator_>(); | 402 validators.Append<BoundsCheckTestInterface::RequestValidator_>(); |
403 | 403 |
404 RunValidationTests("boundscheck_", validators.GetHead()); | 404 RunValidationTests("boundscheck_", &validators); |
405 } | 405 } |
406 | 406 |
407 // This test is similar to the Conformance test but for responses. | 407 // This test is similar to the Conformance test but for responses. |
408 TEST_F(ValidationTest, ResponseConformance) { | 408 TEST_F(ValidationTest, ResponseConformance) { |
409 DummyMessageReceiver dummy_receiver; | 409 DummyMessageReceiver dummy_receiver; |
410 mojo::internal::FilterChain validators(&dummy_receiver); | 410 mojo::FilterChain validators(&dummy_receiver); |
411 validators.Append<mojo::MessageHeaderValidator>(); | 411 validators.Append<mojo::MessageHeaderValidator>(); |
412 validators.Append<ConformanceTestInterface::ResponseValidator_>(); | 412 validators.Append<ConformanceTestInterface::ResponseValidator_>(); |
413 | 413 |
414 RunValidationTests("resp_conformance_", validators.GetHead()); | 414 RunValidationTests("resp_conformance_", &validators); |
415 } | 415 } |
416 | 416 |
417 // This test is similar to the BoundsCheck test but for responses. | 417 // This test is similar to the BoundsCheck test but for responses. |
418 TEST_F(ValidationTest, ResponseBoundsCheck) { | 418 TEST_F(ValidationTest, ResponseBoundsCheck) { |
419 DummyMessageReceiver dummy_receiver; | 419 DummyMessageReceiver dummy_receiver; |
420 mojo::internal::FilterChain validators(&dummy_receiver); | 420 mojo::FilterChain validators(&dummy_receiver); |
421 validators.Append<mojo::MessageHeaderValidator>(); | 421 validators.Append<mojo::MessageHeaderValidator>(); |
422 validators.Append<BoundsCheckTestInterface::ResponseValidator_>(); | 422 validators.Append<BoundsCheckTestInterface::ResponseValidator_>(); |
423 | 423 |
424 RunValidationTests("resp_boundscheck_", validators.GetHead()); | 424 RunValidationTests("resp_boundscheck_", &validators); |
425 } | 425 } |
426 | 426 |
427 // Test that InterfacePtr<X> applies the correct validators and they don't | 427 // Test that InterfacePtr<X> applies the correct validators and they don't |
428 // conflict with each other: | 428 // conflict with each other: |
429 // - MessageHeaderValidator | 429 // - MessageHeaderValidator |
430 // - X::ResponseValidator_ | 430 // - X::ResponseValidator_ |
431 TEST_F(ValidationIntegrationTest, InterfacePtr) { | 431 TEST_F(ValidationIntegrationTest, InterfacePtr) { |
432 IntegrationTestInterfacePtr interface_ptr = MakeProxy( | 432 IntegrationTestInterfacePtr interface_ptr = MakeProxy( |
433 InterfacePtrInfo<IntegrationTestInterface>(testee_endpoint(), 0u)); | 433 InterfacePtrInfo<IntegrationTestInterface>(testee_endpoint(), 0u)); |
434 interface_ptr.internal_state()->EnableTestingMode(); | 434 interface_ptr.internal_state()->EnableTestingMode(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(0))); | 490 EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(0))); |
491 EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(1))); | 491 EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(1))); |
492 EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(2))); | 492 EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(2))); |
493 EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(3))); | 493 EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(3))); |
494 EXPECT_FALSE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(4))); | 494 EXPECT_FALSE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(4))); |
495 } | 495 } |
496 | 496 |
497 } // namespace | 497 } // namespace |
498 } // namespace test | 498 } // namespace test |
499 } // namespace mojo | 499 } // namespace mojo |
OLD | NEW |