aboutsummaryrefslogtreecommitdiff
path: root/unicorn/Unicorn2_test.go
diff options
context:
space:
mode:
authorMartin Ashby <martin@martin-laptop.lan>2018-05-28 16:31:18 +0100
committerMartin Ashby <martin@martin-laptop.lan>2018-05-28 16:31:18 +0100
commit28f0ac19eb3b42601b0511131b5e39c77b80da9c (patch)
treea0765d2742926bb418ce623175876a68cb000c8b /unicorn/Unicorn2_test.go
parent5766b0c285052d48ab7756c9c3eef6ae41ecd36e (diff)
parentf20896ef3b147ac07769eb36c67ba436c6d2ed22 (diff)
downloadunicornpaint-28f0ac19eb3b42601b0511131b5e39c77b80da9c.tar.gz
unicornpaint-28f0ac19eb3b42601b0511131b5e39c77b80da9c.tar.bz2
unicornpaint-28f0ac19eb3b42601b0511131b5e39c77b80da9c.tar.xz
unicornpaint-28f0ac19eb3b42601b0511131b5e39c77b80da9c.zip
Merge branch 'master' of github.com:MFAshby/unicornpaint
Diffstat (limited to 'unicorn/Unicorn2_test.go')
-rw-r--r--unicorn/Unicorn2_test.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/unicorn/Unicorn2_test.go b/unicorn/Unicorn2_test.go
new file mode 100644
index 0000000..c74571f
--- /dev/null
+++ b/unicorn/Unicorn2_test.go
@@ -0,0 +1,61 @@
+package unicorn
+
+import (
+ "bytes"
+ "image/gif"
+ "testing"
+ "time"
+)
+
+func gifAsset(name string) (*gif.GIF, error) {
+ data, err := Asset(name)
+ if err != nil {
+ return nil, err
+ }
+
+ g, err := gif.DecodeAll(bytes.NewReader(data))
+ if err != nil {
+ return nil, err
+ }
+
+ return g, nil
+}
+
+func TestAnimated(t *testing.T) {
+ un, err := NewUnicorn2()
+ if err != nil {
+ t.Errorf("Failed to create fake unicorn :( %v", err)
+ return
+ }
+ defer un.Close()
+
+ g, err := gifAsset("data/sample.gif")
+ if err != nil {
+ t.Errorf("Failed to load asset %v", err)
+ return
+ }
+
+ un.SetGif(g)
+ stopChan := un.StartRender()
+
+ // Stop after 3
+ time.Sleep(3 * time.Second)
+ stopChan <- true
+
+ // Leave it for a sec
+ time.Sleep(1 * time.Second)
+ g2, err := gifAsset("data/sample2.gif")
+ if err != nil {
+ t.Errorf("Failed to load asset %v", err)
+ return
+ }
+ un.SetGif(g2)
+ stopChan = un.StartRender()
+
+ // Stop after 5
+ time.Sleep(5 * time.Second)
+ stopChan <- true
+
+ // Make sure it's stopped
+ time.Sleep(2 * time.Second)
+}