File: types_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 (68 lines) | stat: -rw-r--r-- 1,986 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package dbus

import . "gopkg.in/check.v1"

func (s *S) TestSignatureNextType(c *C) {
	// NextType() works for basic types
	for _, sig := range []Signature{"y", "b", "n", "q", "i", "u", "x", "t", "d", "s", "o", "g", "v", "h"} {
		next, err := sig.NextType(0)
		c.Check(next, Equals, 1)
		c.Check(err, Equals, nil)
	}

	// Unknown type code gives error
	next, err := Signature("_").NextType(0)
	c.Check(err, Not(Equals), nil)

	// Offset inside signature
	next, err = Signature("ii").NextType(1)
	c.Check(next, Equals, 2)
	c.Check(err, Equals, nil)

	// Error if there is no more type codes in signature
	next, err = Signature("i").NextType(1)
	c.Check(err, Not(Equals), nil)

	// Arrays consume their element type code
	next, err = Signature("ai").NextType(0)
	c.Check(next, Equals, 2)
	c.Check(err, Equals, nil)

	// Array without element type code gives error
	next, err = Signature("a").NextType(0)
	c.Check(err, Not(Equals), nil)

	// Structs are consumed entirely
	next, err = Signature("(isv)").NextType(0)
	c.Check(next, Equals, 5)
	c.Check(err, Equals, nil)

	// Incomplete struct gives error
	next, err = Signature("(isv").NextType(0)
	c.Check(err, Not(Equals), nil)

	// Dict entries have two contained type codes
	next, err = Signature("{ii}").NextType(0)
	c.Check(next, Equals, 4)
	c.Check(err, Equals, nil)

	next, err = Signature("{}").NextType(0)
	c.Check(err, Not(Equals), nil)
	next, err = Signature("{i}").NextType(0)
	c.Check(err, Not(Equals), nil)
	next, err = Signature("{iii}").NextType(0)
	c.Check(err, Not(Equals), nil)
	next, err = Signature("{ii").NextType(0)
	c.Check(err, Not(Equals), nil)

	// Now a recursive type combining the above.
	next, err = Signature("a{s(saax)}").NextType(0)
	c.Check(next, Equals, 10)
	c.Check(err, Equals, nil)
}

func (s *S) TestSignatureValidate(c *C) {
	c.Check(Signature("a{s(sax)}aav").Validate(), Equals, nil)
	c.Check(Signature("a").Validate(), Not(Equals), nil)
	c.Check(Signature("a(ii").Validate(), Not(Equals), nil)
}