|
@@ -4,6 +4,7 @@ import (
|
|
|
"flag"
|
|
|
"fmt"
|
|
|
"io/ioutil"
|
|
|
+ "net"
|
|
|
"os"
|
|
|
"strings"
|
|
|
"testing"
|
|
@@ -11,7 +12,9 @@ import (
|
|
|
)
|
|
|
|
|
|
func TestDoorInputConnection(t *testing.T) {
|
|
|
- tmpFile, err := ioutil.TempFile(os.TempDir(), "test-")
|
|
|
+ var tmpFile *os.File
|
|
|
+ var err error
|
|
|
+ tmpFile, err = ioutil.TempFile(os.TempDir(), "test-")
|
|
|
if err != nil {
|
|
|
panic("Cannot create temporary file")
|
|
|
}
|
|
@@ -20,7 +23,8 @@ func TestDoorInputConnection(t *testing.T) {
|
|
|
defer os.Remove(tmpFile.Name())
|
|
|
|
|
|
// establish network socket connection to set Comm_handle
|
|
|
- server, client := setupSockets()
|
|
|
+ var server, client net.Conn
|
|
|
+ server, client = setupSockets()
|
|
|
|
|
|
// Ok, we have a server socket, and the client socket (that the door would talk to)
|
|
|
|
|
@@ -108,11 +112,11 @@ func TestDoorInputConnection(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
for send, get := range keytest {
|
|
|
- buffer := []byte(send)
|
|
|
+ var buffer []byte = []byte(send)
|
|
|
server.Write(buffer)
|
|
|
time.Sleep(time.Millisecond)
|
|
|
|
|
|
- recv := make([]int, 0)
|
|
|
+ var recv []int = make([]int, 0)
|
|
|
var retries int = 0
|
|
|
for {
|
|
|
// input := d.WaitKey(0, 50)
|
|
@@ -178,7 +182,7 @@ func TestDoorInputConnection(t *testing.T) {
|
|
|
server.Write(buffer)
|
|
|
time.Sleep(time.Millisecond)
|
|
|
|
|
|
- input := d.Input(5)
|
|
|
+ var input string = d.Input(5)
|
|
|
|
|
|
if input != "12345" {
|
|
|
t.Errorf("Expected Input(5) = 12345, but got %#v", input)
|
|
@@ -191,7 +195,7 @@ func TestDoorInputConnection(t *testing.T) {
|
|
|
if err != nil {
|
|
|
t.Errorf("server.Read: %#v", err)
|
|
|
}
|
|
|
- result := string(buffer[:r])
|
|
|
+ var result string = string(buffer[:r])
|
|
|
expected := " \x08\x08\x08\x08\x0812345\x07\x07\x07\x07\x07"
|
|
|
if result != expected {
|
|
|
t.Errorf("Buffer Input(5): Expected %#v, got %#v\n", expected, result)
|
|
@@ -220,7 +224,7 @@ func TestDoorInputConnection(t *testing.T) {
|
|
|
|
|
|
server.Close()
|
|
|
|
|
|
- hungup := d.WaitKey(1, 0)
|
|
|
+ var hungup int = d.WaitKey(1, 0)
|
|
|
if hungup != -2 {
|
|
|
t.Errorf("Expected -2 (hangup), got %d", hungup)
|
|
|
}
|
|
@@ -243,7 +247,7 @@ func TestDoorInputConnection(t *testing.T) {
|
|
|
client.Close()
|
|
|
time.Sleep(time.Millisecond)
|
|
|
|
|
|
- blank := d.Input(5)
|
|
|
+ var blank string = d.Input(5)
|
|
|
|
|
|
if blank != "" {
|
|
|
t.Errorf("Input should return blank (hangup).")
|