mirror of https://bitbucket.org/ausocean/av.git
Initial revision.
This commit is contained in:
parent
aced40b5bd
commit
e0471d5e2c
|
@ -0,0 +1,60 @@
|
|||
package revid
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"bitbucket.org/ausocean/iot/pi/netsender"
|
||||
)
|
||||
|
||||
// Supress all test logging, except for t.Errorf output.
|
||||
var silent bool
|
||||
|
||||
func TestRaspivid(t *testing.T) {
|
||||
var logger testLogger
|
||||
ns, err := netsender.New(&logger, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Errorf("netsender.New failed with error %v", err)
|
||||
}
|
||||
|
||||
var c Config
|
||||
c.Logger = &logger
|
||||
c.Input = Raspivid
|
||||
c.Outputs = make([]uint8, 1)
|
||||
|
||||
rv, err := New(c, ns)
|
||||
if err != nil {
|
||||
t.Errorf("revid.New failed with error %v", err)
|
||||
}
|
||||
|
||||
err = rv.Start()
|
||||
if err != nil {
|
||||
t.Errorf("revid.Start failed with error %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// testLogger implements a netsender.Logger.
|
||||
type testLogger struct {}
|
||||
|
||||
func (tl *testLogger) SetLevel(level int8) {
|
||||
}
|
||||
|
||||
// Log requests the Logger to write a message at the given level.
|
||||
func (tl *testLogger) Log(level int8, msg string, params ...interface{}) {
|
||||
logLevels := [...]string{"Debug", "Info", "Warn", "Error", "", "", "Fatal"}
|
||||
if level < -1 || level > 5 {
|
||||
panic("Invalid log level")
|
||||
}
|
||||
if !silent {
|
||||
fmt.Printf("%s: %s\n", logLevels[level+1], msg)
|
||||
}
|
||||
if level >= 4 {
|
||||
// Error or Fatal
|
||||
buf := make([]byte, 1<<16)
|
||||
size := runtime.Stack(buf, true)
|
||||
fmt.Printf("%s\n", string(buf[:size]))
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue