58 lines
2.2 KiB
Go
58 lines
2.2 KiB
Go
//go:build windows
|
|
|
|
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
"unicode/utf8"
|
|
)
|
|
|
|
func TestReportTableHeavyFirstAndTruePriorityDirections(t *testing.T) {
|
|
r := scanReport{Title: "ИГРОВОЙ РЕЖИМ ВКЛЮЧЁН", Rows: []priorityChange{{Name: "Background.exe", PID: 20, RSS: 500, Before: PriorityClassNormal, After: PriorityClassIdle}, {Name: "Game.exe", PID: 10, RSS: 3000000000, Before: PriorityClassNormal, After: PriorityClassHigh, Heavy: true}}}
|
|
text := formatReport(r, time.Unix(0, 0))
|
|
if !strings.Contains(text, "Повышено") || !strings.Contains(text, "Понижено") || !strings.Contains(text, "+---") {
|
|
t.Fatalf("missing ASCII table: %q", text)
|
|
}
|
|
if strings.Index(text, "Game.exe") > strings.Index(text, "Background.exe") {
|
|
t.Fatal("heavy process must precede lowered processes")
|
|
}
|
|
var gameLine, bgLine string
|
|
for _, line := range strings.Split(text, "\n") {
|
|
if strings.Contains(line, "Game.exe") {
|
|
gameLine = line
|
|
}
|
|
if strings.Contains(line, "Background.exe") {
|
|
bgLine = line
|
|
}
|
|
}
|
|
if !strings.Contains(strings.Split(gameLine, "|")[4], "NORMAL -> HIGH") {
|
|
t.Fatal("raise in wrong column", gameLine)
|
|
}
|
|
if !strings.Contains(strings.Split(bgLine, "|")[5], "NORMAL -> IDLE") {
|
|
t.Fatal("numeric Win32 constants mistaken for scheduling rank", bgLine)
|
|
}
|
|
if r.Rows[0].Name != "Background.exe" {
|
|
t.Fatal("formatter mutated caller's report")
|
|
}
|
|
}
|
|
func TestReportNoFakePromotionNoControlCharacters(t *testing.T) {
|
|
r := scanReport{Title: "MODE", DryRun: true, Rows: []priorityChange{{Name: "bad\r\n\x1b|name.exe", PID: 1, Before: PriorityClassHigh, After: PriorityClassHigh, Heavy: true, Unchanged: true}}, Errors: []processError{{Description: "denied\r\nforged"}}}
|
|
s := formatReport(r, time.Unix(0, 0))
|
|
if strings.Contains(s, "HIGH -> HIGH") || strings.ContainsAny(s, "\r\x1b") {
|
|
t.Fatalf("misleading or unsafe record: %q", s)
|
|
}
|
|
if !strings.Contains(s, "уже HIGH") || !strings.Contains(s, "DRY-RUN") {
|
|
t.Fatal("missing unchanged/dry-run markers")
|
|
}
|
|
if !utf8.ValidString(s) {
|
|
t.Fatal("invalid UTF-8")
|
|
}
|
|
}
|
|
func TestEmptyReportProducesNoLog(t *testing.T) {
|
|
if got := formatReport(scanReport{}, time.Time{}); got != "" {
|
|
t.Fatalf("noisy empty report %q", got)
|
|
}
|
|
}
|