| OLD | NEW | 
|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef CHROME_COMMON_IPC_TEST_SINK_H_ | 5 #ifndef CHROME_COMMON_IPC_TEST_SINK_H_ | 
| 6 #define CHROME_COMMON_IPC_TEST_SINK_H_ | 6 #define CHROME_COMMON_IPC_TEST_SINK_H_ | 
| 7 | 7 | 
| 8 #include <utility> | 8 #include <utility> | 
| 9 #include <vector> | 9 #include <vector> | 
| 10 | 10 | 
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" | 
| 12 #include "ipc/ipc_message.h" | 12 #include "ipc/ipc_message.h" | 
|  | 13 #include "ipc/ipc_channel.h" | 
| 13 | 14 | 
| 14 namespace IPC { | 15 namespace IPC { | 
| 15 | 16 | 
| 16 // This test sink provides a "sink" for IPC messages that are sent. It allows | 17 // This test sink provides a "sink" for IPC messages that are sent. It allows | 
| 17 // the caller to query messages received in various different ways.  It is | 18 // the caller to query messages received in various different ways.  It is | 
| 18 // designed for tests for objects that use the IPC system. | 19 // designed for tests for objects that use the IPC system. | 
| 19 // | 20 // | 
| 20 // Typical usage: | 21 // Typical usage: | 
| 21 // | 22 // | 
| 22 //   test_sink.ClearMessages(); | 23 //   test_sink.ClearMessages(); | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 33 //   ASSERT_TRUE(msg); | 34 //   ASSERT_TRUE(msg); | 
| 34 //   bool first_param; | 35 //   bool first_param; | 
| 35 //   int second_param; | 36 //   int second_param; | 
| 36 //   ViewMsg_Foo::Read(msg, &first_param, &second_param); | 37 //   ViewMsg_Foo::Read(msg, &first_param, &second_param); | 
| 37 // | 38 // | 
| 38 //   // Go on to the next phase of the test. | 39 //   // Go on to the next phase of the test. | 
| 39 //   test_sink.ClearMessages(); | 40 //   test_sink.ClearMessages(); | 
| 40 // | 41 // | 
| 41 // To hook up the sink, all you need to do is call OnMessageReceived when a | 42 // To hook up the sink, all you need to do is call OnMessageReceived when a | 
| 42 // message is received. | 43 // message is received. | 
| 43 class TestSink { | 44 class TestSink : public IPC::Channel { | 
| 44  public: | 45  public: | 
| 45   TestSink(); | 46   TestSink(); | 
| 46   ~TestSink(); | 47   ~TestSink(); | 
| 47 | 48 | 
| 48   // Used by the source of the messages to send the message to the sink. This | 49   // Used by the source of the messages to send the message to the sink. This | 
| 49   // will make a copy of the message and store it in the list. | 50   // will make a copy of the message and store it in the list. | 
| 50   void OnMessageReceived(const Message& msg); | 51   virtual bool Send(Message* message); | 
| 51 | 52 | 
| 52   // Returns the number of messages in the queue. | 53   // Returns the number of messages in the queue. | 
| 53   size_t message_count() const { return messages_.size(); } | 54   size_t message_count() const { return messages_.size(); } | 
| 54 | 55 | 
| 55   // Clears the message queue of saved messages. | 56   // Clears the message queue of saved messages. | 
| 56   void ClearMessages(); | 57   void ClearMessages(); | 
| 57 | 58 | 
| 58   // Returns the message at the given index in the queue. The index may be out | 59   // Returns the message at the given index in the queue. The index may be out | 
| 59   // of range, in which case the return value is NULL. The returned pointer will | 60   // of range, in which case the return value is NULL. The returned pointer will | 
| 60   // only be valid until another message is received or the list is cleared. | 61   // only be valid until another message is received or the list is cleared. | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 75  private: | 76  private: | 
| 76   // The actual list of received messages. | 77   // The actual list of received messages. | 
| 77   std::vector<Message> messages_; | 78   std::vector<Message> messages_; | 
| 78 | 79 | 
| 79   DISALLOW_COPY_AND_ASSIGN(TestSink); | 80   DISALLOW_COPY_AND_ASSIGN(TestSink); | 
| 80 }; | 81 }; | 
| 81 | 82 | 
| 82 }  // namespace IPC | 83 }  // namespace IPC | 
| 83 | 84 | 
| 84 #endif  // CHROME_COMMON_IPC_TEST_SINK_H_ | 85 #endif  // CHROME_COMMON_IPC_TEST_SINK_H_ | 
| OLD | NEW | 
|---|