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

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

Issue 2114523002: Move more Mojo bindings helpers out of internal namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@group-controller
Patch Set: rebase Created 4 years, 5 months 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 <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/interface_ptr.h" 19 #include "mojo/public/cpp/bindings/interface_ptr.h"
19 #include "mojo/public/cpp/bindings/lib/connector.h"
20 #include "mojo/public/cpp/bindings/lib/filter_chain.h" 20 #include "mojo/public/cpp/bindings/lib/filter_chain.h"
21 #include "mojo/public/cpp/bindings/lib/message_header_validator.h"
22 #include "mojo/public/cpp/bindings/lib/router.h" 21 #include "mojo/public/cpp/bindings/lib/router.h"
23 #include "mojo/public/cpp/bindings/lib/validation_errors.h" 22 #include "mojo/public/cpp/bindings/lib/validation_errors.h"
24 #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"
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"
31 31
32 namespace mojo { 32 namespace mojo {
33 namespace test { 33 namespace test {
34 namespace { 34 namespace {
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 return std::move(testee_endpoint_); 232 return std::move(testee_endpoint_);
233 } 233 }
234 234
235 private: 235 private:
236 class TestMessageReceiver : public MessageReceiver { 236 class TestMessageReceiver : public MessageReceiver {
237 public: 237 public:
238 TestMessageReceiver(ValidationIntegrationTest* owner, 238 TestMessageReceiver(ValidationIntegrationTest* owner,
239 ScopedMessagePipeHandle handle) 239 ScopedMessagePipeHandle handle)
240 : owner_(owner), 240 : owner_(owner),
241 connector_(std::move(handle), 241 connector_(std::move(handle),
242 mojo::internal::Connector::SINGLE_THREADED_SEND, 242 mojo::Connector::SINGLE_THREADED_SEND,
243 base::ThreadTaskRunnerHandle::Get()) { 243 base::ThreadTaskRunnerHandle::Get()) {
244 connector_.set_enforce_errors_from_incoming_receiver(false); 244 connector_.set_enforce_errors_from_incoming_receiver(false);
245 } 245 }
246 ~TestMessageReceiver() override {} 246 ~TestMessageReceiver() override {}
247 247
248 bool Accept(Message* message) override { 248 bool Accept(Message* message) override {
249 return connector_.Accept(message); 249 return connector_.Accept(message);
250 } 250 }
251 251
252 public: 252 public:
253 ValidationIntegrationTest* owner_; 253 ValidationIntegrationTest* owner_;
254 mojo::internal::Connector connector_; 254 mojo::Connector connector_;
255 }; 255 };
256 256
257 void PumpMessages() { loop_.RunUntilIdle(); } 257 void PumpMessages() { loop_.RunUntilIdle(); }
258 258
259 TestMessageReceiver* test_message_receiver_; 259 TestMessageReceiver* test_message_receiver_;
260 ScopedMessagePipeHandle testee_endpoint_; 260 ScopedMessagePipeHandle testee_endpoint_;
261 }; 261 };
262 262
263 class IntegrationTestInterfaceImpl : public IntegrationTestInterface { 263 class IntegrationTestInterfaceImpl : public IntegrationTestInterface {
264 public: 264 public:
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::internal::FilterChain validators(&dummy_receiver);
380 validators.Append<mojo::internal::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.GetHead());
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::internal::FilterChain validators(&dummy_receiver);
389 validators.Append<mojo::internal::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.GetHead());
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::internal::FilterChain validators(&dummy_receiver);
401 validators.Append<mojo::internal::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.GetHead());
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::internal::FilterChain validators(&dummy_receiver);
411 validators.Append<mojo::internal::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.GetHead());
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::internal::FilterChain validators(&dummy_receiver);
421 validators.Append<mojo::internal::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.GetHead());
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) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698