Ejemplo n.º 1
0
func TestSimpleProcessor(t *testing.T) {
	g1 := newTestImage()
	prc := &SimpleProcessor{
		Processor: imageserver_image.ProcessorFunc(func(nim image.Image, params imageserver.Params) (image.Image, error) {
			return image.NewRGBA(image.Rectangle{Min: nim.Bounds().Min.Div(2), Max: nim.Bounds().Max.Div(2)}), nil
		}),
	}
	g2, err := prc.Process(g1, imageserver.Params{})
	if err != nil {
		t.Fatal(err)
	}
	if len(g1.Image) != len(g2.Image) {
		t.Fatalf("Image length not equal: %d & %d", len(g1.Image), len(g2.Image))
	}
	if !reflect.DeepEqual(g1.Delay, g2.Delay) {
		t.Fatalf("Delay not equal: %#v & %#v", g1.Delay, g2.Delay)
	}
	if g1.LoopCount != g2.LoopCount {
		t.Fatalf("LoopCount not equal: %d & %d", g1.LoopCount, g2.LoopCount)
	}
	if !reflect.DeepEqual(g1.Config.ColorModel, g2.Config.ColorModel) {
		t.Fatalf("Config.ColorModel not equal: %#v & %#v", g1.Config.ColorModel, g2.Config.ColorModel)
	}
	if g2.Config.Width != 50 {
		t.Fatalf("unexpected Config.Width value: got %d, want %d", g2.Config.Width, 50)
	}
	if g2.Config.Height != 50 {
		t.Fatalf("unexpected Config.Height value: got %d, want %d", g2.Config.Height, 50)
	}
	if g1.BackgroundIndex != g2.BackgroundIndex {
		t.Fatalf("BackgroundIndex not equal: %d & %d", g1.BackgroundIndex, g2.BackgroundIndex)
	}
}
Ejemplo n.º 2
0
func TestSimpleProcessorError(t *testing.T) {
	g := newTestImage()
	prc := &SimpleProcessor{
		Processor: imageserver_image.ProcessorFunc(func(nim image.Image, params imageserver.Params) (image.Image, error) {
			return nil, fmt.Errorf("error")
		}),
	}
	_, err := prc.Process(g, imageserver.Params{})
	if err == nil {
		t.Fatal("no error")
	}
}
Ejemplo n.º 3
0
func BenchmarkCorrectionProcessor(b *testing.B) {
	nim, err := imageserver_image.Decode(testdata.Medium)
	if err != nil {
		b.Fatal(err)
	}
	prc := NewCorrectionProcessor(
		imageserver_image.ProcessorFunc(func(nim image.Image, params imageserver.Params) (image.Image, error) {
			return nim, nil
		}),
		true,
	)
	params := imageserver.Params{}
	for i := 0; i < b.N; i++ {
		prc.Process(nim, params)
	}
}
func BenchmarkCorrectionProcessor(b *testing.B) {
	nim, err := imageserver_image.Decode(testdata.Medium)
	if err != nil {
		b.Fatal(err)
	}
	prc := NewCorrectionProcessor(
		imageserver_image.ProcessorFunc(func(nim image.Image, params imageserver.Params) (image.Image, error) {
			return nim, nil
		}),
		true,
	)
	params := imageserver.Params{}
	b.RunParallel(func(pb *testing.PB) {
		for pb.Next() {
			prc.Process(nim, params)
		}
	})
}
Ejemplo n.º 5
0
func TestCorrectionProcessor(t *testing.T) {
	nim, err := imageserver_image.Decode(testdata.Medium)
	if err != nil {
		t.Fatal(err)
	}
	simplePrc := imageserver_image.ProcessorFunc(func(nim image.Image, params imageserver.Params) (image.Image, error) {
		return nim, nil
	})
	errPrc := imageserver_image.ProcessorFunc(func(nim image.Image, params imageserver.Params) (image.Image, error) {
		return nil, fmt.Errorf("error")
	})
	type TC struct {
		processor     imageserver_image.Processor
		enabled       bool
		params        imageserver.Params
		errorExpected bool
	}
	for _, tc := range []TC{
		{
			processor: simplePrc,
			enabled:   true,
		},
		{
			processor: simplePrc,
			enabled:   false,
		},
		{
			processor: simplePrc,
			enabled:   true,
			params: imageserver.Params{
				"gamma_correction": false,
			},
		},
		{
			processor: simplePrc,
			enabled:   false,
			params: imageserver.Params{
				"gamma_correction": true,
			},
		},
		{
			processor:     errPrc,
			enabled:       true,
			errorExpected: true,
		},
		{
			processor: simplePrc,
			enabled:   true,
			params: imageserver.Params{
				"gamma_correction": "invalid",
			},
			errorExpected: true,
		},
	} {
		func() {
			defer func() {
				if t.Failed() {
					t.Logf("%#v", tc)
				}
			}()
			prc := NewCorrectionProcessor(tc.processor, tc.enabled)
			params := tc.params
			if params == nil {
				params = imageserver.Params{}
			}
			_, err = prc.Process(nim, params)
			if tc.errorExpected && err == nil {
				t.Fatal("no error")
			} else if !tc.errorExpected && err != nil {
				t.Fatal(err)
			}
		}()

	}
}
Ejemplo n.º 6
0
func TestCorrectionProcessor(t *testing.T) {
	nim, err := imageserver_image.Decode(testdata.Medium)
	if err != nil {
		t.Fatal(err)
	}
	simplePrc := imageserver_image.ProcessorFunc(func(nim image.Image, params imageserver.Params) (image.Image, error) {
		return nim, nil
	})
	errPrc := imageserver_image.ProcessorFunc(func(nim image.Image, params imageserver.Params) (image.Image, error) {
		return nil, fmt.Errorf("error")
	})
	for _, tc := range []struct {
		name          string
		processor     imageserver_image.Processor
		enabled       bool
		params        imageserver.Params
		errorExpected bool
	}{
		{
			name:      "DefaultEnabled",
			processor: simplePrc,
			enabled:   true,
		},
		{
			name:      "DefaultDisabled",
			processor: simplePrc,
			enabled:   false,
		},
		{
			name:      "ParamDisabled",
			processor: simplePrc,
			enabled:   true,
			params: imageserver.Params{
				"gamma_correction": false,
			},
		},
		{
			name:      "ParamEnabled",
			processor: simplePrc,
			enabled:   false,
			params: imageserver.Params{
				"gamma_correction": true,
			},
		},
		{
			name:          "Error",
			processor:     errPrc,
			enabled:       true,
			errorExpected: true,
		},
		{
			name:      "Invalid",
			processor: simplePrc,
			enabled:   true,
			params: imageserver.Params{
				"gamma_correction": "invalid",
			},
			errorExpected: true,
		},
	} {
		t.Run(tc.name, func(t *testing.T) {
			prc := NewCorrectionProcessor(tc.processor, tc.enabled)
			params := tc.params
			if params == nil {
				params = imageserver.Params{}
			}
			_, err = prc.Process(nim, params)
			if tc.errorExpected && err == nil {
				t.Fatal("no error")
			} else if !tc.errorExpected && err != nil {
				t.Fatal(err)
			}
		})
	}
}