Skip to content

Commit

Permalink
more tests, more badges
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonWaldherr committed Oct 19, 2018
1 parent 5ab86c6 commit 9ab539b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 35 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# ZPLGFA Golang Package

[![GoDoc](https://godoc.org/github.com/SimonWaldherr/zplgfa?status.svg)](https://godoc.org/github.com/SimonWaldherr/zplgfa)
[![Build Status](https://travis-ci.org/SimonWaldherr/zplgfa.svg?branch=master)](https://travis-ci.org/SimonWaldherr/zplgfa)
[![Coverage Status](https://coveralls.io/repos/github/SimonWaldherr/zplgfa/badge.svg?branch=master)](https://coveralls.io/github/SimonWaldherr/zplgfa?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/SimonWaldherr/zplgfa)](https://goreportcard.com/report/github.com/SimonWaldherr/zplgfa)
[![codebeat badge](https://codebeat.co/badges/28d795af-6f9b-453a-94c2-4fafb8b5b0d5)](https://codebeat.co/projects/github-com-simonwaldherr-zplgfa-master)
[![BCH compliance](https://bettercodehub.com/edge/badge/SimonWaldherr/zplgfa?branch=master)](https://bettercodehub.com/results/SimonWaldherr/zplgfa)
Expand Down
Binary file added test2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 61 additions & 35 deletions zplgfa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,75 @@ import (
"strings"
)

func Test_CompressASCII(t *testing.T) {
if str := CompressASCII("FFFFFFFF000000"); str != "NFL0" {
t.Fatalf("CompressASCII failed")
}
type zplTest struct {
file string
zpl string
}

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()
var zplTests []zplTest

// 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)
func init() {
zplTests = []zplTest{
{
file: "./test.png",
zpl: "^XA,^FS^FO0,0^GFA,32,51,3,,::01C000::,001C00::,1DDC00::,::^FS,^XZ",
},
{
file: "./test2.png",
zpl: "^XA,^FS^FO0,0^GFA,389,630,63,,038038038038038038038038038038038038038038038038038038038038038038038038038038038038038038038038038038038038038038038038038000::1C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C71C7100::E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00E00:lJF00^FS,^XZ",
},
}
}

// 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
func Test_CompressASCII(t *testing.T) {
if str := CompressASCII("FFFFFFFF000000"); str != "NFL0" {
t.Fatalf("CompressASCII failed")
}
}

// 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")
func Test_ConvertToZPL(t *testing.T) {
for i, testcase := range zplTests {

filename, zplstring := testcase.file, testcase.zpl
// open file
file, err := os.Open(filename)
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 != zplstring {
t.Fatalf("Testcase %d ConvertToZPL failed", i)
}
}
}

0 comments on commit 9ab539b

Please sign in to comment.