[email protected] | a16ed65e | 2009-02-14 01:35:27 | [diff] [blame^] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/common/ipc_test_sink.h" |
| 6 | |
| 7 | namespace IPC { |
| 8 | |
| 9 | TestSink::TestSink() { |
| 10 | } |
| 11 | |
| 12 | TestSink::~TestSink() { |
| 13 | } |
| 14 | |
| 15 | void TestSink::OnMessageReceived(const Message& msg) { |
| 16 | messages_.push_back(Message(msg)); |
| 17 | } |
| 18 | |
| 19 | void TestSink::ClearMessages() { |
| 20 | messages_.clear(); |
| 21 | } |
| 22 | |
| 23 | const Message* TestSink::GetMessageAt(size_t index) const { |
| 24 | if (index >= messages_.size()) |
| 25 | return NULL; |
| 26 | return &messages_[index]; |
| 27 | } |
| 28 | |
| 29 | const Message* TestSink::GetFirstMessageMatching(uint16 id) const { |
| 30 | for (size_t i = 0; i < messages_.size(); i++) { |
| 31 | if (messages_[i].type() == id) |
| 32 | return &messages_[i]; |
| 33 | } |
| 34 | return NULL; |
| 35 | } |
| 36 | |
| 37 | const Message* TestSink::GetUniqueMessageMatching(uint16 id) const { |
| 38 | size_t found_index = 0; |
| 39 | size_t found_count = 0; |
| 40 | for (size_t i = 0; i < messages_.size(); i++) { |
| 41 | if (messages_[i].type() == id) { |
| 42 | found_count++; |
| 43 | found_index = i; |
| 44 | } |
| 45 | } |
| 46 | if (found_count != 1) |
| 47 | return NULL; // Didn't find a unique one. |
| 48 | return &messages_[found_index]; |
| 49 | } |
| 50 | |
| 51 | } // namespace IPC |