-
Notifications
You must be signed in to change notification settings - Fork 4
/
scanner_test.go
108 lines (86 loc) · 1.78 KB
/
scanner_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package gozbar
import (
"image/jpeg"
"image/png"
"os"
"testing"
)
func TestBarcode(t *testing.T) {
const expectedVal = "9876543210128"
f, err := os.Open("testdata/barcode.png")
if err != nil {
t.Fatal(err)
}
i, err := png.Decode(f)
if err != nil {
t.Fatal(err)
}
img := FromImage(i)
s := NewScanner()
err = s.SetConfig(0, CFG_ENABLE, 1)
if err != nil {
t.Fatal("error setting config", err)
}
err = s.Scan(img)
if err != nil {
t.Fatal("error scanning", err)
}
defer s.Destroy()
img.First().Each(func(str string) {
if str != expectedVal {
t.Fatalf("expected [%s] got [%s]", expectedVal, str)
}
})
}
func TestQRCode(t *testing.T) {
const expectedVal = "ZBar big law good! ZBar螟ァ豕募・ス!"
f, err := os.Open("testdata/qr.jpg")
if err != nil {
t.Fail()
return
}
i, _ := jpeg.Decode(f)
img := FromImage(i)
s := NewScanner()
err = s.SetConfig(0, CFG_ENABLE, 1)
if err != nil {
t.Fatal("error setting config", err)
}
err = s.Scan(img)
if err != nil {
t.Fatal("error scanning", err)
}
defer s.Destroy()
img.First().Each(func(str string) {
if str != expectedVal {
t.Fatalf("expected [%s] got [%s]", expectedVal, str)
}
})
}
func TestPhoto(t *testing.T) {
const expectedStr = "http://www.searchenginestrategies.com/sanfrancisco/share.html"
f, err := os.Open("./testdata/photo.jpg")
if err != nil {
t.Fatal(err)
}
i, err := jpeg.Decode(f)
if err != nil {
t.Fatal(err)
}
img := FromImage(i)
s := NewScanner()
err = s.SetConfig(0, CFG_ENABLE, 1)
if err != nil {
t.Fatal("error setting config", err)
}
err = s.Scan(img)
if err != nil {
t.Fatal("error scanning", err)
}
defer s.Destroy()
img.First().Each(func(str string) {
if str != expectedStr {
t.Fatalf("expected [%s] got [%s]", expectedStr, str)
}
})
}