After commit c018f5fd29 Fenrir is being switched over to go. If you do not want to be part of the testing process, please switch to master.
This commit is contained in:
1 parent
c018f5fd29
commit
0e50de4c76
1047 files changed
+58364
-63747
No files matched your search
@@ -0,0 +1,79 @@
|
||||
// Fenrir console screen reader.
|
||||
// Copyright (c) 2026 Storm Dragon
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it
|
||||
// under the terms of the GNU General Public License as published by the Free
|
||||
// Software Foundation, either version 3 of the License, or (at your option)
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
// more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.html>.
|
||||
|
||||
//go:build linux && cgo
|
||||
|
||||
package console
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"git.stormux.org/storm/fenrir/internal/presentation"
|
||||
"git.stormux.org/storm/fenrir/internal/screen"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestVCSAAttributesUseNativeWordsAndKeepUnicode(t *testing.T) {
|
||||
text := make([]byte, 8)
|
||||
binary.NativeEndian.PutUint32(text, 'é')
|
||||
binary.NativeEndian.PutUint32(text[4:], '界')
|
||||
data := []byte{1, 2, 0, 0, 0, 0, 0, 0}
|
||||
binary.NativeEndian.PutUint16(data[4:], 0x1741)
|
||||
binary.NativeEndian.PutUint16(data[6:], 0x8742)
|
||||
snapshot, err := decode_snapshot(2, data, text)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := decode_attributes(&snapshot, data); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(snapshot.Cells) != "é界" || snapshot.Attributes[0] != (screen.Attribute{Foreground: screen.ColorIndexed | 7, Background: screen.ColorIndexed | 4}) || snapshot.Attributes[1] != (screen.Attribute{Foreground: screen.ColorIndexed | 7, Background: screen.ColorIndexed, Style: screen.ConsoleHigh}) {
|
||||
t.Fatal("attributes corrupted Unicode or cell order", snapshot)
|
||||
}
|
||||
if got := presentation.Format_attributes(snapshot.Attributes[0], "fenrirFGColor|fenrirBGColor|fenrirBold|fenrirBlink"); got != "light gray|blue||" {
|
||||
t.Fatal(got)
|
||||
}
|
||||
if got := presentation.Format_attributes(snapshot.Attributes[1], "fenrirFGColor|fenrirBGColor|fenrirBold|fenrirBlink"); got != "light gray|black||" {
|
||||
t.Fatal(got)
|
||||
}
|
||||
for _, invalid := range [][]byte{data[:4], data[:7], append(append([]byte{}, data...), 0)} {
|
||||
if err := decode_attributes(&snapshot, invalid); err == nil {
|
||||
t.Fatal("accepted partial or oversized VCSA", invalid)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeUnicodeAndGeometry(t *testing.T) {
|
||||
data := make([]byte, 16)
|
||||
for index, value := range []uint32{'é', '界', 0, 0x110000} {
|
||||
binary.NativeEndian.PutUint32(data[index*4:], value)
|
||||
}
|
||||
snapshot, err := decode_snapshot(2, []byte{2, 2, 1, 0}, data)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(snapshot.Cells) != "é界 �" || snapshot.Text(0) != "é界" {
|
||||
t.Fatalf("wrong Unicode: %+v", snapshot)
|
||||
}
|
||||
for _, header := range [][]byte{{}, {0, 2, 0, 0}, {2, 2, 2, 0}, {2, 2, 0, 2}} {
|
||||
if _, err := decode_snapshot(1, header, data); err == nil {
|
||||
t.Fatalf("accepted invalid header %v", header)
|
||||
}
|
||||
}
|
||||
if _, err := decode_snapshot(1, []byte{2, 2, 0, 0}, data[:12]); err == nil {
|
||||
t.Fatal("accepted resize mismatch")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user