File: matchrule_test.go

package info (click to toggle)
golang-go-dbus 1~bzr20150122-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 328 kB
  • sloc: makefile: 13
file content (46 lines) | stat: -rw-r--r-- 1,306 bytes parent folder | download
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
package dbus

import . "gopkg.in/check.v1"

func (s *S) TestMatchRuleToString(c *C) {
	mr := MatchRule{
		Type:      TypeSignal,
		Interface: "org.freedesktop.DBus",
		Member:    "Foo",
		Path:      "/bar/foo"}
	c.Check(mr.String(), Equals, "type='signal',path='/bar/foo',interface='org.freedesktop.DBus',member='Foo'")

	// A rule that doesn't match the member
	mr = MatchRule{
		Type:      TypeSignal,
		Interface: "com.example.Foo",
		Member:    "Bar"}
	c.Check(mr.String(), Equals, "type='signal',interface='com.example.Foo',member='Bar'")
}

func (s *S) TestMatchRuleMatch(c *C) {
	msg := NewSignalMessage("", "org.freedesktop.DBus", "NameOwnerChanged")
	_ = msg.AppendArgs("com.example.Foo", "", ":2.0")

	mr := MatchRule{
		Type:      TypeSignal,
		Interface: "org.freedesktop.DBus",
		Member:    "NameOwnerChanged"}
	c.Check(mr.Match(msg), Equals, true)

	mr = MatchRule{
		Type:      TypeSignal,
		Interface: "org.freedesktop.DBus",
		Member:    "NameAcquired"}
	c.Check(mr.Match(msg), Equals, false)

	// Check matching against first argument.
	mr = MatchRule{
		Type:      TypeSignal,
		Interface: "org.freedesktop.DBus",
		Member:    "NameOwnerChanged",
		Arg0:      "com.example.Foo"}
	c.Check(mr.Match(msg), Equals, true)
	mr.Arg0 = "com.example.Bar"
	c.Check(mr.Match(msg), Equals, false)
}