256 lines
7.7 KiB
HTML
256 lines
7.7 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of Net::DBus::Test::MockConnection</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>Net::DBus::Test::MockConnection</H1>
|
|
Section: User Contributed Perl Documentation (3pm)<BR>Updated: 2019-12-26<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
Net::DBus::Test::MockConnection - Fake a connection to the bus unit testing
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
|
|
|
|
|
|
|
|
<PRE>
|
|
use Net::DBus;
|
|
|
|
my $bus = Net::DBus->test
|
|
|
|
# Register a service, and the objec to be tested
|
|
use MyObject
|
|
my $service = $bus->export_service("org.example.MyService");
|
|
my $object = MyObject->new($service);
|
|
|
|
|
|
# Acquire the service & do tests
|
|
my $remote_service = $bus->get_service('org.example.MyService');
|
|
my $remote_object = $service->get_object("/org/example/MyObjct");
|
|
|
|
# This traverses the mock connection, eventually
|
|
# invoking 'testSomething' on the $object above.
|
|
$remote_object->testSomething()
|
|
|
|
</PRE>
|
|
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
|
|
|
|
This object provides a fake implementation of the Net::DBus::Binding::Connection
|
|
enabling a pure 'in-memory' message bus to be mocked up. This is intended to
|
|
facilitate creation of unit tests for services which would otherwise need to
|
|
call out to other object on a live message bus. It is used as a companion to
|
|
the Net::DBus::Test::MockObject module which is how fake objects are to be
|
|
provided on the fake bus.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>METHODS</H2>
|
|
|
|
|
|
|
|
<DL COMPACT>
|
|
<DT id="1">my $con = Net::DBus::Test::MockConnection-><B>new()</B><DD>
|
|
|
|
|
|
|
|
|
|
Create a new mock connection object instance. It is not usually
|
|
necessary to create instances of this object directly, instead
|
|
the <TT>"test"</TT> method on the Net::DBus object can be used to
|
|
get a handle to a test bus.
|
|
<DT id="2">$con->send($message)<DD>
|
|
|
|
|
|
|
|
|
|
Send a message over the mock connection. If the message is
|
|
a method call, it will be dispatched straight to any corresponding
|
|
mock object registered. If the message is an error or method return
|
|
it will be made available as a return value for the <TT>"send_with_reply_and_block"</TT>
|
|
method. If the message is a signal it will be queued up for processing
|
|
by the <TT>"dispatch"</TT> method.
|
|
<DT id="3">$bus->request_name($service_name)<DD>
|
|
|
|
|
|
|
|
|
|
Pretend to send a request to the bus registering the well known
|
|
name specified in the <TT>$service_name</TT> parameter. In reality
|
|
this is just a no-op giving the impression that the name was
|
|
successfully registered.
|
|
<DT id="4">my $reply = $con->send_with_reply_and_block($msg)<DD>
|
|
|
|
|
|
|
|
|
|
Send a message over the mock connection and wait for a
|
|
reply. The <TT>$msg</TT> should be an instance of <TT>"Net::DBus::Binding::Message::MethodCall"</TT>
|
|
and the return <TT>$reply</TT> will be an instance of <TT>"Net::DBus::Binding::Message::MethodReturn"</TT>.
|
|
It is also possible that an error will be thrown, with
|
|
the thrown error being blessed into the <TT>"Net::DBus::Error"</TT>
|
|
class.
|
|
<DT id="5">$con->dispatch;<DD>
|
|
|
|
|
|
|
|
|
|
Dispatches any pending messages in the incoming queue
|
|
to their message handlers. This method should be called
|
|
by test suites whenever they anticipate that there are
|
|
pending signals to be dealt with.
|
|
<DT id="6">$con->add_filter($coderef);<DD>
|
|
|
|
|
|
|
|
|
|
Adds a filter to the connection which will be invoked whenever a
|
|
message is received. The <TT>$coderef</TT> should be a reference to a
|
|
subroutine, which returns a true value if the message should be
|
|
filtered out, or a false value if the normal message dispatch
|
|
should be performed.
|
|
<DT id="7">$bus->add_match($rule)<DD>
|
|
|
|
|
|
|
|
|
|
Register a signal match rule with the bus controller, allowing
|
|
matching broadcast signals to routed to this client. In reality
|
|
this is just a no-op giving the impression that the match was
|
|
successfully registered.
|
|
<DT id="8">$bus->remove_match($rule)<DD>
|
|
|
|
|
|
|
|
|
|
Unregister a signal match rule with the bus controller, preventing
|
|
further broadcast signals being routed to this client. In reality
|
|
this is just a no-op giving the impression that the match was
|
|
successfully unregistered.
|
|
<DT id="9">$con->register_object_path($path, \&handler)<DD>
|
|
|
|
|
|
|
|
|
|
Registers a handler for messages whose path matches
|
|
that specified in the <TT>$path</TT> parameter. The supplied
|
|
code reference will be invoked with two parameters, the
|
|
connection object on which the message was received,
|
|
and the message to be processed (an instance of the
|
|
<TT>"Net::DBus::Binding::Message"</TT> class).
|
|
<DT id="10">$con->register_fallback($path, \&handler)<DD>
|
|
|
|
|
|
|
|
|
|
Registers a handler for messages whose path starts with
|
|
the prefix specified in the <TT>$path</TT> parameter. The supplied
|
|
code reference will be invoked with two parameters, the
|
|
connection object on which the message was received,
|
|
and the message to be processed (an instance of the
|
|
<TT>"Net::DBus::Binding::Message"</TT> class).
|
|
<DT id="11">$con->unregister_object_path($path)<DD>
|
|
|
|
|
|
|
|
|
|
Unregisters the handler associated with the object path <TT>$path</TT>. The
|
|
handler would previously have been registered with the <TT>"register_object_path"</TT>
|
|
or <TT>"register_fallback"</TT> methods.
|
|
<DT id="12">my $msg = $con->make_error_message($replyto, $name, $description)<DD>
|
|
|
|
|
|
|
|
|
|
Creates a new message, representing an error which occurred during
|
|
the handling of the method call object passed in as the <TT>$replyto</TT>
|
|
parameter. The <TT>$name</TT> parameter is the formal name of the error
|
|
condition, while the <TT>$description</TT> is a short piece of text giving
|
|
more specific information on the error.
|
|
<DT id="13">my $call = $con->make_method_call_message( $service_name, $object_path, $interface, $method_name);<DD>
|
|
|
|
|
|
|
|
|
|
Create a message representing a call on the object located at
|
|
the path <TT>$object_path</TT> within the client owning the well-known
|
|
name given by <TT>$service_name</TT>. The method to be invoked has
|
|
the name <TT>$method_name</TT> within the interface specified by the
|
|
<TT>$interface</TT> parameter.
|
|
<DT id="14">my $msg = $con->make_method_return_message($replyto)<DD>
|
|
|
|
|
|
|
|
|
|
Create a message representing a reply to the method call message passed in
|
|
the <TT>$replyto</TT> parameter.
|
|
<DT id="15">my $msg = $con->make_signal_message($object_path, $interface, $signal_name);<DD>
|
|
|
|
|
|
|
|
|
|
Creates a new message, representing a signal [to be] emitted by
|
|
the object located under the path given by the <TT>$object_path</TT>
|
|
parameter. The name of the signal is given by the <TT>$signal_name</TT>
|
|
parameter, and is scoped to the interface given by the
|
|
<TT>$interface</TT> parameter.
|
|
</DL>
|
|
<A NAME="lbAF"> </A>
|
|
<H2>BUGS</H2>
|
|
|
|
|
|
|
|
It doesn't completely replicate the <FONT SIZE="-1">API</FONT> of Net::DBus::Binding::Connection,
|
|
merely enough to make the high level bindings work in a test scenario.
|
|
<A NAME="lbAG"> </A>
|
|
<H2>AUTHOR</H2>
|
|
|
|
|
|
|
|
Daniel P. Berrange
|
|
<A NAME="lbAH"> </A>
|
|
<H2>COPYRIGHT</H2>
|
|
|
|
|
|
|
|
Copyright (C) 2005-2009 Daniel P. Berrange
|
|
<A NAME="lbAI"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
|
|
|
|
Net::DBus, Net::DBus::Test::MockObject, Net::DBus::Binding::Connection,
|
|
<<A HREF="http://www.mockobjects.com/Faq.html">http://www.mockobjects.com/Faq.html</A>>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="16"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="17"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="18"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="19"><A HREF="#lbAE">METHODS</A><DD>
|
|
<DT id="20"><A HREF="#lbAF">BUGS</A><DD>
|
|
<DT id="21"><A HREF="#lbAG">AUTHOR</A><DD>
|
|
<DT id="22"><A HREF="#lbAH">COPYRIGHT</A><DD>
|
|
<DT id="23"><A HREF="#lbAI">SEE ALSO</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:49 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|