-
Notifications
You must be signed in to change notification settings - Fork 5
/
opcbrowser_test.go
154 lines (145 loc) · 3.56 KB
/
opcbrowser_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
package opcda
import (
"fmt"
"testing"
"github.com/huskar-t/opcda/com"
"github.com/stretchr/testify/assert"
)
func TestOPCBrowser(t *testing.T) {
server, err := Connect(TestProgID, TestHost)
assert.NoError(t, err)
defer server.Disconnect()
browser, err := server.CreateBrowser()
if err != nil {
t.Fatal(err)
}
defer browser.Release()
browser.MoveToRoot()
browse(t, browser)
err = browser.MoveUp()
assert.NoError(t, err)
err = browser.MoveUp()
assert.NoError(t, err)
browse(t, browser)
browser.MoveToRoot()
browse(t, browser)
err = browser.MoveTo([]string{"Simulation Items", "Bucket Brigade"})
assert.NoError(t, err)
err = browser.ShowLeafs(false)
assert.NoError(t, err)
count := browser.GetCount()
assert.Equal(t, 14, count)
expectLeafs := []string{
"ArrayOfReal8",
"ArrayOfString",
"Boolean",
"Int1",
"Int2",
"Int4",
"Money",
"Real4",
"Real8",
"String",
"Time",
"UInt1",
"UInt2",
"UInt4",
}
for i := 0; i < count; i++ {
nextName, err := browser.Item(i)
assert.NoError(t, err)
assert.Equal(t, expectLeafs[i], nextName)
itermID, err := browser.GetItemID(nextName)
assert.NoError(t, err)
assert.Equal(t, fmt.Sprintf("Bucket Brigade.%s", nextName), itermID)
}
browser.SetFilter("")
filter := browser.GetFilter()
assert.Equal(t, "", filter)
browser.SetDataType(uint16(com.VT_BOOL))
dataType := browser.GetDataType()
assert.Equal(t, uint16(com.VT_BOOL), dataType)
err = browser.SetAccessRights(OPC_READABLE)
assert.NoError(t, err)
accessRights := browser.GetAccessRights()
assert.Equal(t, OPC_READABLE, accessRights)
err = browser.SetAccessRights(4)
assert.Error(t, err)
position, err := browser.GetCurrentPosition()
assert.NoError(t, err)
assert.Equal(t, "Bucket Brigade", position)
organization, err := browser.GetOrganization()
assert.NoError(t, err)
assert.Equal(t, OPC_NS_HIERARCHIAL, organization)
browser.MoveToRoot()
position, err = browser.GetCurrentPosition()
assert.NoError(t, err)
assert.Equal(t, "", position)
}
func browse(t *testing.T, browser *OPCBrowser) {
err := browser.ShowBranches()
assert.NoError(t, err)
count := browser.GetCount()
assert.Equal(t, 2, count)
expectBranch := []string{"Simulation Items", "Configured Aliases"}
for i := 0; i < count; i++ {
nextName, err := browser.Item(i)
assert.NoError(t, err)
assert.Equal(t, expectBranch[i], nextName)
}
err = browser.MoveDown("Simulation Items")
assert.NoError(t, err)
err = browser.ShowBranches()
assert.NoError(t, err)
count = browser.GetCount()
assert.Equal(t, 8, count)
expectBranch = []string{
"Bucket Brigade",
"Random",
"Read Error",
"Saw-toothed Waves",
"Square Waves",
"Triangle Waves",
"Write Error",
"Write Only",
}
for i := 0; i < count; i++ {
nextName, err := browser.Item(i)
assert.NoError(t, err)
assert.Equal(t, expectBranch[i], nextName)
}
err = browser.MoveDown("Bucket Brigade")
assert.NoError(t, err)
err = browser.ShowLeafs(false)
assert.NoError(t, err)
count = browser.GetCount()
assert.Equal(t, 14, count)
expectLeafs := []string{
"ArrayOfReal8",
"ArrayOfString",
"Boolean",
"Int1",
"Int2",
"Int4",
"Money",
"Real4",
"Real8",
"String",
"Time",
"UInt1",
"UInt2",
"UInt4",
}
for i := 0; i < count; i++ {
nextName, err := browser.Item(i)
assert.NoError(t, err)
assert.Equal(t, expectLeafs[i], nextName)
itermID, err := browser.GetItemID(nextName)
assert.NoError(t, err)
assert.Equal(t, fmt.Sprintf("Bucket Brigade.%s", nextName), itermID)
}
err = browser.ShowBranches()
assert.NoError(t, err)
count = browser.GetCount()
assert.Equal(t, 0, count)
}