unicornpaint

A web-based painting app for raspberry PI and pimoroni Unicorn Hat HD
Log | Files | Refs | README

Unicorn2_test.go (1005B)


      1 package unicorn
      2 
      3 import (
      4 	"bytes"
      5 	"image/gif"
      6 	"testing"
      7 	"time"
      8 )
      9 
     10 func gifAsset(name string) (*gif.GIF, error) {
     11 	data, err := Asset(name)
     12 	if err != nil {
     13 		return nil, err
     14 	}
     15 
     16 	g, err := gif.DecodeAll(bytes.NewReader(data))
     17 	if err != nil {
     18 		return nil, err
     19 	}
     20 
     21 	return g, nil
     22 }
     23 
     24 func TestAnimated(t *testing.T) {
     25 	un, err := NewUnicorn2()
     26 	if err != nil {
     27 		t.Errorf("Failed to create fake unicorn :( %v", err)
     28 		return
     29 	}
     30 	defer un.Close()
     31 
     32 	g, err := gifAsset("data/sample.gif")
     33 	if err != nil {
     34 		t.Errorf("Failed to load asset %v", err)
     35 		return
     36 	}
     37 
     38 	un.SetGif(g)
     39 	stopChan := un.StartRender()
     40 
     41 	// Stop after 3
     42 	time.Sleep(3 * time.Second)
     43 	stopChan <- true
     44 
     45 	// Leave it for a sec
     46 	time.Sleep(1 * time.Second)
     47 	g2, err := gifAsset("data/sample2.gif")
     48 	if err != nil {
     49 		t.Errorf("Failed to load asset %v", err)
     50 		return
     51 	}
     52 	un.SetGif(g2)
     53 	stopChan = un.StartRender()
     54 
     55 	// Stop after 5
     56 	time.Sleep(5 * time.Second)
     57 	stopChan <- true
     58 
     59 	// Make sure it's stopped
     60 	time.Sleep(2 * time.Second)
     61 }