Exemplo n.º 1
0
func TestButtonDriverActive(t *testing.T) {
	d := initTestButtonDriver()
	d.update(1)
	gobot.Expect(t, d.Active, true)

	d.update(0)
	gobot.Expect(t, d.Active, false)
}
Exemplo n.º 2
0
func TestLedDriverToggle(t *testing.T) {
	d := initTestLedDriver()
	d.Off()
	d.Toggle()
	gobot.Expect(t, d.IsOn(), true)
	d.Toggle()
	gobot.Expect(t, d.IsOff(), true)
}
Exemplo n.º 3
0
func TestFirmataAdaptorDigitalRead(t *testing.T) {
	a := initTestFirmataAdaptor()
	// -1 on no data
	gobot.Expect(t, a.DigitalRead("1"), -1)

	pinNumber := "1"
	a.Board.Events = append(a.Board.Events, event{Name: fmt.Sprintf("digital_read_%v", pinNumber), Data: []byte{0x01}})
	gobot.Expect(t, a.DigitalRead(pinNumber), 0x01)
}
Exemplo n.º 4
0
func TestMotorDriverIsOn(t *testing.T) {
	d := initTestMotorDriver()
	d.CurrentMode = "digital"
	d.CurrentState = 1
	gobot.Expect(t, d.IsOn(), true)
	d.CurrentMode = "analog"
	d.CurrentSpeed = 100
	gobot.Expect(t, d.IsOn(), true)
}
Exemplo n.º 5
0
func TestPebbleDriverNotification(t *testing.T) {
	d := initTestPebbleDriver()
	d.SendNotification("Hello")
	d.SendNotification("World")

	gobot.Expect(t, d.Messages[0], "Hello")
	gobot.Expect(t, d.PendingMessage(), "Hello")
	gobot.Expect(t, d.PendingMessage(), "World")
	gobot.Expect(t, d.PendingMessage(), "")
}
Exemplo n.º 6
0
func TestFirmataAdaptorAnalogRead(t *testing.T) {
	a := initTestFirmataAdaptor()
	// -1 on no data
	gobot.Expect(t, a.AnalogRead("1"), -1)

	pinNumber := "1"
	value := 133
	a.Board.Events = append(a.Board.Events, event{Name: fmt.Sprintf("analog_read_%v", pinNumber), Data: []byte{byte(value >> 24), byte(value >> 16), byte(value >> 8), byte(value & 0xff)}})
	gobot.Expect(t, a.AnalogRead(pinNumber), 133)
}
Exemplo n.º 7
0
func TestMotorDriverOff(t *testing.T) {
	d := initTestMotorDriver()
	d.CurrentMode = "digital"
	d.Off()
	gobot.Expect(t, d.CurrentState, uint8(0))
	d.CurrentMode = "analog"
	d.CurrentSpeed = 100
	d.Off()
	gobot.Expect(t, d.CurrentSpeed, uint8(0))
}
Exemplo n.º 8
0
func TestFirmataAdaptorI2cRead(t *testing.T) {
	a := initTestFirmataAdaptor()
	// [] on no data
	gobot.Expect(t, a.I2cRead(1), []byte{})

	i := []byte{100}
	i2cReply := map[string][]byte{}
	i2cReply["data"] = i
	a.Board.Events = append(a.Board.Events, event{Name: "i2c_reply", I2cReply: i2cReply})
	gobot.Expect(t, a.I2cRead(1), i)
}
Exemplo n.º 9
0
func TestRobotDevices(t *testing.T) {
	a := initTestAPI()
	request, _ := http.NewRequest("GET", "/robots/Robot%201/devices", nil)
	response := httptest.NewRecorder()
	a.server.ServeHTTP(response, request)

	body, _ := ioutil.ReadAll(response.Body)
	var i []map[string]interface{}
	json.Unmarshal(body, &i)
	gobot.Expect(t, len(i), 3)
}
Exemplo n.º 10
0
func TestRobotCommands(t *testing.T) {
	a := initTestAPI()
	request, _ := http.NewRequest("GET", "/robots/Robot%201/commands", nil)
	response := httptest.NewRecorder()
	a.server.ServeHTTP(response, request)

	body, _ := ioutil.ReadAll(response.Body)
	var i []string
	json.Unmarshal(body, &i)
	gobot.Expect(t, i, []string{"robotTestFunction"})
}
Exemplo n.º 11
0
func TestRobot(t *testing.T) {
	a := initTestAPI()
	request, _ := http.NewRequest("GET", "/robots/Robot%201", nil)
	response := httptest.NewRecorder()
	a.server.ServeHTTP(response, request)

	body, _ := ioutil.ReadAll(response.Body)
	var i map[string]interface{}
	json.Unmarshal(body, &i)
	gobot.Expect(t, i["name"].(string), "Robot 1")
}
Exemplo n.º 12
0
func TestLeapMotionDriverParser(t *testing.T) {
	d := initTestLeapMotionDriver()
	file, _ := ioutil.ReadFile("./test/support/example_frame.json")
	parsedFrame := d.ParseFrame(file)

	if parsedFrame.Hands == nil || parsedFrame.Pointables == nil || parsedFrame.Gestures == nil {
		t.Errorf("ParseFrame incorrectly parsed frame")
	}

	parsedFrame = d.ParseFrame([]byte{})
	gobot.Expect(t, parsedFrame.Timestamp, 0)
}
Exemplo n.º 13
0
func TestExecuteRobotDeviceCommand(t *testing.T) {
	a := initTestAPI()
	request, _ := http.NewRequest("GET", "/robots/Robot%201/devices/Device%201/commands/TestDriverCommand", bytes.NewBufferString(`{"name":"human"}`))
	request.Header.Add("Content-Type", "application/json")
	response := httptest.NewRecorder()
	a.server.ServeHTTP(response, request)

	body, _ := ioutil.ReadAll(response.Body)
	var i interface{}
	json.Unmarshal(body, &i)
	gobot.Expect(t, i, "hello human")
}
Exemplo n.º 14
0
func TestUnknownRobotCommand(t *testing.T) {
	a := initTestAPI()
	request, _ := http.NewRequest("GET", "/robots/Robot%201/commands/robotTestFuntion1", bytes.NewBufferString(`{"message":"Beep Boop"}`))
	request.Header.Add("Content-Type", "application/json")
	response := httptest.NewRecorder()
	a.server.ServeHTTP(response, request)

	body, _ := ioutil.ReadAll(response.Body)
	var i interface{}
	json.Unmarshal(body, &i)
	gobot.Expect(t, i, "Unknown Command")
}
Exemplo n.º 15
0
func TestConnect(t *testing.T) {
	a := initTestArdroneAdaptor()
	gobot.Expect(t, a.Connect(), true)
}
Exemplo n.º 16
0
func TestPebbleDriverHalt(t *testing.T) {
	d := initTestPebbleDriver()
	gobot.Expect(t, d.Halt(), true)
}
Exemplo n.º 17
0
func TestFinalize(t *testing.T) {
	a := initTestArdroneAdaptor()
	gobot.Expect(t, a.Finalize(), true)
}
Exemplo n.º 18
0
func TestLedDriverOff(t *testing.T) {
	d := initTestLedDriver()
	gobot.Expect(t, d.Off(), true)
	gobot.Expect(t, d.IsOff(), true)
}
Exemplo n.º 19
0
func TestLedDriverInit(t *testing.T) {
	d := initTestLedDriver()
	gobot.Expect(t, d.Init(), true)
}
Exemplo n.º 20
0
func TestServoDriverCenter(t *testing.T) {
	d := initTestServoDriver()
	d.Center()
	gobot.Expect(t, d.CurrentAngle, uint8(90))
}
Exemplo n.º 21
0
func TestAnalogSensorDriverRead(t *testing.T) {
	d := initTestAnalogSensorDriver()
	gobot.Expect(t, d.Read(), 99)
}
Exemplo n.º 22
0
func TestServoDriverMove(t *testing.T) {
	d := initTestServoDriver()
	d.Move(100)
	gobot.Expect(t, d.CurrentAngle, uint8(100))
}
Exemplo n.º 23
0
func TestServoDriverStart(t *testing.T) {
	d := initTestServoDriver()
	gobot.Expect(t, d.Start(), true)
}
Exemplo n.º 24
0
func TestBeagleboneAdaptorFinalize(t *testing.T) {
	a := initTestBeagleboneAdaptor()
	gobot.Expect(t, a.Finalize(), true)
}
Exemplo n.º 25
0
func TestBeagleboneAdaptorReconnect(t *testing.T) {
	a := initTestBeagleboneAdaptor()
	gobot.Expect(t, a.Reconnect(), true)
}
Exemplo n.º 26
0
func TestDigisparkAdaptorReconnect(t *testing.T) {
	a := initTestDigisparkAdaptor()
	gobot.Expect(t, a.Reconnect(), true)
}
Exemplo n.º 27
0
func TestSparkCoreAdaptorConnect(t *testing.T) {
	a := initTestSparkCoreAdaptor()
	gobot.Expect(t, a.Connect(), true)
}
Exemplo n.º 28
0
func TestServoDriverMax(t *testing.T) {
	d := initTestServoDriver()
	d.Max()
	gobot.Expect(t, d.CurrentAngle, uint8(180))
}
Exemplo n.º 29
0
func TestSparkCoreAdaptorFinalize(t *testing.T) {
	a := initTestSparkCoreAdaptor()
	gobot.Expect(t, a.Finalize(), true)
}
Exemplo n.º 30
0
func TestAnalogSensorDriverInit(t *testing.T) {
	d := initTestAnalogSensorDriver()
	gobot.Expect(t, d.Init(), true)
}