draw2d/sync_test.go

47 lines
1,022 B
Go
Raw Normal View History

2017-12-04 08:46:40 +00:00
// go test -race -test.v sync_test.go
2016-12-13 21:22:19 +00:00
package draw2d_test
import (
"fmt"
"image"
"testing"
2018-11-16 11:21:14 +00:00
"git.fromouter.space/crunchy-rocks/draw2d"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dimg"
"git.fromouter.space/crunchy-rocks/draw2d/draw2dkit"
2016-12-13 21:22:19 +00:00
)
func TestSync(t *testing.T) {
ch := make(chan int)
2017-12-04 08:46:40 +00:00
limit := 2
2016-12-13 21:22:19 +00:00
for i := 0; i < limit; i++ {
go Draw(i, ch)
}
for i := 0; i < limit; i++ {
counter := <-ch
t.Logf("Goroutine %d returned\n", counter)
}
}
2016-12-13 21:23:50 +00:00
func Draw(i int, ch chan<- int) {
draw2d.SetFontFolder("./resource/font")
2016-12-13 21:22:19 +00:00
// Draw a rounded rectangle using default colors
dest := image.NewRGBA(image.Rect(0, 0, 297, 210.0))
gc := draw2dimg.NewGraphicContext(dest)
draw2dkit.RoundedRectangle(gc, 5, 5, 135, 95, 10, 10)
gc.FillStroke()
// Set the fill text color to black
gc.SetFillColor(image.Black)
gc.SetFontSize(14)
// Display Hello World dimensions
x1, y1, x2, y2 := gc.GetStringBounds("Hello world")
gc.FillStringAt(fmt.Sprintf("%.2f %.2f %.2f %.2f", x1, y1, x2, y2), 0, 0)
ch <- i
}