2016-12-09 19:15:33 +08:00
|
|
|
package ble
|
|
|
|
|
|
|
|
import (
|
2017-02-02 22:56:26 +08:00
|
|
|
"strings"
|
2016-12-09 19:15:33 +08:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/gobottest"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ gobot.Driver = (*BatteryDriver)(nil)
|
|
|
|
|
|
|
|
func initTestBatteryDriver() *BatteryDriver {
|
2017-04-05 18:22:46 +08:00
|
|
|
d := NewBatteryDriver(NewBleTestAdaptor())
|
2016-12-09 19:15:33 +08:00
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBatteryDriver(t *testing.T) {
|
|
|
|
d := initTestBatteryDriver()
|
2017-02-02 22:56:26 +08:00
|
|
|
gobottest.Assert(t, strings.HasPrefix(d.Name(), "Battery"), true)
|
2017-04-05 18:01:13 +08:00
|
|
|
d.SetName("NewName")
|
|
|
|
gobottest.Assert(t, d.Name(), "NewName")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBatteryDriverStartAndHalt(t *testing.T) {
|
|
|
|
d := initTestBatteryDriver()
|
|
|
|
gobottest.Assert(t, d.Start(), nil)
|
|
|
|
gobottest.Assert(t, d.Halt(), nil)
|
2016-12-09 19:15:33 +08:00
|
|
|
}
|
2017-04-05 17:47:28 +08:00
|
|
|
|
|
|
|
func TestBatteryDriverRead(t *testing.T) {
|
2017-04-05 18:22:46 +08:00
|
|
|
a := NewBleTestAdaptor()
|
2017-04-05 17:47:28 +08:00
|
|
|
d := NewBatteryDriver(a)
|
|
|
|
a.TestReadCharacteristic(func(cUUID string) ([]byte, error) {
|
|
|
|
return []byte{20}, nil
|
|
|
|
})
|
|
|
|
|
|
|
|
gobottest.Assert(t, d.GetBatteryLevel(), uint8(20))
|
|
|
|
}
|