1Net::DBus::Test::MockMeUssseargeC(o3n)tributed Perl DocuNmeetn:t:aDtBiuosn::Test::MockMessage(3)
2
3
4
6 Net::DBus::Test::MockMessage - Fake a message object when unit testing
7
9 Sending a message
10
11 my $msg = new Net::DBus::Test::MockMessage;
12 my $iterator = $msg->iterator;
13
14 $iterator->append_byte(132);
15 $iterator->append_int32(14241);
16
17 $connection->send($msg);
18
20 This module provides a "mock" counterpart to the Net::DBus::Bind‐
21 ing::Message class. It is basically a pure Perl fake message object
22 providing the same contract as the real message object. It is intended
23 for use internally by the testing APIs.
24
26 my $call = Net::DBus::Test::MockMessage->new_method_call( service_name
27 => $service, object_path => $object, interface => $interface,
28 method_name => $name);
29 Create a message representing a call on the object located at the
30 path "object_path" within the client owning the well-known name
31 given by "service_name". The method to be invoked has the name
32 "method_name" within the interface specified by the "interface"
33 parameter.
34
35 my $msg = Net::DBus::Test::MockMessage->new_method_return( replyto =>
36 $method_call);
37 Create a message representing a reply to the method call passed in
38 the "replyto" parameter.
39
40 my $signal = Net::DBus::Test::MockMessage->new_signal( object_path =>
41 $path, interface => $interface, signal_name => $name);
42 Creates a new message, representing a signal [to be] emitted by the
43 object located under the path given by the "object_path" parameter.
44 The name of the signal is given by the "signal_name" parameter, and
45 is scoped to the interface given by the "interface" parameter.
46
47 my $msg = Net::DBus::Test::MockMessage->new_error( replyto =>
48 $method_call, name => $name, description => $description);
49 Creates a new message, representing an error which occurred during
50 the handling of the method call object passed in as the "replyto"
51 parameter. The "name" parameter is the formal name of the error
52 condition, while the "description" is a short piece of text giving
53 more specific information on the error.
54
55 my $type = $msg->get_type
56 Retrieves the type code for this message. The returned value corre‐
57 sponds to one of the four "Net::DBus::Test::MockMessage::MES‐
58 SAGE_TYPE_*" constants.
59
60 my $name = $msg->get_error_name
61 Returns the formal name of the error, as previously passed in via
62 the "name" parameter in the constructor.
63
64 my $interface = $msg->get_interface
65 Retrieves the name of the interface targetted by this message, pos‐
66 sibly an empty string if there is no applicable interface for this
67 message.
68
69 my $path = $msg->get_path
70 Retrieves the object path associated with the message, possibly an
71 empty string if there is no applicable object for this message.
72
73 my $name = $msg->get_destination
74 Retrieves the uniqe or well-known bus name for client intended to
75 be the recipient of the message. Possibly returns an empty string
76 if the message is being broadcast to all clients.
77
78 my $name = $msg->get_sender
79 Retireves the unique name of the client sending the message
80
81 my $serial = $msg->get_serial
82 Retrieves the unique serial number of this message. The number is
83 guarenteed unique for as long as the connection over which the mes‐
84 sage was sent remains open. May return zero, if the message is yet
85 to be sent.
86
87 my $name = $msg->get_member
88 For method calls, retrieves the name of the method to be invoked,
89 while for signals, retrieves the name of the signal.
90
91 $msg->set_sender($name)
92 Set the name of the client sending the message. The name must be
93 the unique name of the client.
94
95 $msg->set_destination($name)
96 Set the name of the intended recipient of the message. This is typ‐
97 ically used for signals to switch them from broadcast to unicast.
98
99 my $iterator = $msg->iterator;
100 Retrieves an iterator which can be used for reading or writing
101 fields of the message. The returned object is an instance of the
102 "Net::DBus::Binding::Iterator" class.
103
104 $boolean = $msg->get_no_reply()
105 Gets the flag indicating whether the message is expecting a reply
106 to be sent.
107
108 $msg->set_no_reply($boolean)
109 Toggles the flag indicating whether the message is expecting a
110 reply to be sent. All method call messages expect a reply by
111 default. By toggling this flag the communication latency is reduced
112 by removing the need for the client to wait
113
114 my @values = $msg->get_args_list
115 De-marshall all the values in the body of the message, using the
116 message signature to identify data types. The values are returned
117 as a list.
118
119 $msg->append_args_list(@values)
120 Append a set of values to the body of the message. Values will be
121 encoded as either a string, list or dictionary as appropriate to
122 their Perl data type. For more specific data typing needs, the
123 Net::DBus::Binding::Iterator object should be used instead.
124
125 my $sig = $msg->get_signature
126 Retrieves a string representing the type signature of the values
127 packed into the body of the message.
128
130 Net::DBus::Binding::Message, Net::DBus::Test::MockConnection,
131 Net::DBus::Test::MockIterator
132
134 Daniel Berrange <dan@berrange.com>
135
137 Copyright 2004 by Daniel Berrange
138
139
140
141perl v5.8.8 2008-02-20 Net::DBus::Test::MockMessage(3)