Sfoglia il codice sorgente

Working Mouse tests.

Steve Thielemann 2 anni fa
parent
commit
eac5617607
2 ha cambiato i file con 51 aggiunte e 11 eliminazioni
  1. 41 5
      door/door_test.go
  2. 10 6
      door/help_test.go

+ 41 - 5
door/door_test.go

@@ -18,7 +18,7 @@ import (
 // go test -c; ./door.test -test.run DoorCP437 -test.v
 
 const KEEP_LOGS bool = false
-const VERBOSE_TEST bool = false
+const VERBOSE_TEST bool = true // false
 
 func TestGoto(t *testing.T) {
 	GotoMap := map[string][]int{"\x1b[10;20H": {20, 10},
@@ -468,19 +468,18 @@ func InputTests(t *testing.T, server net.Conn, d *Door, mode string) {
 		if VERBOSE_TEST {
 			t.Logf("Sending CursorPos(%d,%d)\n", pos.X, pos.Y)
 		}
-		buffer = CursorReply(pos.X, pos.Y)
+		buffer = CursorReply(pos)
 		_, err := server.Write([]byte(buffer))
 		if err != nil {
 			t.Error("server.Write:", err)
 		}
 	}
 
-	log.Printf("d = %p / %p\n", &d, &d.LastCursor)
-
 	for _, pos := range cpos {
 		_, ex, err := d.WaitKey(keyWait)
 		if err != nil {
 			t.Error("WaitKey:", err)
+			continue
 		}
 
 		if ex != CURSOR {
@@ -491,7 +490,7 @@ func InputTests(t *testing.T, server net.Conn, d *Door, mode string) {
 		cp, ok := d.GetCursorPos()
 
 		if !ok {
-			t.Error("Extended sent MOUSE, but GetMouse failed.")
+			t.Error("Extended sent CURSOR, but GetCursorPos failed.")
 			continue
 		}
 
@@ -500,6 +499,43 @@ func InputTests(t *testing.T, server net.Conn, d *Door, mode string) {
 		}
 	}
 
+	t.Logf("Starting Mouse test (%s)\n", mode)
+	var mouse []Mouse = []Mouse{{1, 4, 5}, {4, 4, 5}, {45, 80, 25}, {2, 55, 17}}
+	for _, m := range mouse {
+		if VERBOSE_TEST {
+			t.Logf("Sending Mouse(%d @ %d,%d)\n", m.Button, m.X, m.Y)
+		}
+		buffer = MouseReply(m)
+		_, err = server.Write([]byte(buffer))
+		if err != nil {
+			t.Error("server.Write:", err)
+		}
+	}
+
+	for _, pos := range mouse {
+		_, ex, err := d.WaitKey(keyWait)
+		if err != nil {
+			t.Error("WaitKey:", err)
+			continue
+		}
+
+		if ex != MOUSE {
+			t.Errorf("Expected Extended = MOUSE (was %s)", ex.String())
+			continue
+		}
+
+		mpos, ok := d.GetMouse()
+
+		if !ok {
+			t.Error("Extended sent MOUSE, but GetMouse failed.")
+			continue
+		}
+
+		if (pos.Button != mpos.Button) || (pos.X != mpos.X) || (pos.Y != mpos.Y) {
+			t.Errorf("Expected (%d @ %d, %d), Got (%d @ %d, %d)",
+				pos.Button, pos.X, pos.Y, mpos.Button, mpos.X, mpos.Y)
+		}
+	}
 }
 
 func TestDoorCP437(t *testing.T) {

+ 10 - 6
door/help_test.go

@@ -71,20 +71,24 @@ func clear_socket(socket net.Conn, t *testing.T) string {
 
 // Unicode detection response with given screen width/height.
 func UnicodeWidthHeight(width, height int) string {
-	return CursorReply(1, 1) + CursorReply(3, 1) + CursorReply(width, height)
+	return CursorReply(CursorPos{1, 1}) +
+		CursorReply(CursorPos{3, 1}) +
+		CursorReply(CursorPos{width, height})
 }
 
 // CP437 response with screen width/height. (80x25)
 func CP437WidthHeight(width, height int) string {
-	return CursorReply(3, 1) + CursorReply(4, 1) + CursorReply(width, height)
+	return CursorReply(CursorPos{3, 1}) +
+		CursorReply(CursorPos{4, 1}) +
+		CursorReply(CursorPos{width, height})
 }
 
 // Cursor Position Reply
-func CursorReply(x, y int) string {
-	return fmt.Sprintf("\x1b[%d;%dR", y, x)
+func CursorReply(c CursorPos) string {
+	return fmt.Sprintf("\x1b[%d;%dR", c.Y, c.X)
 }
 
 // Mouse Button X,Y Reply
-func MouseResponse(button, x, y int8) string {
-	return fmt.Sprintf("\x1b[M%c%c%c", button+' '+1, x+'!'+1, y+'!'+1)
+func MouseReply(m Mouse) string {
+	return fmt.Sprintf("\x1b[M%c%c%c", m.Button+' '-1, m.X+'!'-1, m.Y+'!'-1)
 }