gobot.io/x/gobot/v2@v2.1.0/platforms/ble/device_information_driver_test.go (about) 1 package ble 2 3 import ( 4 "strings" 5 "testing" 6 7 "gobot.io/x/gobot/v2" 8 "gobot.io/x/gobot/v2/gobottest" 9 ) 10 11 var _ gobot.Driver = (*DeviceInformationDriver)(nil) 12 13 func initTestDeviceInformationDriver() *DeviceInformationDriver { 14 d := NewDeviceInformationDriver(NewBleTestAdaptor()) 15 return d 16 } 17 18 func TestDeviceInformationDriver(t *testing.T) { 19 d := initTestDeviceInformationDriver() 20 gobottest.Assert(t, strings.HasPrefix(d.Name(), "DeviceInformation"), true) 21 d.SetName("NewName") 22 gobottest.Assert(t, d.Name(), "NewName") 23 } 24 25 func TestDeviceInformationDriverStartAndHalt(t *testing.T) { 26 d := initTestDeviceInformationDriver() 27 gobottest.Assert(t, d.Start(), nil) 28 gobottest.Assert(t, d.Halt(), nil) 29 } 30 31 func TestDeviceInformationDriverGetModelNumber(t *testing.T) { 32 a := NewBleTestAdaptor() 33 d := NewDeviceInformationDriver(a) 34 a.TestReadCharacteristic(func(cUUID string) ([]byte, error) { 35 return []byte("TestDevice"), nil 36 }) 37 38 gobottest.Assert(t, d.GetModelNumber(), "TestDevice") 39 } 40 41 func TestDeviceInformationDriverGetFirmwareRevision(t *testing.T) { 42 a := NewBleTestAdaptor() 43 d := NewDeviceInformationDriver(a) 44 a.TestReadCharacteristic(func(cUUID string) ([]byte, error) { 45 return []byte("TestDevice"), nil 46 }) 47 48 gobottest.Assert(t, d.GetFirmwareRevision(), "TestDevice") 49 } 50 51 func TestDeviceInformationDriverGetHardwareRevision(t *testing.T) { 52 a := NewBleTestAdaptor() 53 d := NewDeviceInformationDriver(a) 54 a.TestReadCharacteristic(func(cUUID string) ([]byte, error) { 55 return []byte("TestDevice"), nil 56 }) 57 58 gobottest.Assert(t, d.GetHardwareRevision(), "TestDevice") 59 } 60 61 func TestDeviceInformationDriverGetManufacturerName(t *testing.T) { 62 a := NewBleTestAdaptor() 63 d := NewDeviceInformationDriver(a) 64 a.TestReadCharacteristic(func(cUUID string) ([]byte, error) { 65 return []byte("TestDevice"), nil 66 }) 67 68 gobottest.Assert(t, d.GetManufacturerName(), "TestDevice") 69 } 70 71 func TestDeviceInformationDriverGetPnPId(t *testing.T) { 72 a := NewBleTestAdaptor() 73 d := NewDeviceInformationDriver(a) 74 a.TestReadCharacteristic(func(cUUID string) ([]byte, error) { 75 return []byte("TestDevice"), nil 76 }) 77 78 gobottest.Assert(t, d.GetPnPId(), "TestDevice") 79 }