diff options
author | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-20 23:50:27 +0000 |
---|---|---|
committer | brettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-20 23:50:27 +0000 |
commit | 3ff2a10362f73dfaf2b6509f6553f963cdbc7b7d (patch) | |
tree | 2b2e824e76b9b6c473ab91933a1759e10c9e685d /ipc/ipc_test_sink.cc | |
parent | f63ad079d7c5b1bcd6a8b42aed298de328be0811 (diff) | |
download | chromium_src-3ff2a10362f73dfaf2b6509f6553f963cdbc7b7d.zip chromium_src-3ff2a10362f73dfaf2b6509f6553f963cdbc7b7d.tar.gz chromium_src-3ff2a10362f73dfaf2b6509f6553f963cdbc7b7d.tar.bz2 |
Move the TestSink for doing IPC tests from chrome/common into IPC and create a new IPC test_support project that references it.
This is necessary because I want to make a test that uses the sink outside of chrome.
TEST=this is a test
BUG=none
Review URL: http://codereview.chromium.org/6290008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72044 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc/ipc_test_sink.cc')
-rw-r--r-- | ipc/ipc_test_sink.cc | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/ipc/ipc_test_sink.cc b/ipc/ipc_test_sink.cc new file mode 100644 index 0000000..95900b6 --- /dev/null +++ b/ipc/ipc_test_sink.cc @@ -0,0 +1,60 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ipc/ipc_test_sink.h" + +#include "ipc/ipc_message.h" + +namespace IPC { + +TestSink::TestSink() { +} + +TestSink::~TestSink() { +} + +bool TestSink::Send(Message* message) { + OnMessageReceived(*message); + delete message; + return true; +} + +bool TestSink::OnMessageReceived(const Message& msg) { + messages_.push_back(Message(msg)); + return true; +} + +void TestSink::ClearMessages() { + messages_.clear(); +} + +const Message* TestSink::GetMessageAt(size_t index) const { + if (index >= messages_.size()) + return NULL; + return &messages_[index]; +} + +const Message* TestSink::GetFirstMessageMatching(uint32 id) const { + for (size_t i = 0; i < messages_.size(); i++) { + if (messages_[i].type() == id) + return &messages_[i]; + } + return NULL; +} + +const Message* TestSink::GetUniqueMessageMatching(uint32 id) const { + size_t found_index = 0; + size_t found_count = 0; + for (size_t i = 0; i < messages_.size(); i++) { + if (messages_[i].type() == id) { + found_count++; + found_index = i; + } + } + if (found_count != 1) + return NULL; // Didn't find a unique one. + return &messages_[found_index]; +} + +} // namespace IPC |