i2c: test coverage for Close()
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
647b3e3ba7
commit
ca3a9bdbda
|
@ -58,7 +58,7 @@ func NewConnection(bus sysfs.I2cDevice, address int) (connection *i2cConnection)
|
||||||
|
|
||||||
// Read data from an i2c device.
|
// Read data from an i2c device.
|
||||||
func (c *i2cConnection) Read(data []byte) (read int, err error) {
|
func (c *i2cConnection) Read(data []byte) (read int, err error) {
|
||||||
if err := c.bus.SetAddress(c.address); err != nil {
|
if err = c.bus.SetAddress(c.address); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
read, err = c.bus.Read(data)
|
read, err = c.bus.Read(data)
|
||||||
|
@ -67,7 +67,7 @@ func (c *i2cConnection) Read(data []byte) (read int, err error) {
|
||||||
|
|
||||||
// Write data to an i2c device.
|
// Write data to an i2c device.
|
||||||
func (c *i2cConnection) Write(data []byte) (written int, err error) {
|
func (c *i2cConnection) Write(data []byte) (written int, err error) {
|
||||||
if err := c.bus.SetAddress(c.address); err != nil {
|
if err = c.bus.SetAddress(c.address); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
written, err = c.bus.Write(data)
|
written, err = c.bus.Write(data)
|
||||||
|
|
|
@ -3,10 +3,11 @@ package i2c
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gobot.io/x/gobot/gobottest"
|
|
||||||
"gobot.io/x/gobot/sysfs"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
|
"gobot.io/x/gobot/gobottest"
|
||||||
|
"gobot.io/x/gobot/sysfs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func syscallImpl(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) {
|
func syscallImpl(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) {
|
||||||
|
@ -39,6 +40,11 @@ func TestI2CAddress(t *testing.T) {
|
||||||
gobottest.Assert(t, c.address, 0x66)
|
gobottest.Assert(t, c.address, 0x66)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestI2CClose(t *testing.T) {
|
||||||
|
c := NewConnection(initI2CDevice(), 0x06)
|
||||||
|
gobottest.Assert(t, c.Close(), nil)
|
||||||
|
}
|
||||||
|
|
||||||
func TestI2CRead(t *testing.T) {
|
func TestI2CRead(t *testing.T) {
|
||||||
c := NewConnection(initI2CDevice(), 0x06)
|
c := NewConnection(initI2CDevice(), 0x06)
|
||||||
i, _ := c.Read([]byte{})
|
i, _ := c.Read([]byte{})
|
||||||
|
|
Loading…
Reference in New Issue