1--[[--------------------------------------------------------------------------
2
3  lgi testsuite, Gio DBus test suite.
4
5  Copyright (c) 2013 Pavel Holejsovsky
6  Licensed under the MIT license:
7  http://www.opensource.org/licenses/mit-license.php
8
9--]]--------------------------------------------------------------------------
10
11local lgi = require 'lgi'
12
13local check = testsuite.check
14
15-- Basic GLib testing
16local dbus = testsuite.group.new('dbus')
17
18function dbus.info_basic()
19   local Gio = lgi.Gio
20   local node = Gio.DBusNodeInfo {
21      path = '/some/path',
22      interfaces = {
23	 Gio.DBusInterfaceInfo {
24	    name = 'SomeInterface',
25	    methods = {
26	       Gio.DBusMethodInfo {
27		  name = 'SomeMethod',
28		  in_args = {
29		     Gio.DBusArgInfo {
30			name = 'args',
31			signature = 's',
32		     },
33		     Gio.DBusArgInfo {
34			name = 'argi',
35			signature = 'i',
36		     },
37		  },
38	       },
39	    },
40	    properties = {
41	       Gio.DBusPropertyInfo {
42		  name = 'someProperty',
43		  signature = 's',
44		  flags = { 'READABLE', 'WRITABLE' },
45	       },
46	    },
47	 },
48      },
49   }
50
51   check(node.path == '/some/path')
52   check(node.ref_count == 1)
53   check(node.interfaces[1].name == 'SomeInterface')
54   check(node.interfaces[1].methods[1].name == 'SomeMethod')
55   check(#node.interfaces[1].methods[1].in_args == 2)
56   check(node.interfaces[1].methods[1].in_args[1].name == 'args')
57   check(node.interfaces[1].methods[1].in_args[1].signature == 's')
58   check(node.interfaces[1].methods[1].in_args[2].name == 'argi')
59   check(node.interfaces[1].methods[1].in_args[2].signature == 'i')
60   check(#node.interfaces[1].methods[1].out_args == 0)
61   check(#node.interfaces[1].properties == 1)
62   check(node.interfaces[1].properties[1].name == 'someProperty')
63   check(node.interfaces[1].properties[1].signature == 's')
64   check(node.interfaces[1].properties[1].flags.READABLE)
65   check(node.interfaces[1].properties[1].flags.WRITABLE)
66end
67
68function dbus.info_xml()
69   local GLib = lgi.GLib
70   local Gio = lgi.Gio
71   local node = Gio.DBusNodeInfo {
72      path = '/some/path',
73      interfaces = {
74	 Gio.DBusInterfaceInfo {
75	    name = 'SomeInterface',
76	    methods = {
77	       Gio.DBusMethodInfo {
78		  name = 'SomeMethod',
79		  in_args = {
80		     Gio.DBusArgInfo {
81			name = 'args',
82			signature = 's',
83		     },
84		     Gio.DBusArgInfo {
85			name = 'argi',
86			signature = 'i',
87		     },
88		  },
89	       },
90	    },
91	    properties = {
92	       Gio.DBusPropertyInfo {
93		  name = 'someProperty',
94		  signature = 's',
95		  flags = { 'READABLE', 'WRITABLE' },
96	       },
97	    },
98	 },
99      },
100   }
101
102   local xml_builder = GLib.String('')
103   node:generate_xml(0, xml_builder)
104   local xml = node.xml
105   check(xml_builder.str == xml)
106
107   local node = Gio.DBusNodeInfo.new_for_xml(xml)
108   check(node)
109   check(node.path == '/some/path')
110   check(node.ref_count == 1)
111   check(node.interfaces[1].name == 'SomeInterface')
112   check(node.interfaces[1].methods[1].name == 'SomeMethod')
113   check(#node.interfaces[1].methods[1].in_args == 2)
114   check(node.interfaces[1].methods[1].in_args[1].name == 'args')
115   check(node.interfaces[1].methods[1].in_args[1].signature == 's')
116   check(node.interfaces[1].methods[1].in_args[2].name == 'argi')
117   check(node.interfaces[1].methods[1].in_args[2].signature == 'i')
118   check(#node.interfaces[1].methods[1].out_args == 0)
119   check(#node.interfaces[1].properties == 1)
120   check(node.interfaces[1].properties[1].name == 'someProperty')
121   check(node.interfaces[1].properties[1].signature == 's')
122   check(node.interfaces[1].properties[1].flags.READABLE)
123   check(node.interfaces[1].properties[1].flags.WRITABLE)
124end
125
126function dbus.proxy_get_interface_info()
127   local Gio = lgi.Gio
128
129   local interface = Gio.DBusInterfaceInfo {
130      name = 'SomeInterface'
131   }
132   local bus = Gio.bus_get_sync(Gio.BusType.SESSION)
133   local proxy, err = Gio.DBusProxy.new_sync(bus, Gio.DBusProxyFlags.NONE, interface, "org.foo", "/", "org.foo.SomeInterface", nil)
134   assert(proxy, err)
135
136   local interface2 = proxy:get_interface_info()
137
138   -- Just so that we do test something
139   assert(interface == interface2)
140end
141