-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmicro_qrcode_test.go
126 lines (121 loc) · 3.5 KB
/
micro_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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package test
import (
"fmt"
"github.com/KangSpace/gqrcode"
"github.com/KangSpace/gqrcode/core/output"
"strconv"
"testing"
)
// -----------------------------TestMicroQRCode----------------------------------
// TestNewNumeric1MicroQRCode : test 1 single numeric MicroQRCode
func TestNewNumeric1MicroQRCode(t *testing.T) {
data := "0123456789012345"
fmt.Println(len(data))
//data := "8675309"
fileNamePrefix := "numeric_micro_qrcode"
fileName := gqrcodePath + fileNamePrefix + ".png"
out := output.NewPNGOutput(60 * 4)
qrcode, err := gqrcode.NewMicroQRCode(data)
if err != nil {
t.Fatal(err)
}
err = qrcode.Encode(out, fileName)
if err != nil {
t.Fatal(err)
}
fmt.Printf("version:%v,moduleSize:%d, size:%d, ec:%v mode:%s \n", qrcode.Version, qrcode.Version.GetModuleSize(), out.Size, qrcode.ErrorCorrection, qrcode.Mode.GetMode())
fmt.Println("SUCCESS," + fileName)
}
// TestNewNumericAllVersionMicroQRCode :Test numeric all version for Micro QRCode
func TestNewNumericAllVersionMicroQRCode(t *testing.T) {
// Numeric
dataArr := []string{
// M1,5
"01234",
// M2,L:10,M:8
"01234567",
"0123456789",
// M3,L:23,M:18
"01234567890123456789012",
"012345678901235467",
// M4,L:35,M:30,Q:21
"01234567890123456789012345678901234",
"012345678901234567890123456789",
"012345678901234567890",
}
for _, data := range dataArr {
dLen := len(data)
fileNamePrefix := "numeric_micro_qrcode" + strconv.Itoa(dLen)
fileName := gqrcodePath + fileNamePrefix + ".png"
out := output.NewPNGOutput(60 * 4)
qrcode, err := gqrcode.NewMicroQRCode(data)
if err != nil {
t.Fatal(err)
}
err = qrcode.Encode(out, fileName)
if err != nil {
t.Fatal(err)
}
fmt.Printf("version:%v,moduleSize:%d, size:%d, ec:%v mode:%s \n", qrcode.Version, qrcode.Version.GetModuleSize(), out.Size, qrcode.ErrorCorrection, qrcode.Mode.GetMode())
fmt.Println("SUCCESS," + fileName)
}
}
func TestNewAlphaNumericAllVersionMicroQRCode(t *testing.T) {
// Alphanumeric
dataArr := []string{
// M2,L:6,M:5
"012AB",
"012AB+",
// M3,L:14,M:11
"012AB+-*C30",
"012AB+-*C3012AB",
// M4,L:21,M:18,Q:13
"012AB+-*C3012AB+-*C30",
"012AB+-*C3012AB+-*",
"012AB+-*C3012",
}
for _, data := range dataArr {
dLen := len(data)
fileNamePrefix := "alphanumeric_micro_qrcode" + strconv.Itoa(dLen)
fileName := gqrcodePath + fileNamePrefix + ".png"
out := output.NewPNGOutput(60 * 4)
qrcode, err := gqrcode.NewMicroQRCode(data)
if err != nil {
t.Fatal(err)
}
err = qrcode.Encode(out, fileName)
if err != nil {
t.Fatal(err)
}
fmt.Printf("version:%v,moduleSize:%d, size:%d, ec:%v mode:%s \n", qrcode.Version, qrcode.Version.GetModuleSize(), out.Size, qrcode.ErrorCorrection, qrcode.Mode.GetMode())
fmt.Println("SUCCESS," + fileName)
}
}
func TestNewByteAllVersionMicroQRCode(t *testing.T) {
// byte
dataArr := []string{
// M3,L:9,M:7
"abc123ABC",
"abc123A",
// M4,L:15,M:13,Q:9
"i.kangspace.org",
"kangspace.org",
"kangspace",
}
for _, data := range dataArr {
dLen := len(data)
fileNamePrefix := "byte_micro_qrcode" + strconv.Itoa(dLen)
fileName := gqrcodePath + fileNamePrefix + ".png"
out := output.NewPNGOutput(60 * 5)
qrcode, err := gqrcode.NewMicroQRCodeAutoQuiet(data)
if err != nil {
t.Fatal(err)
}
err = qrcode.Encode(out, fileName)
if err != nil {
t.Fatal(err)
}
fmt.Printf("version:%v,moduleSize:%d, size:%d, ec:%v mode:%s \n", qrcode.Version, qrcode.Version.GetModuleSize(), out.Size, qrcode.ErrorCorrection, qrcode.Mode.GetMode())
fmt.Println("SUCCESS," + fileName)
}
}