1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
# -*- perl -*-
use Test::More tests => 94;
use strict;
use warnings;
package MyObject1;
use strict;
use warnings;
use Test::More;
use base qw(Net::DBus::Object);
use Net::DBus;
use Net::DBus::Service;
use Net::DBus::Exporter qw(org.example.MyObject);
my $bus = Net::DBus->test;
my $service = $bus->export_service("org.example.MyService");
my $obj = MyObject1->new($service, "/org/example/MyObject");
# First the full APIs
dbus_method("Everything", ["string"], ["int32"]);
dbus_method("EverythingInterface", ["string"], ["int32"], "org.example.OtherObject");
# Now add in annotations to the mix
dbus_method("EverythingAnnotate", ["string"], ["int32"], { deprecated => 1,
no_return => 1 });
dbus_method("EverythingNegativeAnnotate", ["string"], ["int32"], { deprecated => 0,
no_return => 0 });
dbus_method("EverythingInterfaceAnnotate", ["string"], ["int32"], "org.example.OtherObject", { deprecated => 1,
no_return => 1 });
dbus_method("EverythingInterfaceNegativeAnnotate", ["string"], ["int32"], "org.example.OtherObject", { deprecated => 0,
no_return => 0 });
# Now test 'defaults'
dbus_method("NoArgsReturns");
dbus_method("NoReturns", ["string"], [], { param_names => ["wizz"] });
dbus_method("NoArgs",[],["int32"]);
dbus_method("NoArgsReturnsInterface", "org.example.OtherObject");
dbus_method("NoReturnsInterface", ["string"], "org.example.OtherObject");
dbus_method("NoArgsInterface", [],["int32"], "org.example.OtherObject");
dbus_method("NoArgsReturnsAnnotate", { deprecated => 1 });
dbus_method("NoReturnsAnnotate", ["string"], { deprecated => 1 });
dbus_method("NoArgsAnnotate",[],["int32"], { deprecated => 1 });
dbus_method("NoArgsReturnsInterfaceAnnotate", "org.example.OtherObject", { deprecated => 1 });
dbus_method("NoReturnsInterfaceAnnotate", ["string"], "org.example.OtherObject", { deprecated => 1, param_names => ["one"] });
dbus_method("NoArgsInterfaceAnnotate", [],["int32"], "org.example.OtherObject", { deprecated => 1, return_names => ["two"] });
dbus_method("DemoInterfaceName1", [], ["string"], "_org.example._some_9object");
eval {
dbus_method("DemoInterfaceName2", [], ["string"], "9org.example.SomeObject");
};
ok($@ ne "", "raised error for leading digit in interface");
my $ins = Net::DBus::Exporter::_dbus_introspector(ref($obj));
ok($ins->has_interface("org.example.MyObject"), "interface registration");
ok(!$ins->has_interface("org.example.BogusObject"), "-ve interface registration");
my $wantxml = <<EOF;
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="/org/example/MyObject">
<interface name="_org.example._some_9object">
<method name="DemoInterfaceName1">
<arg type="s" direction="out"/>
</method>
</interface>
<interface name="org.example.MyObject">
<method name="Everything">
<arg type="s" direction="in"/>
<arg type="i" direction="out"/>
</method>
<method name="EverythingAnnotate">
<arg type="s" direction="in"/>
<arg type="i" direction="out"/>
<annotation name="org.freedesktop.DBus.Deprecated" value="true"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="EverythingNegativeAnnotate">
<arg type="s" direction="in"/>
<arg type="i" direction="out"/>
</method>
<method name="NoArgs">
<arg type="i" direction="out"/>
</method>
<method name="NoArgsAnnotate">
<arg type="i" direction="out"/>
<annotation name="org.freedesktop.DBus.Deprecated" value="true"/>
</method>
<method name="NoArgsReturns">
</method>
<method name="NoArgsReturnsAnnotate">
<annotation name="org.freedesktop.DBus.Deprecated" value="true"/>
</method>
<method name="NoReturns">
<arg name="wizz" type="s" direction="in"/>
</method>
<method name="NoReturnsAnnotate">
<arg type="s" direction="in"/>
<annotation name="org.freedesktop.DBus.Deprecated" value="true"/>
</method>
</interface>
<interface name="org.example.OtherObject">
<method name="EverythingInterface">
<arg type="s" direction="in"/>
<arg type="i" direction="out"/>
</method>
<method name="EverythingInterfaceAnnotate">
<arg type="s" direction="in"/>
<arg type="i" direction="out"/>
<annotation name="org.freedesktop.DBus.Deprecated" value="true"/>
<annotation name="org.freedesktop.DBus.Method.NoReply" value="true"/>
</method>
<method name="EverythingInterfaceNegativeAnnotate">
<arg type="s" direction="in"/>
<arg type="i" direction="out"/>
</method>
<method name="NoArgsInterface">
<arg type="i" direction="out"/>
</method>
<method name="NoArgsInterfaceAnnotate">
<arg name="two" type="i" direction="out"/>
<annotation name="org.freedesktop.DBus.Deprecated" value="true"/>
</method>
<method name="NoArgsReturnsInterface">
</method>
<method name="NoArgsReturnsInterfaceAnnotate">
<annotation name="org.freedesktop.DBus.Deprecated" value="true"/>
</method>
<method name="NoReturnsInterface">
<arg type="s" direction="in"/>
</method>
<method name="NoReturnsInterfaceAnnotate">
<arg name="one" type="s" direction="in"/>
<annotation name="org.freedesktop.DBus.Deprecated" value="true"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg type="s" direction="out"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Properties">
<method name="Get">
<arg type="s" direction="in"/>
<arg type="s" direction="in"/>
<arg type="v" direction="out"/>
</method>
<method name="GetAll">
<arg type="s" direction="in"/>
<arg type="a{sv}" direction="out"/>
</method>
<method name="Set">
<arg type="s" direction="in"/>
<arg type="s" direction="in"/>
<arg type="v" direction="in"/>
</method>
</interface>
</node>
EOF
is ($ins->format($obj), $wantxml, "xml matches");
&check_method($ins, "Everything", ["string"], ["int32"], "org.example.MyObject", 0, 0);
&check_method($ins, "EverythingInterface", ["string"], ["int32"], "org.example.OtherObject", 0, 0);
&check_method($ins, "EverythingAnnotate", ["string"], ["int32"], "org.example.MyObject", 1, 1);
&check_method($ins, "EverythingNegativeAnnotate", ["string"], ["int32"], "org.example.MyObject", 0, 0);
&check_method($ins, "EverythingInterfaceAnnotate", ["string"], ["int32"], "org.example.OtherObject", 1, 1);
&check_method($ins, "EverythingInterfaceNegativeAnnotate", ["string"], ["int32"], "org.example.OtherObject", 0, 0);
&check_method($ins, "NoArgsReturns", [], [], "org.example.MyObject", 0, 0);
&check_method($ins, "NoReturns", ["string"], [], "org.example.MyObject", 0, 0);
&check_method($ins, "NoArgs", [], ["int32"], "org.example.MyObject", 0, 0);
&check_method($ins, "NoArgsReturnsInterface", [], [], "org.example.OtherObject", 0, 0);
&check_method($ins, "NoReturnsInterface", ["string"], [], "org.example.OtherObject", 0, 0);
&check_method($ins, "NoArgsInterface", [], ["int32"], "org.example.OtherObject", 0, 0);
&check_method($ins, "NoArgsReturnsAnnotate", [], [], "org.example.MyObject", 1, 0);
&check_method($ins, "NoReturnsAnnotate", ["string"], [], "org.example.MyObject", 1, 0);
&check_method($ins, "NoArgsAnnotate", [], ["int32"], "org.example.MyObject", 1, 0);
&check_method($ins, "NoArgsReturnsInterfaceAnnotate", [], [], "org.example.OtherObject", 1, 0);
&check_method($ins, "NoReturnsInterfaceAnnotate", ["string"], [], "org.example.OtherObject", 1, 0);
&check_method($ins, "NoArgsInterfaceAnnotate", [], ["int32"], "org.example.OtherObject", 1, 0);
sub check_method {
my $ins = shift;
my $name = shift;
my $params = shift;
my $returns = shift;
my $interface = shift;
my $deprecated = shift;
my $no_return = shift;
my @interfaces = $ins->has_method($name);
is_deeply([$interface], \@interfaces, "method interface mapping");
my @params = $ins->get_method_params($interface, $name);
is_deeply($params, \@params, "method parameters");
my @returns = $ins->get_method_returns($interface, $name);
is_deeply($returns, \@returns, "method returneters");
if ($deprecated) {
ok($ins->is_method_deprecated($name, $interface), "method deprecated");
} else {
ok(!$ins->is_method_deprecated($name, $interface), "method deprecated");
}
if ($no_return) {
ok(!$ins->does_method_reply($name, $interface), "method no reply");
} else {
ok($ins->does_method_reply($name, $interface), "method no reply");
}
}
|