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
|
# -*- perl -*-
use Test::More tests => 6;
use strict;
use warnings;
BEGIN {
use_ok('Net::DBus::Binding::Introspector');
};
TEST_ONE: {
my $other_object = Net::DBus::Binding::Introspector->new(
object_path => "org.example.Object.OtherObject",
interfaces => {
"org.example.SomeInterface" => {
methods => {
"hello" => {
params => ["int32", "int32", ["struct", "int32","byte"]],
returns => ["int32"],
paramnames => ["wibble", "eek"],
returnnames => ["frob"],
},
"goodbye" => {
params => [["array", ["struct", "int32", "string"]]],
returns => ["string", "string"],
paramnames => ["ooh"],
returnnames => ["ahh", "eek"],
},
},
signals => {
"meltdown" => {
params => ["int32", "byte"],
}
},
props => {
"name" => { type => "string", access => "readwrite"},
"email" => { type => "string", access => "read"},
"age" => { type => "int32", access => "read"},
"parents" => { type => ["array", "string"], access => "readwrite" },
},
}
});
isa_ok($other_object, "Net::DBus::Binding::Introspector");
my $other_xml_got = $other_object->format();
my $other_xml_expect = <<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.Object.OtherObject">
<interface name="org.example.SomeInterface">
<method name="goodbye">
<arg name="ooh" type="a(is)" direction="in"/>
<arg name="ahh" type="s" direction="out"/>
<arg name="eek" type="s" direction="out"/>
</method>
<method name="hello">
<arg name="wibble" type="i" direction="in"/>
<arg name="eek" type="i" direction="in"/>
<arg type="(iy)" direction="in"/>
<arg name="frob" type="i" direction="out"/>
</method>
<signal name="meltdown">
<arg type="i"/>
<arg type="y"/>
</signal>
<property name="age" type="i" access="read"/>
<property name="email" type="s" access="read"/>
<property name="name" type="s" access="readwrite"/>
<property name="parents" type="as" access="readwrite"/>
</interface>
</node>
EOF
is($other_xml_got, $other_xml_expect, "xml data matches");
my $object = Net::DBus::Binding::Introspector->new(
object_path => "org.example.Object",
interfaces => {
"org.example.SomeInterface" => {
methods => {
"hello" => {
params => ["int32", "int32", ["struct", "int32","byte"]],
returns => ["uint32"],
paramnames => [],
returnnames => [],
},
"goodbye" => {
params => [["array", ["dict", "int32", "string"]]],
returns => ["string", ["array", "string"]],
paramnames => [],
returnnames => [],
},
},
signals => {
"meltdown" => {
params => ["int32", "byte"],
paramnames => [],
}
},
},
"org.example.OtherInterface" => {
methods => {
"hitme" => {
params => ["int32", "uint32"],
return => [],
paramnames => [],
returnnames => [],
}
},
props => {
"title" => { type => "string", access => "readwrite"},
"salary" => { type => "int32", access => "read"},
},
},
},
children => [
"org.example.Object.SubObject",
$other_object,
]);
isa_ok($object, "Net::DBus::Binding::Introspector");
my $object_xml_got = $object->format();
my $object_xml_expect = <<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.Object">
<interface name="org.example.OtherInterface">
<method name="hitme">
<arg type="i" direction="in"/>
<arg type="u" direction="in"/>
</method>
<property name="salary" type="i" access="read"/>
<property name="title" type="s" access="readwrite"/>
</interface>
<interface name="org.example.SomeInterface">
<method name="goodbye">
<arg type="aa{is}" direction="in"/>
<arg type="s" direction="out"/>
<arg type="as" direction="out"/>
</method>
<method name="hello">
<arg type="i" direction="in"/>
<arg type="i" direction="in"/>
<arg type="(iy)" direction="in"/>
<arg type="u" direction="out"/>
</method>
<signal name="meltdown">
<arg type="i"/>
<arg type="y"/>
</signal>
</interface>
<node name="org.example.Object.SubObject"/>
<node name="org.example.Object.OtherObject">
<interface name="org.example.SomeInterface">
<method name="goodbye">
<arg name="ooh" type="a(is)" direction="in"/>
<arg name="ahh" type="s" direction="out"/>
<arg name="eek" type="s" direction="out"/>
</method>
<method name="hello">
<arg name="wibble" type="i" direction="in"/>
<arg name="eek" type="i" direction="in"/>
<arg type="(iy)" direction="in"/>
<arg name="frob" type="i" direction="out"/>
</method>
<signal name="meltdown">
<arg type="i"/>
<arg type="y"/>
</signal>
<property name="age" type="i" access="read"/>
<property name="email" type="s" access="read"/>
<property name="name" type="s" access="readwrite"/>
<property name="parents" type="as" access="readwrite"/>
</interface>
</node>
</node>
EOF
is($object_xml_got, $object_xml_expect, "xml data matches");
my $recon_other = Net::DBus::Binding::Introspector->new(xml => $object_xml_got);
my $object_xml_got_again = $recon_other->format();
is($object_xml_got_again, $object_xml_expect, "reconstructed xml matches");
}
|