Skip to content

Commit

Permalink
fixed a runtime error in fix(), added TestTags & TestAutomationItemsC…
Browse files Browse the repository at this point in the history
…lose
  • Loading branch information
Lynckx authored and konimarti committed Aug 12, 2019
1 parent 3a9d37d commit 5eae5c3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
16 changes: 16 additions & 0 deletions connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ func TestGetTags(t *testing.T) {
}
}

func TestTags(t *testing.T) {
var want []string
client := &opcConnectionImpl{}
tags := client.Tags()
if !reflect.DeepEqual(tags, want) {
fmt.Printf("actual: %+v\n", tags)
fmt.Printf("Want: %+v\n", want)
t.Error("Tags() should return a empty array of strings")
}
}

func TestAutomationItemsClose(t *testing.T) {
conn := &opcConnectionImpl{}
conn.AutomationItems.Close()
}

func TestOpcRead(t *testing.T) {
client, _ := NewConnection(
"Graybox.Simulator",
Expand Down
17 changes: 11 additions & 6 deletions connection_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,13 @@ func (ai *AutomationItems) writeToOpc(opcitem *ole.IDispatch, value interface{})

//Close closes the OLE objects in AutomationItems.
func (ai *AutomationItems) Close() {
for key, opcitem := range ai.items {
opcitem.Release()
delete(ai.items, key)
if ai != nil {
for key, opcitem := range ai.items {
opcitem.Release()
delete(ai.items, key)
}
ai.addItemObject.Release()
}
ai.addItemObject.Release()
}

//NewAutomationItems returns a new AutomationItems instance.
Expand Down Expand Up @@ -393,10 +395,13 @@ func (conn *opcConnectionImpl) Read() map[string]Item {
//Tags returns the currently active tags
func (conn *opcConnectionImpl) Tags() []string {
var tags []string
for tag, _ := range conn.AutomationItems.items {
tags = append(tags, tag)
if conn.AutomationItems != nil {
for tag, _ := range conn.AutomationItems.items {
tags = append(tags, tag)
}
}
return tags

}

//fix tries to reconnect if connection is lost by creating a new connection
Expand Down

0 comments on commit 5eae5c3

Please sign in to comment.