blob: 45db8f52372ac283aef625a7f0c3290664493912 [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]2c9847a12010-12-24 08:16:4622void TestSink::OnMessageReceived(const Message& msg) {
[email protected]445623e62010-03-25 23:20:2423 messages_.push_back(Message(msg));
[email protected]a16ed65e2009-02-14 01:35:2724}
25
26void TestSink::ClearMessages() {
27 messages_.clear();
28}
29
30const Message* TestSink::GetMessageAt(size_t index) const {
31 if (index >= messages_.size())
32 return NULL;
33 return &messages_[index];
34}
35
[email protected]168ae922009-12-04 18:08:4536const Message* TestSink::GetFirstMessageMatching(uint32 id) const {
[email protected]a16ed65e2009-02-14 01:35:2737 for (size_t i = 0; i < messages_.size(); i++) {
38 if (messages_[i].type() == id)
39 return &messages_[i];
40 }
41 return NULL;
42}
43
[email protected]168ae922009-12-04 18:08:4544const Message* TestSink::GetUniqueMessageMatching(uint32 id) const {
[email protected]a16ed65e2009-02-14 01:35:2745 size_t found_index = 0;
46 size_t found_count = 0;
47 for (size_t i = 0; i < messages_.size(); i++) {
48 if (messages_[i].type() == id) {
49 found_count++;
50 found_index = i;
51 }
52 }
53 if (found_count != 1)
54 return NULL; // Didn't find a unique one.
55 return &messages_[found_index];
56}
57
58} // namespace IPC