File: dbus.lua

package info (click to toggle)
lua-lgi 0.9.2-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,388 kB
  • sloc: ansic: 5,082; makefile: 169; sh: 31
file content (140 lines) | stat: -rw-r--r-- 4,101 bytes parent folder | download | duplicates (4)
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
--[[--------------------------------------------------------------------------

  lgi testsuite, Gio DBus test suite.

  Copyright (c) 2013 Pavel Holejsovsky
  Licensed under the MIT license:
  http://www.opensource.org/licenses/mit-license.php

--]]--------------------------------------------------------------------------

local lgi = require 'lgi'

local check = testsuite.check

-- Basic GLib testing
local dbus = testsuite.group.new('dbus')

function dbus.info_basic()
   local Gio = lgi.Gio
   local node = Gio.DBusNodeInfo {
      path = '/some/path',
      interfaces = {
	 Gio.DBusInterfaceInfo {
	    name = 'SomeInterface',
	    methods = {
	       Gio.DBusMethodInfo {
		  name = 'SomeMethod',
		  in_args = {
		     Gio.DBusArgInfo {
			name = 'args',
			signature = 's',
		     },
		     Gio.DBusArgInfo {
			name = 'argi',
			signature = 'i',
		     },
		  },
	       },
	    },
	    properties = {
	       Gio.DBusPropertyInfo {
		  name = 'someProperty',
		  signature = 's',
		  flags = { 'READABLE', 'WRITABLE' },
	       },
	    },
	 },
      },
   }

   check(node.path == '/some/path')
   check(node.ref_count == 1)
   check(node.interfaces[1].name == 'SomeInterface')
   check(node.interfaces[1].methods[1].name == 'SomeMethod')
   check(#node.interfaces[1].methods[1].in_args == 2)
   check(node.interfaces[1].methods[1].in_args[1].name == 'args')
   check(node.interfaces[1].methods[1].in_args[1].signature == 's')
   check(node.interfaces[1].methods[1].in_args[2].name == 'argi')
   check(node.interfaces[1].methods[1].in_args[2].signature == 'i')
   check(#node.interfaces[1].methods[1].out_args == 0)
   check(#node.interfaces[1].properties == 1)
   check(node.interfaces[1].properties[1].name == 'someProperty')
   check(node.interfaces[1].properties[1].signature == 's')
   check(node.interfaces[1].properties[1].flags.READABLE)
   check(node.interfaces[1].properties[1].flags.WRITABLE)
end

function dbus.info_xml()
   local GLib = lgi.GLib
   local Gio = lgi.Gio
   local node = Gio.DBusNodeInfo {
      path = '/some/path',
      interfaces = {
	 Gio.DBusInterfaceInfo {
	    name = 'SomeInterface',
	    methods = {
	       Gio.DBusMethodInfo {
		  name = 'SomeMethod',
		  in_args = {
		     Gio.DBusArgInfo {
			name = 'args',
			signature = 's',
		     },
		     Gio.DBusArgInfo {
			name = 'argi',
			signature = 'i',
		     },
		  },
	       },
	    },
	    properties = {
	       Gio.DBusPropertyInfo {
		  name = 'someProperty',
		  signature = 's',
		  flags = { 'READABLE', 'WRITABLE' },
	       },
	    },
	 },
      },
   }

   local xml_builder = GLib.String('')
   node:generate_xml(0, xml_builder)
   local xml = node.xml
   check(xml_builder.str == xml)

   local node = Gio.DBusNodeInfo.new_for_xml(xml)
   check(node)
   check(node.path == '/some/path')
   check(node.ref_count == 1)
   check(node.interfaces[1].name == 'SomeInterface')
   check(node.interfaces[1].methods[1].name == 'SomeMethod')
   check(#node.interfaces[1].methods[1].in_args == 2)
   check(node.interfaces[1].methods[1].in_args[1].name == 'args')
   check(node.interfaces[1].methods[1].in_args[1].signature == 's')
   check(node.interfaces[1].methods[1].in_args[2].name == 'argi')
   check(node.interfaces[1].methods[1].in_args[2].signature == 'i')
   check(#node.interfaces[1].methods[1].out_args == 0)
   check(#node.interfaces[1].properties == 1)
   check(node.interfaces[1].properties[1].name == 'someProperty')
   check(node.interfaces[1].properties[1].signature == 's')
   check(node.interfaces[1].properties[1].flags.READABLE)
   check(node.interfaces[1].properties[1].flags.WRITABLE)
end

function dbus.proxy_get_interface_info()
   local Gio = lgi.Gio

   local interface = Gio.DBusInterfaceInfo {
      name = 'SomeInterface'
   }
   local bus = Gio.bus_get_sync(Gio.BusType.SESSION)
   local proxy, err = Gio.DBusProxy.new_sync(bus, Gio.DBusProxyFlags.NONE, interface, "org.foo", "/", "org.foo.SomeInterface", nil)
   assert(proxy, err)

   local interface2 = proxy:get_interface_info()

   -- Just so that we do test something
   assert(interface == interface2)
end