Exemplo n.º 1
0
// TestImage compares a saved expected image of a given filename with
// an actual image.Image that typically contains the result of a
// rendering. It returns the distance value and the two compared
// images.
func TestImage(filename string, act image.Image, adjust imagetest.Adjuster) (float64, image.Image, image.Image, error) {
	request := mandala.LoadResourceRequest{
		Filename: filepath.Join(expectedImgPath, filename),
		Response: make(chan mandala.LoadResourceResponse),
	}

	mandala.ResourceManager() <- request
	response := <-request.Response
	buffer := response.Buffer

	if response.Error != nil {
		return 1, nil, nil, response.Error
	}

	exp, err := png.Decode(bytes.NewBuffer(buffer))
	if err != nil {
		return 1, nil, nil, err
	}
	return imagetest.CompareDistance(exp, act, adjust), exp, act, nil
}
Exemplo n.º 2
0
func (t *TestSuite) TestDraw() {
	request := mandala.LoadResourceRequest{
		Filename: "drawable/expected.png",
		Response: make(chan mandala.LoadResourceResponse),
	}

	mandala.ResourceManager() <- request
	response := <-request.Response
	buffer := response.Buffer

	t.True(response.Error == nil, "An error occured during resource opening")

	if buffer != nil {
		exp, err := png.Decode(bytes.NewBuffer(buffer))
		t.True(err == nil, "An error occured during png decoding")

		distance := imagetest.CompareDistance(exp, <-t.testDraw, nil)
		t.True(distance < 0.1, fmt.Sprintf("Distance is %f", distance))
	}
}