2013-12-31 08:51:21 +08:00
|
|
|
package gobot
|
|
|
|
|
|
|
|
import (
|
2014-06-13 05:38:03 +08:00
|
|
|
"log"
|
2014-04-27 00:24:43 +08:00
|
|
|
"os"
|
2014-06-13 05:38:03 +08:00
|
|
|
"testing"
|
2013-12-31 08:51:21 +08:00
|
|
|
)
|
|
|
|
|
2014-06-14 07:01:39 +08:00
|
|
|
func initTestGobot() *Gobot {
|
|
|
|
log.SetOutput(&NullReadWriteCloser{})
|
|
|
|
g := NewGobot()
|
2014-06-13 05:38:03 +08:00
|
|
|
g.trap = func(c chan os.Signal) {
|
|
|
|
c <- os.Interrupt
|
|
|
|
}
|
2014-06-24 11:33:59 +08:00
|
|
|
g.Robots().Add(NewTestRobot("Robot 1"))
|
|
|
|
g.Robots().Add(NewTestRobot("Robot 2"))
|
|
|
|
g.Robots().Add(NewTestRobot("Robot 3"))
|
2014-06-14 07:01:39 +08:00
|
|
|
return g
|
2014-06-13 05:38:03 +08:00
|
|
|
}
|
2013-12-31 08:51:21 +08:00
|
|
|
|
2014-06-14 07:01:39 +08:00
|
|
|
func TestGobotStart(t *testing.T) {
|
|
|
|
g := initTestGobot()
|
2014-06-13 05:38:03 +08:00
|
|
|
g.Start()
|
|
|
|
}
|
2014-05-03 18:22:22 +08:00
|
|
|
|
2014-06-14 07:01:39 +08:00
|
|
|
func TestGobotRobot(t *testing.T) {
|
|
|
|
g := initTestGobot()
|
2014-06-13 05:38:03 +08:00
|
|
|
Expect(t, g.Robot("Robot 1").Name, "Robot 1")
|
|
|
|
Expect(t, g.Robot("Robot 4"), (*Robot)(nil))
|
2014-06-24 11:33:59 +08:00
|
|
|
Expect(t, g.Robot("Robot 1").Device("Device 4"), (DriverInterface)(nil))
|
|
|
|
Expect(t, g.Robot("Robot 1").Device("Device 1").name(), "Device 1")
|
|
|
|
Expect(t, g.Robot("Robot 1").Devices().Len(), 3)
|
|
|
|
Expect(t, g.Robot("Robot 1").Connection("Connection 4"), (AdaptorInterface)(nil))
|
|
|
|
Expect(t, g.Robot("Robot 1").Connections().Len(), 3)
|
2014-06-13 05:38:03 +08:00
|
|
|
}
|