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

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

Issue 617503003: Mojo: MOJO_OVERRIDE -> override in mojo/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 6 years, 2 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stdlib.h> 5 #include <stdlib.h>
6 #include <string.h> 6 #include <string.h>
7 7
8 #include "mojo/public/cpp/bindings/lib/connector.h" 8 #include "mojo/public/cpp/bindings/lib/connector.h"
9 #include "mojo/public/cpp/bindings/lib/message_builder.h" 9 #include "mojo/public/cpp/bindings/lib/message_builder.h"
10 #include "mojo/public/cpp/bindings/lib/message_queue.h" 10 #include "mojo/public/cpp/bindings/lib/message_queue.h"
11 #include "mojo/public/cpp/environment/environment.h" 11 #include "mojo/public/cpp/environment/environment.h"
12 #include "mojo/public/cpp/system/macros.h" 12 #include "mojo/public/cpp/system/macros.h"
13 #include "mojo/public/cpp/utility/run_loop.h" 13 #include "mojo/public/cpp/utility/run_loop.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace mojo { 16 namespace mojo {
17 namespace test { 17 namespace test {
18 namespace { 18 namespace {
19 19
20 class MessageAccumulator : public MessageReceiver { 20 class MessageAccumulator : public MessageReceiver {
21 public: 21 public:
22 MessageAccumulator() { 22 MessageAccumulator() {
23 } 23 }
24 24
25 virtual bool Accept(Message* message) MOJO_OVERRIDE { 25 virtual bool Accept(Message* message) override {
26 queue_.Push(message); 26 queue_.Push(message);
27 return true; 27 return true;
28 } 28 }
29 29
30 bool IsEmpty() const { 30 bool IsEmpty() const {
31 return queue_.IsEmpty(); 31 return queue_.IsEmpty();
32 } 32 }
33 33
34 void Pop(Message* message) { 34 void Pop(Message* message) {
35 queue_.Pop(message); 35 queue_.Pop(message);
36 } 36 }
37 37
38 private: 38 private:
39 internal::MessageQueue queue_; 39 internal::MessageQueue queue_;
40 }; 40 };
41 41
42 class ConnectorDeletingMessageAccumulator : public MessageAccumulator { 42 class ConnectorDeletingMessageAccumulator : public MessageAccumulator {
43 public: 43 public:
44 ConnectorDeletingMessageAccumulator(internal::Connector** connector) 44 ConnectorDeletingMessageAccumulator(internal::Connector** connector)
45 : connector_(connector) {} 45 : connector_(connector) {}
46 46
47 virtual bool Accept(Message* message) MOJO_OVERRIDE { 47 virtual bool Accept(Message* message) override {
48 delete *connector_; 48 delete *connector_;
49 *connector_ = 0; 49 *connector_ = 0;
50 return MessageAccumulator::Accept(message); 50 return MessageAccumulator::Accept(message);
51 } 51 }
52 52
53 private: 53 private:
54 internal::Connector** connector_; 54 internal::Connector** connector_;
55 }; 55 };
56 56
57 class ReentrantMessageAccumulator : public MessageAccumulator { 57 class ReentrantMessageAccumulator : public MessageAccumulator {
58 public: 58 public:
59 ReentrantMessageAccumulator(internal::Connector* connector) 59 ReentrantMessageAccumulator(internal::Connector* connector)
60 : connector_(connector), number_of_calls_(0) {} 60 : connector_(connector), number_of_calls_(0) {}
61 61
62 virtual bool Accept(Message* message) MOJO_OVERRIDE { 62 virtual bool Accept(Message* message) override {
63 if (!MessageAccumulator::Accept(message)) 63 if (!MessageAccumulator::Accept(message))
64 return false; 64 return false;
65 number_of_calls_++; 65 number_of_calls_++;
66 if (number_of_calls_ == 1) { 66 if (number_of_calls_ == 1) {
67 return connector_->WaitForIncomingMessage(); 67 return connector_->WaitForIncomingMessage();
68 } 68 }
69 return true; 69 return true;
70 } 70 }
71 71
72 int number_of_calls() { return number_of_calls_; } 72 int number_of_calls() { return number_of_calls_; }
73 73
74 private: 74 private:
75 internal::Connector* connector_; 75 internal::Connector* connector_;
76 int number_of_calls_; 76 int number_of_calls_;
77 }; 77 };
78 78
79 class ConnectorTest : public testing::Test { 79 class ConnectorTest : public testing::Test {
80 public: 80 public:
81 ConnectorTest() { 81 ConnectorTest() {
82 } 82 }
83 83
84 virtual void SetUp() MOJO_OVERRIDE { 84 virtual void SetUp() override {
85 CreateMessagePipe(NULL, &handle0_, &handle1_); 85 CreateMessagePipe(NULL, &handle0_, &handle1_);
86 } 86 }
87 87
88 virtual void TearDown() MOJO_OVERRIDE { 88 virtual void TearDown() override {}
89 }
90 89
91 void AllocMessage(const char* text, Message* message) { 90 void AllocMessage(const char* text, Message* message) {
92 size_t payload_size = strlen(text) + 1; // Plus null terminator. 91 size_t payload_size = strlen(text) + 1; // Plus null terminator.
93 internal::MessageBuilder builder(1, payload_size); 92 internal::MessageBuilder builder(1, payload_size);
94 memcpy(builder.buffer()->Allocate(payload_size), text, payload_size); 93 memcpy(builder.buffer()->Allocate(payload_size), text, payload_size);
95 builder.Finish(message); 94 builder.Finish(message);
96 } 95 }
97 96
98 void PumpMessages() { 97 void PumpMessages() {
99 loop_.RunUntilIdle(); 98 loop_.RunUntilIdle();
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 std::string(kText[i]), 393 std::string(kText[i]),
395 std::string(reinterpret_cast<const char*>(message_received.payload()))); 394 std::string(reinterpret_cast<const char*>(message_received.payload())));
396 } 395 }
397 396
398 ASSERT_EQ(2, accumulator.number_of_calls()); 397 ASSERT_EQ(2, accumulator.number_of_calls());
399 } 398 }
400 399
401 } // namespace 400 } // namespace
402 } // namespace test 401 } // namespace test
403 } // namespace mojo 402 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/no_interface.h ('k') | mojo/public/cpp/bindings/tests/handle_passing_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698