-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqrcode_test.go
634 lines (590 loc) · 65.6 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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
package test
import (
"bufio"
"fmt"
"github.com/KangSpace/gqrcode"
"github.com/KangSpace/gqrcode/core/cons"
"github.com/KangSpace/gqrcode/core/mode"
"github.com/KangSpace/gqrcode/core/model"
"github.com/KangSpace/gqrcode/core/output"
"github.com/KangSpace/gqrcode/util"
"golang.org/x/text/encoding/japanese"
"golang.org/x/text/transform"
"image"
"image/color"
"image/png"
"io"
"io/ioutil"
"os"
"strconv"
"strings"
"sync"
"testing"
"time"
)
var home = os.Getenv("HOME")
var gqrcodePath = home + "/Desktop/gqrcode/"
var currentPath, _ = os.Getwd()
// -----------------------------TestAllNumericQRCode----------------------------------
// TestAllNumericQRCode :Test all numeric string for QRCode by 1 to 7089 length of string.
// e.g.: 0,01,012,0123....
// --- PASS: TestAllNumericQRCode (990.46s)
func TestAllNumericQRCode(t *testing.T) {
fmt.Println("TestAllNumericQRCode:")
testFile := currentPath + "/../doc/test/numeric_test/nmb.txt"
resultPath := currentPath + "/../doc/test/numeric_test/imgs/"
reportFile := currentPath + "/../doc/test/numeric_test/test_report.csv"
dataRowCount := 7089
AllQRCodeTest(testFile, resultPath, reportFile, dataRowCount, t)
}
func AllQRCodeTest(testFile, resultPath, reportFile string, dataRowCount int, t *testing.T) {
os.Mkdir(resultPath, os.ModePerm)
if err := initVerifyQRCodeByPythonEnv(); err != nil {
fmt.Println("python environment init failed.")
t.Fatal(err)
} else {
fmt.Println("python environment init success.")
}
wg := sync.WaitGroup{}
// read test data file
if file, err := os.Open(testFile); err == nil {
defer file.Close()
rd := bufio.NewReaderSize(file, dataRowCount)
// result str: [qgrcode result],[time/Milliseconds],[python result],[python return str],[data]
resultStr := "[qgrcode result],[time/Milliseconds],[python result],[python err][data]\n"
lop := true
allData := make([]string, 0, dataRowCount)
for i := 0; lop; i++ {
data_, isEnd, err := rd.ReadLine()
data := string(data_)
if err != nil || io.EOF == err || isEnd {
lop = false
}
allData = append(allData, data)
}
routineCount := 20
dataCountPerRoutine := dataRowCount / routineCount
if dataRowCount%routineCount > 0 {
routineCount += 1
}
wg.Add(routineCount)
lock := sync.Mutex{}
for i := 0; i < routineCount; i++ {
startIdx := i * dataCountPerRoutine
endIdx := startIdx + dataCountPerRoutine
var subDatas []string
if endIdx > dataRowCount {
endIdx = dataRowCount
}
subDatas = allData[startIdx:endIdx]
go func(subDatas []string) {
for _, data := range subDatas {
dataLen := len(data)
fileName := resultPath + strconv.Itoa(dataLen) + ".png"
result := singleQrCodeGenerateVerify(data, fileName)
lock.Lock()
// multi goroutine lock
resultStr += result
fmt.Println(fileName)
lock.Unlock()
}
wg.Done()
}(subDatas)
}
// waiting for goroutine run over
wg.Wait()
if resultStr != "" {
if reportF, err := os.Create(reportFile); err == nil {
defer reportF.Close()
reportF.WriteString(resultStr)
} else {
fmt.Printf("report :\n" + resultStr)
t.Fatal(err)
}
}
} else {
t.Fatal(err)
}
}
// generate qrcode by gqrcode(record time), and verify the qrcode by python pyzbar(record valid result).
func singleQrCodeGenerateVerify(data, fileName string) (result string) {
startTime := time.Now()
tempResult := ""
if err := generateTestQRCode(data, fileName); err == nil {
cost := time.Since(startTime).Milliseconds()
tempResult += "true," + fmt.Sprintf("%d", cost) + ","
// verify qrcode
if pyResult, err := VerifyQRCodeByPython(fileName); err == nil {
tempResult += strconv.FormatBool(data == pyResult) + ","
} else {
tempResult += "false," + err.Error()
}
tempResult += "," + data
} else {
tempResult += "false,0,false,," + data
fmt.Println(err.Error())
}
tempResult += "\n"
return tempResult
}
func generateTestQRCode(data string, fileName string) error {
if qr, err := gqrcode.NewQRCode(data); err == nil {
err = qr.Encode(output.NewPNGOutput0(), fileName)
return err
} else {
return err
}
}
// TODO Need Change python3 to your python
var verifyQRCodeByPythonCmd = "python3"
var verifyArg0 = currentPath + "/../doc/test/run.py"
// TODO Need Change pip3 to your pip
var verifyQRCodeByPythonInitEnvCmd = "pip3"
var envArg = []string{"install", "qrcode", "pillow", "image", "zxing"}
func initVerifyQRCodeByPythonEnv() (err error) {
fmt.Println("init python environment!")
if result, err := util.RunCmd(verifyQRCodeByPythonInitEnvCmd, envArg...); err == nil {
fmt.Println(result)
return nil
} else {
return err
}
}
// Python decoder(zxing) maybe so slow(because it's implement by java jar in side.)
// The decoder is python pyzbar in here.
func VerifyQRCodeByPython(fileName string) (result string, err error) {
fmt.Println("Verify:" + fileName)
return util.RunCmd(verifyQRCodeByPythonCmd, verifyArg0, fileName)
}
// -----------------------------TestNumericQRCode----------------------------------
func TestPng(t *testing.T) {
fmt.Println(home)
file, _ := os.Create(home + "/Desktop/i.png")
defer file.Close()
img := image.NewRGBA(image.Rect(0, 0, 100, 100))
img.Set(50, 50, color.Black)
img.Set(101, 101, color.Black)
img.Set(99, 99, color.Black)
img.Set(100, 100, color.Black)
img.Set(1, 1, color.White)
fmt.Println("pix:")
fmt.Println("50,50:", img.At(50, 50))
fmt.Println("1,1:", img.At(1, 1))
fmt.Println("10,10:", img.At(10, 10))
fmt.Println("90,90:", img.At(99, 99))
fmt.Println("100,100:", img.At(100, 100))
fmt.Println("101,101:", img.At(101, 101))
fmt.Println(img.Opaque())
if err := png.Encode(file, img); err != nil {
t.Fatal(err)
} else {
fileInfo, _ := file.Stat()
fmt.Println(fileInfo.Name())
}
}
// TestNewNumeric1QRCode : test 1 single numeric QRCode
func TestNewNumeric1QRCode(t *testing.T) {
// 192
//data := "123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123"
// 7089 OK
//data := "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"
// 7067
//data := "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456"
// 1016 OK
//data := "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345"
// 6113 OK
//data := "01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012"
// 1022 OK, 1023 OK
//data := "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567123456789012345678901234567890123456789012345678901234567123456789012345678901234567890123456789012345678901234567123456789012345678901234567890123456789012345678901234567123456789012345678901234567890123456789012345678901234567123456789012345678901234567890123456789012345678901234567123456789012345678901234567890123456789012345678901234567123456789012345678901234567890123456789012345678901234567123456789012345678901234567890123456789012345678901234567123456789012345678901234567890123456789012345678901234567123456789012345678901234567890123456789012345678901234567123456789012345678901234567890123456789012345678901234567123456789012345678901234567890123456789012345678901234567012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
// 370 version7 L
//data := "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
// 5269 OK
//data := "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"
data := "0123456789"
fmt.Println(len(data))
//data := "8675309"
fileNamePrefix := "numeric"
fileName := gqrcodePath + fileNamePrefix + ".png"
//out := output.NewPNGOutput(100)
out := output.NewPNGOutput0()
//out := output.NewGIFOutput0()
//qrcode, err := NewQRCode0(data, core.QRCODE_MODEL2,mode.NewErrorCorrection(core.L),mode.NewNumericMode())
qrcode, err := gqrcode.NewQRCode(data)
if err != nil {
t.Fatal(err)
}
qrcode.Encode(out, fileName)
fmt.Printf("version:%v, size:%d, ec:%v mode:%s \n", qrcode.Version, out.Size, qrcode.ErrorCorrection, qrcode.Mode.GetMode())
fmt.Println("SUCCESS," + fileName)
}
// TestNewNumeric4SizeQRCode :
// test case:
// 1. qrcode with autosize and no quiet zone, OK
// 2. qrcode with autosize and auto quiet zone or 2 quiet zone, OK
// 3. qrcode with 100px and no quiet zone
// 4. qrcode with 100px and auto quiet zone or 2 quiet zone
func TestNewNumeric4SizeQRCode(t *testing.T) {
//data := "123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123123"
//data := "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"
data := "8675309"
fileNamePrefix := "7089"
imageSize := 400
// 7090 numeric
//data := "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"
//fileNamePrefix:="7090"
fmt.Println("data length:" + strconv.Itoa(len(data)))
//data := "8675309"
fileName := gqrcodePath + fileNamePrefix + "_auto_size_no_quiet.png"
fmt.Println("test case1:" + fileName)
//out := output.NewPNGOutput(100)
out := output.NewPNGOutput0()
//quietZone := model.AutoQuietZone
quietZone := model.NoneQuietZone
//quietZone := model.NewQuietZone(2)
qrcode, err := gqrcode.NewQRCode0(data, cons.QrcodeModel2, nil, mode.NewNumericMode(), quietZone)
//qrcode, err := core.NewQRCode(data)
if err != nil {
t.Fatal(err)
}
qrcode.Encode(out, fileName)
fileName = gqrcodePath + fileNamePrefix + "_auto_size_auto_quiet.png"
fmt.Println("test case2:" + fileName)
//out = output.NewPNGOutput(100)
out = output.NewPNGOutput0()
quietZone = model.AutoQuietZone
//quietZone = model.NoneQuietZone
//quietZone = model.NewQuietZone(2)
qrcode, err = gqrcode.NewQRCode0(data, cons.QrcodeModel2, nil, mode.NewNumericMode(), quietZone)
//qrcode, err := core.NewQRCode(data)
if err != nil {
t.Fatal(err)
}
qrcode.Encode(out, fileName)
fileName = gqrcodePath + fileNamePrefix + "_" + (strconv.Itoa(imageSize)) + "_size_no_quiet.png"
fmt.Println("test case3:" + fileName)
out = output.NewPNGOutput(imageSize)
//out = output.NewPNGOutput0()
//quietZone = model.AutoQuietZone
quietZone = model.NoneQuietZone
//quietZone = model.NewQuietZone(2)
qrcode, err = gqrcode.NewQRCode0(data, cons.QrcodeModel2, nil, mode.NewNumericMode(), quietZone)
if err != nil {
t.Fatal(err)
}
qrcode.Encode(out, fileName)
fileName = gqrcodePath + fileNamePrefix + "_" + (strconv.Itoa(imageSize)) + "_size_auto_quiet.png"
fmt.Println("test case4:" + fileName)
out = output.NewPNGOutput(imageSize)
//out = output.NewPNGOutput0()
quietZone = model.AutoQuietZone
//quietZone = model.NoneQuietZone
//quietZone = model.NewQuietZone(2)
qrcode, err = gqrcode.NewQRCode0(data, cons.QrcodeModel2, nil, mode.NewNumericMode(), quietZone)
if err != nil {
t.Fatal(err)
}
qrcode.Encode(out, fileName)
fmt.Println("SUCCESS")
}
// -----------------------------TestAlphanumericQRCode----------------------------------
// TestAlphanumericQRCode :Test 1 single alphanumeric QRCode
func TestAlphanumericQRCode(t *testing.T) {
// 1 OK
//data := "A"
// 45 OK
data := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"
fmt.Println(len(data))
fileNamePrefix := "alphanumeric"
fileName := gqrcodePath + fileNamePrefix + ".jpg"
out := output.NewJPGOutput0()
qrcode, err := gqrcode.NewQRCodeAutoQuiet(data)
if err != nil {
t.Fatal(err)
}
qrcode.Encode(out, fileName)
fmt.Printf("version:%v, size:%d, ec:%v mode:%s \n", qrcode.Version, out.Size, qrcode.ErrorCorrection, qrcode.Mode.GetMode())
fmt.Println("fileName," + fileName)
//initVerifyQRCodeByPythonEnv()
if result, err := VerifyQRCodeByPython(fileName); err == nil {
fmt.Println("SUCCESS," + result)
} else {
fmt.Println("FAIL," + result)
t.Fatal(err)
}
}
// TestAllAlphanumericQRCode :Test all alphanumeric string for QRCode by 1 to 4296 length of string.
func TestAllAlphanumericQRCode(t *testing.T) {
fmt.Println("TestAllAlphanumericQRCode:")
testFile := currentPath + "/../doc/test/numeric_test/nmb.txt"
resultPath := currentPath + "/../doc/test/numeric_test/imgs/"
reportFile := currentPath + "/../doc/test/numeric_test/test_report.csv"
dataRowCount := 4296
AllQRCodeTest(testFile, resultPath, reportFile, dataRowCount, t)
}
// -----------------------------TestByteQRCode----------------------------------
// TestAlphanumericQRCode :Test byte(IOS-8859-1) QRCode
func TestByteQRCode(t *testing.T) {
data := "https://kangspace.org"
fmt.Println(len(data))
fileNamePrefix := "byte"
fileName := gqrcodePath + fileNamePrefix + ".gif"
out := output.NewGIFOutput0()
qrcode, err := gqrcode.NewQRCode(data)
if err != nil {
t.Fatal(err)
}
qrcode.Encode(out, fileName)
fmt.Printf("version:%v, size:%d, ec:%v mode:%s \n", qrcode.Version, out.Size, qrcode.ErrorCorrection, qrcode.Mode.GetMode())
fmt.Println("fileName," + fileName)
//initVerifyQRCodeByPythonEnv()
if result, err := VerifyQRCodeByPython(fileName); err == nil {
fmt.Println("SUCCESS," + result)
} else {
fmt.Println("FAIL," + result)
t.Fatal(err)
}
}
// TestByteQRCodeWithColor :Test byte(IOS-8859-1) QRCode
func TestByteQRCodeWithColor(t *testing.T) {
//data := "https://kangspace.org"
data := "是你让我看透生命这东西,四个字“坚持到底”……看那扑翅的飞蛾,不顾一切地朝着灯光的方向扑去;看那缓缓的蜗牛,不变地朝着一个目标“金字塔顶”而坚持。\n 李白看到了“只要功夫深铁杵磨成针”他成为了诗之仙,文飞剑舞。\n 司马迁懂得生死如鸿毛、如泰山,沿着泰山攀爬,才能成就大事业。正应了那句“世上无难事,只要肯攀登”,他成就了那部伟大的《史记》,汗青留名,永垂不朽。\n 爱迪生,仅发明灯泡就让他失败了3000多次。然而,他没有放弃,宁愿“在大海中捞针”,也要坚持不懈。最终,他成功了,他的名字同“光明”刻在了一起。就是一样的精神,使它成为了发明大王。\n 库提斯,仅有上半身,而当你看到他是怎样幸福地生活、怎样灵巧地行走、怎样地游着滑板到演讲台上时,你便会知道一个强壮、坚强、执着、顽强的励志大师是可以这样成功的。\n 古今中外,名人志士、成功人士,有多少的人共同验证着这样一句话:“成功就是坚持到底”。路是人走出来的,没有比脚更长的路。坚持沿着自己的路走下去,便会有意想不到的成功、收获。\n 眺望远方,因为有梦想,所以追求。流水潺潺,水滴石穿。人生有道,天道酬勤。骐骥一跃,不能十步;驽马十驾,功在不舍。锲而舍之,朽木不折;锲而不舍,金石可镂。将执着的追求进行到底,没有比脚更长的路。"
fmt.Println(len(data))
fileNamePrefix := "byte_color"
fileName := gqrcodePath + fileNamePrefix + ".png"
out := output.NewOutput(&output.BaseOutput{Type: output.PNG, Size: 800, CodeColor: output.ColorfulCodeColor})
qrcode, err := gqrcode.NewQRCodeAutoQuiet(data)
if err != nil {
t.Fatal(err)
}
qrcode.Encode(out, fileName)
fmt.Printf("version:%v, size:%d, ec:%v mode:%s \n", qrcode.Version, out.Size, qrcode.ErrorCorrection, qrcode.Mode.GetMode())
fmt.Println("fileName," + fileName)
}
// TestByteQRCodeBase64 :Test Base64 output string
func TestByteQRCodeBase64(t *testing.T) {
data := "https://kangspace.org"
fmt.Println(len(data))
fileNamePrefix := "base64"
out := output.NewPNGOutput0()
qrcode, err := gqrcode.NewQRCodeAutoQuiet(data)
if err != nil {
t.Fatal(err)
}
base64, err := qrcode.EncodeToBase64(out)
fmt.Println(fileNamePrefix + ",png:" + base64)
base64, err = qrcode.EncodeToBase64(output.NewJPGOutput0())
fmt.Println(fileNamePrefix + ",jpg:" + base64)
base64, err = qrcode.EncodeToBase64(output.NewGIFOutput0())
fmt.Println(fileNamePrefix + ",gif:" + base64)
fileName := gqrcodePath + fileNamePrefix + ".png"
qrcode.Encode(out, fileName)
fmt.Printf("version:%v, size:%d, ec:%v mode:%s \n", qrcode.Version, out.Size, qrcode.ErrorCorrection, qrcode.Mode.GetMode())
fmt.Println("fileName," + fileName)
//initVerifyQRCodeByPythonEnv()
if result, err := VerifyQRCodeByPython(fileName); err == nil {
fmt.Println("SUCCESS," + result)
} else {
fmt.Println("FAIL," + result)
t.Fatal(err)
}
}
func TestByteQRCodeSaveToWriter(t *testing.T) {
data := "https://kangspace.org"
fmt.Println(len(data))
fileNamePrefix := "saveToWriter"
out := output.NewPNGOutput0()
qrcode, err := gqrcode.NewQRCodeAutoQuiet(data)
if err != nil {
t.Fatal(err)
}
fileName := gqrcodePath + fileNamePrefix + ".png"
var file *os.File
if file, err = os.Open(fileName); err != nil {
if file, err = os.Create(fileName); err == nil {
err := qrcode.EncodeToWriter(out, file)
if err == nil {
fmt.Println("SUCCESS")
}
}
}
if err != nil {
t.Fatal(err)
}
fmt.Printf("version:%v, size:%d, ec:%v mode:%s \n", qrcode.Version, out.Size, qrcode.ErrorCorrection, qrcode.Mode.GetMode())
fmt.Println("fileName," + fileName)
}
func TestByteChineseQRCode(t *testing.T) {
//data := "你好,世界!Hello World!"
// max:2953 ,curr: 2953
data := "1234567891234你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!你好,世界!Hello World!"
fmt.Println(len(data))
fileNamePrefix := "byte-utf8"
fileName := gqrcodePath + fileNamePrefix + ".gif"
out := output.NewGIFOutput0()
qrcode, err := gqrcode.NewQRCode(data)
if err != nil {
t.Fatal(err)
}
qrcode.Encode(out, fileName)
fmt.Printf("version:%v, size:%d, ec:%v mode:%s \n", qrcode.Version, out.Size, qrcode.ErrorCorrection, qrcode.Mode.GetMode())
fmt.Println("fileName," + fileName)
//initVerifyQRCodeByPythonEnv()
if result, err := VerifyQRCodeByPython(fileName); err == nil {
fmt.Println("SUCCESS," + result)
} else {
fmt.Println("FAIL," + result)
t.Fatal(err)
}
}
// TestByteQRCodeWithLogo :Test byte qrcode with logo
func TestByteQRCodeWithLogo(t *testing.T) {
data := "https://kangspace.org"
logoImageFilePath := currentPath + "/../doc/images/qr/kangspace_logo.png"
//logoImageFilePath := currentPath+"/../doc/images/qr/bd.png"
fileNamePrefix := "qrcode_with_logo"
// 264,429
out := output.NewJPGOutput(1000)
out.AddOption(output.LogoOption(logoImageFilePath))
qrcode, err := gqrcode.NewQRCodeAutoQuiet(data)
if err != nil {
panic(err)
}
fileName := gqrcodePath + fileNamePrefix + ".png"
err = qrcode.Encode(out, fileName)
if err != nil {
t.Fatal(err)
}
fmt.Printf("moduleSize:%v, version:%v, size:%d, ec:%v mode:%s \n", qrcode.GetModuleSize(), qrcode.Version, out.Size, qrcode.ErrorCorrection, qrcode.Mode.GetMode())
fmt.Println("fileName," + fileName)
fmt.Printf("RecommendSize:%d \n", out.GetRecommendSize(qrcode.GetModuleSize()))
}
// -----------------------------TestKanjiQRCode----------------------------------
func TestKanjiQRCode(t *testing.T) {
data := "茗荷" //日月
//data := "はの"
data, err := ToShiftJIS(data)
if err != nil {
t.Fatal(err)
}
fmt.Printf("dataLen:%d\n", len(data))
fileNamePrefix := "kanji"
fileName := gqrcodePath + fileNamePrefix + ".png"
out := output.NewPNGOutput0()
qrcode, err := gqrcode.NewQRCode(data)
if err != nil {
fmt.Println(err)
t.Fatal(err)
}
qrcode.Encode(out, fileName)
fmt.Printf("version:%v, size:%d, ec:%v mode:%s \n", qrcode.Version, out.Size, qrcode.ErrorCorrection, qrcode.Mode.GetMode())
fmt.Println("fileName," + fileName)
//initVerifyQRCodeByPythonEnv()
if result, err := VerifyQRCodeByPython(fileName); err == nil {
fmt.Println("SUCCESS," + result)
} else {
fmt.Println("FAIL," + result)
t.Fatal(err)
}
}
func transformEncoding(rawReader io.Reader, trans transform.Transformer) (string, error) {
ret, err := ioutil.ReadAll(transform.NewReader(rawReader, trans))
if err == nil {
return string(ret), nil
} else {
return "", err
}
}
// Convert a string encoding from UTF-8 to ShiftJIS
func ToShiftJIS(str string) (string, error) {
return transformEncoding(strings.NewReader(str), japanese.ShiftJIS.NewEncoder())
}
// TestAllVersionBestQRCodeImageSize : 各版本二维码最佳尺寸(使用4倍像素表示)
func TestAllVersionBestQRCodeImageSize(t *testing.T) {
fmt.Println("Best size of QR code of each version. (1 point by 4 pixels!)")
fmt.Println("Version\t 0QuietZone\t 1QuietZone\t 2QuietZone\t 4QuietZone\t maxCharacterLen(AlphaNumeric)\t")
allSize := make([]int, 0)
versions := model.Versions
quiteZones := model.QuietZones
for _, version := range versions {
versionName := strconv.Itoa(version.Id)
if version.Id < 0 {
versionName, _ = model.VersionM1ToM4IdNameMap[version.Id]
}
fmt.Printf("%s\t", versionName)
for _, qz := range quiteZones {
out := output.NewJPGOutput0()
out.Init(version, qz)
size := out.GetBaseOutput().Size
allSize = append(allSize, size)
fmt.Printf("%d\t", size)
}
ecMap, _ := model.VersionSymbolCharsAndInputDataCapacityMap[version.Id]
ec := cons.L
mode := cons.AlphanumericMode
desc := ""
if version.Id == model.VersionM1 {
ec = cons.NONE
mode = cons.NumericMode
desc = "(Numeric)"
}
dataCapacity, _ := ecMap[ec].DataCapacity[mode]
fmt.Printf("%d%s\t", dataCapacity, desc)
fmt.Println("")
}
fmt.Println(allSize)
}
type ImageSuffix struct {
suffix string
}
var (
Png = ImageSuffix{".png"}
Jpg = ImageSuffix{".jpg"}
Gif = ImageSuffix{".gif"}
)
// TestQRCodeImageSizeToBestVersion : 测试使用最合适的版本生成指定图片大小的二维码
func TestQRCodeImageSizeToBestVersion(t *testing.T) {
fmt.Println("TestQRCodeImageSizeToBestVersion start!")
imageSizes := []int{
//100,200,300,
400,
//500,600,700,800,900,1000,
}
data := []string{
"helloworld123456", "HELLOWORLD123456",
// length: 320
"HELLOWORLD123456HELLOWORLD123456HELLOWORLD123456HELLOWORLD123456HELLOWORLD123456HELLOWORLD123456HELLOWORLD123456HELLOWORLD123456HELLOWORLD123456HELLOWORLD123456HELLOWORLD123456HELLOWORLD123456HELLOWORLD123456HELLOWORLD123456HELLOWORLD123456HELLOWORLD123456HELLOWORLD123456HELLOWORLD123456HELLOWORLD123456HELLOWORLD123456"}
fileNamePrefix := "best_version/best_version_"
//suffix := Png
//suffix := Jpg
suffix := Gif
for i, subData := range data {
drawQRCode(subData, imageSizes, fileNamePrefix+(strconv.Itoa(i))+"_", model.AutoQuietZone, suffix, t)
}
fmt.Println("end!")
}
func drawQRCode(data string, imageSizes []int, fileNamePrefix string, quietZone *model.QuietZone, suffix ImageSuffix, t *testing.T) {
fmt.Println("================")
fmt.Println("fileNamePrefix:", fileNamePrefix, " size:", imageSizes)
suffixFormat := suffix.suffix
outputFn := func(qrcode *mode.QRCodeStruct, size int, fileName string) {
var imageOut *output.ImageOutput
if suffix == Png {
imageOut = output.NewPNGOutput(size)
} else if suffix == Jpg {
imageOut = output.NewJPGOutput(size)
} else if suffix == Gif {
imageOut = output.NewGIFOutput(size)
}
qrcode.Encode(imageOut, fileName)
}
for _, size := range imageSizes {
fileName := gqrcodePath + fileNamePrefix + (strconv.Itoa(size)) + suffixFormat
if qrcode, err := gqrcode.NewQRCodeWithQuiet(data, quietZone); err == nil {
outputFn(qrcode, size, fileName)
fmt.Printf("version:%v, size:%d, ec:%v mode:%s \n", qrcode.Version, size, qrcode.ErrorCorrection, qrcode.Mode.GetMode())
fmt.Println("fileName," + fileName)
} else {
t.Fatal(err)
}
}
}