File: decode_test.go

package info (click to toggle)
golang-github-edwvee-exiffix 0.0~git20240229.0dbb146-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 108 kB
  • sloc: makefile: 3
file content (46 lines) | stat: -rw-r--r-- 1,090 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package exiffix

import (
	"image/color"
	"os"
	"strconv"
	"testing"
)

func TestDecode(t *testing.T) {
	for i := 1; i < 9; i++ {
		path := "test_data/f" + strconv.Itoa(i) + "t.jpg"
		file, err := os.Open(path)
		if err != nil {
			panic(err)
		}
		defer file.Close()
		img, _, err := Decode(file)
		if err != nil {
			panic(err)
		}
		bounds := img.Bounds()
		minP := bounds.Min
		maxP := bounds.Max
		leftUpper := img.At(minP.X, minP.Y)
		rightUpper := img.At(maxP.X-1, minP.Y)
		leftLower := img.At(minP.X, maxP.Y-1)
		rightLower := img.At(maxP.X-1, maxP.Y-1)
		if !(isBlack(leftUpper) && isBlack(rightUpper) && isBlack(leftLower) && !isBlack(rightLower)) {
			t.Errorf(`
				The path is %s.
				isBlack(leftUpper) && isBlack(rightUpper) && isBlack(leftLower) && !isBlack(rightLower):
				Expected 	%t, %t, %t, %t. 
				Got			%t, %t, %t, %t`,
				path,
				true, true, true, true,
				isBlack(leftUpper), isBlack(rightUpper), isBlack(leftLower), !isBlack(rightLower),
			)
		}
	}
}

func isBlack(point color.Color) bool {
	r, g, b, _ := point.RGBA()
	return r == 0 && g == 0 && b == 0
}