-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathqrcode_test.go
50 lines (46 loc) · 1.82 KB
/
qrcode_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
package qrcode
import (
"os"
"path/filepath"
"testing"
"time"
)
func TestDecode(t *testing.T) {
tests := []struct {
in, out string
}{
{in: "qrcode.jpg", out: "http://www.imdb.com/title/tt2948356/"},
{in: "qrcode.png", out: "http://weixin.qq.com/r/2fKmvj-EkmLtrXvd96fL"},
{in: "qrcode1.png", out: "http://weixin.qq.com/r/2fKmvj-EkmLtrXvd96fL"},
{in: "qrcode4.png", out: "http://www.example.org"},
{in: "qrcode5.png", out: "a"},
{in: "qrcode6.png", out: "abcdefg"},
{in: "qrcode7.png", out: "abcdefg"},
{in: "qrcode8.png", out: "中文"},
{in: "qrcode9.png", out: "abcdefg"},
{in: "qrcode10.png", out: "abcdefghijklmnopqrstuvwxyz"},
{in: "qrcode11.png", out: `PProf是一个CPU分析器( cpu profiler), 它是gperftools工具的一个组件, 由Google工程师为分析多线程的程序所开发。
Go标准库中的pprof package通过HTTP的方式为pprof工具提供数据。
(译者注:不止这个包,runtime/pprof还可以为控制`},
{in: "qrcode13.png", out: `PProf是一个CPU分析器( cpu profiler), 它是gperftools工具的一个组件, 由Google工程师为分析多线程的程序所开发。
Go标准库中的pprof package通过HTTP的方式为pprof工具提供数据。
(译者注:不止这个包,runtime/pprof还可以为控制`},
{in: "qrcode14.jpeg", out: "AEL-10007-78402-01XXB45EBF1163C414B24AFD062B008024605AA3AB554463147C78A4B0ECA23B1DA80"},
{in: "qrcode15.jpeg", out: "AEL-10007-78379-02XX524DBEEF63C414A830F3062A0047E2404ECEAF6E8C1DCCF9E0ED2484355C22EF0"},
}
for _, tt := range tests {
f, err := os.Open(filepath.Join("example", tt.in))
if err != nil {
t.Fatal(err)
}
startAt := time.Now()
qr, err := Decode(f)
if err != nil {
t.Fatal(err)
}
if qr.Content != tt.out {
t.Errorf("expect: %s, got: %s", tt.out, qr.Content)
}
t.Log(time.Since(startAt))
}
}