gobot.io/x/gobot/v2@v2.1.0/platforms/ble/generic_access_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 = (*GenericAccessDriver)(nil)
    12  
    13  func initTestGenericAccessDriver() *GenericAccessDriver {
    14  	d := NewGenericAccessDriver(NewBleTestAdaptor())
    15  	return d
    16  }
    17  
    18  func TestGenericAccessDriver(t *testing.T) {
    19  	d := initTestGenericAccessDriver()
    20  	gobottest.Assert(t, strings.HasPrefix(d.Name(), "GenericAccess"), true)
    21  	d.SetName("NewName")
    22  	gobottest.Assert(t, d.Name(), "NewName")
    23  }
    24  
    25  func TestGenericAccessDriverStartAndHalt(t *testing.T) {
    26  	d := initTestGenericAccessDriver()
    27  	gobottest.Assert(t, d.Start(), nil)
    28  	gobottest.Assert(t, d.Halt(), nil)
    29  }
    30  
    31  func TestGenericAccessDriverGetDeviceName(t *testing.T) {
    32  	a := NewBleTestAdaptor()
    33  	d := NewGenericAccessDriver(a)
    34  	a.TestReadCharacteristic(func(cUUID string) ([]byte, error) {
    35  		return []byte("TestDevice"), nil
    36  	})
    37  
    38  	gobottest.Assert(t, d.GetDeviceName(), "TestDevice")
    39  }
    40  
    41  func TestGenericAccessDriverGetAppearance(t *testing.T) {
    42  	a := NewBleTestAdaptor()
    43  	d := NewGenericAccessDriver(a)
    44  	a.TestReadCharacteristic(func(cUUID string) ([]byte, error) {
    45  		return []byte{128, 0}, nil
    46  	})
    47  
    48  	gobottest.Assert(t, d.GetAppearance(), "Generic Computer")
    49  }