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

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

Issue 1486573003: Mojo C++ bindings: associated interface pointers/requests validation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
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 <stdio.h> 5 #include <stdio.h>
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "mojo/message_pump/message_pump_mojo.h" 12 #include "mojo/message_pump/message_pump_mojo.h"
13 #include "mojo/public/c/system/macros.h" 13 #include "mojo/public/c/system/macros.h"
14 #include "mojo/public/cpp/bindings/binding.h" 14 #include "mojo/public/cpp/bindings/binding.h"
15 #include "mojo/public/cpp/bindings/interface_ptr.h" 15 #include "mojo/public/cpp/bindings/interface_ptr.h"
16 #include "mojo/public/cpp/bindings/lib/connector.h" 16 #include "mojo/public/cpp/bindings/lib/connector.h"
17 #include "mojo/public/cpp/bindings/lib/filter_chain.h" 17 #include "mojo/public/cpp/bindings/lib/filter_chain.h"
18 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" 18 #include "mojo/public/cpp/bindings/lib/message_header_validator.h"
19 #include "mojo/public/cpp/bindings/lib/router.h" 19 #include "mojo/public/cpp/bindings/lib/router.h"
20 #include "mojo/public/cpp/bindings/lib/validation_errors.h" 20 #include "mojo/public/cpp/bindings/lib/validation_errors.h"
21 #include "mojo/public/cpp/bindings/message.h" 21 #include "mojo/public/cpp/bindings/message.h"
22 #include "mojo/public/cpp/bindings/tests/validation_test_input_parser.h" 22 #include "mojo/public/cpp/bindings/tests/validation_test_input_parser.h"
23 #include "mojo/public/cpp/system/core.h" 23 #include "mojo/public/cpp/system/core.h"
24 #include "mojo/public/cpp/test_support/test_support.h" 24 #include "mojo/public/cpp/test_support/test_support.h"
25 #include "mojo/public/interfaces/bindings/tests/validation_test_associated_inter faces.mojom.h"
25 #include "mojo/public/interfaces/bindings/tests/validation_test_interfaces.mojom .h" 26 #include "mojo/public/interfaces/bindings/tests/validation_test_interfaces.mojom .h"
26 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
27 28
28 namespace mojo { 29 namespace mojo {
29 namespace test { 30 namespace test {
30 namespace { 31 namespace {
31 32
32 template <typename T> 33 template <typename T>
33 void Append(std::vector<uint8_t>* data_vector, T data) { 34 void Append(std::vector<uint8_t>* data_vector, T data) {
34 size_t pos = data_vector->size(); 35 size_t pos = data_vector->size();
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 363
363 TEST_F(ValidationTest, Conformance) { 364 TEST_F(ValidationTest, Conformance) {
364 DummyMessageReceiver dummy_receiver; 365 DummyMessageReceiver dummy_receiver;
365 mojo::internal::FilterChain validators(&dummy_receiver); 366 mojo::internal::FilterChain validators(&dummy_receiver);
366 validators.Append<mojo::internal::MessageHeaderValidator>(); 367 validators.Append<mojo::internal::MessageHeaderValidator>();
367 validators.Append<ConformanceTestInterface::RequestValidator_>(); 368 validators.Append<ConformanceTestInterface::RequestValidator_>();
368 369
369 RunValidationTests("conformance_", validators.GetHead()); 370 RunValidationTests("conformance_", validators.GetHead());
370 } 371 }
371 372
373 TEST_F(ValidationTest, AssociatedConformace) {
374 DummyMessageReceiver dummy_receiver;
375 mojo::internal::FilterChain validators(&dummy_receiver);
376 validators.Append<mojo::internal::MessageHeaderValidator>();
377 validators.Append<AssociatedConformanceTestInterface::RequestValidator_>();
378
379 RunValidationTests("associated_conformance_", validators.GetHead());
380 }
381
372 // This test is similar to Conformance test but its goal is specifically 382 // This test is similar to Conformance test but its goal is specifically
373 // do bounds-check testing of message validation. For example we test the 383 // do bounds-check testing of message validation. For example we test the
374 // detection of off-by-one errors in method ordinals. 384 // detection of off-by-one errors in method ordinals.
375 TEST_F(ValidationTest, BoundsCheck) { 385 TEST_F(ValidationTest, BoundsCheck) {
376 DummyMessageReceiver dummy_receiver; 386 DummyMessageReceiver dummy_receiver;
377 mojo::internal::FilterChain validators(&dummy_receiver); 387 mojo::internal::FilterChain validators(&dummy_receiver);
378 validators.Append<mojo::internal::MessageHeaderValidator>(); 388 validators.Append<mojo::internal::MessageHeaderValidator>();
379 validators.Append<BoundsCheckTestInterface::RequestValidator_>(); 389 validators.Append<BoundsCheckTestInterface::RequestValidator_>();
380 390
381 RunValidationTests("boundscheck_", validators.GetHead()); 391 RunValidationTests("boundscheck_", validators.GetHead());
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 static_cast<StructWithEnum::EnumWithin>(2))); 483 static_cast<StructWithEnum::EnumWithin>(2)));
474 EXPECT_TRUE(StructWithEnum::EnumWithin_IsValidValue( 484 EXPECT_TRUE(StructWithEnum::EnumWithin_IsValidValue(
475 static_cast<StructWithEnum::EnumWithin>(3))); 485 static_cast<StructWithEnum::EnumWithin>(3)));
476 EXPECT_FALSE(StructWithEnum::EnumWithin_IsValidValue( 486 EXPECT_FALSE(StructWithEnum::EnumWithin_IsValidValue(
477 static_cast<StructWithEnum::EnumWithin>(4))); 487 static_cast<StructWithEnum::EnumWithin>(4)));
478 } 488 }
479 489
480 } // namespace 490 } // namespace
481 } // namespace test 491 } // namespace test
482 } // namespace mojo 492 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/validation_util.cc ('k') | mojo/public/interfaces/bindings/tests/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698