hybridgroup.gobot/helpers_test.go

90 lines
2.4 KiB
Go
Raw Normal View History

2013-12-31 08:51:21 +08:00
package gobot
import "os"
2014-06-14 07:01:39 +08:00
type NullReadWriteCloser struct{}
2014-04-11 21:02:21 +08:00
2014-06-14 07:01:39 +08:00
func (NullReadWriteCloser) Write(p []byte) (int, error) {
2014-04-11 21:02:21 +08:00
return len(p), nil
}
2014-06-14 07:01:39 +08:00
func (NullReadWriteCloser) Read(b []byte) (int, error) {
return len(b), nil
}
2014-07-10 00:38:43 +08:00
2014-06-14 07:01:39 +08:00
func (NullReadWriteCloser) Close() error {
return nil
}
2013-12-31 08:51:21 +08:00
type testDriver struct {
name string
pin string
connection Connection
Commander
2013-12-31 08:51:21 +08:00
}
2014-11-30 16:19:53 +08:00
var testDriverStart = func() (errs []error) { return }
var testDriverHalt = func() (errs []error) { return }
func (t *testDriver) Start() (errs []error) { return testDriverStart() }
func (t *testDriver) Halt() (errs []error) { return testDriverHalt() }
func (t *testDriver) Name() string { return t.name }
func (t *testDriver) SetName(n string) { t.name = n }
func (t *testDriver) Pin() string { return t.pin }
func (t *testDriver) Connection() Connection { return t.connection }
2013-12-31 08:51:21 +08:00
2014-11-30 16:19:53 +08:00
func newTestDriver(adaptor *testAdaptor, name string, pin string) *testDriver {
2014-06-12 08:41:04 +08:00
t := &testDriver{
name: name,
connection: adaptor,
2014-11-30 16:19:53 +08:00
pin: pin,
Commander: NewCommander(),
2013-12-31 09:22:16 +08:00
}
2014-06-12 08:41:04 +08:00
t.AddCommand("DriverCommand", func(params map[string]interface{}) interface{} { return nil })
2014-06-12 08:41:04 +08:00
return t
2013-12-31 08:51:21 +08:00
}
2014-04-15 14:16:35 +08:00
2014-06-14 05:46:07 +08:00
type testAdaptor struct {
name string
port string
2014-06-14 05:46:07 +08:00
}
2014-11-30 16:19:53 +08:00
var testAdaptorConnect = func() (errs []error) { return }
var testAdaptorFinalize = func() (errs []error) { return }
func (t *testAdaptor) Finalize() (errs []error) { return testAdaptorFinalize() }
func (t *testAdaptor) Connect() (errs []error) { return testAdaptorConnect() }
func (t *testAdaptor) Name() string { return t.name }
func (t *testAdaptor) SetName(n string) { t.name = n }
func (t *testAdaptor) Port() string { return t.port }
2014-06-14 05:46:07 +08:00
2014-11-30 16:19:53 +08:00
func newTestAdaptor(name string, port string) *testAdaptor {
2014-06-11 06:16:11 +08:00
return &testAdaptor{
name: name,
2014-11-30 16:19:53 +08:00
port: port,
2014-04-15 14:16:35 +08:00
}
2013-12-31 08:51:21 +08:00
}
2014-01-01 05:16:25 +08:00
2014-11-30 16:19:53 +08:00
func newTestRobot(name string) *Robot {
adaptor1 := newTestAdaptor("Connection1", "/dev/null")
adaptor2 := newTestAdaptor("Connection2", "/dev/null")
adaptor3 := newTestAdaptor("", "/dev/null")
driver1 := newTestDriver(adaptor1, "Device1", "0")
driver2 := newTestDriver(adaptor2, "Device2", "2")
driver3 := newTestDriver(adaptor3, "", "1")
2014-05-03 18:22:22 +08:00
work := func() {}
2014-07-11 02:14:08 +08:00
r := NewRobot(name,
[]Connection{adaptor1, adaptor2, adaptor3},
[]Device{driver1, driver2, driver3},
work,
)
2014-11-30 16:19:53 +08:00
r.AddCommand("RobotCommand", func(params map[string]interface{}) interface{} { return nil })
r.trap = func(c chan os.Signal) {
c <- os.Interrupt
}
2014-11-30 16:19:53 +08:00
2014-06-12 08:41:04 +08:00
return r
2014-01-01 05:16:25 +08:00
}