-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write multiple QR code images if data exceeds capacity (#13)
- Loading branch information
Christian Häusler
authored
Oct 21, 2018
1 parent
f9d4ba6
commit daca659
Showing
77 changed files
with
292 additions
and
502 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
//////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
������ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/w== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
� |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
fIttAujV5kCX6zsOQqe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uuOJT4gJ9ToWOpctPAL4tbVVFxOf3ImtqlL2XM7OtFmV4AJKGy6+BnRXl+SrIjVhJCZupmkCBIC1PPzXgfsozoC7cHQQ4v3sHs+zI+DdQHBs2atRRyB/k0qQm+89WQgvxFsL3ECPD1YrcLBCwLTK5rD3VlaFgWt7eFaJZDAm04o+JI3Y15nw9VIiT7aTz3GciTfSuKln0z9dwqxt16SDW6lwsDzu/N+Xd2+Yx3vvsJjC3J4xA5JSYGK2m/TU34mjMylq2vioM6oJmtY6wcEGFcQbOmMwY94ehkZ63iZSbmWbBTFqKSONGRG0UhLgOgwX8R2FNua+4PM4g00sRuBdxmb8j+Xsbi25mLt+OTWnRo3In08KcF7b6TqWBwU1k+upgbcnLYlU6d/cUz/VI3SDhubEK7Iry9ZA1mvcYuDUaYN+Ja7V4Itsnj5K3yF7Udk8OqRociR1ZjcIUxdtw9GObkizHW9wKZoSArXaFXxPelGdRcxZnyxFZbIuKj9Kt/xJ333aOsWeRkwBnZk6SO258AeYdXJW/cwVH8SKSi7XQxBPhfrS/w5dF0m3+4bg5Hv036Gzwa4DzIJa9QZH8s1tSwcBAxt61FtCdx35Tlk1gmA0lhs3zaya22n6GJ7M7yqNdEBDs8dA== |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
AA== |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,99 @@ | ||
package assert | ||
|
||
import ( | ||
"bytes" | ||
"crypto/rand" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/corvus-ch/horcrux/format" | ||
"github.com/sebdah/goldie" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// DataTest holds data required for format data read and write assertions. | ||
type DataTest struct { | ||
Decoded []byte | ||
Encoded string | ||
} | ||
// FormatFactory describes a func used for instantiating a Format during assertions. | ||
type FormatFactory func(string) format.Format | ||
|
||
// OutputFileNames describes a func used to get the output file names only known to the calling test case. | ||
type OutputFileNames func(file string, x byte) []string | ||
|
||
// DataRead asserts a formats read behaviour. | ||
func DataRead(t *testing.T, tests []DataTest, factory FormatFactory) { | ||
for _, test := range tests { | ||
t.Run(test.Encoded, func(t *testing.T) { | ||
r, err := factory("").Reader(bytes.NewBufferString(test.Encoded)) | ||
func DataRead(t *testing.T, factory FormatFactory, suffix string) { | ||
goldie.FileNameSuffix = ".bin" | ||
files, err := filepath.Glob(filepath.Join(goldie.FixtureDir, "*"+suffix)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
for _, file := range files { | ||
basename := filepath.Base(file) | ||
name := strings.TrimSuffix(basename, filepath.Ext(basename)) | ||
t.Run(name, func(t *testing.T) { | ||
f, err := os.Open(file) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
r, err := factory("").Reader(f) | ||
assert.Nil(t, err) | ||
out, err := ioutil.ReadAll(r) | ||
assert.NoError(t, err) | ||
assert.Equal(t, test.Decoded, out) | ||
goldie.Assert(t, name, out) | ||
}) | ||
} | ||
} | ||
|
||
// DataWrite asserts a formats write behaviour. | ||
func DataWrite(t *testing.T, tests []DataTest, factory FormatFactory) { | ||
for _, test := range tests { | ||
t.Run(test.Encoded, func(t *testing.T) { | ||
out := &bytes.Buffer{} | ||
w, cl, err := factory("").Writer(out) | ||
func DataWrite(t *testing.T, factory FormatFactory, suffix string, outfilenames OutputFileNames) { | ||
goldie.FileNameSuffix = suffix | ||
files, err := filepath.Glob(filepath.Join(goldie.FixtureDir, "*.bin")) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
for _, file := range files { | ||
basename := filepath.Base(file) | ||
name := strings.TrimSuffix(basename, filepath.Ext(basename)) | ||
t.Run(name, func(t *testing.T) { | ||
x := randomByte(t) | ||
f, err := os.Open(file) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
dir, err := ioutil.TempDir("", name) | ||
defer os.RemoveAll(dir) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
subject := factory(filepath.Join(dir, name)) | ||
w, cl, err := subject.Writer(x) | ||
assert.NoError(t, err) | ||
_, err = io.Copy(w, f) | ||
assert.NoError(t, err) | ||
w.Write(test.Decoded) | ||
for i := len(cl); i > 0; i-- { | ||
cl[i-1].Close() | ||
err = cl[i-1].Close() | ||
assert.NoError(t, err) | ||
} | ||
for _, outfile := range outfilenames(file, x) { | ||
file, err := os.Open(filepath.Join(dir, outfile)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
out, _ := ioutil.ReadAll(file) | ||
goldenName := strings.Replace(strings.Replace(outfile, suffix, "", -1), fmt.Sprintf(".%03d", x), "", -1) | ||
t.Log(goldenName) | ||
goldie.Assert(t, goldenName, out) | ||
} | ||
assert.Equal(t, test.Encoded, out.String()) | ||
}) | ||
} | ||
} | ||
|
||
func randomByte(t *testing.T) byte { | ||
b := make([]byte, 1) | ||
if _, err := rand.Read(b); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
return b[0] | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
������ |
Binary file not shown.
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
� |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
File renamed without changes
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.