1Net::DBus::Test::MockCoUnsneerctCioonnt(r3i)buted Perl DNoectu:m:eDnBtuast:i:oTnest::MockConnection(3)
2
3
4

NAME

6       Net::DBus::Test::MockConnection - Fake a connection to the bus unit
7       testing
8

SYNOPSIS

10         use Net::DBus;
11
12         my $bus = Net::DBus->test
13
14         # Register a service, and the objec to be tested
15         use MyObject
16         my $service = $bus->export_service("org.example.MyService");
17         my $object = MyObject->new($service);
18
19
20         # Acquire the service & do tests
21         my $remote_service = $bus->get_service('org.example.MyService');
22         my $remote_object = $service->get_object("/org/example/MyObjct");
23
24         # This traverses the mock connection, eventually
25         # invoking 'testSomething' on the $object above.
26         $remote_object->testSomething()
27

DESCRIPTION

29       This object provides a fake implementation of the
30       Net::DBus::Binding::Connection enabling a pure 'in-memory' message bus
31       to be mocked up. This is intended to facilitate creation of unit tests
32       for services which would otherwise need to call out to other object on
33       a live message bus. It is used as a companion to the
34       Net::DBus::Test::MockObject module which is how fake objects are to be
35       provided on the fake bus.
36

METHODS

38       my $con = Net::DBus::Test::MockConnection->new()
39           Create a new mock connection object instance. It is not usually
40           necessary to create instances of this object directly, instead the
41           "test" method on the Net::DBus object can be used to get a handle
42           to a test bus.
43
44       $con->send($message)
45           Send a message over the mock connection. If the message is a method
46           call, it will be dispatched straight to any corresponding mock
47           object registered. If the message is an error or method return it
48           will be made available as a return value for the
49           "send_with_reply_and_block" method. If the message is a signal it
50           will be queued up for processing by the "dispatch" method.
51
52       $bus->request_name($service_name)
53           Pretend to send a request to the bus registering the well known
54           name specified in the $service_name parameter. In reality this is
55           just a no-op giving the impression that the name was successfully
56           registered.
57
58       my $reply = $con->send_with_reply_and_block($msg)
59           Send a message over the mock connection and wait for a reply. The
60           $msg should be an instance of
61           "Net::DBus::Binding::Message::MethodCall" and the return $reply
62           will be an instance of "Net::DBus::Binding::Message::MethodReturn".
63           It is also possible that an error will be thrown, with the thrown
64           error being blessed into the "Net::DBus::Error" class.
65
66       $con->dispatch;
67           Dispatches any pending messages in the incoming queue to their
68           message handlers. This method should be called by test suites
69           whenever they anticipate that there are pending signals to be dealt
70           with.
71
72       $con->add_filter($coderef);
73           Adds a filter to the connection which will be invoked whenever a
74           message is received. The $coderef should be a reference to a
75           subroutine, which returns a true value if the message should be
76           filtered out, or a false value if the normal message dispatch
77           should be performed.
78
79       $bus->add_match($rule)
80           Register a signal match rule with the bus controller, allowing
81           matching broadcast signals to routed to this client. In reality
82           this is just a no-op giving the impression that the match was
83           successfully registered.
84
85       $bus->remove_match($rule)
86           Unregister a signal match rule with the bus controller, preventing
87           further broadcast signals being routed to this client. In reality
88           this is just a no-op giving the impression that the match was
89           successfully unregistered.
90
91       $con->register_object_path($path, \&handler)
92           Registers a handler for messages whose path matches that specified
93           in the $path parameter. The supplied code reference will be invoked
94           with two parameters, the connection object on which the message was
95           received, and the message to be processed (an instance of the
96           "Net::DBus::Binding::Message" class).
97
98       $con->register_fallback($path, \&handler)
99           Registers a handler for messages whose path starts with the prefix
100           specified in the $path parameter. The supplied code reference will
101           be invoked with two parameters, the connection object on which the
102           message was received, and the message to be processed (an instance
103           of the "Net::DBus::Binding::Message" class).
104
105       $con->unregister_object_path($path)
106           Unregisters the handler associated with the object path $path. The
107           handler would previously have been registered with the
108           "register_object_path" or "register_fallback" methods.
109
110       my $msg = $con->make_error_message($replyto, $name, $description)
111           Creates a new message, representing an error which occurred during
112           the handling of the method call object passed in as the $replyto
113           parameter. The $name parameter is the formal name of the error
114           condition, while the $description is a short piece of text giving
115           more specific information on the error.
116
117       my $call = $con->make_method_call_message( $service_name, $object_path,
118       $interface, $method_name);
119           Create a message representing a call on the object located at the
120           path $object_path within the client owning the well-known name
121           given by $service_name. The method to be invoked has the name
122           $method_name within the interface specified by the $interface
123           parameter.
124
125       my $msg = $con->make_method_return_message($replyto)
126           Create a message representing a reply to the method call message
127           passed in the $replyto parameter.
128
129       my $msg = $con->make_signal_message($object_path, $interface,
130       $signal_name);
131           Creates a new message, representing a signal [to be] emitted by the
132           object located under the path given by the $object_path parameter.
133           The name of the signal is given by the $signal_name parameter, and
134           is scoped to the interface given by the $interface parameter.
135

BUGS

137       It doesn't completely replicate the API of
138       Net::DBus::Binding::Connection, merely enough to make the high level
139       bindings work in a test scenario.
140

AUTHOR

142       Daniel P. Berrange
143
145       Copyright (C) 2005-2009 Daniel P. Berrange
146

SEE ALSO

148       Net::DBus, Net::DBus::Test::MockObject, Net::DBus::Binding::Connection,
149       <http://www.mockobjects.com/Faq.html>
150
151
152
153perl v5.34.0                      2021-07-22Net::DBus::Test::MockConnection(3)
Impressum