more test coverage
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,3 @@
|
|||||||
*.zpl
|
*.zpl
|
||||||
*.png
|
cmd/zplgfa/*.png
|
||||||
cmd/zplgfa/zplgfa
|
cmd/zplgfa/zplgfa
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
[](https://goreportcard.com/report/github.com/SimonWaldherr/zplgfa)
|
[](https://goreportcard.com/report/github.com/SimonWaldherr/zplgfa)
|
||||||
[](https://codebeat.co/projects/github-com-simonwaldherr-zplgfa-master)
|
[](https://codebeat.co/projects/github-com-simonwaldherr-zplgfa-master)
|
||||||
[](https://bettercodehub.com/results/SimonWaldherr/zplgfa)
|
[](https://bettercodehub.com/results/SimonWaldherr/zplgfa)
|
||||||
|
[](https://app.fossa.io/projects/git%2Bgithub.com%2FSimonWaldherr%2Fzplgfa?ref=badge_shield)
|
||||||
[](https://raw.githubusercontent.com/SimonWaldherr/zplgfa/master/LICENSE)
|
[](https://raw.githubusercontent.com/SimonWaldherr/zplgfa/master/LICENSE)
|
||||||
|
|
||||||
The ZPLGFA Golang package implements some functions to convert PNG, JPEG and GIF files to ZPL compatible ^GF-elements ([Graphic Fields](https://www.zebra.com/us/en/support-downloads/knowledge-articles/gf-graphic-field-zpl-command.html)).
|
The ZPLGFA Golang package implements some functions to convert PNG, JPEG and GIF files to ZPL compatible ^GF-elements ([Graphic Fields](https://www.zebra.com/us/en/support-downloads/knowledge-articles/gf-graphic-field-zpl-command.html)).
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
package zplgfa
|
package zplgfa
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"image"
|
||||||
|
_ "image/gif"
|
||||||
|
_ "image/jpeg"
|
||||||
|
_ "image/png"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_CompressASCII(t *testing.T) {
|
func Test_CompressASCII(t *testing.T) {
|
||||||
@@ -9,3 +16,44 @@ func Test_CompressASCII(t *testing.T) {
|
|||||||
t.Fatalf("CompressASCII failed")
|
t.Fatalf("CompressASCII failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_ConvertToZPL(t *testing.T) {
|
||||||
|
// open file
|
||||||
|
file, err := os.Open("./test.png")
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Warning: could not open the file: %s\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
// load image head information
|
||||||
|
config, format, err := image.DecodeConfig(file)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Warning: image not compatible, format: %s, config: %v, error: %s\n", format, config, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset file pointer to the beginning of the file
|
||||||
|
file.Seek(0, 0)
|
||||||
|
|
||||||
|
// load and decode image
|
||||||
|
img, _, err := image.Decode(file)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Warning: could not decode the file, %s\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// flatten image
|
||||||
|
flat := FlattenImage(img)
|
||||||
|
|
||||||
|
// convert image to zpl compatible type
|
||||||
|
gfimg := ConvertToZPL(flat, CompressedASCII)
|
||||||
|
|
||||||
|
// remove whitespace - only for the test
|
||||||
|
gfimg = strings.Replace(gfimg, " ", "", -1)
|
||||||
|
gfimg = strings.Replace(gfimg, "\n", "", -1)
|
||||||
|
|
||||||
|
if gfimg != "^XA,^FS^FO0,0^GFA,32,51,3,,::01C000::,001C00::,1DDC00::,::^FS,^XZ" {
|
||||||
|
t.Fatalf("ConvertToZPL failed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user