/home/aconway/svn/qpid/cpp/src/tests/MockChannel.h

00001 #ifndef _tests_MockChannel_h
00002 #define _tests_MockChannel_h
00003 
00004 /*
00005  *
00006  * Copyright (c) 2006 The Apache Software Foundation
00007  *
00008  * Licensed under the Apache License, Version 2.0 (the "License");
00009  * you may not use this file except in compliance with the License.
00010  * You may obtain a copy of the License at
00011  *
00012  *    http://www.apache.org/licenses/LICENSE-2.0
00013  *
00014  * Unless required by applicable law or agreed to in writing, software
00015  * distributed under the License is distributed on an "AS IS" BASIS,
00016  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00017  * See the License for the specific language governing permissions and
00018  * limitations under the License.
00019  *
00020  */
00021 
00022 #include "qpid/framing/MethodContext.h"
00023 #include "qpid/framing/ChannelAdapter.h"
00024 #include "qpid/framing/OutputHandler.h"
00025 #include "qpid/framing/AMQFrame.h"
00026 #include "qpid/framing/BasicGetBody.h"
00027 #include <boost/shared_ptr.hpp>
00028 #include <boost/ptr_container/ptr_vector.hpp>
00029 
00031 struct MockOutputHandler : public qpid::framing::OutputHandler {
00032     boost::ptr_vector<qpid::framing::AMQFrame> frames;
00033     void send(qpid::framing::AMQFrame* frame){ frames.push_back(frame); }
00034 };
00035 
00039 struct MockChannel : public qpid::framing::ChannelAdapter
00040 {
00041     typedef qpid::framing::BasicGetBody Body;
00042     static Body::shared_ptr basicGetBody() {
00043         return Body::shared_ptr(
00044             new Body(qpid::framing::ProtocolVersion()));
00045     }
00046 
00047     MockOutputHandler out;
00048 
00049     MockChannel(qpid::framing::ChannelId id) {
00050         init(id, out, qpid::framing::ProtocolVersion());
00051     }
00052 
00053     bool isOpen() const { return true; }
00054 
00055     void handleHeader(
00056         boost::shared_ptr<qpid::framing::AMQHeaderBody> b) { send(b); }
00057     void handleContent(
00058         boost::shared_ptr<qpid::framing::AMQContentBody> b) { send(b); }
00059     void handleHeartbeat(
00060         boost::shared_ptr<qpid::framing::AMQHeartbeatBody> b) { send(b); }
00061     void handleMethodInContext(
00062         boost::shared_ptr<qpid::framing::AMQMethodBody> method,
00063         const qpid::framing::MethodContext& context)
00064     {
00065         context.channel->send(method);
00066     };
00067 
00068 };
00069 
00070 #endif  

Generated on Tue Apr 17 14:22:03 2007 for Qpid by  doxygen 1.4.7