From 6ad6f122eb2ec9cd8a55c042dffe38db41ed1959 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Tue, 15 Sep 2026 18:04:59 +0200 Subject: test(notify): cover image-data materialisation TestNotifyMaterialisesImageData drives a 2x2 RGBA image-data hint through Notify and asserts the PNG is written under the image directory for the returned id, decodes to the right bounds, and is carried on the re-published Popup.Image. The encode-error path now logs instead of dropping the failure silently, matching the WriteImage branch. --- internal/notify/service.go | 2 ++ internal/notify/service_test.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) (limited to 'internal/notify') diff --git a/internal/notify/service.go b/internal/notify/service.go index 7bfad6e..a8f0728 100644 --- a/internal/notify/service.go +++ b/internal/notify/service.go @@ -118,6 +118,8 @@ func (s *Service) Notify(appName string, replacesID uint32, appIcon, summary, bo if raw, ok := ImageDataFromHints(hints); ok { if data, err := raw.PNG(); err == nil { pendingImage = data + } else { + log.Printf("notifyd: encode image: %v", err) } } else if path, ok := ImagePathFromHints(hints); ok { n.Image = ResolveIcon(path) diff --git a/internal/notify/service_test.go b/internal/notify/service_test.go index 611c8fa..3d7c2cc 100644 --- a/internal/notify/service_test.go +++ b/internal/notify/service_test.go @@ -13,8 +13,10 @@ package notify import ( "encoding/json" + "image/png" "os" "path/filepath" + "strconv" "testing" "time" @@ -96,6 +98,41 @@ func TestNotifyPublishesImagePath(t *testing.T) { } } +func TestNotifyMaterialisesImageData(t *testing.T) { + var live []Popup + s := &Service{dir: t.TempDir(), timers: map[uint32]*time.Timer{}} + s.store = NewStore(s.emitClosed, func(l, _ []Popup) { live = l }, s.removeImage) + // A 2x2 RGBA image, row stride exactly width*channels. + data := []byte{ + 255, 0, 0, 255, 0, 255, 0, 255, + 0, 0, 255, 255, 255, 255, 255, 255, + } + hints := map[string]dbus.Variant{"image-data": dbus.MakeVariant([]interface{}{ + int32(2), int32(2), int32(8), true, int32(8), int32(4), data, + })} + id, dbusErr := s.Notify("t", 0, "", "s", "b", nil, hints, -1) + if dbusErr != nil { + t.Fatal(dbusErr) + } + path := filepath.Join(ImagesDir(s.dir), strconv.FormatUint(uint64(id), 10)+".png") + f, err := os.Open(path) + if err != nil { + t.Fatalf("image not written: %v", err) + } + defer f.Close() + img, err := png.Decode(f) + if err != nil { + t.Fatalf("image does not decode: %v", err) + } + if b := img.Bounds(); b.Dx() != 2 || b.Dy() != 2 { + t.Fatalf("decoded %v, want 2x2", b) + } + // The first publish precedes SetImage, so the last one must carry the path. + if len(live) != 1 || live[0].Image != path { + t.Fatalf("published %+v, want image %q", live, path) + } +} + func TestNotifyReturnsAnIDAndPublishes(t *testing.T) { conn := busOrSkip(t) dir := t.TempDir() -- cgit v1.2.3