00001 #ifndef _tests_MockChannel_h
00002 #define _tests_MockChannel_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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