Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test for concurrent text drawing #126

Merged
merged 4 commits into from
Dec 4, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions sync_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// go test -race -test.v sync_test.go

package draw2d_test

import (
"fmt"
"github.com/llgcode/draw2d"
"github.com/llgcode/draw2d/draw2dimg"
"github.com/llgcode/draw2d/draw2dkit"
"image"
"testing"
)

func TestSync(t *testing.T) {
ch := make(chan int)
limit := 2000
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)
}
}

func Draw(i int, ch chan<- int) {
draw2d.SetFontFolder("./resource/font")
// 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
}