// 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 . package config import ( "path/filepath" "reflect" "testing" ) func TestScriptDefaultsAndSaveRoundTrip(t *testing.T) { for _, version := range []string{"1", "2", "3"} { settings, err := Decode([]byte("version=" + version + "\n[general]\nscript_path='/custom/scripts'\nscript_keys=['KEY_F12','KEY_RIGHTCTRL']\n[scripts]\ntimeout_seconds=20\n[remote]\nsocket_file='/tmp/private.sock'\n")) if err != nil || settings.General.ScriptPath != "/custom/scripts" || settings.Scripts.TimeoutSeconds != 20 || settings.Remote.SocketFile != "/tmp/private.sock" { t.Fatal(version, settings, err) } path := filepath.Join(t.TempDir(), "settings.toml") doc, err := Open_document(path, settings) if err != nil { t.Fatal(err) } if err := doc.Save(settings); err != nil { t.Fatal(err) } loaded, _, err := Load(path, nil) // TOML serializes a nil device slice as an empty array. if len(loaded.Keyboard.Devices) == 0 && len(settings.Keyboard.Devices) == 0 { loaded.Keyboard.Devices = settings.Keyboard.Devices } if err != nil || !reflect.DeepEqual(loaded, settings) { t.Fatal(loaded, err) } } defaults := Defaults() if !reflect.DeepEqual(defaults.General.ScriptKeys, []string{"KEY_COMPOSE"}) || defaults.General.ScriptPath != "/usr/share/fenrirscreenreader/scripts" || defaults.Scripts.TimeoutSeconds != 0 { t.Fatal(defaults) } } func TestRejectInvalidScriptLimitsAndModifierNames(t *testing.T) { for _, data := range []string{"[scripts]\nworkers=0", "[scripts]\nqueue_limit=0", "[scripts]\noutput_bytes=0", "[scripts]\ntimeout_seconds=-1", "[general]\nscript_keys=['KEY_UNKNOWN_123']"} { if _, err := Decode([]byte("version=3\n" + data)); err == nil { t.Fatal("accepted invalid settings", data) } } }