1
0
mirror of https://github.com/taigrr/gopher-os synced 2025-01-18 04:43:13 -08:00
gopher-os/kernel/driver/tty/vt_test.go
Achilleas Anagnostopoulos 616fc6a412 Implement simple terminal
The terminal uses console.Vga as its output device. A proper terminal
implementation would be using a console.Console interface as its output.
However, at this point we cannot use Go interfaces as the fn pointers in
the itables have not been yet initialized. The Go runtime bits that set
up the itables need access to a memory allocator, a facility which is
not yet provided by the kernel.
2017-03-27 20:12:01 +01:00

71 lines
1.3 KiB
Go

package tty
import (
"testing"
"github.com/achilleasa/gopher-os/kernel/driver/video/console"
)
func TestVtPosition(t *testing.T) {
specs := []struct {
inX, inY uint16
expX, expY uint16
}{
{20, 20, 20, 20},
{100, 20, 79, 20},
{10, 200, 10, 24},
{10, 200, 10, 24},
{100, 100, 79, 24},
}
var cons console.Vga
cons.Init()
var vt Vt
vt.Init(&cons)
for specIndex, spec := range specs {
vt.SetPosition(spec.inX, spec.inY)
if x, y := vt.Position(); x != spec.expX || y != spec.expY {
t.Errorf("[spec %d] expected setting position to (%d, %d) to update the position to (%d, %d); got (%d, %d)", specIndex, spec.inX, spec.inY, spec.expX, spec.expY, x, y)
}
}
}
func TestWrite(t *testing.T) {
fb := make([]uint16, 80*25)
cons := &console.Vga{}
cons.OverrideFb(fb)
cons.Init()
var vt Vt
vt.Init(cons)
vt.Clear()
vt.SetPosition(0, 1)
vt.Write([]byte("12\n3\n4\r56"))
// Trigger scroll
vt.SetPosition(79, 24)
vt.Write([]byte{'!'})
specs := []struct {
x, y uint16
expChar byte
}{
{0, 0, '1'},
{1, 0, '2'},
{0, 1, '3'},
{0, 2, '5'},
{1, 2, '6'},
{79, 23, '!'},
}
for specIndex, spec := range specs {
ch := (byte)(fb[(spec.y*vt.width)+spec.x] & 0xFF)
if ch != spec.expChar {
t.Errorf("[spec %d] expected char at (%d, %d) to be %c; got %c", specIndex, spec.x, spec.y, spec.expChar, ch)
}
}
}