forked from chamaken/cgolmnfct
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpect_test.go
161 lines (149 loc) · 4.86 KB
/
expect_test.go
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
package cgolmnfct_test
import (
nfct "github.com/chamaken/cgolmnfct"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"fmt"
"os"
"syscall"
"unsafe"
)
// almost just calling them
var _ = Describe("Cpylmnfct Expect", func() {
fmt.Fprintf(os.Stdout, "Hello, expect tester!\n")
Context("Construct and Destruct", func() {
It("should success", func() {
exp, err := nfct.NewExpect()
defer exp.Destroy()
Expect(err).To(BeNil())
})
})
Context("Clone", func() {
It("should have different addr", func() {
exp, _ := nfct.NewExpect()
defer exp.Destroy()
clone, err := exp.Clone()
Expect(err).To(BeNil())
defer clone.Destroy()
Expect(exp == clone).To(BeFalse())
})
It("should have same attr value", func() {
exp, _ := nfct.NewExpect()
defer exp.Destroy()
exp.SetAttrU32(nfct.ATTR_EXP_TIMEOUT, 0x12345678)
clone, err := exp.Clone()
Expect(err).To(BeNil())
defer clone.Destroy()
v, _ := clone.AttrU32(nfct.ATTR_EXP_TIMEOUT)
Expect(v).To(Equal(uint32(0x12345678)))
})
})
Context("cmp", func() {
It("shoule work with NFCT_CMP_STRING flag (XXX: no NFCT_CMP_MASK)", func() {
s := "abcdefghijklmn"
exp1, _ := nfct.NewExpect()
defer exp1.Destroy()
exp1.SetAttrU32(nfct.ATTR_EXP_TIMEOUT, 0x12345678)
exp1.SetAttrU16(nfct.ATTR_EXP_ZONE, 0x4321)
exp1.SetAttrU32(nfct.ATTR_EXP_FLAGS, 0x77777777)
exp1.SetAttr(nfct.ATTR_EXP_FN, unsafe.Pointer(&s))
exp2, _ := nfct.NewExpect()
defer exp2.Destroy()
exp2.SetAttrU32(nfct.ATTR_EXP_TIMEOUT, 0x12345678)
exp2.SetAttrU16(nfct.ATTR_EXP_ZONE, 0x4321)
exp2.SetAttrU32(nfct.ATTR_EXP_FLAGS, 0x55555555)
exp2.SetAttrPtr(nfct.ATTR_EXP_FN, &s)
Expect(exp1.Cmp(exp2, nfct.NFCT_CMP_STRICT)).To(BeZero())
exp2.SetAttrU32(nfct.ATTR_EXP_FLAGS, 0x77777777)
Expect(exp1.Cmp(exp2, nfct.NFCT_CMP_STRICT)).To(Equal(1))
})
})
Context("attr set/get", func() {
It("should set/get with raw value", func() {
v1 := uint32(0x87654321)
v2 := uint32(0x33333333)
exp, _ := nfct.NewExpect()
defer exp.Destroy()
err := exp.SetAttr(nfct.ATTR_EXP_CLASS, unsafe.Pointer(&v1))
Expect(err).To(BeNil())
ret, err := exp.Attr(nfct.ATTR_EXP_CLASS)
Expect(*((*uint32)(ret))).To(Equal(v1))
err = exp.SetAttrPtr(nfct.ATTR_EXP_CLASS, &v2)
Expect(err).To(BeNil())
ret, err = exp.Attr(nfct.ATTR_EXP_CLASS)
Expect(*((*uint32)(ret))).To(Equal(v2))
err = exp.SetAttrPtr(nfct.ATTR_EXP_MAX, &v1)
Expect(err).To(Equal(syscall.EINVAL))
_, err = exp.Attr(nfct.ATTR_EXP_MAX)
Expect(err).To(Equal(syscall.EINVAL))
})
It("should set/get with u8", func() {
exp, _ := nfct.NewExpect()
defer exp.Destroy()
err := exp.SetAttrU8(nfct.ATTR_EXP_NAT_DIR, 127)
Expect(err).To(BeNil())
ret, err := exp.AttrU8(nfct.ATTR_EXP_NAT_DIR)
Expect(err).To(BeNil())
Expect(ret).To(Equal(uint8(127)))
err = exp.SetAttrU8(nfct.ATTR_EXP_MAX, 127)
Expect(err).To(Equal(syscall.EINVAL))
_, err = exp.AttrU8(nfct.ATTR_EXP_MAX)
Expect(err).To(Equal(syscall.EINVAL))
})
It("should set/get u16", func() {
exp, _ := nfct.NewExpect()
defer exp.Destroy()
err := exp.SetAttrU16(nfct.ATTR_EXP_ZONE, 0x3333)
Expect(err).To(BeNil())
ret, err := exp.AttrU16(nfct.ATTR_EXP_ZONE)
Expect(err).To(BeNil())
Expect(ret).To(Equal(uint16(0x3333)))
err = exp.SetAttrU16(nfct.ATTR_EXP_MAX, 0x3333)
Expect(err).To(Equal(syscall.EINVAL))
_, err = exp.AttrU16(nfct.ATTR_EXP_MAX)
Expect(err).To(Equal(syscall.EINVAL))
})
It("should set/get u32", func() {
exp, _ := nfct.NewExpect()
defer exp.Destroy()
err := exp.SetAttrU32(nfct.ATTR_EXP_CLASS, 0x13135757)
Expect(err).To(BeNil())
ret, err := exp.AttrU32(nfct.ATTR_EXP_CLASS)
Expect(err).To(BeNil())
Expect(ret).To(Equal(uint32(0x13135757)))
err = exp.SetAttrU32(nfct.ATTR_EXP_MAX, 0x13135757)
Expect(err).To(Equal(syscall.EINVAL))
_, err = exp.AttrU32(nfct.ATTR_EXP_MAX)
Expect(err).To(Equal(syscall.EINVAL))
})
})
Context("attr set/unset", func() {
It("should set/unset attrs", func() {
exp, _ := nfct.NewExpect()
exp.SetAttrU32(nfct.ATTR_EXP_TIMEOUT, 0x12345678)
exp.SetAttrU16(nfct.ATTR_EXP_ZONE, 0x4321)
ret, err := exp.AttrIsSet(nfct.ATTR_EXP_TIMEOUT)
Expect(err).To(BeNil())
Expect(ret).To(BeTrue())
ret, err = exp.AttrIsSet(nfct.ATTR_EXP_ZONE)
Expect(err).To(BeNil())
Expect(ret).To(BeTrue())
err = exp.AttrUnset(nfct.ATTR_EXP_TIMEOUT)
Expect(err).To(BeNil())
ret, err = exp.AttrIsSet(nfct.ATTR_EXP_TIMEOUT)
Expect(err).To(BeNil())
Expect(ret).To(BeFalse())
ret, err = exp.AttrIsSet(nfct.ATTR_EXP_ZONE)
Expect(err).To(BeNil())
Expect(ret).To(BeTrue())
err = exp.AttrUnset(nfct.ATTR_EXP_MAX)
Expect(err).To(Equal(syscall.EINVAL))
ret, err = exp.AttrIsSet(nfct.ATTR_EXP_MAX)
Expect(err).To(Equal(syscall.EINVAL))
Expect(ret).To(BeFalse())
})
})
// XXX: Expect.snprintf
// XXX: Expect.nlmsg_build
// XXX: Expect.nlmsg_parse
})