Skip to content

Commit

Permalink
sysfs: increase test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Apr 9, 2017
1 parent faf506d commit 2300ef7
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions sysfs/i2c_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,42 @@ func TestNewI2cDeviceWriteWordDataNotSupported(t *testing.T) {
gobottest.Assert(t, err.Error(), "SMBus write word data not supported")
}

func TestNewI2cDeviceWriteBlockData(t *testing.T) {
fs := NewMockFilesystem([]string{
"/dev/i2c-1",
})
SetFilesystem(fs)

i, err := NewI2cDevice("/dev/i2c-1")
var _ I2cDevice = i

gobottest.Assert(t, err, nil)

i.SetAddress(0xff)

e := i.WriteBlockData(0x01, []byte{0x01, 0x02, 0x03})
gobottest.Assert(t, e, nil)
}

func TestNewI2cDeviceWriteBlockDataTooMuch(t *testing.T) {
fs := NewMockFilesystem([]string{
"/dev/i2c-1",
})
SetFilesystem(fs)

i, err := NewI2cDevice("/dev/i2c-1")
var _ I2cDevice = i

gobottest.Assert(t, err, nil)

i.SetAddress(0xff)

var data []byte
data = make([]byte, 33)
e := i.WriteBlockData(0x01, data)
gobottest.Assert(t, e, errors.New("Writing blocks larger than 32 bytes (33) not supported"))
}

func TestNewI2cDeviceWrite(t *testing.T) {
SetSyscall(&MockSyscall{})
i, err := NewI2cDevice("/dev/i2c-1")
Expand Down

0 comments on commit 2300ef7

Please sign in to comment.