aboutsummaryrefslogtreecommitdiffstats
path: root/internal/notify/service_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/notify/service_test.go')
-rw-r--r--internal/notify/service_test.go37
1 files changed, 37 insertions, 0 deletions
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()