This repository has been archived by the owner on Jul 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
recognition_test.go
78 lines (73 loc) · 1.83 KB
/
recognition_test.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package goqr
import (
"bytes"
"github.com/stretchr/testify/assert"
"image"
_ "image/jpeg"
_ "image/png"
"io/ioutil"
"testing"
)
func recognizeFile(path string) (string, error) {
imgdata, err := ioutil.ReadFile(path)
if err != nil {
return "", err
}
img, _, err := image.Decode(bytes.NewReader(imgdata))
if err != nil {
return "", err
}
qrCodes, err := Recognize(img)
if err != nil {
return "", nil
}
return string(qrCodes[0].Payload), nil
}
func TestRecognize(t *testing.T) {
testCases := []struct {
filePath string
text string
}{
{
"example/testdata/000.jpg",
"http://www.amazon.co.jp/gp/aw/rd.html?uid=NULLGWDOCOMO&url=/gp/aw/h.html&at=aw_intl6-22",
},
{
"example/testdata/001.jpg",
"http://www.amazon.co.jp/gp/aw/rd.html?uid=NULLGWDOCOMO&url=/gp/aw/h.html&at=aw_intl6-22",
},
{
"example/testdata/002.jpg",
"http://www.amazon.co.jp/gp/aw/rd.html?uid=NULLGWDOCOMO&url=/gp/aw/h.html&at=aw_intl6-22",
},
{
"example/testdata/003.jpg",
"http://www.amazon.co.jp/gp/aw/rd.html?uid=NULLGWDOCOMO&url=/gp/aw/h.html&at=aw_intl6-22",
},
{
"example/testdata/004.png",
"http://swtch.com/pjw/#523892624657510299353520120480795433576563223876200460867159368633143833417166162086873959805500633263545263286786346759633071266643358952888263169163143415896058956186071276000133287120333224396223386892286076080898690020480143143263415796162046552639449120143662",
},
{
"example/testdata/005.png",
"https://github.com/",
},
{
"example/testdata/006.png",
"https://github.com/liyue201",
},
{
"example/testdata/007.png",
"https://github.com/",
},
{
"example/testdata/008.png",
"https://github.com/liyue201/goqr",
},
}
for _, testCase := range testCases {
text, err := recognizeFile(testCase.filePath)
assert.Nil(t, err)
assert.Equal(t, testCase.text, text)
}
}