diff --git a/devices/devices.go b/devices/devices.go index 5995685..5b29ac0 100644 --- a/devices/devices.go +++ b/devices/devices.go @@ -4,8 +4,8 @@ import ( "net" ) -// [impl->dsn~low-level-abstraction~0] -// [impl->dsn~list-devices~0] +// [impl->dsn~low-level-abstraction~0>>utest] +// [impl->dsn~list-devices~0>>utest] // Transmitter interface for sending packets type Transmitter interface { diff --git a/devices/devices_linux.go b/devices/devices_linux.go index 0aa10a6..2078238 100644 --- a/devices/devices_linux.go +++ b/devices/devices_linux.go @@ -1,6 +1,6 @@ package devices -// [impllnx dsn~low-level-abstraction~0] +// [impllnx dsn~low-level-abstraction~0>>utest] import "golang.org/x/sys/unix" @@ -11,7 +11,8 @@ type TransmitterLinux struct { // Send implements sending packets on Linux func (tl TransmitterLinux) Send(data []byte) error { - return nil + err := unix.Send(tl.socket, data, 0) + return err } // Close closes the transmitter socket @@ -32,5 +33,6 @@ func CreateTransmitter(device string) (Transmitter, error) { // CreateReceiver creates and starts the Receiver instance func CreateReceiver(device string) (Receiver, error) { + //TODO return nil, nil } diff --git a/devices/devices_test.go b/devices/devices_test.go new file mode 100644 index 0000000..b516ee7 --- /dev/null +++ b/devices/devices_test.go @@ -0,0 +1,60 @@ +package devices_test + +import ( + "fmt" + "testing" + + "gitea.mmo.to/ppForge/ppforge/devices" +) + +func TestListDevices(t *testing.T) { + list, err := devices.List() + if err != nil { + fmt.Println("Got error: ", err) + t.Fail() + } + fmt.Printf("%s", list) + lo_in_list := false + for _, e := range list { + if e == "lo" { + lo_in_list = true + } + } + if !lo_in_list { + t.Fail() + } +} + +func TestGetHardwareAddress(t *testing.T) { + list, err := devices.List() + if err != nil { + fmt.Println("Got error: ", err) + t.Fail() + } + fmt.Printf("%s", list) + + hwaddr, err := devices.GetHardwareAddress(list[1]) + fmt.Println("Hardware address: ", hwaddr) + + if hwaddr == "" || err != nil { + // might have catched lo ? + fmt.Println("catched 'lo'? or error: ", err) + t.Fail() + } +} + +func TestGetAddresses(t *testing.T) { + list, err := devices.List() + if err != nil { + fmt.Println("Got error: ", err) + t.Fail() + } + fmt.Printf("%s", list) + addrlist, err := devices.GetAddresses(list[1]) + fmt.Println("Addresses: ", addrlist) + + if len(addrlist) == 0 || err != nil { + fmt.Println("Addrlist empty? or error: ", err) + t.Fail() + } +}