blob: c27890203fdc422cc66c81de36d0615a44b042ea [file] [log] [blame]
[email protected]a16ed65e2009-02-14 01:35:271// 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
7namespace IPC {
8
9TestSink::TestSink() {
10}
11
12TestSink::~TestSink() {
13}
14
15void TestSink::OnMessageReceived(const Message& msg) {
16 messages_.push_back(Message(msg));
17}
18
19void TestSink::ClearMessages() {
20 messages_.clear();
21}
22
23const Message* TestSink::GetMessageAt(size_t index) const {
24 if (index >= messages_.size())
25 return NULL;
26 return &messages_[index];
27}
28
29const 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
37const 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