-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgoBarcodeQrSDK_test.go
114 lines (100 loc) · 3.79 KB
/
goBarcodeQrSDK_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
package goBarcodeQrSDK
import (
"fmt"
"os"
"testing"
"time"
)
func TestInitLicense(t *testing.T) {
ret, _ := InitLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
if ret != 0 {
t.Fatalf(`initLicense("") = %d`, ret)
}
}
func TestCreateBarcodeReader(t *testing.T) {
obj := CreateBarcodeReader()
if obj == nil {
t.Fatalf(`Failed to create instance`)
}
}
func TestDestroyBarcodeReader(t *testing.T) {
obj := CreateBarcodeReader()
DestroyBarcodeReader(obj)
}
func TestSetParameters(t *testing.T) {
obj := CreateBarcodeReader()
ret, _ := obj.SetParameters("{\"ImageParameter\":{\"BarcodeFormatIds\":[\"BF_ONED\",\"BF_PDF417\",\"BF_QR_CODE\",\"BF_DATAMATRIX\"],\"BarcodeFormatIds_2\":null,\"Name\":\"sts\",\"RegionDefinitionNameArray\":[\"region0\"]},\"RegionDefinition\":{\"Bottom\":100,\"Left\":0,\"MeasuredByPercentage\":1,\"Name\":\"region0\",\"Right\":100,\"Top\":0}}")
if ret != 0 {
t.Fatalf(`SetParameters() = %d`, ret)
}
}
func TestLoadTemplateFile(t *testing.T) {
obj := CreateBarcodeReader()
ret, _ := obj.LoadTemplateFile("template.json")
if ret != 0 {
t.Fatalf(`LoadTemplateFile() = %d`, ret)
}
}
func TestDecodeFile(t *testing.T) {
obj := CreateBarcodeReader()
obj.SetParameters("{\"ImageParameter\":{\"BarcodeFormatIds\":[\"BF_ONED\",\"BF_PDF417\",\"BF_QR_CODE\",\"BF_DATAMATRIX\"],\"BarcodeFormatIds_2\":null,\"Name\":\"sts\",\"RegionDefinitionNameArray\":[\"region0\"]},\"RegionDefinition\":{\"Bottom\":100,\"Left\":0,\"MeasuredByPercentage\":1,\"Name\":\"region0\",\"Right\":100,\"Top\":0}}")
ret, _ := obj.DecodeFile("test.png")
if ret != 0 {
t.Fatalf(`DecodeFile() = %d`, ret)
}
}
func TestApp(t *testing.T) {
ret, _ := InitLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
if ret != 0 {
t.Fatalf(`initLicense("") = %d`, ret)
}
obj := CreateBarcodeReader()
obj.SetParameters("{\"ImageParameter\":{\"BarcodeFormatIds\":[\"BF_ONED\",\"BF_PDF417\",\"BF_QR_CODE\",\"BF_DATAMATRIX\"],\"BarcodeFormatIds_2\":null,\"Name\":\"sts\",\"RegionDefinitionNameArray\":[\"region0\"]},\"RegionDefinition\":{\"Bottom\":100,\"Left\":0,\"MeasuredByPercentage\":1,\"Name\":\"region0\",\"Right\":100,\"Top\":0}}")
startTime := time.Now()
code, barcodes := obj.DecodeFile("test.png")
elapsed := time.Since(startTime)
fmt.Println("DecodeFile() time cost: ", elapsed)
if code != 0 {
t.Fatalf(`DecodeFile() = %d`, code)
}
for _, barcode := range barcodes {
fmt.Println(barcode.Text)
fmt.Println(barcode.Format)
fmt.Println(barcode.X1)
fmt.Println(barcode.Y1)
fmt.Println(barcode.X2)
fmt.Println(barcode.Y2)
fmt.Println(barcode.X3)
fmt.Println(barcode.Y3)
fmt.Println(barcode.X4)
fmt.Println(barcode.Y4)
}
}
func TestGetVersion(t *testing.T) {
ret := GetVersion()
fmt.Println(ret)
}
func TestDecodeStream(t *testing.T) {
obj := CreateBarcodeReader()
obj.SetParameters("{\"ImageParameter\":{\"BarcodeFormatIds\":[\"BF_ONED\",\"BF_PDF417\",\"BF_QR_CODE\",\"BF_DATAMATRIX\"],\"BarcodeFormatIds_2\":null,\"Name\":\"sts\",\"RegionDefinitionNameArray\":[\"region0\"]},\"RegionDefinition\":{\"Bottom\":100,\"Left\":0,\"MeasuredByPercentage\":1,\"Name\":\"region0\",\"Right\":100,\"Top\":0}}")
data, err := os.ReadFile("test.png")
if err != nil {
t.Fatalf("Unable to read file: %v", err)
}
ret, barcodes := obj.DecodeStream(data)
if ret != 0 {
t.Fatalf(`DecodeFile() = %d`, ret)
}
for _, barcode := range barcodes {
fmt.Println(barcode.Text)
fmt.Println(barcode.Format)
fmt.Println(barcode.X1)
fmt.Println(barcode.Y1)
fmt.Println(barcode.X2)
fmt.Println(barcode.Y2)
fmt.Println(barcode.X3)
fmt.Println(barcode.Y3)
fmt.Println(barcode.X4)
fmt.Println(barcode.Y4)
}
}