blob: 69d328c8ebf50bbfe6af84a5af7bc98c36f33223 [file] [log] [blame]
[email protected]90b721e62010-04-05 17:35:011// Copyright (c) 2010 The Chromium Authors. All rights reserved.
[email protected]a16ed65e2009-02-14 01:35:272// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]82e5ee82009-04-03 02:29:455#include "chrome/common/ipc_test_sink.h"
[email protected]a83d42292010-08-17 22:51:106#include "ipc/ipc_message.h"
[email protected]a16ed65e2009-02-14 01:35:277
8namespace IPC {
9
10TestSink::TestSink() {
11}
12
13TestSink::~TestSink() {
14}
15
[email protected]90b721e62010-04-05 17:35:0116bool TestSink::Send(IPC::Message* message) {
17 OnMessageReceived(*message);
18 delete message;
19 return true;
20}
21
[email protected]6db8d9902010-12-24 08:36:2522bool TestSink::OnMessageReceived(const Message& msg) {
[email protected]445623e62010-03-25 23:20:2423 messages_.push_back(Message(msg));
[email protected]6db8d9902010-12-24 08:36:2524 return true;
[email protected]a16ed65e2009-02-14 01:35:2725}
26
27void TestSink::ClearMessages() {
28 messages_.clear();
29}
30
31const Message* TestSink::GetMessageAt(size_t index) const {
32 if (index >= messages_.size())
33 return NULL;
34 return &messages_[index];
35}
36
[email protected]168ae922009-12-04 18:08:4537const Message* TestSink::GetFirstMessageMatching(uint32 id) const {
[email protected]a16ed65e2009-02-14 01:35:2738 for (size_t i = 0; i < messages_.size(); i++) {
39 if (messages_[i].type() == id)
40 return &messages_[i];
41 }
42 return NULL;
43}
44
[email protected]168ae922009-12-04 18:08:4545const Message* TestSink::GetUniqueMessageMatching(uint32 id) const {
[email protected]a16ed65e2009-02-14 01:35:2746 size_t found_index = 0;
47 size_t found_count = 0;
48 for (size_t i = 0; i < messages_.size(); i++) {
49 if (messages_[i].type() == id) {
50 found_count++;
51 found_index = i;
52 }
53 }
54 if (found_count != 1)
55 return NULL; // Didn't find a unique one.
56 return &messages_[found_index];
57}
58
59} // namespace IPC