package main import ( "reflect" "strings" "testing" ) // picom's shape (novox/hq ADR 0208): it claims node-compositor and serves no verb of it, requires the // X display on its own machine, owns its configuration file, and is started once, by its package's // XDG autostart entry, never by the window manager or the session's start as well. func TestItClaimsTheCompositorSeatAndRequiresTheXDisplay(t *testing.T) { m := readManifest(t) if m.Module != "picom" || m.Seats != nil { t.Fatalf("module %q declares seats %v", m.Module, m.Seats) } if !reflect.DeepEqual(m.Claims, []claim{{Name: "node-compositor", Scope: "node"}}) { t.Fatalf("claims: %+v", m.Claims) } if !reflect.DeepEqual(m.Requires, []string{"x11-display"}) { t.Fatalf("requires: %v", m.Requires) } if present, absent := m.packages(); !reflect.DeepEqual(present, []string{"picom", "xorg-xprop"}) || absent != nil { t.Fatalf("packages: %v, absent %v", present, absent) } } func TestItOwnsItsConfigurationAsWrittenInTheModule(t *testing.T) { m := readManifest(t) m.sameAsSource(t, "configuration", "files/picom.conf") if p := m.resource(t, "configuration")["path"]; p != "${machine:account-home}/.config/picom/picom.conf" { t.Fatalf("path: %v", p) } if d := m.resource(t, "configuration-dir"); d["type"] != "directory" || d["path"] != "${machine:account-home}/.config/picom" { t.Fatalf("the directory: %v", d) } } func TestThePackagesAutostartEntryIsItsOnlyStart(t *testing.T) { m := readManifest(t) // picom's package ships /etc/xdg/autostart/picom.desktop, which the session's dex runs. A second // start from here would be a second compositor, refused by the first. if m.Shell != nil { t.Fatalf("a session-start line as well as the package's autostart entry: %+v", m.Shell) } for _, r := range m.Resources { if p, _ := r["path"].(string); strings.Contains(p, "i3/config.d") || strings.Contains(p, "autostart") { t.Fatalf("a second start: %v", r) } if r["type"] == "service" || r["type"] == "process" { t.Fatalf("a unit: %v", r) } } } func TestTheToolsAgreeWithTheManifest(t *testing.T) { m := readManifest(t) checkTheToolsAgree(t, m) checkNoSecretsOrInstallationNames(t) } // The backend and damage tracking are each machine's (novox/hq research 037: the backend depends on the // machine's graphics driver; issue 345: a window left unpainted under glx is the first suspect). Both // are settings whose defaults are what every machine ran before, so the file filled with them is today's. func TestTheBackendAndDamageTrackingAreSettingsWithTodaysDefaults(t *testing.T) { m := readManifest(t) b, d := m.Settings["backend"], m.Settings["use-damage"] if b.Kind != "preference" || b.Default != "glx" || b.Why == "" || d.Kind != "preference" || d.Default != true || d.Why == "" { t.Fatalf("settings: %+v", m.Settings) } r := m.resource(t, "configuration") c := r["content"].(string) for _, want := range []string{`backend = "${setting:backend}";`, "use-damage = ${setting:use-damage};"} { if !strings.Contains(c, want) { t.Errorf("the file asks for %q", want) } } // Trusted (unmarked): a value is pasted into the file as it is, so `xrender"; write-pid-path = "…` // would add an option of the caller's. Until settings are typed and quoted (hq issue 346), only the // controller's terminal sets them. if _, marked := r["trusted"]; marked { t.Fatal("the file stays trusted: its settings are set at the terminal alone (hq issue 346)") } got := parseRules("picom.conf", withDefaults(c), nil) if got.Global["backend"] != "glx" || got.Global["use-damage"] != "true" || got.Global["vsync"] != "true" { t.Fatalf("filled with the defaults: %v", got.Global) } } // withDefaults fills the file's settings with their defaults, as a machine without its own values gets it. func withDefaults(c string) string { return strings.NewReplacer("${setting:backend}", "glx", "${setting:use-damage}", "true").Replace(c) }