Files

49 lines
1.5 KiB
Go

package config
import "testing"
func TestOCRSettingsPersistAndRebase(t *testing.T) {
settings := DefaultSettings()
settings.OCR = OCRSettings{Language: "fra+eng", Layout: 11, Scale: 3, Grayscale: true,
Invert: true, BlackWhite: true, Threshold: 231, AutoRefresh: true, RefreshInterval: 700,
ConfirmClick: false, CopyFirstResult: true, AutoReadAll: true}
encoded, err := encodeWritable(settings)
if err != nil {
t.Fatal(err)
}
decoded, err := decodeWritable(encoded)
if err != nil {
t.Fatal(err)
}
if decoded.OCR != settings.OCR {
t.Fatalf("OCR settings changed: %+v", decoded.OCR)
}
global := DefaultSettings()
application := global
application.OCR.Language = "deu"
global.OCR.AutoReadAll = true
application.OCR.AutoReadAll = false
newGlobal := global
newGlobal.OCR.Scale = 2
rebased := RebaseApplicationSettings(global, newGlobal, application)
if rebased.OCR.Language != "deu" || rebased.OCR.Scale != 2 || rebased.OCR.AutoReadAll {
t.Fatalf("OCR override rebase: %+v", rebased.OCR)
}
}
func TestOCRAutoReadAllDefaultsAndExplicitFalse(t *testing.T) {
settings := DefaultSettings()
if settings.OCR.AutoReadAll {
t.Fatal("automatic OCR reading must default off")
}
settings.OCR.AutoReadAll = true
apply_profile_ocr(&settings.OCR, writableOCR{})
if !settings.OCR.AutoReadAll {
t.Fatal("omitted setting changed inherited value")
}
apply_profile_ocr(&settings.OCR, writableOCR{AutoReadAll: boolPointer(false)})
if settings.OCR.AutoReadAll {
t.Fatal("explicit false did not override inherited value")
}
}