// Cthulhu screen reader. // Copyright (c) 2026 Storm Dragon // Authors: Storm Dragon, Angus Kola // // 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 app import ( "testing" "git.stormux.org/storm/cthulhu/internal/config" ) func TestSpeechSettingsFromConfig(t *testing.T) { rate, pitch, gain := 75.0, 4.5, 5.0 settings := config.DefaultSettings() settings.VerbalizePunctuationStyle = 2 settings.CapitalizationStyle = "icon" settings.DefaultVoice = config.Voice{ Rate: &rate, AveragePitch: &pitch, Gain: &gain, Family: &config.VoiceFamily{Name: "Generic Voice", Lang: "en", Dialect: "US"}, } got := speechSettingsFromConfig(settings) if got.Rate == nil || *got.Rate != 52 || got.Pitch == nil || *got.Pitch != 0 || got.Volume == nil || *got.Volume != 40 { t.Fatalf("converted voice values = rate %v pitch %v volume %v", got.Rate, got.Pitch, got.Volume) } if got.Punctuation != "some" || got.Capitalization != "icon" || got.Language != "en-US" || got.SynthesisVoice != "Generic Voice" { t.Fatalf("converted speech settings = %#v", got) } } func TestSpeechSettingsLanguageWithoutPerson(t *testing.T) { settings := config.DefaultSettings() settings.DefaultVoice.Family = &config.VoiceFamily{Lang: "es"} got := speechSettingsFromConfig(settings) if got.Language != "es" || got.SynthesisVoice != "" { t.Fatalf("language-only speech settings = %#v", got) } } func TestPresentationSettingsFromConfig(t *testing.T) { settings := config.DefaultSettings() settings.SpeakDescription = false settings.PlaySoundForRole = true settings.PlaySoundForState = true settings.PlaySoundForPositionInSet = true settings.RoleSoundPresentation = "speech_only" settings.EnableKeyEcho = false settings.EnableEchoByCharacter = true settings.EnableEchoByWord = true settings.EnableEchoBySentence = true settings.EnableAlphabeticKeys = false settings.EnableNumericKeys = false settings.EnablePunctuationKeys = false settings.EnableSpace = false settings.EnableDiacriticalKeys = true got := presentationSettingsFromConfig(settings, true) if got.SpeakDescription || !got.EnableSound || !got.PlaySoundForRole || !got.PlaySoundForState || !got.PlaySoundForPositionInSet || got.RoleSoundPresentation != "speech_only" || got.EnableKeyEcho || !got.EnableEchoByCharacter || !got.EnableEchoByWord || !got.EnableEchoBySentence || got.EnableAlphabeticKeys || got.EnableNumericKeys || got.EnablePunctuationKeys || got.EnableSpace || !got.EnableDiacriticalKeys { t.Fatalf("presentation settings = %+v", got) } settings.EnableSound = false settings.PlaySoundForPositionInSet = false if got := presentationSettingsFromConfig(settings, true); got.PlaySoundForPositionInSet { t.Fatal("disabled position setting remained enabled in presentation") } if got := presentationSettingsFromConfig(settings, true); got.EnableSound { t.Fatal("disabled sound setting remained enabled in presentation") } settings.EnableSound = true settings.SoundTheme = "none" if got := presentationSettingsFromConfig(settings, true); got.EnableSound { t.Fatal("none sound theme remained enabled in presentation") } } func TestInputEchoSettingsFromConfig(t *testing.T) { settings := config.DefaultSettings() settings.EnableModifierKeys = false settings.EnableFunctionKeys = false settings.EnableActionKeys = false settings.EnableNavigationKeys = true settings.EnableDiacriticalKeys = true settings.CthulhuModifierKeys = []string{"Insert"} got := inputEchoSettingsFromConfig(settings) if !got.EnableKeyEcho || got.EnableModifierKeys || got.EnableFunctionKeys || got.EnableActionKeys || !got.EnableNavigationKeys || !got.EnableDiacriticalKeys || len(got.CthulhuModifierKeys) != 1 || got.CthulhuModifierKeys[0] != "Insert" { t.Fatalf("input echo settings = %+v", got) } settings.CthulhuModifierKeys[0] = "KP_Insert" if got.CthulhuModifierKeys[0] != "Insert" { t.Fatal("input echo settings retained the mutable configuration slice") } }